www.mooseframework.org
XFEMSingleVariableConstraint.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 
12 // MOOSE includes
13 #include "Assembly.h"
14 #include "ElementPairInfo.h"
15 #include "FEProblem.h"
16 #include "GeometricCutUserObject.h"
17 #include "XFEM.h"
18 #include "Function.h"
19 
20 #include "libmesh/quadrature.h"
21 
23 
26 {
28  params.addParam<Real>("alpha",
29  100,
30  "Stabilization parameter in Nitsche's formulation and penalty factor "
31  "in the Penalty Method. In Nitsche's formulation this should be as "
32  "small as possible while the method is still stable; while in the "
33  "Penalty Method you want this to be quite large (e.g. 1e6).");
34  params.addParam<FunctionName>("jump", 0, "Jump at the interface. Can be a Real or FunctionName.");
35  params.addParam<FunctionName>(
36  "jump_flux", 0, "Flux jump at the interface. Can be a Real or FunctionName.");
37  params.addParam<UserObjectName>(
38  "geometric_cut_userobject",
39  "Name of GeometricCutUserObject associated with this constraint.");
40  params.addParam<bool>(
41  "use_penalty",
42  false,
43  "Use the Penalty instead of Nitsche (Nitsche only works for simple diffusion problems).");
44  params.addClassDescription("Enforce constraints on the value or flux associated with a variable "
45  "at an XFEM interface.");
46  return params;
47 }
48 
50  : ElemElemConstraint(parameters),
51  _alpha(getParam<Real>("alpha")),
52  _jump(getFunction("jump")),
53  _jump_flux(getFunction("jump_flux")),
54  _use_penalty(getParam<bool>("use_penalty"))
55 {
56  _xfem = std::dynamic_pointer_cast<XFEM>(_fe_problem.getXFEM());
57  if (_xfem == nullptr)
58  mooseError("Problem casting to XFEM in XFEMSingleVariableConstraint");
59 
60  const UserObject * uo =
61  &(_fe_problem.getUserObjectBase(getParam<UserObjectName>("geometric_cut_userobject")));
62 
63  if (dynamic_cast<const GeometricCutUserObject *>(uo) == nullptr)
64  mooseError("UserObject casting to GeometricCutUserObject in XFEMSingleVariableConstraint");
65 
66  _interface_id = _xfem->getGeometricCutID(dynamic_cast<const GeometricCutUserObject *>(uo));
67 }
68 
70 
71 void
73 {
74  _interface_normal = element_pair_info._elem1_normal;
76 }
77 
78 Real
80 {
81  Real r = 0;
82 
83  switch (type)
84  {
85  case Moose::Element:
86  if (!_use_penalty)
87  {
88  r -= (0.5 * _grad_u[_qp] * _interface_normal +
90  _test[_i][_qp];
91  r -= (_u[_qp] - _u_neighbor[_qp]) * 0.5 * _grad_test[_i][_qp] * _interface_normal;
92  r += 0.5 * _grad_test[_i][_qp] * _interface_normal * _jump.value(_t, _u[_qp]);
93  }
94  r += 0.5 * _test[_i][_qp] * _jump_flux.value(_t, _u[_qp]);
95  r += _alpha * (_u[_qp] - _u_neighbor[_qp] - _jump.value(_t, _u[_qp])) * _test[_i][_qp];
96  break;
97 
98  case Moose::Neighbor:
99  if (!_use_penalty)
100  {
101  r += (0.5 * _grad_u[_qp] * _interface_normal +
107  }
109  r -= _alpha * (_u[_qp] - _u_neighbor[_qp] - _jump.value(_t, _u_neighbor[_qp])) *
111  break;
112  }
113  return r;
114 }
115 
116 Real
118 {
119  Real r = 0;
120 
121  switch (type)
122  {
124  if (!_use_penalty)
125  r += -0.5 * _grad_phi[_j][_qp] * _interface_normal * _test[_i][_qp] -
126  _phi[_j][_qp] * 0.5 * _grad_test[_i][_qp] * _interface_normal;
127  r += _alpha * _phi[_j][_qp] * _test[_i][_qp];
128  break;
129 
131  if (!_use_penalty)
132  r += -0.5 * _grad_phi_neighbor[_j][_qp] * _interface_normal * _test[_i][_qp] +
134  r -= _alpha * _phi_neighbor[_j][_qp] * _test[_i][_qp];
135  break;
136 
138  if (!_use_penalty)
139  r += 0.5 * _grad_phi[_j][_qp] * _interface_normal * _test_neighbor[_i][_qp] -
141  r -= _alpha * _phi[_j][_qp] * _test_neighbor[_i][_qp];
142  break;
143 
145  if (!_use_penalty)
149  break;
150  }
151 
152  return r;
153 }
virtual Real computeQpJacobian(Moose::DGJacobianType type) override
std::shared_ptr< XFEM > _xfem
Pointer to the XFEM controller object.
NeighborElement
FEProblemBase & _fe_problem
const VariablePhiGradient & _grad_phi_neighbor
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
unsigned int _interface_id
const Function & _jump_flux
Change in flux of variable value at the interface.
const VariableValue & _u_neighbor
Real _alpha
Stabilization parameter in Nitsche&#39;s formulation and penalty factor in the Penalty Method...
registerMooseObject("XFEMApp", XFEMSingleVariableConstraint)
XFEMSingleVariableConstraint(const InputParameters &parameters)
const VariableTestGradient & _grad_test
DGResidualType
This is the XFEM class.
Definition: XFEM.h:107
ElementElement
const VariableTestValue & _test_neighbor
static InputParameters validParams()
ElementNeighbor
virtual void reinitConstraintQuadrature(const ElementPairInfo &element_pair_info)
bool _use_penalty
Use penalty formulation.
const Function & _jump
Change in variable value at the interface.
const VariableTestValue & _test
const std::string & type() const
virtual Real computeQpResidual(Moose::DGResidualType type) override
const VariableGradient & _grad_u
const VariableGradient & _grad_u_neighbor
const VariablePhiValue & _phi_neighbor
const VariableTestGradient & _grad_test_neighbor
DGJacobianType
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const VariableValue & _u
const VariablePhiGradient & _grad_phi
std::shared_ptr< XFEMInterface > getXFEM()
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
const VariablePhiValue & _phi
const UserObject & getUserObjectBase(const std::string &name, const THREAD_ID tid=0) const
virtual Real value(Real t, const Point &p) const
virtual void reinitConstraintQuadrature(const ElementPairInfo &element_pair_info) override
unsigned int _j
unsigned int _qp
NeighborNeighbor
unsigned int _i
Point _interface_normal
Vector normal to the internal interface.