https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComputeFrictionalForceCartesianLMMechanicalContact.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 "MortarContactUtils.h"
12#include "DisplacedProblem.h"
13#include "Assembly.h"
15#include "metaphysicl/metaphysicl_version.h"
16#include "metaphysicl/dualsemidynamicsparsenumberarray.h"
17#include "metaphysicl/parallel_dualnumber.h"
18#if METAPHYSICL_MAJOR_VERSION < 2
19#include "metaphysicl/parallel_dynamic_std_array_wrapper.h"
20#else
21#include "metaphysicl/parallel_dynamic_array_wrapper.h"
22#endif
23#include "metaphysicl/parallel_semidynamicsparsenumberarray.h"
24#include "timpi/parallel_sync.h"
25
27
28namespace
29{
30const InputParameters &
31assignVarsInParamsFriction(const InputParameters & params_in)
32{
33 InputParameters & ret = const_cast<InputParameters &>(params_in);
34 const auto & disp_x_name = ret.get<std::vector<VariableName>>("disp_x");
35 if (disp_x_name.size() != 1)
36 mooseError("We require that the disp_x parameter have exactly one coupled name");
37
38 // We do this so we don't get any variable errors during MortarConstraint(Base) construction
39 ret.set<VariableName>("secondary_variable") = disp_x_name[0];
40 ret.set<VariableName>("primary_variable") = disp_x_name[0];
41
42 return ret;
43}
44}
45
48{
50 params.addClassDescription("Computes mortar frictional forces.");
51 params.addParam<Real>("c_t", 1e0, "Numerical parameter for tangential constraints");
52 params.addParam<Real>(
53 "epsilon",
54 1.0e-7,
55 "Minimum value of contact pressure that will trigger frictional enforcement");
56 params.addRangeCheckedParam<Real>(
57 "mu", "mu > 0", "The friction coefficient for the Coulomb friction law");
58 MooseEnum friction_projection_degree("ONE TWO", "TWO");
59 friction_projection_degree.addDocumentation(
60 "ONE", "Use the degree-one Alart-Curnier friction residual.");
61 friction_projection_degree.addDocumentation(
62 "TWO", "Use the degree-two Hueber-Stadler-Wohlmuth friction residual.");
63 params.addParam<MooseEnum>(
64 "friction_projection_degree",
65 friction_projection_degree,
66 "Degree of the friction-residual projection; see MortarContactUtils.h.");
67 return params;
68}
69
72 : ComputeWeightedGapCartesianLMMechanicalContact(assignVarsInParamsFriction(parameters)),
73 _c_t(getParam<Real>("c_t")),
74 _friction_projection_degree(getParam<MooseEnum>("friction_projection_degree")
75 .getEnum<Moose::Mortar::Contact::FrictionProjectionDegree>()),
76 _secondary_x_dot(adCoupledDot("disp_x")),
77 _primary_x_dot(adCoupledNeighborValueDot("disp_x")),
78 _secondary_y_dot(adCoupledDot("disp_y")),
79 _primary_y_dot(adCoupledNeighborValueDot("disp_y")),
80 _secondary_z_dot(_has_disp_z ? &adCoupledDot("disp_z") : nullptr),
81 _primary_z_dot(_has_disp_z ? &adCoupledNeighborValueDot("disp_z") : nullptr),
82 _mu(getParam<Real>("mu")),
83 _epsilon(getParam<Real>("epsilon"))
84{
85}
86
87void
89{
91
92 // Trim derivatives
93 const auto & primary_ip_lowerd_map = amg().getPrimaryIpToLowerElementMap(
97 const auto & secondary_ip_lowerd_map =
99
100 std::array<const MooseVariable *, 3> var_array{{_disp_x_var, _disp_y_var, _disp_z_var}};
101 std::array<ADReal, 3> primary_disp_dot{
102 {_primary_x_dot[_qp], _primary_y_dot[_qp], _has_disp_z ? (*_primary_z_dot)[_qp] : 0}};
103 std::array<ADReal, 3> secondary_disp_dot{
104 {_secondary_x_dot[_qp], _secondary_y_dot[_qp], _has_disp_z ? (*_secondary_z_dot)[_qp] : 0}};
105
106 trimInteriorNodeDerivatives(primary_ip_lowerd_map, var_array, primary_disp_dot, false);
107 trimInteriorNodeDerivatives(secondary_ip_lowerd_map, var_array, secondary_disp_dot, true);
108
109 const ADReal & prim_x_dot = primary_disp_dot[0];
110 const ADReal & prim_y_dot = primary_disp_dot[1];
111 const ADReal * prim_z_dot = nullptr;
112 if (_has_disp_z)
113 prim_z_dot = &primary_disp_dot[2];
114
115 const ADReal & sec_x_dot = secondary_disp_dot[0];
116 const ADReal & sec_y_dot = secondary_disp_dot[1];
117 const ADReal * sec_z_dot = nullptr;
118 if (_has_disp_z)
119 sec_z_dot = &secondary_disp_dot[2];
120
121 // Build relative velocity vector
122 ADRealVectorValue relative_velocity;
123
124 if (_has_disp_z)
125 relative_velocity = {sec_x_dot - prim_x_dot, sec_y_dot - prim_y_dot, *sec_z_dot - *prim_z_dot};
126 else
127 relative_velocity = {sec_x_dot - prim_x_dot, sec_y_dot - prim_y_dot, 0.0};
128
129 _qp_tangential_velocity_nodal = relative_velocity * (_JxW_msm[_qp] * _coord[_qp]);
130}
131
132void
134{
136
137 const auto & nodal_tangents = _nodal_frames.tangents(amg(),
138 _lower_secondary_elem->node_ref(_i),
139 _normals[_i],
141 // Get the _dof_to_weighted_tangential_velocity map
142 const DofObject * const dof =
143 _lm_vars[0]->isNodal() ? cast_ptr<const DofObject *>(_lower_secondary_elem->node_ptr(_i))
144 : cast_ptr<const DofObject *>(_lower_secondary_elem);
145
147 _test[_i][_qp] * _qp_tangential_velocity_nodal * nodal_tangents[0];
148
149 // Get the _dof_to_weighted_tangential_velocity map for a second direction
150 if (_has_disp_z)
152 _test[_i][_qp] * _qp_tangential_velocity_nodal * nodal_tangents[1];
153}
154
155void
161
162void
164{
169
170 // Enforce frictional complementarity constraints
171 for (const auto & pr : _dof_to_weighted_tangential_velocity)
172 {
173 const DofObject * const dof = pr.first;
174
175 if (dof->processor_id() != this->processor_id())
176 continue;
177
178 auto & weighted_gap_pr = _dof_to_weighted_gap[dof];
179 _weighted_gap_ptr = &weighted_gap_pr.first;
180 _normalization_ptr = &weighted_gap_pr.second;
181 _tangential_vel_ptr[0] = &(pr.second[0]);
182
183 if (_has_disp_z)
184 _tangential_vel_ptr[1] = &(pr.second[1]);
185
187 }
188}
189
190void
192 const std::unordered_set<const Node *> & inactive_lm_nodes)
193{
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 node inactive, skip
205 if ((inactive_lm_nodes.find(static_cast<const Node *>(dof)) != inactive_lm_nodes.end()) ||
206 (dof->processor_id() != this->processor_id()))
207 continue;
208
211 _tangential_vel_ptr[0] = &pr.second[0];
212
213 if (_has_disp_z)
214 _tangential_vel_ptr[1] = &pr.second[1];
215
217 }
218}
219
220void
222 const DofObject * const dof)
223{
224 using std::abs, std::sqrt, std::min;
225
226 const auto & weighted_gap = *_weighted_gap_ptr;
227 const Real c = _normalize_c ? _c / *_normalization_ptr : _c;
228 const Real c_t = _normalize_c ? _c_t / *_normalization_ptr : _c_t;
229
230 const auto dof_index_x = dof->dof_number(_sys.number(), _lm_vars[0]->number(), 0);
231 const auto dof_index_y = dof->dof_number(_sys.number(), _lm_vars[1]->number(), 0);
232 const Real scaling_factor_x = _lm_vars[0]->scalingFactor();
233 const Real scaling_factor_y = _lm_vars[1]->scalingFactor();
234 Real scaling_factor_z = 1;
235
236 ADReal lm_x = (*_sys.currentSolution())(dof_index_x);
237 ADReal lm_y = (*_sys.currentSolution())(dof_index_y);
238
239 Moose::derivInsert(lm_x.derivatives(), dof_index_x, 1.);
240 Moose::derivInsert(lm_y.derivatives(), dof_index_y, 1.);
241
242 dof_id_type dof_index_z(-1);
243 ADReal lm_z;
244 if (_has_disp_z)
245 {
246 dof_index_z = dof->dof_number(_sys.number(), _lm_vars[2]->number(), 0);
247 lm_z = (*_sys.currentSolution())(dof_index_z);
248 Moose::derivInsert(lm_z.derivatives(), dof_index_z, 1.);
249 scaling_factor_z = _lm_vars[2]->scalingFactor();
250 }
251
252 const auto & normal = dofNormal(dof);
253 const auto & tangents = dofTangents(dof);
254
255 ADReal normal_pressure_value = lm_x * normal(0) + lm_y * normal(1);
256 ADReal tangential_pressure_value = lm_x * tangents[0](0) + lm_y * tangents[0](1);
257
258 ADReal tangential_pressure_value_dir;
259
260 if (_has_disp_z)
261 {
262 normal_pressure_value += lm_z * normal(2);
263 tangential_pressure_value += lm_z * tangents[0](2);
264 tangential_pressure_value_dir =
265 lm_x * tangents[1](0) + lm_y * tangents[1](1) + lm_z * tangents[1](2);
266 }
267
268 ADReal normal_dof_residual = min(normal_pressure_value, weighted_gap * c);
269 ADReal tangential_dof_residual;
270 ADReal tangential_dof_residual_dir;
271
272 if (!_has_disp_z)
273 {
274 const std::array<ADReal, 1> tangential_pressure{{tangential_pressure_value}};
275 const std::array<ADReal, 1> tangential_velocity{{*_tangential_vel_ptr[0]}};
276
277 tangential_dof_residual =
279 tangential_velocity,
280 ADReal(c_t),
281 ADReal(_dt),
282 normal_pressure_value,
283 c * weighted_gap,
284 ADReal(_mu),
287 }
288 else
289 {
290 const std::array<ADReal, 2> tangential_pressure{
291 {tangential_pressure_value, tangential_pressure_value_dir}};
292 const std::array<ADReal, 2> tangential_velocity{
294
295 const auto residual =
297 tangential_velocity,
298 ADReal(c_t),
299 ADReal(_dt),
300 normal_pressure_value,
301 c * weighted_gap,
302 ADReal(_mu),
305 tangential_dof_residual = residual[0];
306 tangential_dof_residual_dir = residual[1];
307 }
308
309 // Compute the friction coefficient (constant or function)
310
311 // Get index for normal constraint.
312 // We do this to get a decent Jacobian structure, which is key for the use of iterative solvers.
313 // Using old normal vector to avoid changes in the Jacobian structure within one time step
314
315 Real ny, nz;
316 // Intially, use the current normal vector
317 if (_dof_to_old_normal_vector[dof].norm() < TOLERANCE)
318 {
319 ny = MetaPhysicL::raw_value(normal(1));
320 nz = MetaPhysicL::raw_value(normal(2));
321 }
322 else
323 {
324 ny = _dof_to_old_normal_vector[dof](1);
325 nz = _dof_to_old_normal_vector[dof](2);
326 }
327
328 unsigned int component_normal = 0;
329
330 // Consider constraint orientation to improve Jacobian structure
331 const Real threshold_for_Jacobian = _has_disp_z ? 1.0 / sqrt(3.0) : 1.0 / sqrt(2.0);
332
333 if (abs(ny) > threshold_for_Jacobian)
334 component_normal = 1;
335 else if (abs(nz) > threshold_for_Jacobian)
336 component_normal = 2;
337
339 _assembly,
340 std::array<ADReal, 1>{{normal_dof_residual}},
341 std::array<dof_id_type, 1>{{component_normal == 0
342 ? dof_index_x
343 : (component_normal == 1 ? dof_index_y : dof_index_z)}},
344 component_normal == 0 ? scaling_factor_x
345 : (component_normal == 1 ? scaling_factor_y : scaling_factor_z));
346
348 _assembly,
349 std::array<ADReal, 1>{{tangential_dof_residual}},
350 std::array<dof_id_type, 1>{
351 {(component_normal == 0 || component_normal == 2) ? dof_index_y : dof_index_x}},
352 (component_normal == 0 || component_normal == 2) ? scaling_factor_y : scaling_factor_x);
353
354 if (_has_disp_z)
356 _assembly,
357 std::array<ADReal, 1>{{tangential_dof_residual_dir}},
358 std::array<dof_id_type, 1>{
359 {(component_normal == 0 || component_normal == 1) ? dof_index_z : dof_index_x}},
360 (component_normal == 0 || component_normal == 1) ? scaling_factor_z : scaling_factor_x);
361}
DualNumber< Real, DNDerivativeType, true > ADReal
Mortar
registerMooseObject("ContactApp", ComputeFrictionalForceCartesianLMMechanicalContact)
void mooseError(Args &&... args)
std::map< unsigned int, unsigned int > getSecondaryIpToLowerElementMap(const Elem &lower_secondary_elem) const
std::map< unsigned int, unsigned int > getPrimaryIpToLowerElementMap(const Elem &primary_elem, const Elem &primary_elem_ip, const Elem &lower_secondary_elem) const
static const Elem & primaryInteriorParentOrSelf(const Elem &lower_primary_elem)
Computes the weighted gap that will later be used to enforce the zero-penetration mechanical contact ...
ADRealVectorValue _qp_tangential_velocity_nodal
The value of the tangential velocity vectors at the current node.
void incorrectEdgeDroppingPost(const std::unordered_set< const Node * > &inactive_lm_nodes) override
Copy of the post routine but that skips assembling inactive nodes.
std::array< const ADReal *, 2 > _tangential_vel_ptr
An array of two pointers to avoid copies.
std::unordered_map< const DofObject *, std::array< ADReal, 2 > > _dof_to_weighted_tangential_velocity
A map from node to two weighted tangential velocities.
virtual void computeQpProperties() override
Computes properties that are functions only of the current quadrature point (_qp),...
const Real _epsilon
Minimum value of contact pressure that will trigger including tangential forces in the contact residu...
const ADVariableValue & _secondary_x_dot
x-velocity on the secondary face
const Moose::Mortar::Contact::FrictionProjectionDegree _friction_projection_degree
Degree of the friction-residual projection used by frictionalContactResidual (see MortarContactUtils....
const Real _c_t
Numerical factor used in the tangential constraints for convergence purposes.
const ADVariableValue & _secondary_y_dot
y-velocity on the secondary face
virtual void enforceConstraintOnDof(const DofObject *const dof) override
Method called from post().
virtual void computeQpIProperties() override
Computes properties that are functions both of _qp and _i, for example the weighted gap.
Computes the weighted gap that will later be used to enforce the zero-penetration mechanical contact ...
virtual void computeQpIProperties()
Computes properties that are functions both of _qp and _i, for example the weighted gap.
Moose::Mortar::ADNodalFrames _nodal_frames
Secondary nodal normals and tangents with their displacement derivatives.
const MooseVariable *const _disp_y_var
The y displacement variable.
std::vector< MooseVariable * > _lm_vars
Cartesian Lagrange multipliers for mechanical contact.
const std::array< ADRealVectorValue, 2 > & dofTangents(const DofObject *dof)
const ADReal * _weighted_gap_ptr
A pointer members that can be used to help avoid copying ADReals.
std::unordered_map< const DofObject *, RealVectorValue > _dof_to_old_normal_vector
A map from node to normal vector (2D) - old.
std::unordered_map< const DofObject *, std::pair< ADReal, Real > > _dof_to_weighted_gap
A map from node to weighted gap and normalization (if requested)
bool _normalize_c
Whether to normalize weighted gap by weighting function norm.
const MooseVariable *const _disp_x_var
The x displacement variable.
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 MooseVariable *const _disp_z_var
The z displacement variable.
const bool _has_disp_z
For 2D mortar contact no displacement will be specified, so const pointers used.
unsigned int _qp
unsigned int _i
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
const std::array< ADRealVectorValue, 2 > & tangents(const AutomaticMortarGeneration &amg, const Node &node, const Point &stored_normal, bool do_derivatives)
const MooseArray< Real > & _coord
const VariableTestValue & _test
Elem const *const & _lower_secondary_elem
const AutomaticMortarGeneration & amg() const
Elem const *const & _lower_primary_elem
std::vector< Point > _normals
static void trimInteriorNodeDerivatives(const std::map< unsigned int, unsigned int > &primary_ip_lowerd_map, const Variables &moose_var, DualNumbers &ad_vars, const bool is_secondary)
const std::vector< Real > & _JxW_msm
MooseMesh & _mesh
Assembly & _assembly
SubProblem & _subproblem
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 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 communicateGaps(std::unordered_map< const DofObject *, std::pair< ADReal, Real > > &dof_to_weighted_gap, const MooseMesh &mesh, bool nodal, bool normalize_c, const Parallel::Communicator &communicator, bool send_data_back)
This function is used to communicate gaps across processes.
bool doDerivatives(const SubProblem &subproblem, const SystemBase &sys)
void derivInsert(SemiDynamicSparseNumberArray< Real, libMesh::dof_id_type, NWrapper< N > > &derivs, libMesh::dof_id_type index, Real value)