https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LinearNodalConstraint.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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 "MooseMesh.h"
13
15
18{
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)
91 }
92}
93
94Real
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
117Real
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}
registerMooseObject("MooseApp", LinearNodalConstraint)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
void ErrorVector unsigned int
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
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...
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.
The secondary node variable is programmed as a linear combination of the primary node variables (i....
LinearNodalConstraint(const InputParameters &parameters)
virtual Real computeQpJacobian(Moose::ConstraintJacobianType type) override
Computes the jacobian for the constraint.
static InputParameters validParams()
virtual Real computeQpResidual(Moose::ConstraintType type) override
Computes the residual for the current secondary node.
std::vector< unsigned int > _secondary_node_ids
std::vector< unsigned int > _primary_node_ids
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3549
const std::unordered_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:1236
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition MooseMesh.C:1681
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:3571
unsigned int _i
Counter for primary and secondary nodes.
unsigned int _j
std::vector< dof_id_type > _primary_node_vector
node IDs of the primary node
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,...
static InputParameters validParams()
const VariableValue & _u_secondary
Value of the unknown variable this BC is action on.
const VariableValue & _u_primary
Holds the current solution at the current quadrature point.
MooseMesh & _mesh
Reference to this Kernel's mesh object.
SubProblem & _subproblem
Reference to this kernel's SubProblem.
virtual void addGhostedElem(dof_id_type elem_id)=0
Will make sure that all dofs connected to elem_id are ghosted to this processor.
processor_id_type processor_id() const
ConstraintType
Definition MooseTypes.h:812
@ Primary
Definition MooseTypes.h:814
@ Secondary
Definition MooseTypes.h:813
ConstraintJacobianType
Definition MooseTypes.h:851
@ SecondarySecondary
Definition MooseTypes.h:852
@ SecondaryPrimary
Definition MooseTypes.h:853
@ PrimarySecondary
Definition MooseTypes.h:854
@ PrimaryPrimary
Definition MooseTypes.h:855