diff --git a/include/micm/solver/backward_euler.hpp b/include/micm/solver/backward_euler.hpp index cfea6bbe4..55781650c 100644 --- a/include/micm/solver/backward_euler.hpp +++ b/include/micm/solver/backward_euler.hpp @@ -5,8 +5,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/include/micm/solver/backward_euler.inl b/include/micm/solver/backward_euler.inl index ceeccad16..28ebecefd 100644 --- a/include/micm/solver/backward_euler.inl +++ b/include/micm/solver/backward_euler.inl @@ -152,8 +152,7 @@ namespace micm do { // changes that are much smaller than the tolerance are negligible and we assume can be accepted - converged = (std::abs(*forcing_iter) <= small) || - (std::abs(*forcing_iter) <= *abs_tol_iter) || + converged = (std::abs(*forcing_iter) <= small) || (std::abs(*forcing_iter) <= *abs_tol_iter) || (std::abs(*forcing_iter) <= parameters_.relative_tolerance_ * std::abs(*yn1_iter)); ++forcing_iter, ++yn1_iter, ++abs_tol_iter; } while (converged && forcing_iter != forcing.end()); diff --git a/include/micm/solver/backward_euler_solver_parameters.hpp b/include/micm/solver/backward_euler_solver_parameters.hpp index 46d1e1916..a68528478 100644 --- a/include/micm/solver/backward_euler_solver_parameters.hpp +++ b/include/micm/solver/backward_euler_solver_parameters.hpp @@ -9,7 +9,7 @@ namespace micm { - + template class BackwardEuler; diff --git a/include/micm/solver/cuda_rosenbrock.hpp b/include/micm/solver/cuda_rosenbrock.hpp index 12f271c2e..2033e06a0 100644 --- a/include/micm/solver/cuda_rosenbrock.hpp +++ b/include/micm/solver/cuda_rosenbrock.hpp @@ -80,11 +80,7 @@ namespace micm LinearSolverPolicy&& linear_solver, RatesPolicy&& rates, auto& jacobian) - : RosenbrockSolver( - parameters, - std::move(linear_solver), - std::move(rates), - jacobian) + : RosenbrockSolver(parameters, std::move(linear_solver), std::move(rates), jacobian) { CudaRosenbrockSolverParam hoststruct; // jacobian.GroupVectorSize() is the same as the number of grid cells for the CUDA implementation @@ -107,9 +103,9 @@ namespace micm }; /// @brief @brief Computes [alpha * I - jacobian] on the GPU - /// @tparam SparseMatrixPolicy + /// @tparam SparseMatrixPolicy /// @param jacobian Jacobian matrix - /// @param alpha + /// @param alpha template void AlphaMinusJacobian(SparseMatrixPolicy& jacobian, const double& alpha) const requires(CudaMatrix&& VectorizableSparse) @@ -120,9 +116,9 @@ namespace micm } /// @brief @brief Computes [alpha * I - jacobian] on the CPU - /// @tparam SparseMatrixPolicy + /// @tparam SparseMatrixPolicy /// @param jacobian Jacobian matrix - /// @param alpha + /// @param alpha template void AlphaMinusJacobian(SparseMatrixPolicy& jacobian, const double& alpha) const requires(!CudaMatrix) @@ -137,11 +133,8 @@ namespace micm /// @param errors The computed errors /// @return The scaled norm of the errors template - double NormalizedError( - const DenseMatrixPolicy& y_old, - const DenseMatrixPolicy& y_new, - const DenseMatrixPolicy& errors) const - requires(CudaMatrix&& VectorizableDense) + double NormalizedError(const DenseMatrixPolicy& y_old, const DenseMatrixPolicy& y_new, const DenseMatrixPolicy& errors) + const requires(CudaMatrix&& VectorizableDense) { // At this point, it does not matter which handle we use; may revisit it when we have a multi-node-multi-GPU test return micm::cuda::NormalizedErrorDriver( @@ -154,16 +147,14 @@ namespace micm } /// @brief Computes the scaled norm of the vector errors on the CPU - /// @tparam DenseMatrixPolicy + /// @tparam DenseMatrixPolicy /// @param y_old The original vector /// @param y_new The new vector /// @param errors The computed errors /// @return The scaled norm of the errors template - double NormalizedError( - const DenseMatrixPolicy& y_old, - const DenseMatrixPolicy& y_new, - const DenseMatrixPolicy& errors) const requires(!CudaMatrix) + double NormalizedError(const DenseMatrixPolicy& y_old, const DenseMatrixPolicy& y_new, const DenseMatrixPolicy& errors) + const requires(!CudaMatrix) { return NormalizedErrorDriver(y_old, y_new, errors); } diff --git a/include/micm/solver/cuda_solver_builder.hpp b/include/micm/solver/cuda_solver_builder.hpp index 0ae9c8277..7d6560f23 100644 --- a/include/micm/solver/cuda_solver_builder.hpp +++ b/include/micm/solver/cuda_solver_builder.hpp @@ -21,5 +21,10 @@ namespace micm /// /// GPU solvers only work with vector-ordered matrices template - using CudaSolverBuilder = SolverBuilder, CudaSparseMatrix>, CudaProcessSet, CudaLinearSolver>, CudaLuDecomposition>>; -} // namespace micm \ No newline at end of file + using CudaSolverBuilder = SolverBuilder< + SolverParametersPolicy, + CudaDenseMatrix, + CudaSparseMatrix>, + CudaProcessSet, + CudaLinearSolver>, CudaLuDecomposition>>; +} // namespace micm \ No newline at end of file diff --git a/include/micm/solver/cuda_solver_parameters.hpp b/include/micm/solver/cuda_solver_parameters.hpp index 3b1c48ecd..a340c12e3 100644 --- a/include/micm/solver/cuda_solver_parameters.hpp +++ b/include/micm/solver/cuda_solver_parameters.hpp @@ -5,22 +5,23 @@ #pragma once #include "rosenbrock_solver_parameters.hpp" -#include + #include +#include namespace micm { - /// @brief Parameters for the CUDA Rosenbrock solver - struct CudaRosenbrockSolverParameters : public RosenbrockSolverParameters - { - template - using SolverType = CudaRosenbrockSolver; + /// @brief Parameters for the CUDA Rosenbrock solver + struct CudaRosenbrockSolverParameters : public RosenbrockSolverParameters + { + template + using SolverType = CudaRosenbrockSolver; - /// @brief Constructor from base class - /// @param base - CudaRosenbrockSolverParameters(const RosenbrockSolverParameters& base) - : RosenbrockSolverParameters(base) - { - } - }; -} \ No newline at end of file + /// @brief Constructor from base class + /// @param base + CudaRosenbrockSolverParameters(const RosenbrockSolverParameters& base) + : RosenbrockSolverParameters(base) + { + } + }; +} // namespace micm \ No newline at end of file diff --git a/include/micm/solver/jit_rosenbrock.hpp b/include/micm/solver/jit_rosenbrock.hpp index d412c1f18..2f8f7e8ad 100644 --- a/include/micm/solver/jit_rosenbrock.hpp +++ b/include/micm/solver/jit_rosenbrock.hpp @@ -37,7 +37,6 @@ namespace micm FuncPtr alpha_minus_jacobian_ = nullptr; public: - /// @brief Solver parameters typename using ParametersType = JitRosenbrockSolverParameters; @@ -70,11 +69,7 @@ namespace micm LinearSolverPolicy linear_solver, RatesPolicy rates, auto& jacobian) - : RosenbrockSolver( - parameters, - std::move(linear_solver), - std::move(rates), - jacobian) + : RosenbrockSolver(parameters, std::move(linear_solver), std::move(rates), jacobian) { this->GenerateAlphaMinusJacobian(jacobian); } diff --git a/include/micm/solver/jit_solver_builder.hpp b/include/micm/solver/jit_solver_builder.hpp index f04b903d0..45853ab94 100644 --- a/include/micm/solver/jit_solver_builder.hpp +++ b/include/micm/solver/jit_solver_builder.hpp @@ -5,9 +5,10 @@ #pragma once #include "solver_builder.hpp" + +#include #include #include -#include namespace micm { @@ -17,11 +18,10 @@ namespace micm /// /// JIT-compiled solvers only work with vector-ordered matrices template - using JitSolverBuilder = SolverBuilder, - SparseMatrix>, - JitProcessSet, - JitLinearSolver>, - JitLuDecomposition>>; -} // namespace micm \ No newline at end of file + using JitSolverBuilder = SolverBuilder< + SolverParametersPolicy, + VectorMatrix, + SparseMatrix>, + JitProcessSet, + JitLinearSolver>, JitLuDecomposition>>; +} // namespace micm \ No newline at end of file diff --git a/include/micm/solver/jit_solver_parameters.hpp b/include/micm/solver/jit_solver_parameters.hpp index a2cf93091..32e9dbcf0 100644 --- a/include/micm/solver/jit_solver_parameters.hpp +++ b/include/micm/solver/jit_solver_parameters.hpp @@ -5,23 +5,23 @@ #pragma once #include "rosenbrock_solver_parameters.hpp" -#include + #include +#include namespace micm { - /// @brief Parameters for the JIT Rosenbrock solver - struct JitRosenbrockSolverParameters : public RosenbrockSolverParameters - { - template - using SolverType = JitRosenbrockSolver; - - /// @brief Constructor from base class - /// @param base - JitRosenbrockSolverParameters(const RosenbrockSolverParameters& base) - : RosenbrockSolverParameters(base) - { - } + /// @brief Parameters for the JIT Rosenbrock solver + struct JitRosenbrockSolverParameters : public RosenbrockSolverParameters + { + template + using SolverType = JitRosenbrockSolver; - }; -} \ No newline at end of file + /// @brief Constructor from base class + /// @param base + JitRosenbrockSolverParameters(const RosenbrockSolverParameters& base) + : RosenbrockSolverParameters(base) + { + } + }; +} // namespace micm \ No newline at end of file diff --git a/include/micm/solver/lu_decomposition.hpp b/include/micm/solver/lu_decomposition.hpp index 85266f7c5..b0cae29b5 100644 --- a/include/micm/solver/lu_decomposition.hpp +++ b/include/micm/solver/lu_decomposition.hpp @@ -14,7 +14,7 @@ namespace t.NumColumns(); t.NumberOfBlocks(); }; -} +} // namespace namespace micm { @@ -93,21 +93,18 @@ namespace micm /// @brief Construct an LU decomposition algorithm for a given sparse matrix /// @param matrix Sparse matrix template - requires(SparseMatrixConcept) - LuDecomposition(const SparseMatrixPolicy& matrix); + requires(SparseMatrixConcept) LuDecomposition(const SparseMatrixPolicy& matrix); /// @brief Create an LU decomposition algorithm for a given sparse matrix policy /// @param matrix Sparse matrix template - requires(SparseMatrixConcept) - static LuDecomposition Create(const SparseMatrixPolicy& matrix); + requires(SparseMatrixConcept) static LuDecomposition Create(const SparseMatrixPolicy& matrix); /// @brief Create sparse L and U matrices for a given A matrix /// @param A Sparse matrix that will be decomposed /// @return L and U Sparse matrices template - requires(SparseMatrixConcept) - static std::pair GetLUMatrices( + requires(SparseMatrixConcept) static std::pair GetLUMatrices( const SparseMatrixPolicy& A, typename SparseMatrixPolicy::value_type initial_value); @@ -116,8 +113,10 @@ namespace micm /// @param L The lower triangular matrix created by decomposition /// @param U The upper triangular matrix created by decomposition template - requires(SparseMatrixConcept) - void Decompose(const SparseMatrixPolicy& A, SparseMatrixPolicy& L, SparseMatrixPolicy& U) const; + requires(SparseMatrixConcept) void Decompose( + const SparseMatrixPolicy& A, + SparseMatrixPolicy& L, + SparseMatrixPolicy& U) const; /// @brief Perform an LU decomposition on a given A matrix /// @param A Sparse matrix to decompose @@ -141,8 +140,7 @@ namespace micm /// @brief Initialize arrays for the LU decomposition /// @param A Sparse matrix to decompose template - requires(SparseMatrixConcept) - void Initialize(const SparseMatrixPolicy& matrix, auto initial_value); + requires(SparseMatrixConcept) void Initialize(const SparseMatrixPolicy& matrix, auto initial_value); }; } // namespace micm diff --git a/include/micm/solver/lu_decomposition.inl b/include/micm/solver/lu_decomposition.inl index 450fa093a..306fab562 100644 --- a/include/micm/solver/lu_decomposition.inl +++ b/include/micm/solver/lu_decomposition.inl @@ -9,15 +9,14 @@ namespace micm } template - requires(SparseMatrixConcept) - inline LuDecomposition::LuDecomposition(const SparseMatrixPolicy& matrix) + requires(SparseMatrixConcept) inline LuDecomposition::LuDecomposition(const SparseMatrixPolicy& matrix) { Initialize(matrix, typename SparseMatrixPolicy::value_type()); } template - requires(SparseMatrixConcept) - inline LuDecomposition LuDecomposition::Create(const SparseMatrixPolicy& matrix) + requires(SparseMatrixConcept) inline LuDecomposition LuDecomposition::Create( + const SparseMatrixPolicy& matrix) { LuDecomposition lu_decomp{}; lu_decomp.Initialize(matrix, typename SparseMatrixPolicy::value_type()); @@ -25,8 +24,9 @@ namespace micm } template - requires(SparseMatrixConcept) - inline void LuDecomposition::Initialize(const SparseMatrixPolicy& matrix, auto initial_value) + requires(SparseMatrixConcept) inline void LuDecomposition::Initialize( + const SparseMatrixPolicy& matrix, + auto initial_value) { MICM_PROFILE_FUNCTION(); @@ -102,10 +102,9 @@ namespace micm } template - requires(SparseMatrixConcept) - inline std::pair LuDecomposition::GetLUMatrices( - const SparseMatrixPolicy& A, - typename SparseMatrixPolicy::value_type initial_value) + requires( + SparseMatrixConcept) inline std::pair LuDecomposition:: + GetLUMatrices(const SparseMatrixPolicy& A, typename SparseMatrixPolicy::value_type initial_value) { MICM_PROFILE_FUNCTION(); @@ -165,8 +164,10 @@ namespace micm } template - requires(SparseMatrixConcept) - inline void LuDecomposition::Decompose(const SparseMatrixPolicy& A, SparseMatrixPolicy& L, SparseMatrixPolicy& U) const + requires(SparseMatrixConcept) inline void LuDecomposition::Decompose( + const SparseMatrixPolicy& A, + SparseMatrixPolicy& L, + SparseMatrixPolicy& U) const { bool is_singular = false; Decompose(A, L, U, is_singular); diff --git a/include/micm/solver/rosenbrock.hpp b/include/micm/solver/rosenbrock.hpp index eae6e9870..a661b224a 100644 --- a/include/micm/solver/rosenbrock.hpp +++ b/include/micm/solver/rosenbrock.hpp @@ -15,12 +15,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include @@ -104,12 +104,12 @@ namespace micm /// @param stats The solver stats /// @param state The state void LinearFactor( - double& H, - const double gamma, - bool& singular, - const auto& number_densities, - SolverStats& stats, - auto& state); + double& H, + const double gamma, + bool& singular, + const auto& number_densities, + SolverStats& stats, + auto& state); /// @brief Computes the scaled norm of the vector errors /// @param y the original vector @@ -117,15 +117,11 @@ namespace micm /// @param errors The computed errors /// @return template - double NormalizedError( - const DenseMatrixPolicy& y, - const DenseMatrixPolicy& y_new, - const DenseMatrixPolicy& errors) const requires(!VectorizableDense); + double NormalizedError(const DenseMatrixPolicy& y, const DenseMatrixPolicy& y_new, const DenseMatrixPolicy& errors) const + requires(!VectorizableDense); template - double NormalizedError( - const DenseMatrixPolicy& y, - const DenseMatrixPolicy& y_new, - const DenseMatrixPolicy& errors) const requires(VectorizableDense); + double NormalizedError(const DenseMatrixPolicy& y, const DenseMatrixPolicy& y_new, const DenseMatrixPolicy& errors) const + requires(VectorizableDense); }; } // namespace micm diff --git a/include/micm/solver/rosenbrock.inl b/include/micm/solver/rosenbrock.inl index ccab1e9ed..46f6fa50b 100644 --- a/include/micm/solver/rosenbrock.inl +++ b/include/micm/solver/rosenbrock.inl @@ -4,9 +4,7 @@ namespace micm { template - inline SolverResult RosenbrockSolver::Solve( - double time_step, - auto& state) noexcept + inline SolverResult RosenbrockSolver::Solve(double time_step, auto& state) noexcept { MICM_PROFILE_FUNCTION(); using MatrixPolicy = decltype(state.variables_); diff --git a/include/micm/solver/rosenbrock_solver_parameters.hpp b/include/micm/solver/rosenbrock_solver_parameters.hpp index d5a19f583..6ae0a6b6f 100644 --- a/include/micm/solver/rosenbrock_solver_parameters.hpp +++ b/include/micm/solver/rosenbrock_solver_parameters.hpp @@ -63,7 +63,7 @@ namespace micm std::vector absolute_tolerance_; double relative_tolerance_{ 1e-6 }; - bool check_singularity_{ false }; // Check for singular A matrix in linear solve of A x = b + bool check_singularity_{ false }; // Check for singular A matrix in linear solve of A x = b // Print RosenbrockSolverParameters to console void Print() const; diff --git a/include/micm/solver/solver.hpp b/include/micm/solver/solver.hpp index c53c7f171..22639bee6 100644 --- a/include/micm/solver/solver.hpp +++ b/include/micm/solver/solver.hpp @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 #pragma once -#include #include +#include namespace micm { @@ -73,5 +73,4 @@ namespace micm } }; - } // namespace micm diff --git a/include/micm/solver/solver_builder.hpp b/include/micm/solver/solver_builder.hpp index 29b5ed70c..cba228170 100644 --- a/include/micm/solver/solver_builder.hpp +++ b/include/micm/solver/solver_builder.hpp @@ -28,7 +28,12 @@ namespace micm /// @tparam SparseMatrixPolicy Policy for sparse matrices /// @tparam RatesPolicy Calculator of forcing and Jacobian terms /// @tparam LinearSolverPolicy Policy for the linear solver - template + template< + class SolverParametersPolicy, + class DenseMatrixPolicy, + class SparseMatrixPolicy, + class RatesPolicy, + class LinearSolverPolicy> class SolverBuilder { protected: @@ -42,7 +47,6 @@ namespace micm bool valid_reactions_ = false; public: - SolverBuilder() = delete; SolverBuilder(const SolverParametersPolicy& options) @@ -98,15 +102,22 @@ namespace micm /// @brief Returns the labels of the custom parameters /// @return The labels of the custom parameters std::vector GetCustomParameterLabels() const; - }; /// @brief Builder of CPU-based general solvers /// @tparam SolverParametersPolicy Parameters for the ODE solver /// @tparam DenseMatrixPolicy Policy for dense matrices /// @tparam SparseMatrixPolicy Policy for sparse matrices - template, class SparseMatrixPolicy = SparseMatrix> - using CpuSolverBuilder = SolverBuilder>; + template< + class SolverParametersPolicy, + class DenseMatrixPolicy = Matrix, + class SparseMatrixPolicy = SparseMatrix> + using CpuSolverBuilder = SolverBuilder< + SolverParametersPolicy, + DenseMatrixPolicy, + SparseMatrixPolicy, + ProcessSet, + LinearSolver>; } // namespace micm diff --git a/include/micm/solver/solver_builder.inl b/include/micm/solver/solver_builder.inl index 14eb2106c..8dda24e62 100644 --- a/include/micm/solver/solver_builder.inl +++ b/include/micm/solver/solver_builder.inl @@ -3,10 +3,10 @@ enum class MicmSolverBuilderErrc { - UnusedSpecies = 1, // Unused species present in the chemical system - MissingChemicalSystem = 2, // Missing chemical system - MissingReactions = 3, // Missing processes - MissingChemicalSpecies = 4 // Missing chemical species + UnusedSpecies = 1, // Unused species present in the chemical system + MissingChemicalSystem = 2, // Missing chemical system + MissingReactions = 3, // Missing processes + MissingChemicalSpecies = 4 // Missing chemical species }; namespace std @@ -37,8 +37,7 @@ namespace return "Missing chemical system. Use the SetSystem function to set the chemical system."; case MicmSolverBuilderErrc::MissingReactions: return "Missing reactions. Use the SetReactions function to set the processes."; - case MicmSolverBuilderErrc::MissingChemicalSpecies: - return "Provided chemical system contains no species."; + case MicmSolverBuilderErrc::MissingChemicalSpecies: return "Provided chemical system contains no species."; default: return "Unknown error"; } } @@ -54,50 +53,86 @@ inline std::error_code make_error_code(MicmSolverBuilderErrc e) namespace micm { - template + template< + class SolverParametersPolicy, + class DenseMatrixPolicy, + class SparseMatrixPolicy, + class RatesPolicy, + class LinearSolverPolicy> inline SolverBuilder& - SolverBuilder::SetSystem(const System& system) + SolverBuilder::SetSystem( + const System& system) { system_ = system; valid_system_ = true; return *this; } - template + template< + class SolverParametersPolicy, + class DenseMatrixPolicy, + class SparseMatrixPolicy, + class RatesPolicy, + class LinearSolverPolicy> inline SolverBuilder& - SolverBuilder::SetReactions(const std::vector& reactions) + SolverBuilder:: + SetReactions(const std::vector& reactions) { reactions_ = reactions; valid_reactions_ = reactions_.size() > 0; return *this; } - template + template< + class SolverParametersPolicy, + class DenseMatrixPolicy, + class SparseMatrixPolicy, + class RatesPolicy, + class LinearSolverPolicy> inline SolverBuilder& - SolverBuilder::SetNumberOfGridCells(int number_of_grid_cells) + SolverBuilder:: + SetNumberOfGridCells(int number_of_grid_cells) { number_of_grid_cells_ = number_of_grid_cells; return *this; } - template + template< + class SolverParametersPolicy, + class DenseMatrixPolicy, + class SparseMatrixPolicy, + class RatesPolicy, + class LinearSolverPolicy> inline SolverBuilder& - SolverBuilder::SetIgnoreUnusedSpecies(bool ignore_unused_species) + SolverBuilder:: + SetIgnoreUnusedSpecies(bool ignore_unused_species) { ignore_unused_species_ = ignore_unused_species; return *this; } - template + template< + class SolverParametersPolicy, + class DenseMatrixPolicy, + class SparseMatrixPolicy, + class RatesPolicy, + class LinearSolverPolicy> inline SolverBuilder& - SolverBuilder::SetReorderState(bool reorder_state) + SolverBuilder:: + SetReorderState(bool reorder_state) { reorder_state_ = reorder_state; return *this; } - template - inline void SolverBuilder::UnusedSpeciesCheck() + template< + class SolverParametersPolicy, + class DenseMatrixPolicy, + class SparseMatrixPolicy, + class RatesPolicy, + class LinearSolverPolicy> + inline void SolverBuilder:: + UnusedSpeciesCheck() { if (ignore_unused_species_) { @@ -124,8 +159,15 @@ namespace micm } } - template - inline std::map SolverBuilder::GetSpeciesMap() const + template< + class SolverParametersPolicy, + class DenseMatrixPolicy, + class SparseMatrixPolicy, + class RatesPolicy, + class LinearSolverPolicy> + inline std::map + SolverBuilder:: + GetSpeciesMap() const { std::map species_map; std::function& variables, const std::size_t i)> state_reordering; @@ -156,10 +198,14 @@ namespace micm return species_map; } - template - inline void SolverBuilder::SetAbsoluteTolerances( - std::vector& tolerances, - const std::map& species_map) const + template< + class SolverParametersPolicy, + class DenseMatrixPolicy, + class SparseMatrixPolicy, + class RatesPolicy, + class LinearSolverPolicy> + inline void SolverBuilder:: + SetAbsoluteTolerances(std::vector& tolerances, const std::map& species_map) const { // if the tolerances aren't already set, initialize them and then set based off of information in the system if (tolerances.size() != species_map.size()) @@ -185,8 +231,15 @@ namespace micm } } - template - inline std::vector SolverBuilder::GetCustomParameterLabels() const + template< + class SolverParametersPolicy, + class DenseMatrixPolicy, + class SparseMatrixPolicy, + class RatesPolicy, + class LinearSolverPolicy> + inline std::vector + SolverBuilder:: + GetCustomParameterLabels() const { std::vector param_labels{}; for (const auto& reaction : reactions_) @@ -196,8 +249,14 @@ namespace micm return param_labels; } - template - inline auto SolverBuilder::Build() + template< + class SolverParametersPolicy, + class DenseMatrixPolicy, + class SparseMatrixPolicy, + class RatesPolicy, + class LinearSolverPolicy> + inline auto + SolverBuilder::Build() { if (!valid_system_) { @@ -213,7 +272,8 @@ namespace micm std::size_t number_of_species = this->system_.StateSize(); if (number_of_species == 0) { - throw std::system_error(make_error_code(MicmSolverBuilderErrc::MissingChemicalSpecies), "Provided chemical system contains no species."); + throw std::system_error( + make_error_code(MicmSolverBuilderErrc::MissingChemicalSpecies), "Provided chemical system contains no species."); } this->UnusedSpeciesCheck(); @@ -231,20 +291,19 @@ namespace micm variable_names[species_pair.second] = species_pair.first; StateParameters state_parameters = { .number_of_grid_cells_ = this->number_of_grid_cells_, - .number_of_species_ = number_of_species, - .number_of_rate_constants_ = this->reactions_.size(), - .variable_names_ = variable_names, - .custom_rate_parameter_labels_ = labels, - .nonzero_jacobian_elements_ = nonzero_elements }; + .number_of_species_ = number_of_species, + .number_of_rate_constants_ = this->reactions_.size(), + .variable_names_ = variable_names, + .custom_rate_parameter_labels_ = labels, + .nonzero_jacobian_elements_ = nonzero_elements }; return Solver>( - SolverPolicy( - this->options_, std::move(linear_solver), std::move(rates), jacobian), - state_parameters, - this->number_of_grid_cells_, - number_of_species, - this->reactions_.size(), - this->reactions_); + SolverPolicy(this->options_, std::move(linear_solver), std::move(rates), jacobian), + state_parameters, + this->number_of_grid_cells_, + number_of_species, + this->reactions_.size(), + this->reactions_); } } // namespace micm \ No newline at end of file diff --git a/include/micm/solver/solver_result.hpp b/include/micm/solver/solver_result.hpp index 862204664..a49928a39 100644 --- a/include/micm/solver/solver_result.hpp +++ b/include/micm/solver/solver_result.hpp @@ -6,7 +6,7 @@ namespace micm { - /// @brief The final state the solver was in after the Solve function finishes + /// @brief The final state the solver was in after the Solve function finishes enum class SolverState { /// @brief This is the initial value at the start of the Solve function @@ -80,12 +80,12 @@ namespace micm } struct [[nodiscard]] SolverResult - { - /// @brief The final state the solver was in - SolverState state_ = SolverState::NotYetCalled; - /// @brief A collection of runtime state for this call of the solver - SolverStats stats_{}; - /// @brief The final time the solver iterated to - double final_time_{}; - }; -} + { + /// @brief The final state the solver was in + SolverState state_ = SolverState::NotYetCalled; + /// @brief A collection of runtime state for this call of the solver + SolverStats stats_{}; + /// @brief The final time the solver iterated to + double final_time_{}; + }; +} // namespace micm diff --git a/test/integration/analytical_jit_rosenbrock.cpp b/test/integration/analytical_jit_rosenbrock.cpp index 9414322eb..946924618 100644 --- a/test/integration/analytical_jit_rosenbrock.cpp +++ b/test/integration/analytical_jit_rosenbrock.cpp @@ -1,9 +1,9 @@ #include "analytical_policy.hpp" #include "analytical_surface_rxn_policy.hpp" -#include -#include #include +#include +#include #include @@ -11,84 +11,98 @@ constexpr std::size_t L = 1; TEST(AnalyticalExamplesJitRosenbrock, Troe) { - auto builder = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_troe(builder); } TEST(AnalyticalExamplesJitRosenbrock, TroeSuperStiffButAnalytical) { - auto builder = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_stiff_troe(builder); } TEST(AnalyticalExamplesJitRosenbrock, Photolysis) { - auto builder = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_photolysis(builder); } TEST(AnalyticalExamplesJitRosenbrock, PhotolysisSuperStiffButAnalytical) { - auto builder = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_stiff_photolysis(builder); } TEST(AnalyticalExamplesJitRosenbrock, TernaryChemicalActivation) { - auto builder = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_ternary_chemical_activation(builder); } TEST(AnalyticalExamplesJitRosenbrock, TernaryChemicalActivationSuperStiffButAnalytical) { - auto builder = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_stiff_ternary_chemical_activation(builder); } TEST(AnalyticalExamplesJitRosenbrock, Tunneling) { - auto builder = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_tunneling(builder); } TEST(AnalyticalExamplesJitRosenbrock, TunnelingSuperStiffButAnalytical) { - auto builder = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_stiff_tunneling(builder); } TEST(AnalyticalExamplesJitRosenbrock, Arrhenius) { - auto builder = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_arrhenius(builder); } TEST(AnalyticalExamplesJitRosenbrock, ArrheniusSuperStiffButAnalytical) { - auto builder = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_stiff_arrhenius(builder); } TEST(AnalyticalExamplesJitRosenbrock, Branched) { - auto builder = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_branched(builder); } TEST(AnalyticalExamplesJitRosenbrock, BranchedSuperStiffButAnalytical) { - auto builder = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_stiff_branched(builder); } TEST(AnalyticalExamplesJitRosenbrock, Robertson) { - auto builder = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_robertson(builder); } TEST(AnalyticalExamplesJitRosenbrock, SurfaceRxn) { - auto builder = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_surface_rxn(builder); } diff --git a/test/integration/analytical_policy.hpp b/test/integration/analytical_policy.hpp index 45977912a..f893e4291 100644 --- a/test/integration/analytical_policy.hpp +++ b/test/integration/analytical_policy.hpp @@ -110,9 +110,7 @@ void test_analytical_troe(BuilderPolicy& builder) auto processes = std::vector{ r1, r2 }; auto solver = - builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(processes) - .Build(); + builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })).SetReactions(processes).Build(); auto be_state = solver.GetState(); @@ -258,9 +256,7 @@ void test_analytical_stiff_troe(BuilderPolicy& builder) auto processes = std::vector{ r1, r2, r3, r4, r5 }; auto solver = - builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(processes) - .Build(); + builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })).SetReactions(processes).Build(); double temperature = 272.5; double pressure = 101253.3; @@ -370,9 +366,7 @@ void test_analytical_photolysis(BuilderPolicy& builder) auto processes = std::vector{ r1, r2 }; auto solver = - builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(processes) - .Build(); + builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })).SetReactions(processes).Build(); double temperature = 272.5; double pressure = 101253.3; @@ -499,9 +493,7 @@ void test_analytical_stiff_photolysis(BuilderPolicy& builder) auto processes = std::vector{ r1, r2, r3, r4, r5 }; auto solver = - builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(processes) - .Build(); + builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })).SetReactions(processes).Build(); double temperature = 272.5; double pressure = 101253.3; @@ -618,9 +610,7 @@ void test_analytical_ternary_chemical_activation(BuilderPolicy& builder) auto processes = std::vector{ r1, r2 }; auto solver = - builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(processes) - .Build(); + builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })).SetReactions(processes).Build(); double temperature = 272.5; double pressure = 101253.3; @@ -757,9 +747,7 @@ void test_analytical_stiff_ternary_chemical_activation(BuilderPolicy& builder) auto processes = std::vector{ r1, r2, r3, r4, r5 }; auto solver = - builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(processes) - .Build(); + builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })).SetReactions(processes).Build(); double temperature = 272.5; double pressure = 101253.3; @@ -870,9 +858,7 @@ void test_analytical_tunneling(BuilderPolicy& builder) auto processes = std::vector{ r1, r2 }; auto solver = - builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(processes) - .Build(); + builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })).SetReactions(processes).Build(); double temperature = 272.5; double pressure = 101253.3; @@ -996,9 +982,7 @@ void test_analytical_stiff_tunneling(BuilderPolicy& builder) auto processes = std::vector{ r1, r2, r3, r4, r5 }; auto solver = - builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(processes) - .Build(); + builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })).SetReactions(processes).Build(); double temperature = 272.5; double pressure = 101253.3; @@ -1105,9 +1089,7 @@ void test_analytical_arrhenius(BuilderPolicy& builder) auto processes = std::vector{ r1, r2 }; auto solver = - builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(processes) - .Build(); + builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })).SetReactions(processes).Build(); double temperature = 272.5; double pressure = 101253.3; @@ -1232,9 +1214,7 @@ void test_analytical_stiff_arrhenius(BuilderPolicy& builder) auto processes = std::vector{ r1, r2, r3, r4, r5 }; auto solver = - builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(processes) - .Build(); + builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })).SetReactions(processes).Build(); double temperature = 272.5; double pressure = 101253.3; @@ -1351,9 +1331,7 @@ void test_analytical_branched(BuilderPolicy& builder) auto processes = std::vector{ r1, r2 }; auto solver = - builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(processes) - .Build(); + builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })).SetReactions(processes).Build(); double temperature = 272.5; double pressure = 101253.3; @@ -1507,9 +1485,7 @@ void test_analytical_stiff_branched(BuilderPolicy& builder) auto processes = std::vector{ r1, r2, r3, r4, r5 }; auto solver = - builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(processes) - .Build(); + builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })).SetReactions(processes).Build(); double temperature = 272.5; double pressure = 101253.3; @@ -1643,9 +1619,7 @@ void test_analytical_robertson(BuilderPolicy& builder) auto processes = std::vector{ r1, r2, r3 }; auto solver = - builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(processes) - .Build(); + builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })).SetReactions(processes).Build(); double temperature = 272.5; double pressure = 101253.3; diff --git a/test/integration/analytical_rosenbrock.cpp b/test/integration/analytical_rosenbrock.cpp index 5634d6094..58d29723a 100644 --- a/test/integration/analytical_rosenbrock.cpp +++ b/test/integration/analytical_rosenbrock.cpp @@ -1,9 +1,8 @@ #include "analytical_policy.hpp" #include "analytical_surface_rxn_policy.hpp" - -#include "oregonator.hpp" #include "e5.hpp" #include "hires.hpp" +#include "oregonator.hpp" #include #include @@ -15,85 +14,99 @@ using SparseMatrixTest = micm::SparseMatrix; TEST(AnalyticalExamples, Troe) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_troe(builder); } TEST(AnalyticalExamples, TroeSuperStiffButAnalytical) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_stiff_troe(builder); } TEST(AnalyticalExamples, Photolysis) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_photolysis(builder); } TEST(AnalyticalExamples, PhotolysisSuperStiffButAnalytical) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_stiff_photolysis(builder); } TEST(AnalyticalExamples, TernaryChemicalActivation) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_ternary_chemical_activation(builder); } TEST(AnalyticalExamples, TernaryChemicalActivationSuperStiffButAnalytical) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_stiff_ternary_chemical_activation(builder); } TEST(AnalyticalExamples, Tunneling) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_tunneling(builder); } TEST(AnalyticalExamples, TunnelingSuperStiffButAnalytical) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_stiff_tunneling(builder); } TEST(AnalyticalExamples, Arrhenius) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_arrhenius(builder); } TEST(AnalyticalExamples, ArrheniusSuperStiffButAnalytical) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_stiff_arrhenius(builder); } TEST(AnalyticalExamples, Branched) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_branched(builder); } TEST(AnalyticalExamples, BranchedSuperStiffButAnalytical) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_stiff_branched(builder); } TEST(AnalyticalExamples, Robertson) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_robertson(builder); } TEST(AnalyticalExamples, SurfaceRxn) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); test_analytical_surface_rxn(builder); } @@ -115,7 +128,7 @@ TEST(AnalyticalExamples, Oregonator) auto params = micm::RosenbrockSolverParameters::SixStageDifferentialAlgebraicRosenbrockParameters(); using OregonatorTest = Oregonator, SparseMatrixTest>; auto solver = OregonatorTest::template CreateSolver, LinearSolverTest>(params, 1); - + double end = 360; double time_step = 30; size_t N = static_cast(end / time_step); @@ -204,7 +217,7 @@ TEST(AnalyticalExamples, HIRES) auto params = micm::RosenbrockSolverParameters::SixStageDifferentialAlgebraicRosenbrockParameters(); using HIRESTest = HIRES, SparseMatrixTest>; auto solver = HIRESTest::CreateSolver, LinearSolverTest>(params, 1); - + size_t N = 2; std::vector> model_concentrations(N + 1, std::vector(8)); diff --git a/test/integration/analytical_surface_rxn_policy.hpp b/test/integration/analytical_surface_rxn_policy.hpp index 8607bf78d..bffe73374 100644 --- a/test/integration/analytical_surface_rxn_policy.hpp +++ b/test/integration/analytical_surface_rxn_policy.hpp @@ -63,10 +63,7 @@ void test_analytical_surface_rxn(BuilderPolicy& builder) auto reactions = std::vector{ surface_process }; // Solver - auto solver = - builder.SetSystem(chemical_system) - .SetReactions(reactions) - .Build(); + auto solver = builder.SetSystem(chemical_system).SetReactions(reactions).Build(); // State micm::State state = solver.GetState(); diff --git a/test/integration/chapman.cpp b/test/integration/chapman.cpp index 6a3894870..a0e0a759c 100644 --- a/test/integration/chapman.cpp +++ b/test/integration/chapman.cpp @@ -37,10 +37,10 @@ TEST(ChapmanIntegration, CanBuildChapmanSystemUsingConfig) EXPECT_EQ(options.relative_tolerance_, 1.0e-4); auto solver = micm::CpuSolverBuilder(options) - .SetSystem(solver_params.system_) - .SetReactions(solver_params.processes_) - .SetIgnoreUnusedSpecies(true) - .Build(); + .SetSystem(solver_params.system_) + .SetReactions(solver_params.processes_) + .SetIgnoreUnusedSpecies(true) + .Build(); micm::State state = solver.GetState(); @@ -151,7 +151,7 @@ TEST(ChapmanIntegration, CanBuildChapmanSystem) .SetReactions({ r1, r2, r3, r4, photo_1, photo_2, photo_3 }) .SetIgnoreUnusedSpecies(true) .Build(); - + auto state = solver.GetState(); std::vector concentrations{ 0.1, 0.1, 0.1, 0.2, 0.2, 0.2, 0.3, 0.3, 0.3 }; diff --git a/test/integration/e5.hpp b/test/integration/e5.hpp index bf7506985..37cbdfb26 100644 --- a/test/integration/e5.hpp +++ b/test/integration/e5.hpp @@ -11,12 +11,11 @@ class E5 const std::vector variable_names_ = { "y1", "y2", "y3", "y4" }; public: - E5() = delete; E5(std::size_t number_of_grid_cells, std::set> nonzero_jacobian_elements) - : number_of_grid_cells_(number_of_grid_cells), - nonzero_jacobian_elements_(nonzero_jacobian_elements) + : number_of_grid_cells_(number_of_grid_cells), + nonzero_jacobian_elements_(nonzero_jacobian_elements) { } @@ -41,11 +40,7 @@ class E5 LinearSolverPolicy linear_solver(jacobian, 1.0e-30); E5 e5(number_of_grid_cells, nonzero_jacobian_elements); - return SolverPolicy( - parameters, - std::move(linear_solver), - std::move(e5), - jacobian); + return SolverPolicy(parameters, std::move(linear_solver), std::move(e5), jacobian); } ~E5() @@ -54,18 +49,15 @@ class E5 micm::State GetState() const { - auto state = micm::State{ { - .number_of_grid_cells_ = number_of_grid_cells_, - .number_of_species_ = 4, - .number_of_rate_constants_ = 0, - .variable_names_ = variable_names_, - .nonzero_jacobian_elements_ = nonzero_jacobian_elements_ - } }; - - state.jacobian_ = micm::BuildJacobian( - nonzero_jacobian_elements_, - number_of_grid_cells_, - variable_names_.size()); + auto state = + micm::State{ { .number_of_grid_cells_ = number_of_grid_cells_, + .number_of_species_ = 4, + .number_of_rate_constants_ = 0, + .variable_names_ = variable_names_, + .nonzero_jacobian_elements_ = nonzero_jacobian_elements_ } }; + + state.jacobian_ = + micm::BuildJacobian(nonzero_jacobian_elements_, number_of_grid_cells_, variable_names_.size()); auto lu = micm::LuDecomposition::GetLUMatrices(state.jacobian_, 1.0e-30); auto lower_matrix = std::move(lu.first); @@ -80,10 +72,7 @@ class E5 /// @param rate_constants List of rate constants for each needed species /// @param number_densities The number density of each species /// @param forcing Vector of forcings for the current conditions - void AddForcingTerms( - const MatrixPolicy& rate_constants, - const MatrixPolicy& number_densities, - MatrixPolicy& forcing) + void AddForcingTerms(const MatrixPolicy& rate_constants, const MatrixPolicy& number_densities, MatrixPolicy& forcing) { auto data = number_densities.AsVector(); diff --git a/test/integration/hires.hpp b/test/integration/hires.hpp index bc2da4314..0ba864c5f 100644 --- a/test/integration/hires.hpp +++ b/test/integration/hires.hpp @@ -11,12 +11,11 @@ class HIRES const std::vector variable_names_ = { "y1", "y2", "y3", "y4", "y5", "y6", "y7", "y8" }; public: - HIRES() = delete; HIRES(std::size_t number_of_grid_cells, std::set> nonzero_jacobian_elements) - : number_of_grid_cells_(number_of_grid_cells), - nonzero_jacobian_elements_(nonzero_jacobian_elements) + : number_of_grid_cells_(number_of_grid_cells), + nonzero_jacobian_elements_(nonzero_jacobian_elements) { } @@ -41,11 +40,7 @@ class HIRES LinearSolverPolicy linear_solver(jacobian, 1.0e-30); HIRES hires(number_of_grid_cells, nonzero_jacobian_elements); - return SolverPolicy( - parameters, - std::move(linear_solver), - std::move(hires), - jacobian); + return SolverPolicy(parameters, std::move(linear_solver), std::move(hires), jacobian); } ~HIRES() @@ -54,18 +49,15 @@ class HIRES micm::State GetState() const { - auto state = micm::State{ { - .number_of_grid_cells_ = number_of_grid_cells_, - .number_of_species_ = 8, - .number_of_rate_constants_ = 0, - .variable_names_ = variable_names_, - .nonzero_jacobian_elements_ = nonzero_jacobian_elements_ - } }; - - state.jacobian_ = micm::BuildJacobian( - nonzero_jacobian_elements_, - number_of_grid_cells_, - variable_names_.size()); + auto state = + micm::State{ { .number_of_grid_cells_ = number_of_grid_cells_, + .number_of_species_ = 8, + .number_of_rate_constants_ = 0, + .variable_names_ = variable_names_, + .nonzero_jacobian_elements_ = nonzero_jacobian_elements_ } }; + + state.jacobian_ = + micm::BuildJacobian(nonzero_jacobian_elements_, number_of_grid_cells_, variable_names_.size()); auto lu = micm::LuDecomposition::GetLUMatrices(state.jacobian_, 1.0e-30); auto lower_matrix = std::move(lu.first); @@ -80,10 +72,7 @@ class HIRES /// @param rate_constants List of rate constants for each needed species /// @param number_densities The number density of each species /// @param forcing Vector of forcings for the current conditions - void AddForcingTerms( - const MatrixPolicy& rate_constants, - const MatrixPolicy& number_densities, - MatrixPolicy& forcing) + void AddForcingTerms(const MatrixPolicy& rate_constants, const MatrixPolicy& number_densities, MatrixPolicy& forcing) { auto data = number_densities.AsVector(); @@ -140,6 +129,5 @@ class HIRES jacobian[0][7][5] -= -280.0 * data[7]; jacobian[0][7][6] -= 1.81; jacobian[0][7][7] -= -280.0 * data[6]; - } }; diff --git a/test/integration/jit_terminator.cpp b/test/integration/jit_terminator.cpp index 0864029a3..0ab17fcbf 100644 --- a/test/integration/jit_terminator.cpp +++ b/test/integration/jit_terminator.cpp @@ -30,23 +30,19 @@ TEST(JitRosenbrockSolver, Terminator) parameters.relative_tolerance_ = 1.0e-8; parameters.max_number_of_steps_ = 100000; { - auto builder = micm::JitSolverBuilder(parameters) - .SetIgnoreUnusedSpecies(true); + auto builder = micm::JitSolverBuilder(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 1); } { - auto builder = micm::JitSolverBuilder(parameters) - .SetIgnoreUnusedSpecies(true); + auto builder = micm::JitSolverBuilder(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 2); } { - auto builder = micm::JitSolverBuilder(parameters) - .SetIgnoreUnusedSpecies(true); + auto builder = micm::JitSolverBuilder(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 3); } { - auto builder = micm::JitSolverBuilder(parameters) - .SetIgnoreUnusedSpecies(true); + auto builder = micm::JitSolverBuilder(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 4); } } \ No newline at end of file diff --git a/test/integration/oregonator.hpp b/test/integration/oregonator.hpp index 86c059fd8..7c88d8835 100644 --- a/test/integration/oregonator.hpp +++ b/test/integration/oregonator.hpp @@ -10,12 +10,11 @@ class Oregonator const std::vector variable_names_ = { "A", "B", "C" }; public: - Oregonator() = delete; Oregonator(std::size_t number_of_grid_cells, std::set> nonzero_jacobian_elements) - : number_of_grid_cells_(number_of_grid_cells), - nonzero_jacobian_elements_(nonzero_jacobian_elements) + : number_of_grid_cells_(number_of_grid_cells), + nonzero_jacobian_elements_(nonzero_jacobian_elements) { } @@ -23,7 +22,6 @@ class Oregonator template static auto CreateSolver(auto parameters, std::size_t number_of_grid_cells) { - parameters.relative_tolerance_ = 1e-4; parameters.absolute_tolerance_ = std::vector(3, 1.0e-10); @@ -41,11 +39,7 @@ class Oregonator LinearSolverPolicy linear_solver(jacobian, 1.0e-30); Oregonator oregonator(number_of_grid_cells, nonzero_jacobian_elements); - return SolverPolicy( - parameters, - std::move(linear_solver), - std::move(oregonator), - jacobian); + return SolverPolicy(parameters, std::move(linear_solver), std::move(oregonator), jacobian); } ~Oregonator() @@ -61,10 +55,8 @@ class Oregonator .variable_names_ = variable_names_, .nonzero_jacobian_elements_ = nonzero_jacobian_elements_ } }; - state.jacobian_ = micm::BuildJacobian( - nonzero_jacobian_elements_, - number_of_grid_cells_, - variable_names_.size()); + state.jacobian_ = + micm::BuildJacobian(nonzero_jacobian_elements_, number_of_grid_cells_, variable_names_.size()); auto lu = micm::LuDecomposition::GetLUMatrices(state.jacobian_, 1.0e-30); auto lower_matrix = std::move(lu.first); @@ -79,10 +71,7 @@ class Oregonator /// @param rate_constants List of rate constants for each needed species /// @param number_densities The number density of each species /// @param forcing Vector of forcings for the current conditions - void AddForcingTerms( - const MatrixPolicy& rate_constants, - const MatrixPolicy& number_densities, - MatrixPolicy& forcing) + void AddForcingTerms(const MatrixPolicy& rate_constants, const MatrixPolicy& number_densities, MatrixPolicy& forcing) { auto data = number_densities.AsVector(); diff --git a/test/integration/terminator.cpp b/test/integration/terminator.cpp index 941938128..b86d35cb5 100644 --- a/test/integration/terminator.cpp +++ b/test/integration/terminator.cpp @@ -16,36 +16,36 @@ TEST(RosenbrockSolver, Terminator) auto parameters = micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters(); parameters.relative_tolerance_ = 1.0e-8; parameters.max_number_of_steps_ = 100000; - { + { auto builder = micm::CpuSolverBuilder(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 1); } - { + { auto builder = micm::CpuSolverBuilder(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 2); } - { + { auto builder = micm::CpuSolverBuilder(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 3); } - { + { auto builder = micm::CpuSolverBuilder(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 4); } parameters.check_singularity_ = true; - { + { auto builder = micm::CpuSolverBuilder(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 1); } - { + { auto builder = micm::CpuSolverBuilder(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 2); } - { + { auto builder = micm::CpuSolverBuilder(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 3); } - { + { auto builder = micm::CpuSolverBuilder(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 4); } @@ -53,28 +53,28 @@ TEST(RosenbrockSolver, Terminator) template using VectorBuilder = micm::CpuSolverBuilder< - micm::RosenbrockSolverParameters, - micm::VectorMatrix, - micm::SparseMatrix>>; + micm::RosenbrockSolverParameters, + micm::VectorMatrix, + micm::SparseMatrix>>; TEST(RosenbrockSolver, VectorTerminator) { auto parameters = micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters(); parameters.relative_tolerance_ = 1.0e-8; parameters.max_number_of_steps_ = 100000; - { + { auto builder = VectorBuilder<1>(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 1); } - { + { auto builder = VectorBuilder<2>(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 2); } - { + { auto builder = VectorBuilder<3>(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 3); } - { + { auto builder = VectorBuilder<4>(parameters).SetIgnoreUnusedSpecies(true); TestTerminator(builder, 4); } diff --git a/test/integration/terminator.hpp b/test/integration/terminator.hpp index 6160902e2..e78e77ba9 100644 --- a/test/integration/terminator.hpp +++ b/test/integration/terminator.hpp @@ -21,9 +21,7 @@ /// More details including analytical solution can be found here: /// https://github.com/ESCOMP/CAM/blob/8cd44c50fe107c0b93ccd48b61eaa3d10a5b4e2f/src/chemistry/pp_terminator/chemistry.F90#L1-L434 template -void TestTerminator( - BuilderPolicy& builder, - std::size_t number_of_grid_cells) +void TestTerminator(BuilderPolicy& builder, std::size_t number_of_grid_cells) { auto cl2 = micm::Species("Cl2"); auto cl = micm::Species("Cl"); @@ -45,11 +43,10 @@ void TestTerminator( .SetPhase(gas_phase) .SetRateConstant(micm::ArrheniusRateConstant({ .A_ = k2 })); - auto solver = - builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(std::vector{ toy_r1, toy_r2 }) - .SetNumberOfGridCells(number_of_grid_cells) - .Build(); + auto solver = builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) + .SetReactions(std::vector{ toy_r1, toy_r2 }) + .SetNumberOfGridCells(number_of_grid_cells) + .Build(); auto state = solver.GetState(); auto get_double = std::bind(std::lognormal_distribution(-2.0, 2.0), std::default_random_engine()); diff --git a/test/regression/RosenbrockChapman/jit_util.hpp b/test/regression/RosenbrockChapman/jit_util.hpp index baad9882e..238761b97 100644 --- a/test/regression/RosenbrockChapman/jit_util.hpp +++ b/test/regression/RosenbrockChapman/jit_util.hpp @@ -1,14 +1,14 @@ #include "util.hpp" #include -#include #include +#include #include -template +template using JitBuilder = micm::JitSolverBuilder; -template +template auto getTwoStageMultiCellJitChapmanSolver(const size_t number_of_grid_cells) { micm::Phase gas_phase = createGasPhase(); @@ -22,7 +22,7 @@ auto getTwoStageMultiCellJitChapmanSolver(const size_t number_of_grid_cells) .Build(); } -template +template auto getThreeStageMultiCellJitChapmanSolver(const size_t number_of_grid_cells) { micm::Phase gas_phase = createGasPhase(); @@ -36,7 +36,7 @@ auto getThreeStageMultiCellJitChapmanSolver(const size_t number_of_grid_cells) .Build(); } -template +template auto getFourStageMultiCellJitChapmanSolver(const size_t number_of_grid_cells) { micm::Phase gas_phase = createGasPhase(); @@ -50,7 +50,7 @@ auto getFourStageMultiCellJitChapmanSolver(const size_t number_of_grid_cells) .Build(); } -template +template auto getFourStageDAMultiCellJitChapmanSolver(const size_t number_of_grid_cells) { micm::Phase gas_phase = createGasPhase(); @@ -64,7 +64,7 @@ auto getFourStageDAMultiCellJitChapmanSolver(const size_t number_of_grid_cells) .Build(); } -template +template auto getSixStageDAMultiCellJitChapmanSolver(const size_t number_of_grid_cells) { micm::Phase gas_phase = createGasPhase(); diff --git a/test/regression/RosenbrockChapman/regression_test_dforce_dy.cpp b/test/regression/RosenbrockChapman/regression_test_dforce_dy.cpp index 2de97d7d8..b8ccfb3c2 100644 --- a/test/regression/RosenbrockChapman/regression_test_dforce_dy.cpp +++ b/test/regression/RosenbrockChapman/regression_test_dforce_dy.cpp @@ -9,13 +9,14 @@ template using VectorBuilder = micm::CpuSolverBuilder< - micm::RosenbrockSolverParameters, - micm::VectorMatrix, - micm::SparseMatrix>>; + micm::RosenbrockSolverParameters, + micm::VectorMatrix, + micm::SparseMatrix>>; TEST(RegressionRosenbrock, Jacobian) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); auto solver = getChapmanSolver(builder, 3); testJacobian(solver); } diff --git a/test/regression/RosenbrockChapman/regression_test_p_force.cpp b/test/regression/RosenbrockChapman/regression_test_p_force.cpp index 8eb73e16b..4bd6654d4 100644 --- a/test/regression/RosenbrockChapman/regression_test_p_force.cpp +++ b/test/regression/RosenbrockChapman/regression_test_p_force.cpp @@ -9,13 +9,14 @@ template using VectorBuilder = micm::CpuSolverBuilder< - micm::RosenbrockSolverParameters, - micm::VectorMatrix, - micm::SparseMatrix>>; + micm::RosenbrockSolverParameters, + micm::VectorMatrix, + micm::SparseMatrix>>; TEST(RegressionRosenbrock, RateConstants) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); auto solver = getChapmanSolver(builder, 3); testRateConstants(solver); } @@ -46,7 +47,8 @@ TEST(RegressionRosenbrock, VectorRateConstants) TEST(RegressionRosenbrock, Forcing) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); auto solver = getChapmanSolver(builder, 3); testForcing>(solver); } diff --git a/test/regression/RosenbrockChapman/regression_test_p_force_policy.hpp b/test/regression/RosenbrockChapman/regression_test_p_force_policy.hpp index 7a469eef3..a92cac983 100644 --- a/test/regression/RosenbrockChapman/regression_test_p_force_policy.hpp +++ b/test/regression/RosenbrockChapman/regression_test_p_force_policy.hpp @@ -3,11 +3,11 @@ #include "chapman_ode_solver.hpp" #include "util.hpp" +#include #include #include #include #include -#include #include @@ -49,7 +49,6 @@ void testRateConstants(SolverPolicy& solver) template void testForcing(SolverPolicy& solver) { - std::random_device rnd_device; std::mt19937 engine{ rnd_device() }; std::lognormal_distribution dist(-2.0, 2.0); diff --git a/test/regression/RosenbrockChapman/regression_test_solve.cpp b/test/regression/RosenbrockChapman/regression_test_solve.cpp index 45fb74cbd..a9c820169 100644 --- a/test/regression/RosenbrockChapman/regression_test_solve.cpp +++ b/test/regression/RosenbrockChapman/regression_test_solve.cpp @@ -8,41 +8,46 @@ #include template using VectorBuilder = micm::CpuSolverBuilder< - micm::RosenbrockSolverParameters, - micm::VectorMatrix, - micm::SparseMatrix>>; + micm::RosenbrockSolverParameters, + micm::VectorMatrix, + micm::SparseMatrix>>; TEST(RegressionRosenbrock, TwoStageSolve) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::TwoStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::TwoStageRosenbrockParameters()); auto solver = getChapmanSolver(builder, 3); testSolve(solver, 1.0e-2); } TEST(RegressionRosenbrock, ThreeStageSolve) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); auto solver = getChapmanSolver(builder, 3); testSolve(solver); } TEST(RegressionRosenbrock, FourStageSolve) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::FourStageRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::FourStageRosenbrockParameters()); auto solver = getChapmanSolver(builder, 3); testSolve(solver, 1.0e-4); } TEST(RegressionRosenbrock, FourStageDASolve) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::FourStageDifferentialAlgebraicRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::FourStageDifferentialAlgebraicRosenbrockParameters()); auto solver = getChapmanSolver(builder, 3); testSolve(solver, 1.0e-4); } TEST(RegressionRosenbrock, SixStageDASolve) { - auto builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::FourStageDifferentialAlgebraicRosenbrockParameters()); + auto builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::FourStageDifferentialAlgebraicRosenbrockParameters()); auto solver = getChapmanSolver(builder, 3); testSolve(solver, 1.0e-4); } diff --git a/test/regression/RosenbrockChapman/util.hpp b/test/regression/RosenbrockChapman/util.hpp index 6a9424780..36ca9a72e 100644 --- a/test/regression/RosenbrockChapman/util.hpp +++ b/test/regression/RosenbrockChapman/util.hpp @@ -84,16 +84,13 @@ std::vector createProcesses(const micm::Phase& gas_phase) } template -auto getChapmanSolver( - SolverBuilderPolicy& builder, - const size_t number_of_grid_cells) +auto getChapmanSolver(SolverBuilderPolicy& builder, const size_t number_of_grid_cells) { micm::Phase gas_phase = createGasPhase(); std::vector processes = createProcesses(gas_phase); - return builder - .SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) - .SetReactions(std::move(processes)) - .SetNumberOfGridCells(number_of_grid_cells) - .Build(); + return builder.SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) + .SetReactions(std::move(processes)) + .SetNumberOfGridCells(number_of_grid_cells) + .Build(); } \ No newline at end of file diff --git a/test/unit/openmp/test_openmp.cpp b/test/unit/openmp/test_openmp.cpp index e7802cff3..85de2e50c 100644 --- a/test/unit/openmp/test_openmp.cpp +++ b/test/unit/openmp/test_openmp.cpp @@ -25,10 +25,11 @@ TEST(OpenMP, OneSolverManyStates) std::vector> results(n_threads); - auto solver = CpuSolverBuilder(RosenbrockSolverParameters::ThreeStageRosenbrockParameters()) - .SetSystem(chemical_system) - .SetReactions(reactions) - .Build(); + auto solver = + CpuSolverBuilder(RosenbrockSolverParameters::ThreeStageRosenbrockParameters()) + .SetSystem(chemical_system) + .SetReactions(reactions) + .Build(); #pragma omp parallel num_threads(n_threads) { diff --git a/test/unit/openmp/test_openmp_jit_solver.cpp b/test/unit/openmp/test_openmp_jit_solver.cpp index 13f198f06..26c118226 100644 --- a/test/unit/openmp/test_openmp_jit_solver.cpp +++ b/test/unit/openmp/test_openmp_jit_solver.cpp @@ -3,8 +3,8 @@ #include #include #include -#include #include +#include #include #include @@ -12,7 +12,7 @@ using namespace micm; -template +template using JitBuilder = JitSolverBuilder; TEST(OpenMP, JITOneSolverManyStates) @@ -34,7 +34,7 @@ TEST(OpenMP, JITOneSolverManyStates) auto solver = JitBuilder<1>(RosenbrockSolverParameters::ThreeStageRosenbrockParameters()) .SetSystem(chemical_system) .SetReactions(reactions) - .Build(); + .Build(); #pragma omp parallel num_threads(n_threads) { diff --git a/test/unit/solver/test_cuda_rosenbrock.cpp b/test/unit/solver/test_cuda_rosenbrock.cpp index 81b08a31d..12953bfa8 100644 --- a/test/unit/solver/test_cuda_rosenbrock.cpp +++ b/test/unit/solver/test_cuda_rosenbrock.cpp @@ -15,7 +15,7 @@ #include -template +template using GpuBuilder = micm::CudaSolverBuilder; template @@ -69,7 +69,8 @@ void testAlphaMinusJacobian() auto gpu_builder = GpuBuilder(micm::CudaRosenbrockSolverParameters::ThreeStageRosenbrockParameters()); gpu_builder = getSolver(gpu_builder); auto gpu_solver = gpu_builder.SetNumberOfGridCells(number_of_grid_cells).Build(); - auto cpu_builder = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + auto cpu_builder = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); cpu_builder = getSolver(cpu_builder); auto cpu_solver = cpu_builder.SetNumberOfGridCells(number_of_grid_cells).Build(); @@ -110,7 +111,8 @@ void testAlphaMinusJacobian() { for (std::size_t j = 0; j < 5; ++j) { - if (!cpu_jacobian.IsZero(i, j)) cpu_jacobian[i_cell][i][j] = gpu_jacobian[i_cell][i][j]; + if (!cpu_jacobian.IsZero(i, j)) + cpu_jacobian[i_cell][i][j] = gpu_jacobian[i_cell][i][j]; } } } @@ -145,7 +147,8 @@ void testAlphaMinusJacobian() { for (std::size_t j = 0; j < 5; ++j) { - if (!cpu_jacobian.IsZero(i, j)) EXPECT_EQ(cpu_jacobian[i_cell][i][j], gpu_jacobian[i_cell][i][j]); + if (!cpu_jacobian.IsZero(i, j)) + EXPECT_EQ(cpu_jacobian[i_cell][i][j], gpu_jacobian[i_cell][i][j]); } } } @@ -160,7 +163,7 @@ void testNormalizedErrorConst() auto gpu_builder = GpuBuilder(micm::CudaRosenbrockSolverParameters::ThreeStageRosenbrockParameters()); gpu_builder = getSolver(gpu_builder); auto gpu_solver = gpu_builder.SetNumberOfGridCells(number_of_grid_cells).Build(); - + std::vector atol = gpu_solver.solver_.parameters_.absolute_tolerance_; double rtol = gpu_solver.solver_.parameters_.relative_tolerance_; @@ -205,7 +208,7 @@ void testNormalizedErrorDiff() auto gpu_builder = GpuBuilder(micm::CudaRosenbrockSolverParameters::ThreeStageRosenbrockParameters()); gpu_builder = getSolver(gpu_builder); auto gpu_solver = gpu_builder.SetNumberOfGridCells(number_of_grid_cells).Build(); - + std::vector atol = gpu_solver.solver_.parameters_.absolute_tolerance_; double rtol = gpu_solver.solver_.parameters_.relative_tolerance_; diff --git a/test/unit/solver/test_jit_rosenbrock.cpp b/test/unit/solver/test_jit_rosenbrock.cpp index ede42062b..0ade82a15 100644 --- a/test/unit/solver/test_jit_rosenbrock.cpp +++ b/test/unit/solver/test_jit_rosenbrock.cpp @@ -2,8 +2,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -125,7 +125,7 @@ void run_solver(auto& solver) } } -template +template using JitBuilder = micm::JitSolverBuilder; TEST(JitRosenbrockSolver, AlphaMinusJacobian) diff --git a/test/unit/solver/test_rosenbrock.cpp b/test/unit/solver/test_rosenbrock.cpp index 6e25de679..5c0e864be 100644 --- a/test/unit/solver/test_rosenbrock.cpp +++ b/test/unit/solver/test_rosenbrock.cpp @@ -147,9 +147,15 @@ void testNormalizedErrorDiff(SolverBuilderPolicy builder, std::size_t number_of_ } } -using StandardBuilder = micm::CpuSolverBuilder, micm::SparseMatrix>; +using StandardBuilder = micm::CpuSolverBuilder< + micm::RosenbrockSolverParameters, + micm::Matrix, + micm::SparseMatrix>; template -using VectorBuilder = micm::CpuSolverBuilder, micm::SparseMatrix>>; +using VectorBuilder = micm::CpuSolverBuilder< + micm::RosenbrockSolverParameters, + micm::VectorMatrix, + micm::SparseMatrix>>; TEST(RosenbrockSolver, StandardAlphaMinusJacobian) { @@ -185,7 +191,8 @@ TEST(RosenbrockSolver, CanSetTolerances) for (size_t number_of_grid_cells = 1; number_of_grid_cells <= 10; ++number_of_grid_cells) { - auto solver = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()) + auto solver = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()) .SetSystem(micm::System(micm::SystemParameters{ .gas_phase_ = gas_phase })) .SetReactions(std::vector{ r1 }) .SetNumberOfGridCells(number_of_grid_cells) diff --git a/test/unit/solver/test_solver_builder.cpp b/test/unit/solver/test_solver_builder.cpp index 7a03199c3..e40c780b7 100644 --- a/test/unit/solver/test_solver_builder.cpp +++ b/test/unit/solver/test_solver_builder.cpp @@ -2,8 +2,8 @@ #include #include #ifdef MICM_ENABLE_LLVM -#include -#include +# include +# include #endif #include #include @@ -42,25 +42,27 @@ namespace TEST(SolverBuilder, ThrowsMissingSystem) { - - EXPECT_THROW(micm::CpuSolverBuilder(micm::BackwardEulerSolverParameters{}) - .SetNumberOfGridCells(1) - .Build(), - std::system_error); + EXPECT_THROW( + micm::CpuSolverBuilder(micm::BackwardEulerSolverParameters{}) + .SetNumberOfGridCells(1) + .Build(), + std::system_error); } TEST(SolverBuilder, ThrowsMissingReactions) { - EXPECT_THROW(micm::CpuSolverBuilder(micm::BackwardEulerSolverParameters{}) - .SetSystem(the_system) - .SetNumberOfGridCells(1) - .Build(), - std::system_error); - EXPECT_THROW(micm::CpuSolverBuilder(micm::BackwardEulerSolverParameters{}) - .SetSystem(the_system) - .SetReactions({}) - .Build(), - std::system_error); + EXPECT_THROW( + micm::CpuSolverBuilder(micm::BackwardEulerSolverParameters{}) + .SetSystem(the_system) + .SetNumberOfGridCells(1) + .Build(), + std::system_error); + EXPECT_THROW( + micm::CpuSolverBuilder(micm::BackwardEulerSolverParameters{}) + .SetSystem(the_system) + .SetReactions({}) + .Build(), + std::system_error); } TEST(SolverBuilder, CanBuildBackwardEuler) @@ -72,34 +74,44 @@ TEST(SolverBuilder, CanBuildBackwardEuler) .Build(); constexpr std::size_t L = 4; - auto backward_euler_vector = micm::CpuSolverBuilder, micm::SparseMatrix>>(micm::BackwardEulerSolverParameters{}) - .SetSystem(the_system) - .SetReactions(reactions) - .SetNumberOfGridCells(1) - .Build(); + auto backward_euler_vector = + micm::CpuSolverBuilder< + micm::BackwardEulerSolverParameters, + micm::VectorMatrix, + micm::SparseMatrix>>(micm::BackwardEulerSolverParameters{}) + .SetSystem(the_system) + .SetReactions(reactions) + .SetNumberOfGridCells(1) + .Build(); } TEST(SolverBuilder, CanBuildRosenbrock) { - auto rosenbrock = micm::CpuSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()) - .SetSystem(the_system) - .SetReactions(reactions) - .SetNumberOfGridCells(1) - .Build(); + auto rosenbrock = micm::CpuSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()) + .SetSystem(the_system) + .SetReactions(reactions) + .SetNumberOfGridCells(1) + .Build(); constexpr std::size_t L = 4; - auto rosenbrock_vector = micm::CpuSolverBuilder, micm::SparseMatrix>>(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()) - .SetSystem(the_system) - .SetReactions(reactions) - .SetNumberOfGridCells(1) - .Build(); + auto rosenbrock_vector = micm::CpuSolverBuilder< + micm::RosenbrockSolverParameters, + micm::VectorMatrix, + micm::SparseMatrix>>( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()) + .SetSystem(the_system) + .SetReactions(reactions) + .SetNumberOfGridCells(1) + .Build(); } #ifdef MICM_ENABLE_LLVM TEST(SolverBuilder, CanBuildJitRosenbrock) { constexpr std::size_t L = 4; - auto jit_rosenbrock = micm::JitSolverBuilder(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()) + auto jit_rosenbrock = micm::JitSolverBuilder( + micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()) .SetSystem(the_system) .SetReactions(reactions) .SetNumberOfGridCells(L)