Skip to content

Commit

Permalink
third draft
Browse files Browse the repository at this point in the history
  • Loading branch information
montythind committed Oct 1, 2024
1 parent da7cd22 commit 32a16e2
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 16 deletions.
15 changes: 12 additions & 3 deletions include/micm/configure/solver_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ namespace micm
System system_;
std::vector<Process> processes_;
RosenbrockSolverParameters parameters_;
double relative_tolerance_;

SolverParameters(const System& system, std::vector<Process>&& processes, const RosenbrockSolverParameters&& parameters)
: system_(system),
Expand All @@ -116,6 +117,13 @@ namespace micm
parameters_(parameters)
{
}
SolverParameters(System&& system, std::vector<Process>&& processes, RosenbrockSolverParameters&& parameters, double relative_tolerance)
: system_(system),
processes_(processes),
parameters_(parameters),
relative_tolerance_(relative_tolerance)
{
}
};

class ConfigReaderPolicy
Expand All @@ -138,6 +146,7 @@ namespace micm
std::unordered_map<std::string, Phase> phases_;
std::vector<Process> processes_;
RosenbrockSolverParameters parameters_;
double relative_tolerance_;

// Common YAML
inline static const std::string DEFAULT_CONFIG_FILE_JSON = "config.json";
Expand Down Expand Up @@ -273,7 +282,7 @@ namespace micm
processes_.clear();

// Parse species object array
ParseSpeciesArray(species_objects);
ParseSpeciesArray(species_objects);

// Assign the parsed 'Species' to 'Phase'
std::vector<Species> species_arr;
Expand Down Expand Up @@ -426,7 +435,7 @@ namespace micm
void ParseRelativeTolerance(const objectType& object)
{
ValidateSchema(object, { "value", "type" }, {});
//this->parameters_.relative_tolerance_ = object["value"].as<double>();
this->relative_tolerance_ = object["value"].as<double>();
}

void ParseMechanism(const objectType& object)
Expand Down Expand Up @@ -959,7 +968,7 @@ namespace micm
SolverParameters GetSolverParams()
{
return SolverParameters(
std::move(System(this->gas_phase_, this->phases_)), std::move(this->processes_), std::move(this->parameters_));
std::move(System(this->gas_phase_, this->phases_)), std::move(this->processes_), std::move(this->parameters_), std::move(this->relative_tolerance_));
}
};
} // namespace micm
2 changes: 0 additions & 2 deletions include/micm/solver/rosenbrock_solver_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <limits>
#include <vector>

//#include "../include/micm/solver/solver.hpp"

namespace micm
{

Expand Down
1 change: 1 addition & 0 deletions include/micm/solver/solver_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace micm
bool reorder_state_ = true;
bool valid_system_ = false;
bool valid_reactions_ = false;
double relative_tolerance_ = 1e-06;

public:
SolverBuilder() = delete;
Expand Down
4 changes: 2 additions & 2 deletions include/micm/solver/solver_builder.inl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ namespace micm
}
}
}
}
}

template<
class SolverParametersPolicy,
Expand Down Expand Up @@ -399,7 +399,7 @@ namespace micm
.nonzero_jacobian_elements_ = nonzero_elements };


this->SetAbsoluteTolerances(state_parameters.absolute_tolerance_, species_map); //WHERE TO ADD THIS??????
this->SetAbsoluteTolerances(state_parameters.absolute_tolerance_, species_map);

return Solver<SolverPolicy, StatePolicy>(
SolverPolicy(options, std::move(linear_solver), std::move(rates), jacobian),
Expand Down
3 changes: 2 additions & 1 deletion include/micm/solver/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace micm
std::vector<std::string> variable_names_{};
std::vector<std::string> custom_rate_parameter_labels_{};
std::set<std::pair<std::size_t, std::size_t>> nonzero_jacobian_elements_{};
double relative_tolerance_;
double relative_tolerance_{ 1e-06 };
std::vector<double> absolute_tolerance_ {};
};

Expand Down Expand Up @@ -140,6 +140,7 @@ namespace micm
/// @param value new parameter value
void SetCustomRateParameter(const std::string& label, double value);
void SetCustomRateParameter(const std::string& label, const std::vector<double>& values);
void SetRelativeTolerances(double relativeTolerance);

/// @brief Print a header of species to display concentrations with respect to time
void PrintHeader();
Expand Down
6 changes: 6 additions & 0 deletions include/micm/solver/state.inl
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ namespace micm
for (std::size_t i = 0; i < custom_rate_parameters_.NumRows(); ++i)
custom_rate_parameters_[i][param->second] = values[i];
}

template<class DenseMatrixPolicy, class SparseMatrixPolicy>
inline void State<DenseMatrixPolicy, SparseMatrixPolicy>::SetRelativeTolerances(double relativeTolerance)
{
this->relative_tolerance_ = relativeTolerance;
}

template<class DenseMatrixPolicy, class SparseMatrixPolicy>
inline void State<DenseMatrixPolicy, SparseMatrixPolicy>::PrintHeader()
Expand Down
10 changes: 5 additions & 5 deletions test/integration/test_chapman_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ TEST(ChapmanIntegration, CanBuildChapmanSystemUsingConfig)
// Get solver parameters ('System', the collection of 'Process')
micm::SolverParameters solver_params = solverConfig.GetSolverParams();

auto options = solver_params.parameters_;
auto options = solver_params.parameters_;

auto solver = micm::CpuSolverBuilder<micm::RosenbrockSolverParameters>(options)
.SetSystem(solver_params.system_)
.SetReactions(solver_params.processes_)
.SetIgnoreUnusedSpecies(true)
.Build();
.SetIgnoreUnusedSpecies(true)
.Build();

micm::State state = solver.GetState();

EXPECT_EQ(state.relative_tolerance_, 1.0e-6);
state.SetRelativeTolerances(solver_params.relative_tolerance_);
EXPECT_EQ(state.relative_tolerance_, 1.0e-4);

for (size_t n_grid_cell = 0; n_grid_cell < state.number_of_grid_cells_; ++n_grid_cell)
{
Expand Down
4 changes: 1 addition & 3 deletions test/unit/solver/test_solver_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ TEST(SolverBuilder, CanBuildRosenbrock)
.SetNumberOfGridCells(1)
.Build();
}

/*
TEST(SolverBuilder, MismatchedToleranceSizeIsCaught)
{
Expand All @@ -128,5 +127,4 @@ TEST(SolverBuilder, MismatchedToleranceSizeIsCaught)
micm::SparseMatrix<double, micm::SparseMatrixVectorOrdering<L>>>(params);
EXPECT_ANY_THROW(builder.SetSystem(the_system).SetReactions(reactions).SetNumberOfGridCells(1).Build(););
}
*/
}*/

0 comments on commit 32a16e2

Please sign in to comment.