Skip to content

Conversation

@tophmatthews
Copy link
Contributor

@tophmatthews tophmatthews commented Oct 15, 2025

#29888 showed a nice way of combining AD and nonAD while including jacobians in the non-ad without muddying up the AD classes. This PR cleans up Reaction in this new method, and combines AD and nonAD MatReaction. Also cleans up tests and clarifies internal naming conventions along the way. Also, deprecating duplicative classes.

Ref #15915

@tophmatthews tophmatthews force-pushed the reaction_adnonad_15915 branch 2 times, most recently from f7109ae to 55e582f Compare October 15, 2025 18:40
@moosebuild
Copy link
Contributor

moosebuild commented Oct 15, 2025

Job Documentation, step Docs: sync website on 1c6058b wanted to post the following:

View the site here

This comment will be updated on new commits.

@moosebuild
Copy link
Contributor

moosebuild commented Oct 16, 2025

Job Coverage, step Generate coverage on 1c6058b wanted to post the following:

Framework coverage

17a583 #31728 1c6058
Total Total +/- New
Rate 85.99% 85.98% -0.00% 100.00%
Hits 123706 123698 -8 27
Misses 20161 20162 +1 0

Diff coverage report

Full coverage report

Modules coverage

Phase field

17a583 #31728 1c6058
Total Total +/- New
Rate 86.10% 86.10% - 100.00%
Hits 14018 14018 - 2
Misses 2264 2264 - 0

Diff coverage report

Full coverage report

Full coverage reports

Reports

This comment will be updated on new commits.

@moosebuild
Copy link
Contributor

Job Coverage, step Verify coverage on 0dd10cd wanted to post the following:

The following coverage requirement(s) failed:

  • Failed to generate framework coverage rate (required: 81.0%)

1 similar comment
@moosebuild
Copy link
Contributor

Job Coverage, step Verify coverage on 0dd10cd wanted to post the following:

The following coverage requirement(s) failed:

  • Failed to generate framework coverage rate (required: 81.0%)

@tophmatthews tophmatthews force-pushed the reaction_adnonad_15915 branch from 0dd10cd to 6bd88cd Compare October 16, 2025 15:22
Copy link
Member

@loganharbour loganharbour left a comment

Choose a reason for hiding this comment

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

Check above in #31728 (comment).

New tests are too long!

/// Reaction rate material property
const ADMaterialProperty<Real> & _reaction_rate;
};
#include "MatReaction.h"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can remove this after MARMOT is patched after this PR is in.

Comment on lines 29 to 40
class CoefReaction : public CoefReactionTempl<false>
{
public:
static InputParameters validParams();

CoefReaction(const InputParameters & parameters);

using CoefReactionTempl<false>::CoefReactionTempl;

protected:
virtual Real computeQpJacobian() override;
};
Copy link
Member

Choose a reason for hiding this comment

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

what's the reason for these new lines? It seems like things were already working before with the simple typedefs ?

Copy link
Contributor Author

@tophmatthews tophmatthews Oct 17, 2025

Choose a reason for hiding this comment

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

It's due to needing to override computeQpJacobian due to changes in Reaction. I couldn't figure out a better way to do it.

Copy link
Member

@lindsayad lindsayad left a comment

Choose a reason for hiding this comment

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

I think you should be able to make the exact same implementation changes without adding additional class hierarchy

@lindsayad
Copy link
Member

You were probably running into template type dependent base class compilation issues. In the commit I just pushed I show how you can overcome that with using directives

@lindsayad
Copy link
Member

Another solution would be to qualify all of those data members with this->_i, this->_j etc. but I think this makes for cleaner looking implementations

@tophmatthews
Copy link
Contributor Author

In the commit I just pushed I show how you can overcome that with using directives

interesting...thanks!!

Comment on lines 34 to 45
class Reaction : public ReactionTempl<false>
{
public:
static InputParameters validParams();

Reaction(const InputParameters & parameters);

using ReactionTempl<false>::ReactionTempl;

protected:
virtual Real computeQpJacobian() override;
};
Copy link
Member

Choose a reason for hiding this comment

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

Remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oooh I see, computeQpJacobian is defined in ADKernel.h...

Comment on lines -48 to +42
return _coef * ReactionTempl<is_ad>::computeQpJacobian();
return _coef * _test[_i][_qp] * _rate * _phi[_j][_qp];
Copy link
Member

Choose a reason for hiding this comment

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

why did you change this line? I like what was there before better for code re-use

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh. I would think you'd want to reduce code duplication?

Copy link
Contributor

Choose a reason for hiding this comment

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

recoding the phi * test * rate is code duplication

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so, which version is desired here?

Copy link
Contributor

Choose a reason for hiding this comment

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

