Skip to content

Use reaction chain in visco plastic model - #7331

Open
lhy11009 wants to merge 4 commits into
geodynamics:mainfrom
lhy11009:visco_plastic_reaction_chain
Open

lhy11009 wants to merge 4 commits into
geodynamics:mainfrom
lhy11009:visco_plastic_reaction_chain

Conversation

@lhy11009

@lhy11009 lhy11009 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Pull Request Checklist. Please read and check each box with an X. Delete any part not applicable. Ask on the forum if you need help with any step.

This is a PR that modified the usage of reaction progress in the Visco Plastic model, with the new reaction chain interface from @buchanankerswell

Before your first pull request:

For all pull requests:

Codex does the actual implementation. I assure that I read all the lines and performed tests myself.

For new features/models or changes of existing features:

  • I have tested my new feature locally to ensure it is correct.
  • I have created a testcase for the new feature/benchmark in the tests/ directory.
  • I have added a changelog entry in the doc/modules/changes directory that will inform other users of my change.

@gassmoeller gassmoeller left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like it, we should make sure to use the new interface.

One question though: As far as I understand, this for now uses ReactionChain to clamp the reaction progress values, but it does not yet use ReactionChain to actually progress the reaction, do I understand this correctly?

Comment thread source/material_model/visco_plastic.cc Outdated
Comment on lines +504 to +518
const unsigned int n_reaction_progress_fields =
this->introspection().get_number_of_fields_of_type(CompositionalFieldDescription::reaction_progress);

