https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComputeFrictionalForceLMMechanicalContact.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 "MortarContactUtils.h"
15
16#include "metaphysicl/metaphysicl_version.h"
17#include "metaphysicl/dualsemidynamicsparsenumberarray.h"
18#include "metaphysicl/parallel_dualnumber.h"
19#if METAPHYSICL_MAJOR_VERSION < 2
20#include "metaphysicl/parallel_dynamic_std_array_wrapper.h"
21#else
22#include "metaphysicl/parallel_dynamic_array_wrapper.h"
23#endif
24#include "metaphysicl/parallel_semidynamicsparsenumberarray.h"
25#include "timpi/parallel_sync.h"
26
27#include <cmath>
28
30
33{
35 params.addClassDescription("Computes the tangential frictional forces");
36 params.addRequiredCoupledVar("friction_lm", "The frictional Lagrange's multiplier");
37 params.addCoupledVar("friction_lm_dir",
38 "The frictional Lagrange's multiplier for an addtional direction.");
39 params.addParam<FunctionName>(
40 "function_friction",
41 "Coupled function to evaluate friction with values from contact pressure and relative "
42 "tangential velocities");
43 params.addParam<Real>("c_t", 1e0, "Numerical parameter for tangential constraints");
44 params.addParam<Real>(
45 "epsilon",
46 1.0e-7,
47 "Minimum value of contact pressure that will trigger frictional enforcement");
48 params.addRangeCheckedParam<Real>(
49 "mu", "mu > 0", "The friction coefficient for the Coulomb friction law");
50 params.addRequiredParam<UserObjectName>("weighted_velocities_uo",
51 "The weighted tangential velocities user object.");
52 MooseEnum friction_projection_degree("ONE TWO", "TWO");
53 friction_projection_degree.addDocumentation(
54 "ONE", "Use the degree-one Alart-Curnier friction residual.");
55 friction_projection_degree.addDocumentation(
56 "TWO", "Use the degree-two Hueber-Stadler-Wohlmuth friction residual.");
57 params.addParam<MooseEnum>(
58 "friction_projection_degree",
59 friction_projection_degree,
60 "Degree of the friction-residual projection; see MortarContactUtils.h.");
61
62 return params;
63}
64
66 const InputParameters & parameters)
68 _weighted_velocities_uo(getUserObject<WeightedVelocitiesUserObject>("weighted_velocities_uo")),
69 _c_t(getParam<Real>("c_t")),
70 _friction_projection_degree(getParam<MooseEnum>("friction_projection_degree")
71 .getEnum<Moose::Mortar::Contact::FrictionProjectionDegree>()),
72 _secondary_x_dot(_secondary_var.adUDot()),
73 _primary_x_dot(_primary_var.adUDotNeighbor()),
74 _secondary_y_dot(adCoupledDot("disp_y")),
75 _primary_y_dot(adCoupledNeighborValueDot("disp_y")),
76 _secondary_z_dot(_has_disp_z ? &adCoupledDot("disp_z") : nullptr),
77 _primary_z_dot(_has_disp_z ? &adCoupledNeighborValueDot("disp_z") : nullptr),
78 _epsilon(getParam<Real>("epsilon")),
79 _mu(isParamValid("function_friction") ? std::numeric_limits<double>::quiet_NaN()
80 : getParam<Real>("mu")),
81 _function_friction(isParamValid("function_friction") ? &getFunction("function_friction")
82 : nullptr),
83 _has_friction_function(isParamValid("function_friction")),
84 _3d(_has_disp_z)
85
86{
89 "mu",
90 "Please only provide friction either as a function or as a constant value, but not both.");
92 paramError("mu", "Please provide a value or a function for the coefficient of friction.");
93
94 if (!getParam<bool>("use_displaced_mesh"))
95 paramError("use_displaced_mesh",
96 "'use_displaced_mesh' must be true for the "
97 "ComputeFrictionalForceLMMechanicalContact object");
98
99 if (_3d && !isParamValid("friction_lm_dir"))
100 paramError("friction_lm_dir",
101 "Three-dimensional mortar frictional contact simulations require an additional "
102 "frictional Lagrange's multiplier to enforce a second tangential pressure");
103
104 _friction_vars.push_back(getVar("friction_lm", 0));
105
106 if (_3d)
107 _friction_vars.push_back(getVar("friction_lm_dir", 0));
108
109 if (!_friction_vars[0]->isNodal())
110 if (_friction_vars[0]->feType().order != static_cast<Order>(0))
112 "friction_lm",
113 "Frictional contact constraints only support elemental variables of CONSTANT order");
114}
115
116void
120
121void
125
126void
130
131void
133{
134 const auto & dof_to_weighted_tangential_velocity =
136
137 const std::unordered_map<const DofObject *, std::pair<ADReal, Real>> & dof_to_weighted_gap =
139
140 // Enforce frictional constraints
141
142 for (const auto & [dof_object, weighted_velocities_pr] : dof_to_weighted_tangential_velocity)
143 {
144 if (dof_object->processor_id() != this->processor_id())
145 continue;
146
147 const auto & [weighted_gap_pr, normalization] =
148 libmesh_map_find(dof_to_weighted_gap, dof_object);
149 _weighted_gap_ptr = &weighted_gap_pr;
150 _normalization_ptr = &normalization;
151 _tangential_vel_ptr[0] = &(weighted_velocities_pr[0]);
152
153 if (_3d)
154 {
155 _tangential_vel_ptr[1] = &(weighted_velocities_pr[1]);
156 enforceConstraintOnDof3d(dof_object);
157 }
158 else
159 enforceConstraintOnDof(dof_object);
160 }
161}
162
163void
165 const std::unordered_set<const Node *> & inactive_lm_nodes)
166{
167 const auto & dof_to_weighted_tangential_velocity =
169 const auto & dof_to_weighted_gap = _weighted_gap_uo.dofToWeightedGap();
170 // Enforce frictional complementarity constraints
171 for (const auto & [dof_object, weighted_velocities_pr] : dof_to_weighted_tangential_velocity)
172 {
173 // If node inactive, skip
174 if ((inactive_lm_nodes.find(static_cast<const Node *>(dof_object)) !=
175 inactive_lm_nodes.end()) ||
176 (dof_object->processor_id() != this->processor_id()))
177 continue;
178
179 _weighted_gap_ptr = &dof_to_weighted_gap.at(dof_object).first;
180 _normalization_ptr = &dof_to_weighted_gap.at(dof_object).second;
181 _tangential_vel_ptr[0] = &weighted_velocities_pr[0];
182
183 if (_3d)
184 {
185 _tangential_vel_ptr[1] = &weighted_velocities_pr[1];
186 enforceConstraintOnDof3d(dof_object);
187 }
188 else
189 enforceConstraintOnDof(dof_object);
190 }
191}
192
193void
195{
197
198 // Get normal LM
199 const auto normal_dof_index = dof->dof_number(_sys.number(), _var->number(), 0);
200 const ADReal & weighted_gap = *_weighted_gap_ptr;
201 ADReal contact_pressure = (*_sys.currentSolution())(normal_dof_index);
202 Moose::derivInsert(contact_pressure.derivatives(), normal_dof_index, 1.);
203 // The stored multiplier is zhat = kappa*lambda; recover lambda for the Coulomb bound
204 contact_pressure /= _weighted_gap_uo.nodalScale(dof);
205
206 // Get friction LMs
207 std::array<const ADReal *, 2> & tangential_vel = _tangential_vel_ptr;
208 std::array<dof_id_type, 2> friction_dof_indices;
209 std::array<ADReal, 2> friction_lm_values;
210
211 const unsigned int num_tangents = 2;
212 for (const auto i : make_range(num_tangents))
213 {
214 friction_dof_indices[i] = dof->dof_number(_sys.number(), _friction_vars[i]->number(), 0);
215 friction_lm_values[i] = (*_sys.currentSolution())(friction_dof_indices[i]);
216 Moose::derivInsert(friction_lm_values[i].derivatives(), friction_dof_indices[i], 1.);
217 }
218
219 // Get normalized c and c_t values (if normalization specified
220 const Real c = _normalize_c ? _c / *_normalization_ptr : _c;
221 const Real c_t = _normalize_c ? _c_t / *_normalization_ptr : _c_t;
222
223 // Compute the friction coefficient (constant or function)
224 ADReal mu_ad = computeFrictionValue(contact_pressure,
227
228 const std::array<ADReal, 2> tangential_velocity{{*tangential_vel[0], *tangential_vel[1]}};
229
230 const auto residual =
232 tangential_velocity,
233 ADReal(c_t),
234 ADReal(_dt),
235 contact_pressure,
236 c * weighted_gap,
237 mu_ad,
240 const ADReal dof_residual = residual[0];
241 const ADReal dof_residual_dir = residual[1];
242
244 std::array<ADReal, 1>{{dof_residual}},
245 std::array<dof_id_type, 1>{{friction_dof_indices[0]}},
246 _friction_vars[0]->scalingFactor());
248 std::array<ADReal, 1>{{dof_residual_dir}},
249 std::array<dof_id_type, 1>{{friction_dof_indices[1]}},
250 _friction_vars[1]->scalingFactor());
251}
252
253void
255{
257
258 // Get friction LM
259 const auto friction_dof_index = dof->dof_number(_sys.number(), _friction_vars[0]->number(), 0);
260 const ADReal & tangential_vel = *_tangential_vel_ptr[0];
261 ADReal friction_lm_value = (*_sys.currentSolution())(friction_dof_index);
262 Moose::derivInsert(friction_lm_value.derivatives(), friction_dof_index, 1.);
263
264 // Get normal LM
265 const auto normal_dof_index = dof->dof_number(_sys.number(), _var->number(), 0);
266 const ADReal & weighted_gap = *_weighted_gap_ptr;
267 ADReal contact_pressure = (*_sys.currentSolution())(normal_dof_index);
268 Moose::derivInsert(contact_pressure.derivatives(), normal_dof_index, 1.);
269 // The stored multiplier is zhat = kappa*lambda; recover lambda for the Coulomb bound
270 contact_pressure /= _weighted_gap_uo.nodalScale(dof);
271
272 // Get normalized c and c_t values (if normalization specified
273 const Real c = _normalize_c ? _c / *_normalization_ptr : _c;
274 const Real c_t = _normalize_c ? _c_t / *_normalization_ptr : _c_t;
275
276 // Compute the friction coefficient (constant or function)
277 ADReal mu_ad =
278 computeFrictionValue(contact_pressure, _dof_to_real_tangential_velocity[dof][0], 0.0);
279
280 const std::array<ADReal, 1> tangential_pressure{{friction_lm_value}};
281 const std::array<ADReal, 1> tangential_velocity{{tangential_vel}};
282
283 const ADReal dof_residual =
285 tangential_velocity,
286 ADReal(c_t),
287 ADReal(_dt),
288 contact_pressure,
289 c * weighted_gap,
290 mu_ad,
293
295 std::array<ADReal, 1>{{dof_residual}},
296 std::array<dof_id_type, 1>{{friction_dof_index}},
297 _friction_vars[0]->scalingFactor());
298}
299
300ADReal
302 const ADReal & tangential_vel,
303 const ADReal & tangential_vel_dir)
304{
305 using std::sqrt;
306
307 // TODO: Introduce temperature dependence in the function. Do this when we have an example.
308 ADReal mu_ad;
309
311 mu_ad = _mu;
312 else
313 {
314 ADReal tangential_vel_magnitude =
315 sqrt(tangential_vel * tangential_vel + tangential_vel_dir * tangential_vel_dir + 1.0e-24);
316 mu_ad = _function_friction->value<ADReal>(0.0, contact_pressure, tangential_vel_magnitude, 0.0);
317 }
318
319 return mu_ad;
320}
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("ContactApp", ComputeFrictionalForceLMMechanicalContact)
Computes frictional constraints (and normal contact constraints by calling its parent object)
std::array< const ADReal *, 2 > _tangential_vel_ptr
An array of two pointers to avoid copies.
const Real _epsilon
Minimum value of contact pressure that will trigger including tangential forces in the contact residu...
virtual void enforceConstraintOnDof3d(const DofObject *const dof)
Method called from post().
virtual void computeQpIProperties() override
Computes properties that are functions both of _qp and _i, for example the weighted gap.
ComputeFrictionalForceLMMechanicalContact(const InputParameters &parameters)
std::vector< MooseVariable * > _friction_vars
Frictional Lagrange's multiplier variable pointers.
ADReal computeFrictionValue(const ADReal &contact_pressure, const ADReal &tangential_vel, const ADReal &tangential_vel_dir)
Compute coefficient of friction.
const bool _has_friction_function
Boolean to determine whether the friction coefficient is taken from a function.
const Moose::Mortar::Contact::FrictionProjectionDegree _friction_projection_degree
Degree of the friction-residual projection used by frictionalContactResidual (see MortarContactUtils....
virtual void enforceConstraintOnDof(const DofObject *const dof) override
Method called from post().
const WeightedVelocitiesUserObject & _weighted_velocities_uo
The weighted gap user object.
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 computeQpProperties() override
Computes properties that are functions only of the current quadrature point (_qp),...
std::unordered_map< const DofObject *, std::array< ADReal, 2 > > _dof_to_real_tangential_velocity
A map from node to two interpolated, physical tangential velocities.
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.
Computes the weighted gap that will later be used to enforce the zero-penetration mechanical contact ...
const bool _normalize_c
Whether to normalize weighted gap by weighting function norm.
const WeightedGapUserObject & _weighted_gap_uo
The weighted gap user object.
const ADReal * _weighted_gap_ptr
A pointer members that can be used to help avoid copying ADReals.
virtual void enforceConstraintOnDof(const DofObject *const dof)
Method called from post().
const Real _c
This factor multiplies the weighted gap.
MooseVariable * getVar(const std::string &var_name, unsigned int comp)
virtual Real value(Real t, const Point &p) const
bool isParamSetByUser(const std::string &name) const
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredParam(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 addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
const InputParameters & parameters() const
void paramError(const std::string &param, Args... args) const
bool isParamValid(const std::string &name) const
unsigned int number() const
MooseVariable *const _var
bool isNodal() const
Assembly & _assembly
SystemBase & _sys
virtual const NumericVector< Number > *const & currentSolution() const=0
unsigned int number() const
void addResidualsAndJacobian(Assembly &assembly, const Residuals &residuals, const Indices &dof_indices, Real scaling_factor)
const std::unordered_map< const DofObject *, std::pair< ADReal, Real > > & dofToWeightedGap() const
Get the degree of freedom to weighted gap information.
virtual Real nodalScale(const DofObject *const) const
Node-based Lagrange-multiplier scaling factor kappa_j of Popp et al.
Creates dof object to weighted tangential velocities map.
const std::unordered_map< const DofObject *, std::array< ADReal, 2 > > & dofToWeightedVelocities() const
Get the degree of freedom to weighted velocities information.
processor_id_type processor_id() const
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 derivInsert(SemiDynamicSparseNumberArray< Real, libMesh::dof_id_type, NWrapper< N > > &derivs, libMesh::dof_id_type index, Real value)