https://mooseframework.inl.gov
Loading...
Searching...
No Matches
CoupledSwitchingTimeDerivative.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
11
14
15template <bool is_ad>
18{
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("coupled_variables", "Vector of variable arguments of Fj and hj");
28 return params;
29}
30template <bool is_ad>
32 const InputParameters & parameters)
34 parameters),
35 _v_name(this->coupledName("v", 0)),
36 _Fj_names(this->template getParam<std::vector<MaterialPropertyName>>("Fj_names")),
37 _num_j(_Fj_names.size()),
38 _prop_Fj(_num_j),
39 _hj_names(this->template getParam<std::vector<MaterialPropertyName>>("hj_names")),
40 _prop_dhjdetai(_num_j)
41{
42 // check passed in parameter vectors
43 if (_num_j != _hj_names.size())
44 this->paramError("hj_names", "Need to pass in as many hj_names as Fj_names");
45
46 // reserve space and set phase material properties
47 for (unsigned int n = 0; n < _num_j; ++n)
48 {
49 // get phase free energy
50 _prop_Fj[n] = &this->template getGenericMaterialProperty<Real, is_ad>(_Fj_names[n]);
51
52 // get switching function derivatives wrt eta_i, the nonlinear variable
53 _prop_dhjdetai[n] =
54 &this->template getMaterialPropertyDerivative<Real, is_ad>(_hj_names[n], _v_name);
55 }
56}
57
59 : CoupledSwitchingTimeDerivativeTempl<false>(parameters),
60 _prop_dFjdv(_num_j),
61 _prop_dFjdarg(_num_j),
62 _prop_d2hjdetai2(_num_j),
63 _prop_d2hjdetaidarg(_num_j)
64{
65 // reserve space and set phase material properties
66 for (unsigned int n = 0; n < _num_j; ++n)
67 {
68 // get phase free energy and derivatives
69 _prop_dFjdv[n] = &getMaterialPropertyDerivative<Real>(_Fj_names[n], _var.name());
70 _prop_dFjdarg[n].resize(_n_args);
71
72 // get switching function and derivatives wrt eta_i, the nonlinear variable
73 _prop_d2hjdetai2[n] = &getMaterialPropertyDerivative<Real>(_hj_names[n], _v_name, _v_name);
74 _prop_d2hjdetaidarg[n].resize(_n_args);
75
76 for (unsigned int i = 0; i < _n_args; ++i)
77 {
78 // Get derivatives of all Fj wrt all coupled variables
79 _prop_dFjdarg[n][i] = &getMaterialPropertyDerivative<Real>(_Fj_names[n], i);
80
81 // Get second derivatives of all hj wrt eta_i and all coupled variables
82 _prop_d2hjdetaidarg[n][i] = &getMaterialPropertyDerivative<Real>(_hj_names[n], _v_name, i);
83 }
84 }
85}
86
87template <bool is_ad>
88void
90{
91 for (unsigned int n = 0; n < _num_j; ++n)
92 this->template validateNonlinearCoupling<GenericReal<is_ad>>(_hj_names[n]);
93}
94
95void
97{
99 for (unsigned int n = 0; n < _num_j; ++n)
100 validateNonlinearCoupling<Real>(_Fj_names[n]);
101}
102
103Real
105{
106 Real sum = 0.0;
107 for (unsigned int n = 0; n < _num_j; ++n)
108 sum += (*_prop_dhjdetai[n])[_qp] * (*_prop_Fj[n])[_qp];
109
111}
112
113ADReal
115{
116 ADReal sum = 0.0;
117 for (unsigned int n = 0; n < _num_j; ++n)
118 sum += (*_prop_dhjdetai[n])[_qp] * (*_prop_Fj[n])[_qp];
119
120 return _v_dot[_qp] * sum;
121}
122
123Real
125{
126 Real sum = 0.0;
127 for (unsigned int n = 0; n < _num_j; ++n)
128 sum += (*_prop_dhjdetai[n])[_qp] * (*_prop_dFjdv[n])[_qp];
129
130 return CoupledTimeDerivative::computeQpResidual() * sum * _phi[_j][_qp];
131}
132
133Real
135{
136 // get the coupled variable jvar is referring to
137 const unsigned int cvar = mapJvarToCvar(jvar);
138
139 if (jvar == _v_var)
140 {
141 Real sum = 0.0;
142
143 for (unsigned int n = 0; n < _num_j; ++n)
144 sum +=
145 ((*_prop_d2hjdetai2[n])[_qp] * _v_dot[_qp] + (*_prop_dhjdetai[n])[_qp] * _dv_dot[_qp]) *
146 (*_prop_Fj[n])[_qp];
147
148 return _phi[_j][_qp] * sum * _test[_i][_qp];
149 }
150
151 Real sum = 0.0;
152 for (unsigned int n = 0; n < _num_j; ++n)
153 sum += (*_prop_d2hjdetaidarg[n][cvar])[_qp] * (*_prop_Fj[n])[_qp] +
154 (*_prop_dhjdetai[n])[_qp] * (*_prop_dFjdarg[n][cvar])[_qp];
155
156 return CoupledTimeDerivative::computeQpResidual() * sum * _phi[_j][_qp];
157}
158
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("PhaseFieldApp", CoupledSwitchingTimeDerivative)
typename std::conditional< is_ad, ADCoupledTimeDerivative, CoupledTimeDerivative >::type CoupledSwitchingTimeDerivativeBase
This kernel adds a contribution where are the phases, are the switching functions,...
Moose::GenericType< Real, is_ad > GenericReal
const VariableName _v_name
name of order parameter that derivatives are taken wrt (needed to retrieve the derivative material pr...
std::vector< const GenericMaterialProperty< Real, is_ad > * > _prop_Fj
Values of the functions for each phase .
std::vector< MaterialPropertyName > _hj_names
switching function names
CoupledSwitchingTimeDerivativeTempl(const InputParameters &parameters)
std::vector< const GenericMaterialProperty< Real, is_ad > * > _prop_dhjdetai
Derivatives of the switching functions wrt the order parameter for this kernel.
std::vector< MaterialPropertyName > _Fj_names
Names of functions for each phase .
std::vector< const MaterialProperty< Real > * > _prop_dFjdv
Derivatives of the functions wrt the nonlinear variable for this kernel.
CoupledSwitchingTimeDerivative(const InputParameters &parameters)
std::vector< const MaterialProperty< Real > * > _prop_d2hjdetai2
Second derivatives of the switching functions wrt the order parameter for this kernel.
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_dFjdarg
Derivatives of the functions (needed for off-diagonal Jacobians)
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
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 addRequiredParam(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void addCoupledVar(const std::string &name, const std::string &doc_string)