www.mooseframework.org
CoupledSwitchingTimeDerivative.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
8 
9 template <>
10 InputParameters
12 {
13  InputParameters params = validParams<CoupledTimeDerivative>();
14  params.addClassDescription(
15  "Coupled time derivative Kernel that multiplies the time derivative by "
16  "$\\frac{dh_\\alpha}{d\\eta_i} F_\\alpha + \\frac{dh_\\beta}{d\\eta_i} F_\\beta + \\dots)");
17  params.addRequiredParam<std::vector<MaterialPropertyName>>(
18  "Fj_names", "List of functions for each phase. Place in same order as hj_names!");
19  params.addRequiredParam<std::vector<MaterialPropertyName>>(
20  "hj_names", "Switching Function Materials that provide h. Place in same order as Fj_names!");
21  params.addCoupledVar("args", "Vector of arguments of Fj and hj");
22  return params;
23 }
24 
26  : DerivativeMaterialInterface<JvarMapKernelInterface<CoupledTimeDerivative>>(parameters),
27  _nvar(_coupled_moose_vars.size()), // number of coupled variables
28  _v_name(getVar("v", 0)->name()),
29  _Fj_names(getParam<std::vector<MaterialPropertyName>>("Fj_names")),
30  _num_j(_Fj_names.size()),
31  _prop_Fj(_num_j),
32  _prop_dFjdv(_num_j),
33  _prop_dFjdarg(_num_j),
34  _hj_names(getParam<std::vector<MaterialPropertyName>>("hj_names")),
35  _prop_dhjdetai(_num_j),
36  _prop_d2hjdetai2(_num_j),
37  _prop_d2hjdetaidarg(_num_j)
38 {
39  // check passed in parameter vectors
40  if (_num_j != _hj_names.size())
41  mooseError("Need to pass in as many hj_names as Fj_names in CoupledSwitchingTimeDerivative ",
42  name());
43 
44  // reserve space and set phase material properties
45  for (unsigned int n = 0; n < _num_j; ++n)
46  {
47  // get phase free energy and derivatives
48  _prop_Fj[n] = &getMaterialPropertyByName<Real>(_Fj_names[n]);
49  _prop_dFjdv[n] = &getMaterialPropertyDerivative<Real>(_Fj_names[n], _var.name());
50  _prop_dFjdarg[n].resize(_nvar);
51 
52  // get switching function and derivatives wrt eta_i, the nonlinear variable
53  _prop_dhjdetai[n] = &getMaterialPropertyDerivative<Real>(_hj_names[n], _v_name);
54  _prop_d2hjdetai2[n] = &getMaterialPropertyDerivative<Real>(_hj_names[n], _v_name, _v_name);
55  _prop_d2hjdetaidarg[n].resize(_nvar);
56 
57  for (unsigned int i = 0; i < _nvar; ++i)
58  {
59  MooseVariable * cvar = _coupled_moose_vars[i];
60  // Get derivatives of all Fj wrt all coupled variables
61  _prop_dFjdarg[n][i] = &getMaterialPropertyDerivative<Real>(_Fj_names[n], cvar->name());
62 
63  // Get second derivatives of all hj wrt eta_i and all coupled variables
64  _prop_d2hjdetaidarg[n][i] =
65  &getMaterialPropertyDerivative<Real>(_hj_names[n], _v_name, cvar->name());
66  }
67  }
68 }
69 
70 void
72 {
73  for (unsigned int n = 0; n < _num_j; ++n)
74  {
75  validateNonlinearCoupling<Real>(_Fj_names[n]);
76  validateNonlinearCoupling<Real>(_hj_names[n]);
77  }
78 }
79 
80 Real
82 {
83  Real sum = 0.0;
84  for (unsigned int n = 0; n < _num_j; ++n)
85  sum += (*_prop_dhjdetai[n])[_qp] * (*_prop_Fj[n])[_qp];
86 
87  return CoupledTimeDerivative::computeQpResidual() * sum;
88 }
89 
90 Real
92 {
93  Real sum = 0.0;
94  for (unsigned int n = 0; n < _num_j; ++n)
95  sum += (*_prop_dhjdetai[n])[_qp] * (*_prop_dFjdv[n])[_qp];
96 
97  return CoupledTimeDerivative::computeQpResidual() * sum * _phi[_j][_qp];
98 }
99 
100 Real
102 {
103  // get the coupled variable jvar is referring to
104  const unsigned int cvar = mapJvarToCvar(jvar);
105 
106  if (jvar == _v_var)
107  {
108  Real sum = 0.0;
109 
110  for (unsigned int n = 0; n < _num_j; ++n)
111  sum +=
112  ((*_prop_d2hjdetai2[n])[_qp] * _v_dot[_qp] + (*_prop_dhjdetai[n])[_qp] * _dv_dot[_qp]) *
113  (*_prop_Fj[n])[_qp];
114 
115  return _phi[_j][_qp] * sum * _test[_i][_qp];
116  }
117 
118  Real sum = 0.0;
119  for (unsigned int n = 0; n < _num_j; ++n)
120  sum += (*_prop_d2hjdetaidarg[n][cvar])[_qp] * (*_prop_Fj[n])[_qp] +
121  (*_prop_dhjdetai[n])[_qp] * (*_prop_dFjdarg[n][cvar])[_qp];
122 
123  return CoupledTimeDerivative::computeQpResidual() * sum * _phi[_j][_qp];
124 }
std::vector< const MaterialProperty< Real > * > _prop_Fj
Values of the functions for each phase .
const unsigned int _nvar
Number of coupled variables.
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)
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_d2hjdetaidarg
Second derivatives of the switching functions (needed for off-diagonal Jacobians) ...
std::vector< std::vector< const MaterialProperty< Real > * > > _prop_dFjdarg
Derivatives of the functions (needed for off-diagonal Jacobians)
InputParameters validParams< CoupledSwitchingTimeDerivative >()
std::vector< MaterialPropertyName > _hj_names
switching function names
const VariableName _v_name
name of order parameter that derivatives are taken wrt (needed to retrieve the derivative material pr...
std::vector< const MaterialProperty< Real > * > _prop_dhjdetai
Derivatives of the switching functions wrt the order parameter for this kernel.
std::vector< const MaterialProperty< Real > * > _prop_d2hjdetai2
Second derivatives of the switching functions wrt the order parameter for this kernel.
const unsigned int _num_j
Number of phases.