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 
24 template <>
25 InputParameters
27 {
28  InputParameters params = validParams<ElemElemConstraint>();
29  params.addParam<Real>("alpha",
30  100,
31  "Stabilization parameter in Nitsche's formulation and penalty factor "
32  "in the Penalty Method. In Nitsche's formulation this should be as "
33  "small as possible while the method is still stable; while in the "
34  "Penalty Method you want this to be quite large (e.g. 1e6).");
35  params.addParam<FunctionName>("jump", 0, "Jump at the interface. Can be a Real or FunctionName.");
36  params.addParam<FunctionName>(
37  "jump_flux", 0, "Flux jump at the interface. Can be a Real or FunctionName.");
38  params.addParam<UserObjectName>(
39  "geometric_cut_userobject",
40  "Name of GeometricCutUserObject associated with this constraint.");
41  params.addParam<bool>(
42  "use_penalty",
43  false,
44  "Use the Penalty instead of Nitsche (Nitsche only works for simple diffusion problems).");
45  return params;
46 }
47 
49  : ElemElemConstraint(parameters),
50  _alpha(getParam<Real>("alpha")),
51  _jump(getFunction("jump")),
52  _jump_flux(getFunction("jump_flux")),
53  _use_penalty(getParam<bool>("use_penalty"))
54 {
55  _xfem = std::dynamic_pointer_cast<XFEM>(_fe_problem.getXFEM());
56  if (_xfem == nullptr)
57  mooseError("Problem casting to XFEM in XFEMSingleVariableConstraint");
58 
59  const UserObject * uo =
60  &(_fe_problem.getUserObjectBase(getParam<UserObjectName>("geometric_cut_userobject")));
61 
62  if (dynamic_cast<const GeometricCutUserObject *>(uo) == nullptr)
63  mooseError("UserObject casting to GeometricCutUserObject in XFEMSingleVariableConstraint");
64 
65  _interface_id = _xfem->getGeometricCutID(dynamic_cast<const GeometricCutUserObject *>(uo));
66 }
67 
69 
70 void
71 XFEMSingleVariableConstraint::reinitConstraintQuadrature(const ElementPairInfo & element_pair_info)
72 {
73  _interface_normal = element_pair_info._elem1_normal;
74  ElemElemConstraint::reinitConstraintQuadrature(element_pair_info);
75 }
76 
77 Real
79 {
80  Real r = 0;
81 
82  switch (type)
83  {
84  case Moose::Element:
85  if (!_use_penalty)
86  {
87  r -= (0.5 * _grad_u[_qp] * _interface_normal +
88  0.5 * _grad_u_neighbor[_qp] * _interface_normal) *
89  _test[_i][_qp];
90  r -= (_u[_qp] - _u_neighbor[_qp]) * 0.5 * _grad_test[_i][_qp] * _interface_normal;
91  r += 0.5 * _grad_test[_i][_qp] * _interface_normal * _jump.value(_t, _u[_qp]);
92  }
93  r += 0.5 * _test[_i][_qp] * _jump_flux.value(_t, _u[_qp]);
94  r += _alpha * (_u[_qp] - _u_neighbor[_qp] - _jump.value(_t, _u[_qp])) * _test[_i][_qp];
95  break;
96 
97  case Moose::Neighbor:
98  if (!_use_penalty)
99  {
100  r += (0.5 * _grad_u[_qp] * _interface_normal +
101  0.5 * _grad_u_neighbor[_qp] * _interface_normal) *
102  _test_neighbor[_i][_qp];
103  r -= (_u[_qp] - _u_neighbor[_qp]) * 0.5 * _grad_test_neighbor[_i][_qp] * _interface_normal;
104  r += 0.5 * _grad_test_neighbor[_i][_qp] * _interface_normal *
105  _jump.value(_t, _u_neighbor[_qp]);
106  }
107  r += 0.5 * _test_neighbor[_i][_qp] * _jump_flux.value(_t, _u_neighbor[_qp]);
108  r -= _alpha * (_u[_qp] - _u_neighbor[_qp] - _jump.value(_t, _u_neighbor[_qp])) *
109  _test_neighbor[_i][_qp];
110  break;
111  }
112  return r;
113 }
114 
115 Real
117 {
118  Real r = 0;
119 
120  switch (type)
121  {
122  case Moose::ElementElement:
123  if (!_use_penalty)
124  r += -0.5 * _grad_phi[_j][_qp] * _interface_normal * _test[_i][_qp] -
125  _phi[_j][_qp] * 0.5 * _grad_test[_i][_qp] * _interface_normal;
126  r += _alpha * _phi[_j][_qp] * _test[_i][_qp];
127  break;
128 
129  case Moose::ElementNeighbor:
130  if (!_use_penalty)
131  r += -0.5 * _grad_phi_neighbor[_j][_qp] * _interface_normal * _test[_i][_qp] +
132  _phi_neighbor[_j][_qp] * 0.5 * _grad_test[_i][_qp] * _interface_normal;
133  r -= _alpha * _phi_neighbor[_j][_qp] * _test[_i][_qp];
134  break;
135 
136  case Moose::NeighborElement:
137  if (!_use_penalty)
138  r += 0.5 * _grad_phi[_j][_qp] * _interface_normal * _test_neighbor[_i][_qp] -
139  _phi[_j][_qp] * 0.5 * _grad_test_neighbor[_i][_qp] * _interface_normal;
140  r -= _alpha * _phi[_j][_qp] * _test_neighbor[_i][_qp];
141  break;
142 
143  case Moose::NeighborNeighbor:
144  if (!_use_penalty)
145  r += 0.5 * _grad_phi_neighbor[_j][_qp] * _interface_normal * _test_neighbor[_i][_qp] +
146  _phi_neighbor[_j][_qp] * 0.5 * _grad_test_neighbor[_i][_qp] * _interface_normal;
147  r += _alpha * _phi_neighbor[_j][_qp] * _test_neighbor[_i][_qp];
148  break;
149  }
150 
151  return r;
152 }
XFEMSingleVariableConstraint::XFEMSingleVariableConstraint
XFEMSingleVariableConstraint(const InputParameters &parameters)
Definition: XFEMSingleVariableConstraint.C:48
XFEMSingleVariableConstraint::computeQpJacobian
virtual Real computeQpJacobian(Moose::DGJacobianType type) override
Definition: XFEMSingleVariableConstraint.C:116
validParams< XFEMSingleVariableConstraint >
InputParameters validParams< XFEMSingleVariableConstraint >()
Definition: XFEMSingleVariableConstraint.C:26
XFEMSingleVariableConstraint::_xfem
std::shared_ptr< XFEM > _xfem
Pointer to the XFEM controller object.
Definition: XFEMSingleVariableConstraint.h:56
XFEMSingleVariableConstraint::~XFEMSingleVariableConstraint
virtual ~XFEMSingleVariableConstraint()
Definition: XFEMSingleVariableConstraint.C:68
GeometricCutUserObject.h
registerMooseObject
registerMooseObject("XFEMApp", XFEMSingleVariableConstraint)
XFEMSingleVariableConstraint::computeQpResidual
virtual Real computeQpResidual(Moose::DGResidualType type) override
Definition: XFEMSingleVariableConstraint.C:78
XFEMSingleVariableConstraint::_alpha
Real _alpha
Stabilization parameter in Nitsche's formulation and penalty factor in the Penalty Method.
Definition: XFEMSingleVariableConstraint.h:44
XFEM.h
XFEMSingleVariableConstraint::_jump
const Function & _jump
Change in variable value at the interface.
Definition: XFEMSingleVariableConstraint.h:47
XFEMSingleVariableConstraint::_jump_flux
const Function & _jump_flux
Change in flux of variable value at the interface.
Definition: XFEMSingleVariableConstraint.h:50
XFEMSingleVariableConstraint.h
XFEMSingleVariableConstraint::_interface_normal
Point _interface_normal
Vector normal to the internal interface.
Definition: XFEMSingleVariableConstraint.h:40
XFEMSingleVariableConstraint::reinitConstraintQuadrature
virtual void reinitConstraintQuadrature(const ElementPairInfo &element_pair_info) override
Definition: XFEMSingleVariableConstraint.C:71
XFEMSingleVariableConstraint::_use_penalty
bool _use_penalty
Use penalty formulation.
Definition: XFEMSingleVariableConstraint.h:53
XFEMSingleVariableConstraint
Definition: XFEMSingleVariableConstraint.h:26