https://mooseframework.inl.gov
ADACInterface.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "ADACInterface.h"
11 
12 registerMooseObject("PhaseFieldApp", ADACInterface);
13 
16 {
18  params.addClassDescription("Gradient energy Allen-Cahn Kernel");
19  params.addParam<MaterialPropertyName>("mob_name", "L", "The mobility used with the kernel");
20  params.addParam<MaterialPropertyName>("kappa_name", "kappa_op", "The kappa used with the kernel");
21  params.addCoupledVar("args", "Vector of nonlinear variable arguments this object depends on");
22  params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024");
23 
24  params.addParam<bool>("variable_L",
25  true,
26  "The mobility is a function of any MOOSE variable (if "
27  "this is set to false L must be constant over the "
28  "entire domain!)");
29  return params;
30 }
31 
33  : ADKernel(parameters),
34  _prop_L(getADMaterialProperty<Real>("mob_name")),
35  _name_L(getParam<MaterialPropertyName>("mob_name")),
36  _kappa(getADMaterialProperty<Real>("kappa_name")),
37  _variable_L(getParam<bool>("variable_L")),
38  _dLdop(_variable_L
39  ? &getADMaterialProperty<Real>(derivativePropertyNameFirst(_name_L, _var.name()))
40  : nullptr),
41  _nvar(Coupleable::_coupled_standard_moose_vars.size()),
42  _dLdarg(_nvar),
43  _gradarg(_nvar)
44 {
45  // Get mobility and kappa derivatives and coupled variable gradients
46  if (_variable_L)
47  for (unsigned int i = 0; i < _nvar; ++i)
48  {
50  const VariableName iname = ivar->name();
51  if (iname == _var.name())
52  {
53  if (isCoupled("args"))
54  paramError(
55  "args",
56  "The kernel variable should not be specified in the coupled `args` parameter.");
57  else
58  paramError(
59  "coupled_variables",
60  "The kernel variable should not be specified in the coupled `coupled_variables` "
61  "parameter.");
62  }
63 
64  _dLdarg[i] = &getADMaterialProperty<Real>(derivativePropertyNameFirst(_name_L, iname));
65  _gradarg[i] = &(ivar->adGradSln());
66  }
67 }
68 
69 ADReal
71 {
72  // nabla_Lpsi is the product rule gradient \f$ \nabla (L\psi) \f$
73  ADRealVectorValue nabla_Lpsi = _prop_L[_qp] * _grad_test[_i][_qp];
74 
75  if (_variable_L)
76  {
77  ADRealVectorValue grad_L = _grad_u[_qp] * (*_dLdop)[_qp];
78  for (unsigned int i = 0; i < _nvar; ++i)
79  grad_L += (*_gradarg[i])[_qp] * (*_dLdarg[i])[_qp];
80 
81  nabla_Lpsi += grad_L * _test[_i][_qp];
82  }
83 
84  return _grad_u[_qp] * _kappa[_qp] * nabla_Lpsi;
85 }
virtual bool isCoupled(const std::string &var_name, unsigned int i=0) const
const ADTemplateVariableTestGradient< T > & _grad_test
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const unsigned int _nvar
number of coupled variables
Definition: ADACInterface.h:44
const std::string & name() const override
registerMooseObject("PhaseFieldApp", ADACInterface)
const MaterialPropertyName derivativePropertyNameFirst(const MaterialPropertyName &base, const SymbolName &c1) const
const ADTemplateVariableTestValue< T > & _test
DualNumber< Real, DNDerivativeType, true > ADReal
std::vector< MooseVariable *> _coupled_standard_moose_vars
std::vector< const ADVariableGradient * > _gradarg
Gradients for all coupled variables.
Definition: ADACInterface.h:50
Compute the Allen-Cahn interface term with the weak form residual .
Definition: ADACInterface.h:19
const std::string name
Definition: Setup.h:20
void deprecateCoupledVar(const std::string &old_name, const std::string &new_name, const std::string &removal_date)
unsigned int _i
static InputParameters validParams()
Definition: ADACInterface.C:15
static InputParameters validParams()
void paramError(const std::string &param, Args... args) const
void addCoupledVar(const std::string &name, const std::string &doc_string)
ADACInterface(const InputParameters &parameters)
Definition: ADACInterface.C:32
const ADMaterialProperty< Real > & _prop_L
Mobility.
Definition: ADACInterface.h:30
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const ADTemplateVariableGradient< Real > & adGradSln() const override
const bool _variable_L
flag set if L is a function of non-linear variables in args
Definition: ADACInterface.h:38
const ADTemplateVariableGradient< T > & _grad_u
const MaterialPropertyName & _name_L
Mobility property name.
Definition: ADACInterface.h:32
MooseVariableFE< T > & _var
void addClassDescription(const std::string &doc_string)
std::vector< const ADMaterialProperty< Real > * > _dLdarg
Mobility derivative w.r.t. other coupled variables.
Definition: ADACInterface.h:47
const ADMaterialProperty< Real > & _kappa
Interfacial parameter.
Definition: ADACInterface.h:35
unsigned int _qp
virtual ADReal computeQpResidual()
Definition: ADACInterface.C:70