Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 3 additions & 7 deletions source/material_model/reaction_model/reaction_chain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace aspect

// Reaction progress values should be close to monotonic
for (unsigned int i = 1; i < reaction_progress_values.size(); ++i)
AssertThrow(reaction_progress_values[i] < reaction_progress_values[i-1] + tolerance_in_reaction_progress,
AssertThrow(reaction_progress_values[i] <= reaction_progress_values[i-1] + tolerance_in_reaction_progress,
ExcMessage("'reaction_progress_values[" + std::to_string(i) + "]' = " +
std::to_string(reaction_progress_values[i]) + " exceeds "
"'reaction_progress_values[" + std::to_string(i-1) + "]' = " +
Expand Down Expand Up @@ -176,9 +176,9 @@ namespace aspect
"sets the number of reactions N, which must equal the number of compositional fields tracking reaction progress.");

prm.declare_entry("Tolerance in reaction progress",
"0.1",
"1e20",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the problem you described: "Model immediately crashes during initialization or after a few timesteps". Is that because the model can start off with a very large reaction rate and it gets to a large value, so it requires the tolerance to be large?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is basically what we observed during testing.

However, the issue actually related to the over/undershoot problem that we are addressing in separate PRs (buchanankerswell#1 and #7482). If the operator splitting integration maintains strict [0, 1] bounds, then you don't get the same blow-up even if ASPECT is initialized with very large reaction rates.

This PR is more of a safeguard that sets a large reaction progress tolerance by default until those other kinks are worked out.

Patterns::Double(0.0),
"Allowed excursion before a reaction progress value outside [0, 1] is considered unphysical.");
"Allowed excursion before a reaction progress value outside [0, 1] is considered too extreme for a given timestep.");

// One subsection per registered kinetics model (not per reaction).
ReactionModelPluginList<dim>::declare_parameters(prm);
Expand All @@ -196,10 +196,6 @@ namespace aspect
{
tolerance_in_reaction_progress = prm.get_double("Tolerance in reaction progress");

AssertThrow(tolerance_in_reaction_progress >= 0.0 && tolerance_in_reaction_progress < 1.0,
ExcMessage("The 'Tolerance in reaction progress' must be between [0, 1), "
"but was set to " + std::to_string(tolerance_in_reaction_progress) + "."));

const std::vector<std::string> kinetic_model_names = Utilities::split_string_list(prm.get("Kinetic models"), '|');
const unsigned int n_reactions = kinetic_model_names.size();

Expand Down
63 changes: 39 additions & 24 deletions unit_tests/reaction_model_kinetics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ TEST_CASE("Reaction Chain Processing")
prm.enter_subsection("Reaction chain");
{
prm.set("Kinetic models", "Interface controlled growth|Eutectoid decomposition|Interface controlled growth");
prm.set("Tolerance in reaction progress", "0.05");

prm.enter_subsection("Interface controlled growth");
{
Expand Down Expand Up @@ -249,15 +248,49 @@ TEST_CASE("Reaction Chain Processing")
compare_vectors_approx(xi_clamped, expected);
}

SECTION("Clamping throws on non-physical bounds exceeding tolerance")
SECTION("Without strict tolerance, out-of-range and non-monotonic values are clamped")
{
CHECK_THROWS_AS(reaction_chain.clamp_cumulative_progress({1.06, 0.5, 0.1}), dealii::ExceptionBase);
CHECK_THROWS_AS(reaction_chain.clamp_cumulative_progress({0.8, 0.5, -0.06}), dealii::ExceptionBase);
// Values below 0 (reverse reaction completed) or above 1 (forward reaction completed) are clamped to [0, 1]
compare_vectors_approx(reaction_chain.clamp_cumulative_progress({1.06, 0.5, 0.1}), {1.0, 0.5, 0.1});
compare_vectors_approx(reaction_chain.clamp_cumulative_progress({0.8, 0.5, -0.06}), {0.8, 0.5, 0.0});

// Non-monotonic values are clamped to enforce xi[i] <= xi[i-1]
compare_vectors_approx(reaction_chain.clamp_cumulative_progress({0.80, 0.87, 0.1}), {0.80, 0.80, 0.1});
}

SECTION("Clamping throws on non-monotonic values exceeding tolerance")
SECTION("With strict tolerance, out-of-range and non-monotonic values throw")
{
CHECK_THROWS_AS(reaction_chain.clamp_cumulative_progress({0.80, 0.87, 0.1}), dealii::ExceptionBase);
dealii::ParameterHandler strict_prm;
ReactionChain<2> strict_reaction_chain;
ReactionChain<2>::declare_parameters(strict_prm);

strict_prm.enter_subsection("Reaction chain");
{
strict_prm.set("Kinetic models", "Interface controlled growth|Eutectoid decomposition|Interface controlled growth");
strict_prm.set("Tolerance in reaction progress", "0.05");

strict_prm.enter_subsection("Interface controlled growth");
{
strict_prm.set("Kinetic prefactors", "7.0e7|7.0e7");
strict_prm.set("Activation enthalpies", "274e3|274e3");
strict_prm.set("Activation volumes", "3.3e-6|3.3e-6");
}
strict_prm.leave_subsection();

strict_prm.enter_subsection("Eutectoid decomposition");
{
strict_prm.set("Kinetic prefactors", "2.7e-16");
strict_prm.set("Activation energies", "355e3");
}
strict_prm.leave_subsection();
}
strict_prm.leave_subsection();

strict_reaction_chain.parse_parameters(strict_prm);

CHECK_THROWS_AS(strict_reaction_chain.clamp_cumulative_progress({1.06, 0.5, 0.1}), dealii::ExceptionBase);
CHECK_THROWS_AS(strict_reaction_chain.clamp_cumulative_progress({0.8, 0.5, -0.06}), dealii::ExceptionBase);
CHECK_THROWS_AS(strict_reaction_chain.clamp_cumulative_progress({0.80, 0.87, 0.1}), dealii::ExceptionBase);
}

SECTION("Clamping throws on NaN or Inf input")
Expand Down Expand Up @@ -422,22 +455,4 @@ TEST_CASE("Reaction Chain Kinetic Models Parsing")

CHECK(parsed_default == "Interface controlled growth");
}

SECTION("Parsing throws on invalid 'Tolerance in reaction progress'")
{
SECTION("Tolerance >= 1.0 throws")
{
dealii::ParameterHandler prm;
ReactionChain<2> reaction_chain;
ReactionChain<2>::declare_parameters(prm);

prm.enter_subsection("Reaction chain");
{
prm.set("Tolerance in reaction progress", "1.0");
}
prm.leave_subsection();

CHECK_THROWS_AS(reaction_chain.parse_parameters(prm), dealii::ExceptionBase);
}
}
}
Loading