https://mooseframework.inl.gov
ComputeDynamicFrictionalForceLMMechanicalContact.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 
11 #include "DisplacedProblem.h"
12 #include "Assembly.h"
13 #include "Function.h"
14 #include "MortarContactUtils.h"
16 
17 #include "metaphysicl/metaphysicl_version.h"
18 #include "metaphysicl/dualsemidynamicsparsenumberarray.h"
19 #include "metaphysicl/parallel_dualnumber.h"
20 #if METAPHYSICL_MAJOR_VERSION < 2
21 #include "metaphysicl/parallel_dynamic_std_array_wrapper.h"
22 #else
23 #include "metaphysicl/parallel_dynamic_array_wrapper.h"
24 #endif
25 #include "metaphysicl/parallel_semidynamicsparsenumberarray.h"
26 #include "timpi/parallel_sync.h"
27 
28 #include <limits>
29 
31 
34 {
36  params.addClassDescription("Computes the tangential frictional forces for dynamic simulations");
37  params.addRequiredCoupledVar("friction_lm", "The frictional Lagrange's multiplier");
38  params.addCoupledVar("friction_lm_dir",
39  "The frictional Lagrange's multiplier for an addtional direction.");
40  params.addParam<FunctionName>(
41  "function_friction",
42  "Coupled function to evaluate friction with values from contact pressure and relative "
43  "tangential velocities (from the previous step).");
44  params.addParam<Real>("c_t", 1e0, "Numerical parameter for tangential constraints");
45  params.addParam<Real>(
46  "epsilon",
47  1.0e-7,
48  "Minimum value of contact pressure that will trigger frictional enforcement");
49  params.addParam<Real>("mu", "The friction coefficient for the Coulomb friction law");
50  return params;
51 }
52 
54  const InputParameters & parameters)
56  _c_t(getParam<Real>("c_t")),
57  _secondary_x_dot(_secondary_var.adUDot()),
58  _primary_x_dot(_primary_var.adUDotNeighbor()),
59  _secondary_y_dot(adCoupledDot("disp_y")),
60  _primary_y_dot(adCoupledNeighborValueDot("disp_y")),
61  _secondary_z_dot(_has_disp_z ? &adCoupledDot("disp_z") : nullptr),
62  _primary_z_dot(_has_disp_z ? &adCoupledNeighborValueDot("disp_z") : nullptr),
63  _epsilon(getParam<Real>("epsilon")),
64  _mu(isParamValid("mu") ? getParam<Real>("mu") : std::numeric_limits<double>::quiet_NaN()),
65  _function_friction(isParamValid("function_friction") ? &getFunction("function_friction")
66  : nullptr),
67  _has_friction_function(isParamValid("function_friction")),
68  _3d(_has_disp_z)
69 {
70  if (!_has_friction_function && !isParamValid("mu"))
71  mooseError(
72  "A coefficient of friction needs to be provided as a constant value of via a function.");
73 
75  paramError("mu",
76  "Either provide a constant coefficient of friction or a function defining the "
77  "coefficient of friction. Both inputs cannot be provided simultaneously.");
78 
79  if (!getParam<bool>("use_displaced_mesh"))
80  paramError("use_displaced_mesh",
81  "'use_displaced_mesh' must be true for the "
82  "ComputeFrictionalForceLMMechanicalContact object");
83 
84  if (_3d && !isParamValid("friction_lm_dir"))
85  paramError("friction_lm_dir",
86  "Three-dimensional mortar frictional contact simulations require an additional "
87  "frictional Lagrange's multiplier to enforce a second tangential pressure");
88 
89  _friction_vars.push_back(getVar("friction_lm", 0));
90 
91  if (_3d)
92  _friction_vars.push_back(getVar("friction_lm_dir", 0));
93 
94  if (!_friction_vars[0]->isNodal())
95  if (_friction_vars[0]->feType().order != static_cast<Order>(0))
96  paramError(
97  "friction_lm",
98  "Frictional contact constraints only support elemental variables of CONSTANT order");
99 
100  // Request the old solution state in unison
101  _sys.solutionOld();
102 }
103 
104 void
106 {
107  // Compute the value of _qp_gap
109 
110  // It appears that the relative velocity between weighted gap and this class have a sign
111  // difference
114 }
115 
116 void
118 {
119  // Get the _dof_to_weighted_gap map
121 
122  const auto & nodal_tangents = amg().getNodalTangents(*_lower_secondary_elem);
123 
124  // Get the _dof_to_weighted_tangential_velocity map
125  const DofObject * const dof =
126  _friction_vars[0]->isNodal()
127  ? static_cast<const DofObject *>(_lower_secondary_elem->node_ptr(_i))
128  : static_cast<const DofObject *>(_lower_secondary_elem);
129 
131  _test[_i][_qp] * _qp_tangential_velocity_nodal * nodal_tangents[0][_i];
132 
135  nodal_tangents[0][_i];
136 
137  // Get the _dof_to_weighted_tangential_velocity map for a second direction
138  if (_3d)
139  {
141  _test[_i][_qp] * _qp_tangential_velocity_nodal * nodal_tangents[1][_i];
142 
145  nodal_tangents[1][_i];
146  }
147 }
148 
149 void
151 {
152  // Clear both maps
156 }
157 
158 void
160 {
161 
163 
165 
166  for (auto & map_pr : _dof_to_real_tangential_velocity)
167  _dof_to_old_real_tangential_velocity.emplace(map_pr);
168 }
169 
170 void
172 {
174 
177 
181 
182  // Enforce frictional complementarity constraints
183  for (const auto & pr : _dof_to_weighted_tangential_velocity)
184  {
185  const DofObject * const dof = pr.first;
186 
187  if (dof->processor_id() != this->processor_id())
188  continue;
189 
190  // Use always weighted gap for dynamic PDASS. Omit the dynamic weighted gap approach that is
191  // used in normal contact where the discretized gap velocity is enforced if a node has
192  // identified to be into contact.
193 
196  _tangential_vel_ptr[0] = &(pr.second[0]);
197 
198  if (_3d)
199  {
200  _tangential_vel_ptr[1] = &(pr.second[1]);
202  }
203  else
205  }
206 }
207 
208 void
210  const std::unordered_set<const Node *> & inactive_lm_nodes)
211 {
213 
216 
220 
221  // Enforce frictional complementarity constraints
222  for (const auto & pr : _dof_to_weighted_tangential_velocity)
223  {
224  const DofObject * const dof = pr.first;
225 
226  // If node inactive, skip
227  if ((inactive_lm_nodes.find(static_cast<const Node *>(dof)) != inactive_lm_nodes.end()) ||
228  (dof->processor_id() != this->processor_id()))
229  continue;
230 
231  // Use always weighted gap for dynamic PDASS
234  _tangential_vel_ptr[0] = &pr.second[0];
235 
236  if (_3d)
237  {
238  _tangential_vel_ptr[1] = &pr.second[1];
240  }
241  else
243  }
244 }
245 
246 void
248  const DofObject * const dof)
249 {
250  using std::max, std::sqrt;
251 
252  // Get normal LM
253  const auto normal_dof_index = dof->dof_number(_sys.number(), _var->number(), 0);
254  const ADReal & weighted_gap = *_weighted_gap_ptr;
255  ADReal contact_pressure = (*_sys.currentSolution())(normal_dof_index);
256  Moose::derivInsert(contact_pressure.derivatives(), normal_dof_index, 1.);
257 
258  // Get friction LMs
259  std::array<const ADReal *, 2> & tangential_vel = _tangential_vel_ptr;
260  std::array<dof_id_type, 2> friction_dof_indices;
261  std::array<ADReal, 2> friction_lm_values;
262 
263  const unsigned int num_tangents = 2;
264  for (const auto i : make_range(num_tangents))
265  {
266  friction_dof_indices[i] = dof->dof_number(_sys.number(), _friction_vars[i]->number(), 0);
267  friction_lm_values[i] = (*_sys.currentSolution())(friction_dof_indices[i]);
268  Moose::derivInsert(friction_lm_values[i].derivatives(), friction_dof_indices[i], 1.);
269  }
270 
271  // Get normalized c and c_t values (if normalization specified
272  const Real c = _normalize_c ? _c / *_normalization_ptr : _c;
273  const Real c_t = _normalize_c ? _c_t / *_normalization_ptr : _c_t;
274 
275  const Real contact_pressure_old = _sys.solutionOld()(normal_dof_index);
276 
277  // Compute the friction coefficient (constant or function)
278  ADReal mu_ad = computeFrictionValue(contact_pressure_old,
281 
282  ADReal dof_residual;
283  ADReal dof_residual_dir;
284 
285  // Primal-dual active set strategy (PDASS)
286  if (contact_pressure < _epsilon)
287  {
288  dof_residual = friction_lm_values[0];
289  dof_residual_dir = friction_lm_values[1];
290  }
291  else
292  {
293  const Real epsilon_sqrt = 1.0e-48;
294 
295  const auto lamdba_plus_cg = contact_pressure + c * weighted_gap;
296  std::array<ADReal, 2> lambda_t_plus_ctu;
297  lambda_t_plus_ctu[0] = friction_lm_values[0] + c_t * *tangential_vel[0] * _dt;
298  lambda_t_plus_ctu[1] = friction_lm_values[1] + c_t * *tangential_vel[1] * _dt;
299 
300  const auto term_1_x = max(mu_ad * lamdba_plus_cg,
301  sqrt(lambda_t_plus_ctu[0] * lambda_t_plus_ctu[0] +
302  lambda_t_plus_ctu[1] * lambda_t_plus_ctu[1] + epsilon_sqrt)) *
303  friction_lm_values[0];
304 
305  const auto term_1_y = max(mu_ad * lamdba_plus_cg,
306  sqrt(lambda_t_plus_ctu[0] * lambda_t_plus_ctu[0] +
307  lambda_t_plus_ctu[1] * lambda_t_plus_ctu[1] + epsilon_sqrt)) *
308  friction_lm_values[1];
309 
310  const auto term_2_x = mu_ad * max(0.0, lamdba_plus_cg) * lambda_t_plus_ctu[0];
311 
312  const auto term_2_y = mu_ad * max(0.0, lamdba_plus_cg) * lambda_t_plus_ctu[1];
313 
314  dof_residual = term_1_x - term_2_x;
315  dof_residual_dir = term_1_y - term_2_y;
316  }
317 
319  std::array<ADReal, 1>{{dof_residual}},
320  std::array<dof_id_type, 1>{{friction_dof_indices[0]}},
321  _friction_vars[0]->scalingFactor());
323  std::array<ADReal, 1>{{dof_residual_dir}},
324  std::array<dof_id_type, 1>{{friction_dof_indices[1]}},
325  _friction_vars[1]->scalingFactor());
326 }
327 
328 void
330  const DofObject * const dof)
331 {
332  using std::max, std::abs;
333 
334  // Get friction LM
335  const auto friction_dof_index = dof->dof_number(_sys.number(), _friction_vars[0]->number(), 0);
336  const ADReal & tangential_vel = *_tangential_vel_ptr[0];
337  ADReal friction_lm_value = (*_sys.currentSolution())(friction_dof_index);
338  Moose::derivInsert(friction_lm_value.derivatives(), friction_dof_index, 1.);
339 
340  // Get normal LM
341  const auto normal_dof_index = dof->dof_number(_sys.number(), _var->number(), 0);
342  const ADReal & weighted_gap = *_weighted_gap_ptr;
343  ADReal contact_pressure = (*_sys.currentSolution())(normal_dof_index);
344  Moose::derivInsert(contact_pressure.derivatives(), normal_dof_index, 1.);
345 
346  const Real contact_pressure_old = _sys.solutionOld()(normal_dof_index);
347 
348  // Get normalized c and c_t values (if normalization specified
349  const Real c = _normalize_c ? _c / *_normalization_ptr : _c;
350  const Real c_t = _normalize_c ? _c_t / *_normalization_ptr : _c_t;
351 
352  // Compute the friction coefficient (constant or function)
353  ADReal mu_ad =
354  computeFrictionValue(contact_pressure_old, _dof_to_old_real_tangential_velocity[dof][0], 0.0);
355 
356  ADReal dof_residual;
357  // Primal-dual active set strategy (PDASS)
358  if (contact_pressure < _epsilon)
359  dof_residual = friction_lm_value;
360  else
361  {
362  const auto term_1 = max(mu_ad * (contact_pressure + c * weighted_gap),
363  abs(friction_lm_value + c_t * tangential_vel * _dt)) *
364  friction_lm_value;
365  const auto term_2 = mu_ad * max(0.0, contact_pressure + c * weighted_gap) *
366  (friction_lm_value + c_t * tangential_vel * _dt);
367 
368  dof_residual = term_1 - term_2;
369  }
370 
372  std::array<ADReal, 1>{{dof_residual}},
373  std::array<dof_id_type, 1>{{friction_dof_index}},
374  _friction_vars[0]->scalingFactor());
375 }
376 
377 ADReal
379  const ADReal & contact_pressure, const Real & tangential_vel, const Real & tangential_vel_dir)
380 {
381  using std::sqrt;
382 
383  // TODO: Introduce temperature dependence in the function. Do this when we have an example.
384  ADReal mu_ad;
385 
387  mu_ad = _mu;
388  else
389  {
390  ADReal tangential_vel_magnitude =
391  sqrt(tangential_vel * tangential_vel + tangential_vel_dir * tangential_vel_dir + 1.0e-24);
392 
393  mu_ad = _function_friction->value<ADReal>(0.0, contact_pressure, tangential_vel_magnitude, 0.0);
394  }
395 
396  return mu_ad;
397 }
MooseMesh & _mesh
virtual void computeQpProperties() override
Computes properties that are functions only of the current quadrature point (_qp), e.g.
virtual void computeQpProperties()
Computes properties that are functions only of the current quadrature point (_qp), e.g.
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
virtual const NumericVector< Number > *const & currentSolution() const=0
ADRealVectorValue _qp_tangential_velocity_nodal
The value of the tangential velocity vectors at the current node.
ADRealVectorValue _qp_real_tangential_velocity_nodal
The value of the tangential velocity vectors at the current node.
void addResidualsAndJacobian(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
std::unordered_map< const DofObject *, std::array< Real, 2 > > _dof_to_real_tangential_velocity
A map from node to two tangential velocities. Required to have direct connection to physics...
void communicateVelocities(std::unordered_map< const DofObject *, T > &dof_map, const MooseMesh &mesh, const bool nodal, const Parallel::Communicator &communicator, const bool send_data_back)
This function is used to communicate velocities across processes.
const Real _epsilon
Small contact pressure value to trigger computation of frictional forces.
void paramError(const std::string &param, Args... args) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
unsigned int number() const
registerMooseObject("ContactApp", ComputeDynamicFrictionalForceLMMechanicalContact)
std::unordered_map< const DofObject *, std::pair< ADReal, Real > > _dof_to_weighted_gap
A map from node to weighted gap and normalization (if requested)
ADReal computeFrictionValue(const ADReal &contact_pressure, const Real &tangential_vel, const Real &tangential_vel_dir)
Apply constant or function-based friction coefficient.
auto raw_value(const Eigen::Map< T > &in)
MooseVariable * getVar(const std::string &var_name, unsigned int comp)
std::vector< MooseVariable * > _friction_vars
Frictional Lagrange&#39;s multiplier variable pointers.
const std::vector< Real > & _JxW_msm
Computes the normal contact mortar constraints for dynamic simulations.
const Parallel::Communicator & _communicator
unsigned int _i
DualNumber< Real, DNDerivativeType, true > ADReal
void incorrectEdgeDroppingPost(const std::unordered_set< const Node *> &inactive_lm_nodes) override
Copy of the post routine but that skips assembling inactive nodes.
auto max(const L &left, const R &right)
const VariableTestValue & _test
SystemBase & _sys
std::unordered_map< const DofObject *, std::array< ADReal, 2 > > _dof_to_weighted_tangential_velocity
A map from node to two weighted tangential velocities.
Elem const *const & _lower_secondary_elem
const AutomaticMortarGeneration & amg() const
virtual void incorrectEdgeDroppingPost(const std::unordered_set< const Node *> &inactive_lm_nodes) override
virtual void enforceConstraintOnDof3d(const DofObject *const dof)
Method called from post().
const bool _nodal
Whether the dof objects are nodal; if they&#39;re not, then they&#39;re elemental.
std::array< MooseUtils::SemidynamicVector< Point, 9 >, 2 > getNodalTangents(const Elem &secondary_elem) const
unsigned int number() const
virtual void enforceConstraintOnDof(const DofObject *const dof) override
Method called from post().
const ADReal * _weighted_gap_ptr
A pointer members that can be used to help avoid copying ADReals.
Assembly & _assembly
bool isNodal() const
void addCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
MooseVariable *const _var
std::unordered_map< const DofObject *, std::array< Real, 2 > > _dof_to_old_real_tangential_velocity
A map from node to two old tangential velocities. Required to have direct connection to physics...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool _normalize_c
Whether to normalize weighted gap by weighting function norm.
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sqrt(_arg)) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tanh
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
void derivInsert(SemiDynamicSparseNumberArray< Real, libMesh::dof_id_type, NWrapper< N >> &derivs, libMesh::dof_id_type index, Real value)
std::array< const ADReal *, 2 > _tangential_vel_ptr
An array of two pointers to avoid copies.
bool isParamValid(const std::string &name) const
const bool _has_friction_function
Boolean to determine whether the friction coefficient is taken from a function.
virtual Real value(Real t, const Point &p) const
const MooseArray< Real > & _coord
NumericVector< Number > & solutionOld()
processor_id_type processor_id() const
Computes the mortar tangential frictional forces for dynamic simulations.
unsigned int _qp
bool _3d
Automatic flag to determine whether we are doing three-dimensional work.
virtual void computeQpIProperties() override
Computes properties that are functions both of _qp and _i, for example the weighted gap...
const Real _c
This factor multiplies the weighted gap.
const Real _c_t
Numerical factor used in the tangential constraints for convergence purposes.