www.mooseframework.org
SwitchingFunctionConstraintLagrange.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("Lagrange multiplier kernel to constrain the sum of all switching "
15  "functions in a multiphase system. This kernel acts on the lagrange "
16  "multiplier variable.");
17  params.addParam<std::vector<MaterialPropertyName>>(
18  "h_names", "Switching Function Materials that provide h(eta_i)");
19  params.addRequiredCoupledVar("etas", "eta_i order parameters, one for each h");
20  params.addParam<Real>("epsilon", 1e-9, "Shift factor to avoid a zero pivot");
21  return params;
22 }
23 
25  const InputParameters & parameters)
26  : DerivativeMaterialInterface<Kernel>(parameters),
27  _h_names(getParam<std::vector<MaterialPropertyName>>("h_names")),
28  _num_h(_h_names.size()),
29  _h(_num_h),
30  _dh(_num_h),
31  _number_of_nl_variables(_fe_problem.getNonlinearSystemBase().nVariables()),
32  _j_eta(_number_of_nl_variables, -1),
33  _epsilon(getParam<Real>("epsilon"))
34 {
35  // parameter check. We need exactly one eta per h
36  if (_num_h != coupledComponents("etas"))
37  mooseError(
38  "Need to pass in as many h_names as etas in SwitchingFunctionConstraintLagrange kernel ",
39  name());
40 
41  // fetch switching functions (for the residual) and h derivatives (for the Jacobian)
42  for (unsigned int i = 0; i < _num_h; ++i)
43  {
44  _h[i] = &getMaterialPropertyByName<Real>(_h_names[i]);
45  _dh[i] = &getMaterialPropertyDerivative<Real>(_h_names[i], getVar("etas", i)->name());
46 
47  // generate the lookup table from j_var -> eta index
48  unsigned int num = coupled("etas", i);
49  if (num < _number_of_nl_variables)
50  _j_eta[num] = i;
51  }
52 }
53 
54 Real
56 {
57  Real g = -_epsilon * _u[_qp] - 1.0;
58  for (unsigned int i = 0; i < _num_h; ++i)
59  g += (*_h[i])[_qp];
60 
61  return _test[_i][_qp] * g;
62 }
63 
64 Real
66 {
67  return _test[_i][_qp] * -_epsilon * _phi[_j][_qp];
68 }
69 
70 Real
72 {
73  const int eta = _j_eta[j_var];
74 
75  if (eta >= 0)
76  return (*_dh[eta])[_qp] * _phi[_j][_qp] * _test[_i][_qp];
77  else
78  return 0.0;
79 }
const unsigned int _number_of_nl_variables
number of non-linear variables in the problem
SwitchingFunctionConstraintLagrange(const InputParameters &parameters)
std::vector< const MaterialProperty< Real > * > _dh
std::vector< int > _j_eta
eta index for the j_vars in the jacobian computation
std::vector< MaterialPropertyName > _h_names
Switching function names.
std::vector< const MaterialProperty< Real > * > _h
Switching functions and their drivatives.
InputParameters validParams< SwitchingFunctionConstraintLagrange >()