Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5422556
Move MatDiffusionBase to KernelGrad
tophmatthews Feb 14, 2025
66213f6
remove some really really old deprecations
tophmatthews Feb 14, 2025
9d6477a
make ADMatDiffusionBase and MatDiffusionBase consistant
tophmatthews Feb 14, 2025
095c4d6
add GenericKernelGrad
tophmatthews Feb 14, 2025
4d1f5c7
combine ad/nonad matdiffusionbase
tophmatthews Feb 24, 2025
5f1195b
combine matanisodiffusion ad/nonad
tophmatthews Feb 24, 2025
92cfea5
fix explicit instantiations
tophmatthews Feb 25, 2025
77ea849
coupledGenericGradient fixes
tophmatthews Feb 25, 2025
d758a9a
only require var coupling when nonad
tophmatthews Feb 25, 2025
a9fcd02
doco and inheritance errors
tophmatthews Feb 25, 2025
d74bbf8
inherit nonad from AD
tophmatthews Feb 26, 2025
346f5b4
fixup inheritance
tophmatthews Feb 27, 2025
862fe39
further removing nonad needed things from ad
tophmatthews Feb 27, 2025
1dc8a92
simplify generickernelgrad
tophmatthews Feb 27, 2025
c39ea29
fix typedef for doco
tophmatthews Feb 28, 2025
cd13a47
cleanup framework tests
tophmatthews Feb 28, 2025
e9c7c3d
simplify ad diffusion tests
tophmatthews Feb 28, 2025
e446372
boost coverage with more tests
tophmatthews Feb 28, 2025
d209f16
fix design duplication
tophmatthews Feb 28, 2025
52dab9f
fix multiple issues
tophmatthews Feb 28, 2025
625cac0
update doco for darcy tutorial
tophmatthews Mar 6, 2025
1cbf918
rename Qpjac to precompute
tophmatthews Mar 7, 2025
e5badc9
fix grandpotentialkernelaction derivative
tophmatthews Sep 16, 2025
1d246f3
fix doco
tophmatthews Sep 17, 2025
e70544b
add checks for computeQp methods
tophmatthews Oct 10, 2025
873251d
review comments
tophmatthews Oct 14, 2025
7d3d0b5
remove ADMatDiffusion.md
tophmatthews Oct 14, 2025
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
26 changes: 0 additions & 26 deletions framework/doc/content/source/kernels/ADMatDiffusion.md

This file was deleted.

5 changes: 4 additions & 1 deletion framework/include/interfaces/Coupleable.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
using Coupleable::_zero; \
using Coupleable::_grad_zero; \
using Coupleable::_ad_zero; \
using Coupleable::_ad_grad_zero
using Coupleable::_ad_grad_zero; \
using Coupleable::coupled; \
using Coupleable::isCoupled; \
using Coupleable::coupledComponents

// Forward declarations
class MooseVariableScalar;
Expand Down
25 changes: 0 additions & 25 deletions framework/include/kernels/ADMatDiffusion.h

This file was deleted.

70 changes: 0 additions & 70 deletions framework/include/kernels/ADMatDiffusionBase.h

This file was deleted.

27 changes: 27 additions & 0 deletions framework/include/kernels/GenericKernelGrad.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "KernelGrad.h"
#include "ADKernelGrad.h"

template <bool is_ad>
using GenericKernelGrad = std::conditional_t<is_ad, ADKernelGrad, KernelGrad>;

#define usingGenericKernelGradMembers \
usingFunctionInterfaceMembers; \
usingPostprocessorInterfaceMembers; \
usingMooseObjectMembers; \
usingTransientInterfaceMembers; \
usingTaggingInterfaceMembers; \
usingBlockRestrictableMembers; \
usingCoupleableMembers; \
using GenericKernelGrad<is_ad>::_qp; \
using GenericKernelGrad<is_ad>::_grad_u
6 changes: 4 additions & 2 deletions framework/include/kernels/KernelGrad.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class KernelGrad : public Kernel
/**
* Called before forming the jacobian for an element
*/
virtual RealGradient precomputeQpJacobian();
virtual RealGradient precomputeQpJacobian() { return RealGradient(0.0); }

