Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing backward euler with most of the analytical tests #576

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/micm/solver/backward_euler.inl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace micm

while (t < time_step)
{
result.state_ = SolverState::Running;
bool converged = false;
std::size_t iterations = 0;

Expand Down Expand Up @@ -182,6 +183,7 @@ namespace micm
}
else
{
result.state_ = SolverState::Converged;
t += H;
Yn = Yn1;

Expand Down
18 changes: 9 additions & 9 deletions test/integration/analytical_jit_rosenbrock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TEST(AnalyticalExamplesJitRosenbrock, TroeSuperStiffButAnalytical)
{
auto builder = micm::JitSolverBuilder<micm::JitRosenbrockSolverParameters, L>(
micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters());
test_analytical_stiff_troe(builder);
test_analytical_stiff_troe(builder, 1e-4);
}

TEST(AnalyticalExamplesJitRosenbrock, Photolysis)
Expand All @@ -34,7 +34,7 @@ TEST(AnalyticalExamplesJitRosenbrock, PhotolysisSuperStiffButAnalytical)
{
auto builder = micm::JitSolverBuilder<micm::JitRosenbrockSolverParameters, L>(
micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters());
test_analytical_stiff_photolysis(builder);
test_analytical_stiff_photolysis(builder, 1e-4);
}

TEST(AnalyticalExamplesJitRosenbrock, TernaryChemicalActivation)
Expand All @@ -48,7 +48,7 @@ TEST(AnalyticalExamplesJitRosenbrock, TernaryChemicalActivationSuperStiffButAnal
{
auto builder = micm::JitSolverBuilder<micm::JitRosenbrockSolverParameters, L>(
micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters());
test_analytical_stiff_ternary_chemical_activation(builder);
test_analytical_stiff_ternary_chemical_activation(builder, 1e-4);
}

TEST(AnalyticalExamplesJitRosenbrock, Tunneling)
Expand All @@ -62,7 +62,7 @@ TEST(AnalyticalExamplesJitRosenbrock, TunnelingSuperStiffButAnalytical)
{
auto builder = micm::JitSolverBuilder<micm::JitRosenbrockSolverParameters, L>(
micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters());
test_analytical_stiff_tunneling(builder);
test_analytical_stiff_tunneling(builder, 1e-4);
}

TEST(AnalyticalExamplesJitRosenbrock, Arrhenius)
Expand All @@ -76,33 +76,33 @@ TEST(AnalyticalExamplesJitRosenbrock, ArrheniusSuperStiffButAnalytical)
{
auto builder = micm::JitSolverBuilder<micm::JitRosenbrockSolverParameters, L>(
micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters());
test_analytical_stiff_arrhenius(builder);
test_analytical_stiff_arrhenius(builder, 1e-4);
}

TEST(AnalyticalExamplesJitRosenbrock, Branched)
{
auto builder = micm::JitSolverBuilder<micm::JitRosenbrockSolverParameters, L>(
micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters());
test_analytical_branched(builder);
test_analytical_branched(builder, 1e-3);
}

TEST(AnalyticalExamplesJitRosenbrock, BranchedSuperStiffButAnalytical)
{
auto builder = micm::JitSolverBuilder<micm::JitRosenbrockSolverParameters, L>(
micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters());
test_analytical_stiff_branched(builder);
test_analytical_stiff_branched(builder, 1e-3);
}

TEST(AnalyticalExamplesJitRosenbrock, Robertson)
{
auto builder = micm::JitSolverBuilder<micm::JitRosenbrockSolverParameters, L>(
micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters());
test_analytical_robertson(builder);
test_analytical_robertson(builder, 1e-1);
}

TEST(AnalyticalExamplesJitRosenbrock, SurfaceRxn)
{
auto builder = micm::JitSolverBuilder<micm::JitRosenbrockSolverParameters, L>(
micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters());
test_analytical_surface_rxn(builder);
test_analytical_surface_rxn(builder, 1e-4);
}
105 changes: 52 additions & 53 deletions test/integration/analytical_policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ using yields = std::pair<micm::Species, double>;
using SparseMatrixTest = micm::SparseMatrix<double>;

template<class BuilderPolicy>
void test_analytical_troe(BuilderPolicy& builder)
void test_analytical_troe(BuilderPolicy& builder, double tolerance = 1e-8)
{
/*
* A -> B, k1
Expand Down Expand Up @@ -189,17 +189,17 @@ void test_analytical_troe(BuilderPolicy& builder)

for (size_t i = 0; i < model_concentrations.size(); ++i)
{
EXPECT_NEAR(model_concentrations[i][_a], analytical_concentrations[i][0], 1e-8)
EXPECT_NEAR(model_concentrations[i][_a], analytical_concentrations[i][0], tolerance)
<< "Arrays differ at index (" << i << ", " << 0 << ")";
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], 1e-8)
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], tolerance)
<< "Arrays differ at index (" << i << ", " << 1 << ")";
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], 1e-8)
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], tolerance)
<< "Arrays differ at index (" << i << ", " << 2 << ")";
}
}

template<class BuilderPolicy>
void test_analytical_stiff_troe(BuilderPolicy& builder)
void test_analytical_stiff_troe(BuilderPolicy& builder, double tolerance = 1e-8)
{
/*
* A1 -> B, k1
Expand Down Expand Up @@ -330,14 +330,14 @@ void test_analytical_stiff_troe(BuilderPolicy& builder)

for (size_t i = 0; i < model_concentrations.size(); ++i)
{
EXPECT_NEAR(model_concentrations[i][_a1] + model_concentrations[i][_a2], analytical_concentrations[i][0], 1e-4);
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], 1e-4);
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], 1e-4);
EXPECT_NEAR(model_concentrations[i][_a1] + model_concentrations[i][_a2], analytical_concentrations[i][0], tolerance);
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], tolerance);
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], tolerance);
}
}

template<class BuilderPolicy>
void test_analytical_photolysis(BuilderPolicy& builder)
void test_analytical_photolysis(BuilderPolicy& builder, double tolerance = 1e-8)
{
/*
* A -> B, k1
Expand Down Expand Up @@ -433,17 +433,17 @@ void test_analytical_photolysis(BuilderPolicy& builder)

for (size_t i = 0; i < model_concentrations.size(); ++i)
{
EXPECT_NEAR(model_concentrations[i][_a], analytical_concentrations[i][0], 1e-8)
EXPECT_NEAR(model_concentrations[i][_a], analytical_concentrations[i][0], tolerance)
<< "Arrays differ at index (" << i << ", " << 0 << ")";
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], 1e-8)
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], tolerance)
<< "Arrays differ at index (" << i << ", " << 1 << ")";
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], 1e-8)
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], tolerance)
<< "Arrays differ at index (" << i << ", " << 2 << ")";
}
}

template<class BuilderPolicy>
void test_analytical_stiff_photolysis(BuilderPolicy& builder)
void test_analytical_stiff_photolysis(BuilderPolicy& builder, double tolerance = 1e-8)
{
/*
* A1 -> B, k1
Expand Down Expand Up @@ -566,14 +566,14 @@ void test_analytical_stiff_photolysis(BuilderPolicy& builder)

for (size_t i = 0; i < model_concentrations.size(); ++i)
{
EXPECT_NEAR(model_concentrations[i][_a1] + model_concentrations[i][_a2], analytical_concentrations[i][0], 1e-4);
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], 1e-4);
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], 1e-4);
EXPECT_NEAR(model_concentrations[i][_a1] + model_concentrations[i][_a2], analytical_concentrations[i][0], tolerance);
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], tolerance);
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], tolerance);
}
}

template<class BuilderPolicy>
void test_analytical_ternary_chemical_activation(BuilderPolicy& builder)
void test_analytical_ternary_chemical_activation(BuilderPolicy& builder, double tolerance = 1e-8)
{
/*
* A -> B, k1
Expand Down Expand Up @@ -680,17 +680,17 @@ void test_analytical_ternary_chemical_activation(BuilderPolicy& builder)

for (size_t i = 0; i < model_concentrations.size(); ++i)
{
EXPECT_NEAR(model_concentrations[i][_a], analytical_concentrations[i][0], 1e-8)
EXPECT_NEAR(model_concentrations[i][_a], analytical_concentrations[i][0], tolerance)
<< "Arrays differ at index (" << i << ", " << 0 << ")";
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], 1e-8)
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], tolerance)
<< "Arrays differ at index (" << i << ", " << 1 << ")";
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], 1e-8)
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], tolerance)
<< "Arrays differ at index (" << i << ", " << 2 << ")";
}
}

template<class BuilderPolicy>
void test_analytical_stiff_ternary_chemical_activation(BuilderPolicy& builder)
void test_analytical_stiff_ternary_chemical_activation(BuilderPolicy& builder, double tolerance = 1e-8)
{
/*
* A1 -> B, k1
Expand Down Expand Up @@ -821,14 +821,14 @@ void test_analytical_stiff_ternary_chemical_activation(BuilderPolicy& builder)

for (size_t i = 0; i < model_concentrations.size(); ++i)
{
EXPECT_NEAR(model_concentrations[i][_a1] + model_concentrations[i][_a2], analytical_concentrations[i][0], 1e-4);
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], 1e-4);
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], 1e-4);
EXPECT_NEAR(model_concentrations[i][_a1] + model_concentrations[i][_a2], analytical_concentrations[i][0], tolerance);
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], tolerance);
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], tolerance);
}
}

template<class BuilderPolicy>
void test_analytical_tunneling(BuilderPolicy& builder)
void test_analytical_tunneling(BuilderPolicy& builder, double tolerance = 1e-8)
{
/*
* A -> B, k1
Expand Down Expand Up @@ -922,17 +922,17 @@ void test_analytical_tunneling(BuilderPolicy& builder)

for (size_t i = 0; i < model_concentrations.size(); ++i)
{
EXPECT_NEAR(model_concentrations[i][_a], analytical_concentrations[i][0], 1e-8)
EXPECT_NEAR(model_concentrations[i][_a], analytical_concentrations[i][0], tolerance)
<< "Arrays differ at index (" << i << ", " << 0 << ")";
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], 1e-8)
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], tolerance)
<< "Arrays differ at index (" << i << ", " << 1 << ")";
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], 1e-8)
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], tolerance)
<< "Arrays differ at index (" << i << ", " << 2 << ")";
}
}

template<class BuilderPolicy>
void test_analytical_stiff_tunneling(BuilderPolicy& builder)
void test_analytical_stiff_tunneling(BuilderPolicy& builder, double tolerance = 1e-8)
{
/*
* A1 -> B, k1
Expand Down Expand Up @@ -1050,17 +1050,17 @@ void test_analytical_stiff_tunneling(BuilderPolicy& builder)

for (size_t i = 0; i < model_concentrations.size(); ++i)
{
EXPECT_NEAR(model_concentrations[i][_a1] + model_concentrations[i][_a2], analytical_concentrations[i][0], 1e-4)
EXPECT_NEAR(model_concentrations[i][_a1] + model_concentrations[i][_a2], analytical_concentrations[i][0], tolerance)
<< "Arrays differ at index (" << i << ", " << 0 << ")";
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], 1e-4)
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], tolerance)
<< "Arrays differ at index (" << i << ", " << 1 << ")";
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], 1e-4)
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], tolerance)
<< "Arrays differ at index (" << i << ", " << 2 << ")";
}
}

template<class BuilderPolicy>
void test_analytical_arrhenius(BuilderPolicy& builder)
void test_analytical_arrhenius(BuilderPolicy& builder, double tolerance = 1e-8)
{
/*
* A -> B, k1
Expand Down Expand Up @@ -1153,17 +1153,17 @@ void test_analytical_arrhenius(BuilderPolicy& builder)

for (size_t i = 0; i < model_concentrations.size(); ++i)
{
EXPECT_NEAR(model_concentrations[i][_a], analytical_concentrations[i][0], 1e-8)
EXPECT_NEAR(model_concentrations[i][_a], analytical_concentrations[i][0], tolerance)
<< "Arrays differ at index (" << i << ", " << 0 << ")";
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], 1e-8)
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], tolerance)
<< "Arrays differ at index (" << i << ", " << 1 << ")";
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], 1e-8)
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], tolerance)
<< "Arrays differ at index (" << i << ", " << 2 << ")";
}
}

template<class BuilderPolicy>
void test_analytical_stiff_arrhenius(BuilderPolicy& builder)
void test_analytical_stiff_arrhenius(BuilderPolicy& builder, double tolerance = 1e-8)
{
/*
* A1 -> B, k1
Expand Down Expand Up @@ -1282,17 +1282,17 @@ void test_analytical_stiff_arrhenius(BuilderPolicy& builder)

for (size_t i = 0; i < model_concentrations.size(); ++i)
{
EXPECT_NEAR(model_concentrations[i][_a1] + model_concentrations[i][_a2], analytical_concentrations[i][0], 1e-4)
EXPECT_NEAR(model_concentrations[i][_a1] + model_concentrations[i][_a2], analytical_concentrations[i][0], tolerance)
<< "Arrays differ at index (" << i << ", " << 0 << ")";
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], 1e-4)
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], tolerance)
<< "Arrays differ at index (" << i << ", " << 1 << ")";
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], 1e-4)
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], tolerance)
<< "Arrays differ at index (" << i << ", " << 2 << ")";
}
}

template<class BuilderPolicy>
void test_analytical_branched(BuilderPolicy& builder)
void test_analytical_branched(BuilderPolicy& builder, double tolerance = 1e-8)
{
/*
* A -> B, k1
Expand Down Expand Up @@ -1410,17 +1410,17 @@ void test_analytical_branched(BuilderPolicy& builder)

for (size_t i = 0; i < model_concentrations.size(); ++i)
{
EXPECT_NEAR(model_concentrations[i][_a], analytical_concentrations[i][0], 1e-3)
EXPECT_NEAR(model_concentrations[i][_a], analytical_concentrations[i][0], tolerance)
<< "Arrays differ at index (" << i << ", " << 0 << ")";
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], 1e-3)
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], tolerance)
<< "Arrays differ at index (" << i << ", " << 1 << ")";
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], 1e-3)
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], tolerance)
<< "Arrays differ at index (" << i << ", " << 2 << ")";
}
}

template<class BuilderPolicy>
void test_analytical_stiff_branched(BuilderPolicy& builder)
void test_analytical_stiff_branched(BuilderPolicy& builder, double tolerance = 1e-8)
{
/*
* A1 -> B, k1
Expand Down Expand Up @@ -1568,17 +1568,17 @@ void test_analytical_stiff_branched(BuilderPolicy& builder)

for (size_t i = 0; i < model_concentrations.size(); ++i)
{
EXPECT_NEAR(model_concentrations[i][_a1] + model_concentrations[i][_a2], analytical_concentrations[i][0], 1e-3)
EXPECT_NEAR(model_concentrations[i][_a1] + model_concentrations[i][_a2], analytical_concentrations[i][0], tolerance)
<< "Arrays differ at index (" << i << ", " << 0 << ")";
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], 1e-3)
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], tolerance)
<< "Arrays differ at index (" << i << ", " << 1 << ")";
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], 1e-3)
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], tolerance)
<< "Arrays differ at index (" << i << ", " << 2 << ")";
}
}

template<class BuilderPolicy>
void test_analytical_robertson(BuilderPolicy& builder)
void test_analytical_robertson(BuilderPolicy& builder, double tolerance = 1e-8)
{
/*
* A -> B, k1 = 0.04
Expand Down Expand Up @@ -1690,14 +1690,13 @@ void test_analytical_robertson(BuilderPolicy& builder)
size_t _b = map.at("B");
size_t _c = map.at("C");

double tol = 1e-1;
for (size_t i = 0; i < model_concentrations.size(); ++i)
{
EXPECT_NEAR(model_concentrations[i][_a], analytical_concentrations[i][0], tol)
EXPECT_NEAR(model_concentrations[i][_a], analytical_concentrations[i][0], tolerance)
<< "Arrays differ at index (" << i << ", " << 0 << ")";
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], tol)
EXPECT_NEAR(model_concentrations[i][_b], analytical_concentrations[i][1], tolerance)
<< "Arrays differ at index (" << i << ", " << 1 << ")";
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], tol)
EXPECT_NEAR(model_concentrations[i][_c], analytical_concentrations[i][2], tolerance)
<< "Arrays differ at index (" << i << ", " << 2 << ")";
}
}
Loading
Loading