www.mooseframework.org
LinearNodalConstraint.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
11 #include "LinearNodalConstraint.h"
12 #include "MooseMesh.h"
13 
15 
18 {
20  params.addClassDescription(
21  "Constrains secondary node to move as a linear combination of primary nodes.");
22  params.addRequiredParam<std::vector<unsigned int>>("primary", "The primary node IDs.");
23  params.addParam<std::vector<unsigned int>>(
24  "secondary_node_ids", {}, "The list of secondary node ids");
25  params.addParam<BoundaryName>(
26  "secondary_node_set", "NaN", "The boundary ID associated with the secondary side");
27  params.addRequiredParam<Real>("penalty", "The penalty used for the boundary term");
28  params.addRequiredParam<std::vector<Real>>("weights",
29  "The weights associated with the primary node ids. "
30  "Must be of the same size as primary nodes");
31  return params;
32 }
33 
35  : NodalConstraint(parameters),
36  _primary_node_ids(getParam<std::vector<unsigned int>>("primary")),
37  _secondary_node_ids(getParam<std::vector<unsigned int>>("secondary_node_ids")),
38  _secondary_node_set_id(getParam<BoundaryName>("secondary_node_set")),
39  _penalty(getParam<Real>("penalty"))
40 {
41  _weights = getParam<std::vector<Real>>("weights");
42 
43  if (_primary_node_ids.size() != _weights.size())
44  mooseError("primary and weights should be of equal size.");
45 
46  const auto & lm_mesh = _mesh.getMesh();
47 
48  if ((_secondary_node_ids.size() == 0) && (_secondary_node_set_id == "NaN"))
49  mooseError("Please specify secondary_node_ids or secondary_node_set.");
50  else if ((_secondary_node_ids.size() == 0) && (_secondary_node_set_id != "NaN"))
51  {
52  std::vector<dof_id_type> nodelist =
54  std::vector<dof_id_type>::iterator in;
55 
56  for (in = nodelist.begin(); in != nodelist.end(); ++in)
57  {
58  const Node * const node = lm_mesh.query_node_ptr(*in);
59  if (node && node->processor_id() == _subproblem.processor_id())
60  _connected_nodes.push_back(*in); // defining secondary nodes in the base class
61  }
62  }
63  else if ((_secondary_node_ids.size() > 0) && (_secondary_node_set_id == "NaN"))
64  {
65  for (const auto & dof : _secondary_node_ids)
66  {
67  const Node * const node = lm_mesh.query_node_ptr(dof);
68  if (node && node->processor_id() == _subproblem.processor_id())
69  _connected_nodes.push_back(dof);
70  }
71  }
72 
73  const auto & node_to_elem_map = _mesh.nodeToElemMap();
74 
75  // Add elements connected to primary node to Ghosted Elements
76  for (const auto & dof : _primary_node_ids)
77  {
78  auto node_to_elem_pair = node_to_elem_map.find(dof);
79 
80  // Our mesh may be distributed
81  if (node_to_elem_pair == node_to_elem_map.end())
82  continue;
83 
84  // defining primary nodes in base class
85  _primary_node_vector.push_back(dof);
86 
87  const std::vector<dof_id_type> & elems = node_to_elem_pair->second;
88 
89  for (const auto & elem_id : elems)
90  _subproblem.addGhostedElem(elem_id);
91  }
92 }
93 
94 Real
96 {
105  unsigned int primary_size = _primary_node_ids.size();
106 
107  switch (type)
108  {
109  case Moose::Primary:
110  return (_u_primary[_j] * _weights[_j] - _u_secondary[_i] / primary_size) * _penalty;
111  case Moose::Secondary:
112  return (_u_secondary[_i] / primary_size - _u_primary[_j] * _weights[_j]) * _penalty;
113  }
114  return 0.;
115 }
116 
117 Real
119 {
120  unsigned int primary_size = _primary_node_ids.size();
121 
122  switch (type)
123  {
125  return _penalty * _weights[_j];
127  return -_penalty / primary_size;
129  return _penalty / primary_size;
131  return -_penalty * _weights[_j];
132  default:
133  mooseError("Unsupported type");
134  break;
135  }
136  return 0.;
137 }
MooseMesh & _mesh
Reference to this Kernel&#39;s mesh object.
virtual Real computeQpResidual(Moose::ConstraintType type) override
Computes the residual for the current secondary node.
ConstraintType
Definition: MooseTypes.h:670
const VariableValue & _u_primary
Holds the current solution at the current quadrature point.
unsigned int _j
const VariableValue & _u_secondary
Value of the unknown variable this BC is action on.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
unsigned int _i
Counter for primary and secondary nodes.
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...
std::vector< dof_id_type > _primary_node_vector
node IDs of the primary node
registerMooseObject("MooseApp", LinearNodalConstraint)
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3198
virtual Real computeQpJacobian(Moose::ConstraintJacobianType type) override
Computes the jacobian for the constraint.
std::vector< dof_id_type > _connected_nodes
node IDs connected to the primary node (secondary nodes)
std::vector< Real > _weights
When the secondary node is constrained to move as a linear combination of the primary nodes...
SubProblem & _subproblem
Reference to this kernel&#39;s SubProblem.
std::vector< unsigned int > _primary_node_ids
const std::vector< dof_id_type > & getNodeList(boundary_id_type nodeset_id) const
Return a writable reference to a vector of node IDs that belong to nodeset_id.
Definition: MooseMesh.C:3220
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:50
The secondary node variable is programmed as a linear combination of the primary node variables (i...
LinearNodalConstraint(const InputParameters &parameters)
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void addGhostedElem(dof_id_type elem_id)=0
Will make sure that all dofs connected to elem_id are ghosted to this processor.
ConstraintJacobianType
Definition: MooseTypes.h:709
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
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...
processor_id_type processor_id() const
std::vector< unsigned int > _secondary_node_ids
void ErrorVector unsigned int
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition: MooseMesh.C:1474
const std::map< dof_id_type, std::vector< dof_id_type > > & nodeToElemMap()
If not already created, creates a map from every node to all elements to which they are connected...
Definition: MooseMesh.C:980