https://mooseframework.inl.gov
SwitchingFunctionPenalty.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 
13 
16 {
18  params.addClassDescription(
19  "Penalty kernel to constrain the sum of all switching functions in a multiphase system.");
20  params.addParam<std::vector<MaterialPropertyName>>(
21  "h_names", "Switching Function Materials that provide h(eta_i)");
22  params.addRequiredCoupledVar("etas", "eta_i order parameters, one for each h");
23  params.addParam<Real>("penalty", 1.0, "Penalty scaling factor");
24  return params;
25 }
26 
28  : DerivativeMaterialInterface<Kernel>(parameters),
29  _h_names(getParam<std::vector<MaterialPropertyName>>("h_names")),
30  _num_h(_h_names.size()),
31  _h(_num_h),
32  _dh(_num_h),
33  _penalty(getParam<Real>("penalty")),
34  _number_of_nl_variables(_sys.nVariables()),
35  _j_eta(_number_of_nl_variables, -1),
36  _a(-1)
37 {
38  // parameter check. We need exactly one eta per h
39  if (_num_h != coupledComponents("etas"))
40  paramError("h_names", "Need to pass in as many h_names as etas");
41 
42  // fetch switching functions (for the residual) and h derivatives (for the Jacobian)
43  for (unsigned int i = 0; i < _num_h; ++i)
44  {
45  _h[i] = &getMaterialPropertyByName<Real>(_h_names[i]);
46  _dh[i] = &getMaterialPropertyDerivative<Real>(_h_names[i], coupledName("etas", i));
47 
48  // generate the lookup table from j_var -> eta index
49  unsigned int num = coupled("etas", i);
50  if (num < _number_of_nl_variables)
51  _j_eta[num] = i;
52 
53  // figure out which variable this kernel is acting on
54  if (num == _var.number())
55  _a = i;
56  }
57 
58  if (_a < 0)
59  paramError("etas", "Kernel variable must be listed in etas");
60 
61  _d2h = &getMaterialPropertyDerivative<Real>(_h_names[_a], _var.name(), _var.name());
62 }
63 
64 Real
66 {
67  Real g = -1.0;
68  for (unsigned int i = 0; i < _num_h; ++i)
69  g += (*_h[i])[_qp];
70 
71  return _test[_i][_qp] * _penalty * 2.0 * g * (*_dh[_a])[_qp];
72 }
73 
74 Real
76 {
77  Real g = -1.0;
78  for (unsigned int i = 0; i < _num_h; ++i)
79  g += (*_h[i])[_qp];
80 
81  return _test[_i][_qp] * _penalty * _phi[_j][_qp] * 2.0 *
82  ((*_dh[_a])[_qp] * (*_dh[_a])[_qp] + g * (*_d2h)[_qp]);
83 }
84 
85 Real
87 {
88  const int eta = _j_eta[j_var];
89 
90  if (eta >= 0)
91  return _test[_i][_qp] * _penalty * _phi[_j][_qp] * 2.0 * (*_dh[eta])[_qp] * (*_dh[_a])[_qp];
92  else
93  return 0.0;
94 }
static InputParameters validParams()
virtual Real computeQpOffDiagJacobian(unsigned int)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
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.
static InputParameters validParams()
SwitchingFunctionPenalty(const InputParameters &parameters)
SwitchingFunctionPenalty is a constraint kernel adds a penalty to each order parameter to enforce ...
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.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
std::vector< const MaterialProperty< Real > * > _dh
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
int _a
Index of the eta this kernel is operating on.
registerMooseObject("PhaseFieldApp", SwitchingFunctionPenalty)
const MaterialProperty< Real > * _d2h
void addClassDescription(const std::string &doc_string)