https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 MooseEnum friction_projection_degree("ONE TWO", "TWO");
51 friction_projection_degree.addDocumentation(
52 "ONE", "Use the degree-one Alart-Curnier friction residual.");
53 friction_projection_degree.addDocumentation(
54 "TWO", "Use the degree-two Hueber-Stadler-Wohlmuth friction residual.");
55 params.addParam<MooseEnum>(
56 "friction_projection_degree",
57 friction_projection_degree,
58 "Degree of the friction-residual projection; see MortarContactUtils.h.");
59 return params;
60}
61
63 const InputParameters & parameters)
65 _c_t(getParam<Real>("c_t")),
66 _friction_projection_degree(getParam<MooseEnum>("friction_projection_degree")
67 .getEnum<Moose::Mortar::Contact::FrictionProjectionDegree>()),
68 _secondary_x_dot(_secondary_var.adUDot()),
69 _primary_x_dot(_primary_var.adUDotNeighbor()),
70 _secondary_y_dot(adCoupledDot("disp_y")),
71 _primary_y_dot(adCoupledNeighborValueDot("disp_y")),
72 _secondary_z_dot(_has_disp_z ? &adCoupledDot("disp_z") : nullptr),
73 _primary_z_dot(_has_disp_z ? &adCoupledNeighborValueDot("disp_z") : nullptr),
74 _epsilon(getParam<Real>("epsilon")),
75 _mu(isParamValid("mu") ? getParam<Real>("mu") : std::numeric_limits<double>::quiet_NaN()),
76 _function_friction(isParamValid("function_friction") ? &getFunction("function_friction")
77 : nullptr),
78 _has_friction_function(isParamValid("function_friction")),
79 _3d(_has_disp_z)
80{
83 "A coefficient of friction needs to be provided as a constant value of via a function.");
84
86 paramError("mu",
87 "Either provide a constant coefficient of friction or a function defining the "
88 "coefficient of friction. Both inputs cannot be provided simultaneously.");
89
90 if (!getParam<bool>("use_displaced_mesh"))
91 paramError("use_displaced_mesh",
92 "'use_displaced_mesh' must be true for the "
93 "ComputeFrictionalForceLMMechanicalContact object");
94
95 if (_3d && !isParamValid("friction_lm_dir"))
96 paramError("friction_lm_dir",
97 "Three-dimensional mortar frictional contact simulations require an additional "
98 "frictional Lagrange's multiplier to enforce a second tangential pressure");
99
100 _friction_vars.push_back(getVar("friction_lm", 0));
101
102 if (_3d)
103 _friction_vars.push_back(getVar("friction_lm_dir", 0));
104
105 if (!_friction_vars[0]->isNodal())
106 if (_friction_vars[0]->feType().order != static_cast<Order>(0))
108 "friction_lm",
109 "Frictional contact constraints only support elemental variables of CONSTANT order");
110
111 // Request the old solution state in unison
113}
114
115void
117{
118 // Compute the value of _qp_gap
120
121 // It appears that the relative velocity between weighted gap and this class have a sign
122 // difference
125}
126
127void
129{
130 // Get the _dof_to_weighted_gap map
132
133 const auto & nodal_tangents = amg().getNodalTangents(*_lower_secondary_elem);
134
135 // Get the _dof_to_weighted_tangential_velocity map
136 const DofObject * const dof =
137 _friction_vars[0]->isNodal()
138 ? cast_ptr<const DofObject *>(_lower_secondary_elem->node_ptr(_i))
139 : cast_ptr<const DofObject *>(_lower_secondary_elem);
140
142 _test[_i][_qp] * _qp_tangential_velocity_nodal * nodal_tangents[0][_i];
143
146 nodal_tangents[0][_i];
147
148 // Get the _dof_to_weighted_tangential_velocity map for a second direction
149 if (_3d)
150 {
152 _test[_i][_qp] * _qp_tangential_velocity_nodal * nodal_tangents[1][_i];
153
156 nodal_tangents[1][_i];
157 }
158}
159
160void
168
169void
171{
172
174
175 // The base class sets _retried_timestep to indicate whether this call is for a retried
176 // timestep (e.g. --test-restep or a rejected step); if so, the history below has already been
177 // advanced from the accepted state and must not be advanced again.
179 return;
180
182
183 for (auto & map_pr : _dof_to_real_tangential_velocity)
185}
186
187void
189{
191
194
198
199 // Enforce frictional complementarity constraints
200 for (const auto & pr : _dof_to_weighted_tangential_velocity)
201 {
202 const DofObject * const dof = pr.first;
203
204 if (dof->processor_id() != this->processor_id())
205 continue;
206
207 // Use always weighted gap for dynamic PDASS. Omit the dynamic weighted gap approach that is
208 // used in normal contact where the discretized gap velocity is enforced if a node has
209 // identified to be into contact.
210
213 _tangential_vel_ptr[0] = &(pr.second[0]);
214
215 if (_3d)
216 {
217 _tangential_vel_ptr[1] = &(pr.second[1]);
219 }
220 else
222 }
223}
224
225void
227 const std::unordered_set<const Node *> & inactive_lm_nodes)
228{
230
233
237
238 // Enforce frictional complementarity constraints
239 for (const auto & pr : _dof_to_weighted_tangential_velocity)
240 {
241 const DofObject * const dof = pr.first;
242
243 // If node inactive, skip
244 if ((inactive_lm_nodes.find(static_cast<const Node *>(dof)) != inactive_lm_nodes.end()) ||
245 (dof->processor_id() != this->processor_id()))
246 continue;
247
248 // Use always weighted gap for dynamic PDASS
251 _tangential_vel_ptr[0] = &pr.second[0];
252
253 if (_3d)
254 {
255 _tangential_vel_ptr[1] = &pr.second[1];
257 }
258 else
260 }
261}
262
263void
265 const DofObject * const dof)
266{
267 // Get normal LM
268 const auto normal_dof_index = dof->dof_number(_sys.number(), _var->number(), 0);
269 const ADReal & weighted_gap = *_weighted_gap_ptr;
270 ADReal contact_pressure = (*_sys.currentSolution())(normal_dof_index);
271 Moose::derivInsert(contact_pressure.derivatives(), normal_dof_index, 1.);
272
273 // Get friction LMs
274 std::array<const ADReal *, 2> & tangential_vel = _tangential_vel_ptr;
275 std::array<dof_id_type, 2> friction_dof_indices;
276 std::array<ADReal, 2> friction_lm_values;
277
278 const unsigned int num_tangents = 2;
279 for (const auto i : make_range(num_tangents))
280 {
281 friction_dof_indices[i] = dof->dof_number(_sys.number(), _friction_vars[i]->number(), 0);
282 friction_lm_values[i] = (*_sys.currentSolution())(friction_dof_indices[i]);
283 Moose::derivInsert(friction_lm_values[i].derivatives(), friction_dof_indices[i], 1.);
284 }
285
286 // Get normalized c and c_t values (if normalization specified
287 const Real c = _normalize_c ? _c / *_normalization_ptr : _c;
288 const Real c_t = _normalize_c ? _c_t / *_normalization_ptr : _c_t;
289
290 const Real contact_pressure_old = _sys.solutionOld()(normal_dof_index);
291
292 // Compute the friction coefficient (constant or function)
293 ADReal mu_ad = computeFrictionValue(contact_pressure_old,
296
297 const std::array<ADReal, 2> tangential_velocity{{*tangential_vel[0], *tangential_vel[1]}};
298
299 const auto residual =
301 tangential_velocity,
302 ADReal(c_t),
303 ADReal(_dt),
304 contact_pressure,
305 c * weighted_gap,
306 mu_ad,
309 const ADReal dof_residual = residual[0];
310 const ADReal dof_residual_dir = residual[1];
311
313 std::array<ADReal, 1>{{dof_residual}},
314 std::array<dof_id_type, 1>{{friction_dof_indices[0]}},
315 _friction_vars[0]->scalingFactor());
317 std::array<ADReal, 1>{{dof_residual_dir}},
318 std::array<dof_id_type, 1>{{friction_dof_indices[1]}},
319 _friction_vars[1]->scalingFactor());
320}
321
322void
324 const DofObject * const dof)
325{
326 // Get friction LM
327 const auto friction_dof_index = dof->dof_number(_sys.number(), _friction_vars[0]->number(), 0);
328 const ADReal & tangential_vel = *_tangential_vel_ptr[0];
329 ADReal friction_lm_value = (*_sys.currentSolution())(friction_dof_index);
330 Moose::derivInsert(friction_lm_value.derivatives(), friction_dof_index, 1.);
331
332 // Get normal LM
333 const auto normal_dof_index = dof->dof_number(_sys.number(), _var->number(), 0);
334 const ADReal & weighted_gap = *_weighted_gap_ptr;
335 ADReal contact_pressure = (*_sys.currentSolution())(normal_dof_index);
336 Moose::derivInsert(contact_pressure.derivatives(), normal_dof_index, 1.);
337
338 const Real contact_pressure_old = _sys.solutionOld()(normal_dof_index);
339
340 // Get normalized c and c_t values (if normalization specified
341 const Real c = _normalize_c ? _c / *_normalization_ptr : _c;
342 const Real c_t = _normalize_c ? _c_t / *_normalization_ptr : _c_t;
343
344 // Compute the friction coefficient (constant or function)
345 ADReal mu_ad =
346 computeFrictionValue(contact_pressure_old, _dof_to_old_real_tangential_velocity[dof][0], 0.0);
347
348 const std::array<ADReal, 1> tangential_pressure{{friction_lm_value}};
349 const std::array<ADReal, 1> tangential_velocity{{tangential_vel}};
350
351 const ADReal dof_residual =
353 tangential_velocity,
354 ADReal(c_t),
355 ADReal(_dt),
356 contact_pressure,
357 c * weighted_gap,
358 mu_ad,
361
363 std::array<ADReal, 1>{{dof_residual}},
364 std::array<dof_id_type, 1>{{friction_dof_index}},
365 _friction_vars[0]->scalingFactor());
366}
367
368ADReal
370 const ADReal & contact_pressure, const Real & tangential_vel, const Real & tangential_vel_dir)
371{
372 using std::sqrt;
373
374 // TODO: Introduce temperature dependence in the function. Do this when we have an example.
375 ADReal mu_ad;
376
378 mu_ad = _mu;
379 else
380 {
381 ADReal tangential_vel_magnitude =
382 sqrt(tangential_vel * tangential_vel + tangential_vel_dir * tangential_vel_dir + 1.0e-24);
383
384 mu_ad = _function_friction->value<ADReal>(0.0, contact_pressure, tangential_vel_magnitude, 0.0);
385 }
386
387 return mu_ad;
388}
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("ContactApp", ComputeDynamicFrictionalForceLMMechanicalContact)
std::array< MooseUtils::SemidynamicVector< Point, 9 >, 2 > getNodalTangents(const Elem &secondary_elem) const
Computes the mortar tangential frictional forces for dynamic simulations.
const bool _has_friction_function
Boolean to determine whether the friction coefficient is taken from a function.
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.
ADReal computeFrictionValue(const ADReal &contact_pressure, const Real &tangential_vel, const Real &tangential_vel_dir)
Apply constant or function-based friction coefficient.
void incorrectEdgeDroppingPost(const std::unordered_set< const Node * > &inactive_lm_nodes) override
Copy of the post routine but that skips assembling inactive nodes.
virtual void computeQpIProperties() override
Computes properties that are functions both of _qp and _i, for example the weighted gap.
virtual void enforceConstraintOnDof(const DofObject *const dof) override
Method called from post().
virtual void computeQpProperties() override
Computes properties that are functions only of the current quadrature point (_qp),...
ADRealVectorValue _qp_real_tangential_velocity_nodal
The value of the tangential velocity vectors at the current node.
std::unordered_map< const DofObject *, std::array< ADReal, 2 > > _dof_to_weighted_tangential_velocity
A map from node to two weighted tangential velocities.
const Real _epsilon
Minimum value of contact pressure that will trigger including tangential forces in the contact residu...
std::vector< MooseVariable * > _friction_vars
Frictional Lagrange's multiplier variable pointers.
ADRealVectorValue _qp_tangential_velocity_nodal
The value of the tangential velocity vectors at the current node.
std::array< const ADReal *, 2 > _tangential_vel_ptr
An array of two pointers to avoid copies.
const Moose::Mortar::Contact::FrictionProjectionDegree _friction_projection_degree
Degree of the friction-residual projection used by frictionalContactResidual (see MortarContactUtils....
virtual void enforceConstraintOnDof3d(const DofObject *const dof)
Method called from post().
bool _3d
Automatic flag to determine whether we are doing three-dimensional work.
const Real _c_t
Numerical factor used in the tangential constraints for convergence purposes.
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.
Computes the normal contact mortar constraints for dynamic simulations.
std::unordered_map< const DofObject *, std::pair< ADReal, Real > > _dof_to_weighted_gap
A map from node to weighted gap and normalization (if requested)
virtual void incorrectEdgeDroppingPost(const std::unordered_set< const Node * > &inactive_lm_nodes) override
bool _retried_timestep
Set by timestepSetup() to indicate whether the current call is for a retried timestep,...
virtual void computeQpProperties()
Computes properties that are functions only of the current quadrature point (_qp),...
const bool _nodal
Whether the dof objects are nodal; if they're not, then they're elemental.
const ADReal * _weighted_gap_ptr
A pointer members that can be used to help avoid copying ADReals.
bool _normalize_c
Whether to normalize weighted gap by weighting function norm.
unsigned int _qp
unsigned int _i
MooseVariable * getVar(const std::string &var_name, unsigned int comp)
virtual Real value(Real t, const Point &p) const
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void addCoupledVar(const std::string &name, const std::string &doc_string)
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
bool isParamValid(const std::string &name) const
unsigned int number() const
MooseVariable *const _var
const MooseArray< Real > & _coord
const VariableTestValue & _test
Elem const *const & _lower_secondary_elem
const AutomaticMortarGeneration & amg() const
const std::vector< Real > & _JxW_msm
bool isNodal() const
MooseMesh & _mesh
Assembly & _assembly
SystemBase & _sys
virtual const NumericVector< Number > *const & currentSolution() const=0
unsigned int number() const
NumericVector< Number > & solutionOld()
void addResidualsAndJacobian(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
const Parallel::Communicator & _communicator
processor_id_type processor_id() const
auto raw_value(const Eigen::Map< T > &in)
std::array< T, N > frictionalContactResidual(const std::array< T, N > &tangential_pressure, const std::array< T, N > &tangential_velocity, const T &c_t, const T &dt, const T &normal_pressure, const T &scaled_normal_gap, const T &friction_coefficient, const T &epsilon, const FrictionProjectionDegree projection_degree)
Compute the epsilon-gated frictional residual for a mortar contact node.
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.
void derivInsert(SemiDynamicSparseNumberArray< Real, libMesh::dof_id_type, NWrapper< N > > &derivs, libMesh::dof_id_type index, Real value)