www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SwitchingFunctionPenalty Class Reference

SwitchingFunctionPenalty is a constraint kernel adds a penalty to each order parameter to enforce \( \sum_n h_i(\eta_i) \equiv 1 \). More...

#include <SwitchingFunctionPenalty.h>

Inheritance diagram for SwitchingFunctionPenalty:
[legend]

Public Member Functions

 SwitchingFunctionPenalty (const InputParameters &parameters)
 

Protected Member Functions

virtual Real computeQpResidual ()
 
virtual Real computeQpJacobian ()
 
virtual Real computeQpOffDiagJacobian (unsigned int)
 

Protected Attributes

std::vector< MaterialPropertyName > _h_names
 Switching function names. More...
 
unsigned int _num_h
 
std::vector< const MaterialProperty< Real > * > _h
 Switching functions and their drivatives. More...
 
std::vector< const MaterialProperty< Real > * > _dh
 
const MaterialProperty< Real > * _d2h
 
const Real _penalty
 Penalty pre-factor. More...
 
const unsigned int _number_of_nl_variables
 number of non-linear variables in the problem More...
 
std::vector< int > _j_eta
 eta index for the j_vars in the jacobian computation More...
 
int _a
 Index of the eta this kernel is operating on. More...
 

Detailed Description

SwitchingFunctionPenalty is a constraint kernel adds a penalty to each order parameter to enforce \( \sum_n h_i(\eta_i) \equiv 1 \).

Definition at line 27 of file SwitchingFunctionPenalty.h.

Constructor & Destructor Documentation

◆ SwitchingFunctionPenalty()

SwitchingFunctionPenalty::SwitchingFunctionPenalty ( const InputParameters &  parameters)

Definition at line 28 of file SwitchingFunctionPenalty.C.

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()),
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 }
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.
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

Member Function Documentation

◆ computeQpJacobian()

Real SwitchingFunctionPenalty::computeQpJacobian ( )
protectedvirtual

Definition at line 76 of file SwitchingFunctionPenalty.C.

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 }
std::vector< const MaterialProperty< Real > * > _h
Switching functions and their drivatives.
const Real _penalty
Penalty pre-factor.
std::vector< const MaterialProperty< Real > * > _dh
int _a
Index of the eta this kernel is operating on.

◆ computeQpOffDiagJacobian()

Real SwitchingFunctionPenalty::computeQpOffDiagJacobian ( unsigned int  j_var)
protectedvirtual

Definition at line 87 of file SwitchingFunctionPenalty.C.

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 }
std::vector< int > _j_eta
eta index for the j_vars in the jacobian computation
const Real _penalty
Penalty pre-factor.
std::vector< const MaterialProperty< Real > * > _dh
int _a
Index of the eta this kernel is operating on.

◆ computeQpResidual()

Real SwitchingFunctionPenalty::computeQpResidual ( )
protectedvirtual

Definition at line 66 of file SwitchingFunctionPenalty.C.

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 }
std::vector< const MaterialProperty< Real > * > _h
Switching functions and their drivatives.
const Real _penalty
Penalty pre-factor.
std::vector< const MaterialProperty< Real > * > _dh
int _a
Index of the eta this kernel is operating on.

Member Data Documentation

◆ _a

int SwitchingFunctionPenalty::_a
protected

Index of the eta this kernel is operating on.

Definition at line 55 of file SwitchingFunctionPenalty.h.

Referenced by computeQpJacobian(), computeQpOffDiagJacobian(), computeQpResidual(), and SwitchingFunctionPenalty().

◆ _d2h

const MaterialProperty<Real>* SwitchingFunctionPenalty::_d2h
protected

Definition at line 43 of file SwitchingFunctionPenalty.h.

Referenced by SwitchingFunctionPenalty().

◆ _dh

std::vector<const MaterialProperty<Real> *> SwitchingFunctionPenalty::_dh
protected

◆ _h

std::vector<const MaterialProperty<Real> *> SwitchingFunctionPenalty::_h
protected

Switching functions and their drivatives.

Definition at line 42 of file SwitchingFunctionPenalty.h.

Referenced by computeQpJacobian(), computeQpResidual(), and SwitchingFunctionPenalty().

◆ _h_names

std::vector<MaterialPropertyName> SwitchingFunctionPenalty::_h_names
protected

Switching function names.

Definition at line 38 of file SwitchingFunctionPenalty.h.

Referenced by SwitchingFunctionPenalty().

◆ _j_eta

std::vector<int> SwitchingFunctionPenalty::_j_eta
protected

eta index for the j_vars in the jacobian computation

Definition at line 52 of file SwitchingFunctionPenalty.h.

Referenced by computeQpOffDiagJacobian(), and SwitchingFunctionPenalty().

◆ _num_h

unsigned int SwitchingFunctionPenalty::_num_h
protected

◆ _number_of_nl_variables

const unsigned int SwitchingFunctionPenalty::_number_of_nl_variables
protected

number of non-linear variables in the problem

Definition at line 49 of file SwitchingFunctionPenalty.h.

Referenced by SwitchingFunctionPenalty().

◆ _penalty

const Real SwitchingFunctionPenalty::_penalty
protected

Penalty pre-factor.

Definition at line 46 of file SwitchingFunctionPenalty.h.

Referenced by computeQpJacobian(), computeQpOffDiagJacobian(), and computeQpResidual().


The documentation for this class was generated from the following files: