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 "DisplacedProblem.h"
13#include "Assembly.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
28
29namespace
30{
31const InputParameters &
32assignVarsInParamsDyn(const InputParameters & params_in)
33{
34 InputParameters & ret = const_cast<InputParameters &>(params_in);
35 const auto & disp_x_name = ret.get<std::vector<VariableName>>("disp_x");
36 if (disp_x_name.size() != 1)
37 mooseError("We require that the disp_x parameter have exactly one coupled name");
38
39 // We do this so we don't get any variable errors during MortarConstraint(Base) construction
40 ret.set<VariableName>("secondary_variable") = disp_x_name[0];
41 ret.set<VariableName>("primary_variable") = disp_x_name[0];
42
43 return ret;
44}
45}
48{
51 "Computes the normal contact mortar constraints for dynamic simulations");
52 params.addRangeCheckedParam<Real>("capture_tolerance",
53 1.0e-5,
54 "capture_tolerance>=0",
55 "Parameter describing a gap threshold for the application of "
56 "the persistency constraint in dynamic simulations.");
57 params.addCoupledVar("wear_depth",
58 "The name of the mortar auxiliary variable that is used to modify the "
59 "weighted gap definition");
61 "newmark_beta", "newmark_beta > 0", "Beta parameter for the Newmark time integrator");
63 "newmark_gamma", "newmark_gamma >= 0.0", "Gamma parameter for the Newmark time integrator");
64 params.suppressParameter<VariableName>("secondary_variable");
65 params.suppressParameter<VariableName>("primary_variable");
66 params.addRequiredCoupledVar("disp_x", "The x displacement variable");
67 params.addRequiredCoupledVar("disp_y", "The y displacement variable");
68 params.addCoupledVar("disp_z", "The z displacement variable");
69 params.addParam<Real>(
70 "c", 1e6, "Parameter for balancing the size of the gap and contact pressure");
71 params.addParam<bool>(
72 "normalize_c",
73 false,
74 "Whether to normalize c by weighting function norm. When unnormalized "
75 "the value of c effectively depends on element size since in the constraint we compare nodal "
76 "Lagrange Multiplier values to integrated gap values (LM nodal value is independent of "
77 "element size, where integrated values are dependent on element size).");
78 params.set<bool>("use_displaced_mesh") = true;
79 params.set<bool>("interpolate_normals") = false;
80 return params;
81}
82
84 const InputParameters & parameters)
85 : ADMortarConstraint(assignVarsInParamsDyn(parameters)),
86 _secondary_disp_x(adCoupledValue("disp_x")),
87 _primary_disp_x(adCoupledNeighborValue("disp_x")),
88 _secondary_disp_y(adCoupledValue("disp_y")),
89 _primary_disp_y(adCoupledNeighborValue("disp_y")),
90 _has_disp_z(isCoupled("disp_z")),
91 _secondary_disp_z(_has_disp_z ? &adCoupledValue("disp_z") : nullptr),
92 _primary_disp_z(_has_disp_z ? &adCoupledNeighborValue("disp_z") : nullptr),
93 _c(getParam<Real>("c")),
94 _normalize_c(getParam<bool>("normalize_c")),
95 _nodal(getVar("disp_x", 0)->feType().family == LAGRANGE),
96 _disp_x_var(getVar("disp_x", 0)),
97 _disp_y_var(getVar("disp_y", 0)),
98 _disp_z_var(_has_disp_z ? getVar("disp_z", 0) : nullptr),
99 _capture_tolerance(getParam<Real>("capture_tolerance")),
100 _secondary_x_dot(adCoupledDot("disp_x")),
101 _primary_x_dot(adCoupledNeighborValueDot("disp_x")),
102 _secondary_y_dot(adCoupledDot("disp_y")),
103 _primary_y_dot(adCoupledNeighborValueDot("disp_y")),
104 _secondary_z_dot(_has_disp_z ? &adCoupledDot("disp_z") : nullptr),
105 _primary_z_dot(_has_disp_z ? &adCoupledNeighborValueDot("disp_z") : nullptr),
106 _has_wear(isParamValid("wear_depth")),
107 _wear_depth(_has_wear ? coupledValueLower("wear_depth") : _zero),
108 _newmark_beta(getParam<Real>("newmark_beta")),
109 _newmark_gamma(getParam<Real>("newmark_gamma")),
110 _t_step_old(declareRestartableData<int>("t_step_old", 0)),
111 _retried_timestep(false)
112{
113 if (!useDual())
114 mooseError("Dynamic mortar contact constraints requires the use of Lagrange multipliers dual "
115 "interpolation");
116}
117
118void
120{
121 // Trim interior node variable derivatives
122 const auto & primary_ip_lowerd_map = amg().getPrimaryIpToLowerElementMap(
124 const auto & secondary_ip_lowerd_map =
126
127 std::array<const MooseVariable *, 3> var_array{{_disp_x_var, _disp_y_var, _disp_z_var}};
128 std::array<ADReal, 3> primary_disp{
129 {_primary_disp_x[_qp], _primary_disp_y[_qp], _has_disp_z ? (*_primary_disp_z)[_qp] : 0}};
130 std::array<ADReal, 3> secondary_disp{{_secondary_disp_x[_qp],
132 _has_disp_z ? (*_secondary_disp_z)[_qp] : 0}};
133
134 trimInteriorNodeDerivatives(primary_ip_lowerd_map, var_array, primary_disp, false);
135 trimInteriorNodeDerivatives(secondary_ip_lowerd_map, var_array, secondary_disp, true);
136
137 const ADReal & prim_x = primary_disp[0];
138 const ADReal & prim_y = primary_disp[1];
139 const ADReal * prim_z = nullptr;
140 if (_has_disp_z)
141 prim_z = &primary_disp[2];
142
143 const ADReal & sec_x = secondary_disp[0];
144 const ADReal & sec_y = secondary_disp[1];
145 const ADReal * sec_z = nullptr;
146 if (_has_disp_z)
147 sec_z = &secondary_disp[2];
148
149 std::array<ADReal, 3> primary_disp_dot{
150 {_primary_x_dot[_qp], _primary_y_dot[_qp], _has_disp_z ? (*_primary_z_dot)[_qp] : 0}};
151 std::array<ADReal, 3> secondary_disp_dot{
152 {_secondary_x_dot[_qp], _secondary_y_dot[_qp], _has_disp_z ? (*_secondary_z_dot)[_qp] : 0}};
153
154 trimInteriorNodeDerivatives(primary_ip_lowerd_map, var_array, primary_disp_dot, false);
155 trimInteriorNodeDerivatives(secondary_ip_lowerd_map, var_array, secondary_disp_dot, true);
156
157 const ADReal & prim_x_dot = primary_disp_dot[0];
158 const ADReal & prim_y_dot = primary_disp_dot[1];
159 const ADReal * prim_z_dot = nullptr;
160 if (_has_disp_z)
161 prim_z_dot = &primary_disp_dot[2];
162
163 const ADReal & sec_x_dot = secondary_disp_dot[0];
164 const ADReal & sec_y_dot = secondary_disp_dot[1];
165 const ADReal * sec_z_dot = nullptr;
166 if (_has_disp_z)
167 sec_z_dot = &secondary_disp_dot[2];
168
169 // Compute dynamic constraint-related quantities
171 gap_vec(0).derivatives() = prim_x.derivatives() - sec_x.derivatives();
172 gap_vec(1).derivatives() = prim_y.derivatives() - sec_y.derivatives();
173
174 _relative_velocity = ADRealVectorValue(prim_x_dot - sec_x_dot, prim_y_dot - sec_y_dot, 0.0);
175
176 if (_has_disp_z)
177 {
178 gap_vec(2).derivatives() = prim_z->derivatives() - sec_z->derivatives();
179 _relative_velocity(2) = *prim_z_dot - *sec_z_dot;
180 }
181
182 _qp_gap_nodal = gap_vec * (_JxW_msm[_qp] * _coord[_qp]);
184
185 // Current part of the gap velocity Newmark-beta time discretization
187 (_newmark_gamma / _newmark_beta * gap_vec / _dt) * (_JxW_msm[_qp] * _coord[_qp]);
188
189 // To do normalization of constraint coefficient (c_n)
191}
192
193ADReal
195{
197 "We should never call computeQpResidual for ComputeDynamicWeightedGapLMMechanicalContact");
198}
199
200void
202{
203 mooseAssert(_normals.size() == _lower_secondary_elem->n_nodes(),
204 "Making sure that _normals is the expected size");
205
206 // Get the _dof_to_weighted_gap map
207 const DofObject * dof = _var->isNodal()
208 ? cast_ptr<const DofObject *>(_lower_secondary_elem->node_ptr(_i))
209 : cast_ptr<const DofObject *>(_lower_secondary_elem);
210
211 // Regular normal contact constraint: Use before contact is established for contact detection
213
214 // Integrated part of the "persistency" constraint
217
219
220 if (_normalize_c)
221 _dof_to_weighted_gap[dof].second += _test[_i][_qp] * _qp_factor;
222}
223
224void
226{
227 // These dof maps are not recoverable as they are maps of pointers, and recovering old pointers
228 // would be wrong. We would need to create a custom dataStore() and dataLoad()
229 if (_app.isRecovering())
230 mooseError("This object does not support recovering");
231
232 // timestepSetup() runs once per time step attempt, so on a retried timestep (e.g. --test-restep
233 // or a rejected step) the history below has already been advanced from the accepted state;
234 // advancing it again would overwrite that history with the discarded attempt's last values.
238 return;
239
241 _dof_to_old_velocity.clear();
243
244 for (auto & map_pr : _dof_to_weighted_gap)
245 _dof_to_old_weighted_gap.emplace(map_pr.first, std::move(map_pr.second.first));
246
247 for (auto & map_pr : _dof_to_velocity)
248 _dof_to_old_velocity.emplace(map_pr);
249
250 for (auto & map_pr : _dof_to_nodal_wear_depth)
251 _dof_to_nodal_old_wear_depth.emplace(map_pr);
252}
253
254void
264
265void
267{
270
271 if (_has_wear)
273
274 // There is a need for the dynamic constraint to uncouple the computation of the weighted gap from
275 // the computation of the constraint itself since we are switching from gap constraint to
276 // persistency constraint.
277 for (const auto & pr : _dof_to_weighted_gap)
278 {
279 if (pr.first->processor_id() != this->processor_id())
280 continue;
281
282 //
283 _dof_to_weighted_gap[pr.first].first += _dof_to_nodal_wear_depth[pr.first];
286 //
287
288 const auto is_dof_on_map = _dof_to_old_weighted_gap.find(pr.first);
289
290 // If is_dof_on_map isn't on map, it means it's an initial step
291 if (is_dof_on_map == _dof_to_old_weighted_gap.end() ||
293 _weighted_gap_ptr = &pr.second.first;
294 else
295 {
297 term += _dof_to_old_velocity[pr.first];
298 _dof_to_weighted_gap_dynamics[pr.first] += term;
300 }
301
302 _normalization_ptr = &pr.second.second;
303
305 }
306}
307
308void
310 const std::unordered_set<const Node *> & inactive_lm_nodes)
311{
314
315 if (_has_wear)
317
318 for (const auto & pr : _dof_to_weighted_gap)
319 {
320 if ((inactive_lm_nodes.find(static_cast<const Node *>(pr.first)) != inactive_lm_nodes.end()) ||
321 (pr.first->processor_id() != this->processor_id()))
322 continue;
323
324 //
325 _dof_to_weighted_gap[pr.first].first += _dof_to_nodal_wear_depth[pr.first];
328 const auto is_dof_on_map = _dof_to_old_weighted_gap.find(pr.first);
329
330 // If is_dof_on_map isn't on map, it means it's an initial step
331 if (is_dof_on_map == _dof_to_old_weighted_gap.end() ||
333 {
334 // If this is the first step or the previous step gap is not identified as in contact, apply
335 // regular conditions
336 _weighted_gap_ptr = &pr.second.first;
337 }
338 else
339 {
340 ADReal term = _dof_to_weighted_gap[pr.first].first * _newmark_gamma / (_newmark_beta * _dt);
342 term -= _dof_to_old_velocity[pr.first];
343 _dof_to_weighted_gap_dynamics[pr.first] = term;
344 // Enable the application of persistency condition
346 }
347
348 _normalization_ptr = &pr.second.second;
349
351 }
352}
353
354void
356{
357 // We may have wear depth information that should go to other processes that own the dofs
358 using Datum = std::pair<dof_id_type, ADReal>;
359 std::unordered_map<processor_id_type, std::vector<Datum>> push_data;
360
361 for (auto & pr : _dof_to_nodal_wear_depth)
362 {
363 const auto * const dof_object = pr.first;
364 const auto proc_id = dof_object->processor_id();
365 if (proc_id == this->processor_id())
366 continue;
367
368 push_data[proc_id].push_back(std::make_pair(dof_object->id(), std::move(pr.second)));
369 }
370
371 const auto & lm_mesh = _mesh.getMesh();
372
373 auto action_functor = [this, &lm_mesh](const processor_id_type libmesh_dbg_var(pid),
374 const std::vector<Datum> & sent_data)
375 {
376 mooseAssert(pid != this->processor_id(), "We do not send messages to ourself here");
377 for (auto & pr : sent_data)
378 {
379 const auto dof_id = pr.first;
380 const auto * const dof_object = _nodal
381 ? cast_ptr<const DofObject *>(lm_mesh.node_ptr(dof_id))
382 : cast_ptr<const DofObject *>(lm_mesh.elem_ptr(dof_id));
383 mooseAssert(dof_object, "This should be non-null");
384 _dof_to_nodal_wear_depth[dof_object] += std::move(pr.second);
385 }
386 };
387
388 TIMPI::push_parallel_vector_data(_communicator, push_data, action_functor);
389}
390
391void
393{
394 const auto & weighted_gap = *_weighted_gap_ptr;
395 const Real c = _normalize_c ? _c / *_normalization_ptr : _c;
396
397 const auto dof_index = dof->dof_number(_sys.number(), _var->number(), 0);
398 ADReal lm_value = (*_sys.currentSolution())(dof_index);
399 Moose::derivInsert(lm_value.derivatives(), dof_index, 1.);
400
401 const ADReal dof_residual = std::min(lm_value, weighted_gap * c);
402
404 std::array<ADReal, 1>{{dof_residual}},
405 std::array<dof_id_type, 1>{{dof_index}},
407}
408
409void
411{
412 if (mortar_type != Moose::MortarType::Lower)
413 return;
414
415 mooseAssert(_var, "LM variable is null");
416
417 for (_qp = 0; _qp < _qrule_msm->n_points(); _qp++)
418 {
420 for (_i = 0; _i < _test.size(); ++_i)
422 }
423}
424
425void
430
431void
433{
434 // During "computeResidual" and "computeJacobian" we are actually just computing properties on the
435 // mortar segment element mesh. We are *not* actually assembling into the residual/Jacobian. For
436 // the zero-penetration constraint, the property of interest is the map from node to weighted gap.
437 // Computation of the properties proceeds identically for residual and Jacobian evaluation hence
438 // why we simply call computeResidual here. We will assemble into the residual/Jacobian later from
439 // the post() method
440 computeResidual(mortar_type);
441}
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
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.
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
MooseVariable *const _var
bool useDual() const
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
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
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 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)