www.mooseframework.org
SwitchingFunctionConstraintLagrange.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("Lagrange multiplier kernel to constrain the sum of all switching "
20  "functions in a multiphase system. This kernel acts on the Lagrange "
21  "multiplier variable.");
22  params.addParam<std::vector<MaterialPropertyName>>("h_names", "Switching function materials");
23  params.addRequiredCoupledVar("etas", "eta order parameters");
24  params.addParam<Real>("epsilon", 1e-9, "Shift factor to avoid a zero pivot");
25  return params;
26 }
27 
29  const InputParameters & parameters)
30  : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
31  _h_names(getParam<std::vector<MaterialPropertyName>>("h_names")),
32  _num_h(_h_names.size()),
33  _h(_num_h),
34  _dh(_num_h),
35  _eta_map(getParameterJvarMap("etas")),
36  _epsilon(getParam<Real>("epsilon"))
37 {
38  // parameter check. We need exactly one eta per h
39  if (_num_h != coupledComponents("etas"))
40  paramError("etas", "Need to pass in as many etas as h_names");
41 
42  // fetch switching functions (for the residual) and h derivatives (for the Jacobian)
43  for (std::size_t i = 0; i < _num_h; ++i)
44  {
45  _h[i] = &getMaterialPropertyByName<Real>(_h_names[i]);
46 
47  _dh[i].resize(_num_h);
48  for (std::size_t j = 0; j < _num_h; ++j)
49  _dh[i][j] = &getMaterialPropertyDerivative<Real>(_h_names[i], getVar("etas", j)->name());
50  }
51 }
52 
53 Real
55 {
56  Real g = -_epsilon * _u[_qp] - 1.0;
57  for (std::size_t i = 0; i < _num_h; ++i)
58  g += (*_h[i])[_qp];
59 
60  return _test[_i][_qp] * g;
61 }
62 
63 Real
65 {
66  return _test[_i][_qp] * -_epsilon * _phi[_j][_qp];
67 }
68 
69 Real
71 {
72  auto eta = mapJvarToCvar(jvar, _eta_map);
73  if (eta >= 0)
74  {
75  Real g = 0.0;
76  for (std::size_t i = 0; i < _num_h; ++i)
77  g += (*_dh[i][eta])[_qp] * _phi[_j][_qp];
78  return g * _test[_i][_qp];
79  }
80 
81  return 0.0;
82 }
SwitchingFunctionConstraintLagrange::computeQpResidual
virtual Real computeQpResidual()
Definition: SwitchingFunctionConstraintLagrange.C:54
SwitchingFunctionConstraintLagrange.h
registerMooseObject
registerMooseObject("PhaseFieldApp", SwitchingFunctionConstraintLagrange)
SwitchingFunctionConstraintLagrange::_epsilon
Real _epsilon
shift factor
Definition: SwitchingFunctionConstraintLagrange.h:55
SwitchingFunctionConstraintLagrange::computeQpOffDiagJacobian
virtual Real computeQpOffDiagJacobian(unsigned int)
Definition: SwitchingFunctionConstraintLagrange.C:70
SwitchingFunctionConstraintLagrange::SwitchingFunctionConstraintLagrange
SwitchingFunctionConstraintLagrange(const InputParameters &parameters)
Definition: SwitchingFunctionConstraintLagrange.C:28
SwitchingFunctionConstraintLagrange::_num_h
unsigned int _num_h
number of switching functions
Definition: SwitchingFunctionConstraintLagrange.h:43
SwitchingFunctionConstraintLagrange::_dh
std::vector< std::vector< const MaterialProperty< Real > * > > _dh
Switching function derivatives.
Definition: SwitchingFunctionConstraintLagrange.h:49
SwitchingFunctionConstraintLagrange::_h_names
std::vector< MaterialPropertyName > _h_names
Switching function names.
Definition: SwitchingFunctionConstraintLagrange.h:40
name
const std::string name
Definition: Setup.h:21
SwitchingFunctionConstraintLagrange::computeQpJacobian
virtual Real computeQpJacobian()
Definition: SwitchingFunctionConstraintLagrange.C:64
validParams< SwitchingFunctionConstraintLagrange >
InputParameters validParams< SwitchingFunctionConstraintLagrange >()
Definition: SwitchingFunctionConstraintLagrange.C:16
SwitchingFunctionConstraintLagrange::_h
std::vector< const MaterialProperty< Real > * > _h
Switching functions.
Definition: SwitchingFunctionConstraintLagrange.h:46
SwitchingFunctionConstraintLagrange::_eta_map
const JvarMap & _eta_map
map for getting the "etas" index from jvar
Definition: SwitchingFunctionConstraintLagrange.h:52
SwitchingFunctionConstraintLagrange
SwitchingFunctionConstraintLagrange is a constraint kernel that acts on the lambda lagrange multiplie...
Definition: SwitchingFunctionConstraintLagrange.h:28