diff --git a/include/micm/solver/solver_builder.hpp b/include/micm/solver/solver_builder.hpp index 352d07425..da2de8f20 100644 --- a/include/micm/solver/solver_builder.hpp +++ b/include/micm/solver/solver_builder.hpp @@ -115,6 +115,7 @@ namespace micm /// @tparam SolverParametersPolicy Parameters for the ODE solver /// @tparam DenseMatrixPolicy Policy for dense matrices /// @tparam SparseMatrixPolicy Policy for sparse matrices + /// @tparam LuDecompositionPolicy Policy for the LU decomposition template< class SolverParametersPolicy, class DenseMatrixPolicy = Matrix, diff --git a/test/integration/test_analytical_backward_euler.cpp b/test/integration/test_analytical_backward_euler.cpp index 90cb04a35..feccccaa8 100644 --- a/test/integration/test_analytical_backward_euler.cpp +++ b/test/integration/test_analytical_backward_euler.cpp @@ -18,12 +18,41 @@ template using VectorStateType = micm::State, micm::SparseMatrix>>; +template +using VectorBackwardEulerDoolittle = micm::CpuSolverBuilder< + micm::BackwardEulerSolverParameters, + micm::VectorMatrix, + micm::SparseMatrix>, micm::LuDecompositionDoolittle>; + +template +using VectorStateTypeDoolittle = + micm::State, micm::SparseMatrix>, micm::LuDecompositionDoolittle>; + +template +using VectorBackwardEulerMozart = micm::CpuSolverBuilder< + micm::BackwardEulerSolverParameters, + micm::VectorMatrix, + micm::SparseMatrix>, micm::LuDecompositionMozart>; + +template +using VectorStateTypeMozart = + micm::State, micm::SparseMatrix>, micm::LuDecompositionMozart>; + auto backward_euler = micm::CpuSolverBuilder(micm::BackwardEulerSolverParameters()); auto backard_euler_vector_1 = VectorBackwardEuler<1>(micm::BackwardEulerSolverParameters()); auto backard_euler_vector_2 = VectorBackwardEuler<2>(micm::BackwardEulerSolverParameters()); auto backard_euler_vector_3 = VectorBackwardEuler<3>(micm::BackwardEulerSolverParameters()); auto backard_euler_vector_4 = VectorBackwardEuler<4>(micm::BackwardEulerSolverParameters()); +auto backward_euler_vector_doolittle_1 = VectorBackwardEulerDoolittle<1>(micm::BackwardEulerSolverParameters()); +auto backward_euler_vector_doolittle_2 = VectorBackwardEulerDoolittle<2>(micm::BackwardEulerSolverParameters()); +auto backward_euler_vector_doolittle_3 = VectorBackwardEulerDoolittle<3>(micm::BackwardEulerSolverParameters()); +auto backward_euler_vector_doolittle_4 = VectorBackwardEulerDoolittle<4>(micm::BackwardEulerSolverParameters()); +auto backward_euler_vector_mozart_1 = VectorBackwardEulerMozart<1>(micm::BackwardEulerSolverParameters()); +auto backward_euler_vector_mozart_2 = VectorBackwardEulerMozart<2>(micm::BackwardEulerSolverParameters()); +auto backward_euler_vector_mozart_3 = VectorBackwardEulerMozart<3>(micm::BackwardEulerSolverParameters()); +auto backward_euler_vector_mozart_4 = VectorBackwardEulerMozart<4>(micm::BackwardEulerSolverParameters()); + TEST(AnalyticalExamples, Troe) { test_analytical_troe(backward_euler, 1e-6); @@ -31,6 +60,14 @@ TEST(AnalyticalExamples, Troe) test_analytical_troe, VectorStateType<2>>(backard_euler_vector_2, 1e-6); test_analytical_troe, VectorStateType<3>>(backard_euler_vector_3, 1e-6); test_analytical_troe, VectorStateType<4>>(backard_euler_vector_4, 1e-6); + test_analytical_troe, VectorStateTypeDoolittle<1>>(backward_euler_vector_doolittle_1, 1e-6); + test_analytical_troe, VectorStateTypeDoolittle<2>>(backward_euler_vector_doolittle_2, 1e-6); + test_analytical_troe, VectorStateTypeDoolittle<3>>(backward_euler_vector_doolittle_3, 1e-6); + test_analytical_troe, VectorStateTypeDoolittle<4>>(backward_euler_vector_doolittle_4, 1e-6); + test_analytical_troe, VectorStateTypeMozart<1>>(backward_euler_vector_mozart_1, 1e-6); + test_analytical_troe, VectorStateTypeMozart<2>>(backward_euler_vector_mozart_2, 1e-6); + test_analytical_troe, VectorStateTypeMozart<3>>(backward_euler_vector_mozart_3, 1e-6); + test_analytical_troe, VectorStateTypeMozart<4>>(backward_euler_vector_mozart_4, 1e-6); } TEST(AnalyticalExamples, TroeSuperStiffButAnalytical) @@ -144,9 +181,33 @@ TEST(AnalyticalExamples, SurfaceRxn) TEST(AnalyticalExamples, HIRES) { test_analytical_hires(backward_euler, 1e-1); + test_analytical_hires, VectorStateType<1>>(backard_euler_vector_1, 1e-1); + test_analytical_hires, VectorStateType<2>>(backard_euler_vector_2, 1e-1); + test_analytical_hires, VectorStateType<3>>(backard_euler_vector_3, 1e-1); + test_analytical_hires, VectorStateType<4>>(backard_euler_vector_4, 1e-1); + test_analytical_hires, VectorStateTypeDoolittle<1>>(backward_euler_vector_doolittle_1, 1e-1); + test_analytical_hires, VectorStateTypeDoolittle<2>>(backward_euler_vector_doolittle_2, 1e-1); + test_analytical_hires, VectorStateTypeDoolittle<3>>(backward_euler_vector_doolittle_3, 1e-1); + test_analytical_hires, VectorStateTypeDoolittle<4>>(backward_euler_vector_doolittle_4, 1e-1); + test_analytical_hires, VectorStateTypeMozart<1>>(backward_euler_vector_mozart_1, 1e-1); + test_analytical_hires, VectorStateTypeMozart<2>>(backward_euler_vector_mozart_2, 1e-1); + test_analytical_hires, VectorStateTypeMozart<3>>(backward_euler_vector_mozart_3, 1e-1); + test_analytical_hires, VectorStateTypeMozart<4>>(backward_euler_vector_mozart_4, 1e-1); } TEST(AnalyticalExamples, Oregonator) { test_analytical_oregonator(backward_euler, 1e-3); + test_analytical_oregonator, VectorStateType<1>>(backard_euler_vector_1, 1e-3); + test_analytical_oregonator, VectorStateType<2>>(backard_euler_vector_2, 1e-3); + test_analytical_oregonator, VectorStateType<3>>(backard_euler_vector_3, 1e-3); + test_analytical_oregonator, VectorStateType<4>>(backard_euler_vector_4, 1e-3); + test_analytical_oregonator, VectorStateTypeDoolittle<1>>(backward_euler_vector_doolittle_1, 1e-3); + test_analytical_oregonator, VectorStateTypeDoolittle<2>>(backward_euler_vector_doolittle_2, 1e-3); + test_analytical_oregonator, VectorStateTypeDoolittle<3>>(backward_euler_vector_doolittle_3, 1e-3); + test_analytical_oregonator, VectorStateTypeDoolittle<4>>(backward_euler_vector_doolittle_4, 1e-3); + test_analytical_oregonator, VectorStateTypeMozart<1>>(backward_euler_vector_mozart_1, 1e-3); + test_analytical_oregonator, VectorStateTypeMozart<2>>(backward_euler_vector_mozart_2, 1e-3); + test_analytical_oregonator, VectorStateTypeMozart<3>>(backward_euler_vector_mozart_3, 1e-3); + test_analytical_oregonator, VectorStateTypeMozart<4>>(backward_euler_vector_mozart_4, 1e-3); } diff --git a/test/integration/test_analytical_rosenbrock.cpp b/test/integration/test_analytical_rosenbrock.cpp index 0c9799cd5..2c31cf62f 100644 --- a/test/integration/test_analytical_rosenbrock.cpp +++ b/test/integration/test_analytical_rosenbrock.cpp @@ -18,6 +18,44 @@ using VectorRosenbrock = micm::CpuSolverBuilder< micm::RosenbrockSolverParameters, micm::VectorMatrix, micm::SparseMatrix>>; + +using StandardRosenbrockDoolittle = micm::CpuSolverBuilder< + micm::RosenbrockSolverParameters, + micm::Matrix, + micm::SparseMatrix, + micm::LuDecompositionDoolittle>; +using StandardStateTypeDoolittle = micm::State, micm::SparseMatrix, micm::LuDecompositionDoolittle>; + +template +using VectorRosenbrockDoolittle = micm::CpuSolverBuilder< + micm::RosenbrockSolverParameters, + micm::VectorMatrix, + micm::SparseMatrix>, + micm::LuDecompositionDoolittle>; + +template +using VectorStateTypeDoolittle = + micm::State, micm::SparseMatrix>, micm::LuDecompositionDoolittle>; + +using StandardRosenbrockMozart = micm::CpuSolverBuilder< + micm::RosenbrockSolverParameters, + micm::Matrix, + micm::SparseMatrix, + micm::LuDecompositionMozart>; + +using StandardStateTypeMozart = micm::State, micm::SparseMatrix, micm::LuDecompositionMozart>; + +template +using VectorRosenbrockMozart = micm::CpuSolverBuilder< + micm::RosenbrockSolverParameters, + micm::VectorMatrix, + micm::SparseMatrix>, + micm::LuDecompositionMozart>; + +template +using VectorStateTypeMozart = + micm::State, micm::SparseMatrix>, micm::LuDecompositionMozart>; + template using VectorStateType = micm::State, micm::SparseMatrix>>; @@ -38,6 +76,17 @@ auto rosenbrock_vector_2 = VectorRosenbrock<2>(micm::RosenbrockSolverParameters: auto rosenbrock_vector_3 = VectorRosenbrock<3>(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); auto rosenbrock_vector_4 = VectorRosenbrock<4>(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); +auto rosenbrock_standard_doolittle = StandardRosenbrockDoolittle(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); +auto rosenbrock_vector_doolittle_1 = VectorRosenbrockDoolittle<1>(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); +auto rosenbrock_vector_doolittle_2 = VectorRosenbrockDoolittle<2>(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); +auto rosenbrock_vector_doolittle_3 = VectorRosenbrockDoolittle<3>(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); +auto rosenbrock_vector_doolittle_4 = VectorRosenbrockDoolittle<4>(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); +auto rosenbrock_standard_mozart = StandardRosenbrockMozart(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); +auto rosenbrock_vector_mozart_1 = VectorRosenbrockMozart<1>(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); +auto rosenbrock_vector_mozart_2 = VectorRosenbrockMozart<2>(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); +auto rosenbrock_vector_mozart_3 = VectorRosenbrockMozart<3>(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); +auto rosenbrock_vector_mozart_4 = VectorRosenbrockMozart<4>(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters()); + TEST(AnalyticalExamples, Troe) { test_analytical_troe(rosenbrock_2stage); @@ -49,6 +98,16 @@ TEST(AnalyticalExamples, Troe) test_analytical_troe, VectorStateType<2>>(rosenbrock_vector_2); test_analytical_troe, VectorStateType<3>>(rosenbrock_vector_3); test_analytical_troe, VectorStateType<4>>(rosenbrock_vector_4); + test_analytical_troe(rosenbrock_standard_doolittle); + test_analytical_troe, VectorStateTypeDoolittle<1>>(rosenbrock_vector_doolittle_1); + test_analytical_troe, VectorStateTypeDoolittle<2>>(rosenbrock_vector_doolittle_2); + test_analytical_troe, VectorStateTypeDoolittle<3>>(rosenbrock_vector_doolittle_3); + test_analytical_troe, VectorStateTypeDoolittle<4>>(rosenbrock_vector_doolittle_4); + test_analytical_troe(rosenbrock_standard_mozart); + test_analytical_troe, VectorStateTypeMozart<1>>(rosenbrock_vector_mozart_1); + test_analytical_troe, VectorStateTypeMozart<2>>(rosenbrock_vector_mozart_2); + test_analytical_troe, VectorStateTypeMozart<3>>(rosenbrock_vector_mozart_3); + test_analytical_troe, VectorStateTypeMozart<4>>(rosenbrock_vector_mozart_4); } TEST(AnalyticalExamples, TroeSuperStiffButAnalytical) @@ -217,6 +276,31 @@ TEST(AnalyticalExamples, Robertson) solver = rosenbrock_solver(micm::RosenbrockSolverParameters::SixStageDifferentialAlgebraicRosenbrockParameters()); test_analytical_robertson(solver, 1e-1); + + auto params = micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters(); + params.relative_tolerance_ = 1e-10; + params.absolute_tolerance_ = std::vector(3, params.relative_tolerance_ * 1e-2); + + auto standard_dootlittle = StandardRosenbrockDoolittle(params); + test_analytical_robertson(standard_dootlittle, 1e-1); + auto vector_1_dootlittle = VectorRosenbrockDoolittle<1>(params); + test_analytical_robertson, VectorStateTypeDoolittle<1>>(vector_1_dootlittle, 1e-1); + auto vector_2_dootlittle = VectorRosenbrockDoolittle<2>(params); + test_analytical_robertson, VectorStateTypeDoolittle<2>>(vector_2_dootlittle, 1e-1); + auto vector_3_dootlittle = VectorRosenbrockDoolittle<3>(params); + test_analytical_robertson, VectorStateTypeDoolittle<3>>(vector_3_dootlittle, 1e-1); + auto vector_4_dootlittle = VectorRosenbrockDoolittle<4>(params); + test_analytical_robertson, VectorStateTypeDoolittle<4>>(vector_4_dootlittle, 1e-1); + auto standard_mozart = StandardRosenbrockMozart(params); + test_analytical_robertson(standard_mozart, 1e-1); + auto vector_1_mozart = VectorRosenbrockMozart<1>(params); + test_analytical_robertson, VectorStateTypeMozart<1>>(vector_1_mozart, 1e-1); + auto vector_2_mozart = VectorRosenbrockMozart<2>(params); + test_analytical_robertson, VectorStateTypeMozart<2>>(vector_2_mozart, 1e-1); + auto vector_3_mozart = VectorRosenbrockMozart<3>(params); + test_analytical_robertson, VectorStateTypeMozart<3>>(vector_3_mozart, 1e-1); + auto vector_4_mozart = VectorRosenbrockMozart<4>(params); + test_analytical_robertson, VectorStateTypeMozart<4>>(vector_4_mozart, 1e-1); } TEST(AnalyticalExamples, E5) @@ -248,6 +332,35 @@ TEST(AnalyticalExamples, E5) solver = rosenbrock_solver(micm::RosenbrockSolverParameters::SixStageDifferentialAlgebraicRosenbrockParameters()); test_analytical_e5(solver, 1e-3); + + auto params = micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters(); + params.relative_tolerance_ = 1e-13; + params.absolute_tolerance_ = std::vector(6, 1e-17); + params.absolute_tolerance_[0] = 1e-7; + params.absolute_tolerance_[4] = 1e-7; + params.absolute_tolerance_[5] = 1e-7; + + auto standard_dootlittle = StandardRosenbrockDoolittle(params); + test_analytical_e5(standard_dootlittle, 1e-3); + auto vector_1_dootlittle = VectorRosenbrockDoolittle<1>(params); + test_analytical_e5, VectorStateTypeDoolittle<1>>(vector_1_dootlittle, 1e-3); + auto vector_2_dootlittle = VectorRosenbrockDoolittle<2>(params); + test_analytical_e5, VectorStateTypeDoolittle<2>>(vector_2_dootlittle, 1e-3); + auto vector_3_dootlittle = VectorRosenbrockDoolittle<3>(params); + test_analytical_e5, VectorStateTypeDoolittle<3>>(vector_3_dootlittle, 1e-3); + auto vector_4_dootlittle = VectorRosenbrockDoolittle<4>(params); + test_analytical_e5, VectorStateTypeDoolittle<4>>(vector_4_dootlittle, 1e-3); + auto standard_mozart = StandardRosenbrockMozart(params); + test_analytical_e5(standard_mozart, 1e-3); + auto vector_1_mozart = VectorRosenbrockMozart<1>(params); + test_analytical_e5, VectorStateTypeMozart<1>>(vector_1_mozart, 1e-3); + auto vector_2_mozart = VectorRosenbrockMozart<2>(params); + test_analytical_e5, VectorStateTypeMozart<2>>(vector_2_mozart, 1e-3); + auto vector_3_mozart = VectorRosenbrockMozart<3>(params); + test_analytical_e5, VectorStateTypeMozart<3>>(vector_3_mozart, 1e-3); + auto vector_4_mozart = VectorRosenbrockMozart<4>(params); + test_analytical_e5, VectorStateTypeMozart<4>>(vector_4_mozart, 1e-3); + } TEST(AnalyticalExamples, Oregonator) @@ -274,6 +387,31 @@ TEST(AnalyticalExamples, Oregonator) solver = rosenbrock_solver(micm::RosenbrockSolverParameters::SixStageDifferentialAlgebraicRosenbrockParameters()); test_analytical_oregonator(solver, 4e-6); + + auto params = micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters(); + params.relative_tolerance_ = 1e-8; + params.absolute_tolerance_ = std::vector(5, params.relative_tolerance_ * 1e-6); + + auto standard_dootlittle = StandardRosenbrockDoolittle(params); + test_analytical_oregonator(standard_dootlittle, 4e-6); + auto vector_1_dootlittle = VectorRosenbrockDoolittle<1>(params); + test_analytical_oregonator, VectorStateTypeDoolittle<1>>(vector_1_dootlittle, 4e-6); + auto vector_2_dootlittle = VectorRosenbrockDoolittle<2>(params); + test_analytical_oregonator, VectorStateTypeDoolittle<2>>(vector_2_dootlittle, 4e-6); + auto vector_3_dootlittle = VectorRosenbrockDoolittle<3>(params); + test_analytical_oregonator, VectorStateTypeDoolittle<3>>(vector_3_dootlittle, 4e-6); + auto vector_4_dootlittle = VectorRosenbrockDoolittle<4>(params); + test_analytical_oregonator, VectorStateTypeDoolittle<4>>(vector_4_dootlittle, 4e-6); + auto standard_mozart = StandardRosenbrockMozart(params); + test_analytical_oregonator(standard_mozart, 4e-6); + auto vector_1_mozart = VectorRosenbrockMozart<1>(params); + test_analytical_oregonator, VectorStateTypeMozart<1>>(vector_1_mozart, 4e-6); + auto vector_2_mozart = VectorRosenbrockMozart<2>(params); + test_analytical_oregonator, VectorStateTypeMozart<2>>(vector_2_mozart, 4e-6); + auto vector_3_mozart = VectorRosenbrockMozart<3>(params); + test_analytical_oregonator, VectorStateTypeMozart<3>>(vector_3_mozart, 4e-6); + auto vector_4_mozart = VectorRosenbrockMozart<4>(params); + test_analytical_oregonator, VectorStateTypeMozart<4>>(vector_4_mozart, 4e-6); } TEST(AnalyticalExamples, SurfaceRxn) @@ -308,4 +446,29 @@ TEST(AnalyticalExamples, HIRES) solver = rosenbrock_solver(micm::RosenbrockSolverParameters::SixStageDifferentialAlgebraicRosenbrockParameters()); test_analytical_hires(solver, 1e-6); + + auto params = micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters(); + params.relative_tolerance_ = 1e-6; + params.absolute_tolerance_ = std::vector(8, params.relative_tolerance_ * 1e-2); + + auto standard_dootlittle = StandardRosenbrockDoolittle(params); + test_analytical_hires(standard_dootlittle, 1e-7); + auto vector_1_dootlittle = VectorRosenbrockDoolittle<1>(params); + test_analytical_hires, VectorStateTypeDoolittle<1>>(vector_1_dootlittle, 1e-7); + auto vector_2_dootlittle = VectorRosenbrockDoolittle<2>(params); + test_analytical_hires, VectorStateTypeDoolittle<2>>(vector_2_dootlittle, 1e-7); + auto vector_3_dootlittle = VectorRosenbrockDoolittle<3>(params); + test_analytical_hires, VectorStateTypeDoolittle<3>>(vector_3_dootlittle, 1e-7); + auto vector_4_dootlittle = VectorRosenbrockDoolittle<4>(params); + test_analytical_hires, VectorStateTypeDoolittle<4>>(vector_4_dootlittle, 1e-7); + auto standard_mozart = StandardRosenbrockMozart(params); + test_analytical_hires(standard_mozart, 1e-7); + auto vector_1_mozart = VectorRosenbrockMozart<1>(params); + test_analytical_hires, VectorStateTypeMozart<1>>(vector_1_mozart, 1e-7); + auto vector_2_mozart = VectorRosenbrockMozart<2>(params); + test_analytical_hires, VectorStateTypeMozart<2>>(vector_2_mozart, 1e-7); + auto vector_3_mozart = VectorRosenbrockMozart<3>(params); + test_analytical_hires, VectorStateTypeMozart<3>>(vector_3_mozart, 1e-7); + auto vector_4_mozart = VectorRosenbrockMozart<4>(params); + test_analytical_hires, VectorStateTypeMozart<4>>(vector_4_mozart, 1e-7); }