virtual Real computeQpResidual() override;
virtual Real computeQpResidual() override final { return 0.0; }

virtual Real computeQpJacobian() override final { return 0.0; }
};
12 changes: 10 additions & 2 deletions framework/include/kernels/MatDiffusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@

#include "MatDiffusionBase.h"

template <bool is_ad>
using MatDiffusionBaseParent = typename std::
conditional<is_ad, MatDiffusionBaseTempl<Real, true>, MatDiffusionBase<Real>>::type;

/**
* Isotropic diffusion kernel that takes a diffusion coefficient of type
* Real. All logic is implemnted in the MatDiffusionBase class
* template.
*/
class MatDiffusion : public MatDiffusionBase<Real>
template <bool is_ad>
class MatDiffusionTempl : public MatDiffusionBaseParent<is_ad>
{
public:
static InputParameters validParams();

MatDiffusion(const InputParameters & parameters);
MatDiffusionTempl(const InputParameters & parameters);
};

typedef MatDiffusionTempl<false> MatDiffusion;
typedef MatDiffusionTempl<true> ADMatDiffusion;
147 changes: 39 additions & 108 deletions framework/include/kernels/MatDiffusionBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#pragma once

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

Expand All @@ -22,132 +22,63 @@
* \tparam T Type of the diffusion coefficient parameter. This can be Real for
* isotropic diffusion or RealTensorValue for the general anisotropic case.
*/
template <typename T>
class MatDiffusionBase : public DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>
template <typename T, bool is_ad>
class MatDiffusionBaseTempl
: public DerivativeMaterialInterface<JvarMapKernelInterface<GenericKernelGrad<is_ad>>>
{
public:
static InputParameters validParams();

MatDiffusionBase(const InputParameters & parameters);

virtual void initialSetup() override;
MatDiffusionBaseTempl(const InputParameters & parameters);

protected:
virtual Real computeQpResidual() override;
virtual Real computeQpJacobian() override;
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override;
virtual Real computeQpCJacobian();
virtual GenericRealVectorValue<is_ad> precomputeQpResidual() override;

/// diffusion coefficient
const MaterialProperty<T> & _D;

/// diffusion coefficient derivative w.r.t. the kernel variable
const MaterialProperty<T> & _dDdc;

/// diffusion coefficient derivatives w.r.t. coupled variables
std::vector<const MaterialProperty<T> *> _dDdarg;

/// is the kernel used in a coupled form?
const bool _is_coupled;

/// int label for the Concentration
unsigned int _v_var;
const GenericMaterialProperty<T, is_ad> & _diffusivity;

/// Gradient of the concentration
const VariableGradient & _grad_v;
};

template <typename T>
InputParameters
MatDiffusionBase<T>::validParams()
{
InputParameters params = Kernel::validParams();
params.addDeprecatedParam<MaterialPropertyName>(
"D_name",
"The name of the diffusivity",
"This parameter has been renamed to 'diffusivity', which is more mnemonic and more conducive "
"to passing a number literal");
params.addParam<MaterialPropertyName>(
"diffusivity", "D", "The diffusivity value or material property");
params.addCoupledVar("args",
"Optional vector of arguments for the diffusivity. If provided and "
"diffusivity is a derivative parsed material, Jacobian contributions from "
"the diffusivity will be automatically computed");
params.addCoupledVar("conc", "Deprecated! Use 'v' instead");
params.addCoupledVar("v",
"Coupled concentration variable for kernel to operate on; if this "
"is not specified, the kernel's nonlinear variable will be used as "
"usual");
return params;
}