the old one

Comment on lines -45 to -50
// This function will never be called for the AD version. But because C++ does
// not support an optional function declaration based on a template parameter,
// we must keep this template for all cases.
mooseAssert(!is_ad,
"In ADReaction, computeQpJacobian should not be called. Check computeJacobian "
"implementation.");
Copy link
Member

Choose a reason for hiding this comment

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

why did you remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't get here anyways, but I removed it because I thought the jacobian was never defined for AD version of Reaction, or at least that it was already at final (liked ADKernelValue). All the fancy working before was under this assumption.

Copy link
Member

Choose a reason for hiding this comment

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

I agree it shouldn't get here. The assert is sanity checking just that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I can add that back.


registerMooseObject("StochasticToolsTestApp", MaterialReaction);

registerMooseObjectReplaced("StochasticToolsTestApp", MaterialReaction, "01/01/2027 00:00", Matreaction);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
registerMooseObjectReplaced("StochasticToolsTestApp", MaterialReaction, "01/01/2027 00:00", Matreaction);
registerMooseObjectReplaced("StochasticToolsTestApp", MaterialReaction, "01/01/2027 00:00", MatReaction);

input = 'mat_reaction.i'
difference_tol = 1e-7
design = 'MatReaction.md'
requirement = 'The system shall calculate the correct Jacobian of MatReaction.'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
requirement = 'The system shall calculate the correct Jacobian of MatReaction.'
requirement = 'The system shall calculate the correct hand-coded Jacobian for a steady-state diffusion-reaction problem.'

difference_tol = 1e-7
design = 'MatReaction.md'
requirement = 'The system shall calculate the correct Jacobian of MatReaction.'
[../]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[../]
[]

difference_tol = 1e-7
cli_args = 'AD=AD'
design = 'ADMatReaction.md'
requirement = 'The system shall calculate the correct Jacobian of ADMatReaction using automatic differentiation.'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
requirement = 'The system shall calculate the correct Jacobian of ADMatReaction using automatic differentiation.'
requirement = 'The system shall calculate the correct Jacobian via automatic differentiation for a steady-state diffusion-reaction problem.'

cli_args = 'AD=AD'
design = 'ADMatReaction.md'
requirement = 'The system shall calculate the correct Jacobian of ADMatReaction using automatic differentiation.'
[../]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[../]
[]

@moosebuild
Copy link
Contributor

Job Test, step Results summary on 1c6058b wanted to post the following:

Framework test summary

Removed tests

Test Time (s)
kernels/ad_mat_reaction.ad_mat_reaction 2.1
kernels/ad_reaction.ad_coef_reaction 1.09
kernels/ad_mat_reaction.ad_mat_reaction_jac 1.05
kernels/ad_reaction.ad_coef_reaction_jac 0.92
kernels/ad_reaction.ad_reaction_jac 0.91
kernels/ad_reaction.ad_reaction 0.89

Added tests

Test Time (s)
kernels/mat_reaction.ad_mat_reaction 2.01
kernels/reaction.exact 1.19
kernels/mat_reaction.mat_reaction 1.11
kernels/reaction.ad_exact_jac 1.04
kernels/mat_reaction.mat_reaction_jac 1.02
kernels/mat_reaction.ad_mat_reaction_jac 1.01
kernels/reaction.ad_exact 0.93

Run time changes

Test Base (s) Head (s) +/-
meshgenerators/mesh_diagnostics_generator.generate/nonconformality 0.68 1.16 +71.98%
executioners/fixed_point.tagged_solution_vector/material 1.12 1.89 +68.04%
functions/piecewise_linear_from_vectorpostprocessor.test_spatial_data 0.89 1.43 +61.49%
functions/piecewise_linear.no_extrap 0.82 1.31 +59.46%
userobjects/solution_user_object.write_exodus_second_order 1.19 1.87 +56.83%
scalar_kernels/ad_coupled_scalar.exo 1.04 1.61 +55.61%
userobjects/execution_order_groups.inter_group_dependence 0.85 1.31 +53.79%
fvkernels/fv_burgers.fv_burgers 0.92 1.41 +52.93%
userobjects/nearest_point_layered_average.from_file 1.04 1.58 +51.86%

Modules test summary

Removed tests

None

Added tests

None

Run time changes

Test Base (s) Head (s) +/-
electromagnetics/test:auxkernels/current_density.errors/ES_electric_field_var 1.28 2.03 +58.22%
xfem/test:diffusion_xfem.levelsetcut3d 1.07 1.65 +54.66%
richards/test:pressure_pulse.pp02 1.05 1.59 +52.34%
stochastic_tools/test:web_server_control.stochastic_control/batch_reset 3.67 5.54 +50.92%

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.

5 participants