www.mooseframework.org
ACSwitching.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 /****************************************************************/
7 #include "ACSwitching.h"
8 
9 template <>
10 InputParameters
12 {
13  InputParameters params = ACBulk<Real>::validParams();
14  params.addClassDescription(
15  "Kernel for Allen-Cahn equation that adds derivatives of switching functions and energies");
16  params.addRequiredParam<std::vector<MaterialPropertyName>>(
17  "Fj_names", "List of free energies for each phase. Place in same order as hj_names!");
18  params.addRequiredParam<std::vector<MaterialPropertyName>>(
19  "hj_names", "Switching Function Materials that provide h. Place in same order as Fj_names!");
20  return params;
21 }
22 
23 ACSwitching::ACSwitching(const InputParameters & parameters)
24  : ACBulk<Real>(parameters),
25  _nvar(_coupled_moose_vars.size()),
26  _etai_name(_var.name()),
27  _Fj_names(getParam<std::vector<MaterialPropertyName>>("Fj_names")),
28  _num_j(_Fj_names.size()),
29  _prop_Fj(_num_j),
30  _prop_dFjdarg(_num_j),
31  _hj_names(getParam<std::vector<MaterialPropertyName>>("hj_names")),
32  _prop_dhjdetai(_num_j),
33  _prop_d2hjdetai2(_num_j),
34  _prop_d2hjdetaidarg(_num_j)
35 {
36  // check passed in parameter vectors
37  if (_num_j != _hj_names.size())
38  mooseError("Need to pass in as many hj_names as Fj_names in ACSwitching ", name());
39 
40  // reserve space and set phase material properties
41  for (unsigned int n = 0; n < _num_j; ++n)
42  {
43  // get phase free energy
44  _prop_Fj[n] = &getMaterialPropertyByName<Real>(_Fj_names[n]);
45  _prop_dFjdarg[n].resize(_nvar);
46 
47  // get switching derivatives wrt eta_i, the nonlinear variable
48  _prop_dhjdetai[n] = &getMaterialPropertyDerivative<Real>(_hj_names[n], _etai_name);
49  _prop_d2hjdetai2[n] =
50  &getMaterialPropertyDerivative<Real>(_hj_names[n], _etai_name, _etai_name);
51  _prop_d2hjdetaidarg[n].resize(_nvar);
52 
53  for (unsigned int i = 0; i < _nvar; ++i)
54  {
55  MooseVariable * cvar = _coupled_moose_vars[i];
56  // Get derivatives of all Fj wrt all coupled variables
57  _prop_dFjdarg[n][i] = &getMaterialPropertyDerivative<Real>(_Fj_names[n], cvar->name());
58 
59  // Get second derivatives of all hj wrt eta_i and all coupled variables
60  _prop_d2hjdetaidarg[n][i] =
61  &getMaterialPropertyDerivative<Real>(_hj_names[n], _etai_name, cvar->name());
62  }
63  }
64 }
65 
66 void
67 ACSwitching::initialSetup()
68 {
70 
71  for (unsigned int n = 0; n < _num_j; ++n)
72  {
73  validateNonlinearCoupling<Real>(_Fj_names[n]);
74  validateNonlinearCoupling<Real>(_hj_names[n]);
75  }
76 }
77 
78 Real
79 ACSwitching::computeDFDOP(PFFunctionType type)
80 {
81  Real sum = 0.0;
82 
83  switch (type)
84  {
85  case Residual:
86  for (unsigned int n = 0; n < _num_j; ++n)
87  sum += (*_prop_dhjdetai[n])[_qp] * (*_prop_Fj[n])[_qp];
88 
89  return sum;
90 
91  case Jacobian:
92  for (unsigned int n = 0; n < _num_j; ++n)
93  sum += (*_prop_d2hjdetai2[n])[_qp] * (*_prop_Fj[n])[_qp];
94 
95  return _phi[_j][_qp] * sum;
96  }
97 
98  mooseError("Invalid type passed in to ACSwitching::computeDFDOP");
99 }
100 
101 Real
102 ACSwitching::computeQpOffDiagJacobian(unsigned int jvar)
103 {
104  // get the coupled variable jvar is referring to
105  const unsigned int cvar = mapJvarToCvar(jvar);
106 
107  // first get dependence of mobility _L on other variables using parent class
108  // member function
110 
111  // Then add dependence of ACSwitching on other variables
112  Real sum = 0.0;
113  for (unsigned int n = 0; n < _num_j; ++n)
114  sum += (*_prop_d2hjdetaidarg[n][cvar])[_qp] * (*_prop_Fj[n])[_qp] +
115  (*_prop_dhjdetai[n])[_qp] * (*_prop_dFjdarg[n][cvar])[_qp];
116 
117  res += _L[_qp] * sum * _phi[_j][_qp] * _test[_i][_qp];
118 
119  return res;
120 }
virtual void initialSetup()
Definition: ACBulk.h:83
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
Definition: ACBulk.h:114
static InputParameters validParams()
Definition: ACBulk.h:72
InputParameters validParams< ACSwitching >()
Definition: ACSwitching.C:11