Skip to content

Commit

Permalink
add an assign function in sparse matrix class and chapman integration…
Browse files Browse the repository at this point in the history
… test using config
  • Loading branch information
boulderdaze committed Jun 16, 2023
1 parent eeb08d3 commit d7d5cc1
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 27 deletions.
10 changes: 10 additions & 0 deletions include/micm/util/sparse_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ namespace micm
{
}

SparseMatrix<T>& operator=(SparseMatrixBuilder<T>& builder)
{
number_of_blocks_ = builder.number_of_blocks_;
data_ = std::vector<T>(builder.NumberOfElements(), builder.initial_value_);
row_ids_ = builder.RowIdsVector();
row_start_ = builder.RowStartVector();

return *this;
}

std::vector<T>& AsVector()
{
return data_;
Expand Down
89 changes: 62 additions & 27 deletions test/integration/chapman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,42 @@

using yields = std::pair<micm::Species, double>;

#ifdef USE_JSON
# include <micm/configure/solver_config.hpp>
TEST(ChapmanIntegration, CanBuildChapmanSystemUsingConfig)
{
micm::SolverConfig<micm::JsonReaderPolicy, micm::ThrowPolicy> solverConfig{}; // Throw policy
std::variant<micm::SolverParameters, micm::ConfigErrorCode> configs =
solverConfig.Configure("./unit_configs/chapman/config.json");

// Check if parsing is successful and returns 'Solverparameters'
auto* solver_params_ptr = std::get_if<micm::SolverParameters>(&configs);
EXPECT_TRUE(solver_params_ptr != nullptr);

micm::SolverParameters& solver_params = *solver_params_ptr;

micm::RosenbrockSolver solver{ solver_params.system_,
std::move(solver_params.processes_),
micm::RosenbrockSolverParameters{} };

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

std::vector<double> concentrations{ 0.1, 0.1, 0.1, 0.2, 0.2, 0.2, 0.3, 0.3, 0.3 };
state.variables_[0] = concentrations;
std::vector<double> photo_rates{ 0.1, 0.2, 0.3 };
state.custom_rate_parameters_[0] = photo_rates;
state.conditions_[0].temperature_ = 2;
state.conditions_[0].pressure_ = 3;

for (double t{}; t < 100; ++t)
{
state.custom_rate_parameters_[0] = photo_rates;
auto result = solver.Solve(t, t + 0.5, state);
// output state
}
}
#endif

TEST(ChapmanIntegration, CanBuildChapmanSystem)
{
auto o = micm::Species("O");
Expand All @@ -26,33 +62,32 @@ TEST(ChapmanIntegration, CanBuildChapmanSystem)

micm::Phase gas_phase{ std::vector<micm::Species>{ o, o1d, o2, o3, m, ar, n2, h2o, co2 } };

micm::Process r1 =
micm::Process::create()
.reactants({ o1d, n2 })
.products({ yields(o, 1), yields(n2, 1) })
.rate_constant(micm::ArrheniusRateConstant({ .A_ = 2.15e-11, .B_= 0, .C_ = 110 }))
.phase(gas_phase);

micm::Process r2 =
micm::Process::create()
.reactants({ o1d, o2 })
.products({ yields(o, 1), yields(o2, 1) })
.rate_constant(micm::ArrheniusRateConstant(micm::ArrheniusRateConstantParameters{ .A_ = 3.3e-11, .B_ = 0, .C_ = 55 }))
.phase(gas_phase);

micm::Process r3 =
micm::Process::create()
.reactants({ o, o3 })
.products({ yields(o2, 2) })
.rate_constant(micm::ArrheniusRateConstant(micm::ArrheniusRateConstantParameters{ .A_ = 8e-12, .B_ = 0, .C_ = -2060 }))
.phase(gas_phase);

micm::Process r4 =
micm::Process::create()
.reactants({ o, o2, m })
.products({ yields(o3, 1), yields(m, 1) })
.rate_constant(micm::ArrheniusRateConstant(micm::ArrheniusRateConstantParameters{ .A_ = 6.0e-34, .B_ = 0, .C_ = 2.4 }))
.phase(gas_phase);
micm::Process r1 = micm::Process::create()
.reactants({ o1d, n2 })
.products({ yields(o, 1), yields(n2, 1) })
.rate_constant(micm::ArrheniusRateConstant({ .A_ = 2.15e-11, .B_ = 0, .C_ = 110 }))
.phase(gas_phase);

micm::Process r2 = micm::Process::create()
.reactants({ o1d, o2 })
.products({ yields(o, 1), yields(o2, 1) })
.rate_constant(micm::ArrheniusRateConstant(
micm::ArrheniusRateConstantParameters{ .A_ = 3.3e-11, .B_ = 0, .C_ = 55 }))
.phase(gas_phase);

micm::Process r3 = micm::Process::create()
.reactants({ o, o3 })
.products({ yields(o2, 2) })
.rate_constant(micm::ArrheniusRateConstant(
micm::ArrheniusRateConstantParameters{ .A_ = 8e-12, .B_ = 0, .C_ = -2060 }))
.phase(gas_phase);

micm::Process r4 = micm::Process::create()
.reactants({ o, o2, m })
.products({ yields(o3, 1), yields(m, 1) })
.rate_constant(micm::ArrheniusRateConstant(
micm::ArrheniusRateConstantParameters{ .A_ = 6.0e-34, .B_ = 0, .C_ = 2.4 }))
.phase(gas_phase);

micm::Process photo_1 = micm::Process::create()
.reactants({ o2 })
Expand Down

0 comments on commit d7d5cc1

Please sign in to comment.