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 
16 template <>
19 {
21  params.addClassDescription(
22  "Constrains slave node to move as a linear combination of master nodes.");
23  params.addRequiredParam<std::vector<unsigned int>>("master", "The master node IDs.");
24  params.addParam<std::vector<unsigned int>>("slave_node_ids", "The list of slave node ids");
25  params.addParam<BoundaryName>(
26  "slave_node_set", "NaN", "The boundary ID associated with the slave side");
27  params.addRequiredParam<Real>("penalty", "The penalty used for the boundary term");
28  params.addRequiredParam<std::vector<Real>>(
29  "weights",
30  "The weights associated with the master node ids. Must be of the same size as master nodes");
31  return params;
32 }
33 
35  : NodalConstraint(parameters),
36  _master_node_ids(getParam<std::vector<unsigned int>>("master")),
37  _slave_node_ids(getParam<std::vector<unsigned int>>("slave_node_ids")),
38  _slave_node_set_id(getParam<BoundaryName>("slave_node_set")),
39  _penalty(getParam<Real>("penalty"))
40 {
41  _weights = getParam<std::vector<Real>>("weights");
42 
43  if (_master_node_ids.size() != _weights.size())
44  mooseError("master and weights should be of equal size.");
45 
46  if ((_slave_node_ids.size() == 0) && (_slave_node_set_id == "NaN"))
47  mooseError("Please specify slave_node_ids or slave_node_set.");
48  else if ((_slave_node_ids.size() == 0) && (_slave_node_set_id != "NaN"))
49  {
50  std::vector<dof_id_type> nodelist = _mesh.getNodeList(_mesh.getBoundaryID(_slave_node_set_id));
51  std::vector<dof_id_type>::iterator in;
52 
53  for (in = nodelist.begin(); in != nodelist.end(); ++in)
54  {
55  if (_mesh.nodeRef(*in).processor_id() == _subproblem.processor_id())
56  _connected_nodes.push_back(*in); // defining slave nodes in the base class
57  }
58  }
59  else if ((_slave_node_ids.size() > 0) && (_slave_node_set_id == "NaN"))
60  {
61  for (const auto & dof : _slave_node_ids)
62  if (_mesh.nodeRef(dof).processor_id() == _subproblem.processor_id())
63  _connected_nodes.push_back(dof);
64  }
65 
66  const auto & node_to_elem_map = _mesh.nodeToElemMap();
67 
68  // Add elements connected to master node to Ghosted Elements
69  for (const auto & dof : _master_node_ids)
70  {
71  // defining master nodes in base class
72  _master_node_vector.push_back(dof);
73 
74  auto node_to_elem_pair = node_to_elem_map.find(dof);
75  mooseAssert(node_to_elem_pair != node_to_elem_map.end(), "Missing entry in node to elem map");
76  const std::vector<dof_id_type> & elems = node_to_elem_pair->second;
77 
78  for (const auto & elem_id : elems)
79  _subproblem.addGhostedElem(elem_id);
80  }
81 }
82 
83 Real
85 {
94  unsigned int master_size = _master_node_ids.size();
95 
96  switch (type)
97  {
98  case Moose::Master:
99  return (_u_master[_j] * _weights[_j] - _u_slave[_i] / master_size) * _penalty;
100  case Moose::Slave:
101  return (_u_slave[_i] / master_size - _u_master[_j] * _weights[_j]) * _penalty;
102  }
103  return 0.;
104 }
105 
106 Real
108 {
109  unsigned int master_size = _master_node_ids.size();
110 
111  switch (type)
112  {
113  case Moose::MasterMaster:
114  return _penalty * _weights[_j];
115  case Moose::MasterSlave:
116  return -_penalty / master_size;
117  case Moose::SlaveSlave:
118  return _penalty / master_size;
119  case Moose::SlaveMaster:
120  return -_penalty * _weights[_j];
121  default:
122  mooseError("Unsupported type");
123  break;
124  }
125  return 0.;
126 }
SubProblem & _subproblem
SubProblem that contains tag info.
virtual Real computeQpResidual(Moose::ConstraintType type) override
Computes the residual for the current slave node.
const VariableValue & _u_master
Holds the current solution at the current quadrature point.
ConstraintType
Definition: MooseTypes.h:523
std::vector< unsigned int > _master_node_ids
unsigned int _j
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:436
unsigned int _i
Counter for master and slave nodes.
const VariableValue & _u_slave
Value of the unknown variable this BC is action on.
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...
InputParameters validParams< NodalConstraint >()
const std::string & type() const
Get the type of this object.
Definition: MooseObject.h:53
registerMooseObject("MooseApp", LinearNodalConstraint)
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 master node (slave nodes)
std::vector< Real > _weights
When the slave node is constrained to move as a linear combination of the master nodes, the coefficients associated with each master node is stored in _weights.
MooseMesh & _mesh
Definition: Constraint.h:73
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:2594
The slave node variable is programmed as a linear combination of the master node variables (i...
std::vector< unsigned int > _slave_node_ids
LinearNodalConstraint(const InputParameters &parameters)
MatType type
std::vector< dof_id_type > _master_node_vector
node IDs of the master node
InputParameters validParams< LinearNodalConstraint >()
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:543
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...
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition: MooseMesh.C:1007
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:690