https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComputeDynamicWeightedGapLMMechanicalContact.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 "MortarNodalFrames.h"
13#include "DisplacedProblem.h"
14#include "Assembly.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
29
30namespace
31{
32const InputParameters &
33assignVarsInParamsDyn(const InputParameters & params_in)
34{
35 InputParameters & ret = const_cast<InputParameters &>(params_in);
36 const auto & disp_x_name = ret.get<std::vector<VariableName>>("disp_x");
37 if (disp_x_name.size() != 1)
38 mooseError("We require that the disp_x parameter have exactly one coupled name");
39
40 // We do this so we don't get any variable errors during MortarConstraint(Base) construction
41 ret.set<VariableName>("secondary_variable") = disp_x_name[0];
42 ret.set<VariableName>("primary_variable") = disp_x_name[0];
43
44 return ret;
45}
46}
49{
51 // Mechanical contact residuals use only primal values and normals
52 params.set<bool>("_compute_primal_gradients") = false;
54 "Computes the normal contact mortar constraints for dynamic simulations");
55 params.addRangeCheckedParam<Real>("capture_tolerance",
56 1.0e-5,
57 "capture_tolerance>=0",
58 "Parameter describing a gap threshold for the application of "
59 "the persistency constraint in dynamic simulations.");
60 params.addCoupledVar("wear_depth",
61 "The name of the mortar auxiliary variable that is used to modify the "
62 "weighted gap definition");
64 "newmark_beta", "newmark_beta > 0", "Beta parameter for the Newmark time integrator");
66 "newmark_gamma", "newmark_gamma >= 0.0", "Gamma parameter for the Newmark time integrator");
67 params.suppressParameter<VariableName>("secondary_variable");
68 params.suppressParameter<VariableName>("primary_variable");
69 params.addRequiredCoupledVar("disp_x", "The x displacement variable");
70 params.addRequiredCoupledVar("disp_y", "The y displacement variable");
71 params.addCoupledVar("disp_z", "The z displacement variable");
72 params.addParam<Real>(
73 "c", 1e6, "Parameter for balancing the size of the gap and contact pressure");
74 params.addParam<bool>(
75 "normalize_c",
76 false,
77 "Whether to normalize c by weighting function norm. When unnormalized "
78 "the value of c effectively depends on element size since in the constraint we compare nodal "
79 "Lagrange Multiplier values to integrated gap values (LM nodal value is independent of "
80 "element size, where integrated values are dependent on element size).");
81 // The nodal normal at a secondary node depends on every face incident to it, so the Jacobian
82 // needs the secondary face point-neighbor ghosted and coupled.
83 params.set<bool>("ghost_point_neighbors") = true;
84 params.set<bool>("use_displaced_mesh") = true;
85 params.set<bool>("interpolate_normals") = false;
86 return params;
87}
88
90 const InputParameters & parameters)
91 : ADMortarConstraint(assignVarsInParamsDyn(parameters)),
92 _secondary_disp_x(adCoupledValue("disp_x")),
93 _primary_disp_x(adCoupledNeighborValue("disp_x")),
94 _secondary_disp_y(adCoupledValue("disp_y")),
95 _primary_disp_y(adCoupledNeighborValue("disp_y")),
96 _has_disp_z(isCoupled("disp_z")),
97 _secondary_disp_z(_has_disp_z ? &adCoupledValue("disp_z") : nullptr),
98 _primary_disp_z(_has_disp_z ? &adCoupledNeighborValue("disp_z") : nullptr),
99 _c(getParam<Real>("c")),
100 _normalize_c(getParam<bool>("normalize_c")),
101 _nodal(getVar("disp_x", 0)->feType().family == LAGRANGE),
102 _disp_x_var(getVar("disp_x", 0)),
103 _disp_y_var(getVar("disp_y", 0)),
104 _disp_z_var(_has_disp_z ? getVar("disp_z", 0) : nullptr),
105 _capture_tolerance(getParam<Real>("capture_tolerance")),
106 _secondary_x_dot(adCoupledDot("disp_x")),
107 _primary_x_dot(adCoupledNeighborValueDot("disp_x")),
108 _secondary_y_dot(adCoupledDot("disp_y")),
109 _primary_y_dot(adCoupledNeighborValueDot("disp_y")),
110 _secondary_z_dot(_has_disp_z ? &adCoupledDot("disp_z") : nullptr),
111 _primary_z_dot(_has_disp_z ? &adCoupledNeighborValueDot("disp_z") : nullptr),
112 _has_wear(isParamValid("wear_depth")),
113 _wear_depth(_has_wear ? coupledValueLower("wear_depth") : _zero),
114 _newmark_beta(getParam<Real>("newmark_beta")),
115 _newmark_gamma(getParam<Real>("newmark_gamma")),
116 _t_step_old(declareRestartableData<int>("t_step_old", 0)),
117 _retried_timestep(false),
118 _nodal_frames(std::array<const MooseVariable *, 3>{{_disp_x_var, _disp_y_var, _disp_z_var}})
119{
120 if (!useDual())
121 mooseError("Dynamic mortar contact constraints requires the use of Lagrange multipliers dual "
122 "interpolation");
123
124 if (getParam<bool>("interpolate_normals"))
125 paramError("interpolate_normals",
126 "Mechanical mortar contact uses normalized secondary nodal normals and cannot be "
127 "combined with quadrature-point normal interpolation.");
128}
129
130void
138
139void
141{
142 // Trim interior node variable derivatives
143 const auto & primary_ip_lowerd_map = amg().getPrimaryIpToLowerElementMap(
147 const auto & secondary_ip_lowerd_map =
149
150 std::array<const MooseVariable *, 3> var_array{{_disp_x_var, _disp_y_var, _disp_z_var}};
151 std::array<ADReal, 3> primary_disp{
152 {_primary_disp_x[_qp], _primary_disp_y[_qp], _has_disp_z ? (*_primary_disp_z)[_qp] : 0}};
153 std::array<ADReal, 3> secondary_disp{{_secondary_disp_x[_qp],
155 _has_disp_z ? (*_secondary_disp_z)[_qp] : 0}};
156
157 trimInteriorNodeDerivatives(primary_ip_lowerd_map, var_array, primary_disp, false);
158 trimInteriorNodeDerivatives(secondary_ip_lowerd_map, var_array, secondary_disp, true);
159
160 const ADReal & prim_x = primary_disp[0];
161 const ADReal & prim_y = primary_disp[1];
162 const ADReal * prim_z = nullptr;
163 if (_has_disp_z)
164 prim_z = &primary_disp[2];
165
166 const ADReal & sec_x = secondary_disp[0];
167 const ADReal & sec_y = secondary_disp[1];
168 const ADReal * sec_z = nullptr;
169 if (_has_disp_z)
170 sec_z = &secondary_disp[2];
171
172 std::array<ADReal, 3> primary_disp_dot{
173 {_primary_x_dot[_qp], _primary_y_dot[_qp], _has_disp_z ? (*_primary_z_dot)[_qp] : 0}};
174 std::array<ADReal, 3> secondary_disp_dot{
175 {_secondary_x_dot[_qp], _secondary_y_dot[_qp], _has_disp_z ? (*_secondary_z_dot)[_qp] : 0}};
176
177 trimInteriorNodeDerivatives(primary_ip_lowerd_map, var_array, primary_disp_dot, false);
178 trimInteriorNodeDerivatives(secondary_ip_lowerd_map, var_array, secondary_disp_dot, true);
179
180 const ADReal & prim_x_dot = primary_disp_dot[0];
181 const ADReal & prim_y_dot = primary_disp_dot[1];
182 const ADReal * prim_z_dot = nullptr;
183 if (_has_disp_z)
184 prim_z_dot = &primary_disp_dot[2];
185
186 const ADReal & sec_x_dot = secondary_disp_dot[0];
187 const ADReal & sec_y_dot = secondary_disp_dot[1];
188 const ADReal * sec_z_dot = nullptr;
189 if (_has_disp_z)
190 sec_z_dot = &secondary_disp_dot[2];
191
192 // Compute dynamic constraint-related quantities
194 gap_vec(0).derivatives() = prim_x.derivatives() - sec_x.derivatives();
195 gap_vec(1).derivatives() = prim_y.derivatives() - sec_y.derivatives();
196
197 _relative_velocity = ADRealVectorValue(prim_x_dot - sec_x_dot, prim_y_dot - sec_y_dot, 0.0);
198
199 if (_has_disp_z)
200 {
201 gap_vec(2).derivatives() = prim_z->derivatives() - sec_z->derivatives();
202 _relative_velocity(2) = *prim_z_dot - *sec_z_dot;
203 }
204
205 _qp_gap_nodal = gap_vec * (_JxW_msm[_qp] * _coord[_qp]);
207
208 // Current part of the gap velocity Newmark-beta time discretization
210 (_newmark_gamma / _newmark_beta * gap_vec / _dt) * (_JxW_msm[_qp] * _coord[_qp]);
211
212 // To do normalization of constraint coefficient (c_n)
214}
215
216ADReal
218{
220 "We should never call computeQpResidual for ComputeDynamicWeightedGapLMMechanicalContact");
221}
222
223void
225{
226 mooseAssert(_normals.size() == _lower_secondary_elem->n_nodes(),
227 "Making sure that _normals is the expected size");
228
229 // Get the _dof_to_weighted_gap map
230 const DofObject * dof = _var->isNodal()
231 ? cast_ptr<const DofObject *>(_lower_secondary_elem->node_ptr(_i))
232 : cast_ptr<const DofObject *>(_lower_secondary_elem);
233
234 const auto & normal = _nodal_frames.normal(amg(),
235 _lower_secondary_elem->node_ref(_i),
236 _normals[_i],
238
239 // Regular normal contact constraint: Use before contact is established for contact detection
240 _dof_to_weighted_gap[dof].first += _test[_i][_qp] * (_qp_gap_nodal * normal);
241
242 // Integrated part of the "persistency" constraint
244 _dof_to_velocity[dof] += _test[_i][_qp] * _qp_velocity * normal;
245
247
248 // Always accumulated: also used to compute nodal slip rates for friction
249 _dof_to_weighted_gap[dof].second += _test[_i][_qp] * _qp_factor;
250}
251
252void
254{
255 // These dof maps are not recoverable as they are maps of pointers, and recovering old pointers
256 // would be wrong. We would need to create a custom dataStore() and dataLoad()
257 if (_app.isRecovering())
258 mooseError("This object does not support recovering");
259
260 // timestepSetup() runs once per time step attempt, so on a retried timestep (e.g. --test-restep
261 // or a rejected step) the history below has already been advanced from the accepted state;
262 // advancing it again would overwrite that history with the discarded attempt's last values.
266 return;
267
269 _dof_to_old_velocity.clear();
271
272 for (auto & map_pr : _dof_to_weighted_gap)
273 _dof_to_old_weighted_gap.emplace(map_pr.first, std::move(map_pr.second.first));
274
275 for (auto & map_pr : _dof_to_velocity)
276 _dof_to_old_velocity.emplace(map_pr);
277
278 for (auto & map_pr : _dof_to_nodal_wear_depth)
279 _dof_to_nodal_old_wear_depth.emplace(map_pr);
280}
281
282void
293
294void
296{
298 _dof_to_weighted_gap, _mesh, _nodal, /*normalize_c*/ true, _communicator, false);
299
300 if (_has_wear)
302
303 // There is a need for the dynamic constraint to uncouple the computation of the weighted gap from
304 // the computation of the constraint itself since we are switching from gap constraint to
305 // persistency constraint.
306 for (const auto & pr : _dof_to_weighted_gap)
307 {
308 if (pr.first->processor_id() != this->processor_id())
309 continue;
310
311 //
312 _dof_to_weighted_gap[pr.first].first += _dof_to_nodal_wear_depth[pr.first];
315 //
316
317 const auto is_dof_on_map = _dof_to_old_weighted_gap.find(pr.first);
318
319 // If is_dof_on_map isn't on map, it means it's an initial step
320 if (is_dof_on_map == _dof_to_old_weighted_gap.end() ||
322 _weighted_gap_ptr = &pr.second.first;
323 else
324 {
326 term -= _dof_to_old_velocity[pr.first];
327 _dof_to_weighted_gap_dynamics[pr.first] += term;
329 }
330
331 _normalization_ptr = &pr.second.second;
332
334 }
335}
336
337void
339 const std::unordered_set<const Node *> & inactive_lm_nodes)
340{
342 _dof_to_weighted_gap, _mesh, _nodal, /*normalize_c*/ true, _communicator, false);
343
344 if (_has_wear)
346
347 for (const auto & pr : _dof_to_weighted_gap)
348 {
349 if ((inactive_lm_nodes.find(static_cast<const Node *>(pr.first)) != inactive_lm_nodes.end()) ||
350 (pr.first->processor_id() != this->processor_id()))
351 continue;
352
353 //
354 _dof_to_weighted_gap[pr.first].first += _dof_to_nodal_wear_depth[pr.first];
357 const auto is_dof_on_map = _dof_to_old_weighted_gap.find(pr.first);
358
359 // If is_dof_on_map isn't on map, it means it's an initial step
360 if (is_dof_on_map == _dof_to_old_weighted_gap.end() ||
362 {
363 // If this is the first step or the previous step gap is not identified as in contact, apply
364 // regular conditions
365 _weighted_gap_ptr = &pr.second.first;
366 }
367 else
368 {
369 ADReal term = _dof_to_weighted_gap[pr.first].first * _newmark_gamma / (_newmark_beta * _dt);
371 term -= _dof_to_old_velocity[pr.first];
372 _dof_to_weighted_gap_dynamics[pr.first] = term;
373 // Enable the application of persistency condition
375 }
376
377 _normalization_ptr = &pr.second.second;
378
380 }
381}
382
383void
385{
386 // We may have wear depth information that should go to other processes that own the dofs
387 using Datum = std::pair<dof_id_type, ADReal>;
388 std::unordered_map<processor_id_type, std::vector<Datum>> push_data;
389
390 for (auto & pr : _dof_to_nodal_wear_depth)
391 {
392 const auto * const dof_object = pr.first;
393 const auto proc_id = dof_object->processor_id();
394 if (proc_id == this->processor_id())
395 continue;
396
397 push_data[proc_id].push_back(std::make_pair(dof_object->id(), std::move(pr.second)));
398 }
399
400 const auto & lm_mesh = _mesh.getMesh();
401
402 auto action_functor = [this, &lm_mesh](const processor_id_type libmesh_dbg_var(pid),
403 const std::vector<Datum> & sent_data)
404 {
405 mooseAssert(pid != this->processor_id(), "We do not send messages to ourself here");
406 for (auto & pr : sent_data)
407 {
408 const auto dof_id = pr.first;
409 const auto * const dof_object = _nodal
410 ? cast_ptr<const DofObject *>(lm_mesh.node_ptr(dof_id))
411 : cast_ptr<const DofObject *>(lm_mesh.elem_ptr(dof_id));
412 mooseAssert(dof_object, "This should be non-null");
413 _dof_to_nodal_wear_depth[dof_object] += std::move(pr.second);
414 }
415 };
416
417 TIMPI::push_parallel_vector_data(_communicator, push_data, action_functor);
418}
419
420void
422{
423 const auto & weighted_gap = *_weighted_gap_ptr;
424 const Real c = _normalize_c ? _c / *_normalization_ptr : _c;
425
426 const auto dof_index = dof->dof_number(_sys.number(), _var->number(), 0);
427 ADReal lm_value = (*_sys.currentSolution())(dof_index);
428 Moose::derivInsert(lm_value.derivatives(), dof_index, 1.);
429
430 const ADReal dof_residual = std::min(lm_value, weighted_gap * c);
431
433 std::array<ADReal, 1>{{dof_residual}},
434 std::array<dof_id_type, 1>{{dof_index}},
436}
437
438void
440{
441 if (mortar_type != Moose::MortarType::Lower)
442 return;
443
444 mooseAssert(_var, "LM variable is null");
445
446 for (_qp = 0; _qp < _qrule_msm->n_points(); _qp++)
447 {
449 for (_i = 0; _i < _test.size(); ++_i)
451 }
452}
453
454void
459
460void
462{
463 // During "computeResidual" and "computeJacobian" we are actually just computing properties on the
464 // mortar segment element mesh. We are *not* actually assembling into the residual/Jacobian. For
465 // the zero-penetration constraint, the property of interest is the map from node to weighted gap.
466 // Computation of the properties proceeds identically for residual and Jacobian evaluation hence
467 // why we simply call computeResidual here. We will assemble into the residual/Jacobian later from
468 // the post() method
469 computeResidual(mortar_type);
470}
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("ContactApp", ComputeDynamicWeightedGapLMMechanicalContact)
void mooseError(Args &&... args)
void ErrorVector unsigned int
static InputParameters validParams()
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 normal contact mortar constraints for dynamic simulations.
const bool _has_disp_z
For 2D mortar contact no displacement will be specified, so const pointers used.
std::unordered_map< const DofObject *, std::pair< ADReal, Real > > _dof_to_weighted_gap
A map from node to weighted gap and normalization (if requested)
const MooseVariable *const _disp_y_var
The y displacement variable.
const bool _has_wear
Flag to determine whether wear needs to be included in the contact constraints.
const ADVariableValue & _secondary_disp_x
x-displacement on the secondary face
const ADVariableValue & _secondary_disp_y
y-displacement on the secondary face
std::unordered_map< const DofObject *, ADReal > _dof_to_nodal_wear_depth
A map from node to wear in this step.
const Real _capture_tolerance
A small threshold gap value to consider that a node needs a "persistency" constraint.
const ADVariableValue & _primary_disp_x
x-displacement on the primary face
std::unordered_map< const DofObject *, ADReal > _dof_to_weighted_gap_dynamics
A map from node to weighted gap velocity times _dt.
ADRealVectorValue _qp_gap_nodal
Vector for computation of weighted gap with nodal normals.
std::unordered_map< const DofObject *, ADReal > _dof_to_nodal_old_wear_depth
A map from node to wear in old step.
const MooseVariable *const _disp_x_var
The x displacement variable.
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),...
ADRealVectorValue _qp_velocity
Vector for computation of weighted gap velocity to fulfill "persistency" condition.
const bool _nodal
Whether the dof objects are nodal; if they're not, then they're elemental.
virtual void enforceConstraintOnDof(const DofObject *const dof)
Method called from post().
const ADReal * _weighted_gap_ptr
A pointer members that can be used to help avoid copying ADReals.
Moose::Mortar::ADNodalFrames _nodal_frames
Secondary nodal normals and tangents with their displacement derivatives.
bool _normalize_c
Whether to normalize weighted gap by weighting function norm.
const VariableValue & _wear_depth
Wear depth to include contact.
int & _t_step_old
The timestep index at which the history maps (_dof_to_old_weighted_gap, _dof_to_old_velocity,...
std::unordered_map< const DofObject *, ADReal > _dof_to_velocity
A map from node to weighted gap velocity times _dt.
ADRealVectorValue _qp_gap_nodal_dynamics
Vector for computation of weighted gap velocity to fulfill "persistency" condition.
std::unordered_map< const DofObject *, ADReal > _dof_to_old_weighted_gap
A map from dof-object to the old weighted gap.
Real _qp_factor
The value of the LM at the current quadrature point.
std::unordered_map< const DofObject *, ADReal > _dof_to_old_velocity
A map from node to weighted gap velocity times _dt.
const ADVariableValue & _primary_disp_y
y-displacement on the primary face
const MooseVariable *const _disp_z_var
The z displacement variable.
unsigned int _qp
unsigned int _i
void suppressParameter(const std::string &name)
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
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)
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 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)
bool isRecovering() const
void mooseError(Args &&... args) const
MeshBase & getMesh()
void scalingFactor(const std::vector< Real > &factor)
unsigned int number() const
bool isNodal() const override
const ADRealVectorValue & normal(const AutomaticMortarGeneration &amg, const Node &node, const Point &stored_normal, bool do_derivatives)
MooseVariable *const _var
const MooseArray< Real > & _coord
const VariableTestValue & _test
Elem const *const & _lower_secondary_elem
const libMesh::QBase *const & _qrule_msm
const AutomaticMortarGeneration & amg() const
Elem const *const & _lower_primary_elem
const MooseArray< Point > & _phys_points_secondary
const MooseArray< Point > & _phys_points_primary
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 void initialSetup()
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
unsigned int n_points() const
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.
void checkNodalNormalDisplacements(const MooseBase &object, const std::array< const MooseVariable *, 3 > &disp_vars, const std::array< std::string, 3 > &param_names, const SystemBase &sys)
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)
void push_parallel_vector_data(const Communicator &comm, MapToVectors &&data, const ActionFunctor &act_on_data)