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