www.mooseframework.org
CoupledSwitchingTimeDerivative.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
11 
14 
15 template <bool is_ad>
18 {
20  params.addClassDescription(
21  "Coupled time derivative Kernel that multiplies the time derivative by "
22  "$\\frac{dh_\\alpha}{d\\eta_i} F_\\alpha + \\frac{dh_\\beta}{d\\eta_i} F_\\beta + \\dots$");
23  params.addRequiredParam<std::vector<MaterialPropertyName>>(
24  "Fj_names", "List of functions for each phase. Place in same order as hj_names!");
25  params.addRequiredParam<std::vector<MaterialPropertyName>>(
26  "hj_names", "Switching Function Materials that provide h. Place in same order as Fj_names!");
27  params.addCoupledVar("args", "Vector of variable arguments of Fj and hj");
28  params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024");
29  return params;
30 }
31 template <bool is_ad>
33  const InputParameters & parameters)
35  parameters),
36  _v_name(this->coupledName("v", 0)),
37  _Fj_names(this->template getParam<std::vector<MaterialPropertyName>>("Fj_names")),
38  _num_j(_Fj_names.size()),
39  _prop_Fj(_num_j),
40  _hj_names(this->template getParam<std::vector<MaterialPropertyName>>("hj_names")),
41  _prop_dhjdetai(_num_j)
42 {
43  // check passed in parameter vectors
44  if (_num_j != _hj_names.size())
45  this->paramError("hj_names", "Need to pass in as many hj_names as Fj_names");
46 
47  // reserve space and set phase material properties
48  for (unsigned int n = 0; n < _num_j; ++n)
49  {
50  // get phase free energy
51  _prop_Fj[n] = &this->template getGenericMaterialProperty<Real, is_ad>(_Fj_names[n]);
52 
53  // get switching function derivatives wrt eta_i, the nonlinear variable
54  _prop_dhjdetai[n] =
55  &this->template getMaterialPropertyDerivative<Real, is_ad>(_hj_names[n], _v_name);
56  }
57 }
58 
60  : CoupledSwitchingTimeDerivativeTempl<false>(parameters),
61  _prop_dFjdv(_num_j),
62  _prop_dFjdarg(_num_j),
63  _prop_d2hjdetai2(_num_j),
64  _prop_d2hjdetaidarg(_num_j)
65 {
66  // reserve space and set phase material properties
67  for (unsigned int n = 0; n < _num_j; ++n)
68  {
69  // get phase free energy and derivatives
70  _prop_dFjdv[n] = &getMaterialPropertyDerivative<Real>(_Fj_names[n], _var.name());
71  _prop_dFjdarg[n].resize(_n_args);
72 
73  // get switching function and derivatives wrt eta_i, the nonlinear variable
74  _prop_d2hjdetai2[n] = &getMaterialPropertyDerivative<Real>(_hj_names[n], _v_name, _v_name);
75  _prop_d2hjdetaidarg[n].resize(_n_args);
76 
77  for (unsigned int i = 0; i < _n_args; ++i)
78  {
79  // Get derivatives of all Fj wrt all coupled variables
80  _prop_dFjdarg[n][i] = &getMaterialPropertyDerivative<Real>(_Fj_names[n], i);
81 
82  // Get second derivatives of all hj wrt eta_i and all coupled variables
83  _prop_d2hjdetaidarg[n][i] = &getMaterialPropertyDerivative<Real>(_hj_names[n], _v_name, i);
84  }
85  }
86 }
87 
88 template <bool is_ad>
89 void
91 {
92  for (unsigned int n = 0; n < _num_j; ++n)
93  this->template validateNonlinearCoupling<GenericReal<is_ad>>(_hj_names[n]);
94 }
95 
96 void
98 {
100  for (unsigned int n = 0; n < _num_j; ++n)
101  validateNonlinearCoupling<Real>(_Fj_names[n]);
102 }
103 
104 Real
106 {
107  Real sum = 0.0;
108  for (unsigned int n = 0; n < _num_j; ++n)
109  sum += (*_prop_dhjdetai[n])[_qp] * (*_prop_Fj[n])[_qp];
110 
112 }
113 
114 ADReal
116 {
117  ADReal sum = 0.0;
118  for (unsigned int n = 0; n < _num_j; ++n)
119  sum += (*_prop_dhjdetai[n])[_qp] * (*_prop_Fj[n])[_qp];
120 
121  return _v_dot[_qp] * sum;
122 }
123 
124 Real
126 {
127  Real sum = 0.0;
128  for (unsigned int n = 0; n < _num_j; ++n)
129  sum += (*_prop_dhjdetai[n])[_qp] * (*_prop_dFjdv[n])[_qp];
130 
131  return CoupledTimeDerivative::computeQpResidual() * sum * _phi[_j][_qp];
132 }
133 
134 Real
136 {
137  // get the coupled variable jvar is referring to
138  const unsigned int cvar = mapJvarToCvar(jvar);
139 
140  if (jvar == _v_var)
141  {
142  Real sum = 0.0;
143 
144  for (unsigned int n = 0; n < _num_j; ++n)
145  sum +=
146  ((*_prop_d2hjdetai2[n])[_qp] * _v_dot[_qp] + (*_prop_dhjdetai[n])[_qp] * _dv_dot[_qp]) *
147  (*_prop_Fj[n])[_qp];
148 
149  return _phi[_j][_qp] * sum * _test[_i][_qp];
150  }
151 
152  Real sum = 0.0;
153  for (unsigned int n = 0; n < _num_j; ++n)
154  sum += (*_prop_d2hjdetaidarg[n][cvar])[_qp] * (*_prop_Fj[n])[_qp] +
155  (*_prop_dhjdetai[n])[_qp] * (*_prop_dFjdarg[n][cvar])[_qp];
156 
157  return CoupledTimeDerivative::computeQpResidual() * sum * _phi[_j][_qp];
158 }
159 
std::vector< MaterialPropertyName > _hj_names
switching function names
CoupledSwitchingTimeDerivativeTempl(const InputParameters &parameters)
std::vector< MaterialPropertyName > _Fj_names
Names of functions for each phase .
std::vector< const GenericMaterialProperty< Real, is_ad > * > _prop_dhjdetai
Derivatives of the switching functions wrt the order parameter for this kernel.
registerMooseObject("PhaseFieldApp", CoupledSwitchingTimeDerivative)
void addRequiredParam(const std::string &name, const std::string &doc_string)
std::vector< const MaterialProperty< Real > * > _prop_dFjdv
Derivatives of the functions wrt the nonlinear variable for this kernel.
CoupledSwitchingTimeDerivative(const InputParameters &parameters)
InputParameters validParams()
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_d2hjdetaidarg
Second derivatives of the switching functions (needed for off-diagonal Jacobians) ...
virtual Real computeQpResidual() override
void deprecateCoupledVar(const std::string &old_name, const std::string &new_name, const std::string &removal_date)
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_dFjdarg
Derivatives of the functions (needed for off-diagonal Jacobians)
typename std::conditional< is_ad, ADCoupledTimeDerivative, CoupledTimeDerivative >::type CoupledSwitchingTimeDerivativeBase
This kernel adds a contribution where are the phases, are the switching functions, is the order parameter that is the nonlinear variable, is time, and are functions for each phase.
DualReal ADReal
std::vector< const GenericMaterialProperty< Real, is_ad > * > _prop_Fj
Values of the functions for each phase .
const unsigned int _num_j
Number of phases.
void addCoupledVar(const std::string &name, const std::string &doc_string)
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const VariableName _v_name
name of order parameter that derivatives are taken wrt (needed to retrieve the derivative material pr...
void addClassDescription(const std::string &doc_string)
typename Moose::GenericType< Real, is_ad > GenericReal
std::vector< const MaterialProperty< Real > * > _prop_d2hjdetai2
Second derivatives of the switching functions wrt the order parameter for this kernel.