if (n_reaction_progress_fields > 0)
{
reaction_chain.initialize_simulator(this->get_simulator());
reaction_chain.parse_parameters(prm);

AssertThrow(reaction_chain.n_reactions() == n_reaction_progress_fields,
ExcMessage("The number of reactions configured in 'Reaction chain/Kinetic models' must match "
"the number of reaction progress compositional fields."));
AssertThrow(reaction_progress_mapping.size() == n_reaction_progress_fields,
ExcMessage("The number of entries in 'Reaction progress mapping' must match the number of "
"reaction progress compositional fields."));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would say unconditionally always initialize and parse the reaction chain parameters, and move the asserts into the parse_parameters function of reaction_chain. This way you will always have a fully functional reaction_chain object, that may just happen to manage 0 reactions. But that is safer than the current state, in which reaction_chain may or may not be initialized.

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.

Changed. But there are questions. See my other comments

@buchanankerswell

buchanankerswell commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

I like it, we should make sure to use the new interface.

One question though: As far as I understand, this for now uses ReactionChain to clamp the reaction progress values, but it does not yet use ReactionChain to actually progress the reaction, do I understand this correctly?

Just wanted to flag something for your attention @gassmoeller and @lhy11009.

@lhy11009 may or may not have already noticed issue #7287 in this updated visco plastic model. I have two open PRs that ensure:

  1. the ReactionChain doesn't crash the simulation when reaction_progress fields under/overshoot [0, 1] Relax reaction progress tolerance by default (1e20) #7319
  2. that the material model can write the clamped progress back to the solution Add no-op hook to material model interface to clamp reaction progress… buchanankerswell/aspect#1 (e.g., see https://github.com/buchanankerswell/aspect/blob/7978d4d2fbbd310de76b37f72ff8b559afaf00c6/cookbooks/mtz_kinetics/mtz-kinetics.cc#L328-L345)

Together, these PRs solve #7287. I have tested this in cookbook #7119.

I would suggest we merge #7319 and buchanankerswell#1 before going too much further. Otherwise all material models with ReactionChain will run into issue #7287, including this one.

@gassmoeller

Copy link
Copy Markdown
Member

Good point. I wanted to get to your PRs next week. My comment above still applies, but we should figure out the other issues before merging this PR.

@lhy11009

lhy11009 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks to both of you for the heads-up.

I left my comments #7287

This is indeed an important issue to solve. Let me know how I can contribute. @buchanankerswell, would you be able to join the user meeting next Mon to discuss?

On the other hand, it wouldn't change much what we need to do in this PR.

@lhy11009

lhy11009 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

I like it, we should make sure to use the new interface.

One question though: As far as I understand, this for now uses ReactionChain to clamp the reaction progress values, but it does not yet use ReactionChain to actually progress the reaction, do I understand this correctly?

Exactly, that is the case.

In the existing test, I basically assign an initial value to the transition progress field.

My intention is to first connect all the interfaces before using ReactionChain to actually progress the reaction.

@lhy11009
lhy11009 force-pushed the visco_plastic_reaction_chain branch from 22dcdc2 to 2ded8e4 Compare September 5, 2026 18:00
Comment thread source/material_model/visco_plastic.cc Outdated
void
ViscoPlastic<dim>::initialize()
{
reaction_chain.initialize();

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.

I have put the initialize function here, but the initial_simulator call is in the parse_parameters. Feel free to suggest otherwise.

reaction_progress_mapping = Utilities::string_to_unsigned_int
(Utilities::split_string_list(prm.get ("Reaction progress mapping")));

AssertThrow(reaction_progress_mapping.size() == n_reaction_progress_fields,

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.

I leave this assert here, because this is checking the number of reaction_progress_mapping that is parsed in here.

Patterns::List(Patterns::Selection(ReactionModelPluginList<dim>::get_pattern_of_names()),
1, Patterns::List::max_int_value, "|"),
"",
Patterns::List(Patterns::Anything()),

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.

I have changed the patterns here, to allow 0 kinetic models by default, similar to the "name of fields" entry for the "Composition".

1, Patterns::List::max_int_value, "|"),
"",
Patterns::List(Patterns::Anything()),
"'|'-separated list of registered reaction kinetics model names, one per reaction in the chain. The number of entries "

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.

In addition, should we change "|" to ","?

const unsigned int n_reaction_progress_fields =
this->introspection().get_number_of_fields_of_type(CompositionalFieldDescription::reaction_progress);

AssertThrow(n_reactions == n_reaction_progress_fields,

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.

I move one of the asserts here. For these assertions to work, things should be parsed in this order: compositions -> reaction chains -> the assigned "mapping" in the material model. Tests passed, so this should be the case.

@lhy11009

lhy11009 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

@gassmoeller, please take another look when available. And check my posts above.

@lhy11009 lhy11009 mentioned this pull request Oct 7, 2026
6 of 7 tasks
@gassmoeller

Copy link
Copy Markdown
Member

Hi @lhy11009, very sorry this took so long. Your changes are ok, but I think there are quite a few things inside the ReactionChain class I would like to improve before activating it in ViscoPlastic. I will open a separate PR about that. In the meantime, can you check why the testers are not compiling with this PR? I think there is something wrong about the creation/initialization order of some objects.

@lhy11009

lhy11009 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

@gassmoeller, I also think it might be good to test the series of composite PRs before merging them. Last week, I found several things to update in the existing PRs by trying to put them in the same branch.

Do you think creating an issue with just bullet points of the potential changes is a good idea? This way, we can keep track of where the curve is.

@gassmoeller

Copy link
Copy Markdown
Member

Yes, I think it would be good to have an issue that tracks the progress on this.

Additionally I dont think we need to coordinate all your PRs from the start to work perfectly together. We can start with small independent pieces that individually make sense, and then adjust the larger pieces later to fit into the existing structure.

@lhy11009

lhy11009 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Sorry, I didn't reply to the QS about this PR. There are things I want to change about this one, and it will fix the test issue here. I'll renew this one before our next biweekly meeting.

@lhy11009

lhy11009 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @gassmoeller, I have included a few changes in the implementation of the PR; I can explain why:

Move the reaction-count validation to ViscoPlastic

ViscoPlastic knows which compositional fields are used for reaction progress. Therefore, it should check whether the number of these fields matches the number of reactions. This keeps ReactionChain independent while maintaining the validation.

Allow cases without reaction-progress fields

Regular visco-plastic models should work without reactions. When no reaction-progress fields exist, we skip parsing ReactionChain. However, if a kinetics list is provided, we raise an error to avoid silently ignoring the reactions.

Require at least one reaction when parsing ReactionChain

When ReactionChain is explicitly parsed, it should contain at least one kinetic model. An empty kinetics list will raise an error. Models that do not use reactions simply skip this step.

Update tests and add a regression test

Add a regression test to confirm that ViscoPlastic still detects mismatches between the number of reactions and reaction-progress fields.

Update the unit tests to account for the empty default kinetics list and explicitly define kinetic models where needed. These tests can now run without initializing a simulator.

All the tests except for documentation passed. It is ready for review.

We can discuss tomorrow during meeting.

@lhy11009
lhy11009 force-pushed the visco_plastic_reaction_chain branch from 2ded8e4 to 54f9dec Compare November 16, 2026 00:19

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants