Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
28 changes: 0 additions & 28 deletions framework/doc/content/source/kernels/ADMatReaction.md

This file was deleted.

1 change: 1 addition & 0 deletions framework/doc/content/source/kernels/ADMatReaction.md
30 changes: 1 addition & 29 deletions framework/include/kernels/ADMatReaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,4 @@

#pragma once

#include "ADKernel.h"

/**
* Kernel representing the contribution of the PDE term $-L*v$, where $L$ is a
* reaction rate coefficient material property, $v$ is a scalar variable (nonlinear or coupled
* auxvariable), and whose Jacobian contribution is calculated using automatic differentiation.
*/
class ADMatReaction : public ADKernel
{
public:
static InputParameters validParams();

ADMatReaction(const InputParameters & parameters);

protected:
virtual ADReal computeQpResidual() override;

private:
/**
* Kernel variable (can be nonlinear or coupled variable)
* (For constrained Allen-Cahn problems such as those in
* phase field, v = lambda where lambda is the Lagrange
* multiplier)
*/
const ADVariableValue & _v;

/// 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.

15 changes: 13 additions & 2 deletions framework/include/kernels/CoefReaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,22 @@ class CoefReactionTempl : public ReactionTempl<is_ad>

protected:
virtual GenericReal<is_ad> computeQpResidual() override;
virtual Real computeQpJacobian() override;

/// input parameter multiplied by the reaction kernel
const Real _coef;
};

typedef CoefReactionTempl<false> CoefReaction;
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.


typedef CoefReactionTempl<true> ADCoefReaction;
51 changes: 34 additions & 17 deletions framework/include/kernels/MatReaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,49 @@

#pragma once

#include "Kernel.h"
#include "GenericKernel.h"
#include "JvarMapInterface.h"
#include "DerivativeMaterialInterface.h"

// Forward Declaration

/**
* This kernel adds to the residual a contribution of \f$ -L*v \f$ where \f$ L \f$ is a material
* property and \f$ v \f$ is a variable (nonlinear or coupled).
*/
class MatReaction : public DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>
template <bool is_ad>
class MatReactionTempl : public GenericKernel<is_ad>
{
public:
static InputParameters validParams();

MatReactionTempl(const InputParameters & parameters);

protected:
virtual GenericReal<is_ad> computeQpResidual();

/// Reaction rate
const GenericMaterialProperty<Real, is_ad> & _rate;

/**
* Kernel variable (can be nonlinear or coupled variable)
* (For constrained Allen-Cahn problems, v = lambda
* where lambda is the Lagrange multiplier)
*/
const GenericVariableValue<is_ad> & _v;

usingGenericKernelMembers;
};

class MatReaction
: public DerivativeMaterialInterface<JvarMapKernelInterface<MatReactionTempl<false>>>
{
public:
static InputParameters validParams();

MatReaction(const InputParameters & parameters);

virtual void initialSetup();

protected:
virtual Real computeQpResidual();
virtual Real computeQpJacobian();
virtual Real computeQpOffDiagJacobian(unsigned int jvar);

Expand All @@ -40,23 +63,17 @@ class MatReaction : public DerivativeMaterialInterface<JvarMapKernelInterface<Ke
* (For constrained Allen-Cahn problems, v = lambda
* where lambda is the Lagrange multiplier)
*/

std::string _v_name;
const VariableValue & _v;
unsigned int _v_var;

/// Reaction rate
const MaterialProperty<Real> & _L;

/// name of the order parameter (needed to retrieve the derivative material properties)
VariableName _eta_name;

/// Reaction rate derivative w.r.t. order parameter
const MaterialProperty<Real> & _dLdop;
/// Reaction rate derivative w.r.t. primal variable
const MaterialProperty<Real> & _drate_du;

/// Reaction rate derivative w.r.t. the variable being added by this kernel
const MaterialProperty<Real> & _dLdv;
const MaterialProperty<Real> & _drate_dv;

/// Reaction rate derivatives w.r.t. other coupled variables
std::vector<const MaterialProperty<Real> *> _dLdarg;
std::vector<const MaterialProperty<Real> *> _drate_darg;
};

typedef MatReactionTempl<true> ADMatReaction;
15 changes: 13 additions & 2 deletions framework/include/kernels/Reaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,24 @@ class ReactionTempl : public GenericKernel<is_ad>

protected:
virtual GenericReal<is_ad> computeQpResidual() override;
virtual Real computeQpJacobian() override;

/// Scalar coefficient representing the relative amount consumed per unit time
const Real & _rate;

usingGenericKernelMembers;
};

typedef ReactionTempl<false> Reaction;
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...


typedef ReactionTempl<true> ADReaction;
41 changes: 0 additions & 41 deletions framework/src/kernels/ADMatReaction.C

This file was deleted.

26 changes: 15 additions & 11 deletions framework/src/kernels/CoefReaction.C
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#include "CoefReaction.h"

registerMooseObject("MooseApp", CoefReaction);
registerMooseObject("MooseApp", ADCoefReaction);
registerMooseObjectReplaced("MooseApp", CoefReaction, "01/01/2027 00:00", Reaction);
registerMooseObjectReplaced("MooseApp", ADCoefReaction, "01/21/2027 00:00", ADReaction);

template <bool is_ad>
InputParameters
Expand All @@ -35,17 +35,21 @@ CoefReactionTempl<is_ad>::computeQpResidual()
return _coef * ReactionTempl<is_ad>::computeQpResidual();
}

template <bool is_ad>
InputParameters
CoefReaction::validParams()
{
return CoefReactionTempl<false>::validParams();
}

CoefReaction::CoefReaction(const InputParameters & parameters)
: CoefReactionTempl<false>(parameters)
{
}

Real
CoefReactionTempl<is_ad>::computeQpJacobian()
CoefReaction::computeQpJacobian()
{
// 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 ADCoefReaction, computeQpJacobian should not be called. Check computeJacobian "
"implementation.");
return _coef * ReactionTempl<is_ad>::computeQpJacobian();
return _coef * _test[_i][_qp] * _rate * _phi[_j][_qp];
Comment on lines -48 to +42
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

}

template class CoefReactionTempl<false>;
Expand Down
Loading