www.mooseframework.org
SwitchingFunctionPenalty.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<Kernel>();
14  params.addClassDescription(
15  "Penalty kernel to constrain the sum of all switching functions in a multiphase system.");
16  params.addParam<std::vector<MaterialPropertyName>>(
17  "h_names", "Switching Function Materials that provide h(eta_i)");
18  params.addRequiredCoupledVar("etas", "eta_i order parameters, one for each h");
19  params.addParam<Real>("penalty", 1.0, "Penalty scaling factor");
20  return params;
21 }
22 
23 SwitchingFunctionPenalty::SwitchingFunctionPenalty(const InputParameters & parameters)
24  : DerivativeMaterialInterface<Kernel>(parameters),
25  _h_names(getParam<std::vector<MaterialPropertyName>>("h_names")),
26  _num_h(_h_names.size()),
27  _h(_num_h),
28  _dh(_num_h),
29  _penalty(getParam<Real>("penalty")),
30  _number_of_nl_variables(_fe_problem.getNonlinearSystemBase().nVariables()),
31  _j_eta(_number_of_nl_variables, -1),
32  _a(-1)
33 {
34  // parameter check. We need exactly one eta per h
35  if (_num_h != coupledComponents("etas"))
36  mooseError("Need to pass in as many h_names as etas in SwitchingFunctionPenalty kernel ",
37  name());
38 
39  // fetch switching functions (for the residual) and h derivatives (for the Jacobian)
40  for (unsigned int i = 0; i < _num_h; ++i)
41  {
42  _h[i] = &getMaterialPropertyByName<Real>(_h_names[i]);
43  _dh[i] = &getMaterialPropertyDerivative<Real>(_h_names[i], getVar("etas", i)->name());
44 
45  // generate the lookup table from j_var -> eta index
46  unsigned int num = coupled("etas", i);
47  if (num < _number_of_nl_variables)
48  _j_eta[num] = i;
49 
50  // figure out which variable this kernel is acting on
51  if (num == _var.number())
52  _a = i;
53  }
54 
55  if (_a < 0)
56  mooseError("Kernel variable must be listed in etas for SwitchingFunctionPenalty kernel ",
57  name());
58 
59  _d2h = &getMaterialPropertyDerivative<Real>(_h_names[_a], _var.name(), _var.name());
60 }
61 
62 Real
64 {
65  Real g = -1.0;
66  for (unsigned int i = 0; i < _num_h; ++i)
67  g += (*_h[i])[_qp];
68 
69  return _test[_i][_qp] * _penalty * 2.0 * g * (*_dh[_a])[_qp];
70 }
71 
72 Real
74 {
75  Real g = -1.0;
76  for (unsigned int i = 0; i < _num_h; ++i)
77  g += (*_h[i])[_qp];
78 
79  return _test[_i][_qp] * _penalty * _phi[_j][_qp] * 2.0 *
80  ((*_dh[_a])[_qp] * (*_dh[_a])[_qp] + g * (*_d2h)[_qp]);
81 }
82 
83 Real
85 {
86  const int eta = _j_eta[j_var];
87 
88  if (eta >= 0)
89  return _test[_i][_qp] * _penalty * _phi[_j][_qp] * 2.0 * (*_dh[eta])[_qp] * (*_dh[_a])[_qp];
90  else
91  return 0.0;
92 }
virtual Real computeQpOffDiagJacobian(unsigned int)
const unsigned int _number_of_nl_variables
number of non-linear variables in the problem
std::vector< const MaterialProperty< Real > * > _h
Switching functions and their drivatives.
InputParameters validParams< SwitchingFunctionPenalty >()
SwitchingFunctionPenalty(const InputParameters &parameters)
std::vector< int > _j_eta
eta index for the j_vars in the jacobian computation
std::vector< MaterialPropertyName > _h_names
Switching function names.
const Real _penalty
Penalty pre-factor.
std::vector< const MaterialProperty< Real > * > _dh
int _a
Index of the eta this kernel is operating on.
const MaterialProperty< Real > * _d2h