www.mooseframework.org
NodeElemConstraint.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 #include "NodeElemConstraint.h"
11 
12 // MOOSE includes
13 #include "Assembly.h"
14 #include "MooseEnum.h"
15 #include "MooseMesh.h"
16 #include "MooseVariableFE.h"
17 #include "SystemBase.h"
18 
19 #include "libmesh/string_to_enum.h"
20 
23 {
25  params.addRequiredParam<SubdomainName>("secondary", "secondary block id");
26  params.addRequiredParam<SubdomainName>("primary", "primary block id");
27  params.addRequiredCoupledVar("primary_variable",
28  "The variable on the primary side of the domain");
29 
30  return params;
31 }
32 
34  : Constraint(parameters),
35  // The secondary side is at nodes (hence passing 'true'). The neighbor side is the primary side
36  // and it is not at nodes (so passing false)
40 
41  _secondary(_mesh.getSubdomainID(getParam<SubdomainName>("secondary"))),
42  _primary(_mesh.getSubdomainID(getParam<SubdomainName>("primary"))),
43  _var(_sys.getFieldVariable<Real>(_tid, parameters.get<NonlinearVariableName>("variable"))),
44 
45  _primary_q_point(_assembly.qPoints()),
46  _primary_qrule(_assembly.qRule()),
47 
48  _current_node(_var.node()),
49  _current_elem(_var.neighbor()),
50 
51  _u_secondary(_var.dofValues()),
52  _u_secondary_old(_var.dofValuesOld()),
53  _phi_secondary(1),
54  _test_secondary(1), // One entry
55 
56  _primary_var(*getVar("primary_variable", 0)),
57  _primary_var_num(_primary_var.number()),
58 
59  _phi_primary(_assembly.phiNeighbor(_primary_var)),
60  _grad_phi_primary(_assembly.gradPhiNeighbor(_primary_var)),
61 
62  _test_primary(_var.phiNeighbor()),
63  _grad_test_primary(_var.gradPhiNeighbor()),
64 
65  _u_primary(_primary_var.slnNeighbor()),
66  _u_primary_old(_primary_var.slnOldNeighbor()),
67  _grad_u_primary(_primary_var.gradSlnNeighbor()),
68 
69  _dof_map(_sys.dofMap()),
70  _node_to_elem_map(_mesh.nodeToElemMap()),
71 
72  _overwrite_secondary_residual(false)
73 {
74  _mesh.errorIfDistributedMesh("NodeElemConstraint");
75 
77  // Put a "1" into test_secondary
78  // will always only have one entry that is 1
79  _test_secondary[0].push_back(1);
80 }
81 
83 {
85  _test_secondary.release();
86 }
87 
88 void
90 {
91  const dof_id_type & dof_idx = _var.nodalDofIndex();
92  _qp = 0;
93  current_solution.set(dof_idx, computeQpSecondaryValue());
94 }
95 
96 void
98 {
99  _qp = 0;
100 
102  for (_i = 0; _i < _test_primary.size(); _i++)
105 
107  for (_i = 0; _i < _test_secondary.size(); _i++)
110 }
111 
112 void
114 {
116 
119 
120  for (_i = 0; _i < _test_secondary.size(); _i++)
121  // Loop over the connected dof indices so we can get all the jacobian contributions
122  for (_j = 0; _j < _connected_dof_indices.size(); _j++)
124 
126  if (_local_ke.m() && _local_ke.n())
127  for (_i = 0; _i < _test_secondary.size(); _i++)
128  for (_j = 0; _j < _phi_primary.size(); _j++)
131 
132  for (_i = 0; _i < _test_primary.size(); _i++)
133  // Loop over the connected dof indices so we can get all the jacobian contributions
134  for (_j = 0; _j < _connected_dof_indices.size(); _j++)
136 
139  if (_local_ke.m() && _local_ke.n())
140  for (_i = 0; _i < _test_primary.size(); _i++)
141  for (_j = 0; _j < _phi_primary.size(); _j++)
144 }
145 
146 void
147 NodeElemConstraint::computeOffDiagJacobian(const unsigned int jvar_num)
148 {
149  getConnectedDofIndices(jvar_num);
150 
153 
154  for (_i = 0; _i < _test_secondary.size(); _i++)
155  // Loop over the connected dof indices so we can get all the jacobian contributions
156  for (_j = 0; _j < _connected_dof_indices.size(); _j++)
158 
160  for (_i = 0; _i < _test_secondary.size(); _i++)
161  for (_j = 0; _j < _phi_primary.size(); _j++)
164 
165  if (_Kne.m() && _Kne.n())
166  for (_i = 0; _i < _test_primary.size(); _i++)
167  // Loop over the connected dof indices so we can get all the jacobian contributions
168  for (_j = 0; _j < _connected_dof_indices.size(); _j++)
170 
172  for (_i = 0; _i < _test_primary.size(); _i++)
173  for (_j = 0; _j < _phi_primary.size(); _j++)
176 }
177 
178 void
180 {
181  MooseVariableFEBase & var = _sys.getVariable(0, var_num);
182 
183  _connected_dof_indices.clear();
184  std::set<dof_id_type> unique_dof_indices;
185 
186  auto node_to_elem_pair = _node_to_elem_map.find(_current_node->id());
187  mooseAssert(node_to_elem_pair != _node_to_elem_map.end(), "Missing entry in node to elem map");
188  const std::vector<dof_id_type> & elems = node_to_elem_pair->second;
189 
190  // Get the dof indices from each elem connected to the node
191  for (const auto & cur_elem : elems)
192  {
193  std::vector<dof_id_type> dof_indices;
194 
195  var.getDofIndices(_mesh.elemPtr(cur_elem), dof_indices);
196 
197  for (const auto & dof : dof_indices)
198  unique_dof_indices.insert(dof);
199  }
200 
201  for (const auto & dof : unique_dof_indices)
202  _connected_dof_indices.push_back(dof);
203 
205 
206  const dof_id_type current_node_var_dof_index = _sys.getVariable(0, var_num).nodalDofIndex();
207 
208  // Fill up _phi_secondary so that it is 1 when j corresponds to the dof associated with this node
209  // and 0 for every other dof
210  // This corresponds to evaluating all of the connected shape functions at _this_ node
211  _qp = 0;
212  for (unsigned int j = 0; j < _connected_dof_indices.size(); j++)
213  {
214  _phi_secondary[j].resize(1);
215 
216  if (_connected_dof_indices[j] == current_node_var_dof_index)
217  _phi_secondary[j][_qp] = 1.0;
218  else
219  _phi_secondary[j][_qp] = 0.0;
220  }
221 }
222 
223 bool
225 {
227 }
MooseMesh & _mesh
Reference to this Kernel&#39;s mesh object.
VarFieldType
Definition: MooseTypes.h:634
virtual Real computeQpOffDiagJacobian(Moose::ConstraintJacobianType, unsigned int)
This is the virtual that derived classes should override for computing the off-diag Jacobian...
static InputParameters validParams()
NodeElemConstraint(const InputParameters &parameters)
const VariableTestValue & _test_primary
Side test function.
void accumulateTaggedLocalResidual()
Local residual blocks will be appended by adding the current local kernel residual.
Intermediate base class that ties together all the interfaces for getting MooseVariables with the Moo...
virtual Elem * elemPtr(const dof_id_type i)
Definition: MooseMesh.C:2864
bool _overwrite_secondary_residual
Whether or not the secondary&#39;s residual should be overwritten.
DenseMatrix< Number > _Kee
stiffness matrix holding secondary-secondary jacobian
unsigned int number() const
Get variable number coming from libMesh.
virtual Real computeQpResidual(Moose::ConstraintType type)=0
This is the virtual that derived classes should override for computing the residual.
const std::map< dof_id_type, std::vector< dof_id_type > > & _node_to_elem_map
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1147
Base class for all Constraint types.
Definition: Constraint.h:19
virtual void computeJacobian() override
Computes the jacobian for the current element.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void getDofIndices(const Elem *, std::vector< dof_id_type > &) const
unsigned int m() const
virtual Real computeQpJacobian(Moose::ConstraintJacobianType type)=0
This is the virtual that derived classes should override for computing the Jacobian.
This class provides an interface for common operations on field variables of both FE and FV types wit...
unsigned int _i
Definition: Constraint.h:35
virtual const dof_id_type & nodalDofIndex() const =0
virtual bool overwriteSecondaryResidual()
Whether or not the secondary&#39;s residual should be overwritten.
DenseMatrix< Number > _local_ke
Holds local Jacobian entries as they are accumulated by this Kernel.
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...
SubdomainID getSubdomainID(const SubdomainName &subdomain_name, const MeshBase &mesh)
Gets the subdomain ID associated with the given SubdomainName.
virtual Real computeQpSecondaryValue()=0
Compute the value the secondary node should have at the beginning of a timestep.
SystemBase & _sys
Reference to the EquationSystem object.
MooseVariable & _var
void prepareMatrixTagNeighbor(Assembly &assembly, unsigned int ivar, unsigned int jvar, Moose::DGJacobianType type)
Prepare data for computing element jacobian according to the active tags for DG and interface kernels...
virtual void getConnectedDofIndices(unsigned int var_num)
Gets the indices for all dofs connected to the constraint.
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:3368
unsigned int _j
Definition: Constraint.h:35
Enhances MooseVariableInterface interface provide values from neighbor elements.
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:256
virtual void computeOffDiagJacobian(unsigned int jvar) override
Computes d-residual / d-jvar...
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:627
void accumulateTaggedLocalMatrix()
Local Jacobian blocks will be appended by adding the current local kernel Jacobian.
Assembly & _assembly
Reference to this Kernel&#39;s assembly object.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
MooseVariable & _primary_var
Primary side variable.
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
const VariablePhiValue & _phi_primary
Side shape function.
void prepareVectorTagNeighbor(Assembly &assembly, unsigned int ivar)
Prepare data for computing element residual the according to active tags for DG and interface kernels...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const dof_id_type & nodalDofIndex() const override
void computeSecondaryValue(NumericVector< Number > &current_solution)
Compute the value the secondary node should have at the beginning of a timestep.
virtual void computeResidual() override
Computes the residual Nodal residual.
void release()
Manually deallocates the data pointer.
Definition: MooseArray.h:66
const Node *const & _current_node
current node being processed
std::vector< dof_id_type > _connected_dof_indices
dofs connected to the secondary node
DenseVector< Number > _local_re
Holds local residual entries as they are accumulated by this Kernel.
void resize(const unsigned int new_m, const unsigned int new_n)
void resize(unsigned int size)
Change the number of elements the array can store.
Definition: MooseArray.h:213
virtual void set(const numeric_index_type i, const Number value)=0
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
Definition: SystemBase.C:86
unsigned int n() const
void prepareVectorTag(Assembly &assembly, unsigned int ivar)
Prepare data for computing element residual according to active tags.
VariableTestValue _test_secondary
Shape function on the secondary side. This will always only have one entry and that entry will always...
DenseMatrix< Number > _Kne
stiffness matrix holding primary-secondary jacobian
VariablePhiValue _phi_secondary
Shape function on the secondary side.
static InputParameters validParams()
Definition: Constraint.C:15
unsigned int _qp
Definition: Constraint.h:36
uint8_t dof_id_type