diff --git a/examples/example.cpp b/examples/example.cpp index 4349a93d2..9a8f008af 100644 --- a/examples/example.cpp +++ b/examples/example.cpp @@ -111,6 +111,7 @@ int main(const int argc, const char* argv[]) while (elapsed_solve_time < time_step) { + solver.CalculateRateConstants(state); auto result = solver.Solve(time_step - elapsed_solve_time, state); elapsed_solve_time = result.final_time_; if (result.state_ != SolverState::Converged) diff --git a/examples/profile_example.cpp b/examples/profile_example.cpp index 25f380e5b..98ab93125 100644 --- a/examples/profile_example.cpp +++ b/examples/profile_example.cpp @@ -100,6 +100,7 @@ int Run(const char* filepath, const char* initial_conditions, const std::string& MICM_PROFILE_BEGIN_SESSION("Runtime", "Profile-Runtime-" + matrix_ordering_type + ".json"); while (elapsed_solve_time < time_step) { + solver.CalculateRateConstants(state); auto result = solver.Solve(time_step - elapsed_solve_time, state); elapsed_solve_time = result.final_time_; state.variables_ = result.result_; diff --git a/include/micm/process/process.hpp b/include/micm/process/process.hpp index f190315e2..6adabf73b 100644 --- a/include/micm/process/process.hpp +++ b/include/micm/process/process.hpp @@ -82,15 +82,15 @@ namespace micm std::unique_ptr rate_constant_; Phase phase_; - /// @brief Update the solver state rate constants + /// @brief Recalculate the rate constants for each process for the current state /// @param processes The set of processes being solved /// @param state The solver state to update template - requires(!VectorizableDense) static void UpdateState( + requires(!VectorizableDense) static void CalculateRateConstants( const std::vector& processes, State& state); template - requires(VectorizableDense) static void UpdateState( + requires(VectorizableDense) static void CalculateRateConstants( const std::vector& processes, State& state); @@ -149,7 +149,7 @@ namespace micm }; template - requires(!VectorizableDense) void Process::UpdateState( + requires(!VectorizableDense) void Process::CalculateRateConstants( const std::vector& processes, State& state) { @@ -174,7 +174,7 @@ namespace micm } template - requires(VectorizableDense) void Process::UpdateState( + requires(VectorizableDense) void Process::CalculateRateConstants( const std::vector& processes, State& state) { diff --git a/include/micm/solver/backward_euler.hpp b/include/micm/solver/backward_euler.hpp index 94d87105d..e5a3de709 100644 --- a/include/micm/solver/backward_euler.hpp +++ b/include/micm/solver/backward_euler.hpp @@ -37,7 +37,6 @@ namespace micm LinearSolverPolicy linear_solver_; ProcessSetPolicy process_set_; std::vector jacobian_diagonal_elements_; - std::vector processes_; public: /// @brief Solver parameters typename @@ -48,13 +47,11 @@ namespace micm BackwardEulerSolverParameters parameters, LinearSolverPolicy&& linear_solver, ProcessSetPolicy&& process_set, - auto& jacobian, - std::vector& processes) + auto& jacobian) : parameters_(parameters), linear_solver_(std::move(linear_solver)), process_set_(std::move(process_set)), - jacobian_diagonal_elements_(jacobian.DiagonalIndices(0)), - processes_(processes) + jacobian_diagonal_elements_(jacobian.DiagonalIndices(0)) { } diff --git a/include/micm/solver/backward_euler.inl b/include/micm/solver/backward_euler.inl index eacc41ddf..360bf38a5 100644 --- a/include/micm/solver/backward_euler.inl +++ b/include/micm/solver/backward_euler.inl @@ -75,8 +75,6 @@ namespace micm auto Yn1 = state.variables_; auto forcing = state.variables_; - Process::UpdateState(processes_, state); - while (t < time_step) { bool converged = false; diff --git a/include/micm/solver/cuda_rosenbrock.hpp b/include/micm/solver/cuda_rosenbrock.hpp index 7b573ec7a..0c982f79d 100644 --- a/include/micm/solver/cuda_rosenbrock.hpp +++ b/include/micm/solver/cuda_rosenbrock.hpp @@ -74,24 +74,21 @@ namespace micm devstruct_.errors_output_ = nullptr; }; - /// @brief Builds a CUDA Rosenbrock solver for the given system, processes, and solver parameters + /// @brief Builds a CUDA Rosenbrock solver for the given system and solver parameters /// @param parameters Solver parameters /// @param linear_solver Linear solver /// @param process_set Process set /// @param jacobian Jacobian matrix - /// @param processes Vector of processes CudaRosenbrockSolver( RosenbrockSolverParameters parameters, LinearSolverPolicy&& linear_solver, ProcessSetPolicy&& process_set, - auto& jacobian, - std::vector& processes) + auto& jacobian) : RosenbrockSolver( parameters, std::move(linear_solver), std::move(process_set), - jacobian, - processes) + jacobian) { CudaRosenbrockSolverParam hoststruct; // jacobian.GroupVectorSize() is the same as the number of grid cells for the CUDA implementation diff --git a/include/micm/solver/jit_rosenbrock.hpp b/include/micm/solver/jit_rosenbrock.hpp index a757a11c9..6a9599b21 100644 --- a/include/micm/solver/jit_rosenbrock.hpp +++ b/include/micm/solver/jit_rosenbrock.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -31,9 +30,9 @@ namespace micm { + struct JitRosenbrockSolverParameters; /// @brief A Rosenbrock solver with JIT-compiled optimizations - template class JitRosenbrockSolver : public RosenbrockSolver { @@ -65,24 +64,21 @@ namespace micm return *this; } - /// @brief Builds a Rosenbrock solver for the given system, processes, and solver parameters + /// @brief Builds a Rosenbrock solver for the given system and solver parameters /// @param parameters Solver parameters /// @param linear_solver Linear solver /// @param process_set Process set /// @param jacobian Jacobian matrix - /// @param processes Vector of processes JitRosenbrockSolver( RosenbrockSolverParameters parameters, LinearSolverPolicy linear_solver, ProcessSetPolicy process_set, - auto& jacobian, - std::vector& processes) + auto& jacobian) : RosenbrockSolver( parameters, std::move(linear_solver), std::move(process_set), - jacobian, - processes) + jacobian) { this->GenerateAlphaMinusJacobian(jacobian); } diff --git a/include/micm/solver/rosenbrock.hpp b/include/micm/solver/rosenbrock.hpp index cad0d3c26..a32c463fa 100644 --- a/include/micm/solver/rosenbrock.hpp +++ b/include/micm/solver/rosenbrock.hpp @@ -54,7 +54,6 @@ namespace micm LinearSolverPolicy linear_solver_; ProcessSetPolicy process_set_; std::vector jacobian_diagonal_elements_; - std::vector processes_; static constexpr double DELTA_MIN = 1.0e-6; @@ -68,13 +67,11 @@ namespace micm RosenbrockSolverParameters parameters, LinearSolverPolicy linear_solver, ProcessSetPolicy process_set, - auto& jacobian, - std::vector& processes) + auto& jacobian) : parameters_(parameters), linear_solver_(std::move(linear_solver)), process_set_(std::move(process_set)), - jacobian_diagonal_elements_(jacobian.DiagonalIndices(0)), - processes_(processes) + jacobian_diagonal_elements_(jacobian.DiagonalIndices(0)) { } diff --git a/include/micm/solver/rosenbrock.inl b/include/micm/solver/rosenbrock.inl index 8a3d45c99..d1d5845f7 100644 --- a/include/micm/solver/rosenbrock.inl +++ b/include/micm/solver/rosenbrock.inl @@ -34,8 +34,6 @@ namespace micm SolverStats stats; - Process::UpdateState(processes_, state); - K.reserve(parameters_.stages_); for (std::size_t i = 0; i < parameters_.stages_; ++i) K.emplace_back(num_rows, num_cols, 0.0); diff --git a/include/micm/solver/solver.hpp b/include/micm/solver/solver.hpp index 9b3bd4e7b..af8fab8a4 100644 --- a/include/micm/solver/solver.hpp +++ b/include/micm/solver/solver.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include namespace micm { @@ -16,6 +17,7 @@ namespace micm std::size_t number_of_species_; std::size_t number_of_reactions_; StateParameters state_parameters_; + std::vector processes_; public: SolverPolicy solver_; @@ -25,12 +27,14 @@ namespace micm StateParameters state_parameters, std::size_t number_of_grid_cells, std::size_t number_of_species, - std::size_t number_of_reactions) + std::size_t number_of_reactions, + std::vector processes) : solver_(std::move(solver)), number_of_grid_cells_(number_of_grid_cells), number_of_species_(number_of_species), number_of_reactions_(number_of_reactions), - state_parameters_(state_parameters) + state_parameters_(state_parameters), + processes_(std::move(processes)) { } @@ -64,6 +68,11 @@ namespace micm { return StatePolicy(state_parameters_); } + + void CalculateRateConstants(StatePolicy& state) + { + Process::CalculateRateConstants(processes_, state); + } }; diff --git a/include/micm/solver/solver_builder.inl b/include/micm/solver/solver_builder.inl index 297c0aa2b..62cf4e62c 100644 --- a/include/micm/solver/solver_builder.inl +++ b/include/micm/solver/solver_builder.inl @@ -241,11 +241,12 @@ namespace micm return Solver>( SolverPolicy( - this->options_, std::move(linear_solver), std::move(process_set), jacobian, this->reactions_), + this->options_, std::move(linear_solver), std::move(process_set), jacobian), state_parameters, this->number_of_grid_cells_, number_of_species, - this->reactions_.size()); + this->reactions_.size(), + this->reactions_); } } // namespace micm \ No newline at end of file diff --git a/test/integration/analytical_policy.hpp b/test/integration/analytical_policy.hpp index fcc95d783..93036c256 100644 --- a/test/integration/analytical_policy.hpp +++ b/test/integration/analytical_policy.hpp @@ -160,6 +160,7 @@ void test_analytical_troe(BuilderPolicy& builder) for (size_t i_time = 1; i_time < nsteps; ++i_time) { times.push_back(time_step); + solver.CalculateRateConstants(state); // Model results auto result = solver.Solve(time_step, state); EXPECT_EQ(result.state_, (micm::SolverState::Converged)); @@ -303,6 +304,7 @@ void test_analytical_stiff_troe(BuilderPolicy& builder) for (size_t i_time = 1; i_time < nsteps; ++i_time) { times.push_back(time_step); + solver.CalculateRateConstants(state); // Model results auto result = solver.Solve(time_step, state); EXPECT_EQ(result.state_, (micm::SolverState::Converged)); @@ -412,6 +414,7 @@ void test_analytical_photolysis(BuilderPolicy& builder) for (size_t i_time = 1; i_time < nsteps; ++i_time) { times.push_back(time_step); + solver.CalculateRateConstants(state); // Model results auto result = solver.Solve(time_step, state); EXPECT_EQ(result.state_, (micm::SolverState::Converged)); @@ -547,6 +550,7 @@ void test_analytical_stiff_photolysis(BuilderPolicy& builder) for (size_t i_time = 1; i_time < nsteps; ++i_time) { times.push_back(time_step); + solver.CalculateRateConstants(state); // Model results auto result = solver.Solve(time_step, state); EXPECT_EQ(result.state_, (micm::SolverState::Converged)); @@ -668,6 +672,7 @@ void test_analytical_ternary_chemical_activation(BuilderPolicy& builder) for (size_t i_time = 1; i_time < nsteps; ++i_time) { times.push_back(time_step); + solver.CalculateRateConstants(state); // Model results auto result = solver.Solve(time_step, state); EXPECT_EQ(result.state_, (micm::SolverState::Converged)); @@ -811,6 +816,7 @@ void test_analytical_stiff_ternary_chemical_activation(BuilderPolicy& builder) for (size_t i_time = 1; i_time < nsteps; ++i_time) { times.push_back(time_step); + solver.CalculateRateConstants(state); // Model results auto result = solver.Solve(time_step, state); EXPECT_EQ(result.state_, (micm::SolverState::Converged)); @@ -925,6 +931,7 @@ void test_analytical_tunneling(BuilderPolicy& builder) for (size_t i_time = 1; i_time < nsteps; ++i_time) { times.push_back(time_step); + solver.CalculateRateConstants(state); // Model results auto result = solver.Solve(time_step, state); EXPECT_EQ(result.state_, (micm::SolverState::Converged)); @@ -1055,6 +1062,7 @@ void test_analytical_stiff_tunneling(BuilderPolicy& builder) for (size_t i_time = 1; i_time < nsteps; ++i_time) { times.push_back(time_step); + solver.CalculateRateConstants(state); // Model results auto result = solver.Solve(time_step, state); EXPECT_EQ(result.state_, (micm::SolverState::Converged)); @@ -1157,6 +1165,7 @@ void test_analytical_arrhenius(BuilderPolicy& builder) times.push_back(0); for (size_t i_time = 1; i_time < nsteps; ++i_time) { + solver.CalculateRateConstants(state); // Model results auto result = solver.Solve(time_step, state); EXPECT_EQ(result.state_, (micm::SolverState::Converged)); @@ -1289,6 +1298,7 @@ void test_analytical_stiff_arrhenius(BuilderPolicy& builder) for (size_t i_time = 1; i_time < nsteps; ++i_time) { times.push_back(time_step); + solver.CalculateRateConstants(state); // Model results auto result = solver.Solve(time_step, state); EXPECT_EQ(result.state_, (micm::SolverState::Converged)); @@ -1417,6 +1427,7 @@ void test_analytical_branched(BuilderPolicy& builder) for (size_t i_time = 1; i_time < nsteps; ++i_time) { times.push_back(time_step); + solver.CalculateRateConstants(state); // Model results auto result = solver.Solve(time_step, state); EXPECT_EQ(result.state_, (micm::SolverState::Converged)); @@ -1577,6 +1588,7 @@ void test_analytical_stiff_branched(BuilderPolicy& builder) for (size_t i_time = 1; i_time < nsteps; ++i_time) { times.push_back(time_step); + solver.CalculateRateConstants(state); // Model results auto result = solver.Solve(time_step, state); EXPECT_EQ(result.state_, (micm::SolverState::Converged)); @@ -1708,6 +1720,7 @@ void test_analytical_robertson(BuilderPolicy& builder) { double solve_time = time_step + i_time * time_step; times.push_back(solve_time); + solver.CalculateRateConstants(state); // Model results double actual_solve = 0; while (actual_solve < time_step) diff --git a/test/integration/analytical_rosenbrock.cpp b/test/integration/analytical_rosenbrock.cpp index 1eb84727d..7199d3a09 100644 --- a/test/integration/analytical_rosenbrock.cpp +++ b/test/integration/analytical_rosenbrock.cpp @@ -183,6 +183,7 @@ TEST(AnalyticalExamples, Oregonator) { double solve_time = time_step + i_time * time_step; times.push_back(solve_time); + solver.CalculateRateConstants(state); // Model results double actual_solve = 0; while (actual_solve < time_step) @@ -329,6 +330,7 @@ TEST(AnalyticalExamples, Oregonator2) { double solve_time = time_step + i_time * time_step; times.push_back(solve_time); + solver.CalculateRateConstants(state); // Model results double actual_solve = 0; while (actual_solve < time_step) @@ -471,6 +473,7 @@ TEST(AnalyticalExamples, HIRES) { double solve_time = time_step + i_time * time_step; times.push_back(solve_time); + solver.CalculateRateConstants(state); // Model results double actual_solve = 0; while (actual_solve < time_step) @@ -570,6 +573,7 @@ TEST(AnalyticalExamples, E5) { double solve_time = time_step + i_time * time_step; times.push_back(solve_time); + solver.CalculateRateConstants(state); // Model results double actual_solve = 0; while (actual_solve < time_step) diff --git a/test/integration/analytical_surface_rxn_policy.hpp b/test/integration/analytical_surface_rxn_policy.hpp index 84e3b5887..8607bf78d 100644 --- a/test/integration/analytical_surface_rxn_policy.hpp +++ b/test/integration/analytical_surface_rxn_policy.hpp @@ -98,6 +98,7 @@ void test_analytical_surface_rxn(BuilderPolicy& builder) for (int i = 1; i <= nstep; ++i) { double elapsed_solve_time = 0; + solver.CalculateRateConstants(state); // first iteration auto result = solver.Solve(time_step - elapsed_solve_time, state); diff --git a/test/integration/chapman.cpp b/test/integration/chapman.cpp index f58d51517..6a3894870 100644 --- a/test/integration/chapman.cpp +++ b/test/integration/chapman.cpp @@ -78,6 +78,7 @@ TEST(ChapmanIntegration, CanBuildChapmanSystemUsingConfig) for (double t{}; t < 100; ++t) { state.SetCustomRateParameters(photo_rates); + solver.CalculateRateConstants(state); auto result = solver.Solve(30.0, state); // output state } @@ -163,6 +164,7 @@ TEST(ChapmanIntegration, CanBuildChapmanSystem) for (double t{}; t < 100; ++t) { state.custom_rate_parameters_[0] = photo_rates; + solver.CalculateRateConstants(state); auto result = solver.Solve(30.0, state); // output state } diff --git a/test/integration/cmake/test_micm.cpp b/test/integration/cmake/test_micm.cpp index 957c82a94..253af527b 100644 --- a/test/integration/cmake/test_micm.cpp +++ b/test/integration/cmake/test_micm.cpp @@ -76,6 +76,7 @@ int main() while (elapsed_solve_time < time_step) { + solver.CalculateRateConstants(state); auto result = solver.Solve(time_step - elapsed_solve_time, state); elapsed_solve_time = result.final_time_; } diff --git a/test/integration/integrated_reaction_rates.cpp b/test/integration/integrated_reaction_rates.cpp index da58d3fdb..9308e98c4 100644 --- a/test/integration/integrated_reaction_rates.cpp +++ b/test/integration/integrated_reaction_rates.cpp @@ -72,6 +72,7 @@ TEST(ChapmanIntegration, CanBuildChapmanSystem) { state.SetCustomRateParameter("r2", 0.0); } + solver.CalculateRateConstants(state); std::cout << state.variables_[0][irr1_idx] << " " << state.variables_[0][irr2_idx] << std::endl; double irr1 = state.variables_[0][irr1_idx]; double irr2 = state.variables_[0][irr2_idx]; diff --git a/test/integration/terminator.hpp b/test/integration/terminator.hpp index 12fa3f89e..6160902e2 100644 --- a/test/integration/terminator.hpp +++ b/test/integration/terminator.hpp @@ -84,6 +84,7 @@ void TestTerminator( state.conditions_[i_cell].air_density_ = 42.0; // mol m-3 } state.SetCustomRateParameters(custom_rate_constants); + solver.CalculateRateConstants(state); double dt = 30.0; auto result = solver.Solve(dt, state); diff --git a/test/regression/RosenbrockChapman/regression_test_p_force_policy.hpp b/test/regression/RosenbrockChapman/regression_test_p_force_policy.hpp index 6bf2e9214..f836289c3 100644 --- a/test/regression/RosenbrockChapman/regression_test_p_force_policy.hpp +++ b/test/regression/RosenbrockChapman/regression_test_p_force_policy.hpp @@ -29,7 +29,7 @@ void testRateConstants(SolverPolicy& solver) state.conditions_[2].temperature_ = 299.31; // [K] state.conditions_[2].pressure_ = 101398.0; // [Pa] - micm::Process::UpdateState(solver.solver_.processes_, state); + solver.CalculateRateConstants(state); for (size_t i{}; i < 3; ++i) { diff --git a/test/regression/RosenbrockChapman/regression_test_solve_policy.hpp b/test/regression/RosenbrockChapman/regression_test_solve_policy.hpp index 65160b875..e1fc93195 100644 --- a/test/regression/RosenbrockChapman/regression_test_solve_policy.hpp +++ b/test/regression/RosenbrockChapman/regression_test_solve_policy.hpp @@ -40,6 +40,7 @@ void testSolve(SolverPolicy& solver, double relative_tolerance = 1.0e-8) abs_tol *= 1.0e-12; // run solvers + solver.CalculateRateConstants(state); auto results = solver.Solve(500.0, state); micm::ChapmanODESolver::SolverResult fixed_results[3]; for (int i = 0; i < 3; ++i) diff --git a/test/tutorial/test_README_example.cpp b/test/tutorial/test_README_example.cpp index 9bf6ad53d..042947f50 100644 --- a/test/tutorial/test_README_example.cpp +++ b/test/tutorial/test_README_example.cpp @@ -45,6 +45,7 @@ int main(const int argc, const char *argv[]) state.PrintHeader(); for (int i = 0; i < 10; ++i) { + solver.CalculateRateConstants(state); auto result = solver.Solve(500.0, state); state.PrintState(i * 500); } diff --git a/test/tutorial/test_jit_tutorial.cpp b/test/tutorial/test_jit_tutorial.cpp index baba73daa..96d88177c 100644 --- a/test/tutorial/test_jit_tutorial.cpp +++ b/test/tutorial/test_jit_tutorial.cpp @@ -48,6 +48,7 @@ auto run_solver(auto& solver) while (elapsed_solve_time < time_step) { auto start = std::chrono::high_resolution_clock::now(); + solver.CalculateRateConstants(state); auto result = solver.Solve(time_step - elapsed_solve_time, state); auto end = std::chrono::high_resolution_clock::now(); total_solve_time += std::chrono::duration_cast(end - start); diff --git a/test/tutorial/test_multiple_grid_cells.cpp b/test/tutorial/test_multiple_grid_cells.cpp index 1119f3932..173a62440 100644 --- a/test/tutorial/test_multiple_grid_cells.cpp +++ b/test/tutorial/test_multiple_grid_cells.cpp @@ -84,6 +84,7 @@ int main() while (elapsed_solve_time < time_step) { + solver.CalculateRateConstants(state); auto result = solver.Solve(time_step - elapsed_solve_time, state); elapsed_solve_time = result.final_time_; } diff --git a/test/tutorial/test_openmp.cpp b/test/tutorial/test_openmp.cpp index f0325eddb..e2b4aecf5 100644 --- a/test/tutorial/test_openmp.cpp +++ b/test/tutorial/test_openmp.cpp @@ -51,7 +51,8 @@ std::vector run_solver_on_thread_with_own_state(auto& solver, auto& stat for (int i = 0; i < 10; ++i) { double elapsed_solve_time = 0; - + solver.CalculateRateConstants(state); + while (elapsed_solve_time < time_step) { auto result = solver.Solve(time_step - elapsed_solve_time, state); diff --git a/test/tutorial/test_rate_constants_no_user_defined_by_hand.cpp b/test/tutorial/test_rate_constants_no_user_defined_by_hand.cpp index 800706179..f105da91b 100644 --- a/test/tutorial/test_rate_constants_no_user_defined_by_hand.cpp +++ b/test/tutorial/test_rate_constants_no_user_defined_by_hand.cpp @@ -133,6 +133,7 @@ int main(const int argc, const char* argv[]) // so we need to track how much time the solver was able to integrate for and continue // solving until we finish double elapsed_solve_time = 0; + solver.CalculateRateConstants(state); while (elapsed_solve_time < time_step) { diff --git a/test/tutorial/test_rate_constants_no_user_defined_with_config.cpp b/test/tutorial/test_rate_constants_no_user_defined_with_config.cpp index 2937add8c..873c7f28b 100644 --- a/test/tutorial/test_rate_constants_no_user_defined_with_config.cpp +++ b/test/tutorial/test_rate_constants_no_user_defined_with_config.cpp @@ -75,6 +75,7 @@ int main(const int argc, const char* argv[]) // so we need to track how much time the solver was able to integrate for and continue // solving until we finish double elapsed_solve_time = 0; + solver.CalculateRateConstants(state); while (elapsed_solve_time < time_step) { diff --git a/test/tutorial/test_rate_constants_user_defined_by_hand.cpp b/test/tutorial/test_rate_constants_user_defined_by_hand.cpp index d7277ff23..7ded8f81a 100644 --- a/test/tutorial/test_rate_constants_user_defined_by_hand.cpp +++ b/test/tutorial/test_rate_constants_user_defined_by_hand.cpp @@ -159,6 +159,7 @@ int main(const int argc, const char* argv[]) double elapsed_solve_time = 0; // this rate is updated at each time step and would typically vary with time state.SetCustomRateParameter("my photolysis rate", photo_rate); + solver.CalculateRateConstants(state); while (elapsed_solve_time < time_step) { diff --git a/test/tutorial/test_rate_constants_user_defined_with_config.cpp b/test/tutorial/test_rate_constants_user_defined_with_config.cpp index 15eaf8bc6..7421d645c 100644 --- a/test/tutorial/test_rate_constants_user_defined_with_config.cpp +++ b/test/tutorial/test_rate_constants_user_defined_with_config.cpp @@ -84,6 +84,7 @@ int main(const int argc, const char* argv[]) double elapsed_solve_time = 0; // This rate is updated at each time step and would typically vary with time state.SetCustomRateParameter("PHOTO.my photolysis rate", photo_rate); + solver.CalculateRateConstants(state); while (elapsed_solve_time < time_step) { diff --git a/test/tutorial/test_solver_configuration.cpp b/test/tutorial/test_solver_configuration.cpp index d6f74b4d3..f13125c25 100644 --- a/test/tutorial/test_solver_configuration.cpp +++ b/test/tutorial/test_solver_configuration.cpp @@ -52,6 +52,7 @@ void test_solver_type(auto& solver) while (elapsed_solve_time < time_step) { auto start = std::chrono::high_resolution_clock::now(); + solver.CalculateRateConstants(state); auto result = solver.Solve(time_step - elapsed_solve_time, state); auto end = std::chrono::high_resolution_clock::now(); diff --git a/test/tutorial/test_solver_results.cpp b/test/tutorial/test_solver_results.cpp index c59d7cb94..5c189de67 100644 --- a/test/tutorial/test_solver_results.cpp +++ b/test/tutorial/test_solver_results.cpp @@ -67,6 +67,7 @@ int main() state.conditions_[cell].pressure_ = pressure; state.conditions_[cell].air_density_ = air_density; } + solver.CalculateRateConstants(state); // choose a timestep and print the initial state double time_step = 200; // s diff --git a/test/tutorial/test_vectorized_matrix_solver.cpp b/test/tutorial/test_vectorized_matrix_solver.cpp index be05bb76c..29538e7d5 100644 --- a/test/tutorial/test_vectorized_matrix_solver.cpp +++ b/test/tutorial/test_vectorized_matrix_solver.cpp @@ -39,6 +39,7 @@ void solve(auto& solver, auto& state, std::size_t number_of_grid_cells) for (int i = 0; i < 10 && solver_state == SolverState::Converged; ++i) { double elapsed_solve_time = 0; + solver.CalculateRateConstants(state); while (elapsed_solve_time < time_step && solver_state != SolverState::Converged) { auto result = solver.Solve(time_step - elapsed_solve_time, state); diff --git a/test/unit/openmp/run_solver.hpp b/test/unit/openmp/run_solver.hpp index fc0c55cca..502dcb52c 100644 --- a/test/unit/openmp/run_solver.hpp +++ b/test/unit/openmp/run_solver.hpp @@ -32,6 +32,7 @@ std::vector run_solver_on_thread_with_own_state(auto& solver, auto& stat for (int i = 0; i < 10; ++i) { double elapsed_solve_time = 0; + solver.CalculateRateConstants(state); while (elapsed_solve_time < time_step) { diff --git a/test/unit/process/test_process.cpp b/test/unit/process/test_process.cpp index b4a7e4f01..09053a914 100644 --- a/test/unit/process/test_process.cpp +++ b/test/unit/process/test_process.cpp @@ -63,7 +63,7 @@ void testProcessUpdateState(const std::size_t number_of_grid_cells) param_iter += rc3.SizeCustomParameters(); } - micm::Process::UpdateState(processes, state); + micm::Process::CalculateRateConstants(processes, state); for (std::size_t i_cell = 0; i_cell < number_of_grid_cells; ++i_cell) for (std::size_t i_rxn = 0; i_rxn < processes.size(); ++i_rxn) diff --git a/test/unit/solver/test_backward_euler.cpp b/test/unit/solver/test_backward_euler.cpp index 17596d673..f797391de 100644 --- a/test/unit/solver/test_backward_euler.cpp +++ b/test/unit/solver/test_backward_euler.cpp @@ -48,6 +48,7 @@ TEST(BackwardEuler, CanCallSolve) state.conditions_[0].temperature_ = 272.5; state.conditions_[0].pressure_ = 101253.3; state.conditions_[0].air_density_ = 1e6; + be.CalculateRateConstants(state); EXPECT_NO_THROW(auto result = be.Solve(time_step, state)); } diff --git a/test/unit/solver/test_jit_rosenbrock.cpp b/test/unit/solver/test_jit_rosenbrock.cpp index 3a34de227..ede42062b 100644 --- a/test/unit/solver/test_jit_rosenbrock.cpp +++ b/test/unit/solver/test_jit_rosenbrock.cpp @@ -115,6 +115,7 @@ void run_solver(auto& solver) for (int i = 0; i < 10; ++i) { double elapsed_solve_time = 0; + solver.CalculateRateConstants(state); while (elapsed_solve_time < time_step) {