www.mooseframework.org
EqualValueEmbeddedConstraint.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 
10 // MOOSE includes
12 #include "FEProblem.h"
13 #include "DisplacedProblem.h"
14 #include "AuxiliarySystem.h"
15 #include "SystemBase.h"
16 #include "Assembly.h"
17 #include "MooseMesh.h"
18 #include "Executioner.h"
19 #include "AddVariableAction.h"
20 
21 #include "libmesh/string_to_enum.h"
22 #include "libmesh/sparse_matrix.h"
23 
25 
27 
30 {
33  params.addClassDescription("This is a constraint enforcing overlapping portions of two blocks to "
34  "have the same variable value");
35  params.set<bool>("use_displaced_mesh") = false;
36  MooseEnum formulation("kinematic penalty", "kinematic");
37  params.addParam<MooseEnum>(
38  "formulation", formulation, "Formulation used to enforce the constraint");
39  params.addRequiredParam<Real>(
40  "penalty",
41  "Penalty parameter used in constraint enforcement for kinematic and penalty formulations.");
42 
43  return params;
44 }
45 
47  : NodeElemConstraint(parameters),
48  _displaced_problem(parameters.get<FEProblemBase *>("_fe_problem_base")->getDisplacedProblem()),
49  _fe_problem(*parameters.get<FEProblem *>("_fe_problem")),
50  _formulation(getParam<MooseEnum>("formulation").getEnum<Formulation>()),
51  _penalty(getParam<Real>("penalty")),
52  _residual_copy(_sys.residualGhosted())
53 {
56 }
57 
58 void
60 {
61  // get mesh pointLocator
62  std::unique_ptr<PointLocatorBase> pointLocator = _mesh.getPointLocator();
63  pointLocator->enable_out_of_mesh_mode();
64  const std::set<subdomain_id_type> allowed_subdomains{_master};
65 
66  // slave id and master id
67  dof_id_type sid, mid;
68 
69  // prepare _slave_to_master_map
70  std::set<dof_id_type> unique_slave_node_ids;
71  const MeshBase & meshhelper = _mesh.getMesh();
72  for (const auto & elem : as_range(meshhelper.active_subdomain_elements_begin(_slave),
73  meshhelper.active_subdomain_elements_end(_slave)))
74  {
75  for (auto & sn : elem->node_ref_range())
76  {
77  sid = sn.id();
78  if (_slave_to_master_map.find(sid) == _slave_to_master_map.end())
79  {
80  // master element
81  const Elem * me = pointLocator->operator()(sn, &allowed_subdomains);
82  if (me != NULL)
83  {
84  mid = me->id();
85  _slave_to_master_map.insert(std::pair<dof_id_type, dof_id_type>(sid, mid));
87  }
88  }
89  }
90  }
91 }
92 
93 bool
95 {
96  // master element
97  auto it = _slave_to_master_map.find(_current_node->id());
98 
99  if (it != _slave_to_master_map.end())
100  {
101  const Elem * master_elem = _mesh.elemPtr(it->second);
102  std::vector<Point> points = {*_current_node};
103 
104  // reinit variables on the master element at the slave point
105  _fe_problem.setNeighborSubdomainID(master_elem, 0);
106  _fe_problem.reinitNeighborPhys(master_elem, points, 0);
107 
109 
110  return true;
111  }
112  return false;
113 }
114 
115 void
117 {
118  const Node * node = _current_node;
119  unsigned int sys_num = _sys.number();
120  dof_id_type dof_number = node->dof_number(sys_num, _var.number(), 0);
121 
122  switch (_formulation)
123  {
125  _constraint_residual = -_residual_copy(dof_number);
126  break;
127 
130  break;
131 
132  default:
133  mooseError("Invalid formulation");
134  break;
135  }
136 }
137 
138 Real
140 {
141  return _u_slave[_qp];
142 }
143 
144 Real
146 {
147  Real resid = _constraint_residual;
148 
149  switch (type)
150  {
151  case Moose::Slave:
152  {
154  {
155  Real pen_force = _penalty * (_u_slave[_qp] - _u_master[_qp]);
156  resid += pen_force;
157  }
158  return _test_slave[_i][_qp] * resid;
159  }
160 
161  case Moose::Master:
162  return _test_master[_i][_qp] * -resid;
163  }
164 
165  return 0.0;
166 }
167 
168 Real
170 {
171  unsigned int sys_num = _sys.number();
172  const Real penalty = _penalty;
173  Real curr_jac, slave_jac;
174 
175  switch (type)
176  {
177  case Moose::SlaveSlave:
178  switch (_formulation)
179  {
181  curr_jac = (*_jacobian)(_current_node->dof_number(sys_num, _var.number(), 0),
183  return -curr_jac + _phi_slave[_j][_qp] * penalty * _test_slave[_i][_qp];
185  return _phi_slave[_j][_qp] * penalty * _test_slave[_i][_qp];
186  default:
187  mooseError("Invalid formulation");
188  }
189 
190  case Moose::SlaveMaster:
191  switch (_formulation)
192  {
194  return -_phi_master[_j][_qp] * penalty * _test_slave[_i][_qp];
196  return -_phi_master[_j][_qp] * penalty * _test_slave[_i][_qp];
197  default:
198  mooseError("Invalid formulation");
199  }
200 
201  case Moose::MasterSlave:
202  switch (_formulation)
203  {
205  slave_jac = (*_jacobian)(_current_node->dof_number(sys_num, _var.number(), 0),
207  return slave_jac * _test_master[_i][_qp];
209  return -_phi_slave[_j][_qp] * penalty * _test_master[_i][_qp];
210  default:
211  mooseError("Invalid formulation");
212  }
213 
214  case Moose::MasterMaster:
215  switch (_formulation)
216  {
218  return 0.0;
220  return _test_master[_i][_qp] * penalty * _phi_master[_j][_qp];
221  default:
222  mooseError("Invalid formulation");
223  }
224 
225  default:
226  mooseError("Unsupported type");
227  break;
228  }
229  return 0.0;
230 }
231 
232 Real
234  unsigned int /*jvar*/)
235 {
236  Real curr_jac, slave_jac;
237  unsigned int sys_num = _sys.number();
238 
239  switch (type)
240  {
241  case Moose::SlaveSlave:
242  curr_jac = (*_jacobian)(_current_node->dof_number(sys_num, _var.number(), 0),
244  return -curr_jac;
245 
246  case Moose::SlaveMaster:
247  return 0.0;
248 
249  case Moose::MasterSlave:
250  switch (_formulation)
251  {
253  slave_jac = (*_jacobian)(_current_node->dof_number(sys_num, _var.number(), 0),
255  return slave_jac * _test_master[_i][_qp];
257  return 0.0;
258  default:
259  mooseError("Invalid formulation");
260  }
261 
262  case Moose::MasterMaster:
263  return 0.0;
264 
265  default:
266  mooseError("Unsupported type");
267  break;
268  }
269 
270  return 0.0;
271 }
272 
273 void
275 {
277 
278  DenseMatrix<Number> & Knn =
280 
281  _Kee.resize(_test_slave.size(), _connected_dof_indices.size());
282 
283  for (_i = 0; _i < _test_slave.size(); _i++)
284  // Loop over the connected dof indices so we can get all the jacobian contributions
285  for (_j = 0; _j < _connected_dof_indices.size(); _j++)
287 
288  DenseMatrix<Number> & Ken =
290  if (Ken.m() && Ken.n())
291  for (_i = 0; _i < _test_slave.size(); _i++)
292  for (_j = 0; _j < _phi_master.size(); _j++)
294 
295  _Kne.resize(_test_master.size(), _connected_dof_indices.size());
296  for (_i = 0; _i < _test_master.size(); _i++)
297  // Loop over the connected dof indices so we can get all the jacobian contributions
298  for (_j = 0; _j < _connected_dof_indices.size(); _j++)
300 
301  if (Knn.m() && Knn.n())
302  for (_i = 0; _i < _test_master.size(); _i++)
303  for (_j = 0; _j < _phi_master.size(); _j++)
305 }
306 
307 void
309 {
311 
312  _Kee.resize(_test_slave.size(), _connected_dof_indices.size());
313 
314  DenseMatrix<Number> & Knn =
316 
317  for (_i = 0; _i < _test_slave.size(); _i++)
318  // Loop over the connected dof indices so we can get all the jacobian contributions
319  for (_j = 0; _j < _connected_dof_indices.size(); _j++)
321 
322  DenseMatrix<Number> & Ken =
324  for (_i = 0; _i < _test_slave.size(); _i++)
325  for (_j = 0; _j < _phi_master.size(); _j++)
327 
328  _Kne.resize(_test_master.size(), _connected_dof_indices.size());
329  if (_Kne.m() && _Kne.n())
330  for (_i = 0; _i < _test_master.size(); _i++)
331  // Loop over the connected dof indices so we can get all the jacobian contributions
332  for (_j = 0; _j < _connected_dof_indices.size(); _j++)
334 
335  for (_i = 0; _i < _test_master.size(); _i++)
336  for (_j = 0; _j < _phi_master.size(); _j++)
338 }
339 
340 void
342 {
344 
346 
347  dof_id_type current_node_var_dof_index = _sys.getVariable(0, var_num).nodalDofIndex();
348 
349  // Fill up _phi_slave so that it is 1 when j corresponds to the dof associated with this node
350  // and 0 for every other dof
351  // This corresponds to evaluating all of the connected shape functions at _this_ node
352  _qp = 0;
353  for (unsigned int j = 0; j < _connected_dof_indices.size(); j++)
354  {
355  _phi_slave[j].resize(1);
356 
357  if (_connected_dof_indices[j] == current_node_var_dof_index)
358  _phi_slave[j][_qp] = 1.0;
359  else
360  _phi_slave[j][_qp] = 0.0;
361  }
362 }
MooseMesh::elemPtr
virtual Elem * elemPtr(const dof_id_type i)
Definition: MooseMesh.C:2289
Moose::Slave
Definition: MooseTypes.h:651
EqualValueEmbeddedConstraint::computeQpOffDiagJacobian
virtual Real computeQpOffDiagJacobian(Moose::ConstraintJacobianType type, unsigned int jvar) override
This is the virtual that derived classes should override for computing the off-diag Jacobian.
Definition: EqualValueEmbeddedConstraint.C:233
type
MatType type
Definition: PetscDMMoose.C:1477
SystemBase::getVariable
MooseVariableFEBase & getVariable(THREAD_ID tid, const std::string &var_name)
Gets a reference to a variable of with specified name.
Definition: SystemBase.C:109
NodeElemConstraint::_Kee
DenseMatrix< Number > _Kee
stiffness matrix holding slave-slave jacobian
Definition: NodeElemConstraint.h:256
NodeElemConstraint::_current_node
const Node *const & _current_node
current node being processed
Definition: NodeElemConstraint.h:198
Assembly::jacobianBlockNeighbor
DenseMatrix< Number > & jacobianBlockNeighbor(Moose::DGJacobianType type, unsigned int ivar, unsigned int jvar, TagID tag=0)
Get local Jacobian block of a DG Jacobian type for a pair of variables and a tag.
Definition: Assembly.C:2717
MooseMesh.h
FEProblem.h
SystemBase.h
Moose::NeighborNeighbor
Definition: MooseTypes.h:646
NodeElemConstraint::_var
MooseVariable & _var
Definition: NodeElemConstraint.h:192
FEProblem
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblem.h:24
AuxiliarySystem.h
FEProblemBase::reinitNeighborPhys
virtual void reinitNeighborPhys(const Elem *neighbor, unsigned int neighbor_side, const std::vector< Point > &physical_points, THREAD_ID tid) override
Definition: FEProblemBase.C:1760
MooseObject::mooseError
void mooseError(Args &&... args) const
Definition: MooseObject.h:141
NodeElemConstraint::_u_master
const VariableValue & _u_master
Holds the current solution at the current quadrature point.
Definition: NodeElemConstraint.h:227
SubProblem::addGhostedElem
virtual void addGhostedElem(dof_id_type elem_id)=0
Will make sure that all dofs connected to elem_id are ghosted to this processor.
Moose::SlaveMaster
Definition: MooseTypes.h:681
NodeElemConstraint::validParams
static InputParameters validParams()
Definition: NodeElemConstraint.C:24
NodeElemConstraint::_connected_dof_indices
std::vector< dof_id_type > _connected_dof_indices
dofs connected to the slave node
Definition: NodeElemConstraint.h:252
Constraint::_i
unsigned int _i
Definition: Constraint.h:77
EqualValueEmbeddedConstraint::computeJacobian
virtual void computeJacobian() override
Computes the jacobian for the current element.
Definition: EqualValueEmbeddedConstraint.C:274
MooseObject::type
const std::string & type() const
Get the type of this object.
Definition: MooseObject.h:63
EqualValueEmbeddedConstraint::shouldApply
bool shouldApply() override
Whether or not this constraint should be applied.
Definition: EqualValueEmbeddedConstraint.C:94
registerMooseObject
registerMooseObject("MooseApp", EqualValueEmbeddedConstraint)
MooseEnum
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
NodeElemConstraint::_test_master
const VariableTestValue & _test_master
Side test function.
Definition: NodeElemConstraint.h:222
NodeElemConstraint
A NodeElemConstraint is used when you need to create constraints between a slave node and a master el...
Definition: NodeElemConstraint.h:34
InputParameters::addParam
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object.
Definition: InputParameters.h:1198
Assembly.h
Constraint::_mesh
MooseMesh & _mesh
Definition: Constraint.h:75
EqualValueEmbeddedConstraint::reinitConstraint
void reinitConstraint()
Prepare the residual contribution of the current constraint required to enforce it based on the speci...
Definition: EqualValueEmbeddedConstraint.C:116
defineLegacyParams
defineLegacyParams(EqualValueEmbeddedConstraint)
Executioner.h
EqualValueEmbeddedConstraint::_constraint_residual
Real _constraint_residual
constraint force needed to enforce the constraint
Definition: EqualValueEmbeddedConstraint.h:68
NodeElemConstraint::_slave_to_master_map
std::map< dof_id_type, dof_id_type > _slave_to_master_map
maps slave node ids to master element ids
Definition: NodeElemConstraint.h:239
AddVariableAction::getNonlinearVariableOrders
static MooseEnum getNonlinearVariableOrders()
Get the possible variable orders.
Definition: AddVariableAction.C:75
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
EqualValueEmbeddedConstraint::prepareSlaveToMasterMap
virtual void prepareSlaveToMasterMap() override
prepare the _slave_to_master_map
Definition: EqualValueEmbeddedConstraint.C:59
EqualValueEmbeddedConstraint::computeOffDiagJacobian
virtual void computeOffDiagJacobian(unsigned int jvar) override
Computes d-residual / d-jvar...
Definition: EqualValueEmbeddedConstraint.C:308
InputParameters::set
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Definition: InputParameters.h:987
EqualValueEmbeddedConstraint
A EqualValueEmbeddedConstraint forces the value of a variable to be the same on overlapping portion o...
Definition: EqualValueEmbeddedConstraint.h:25
NodeElemConstraint::_overwrite_slave_residual
bool _overwrite_slave_residual
Whether or not the slave's residual should be overwritten.
Definition: NodeElemConstraint.h:247
Moose::SlaveSlave
Definition: MooseTypes.h:680
FEProblemBase::setNeighborSubdomainID
virtual void setNeighborSubdomainID(const Elem *elem, unsigned int side, THREAD_ID tid) override
Definition: FEProblemBase.C:1298
NodeElemConstraint::_slave
unsigned short _slave
slave block id
Definition: NodeElemConstraint.h:188
EqualValueEmbeddedConstraint::Formulation::PENALTY
Constraint::_sys
SystemBase & _sys
Definition: Constraint.h:70
NodeElemConstraint::_master_var
MooseVariable & _master_var
Master side variable.
Definition: NodeElemConstraint.h:211
NodeElemConstraint::getConnectedDofIndices
virtual void getConnectedDofIndices(unsigned int var_num)
Gets the indices for all dofs connected to the constraint.
Definition: NodeElemConstraint.C:215
TaggingInterface::_subproblem
SubProblem & _subproblem
SubProblem that contains tag info.
Definition: TaggingInterface.h:147
EqualValueEmbeddedConstraint.h
MooseVariableFEBase::nodalDofIndex
virtual const dof_id_type & nodalDofIndex() const =0
NodeElemConstraint::_u_slave
const VariableValue & _u_slave
Value of the unknown variable on the slave node.
Definition: NodeElemConstraint.h:202
MooseMesh::getMesh
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:2599
EqualValueEmbeddedConstraint::validParams
static InputParameters validParams()
Definition: EqualValueEmbeddedConstraint.C:29
EqualValueEmbeddedConstraint::EqualValueEmbeddedConstraint
EqualValueEmbeddedConstraint(const InputParameters &parameters)
Definition: EqualValueEmbeddedConstraint.C:46
SystemBase::number
virtual unsigned int number() const
Gets the number of this system.
Definition: SystemBase.C:973
InputParameters::addClassDescription
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
Definition: InputParameters.C:70
MooseMesh::getPointLocator
virtual std::unique_ptr< PointLocatorBase > getPointLocator() const
Proxy function to get a (sub)PointLocator from either the underlying libMesh mesh (default),...
Definition: MooseMesh.C:2823
EqualValueEmbeddedConstraint::_penalty
const Real _penalty
Penalty parameter used in constraint enforcement for kinematic and penalty formulations.
Definition: EqualValueEmbeddedConstraint.h:64
EqualValueEmbeddedConstraint::Formulation
Formulation
Formulations, currently only supports KINEMATIC and PENALTY.
Definition: EqualValueEmbeddedConstraint.h:62
EqualValueEmbeddedConstraint::getConnectedDofIndices
virtual void getConnectedDofIndices(unsigned int var_num) override
Gets the indices for all dofs connected to the constraint.
Definition: EqualValueEmbeddedConstraint.C:341
EqualValueEmbeddedConstraint::_residual_copy
NumericVector< Number > & _residual_copy
copy of the residual before the constraint is applied
Definition: EqualValueEmbeddedConstraint.h:66
Moose::Master
Definition: MooseTypes.h:652
EqualValueEmbeddedConstraint::computeQpResidual
virtual Real computeQpResidual(Moose::ConstraintType type) override
This is the virtual that derived classes should override for computing the residual.
Definition: EqualValueEmbeddedConstraint.C:145
NodeElemConstraint::_phi_master
const VariablePhiValue & _phi_master
Side shape function.
Definition: NodeElemConstraint.h:217
Constraint::_qp
unsigned int _qp
Definition: Constraint.h:78
EqualValueEmbeddedConstraint::computeQpJacobian
virtual Real computeQpJacobian(Moose::ConstraintJacobianType type) override
This is the virtual that derived classes should override for computing the Jacobian.
Definition: EqualValueEmbeddedConstraint.C:169
EqualValueEmbeddedConstraint::computeQpSlaveValue
virtual Real computeQpSlaveValue() override
Compute the value the slave node should have at the beginning of a timestep.
Definition: EqualValueEmbeddedConstraint.C:139
DisplacedProblem.h
Constraint::_assembly
Assembly & _assembly
Definition: Constraint.h:74
Moose::ElementNeighbor
Definition: MooseTypes.h:644
NodeElemConstraint::_test_slave
VariableTestValue _test_slave
Shape function on the slave side. This will always only have one entry and that entry will always be ...
Definition: NodeElemConstraint.h:208
EqualValueEmbeddedConstraint::_formulation
enum EqualValueEmbeddedConstraint::Formulation _formulation
Moose::ConstraintJacobianType
ConstraintJacobianType
Definition: MooseTypes.h:678
NodeElemConstraint::_Kne
DenseMatrix< Number > _Kne
stiffness matrix holding master-slave jacobian
Definition: NodeElemConstraint.h:254
EqualValueEmbeddedConstraint::Formulation::KINEMATIC
Moose::MasterSlave
Definition: MooseTypes.h:682
MooseArray::resize
void resize(unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:218
NodeElemConstraint::_master
unsigned short _master
master block id
Definition: NodeElemConstraint.h:190
Constraint::_j
unsigned int _j
Definition: Constraint.h:77
EqualValueEmbeddedConstraint::_fe_problem
FEProblem & _fe_problem
Definition: EqualValueEmbeddedConstraint.h:59
Moose::ConstraintType
ConstraintType
Definition: MooseTypes.h:649
MooseArray::size
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:259
AddVariableAction.h
FEProblemBase
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Definition: FEProblemBase.h:139
InputParameters::addRequiredParam
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
Definition: InputParameters.h:1176
NodeElemConstraint::_phi_slave
VariablePhiValue _phi_slave
Shape function on the slave side.
Definition: NodeElemConstraint.h:206
Moose::MasterMaster
Definition: MooseTypes.h:683
MooseVariableBase::number
unsigned int number() const
Get variable number coming from libMesh.
Definition: MooseVariableBase.h:48