https://mooseframework.inl.gov
RANFSTieNode.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 #include "RANFSTieNode.h"
11 #include "PenetrationLocator.h"
12 #include "PenetrationInfo.h"
13 #include "SystemBase.h"
14 #include "Assembly.h"
15 #include "NearestNodeLocator.h"
16 
17 #include "libmesh/numeric_vector.h"
18 #include "libmesh/sparse_matrix.h"
19 
20 registerMooseObject("ContactTestApp", RANFSTieNode);
21 
24 {
26  params.set<bool>("use_displaced_mesh") = true;
27 
28  MooseEnum component("x=0 y=1 z=2");
30  "component", component, "The force component constraint that this object is supplying");
31  params.addRequiredCoupledVar(
32  "displacements",
33  "The displacements appropriate for the simulation geometry and coordinate system");
34  return params;
35 }
36 
38  : NodeFaceConstraint(parameters),
39  _component(getParam<MooseEnum>("component")),
40  _mesh_dimension(_mesh.dimension()),
41  _residual_copy(_sys.residualGhosted())
42 {
43  // modern parameter scheme for displacements
44  for (unsigned int i = 0; i < coupledComponents("displacements"); ++i)
45  {
46  _vars.push_back(coupled("displacements", i));
47  _var_objects.push_back(getVar("displacements", i));
48  }
49 
50  if (_vars.size() != _mesh_dimension)
51  mooseError("The number of displacement variables does not match the mesh dimension!");
52 }
53 
54 void
56 {
57  _node_to_lm.clear();
58 }
59 
60 bool
62 {
63  return _nearest_node;
64 }
65 
66 bool
68 {
69  auto & nearest_node_loc = _penetration_locator._nearest_node;
70  _nearest_node = nearest_node_loc.nearestNode(_current_node->id());
71  if (_nearest_node)
72  {
73  auto secondary_dof_number = _current_node->dof_number(0, _vars[_component], 0);
74  // We overwrite the secondary residual so we cannot use the residual
75  // copy for determining the Lagrange multiplier when computing the Jacobian
77  _node_to_lm.insert(std::make_pair(_current_node->id(),
78  _residual_copy(secondary_dof_number) /
79  _var_objects[_component]->scalingFactor()));
80  else
81  {
82  std::vector<dof_id_type> primary_cols;
83  std::vector<Number> primary_values;
84 
85  _jacobian->get_row(secondary_dof_number, primary_cols, primary_values);
86  mooseAssert(primary_cols.size() == primary_values.size(),
87  "The size of the dof container and value container are different");
88 
89  _dof_number_to_value.clear();
90 
91  for (MooseIndex(primary_cols) i = 0; i < primary_cols.size(); ++i)
92  _dof_number_to_value.insert(
93  std::make_pair(primary_cols[i], primary_values[i] / _var.scalingFactor()));
94  }
95 
96  mooseAssert(_node_to_lm.find(_current_node->id()) != _node_to_lm.end(),
97  "The node " << _current_node->id() << " should map to a lagrange multiplier");
99 
100  _primary_index = _current_primary->get_node_index(_nearest_node);
101  mooseAssert(_primary_index != libMesh::invalid_uint,
102  "nearest node not a node on the current primary element");
103 
104  return true;
105  }
106 
107  return false;
108 }
109 
110 Real
112 {
113  switch (type)
114  {
116  return (*_current_node - *_nearest_node)(_component);
117 
119  {
120  if (_i == _primary_index)
121  return _lagrange_multiplier;
122 
123  else
124  return 0;
125  }
126 
127  default:
128  return 0;
129  }
130 }
131 
132 Real
134 {
135  switch (type)
136  {
137  case Moose::ConstraintJacobianType::SecondarySecondary:
138  return _phi_secondary[_j][_qp];
139 
140  case Moose::ConstraintJacobianType::SecondaryPrimary:
141  if (_primary_index == _j)
142  return -1;
143  else
144  return 0;
145 
146  case Moose::ConstraintJacobianType::PrimarySecondary:
147  if (_i == _primary_index)
148  {
149  mooseAssert(_dof_number_to_value.find(_connected_dof_indices[_j]) !=
150  _dof_number_to_value.end(),
151  "The connected dof index is not found in the _dof_number_to_value container. "
152  "This must mean that insufficient sparsity was allocated");
154  }
155  else
156  return 0;
157 
158  default:
159  return 0;
160  }
161 }
162 
163 void
165 {
166 }
167 
168 Real
170 {
171  mooseError(
172  "We overrode commputeSecondaryValue so computeQpSecondaryValue should never get called");
173 }
std::unordered_map< dof_id_type, Real > _node_to_lm
Definition: RANFSTieNode.h:53
virtual unsigned int coupled(const std::string &var_name, unsigned int comp=0) const
ConstraintType
NumericVector< Number > & _residual_copy
Definition: RANFSTieNode.h:47
const unsigned int invalid_uint
void residualSetup() override
Definition: RANFSTieNode.C:55
RANFSTieNode(const InputParameters &parameters)
Definition: RANFSTieNode.C:37
MooseVariable & _var
static const std::string component
Definition: NS.h:153
const Elem *const & _current_primary
T & set(const std::string &name, bool quiet_mode=false)
static InputParameters validParams()
MooseVariable * getVar(const std::string &var_name, unsigned int comp)
dof_id_type _primary_index
Definition: RANFSTieNode.h:54
unsigned int _i
virtual Real computeQpJacobian(Moose::ConstraintJacobianType type) override
Definition: RANFSTieNode.C:133
static InputParameters validParams()
Definition: RANFSTieNode.C:23
void addRequiredParam(const std::string &name, const std::string &doc_string)
const Node *const & _current_node
const Node * _nearest_node
Definition: RANFSTieNode.h:52
unsigned int _j
virtual Real computeQpResidual(Moose::ConstraintType type) override
Definition: RANFSTieNode.C:111
virtual Real computeQpSecondaryValue() override
Definition: RANFSTieNode.C:169
const MooseEnum _component
Definition: RANFSTieNode.h:45
SubProblem & _subproblem
bool overwriteSecondaryResidual() override
Definition: RANFSTieNode.C:61
const std::string & type() const
std::vector< MooseVariable * > _var_objects
Definition: RANFSTieNode.h:50
std::unordered_map< dof_id_type, Number > _dof_number_to_value
Definition: RANFSTieNode.h:56
registerMooseObject("ContactTestApp", RANFSTieNode)
const unsigned int _mesh_dimension
Definition: RANFSTieNode.h:46
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
unsigned int coupledComponents(const std::string &var_name) const
virtual void get_row(numeric_index_type i, std::vector< numeric_index_type > &indices, std::vector< Number > &values) const =0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void computeSecondaryValue(NumericVector< Number > &solution) override
Definition: RANFSTieNode.C:164
ConstraintJacobianType
bool shouldApply() override
Definition: RANFSTieNode.C:67
void mooseError(Args &&... args) const
std::vector< dof_id_type > _connected_dof_indices
const SparseMatrix< Number > * _jacobian
VariablePhiValue _phi_secondary
std::vector< unsigned int > _vars
Definition: RANFSTieNode.h:49
Real _lagrange_multiplier
Definition: RANFSTieNode.h:51
const bool & currentlyComputingJacobian() const
PenetrationLocator & _penetration_locator
unsigned int _qp
void scalingFactor(const std::vector< Real > &factor)
NearestNodeLocator & _nearest_node