template <typename T>
MatDiffusionBase<T>::MatDiffusionBase(const InputParameters & parameters)
: DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
_D(isParamValid("D_name") ? getMaterialProperty<T>("D_name")
: getMaterialProperty<T>("diffusivity")),
_dDdc(getMaterialPropertyDerivative<T>(isParamValid("D_name") ? "D_name" : "diffusivity",
_var.name())),
_dDdarg(_coupled_moose_vars.size()),
_is_coupled(isCoupled("v")),
_v_var(_is_coupled ? coupled("v") : (isCoupled("conc") ? coupled("conc") : _var.number())),
_grad_v(_is_coupled ? coupledGradient("v")
: (isCoupled("conc") ? coupledGradient("conc") : _grad_u))
{
// deprecated variable parameter conc
if (isCoupled("conc"))
mooseDeprecated("In '", name(), "' the parameter 'conc' is deprecated, please use 'v' instead");
const GenericVariableGradient<is_ad> & _grad_v;

// fetch derivatives
for (unsigned int i = 0; i < _dDdarg.size(); ++i)
_dDdarg[i] = &getMaterialPropertyDerivative<T>(
isParamValid("D_name") ? "D_name" : "diffusivity", _coupled_moose_vars[i]->name());
}
usingGenericKernelGradMembers;
};

template <typename T>
void
MatDiffusionBase<T>::initialSetup()
class MatDiffusionBase : public MatDiffusionBaseTempl<T, false>
{
validateNonlinearCoupling<Real>(parameters().isParamSetByUser("D_name") ? "D_name"
: "diffusivity");
}
public:
static InputParameters validParams();

template <typename T>
Real
MatDiffusionBase<T>::computeQpResidual()
{
return _D[_qp] * _grad_v[_qp] * _grad_test[_i][_qp];
}
MatDiffusionBase(const InputParameters & parameters);

template <typename T>
Real
MatDiffusionBase<T>::computeQpJacobian()
{
Real sum = _phi[_j][_qp] * _dDdc[_qp] * _grad_v[_qp] * _grad_test[_i][_qp];
if (!_is_coupled)
sum += computeQpCJacobian();
using MatDiffusionBaseTempl<T, false>::MatDiffusionBaseTempl;

return sum;
}
protected:
virtual void initialSetup() override;
virtual RealGradient precomputeQpJacobian() override;
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override;
virtual RealGradient precomputeQpCJacobian();

template <typename T>
Real
MatDiffusionBase<T>::computeQpOffDiagJacobian(unsigned int jvar)
{
// get the coupled variable jvar is referring to
const unsigned int cvar = mapJvarToCvar(jvar);
/// diffusion coefficient derivative w.r.t. the kernel variable
const MaterialProperty<T> & _ddiffusivity_dc;

Real sum = (*_dDdarg[cvar])[_qp] * _phi[_j][_qp] * _grad_v[_qp] * _grad_test[_i][_qp];
/// diffusion coefficient derivatives w.r.t. coupled variables
std::vector<const MaterialProperty<T> *> _ddiffusivity_darg;

if (_v_var == jvar)
sum += computeQpCJacobian();
/// is the kernel used in a coupled form?
const bool _is_coupled;

return sum;
}
/// int label for the Concentration
unsigned int _v_var;

template <typename T>
Real
MatDiffusionBase<T>::computeQpCJacobian()
{
return _D[_qp] * _grad_phi[_j][_qp] * _grad_test[_i][_qp];
}
using MatDiffusionBaseTempl<T, false>::_diffusivity;
using MatDiffusionBaseTempl<T, false>::_qp;
using MatDiffusionBaseTempl<T, false>::_grad_phi;
using MatDiffusionBaseTempl<T, false>::_j;
using MatDiffusionBaseTempl<T, false>::_i;
using MatDiffusionBaseTempl<T, false>::_phi;
using MatDiffusionBaseTempl<T, false>::_grad_v;
using MatDiffusionBaseTempl<T, false>::_grad_test;
using MatDiffusionBaseTempl<T, false>::_var;
using MatDiffusionBaseTempl<T, false>::_coupled_moose_vars;
};
Loading