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{
111 if (!useDual())
112 mooseError("Dynamic mortar contact constraints requires the use of Lagrange multipliers dual "
113 "interpolation");
114}
115
116void
118{
119 // Trim interior node variable derivatives
120 const auto & primary_ip_lowerd_map = amg().getPrimaryIpToLowerElementMap(
122 const auto & secondary_ip_lowerd_map =
124
125 std::array<const MooseVariable *, 3> var_array{{_disp_x_var, _disp_y_var, _disp_z_var}};
126 std::array<ADReal, 3> primary_disp{
127 {_primary_disp_x[_qp], _primary_disp_y[_qp], _has_disp_z ? (*_primary_disp_z)[_qp] : 0}};
128 std::array<ADReal, 3> secondary_disp{{_secondary_disp_x[_qp],
130 _has_disp_z ? (*_secondary_disp_z)[_qp] : 0}};
131
132 trimInteriorNodeDerivatives(primary_ip_lowerd_map, var_array, primary_disp, false);
133 trimInteriorNodeDerivatives(secondary_ip_lowerd_map, var_array, secondary_disp, true);
134
135 const ADReal & prim_x = primary_disp[0];
136 const ADReal & prim_y = primary_disp[1];
137 const ADReal * prim_z = nullptr;
138 if (_has_disp_z)
139 prim_z = &primary_disp[2];
140
141 const ADReal & sec_x = secondary_disp[0];
142 const ADReal & sec_y = secondary_disp[1];
143 const ADReal * sec_z = nullptr;
144 if (_has_disp_z)
145 sec_z = &secondary_disp[2];
146
147 std::array<ADReal, 3> primary_disp_dot{
148 {_primary_x_dot[_qp], _primary_y_dot[_qp], _has_disp_z ? (*_primary_z_dot)[_qp] : 0}};
149 std::array<ADReal, 3> secondary_disp_dot{
150 {_secondary_x_dot[_qp], _secondary_y_dot[_qp], _has_disp_z ? (*_secondary_z_dot)[_qp] : 0}};
151
152 trimInteriorNodeDerivatives(primary_ip_lowerd_map, var_array, primary_disp_dot, false);
153 trimInteriorNodeDerivatives(secondary_ip_lowerd_map, var_array, secondary_disp_dot, true);
154
155 const ADReal & prim_x_dot = primary_disp_dot[0];
156 const ADReal & prim_y_dot = primary_disp_dot[1];
157 const ADReal * prim_z_dot = nullptr;
158 if (_has_disp_z)
159 prim_z_dot = &primary_disp_dot[2];
160
161 const ADReal & sec_x_dot = secondary_disp_dot[0];
162 const ADReal & sec_y_dot = secondary_disp_dot[1];
163 const ADReal * sec_z_dot = nullptr;
164 if (_has_disp_z)
165 sec_z_dot = &secondary_disp_dot[2];
166
167 // Compute dynamic constraint-related quantities
169 gap_vec(0).derivatives() = prim_x.derivatives() - sec_x.derivatives();
170 gap_vec(1).derivatives() = prim_y.derivatives() - sec_y.derivatives();
171
172 _relative_velocity = ADRealVectorValue(prim_x_dot - sec_x_dot, prim_y_dot - sec_y_dot, 0.0);
173
174 if (_has_disp_z)
175 {
176 gap_vec(2).derivatives() = prim_z->derivatives() - sec_z->derivatives();
177 _relative_velocity(2) = *prim_z_dot - *sec_z_dot;
178 }
179
180 _qp_gap_nodal = gap_vec * (_JxW_msm[_qp] * _coord[_qp]);
182
183 // Current part of the gap velocity Newmark-beta time discretization
185 (_newmark_gamma / _newmark_beta * gap_vec / _dt) * (_JxW_msm[_qp] * _coord[_qp]);
186
187 // To do normalization of constraint coefficient (c_n)
189}
190
191ADReal
193{
195 "We should never call computeQpResidual for ComputeDynamicWeightedGapLMMechanicalContact");
196}
197
198void
200{
201 mooseAssert(_normals.size() == _lower_secondary_elem->n_nodes(),
202 "Making sure that _normals is the expected size");
203
204 // Get the _dof_to_weighted_gap map
205 const DofObject * dof = _var->isNodal()
206 ? static_cast<const DofObject *>(_lower_secondary_elem->node_ptr(_i))
207 : static_cast<const DofObject *>(_lower_secondary_elem);
208
209 // Regular normal contact constraint: Use before contact is established for contact detection
211
212 // Integrated part of the "persistency" constraint
215
217
218 if (_normalize_c)
219 _dof_to_weighted_gap[dof].second += _test[_i][_qp] * _qp_factor;
220}
221
222void
224{
225 // These dof maps are not recoverable as they are maps of pointers, and recovering old pointers
226 // would be wrong. We would need to create a custom dataStore() and dataLoad()
227 if (_app.isRecovering())
228 mooseError("This object does not support recovering");
229
231 _dof_to_old_velocity.clear();
233
234 for (auto & map_pr : _dof_to_weighted_gap)
235 _dof_to_old_weighted_gap.emplace(map_pr.first, std::move(map_pr.second.first));
236
237 for (auto & map_pr : _dof_to_velocity)
238 _dof_to_old_velocity.emplace(map_pr);
239
240 for (auto & map_pr : _dof_to_nodal_wear_depth)
241 _dof_to_nodal_old_wear_depth.emplace(map_pr);
242}
243
244void
254
255void
257{
260
261 if (_has_wear)
263
264 // There is a need for the dynamic constraint to uncouple the computation of the weighted gap from
265 // the computation of the constraint itself since we are switching from gap constraint to
266 // persistency constraint.
267 for (const auto & pr : _dof_to_weighted_gap)
268 {
269 if (pr.first->processor_id() != this->processor_id())
270 continue;
271
272 //
273 _dof_to_weighted_gap[pr.first].first += _dof_to_nodal_wear_depth[pr.first];
276 //
277
278 const auto is_dof_on_map = _dof_to_old_weighted_gap.find(pr.first);
279
280 // If is_dof_on_map isn't on map, it means it's an initial step
281 if (is_dof_on_map == _dof_to_old_weighted_gap.end() ||
283 _weighted_gap_ptr = &pr.second.first;
284 else
285 {
287 term += _dof_to_old_velocity[pr.first];
288 _dof_to_weighted_gap_dynamics[pr.first] += term;
290 }
291
292 _normalization_ptr = &pr.second.second;
293
295 }
296}
297
298void
300 const std::unordered_set<const Node *> & inactive_lm_nodes)
301{
304
305 if (_has_wear)
307
308 for (const auto & pr : _dof_to_weighted_gap)
309 {
310 if ((inactive_lm_nodes.find(static_cast<const Node *>(pr.first)) != inactive_lm_nodes.end()) ||
311 (pr.first->processor_id() != this->processor_id()))
312 continue;
313
314 //
315 _dof_to_weighted_gap[pr.first].first += _dof_to_nodal_wear_depth[pr.first];
318 const auto is_dof_on_map = _dof_to_old_weighted_gap.find(pr.first);
319
320 // If is_dof_on_map isn't on map, it means it's an initial step
321 if (is_dof_on_map == _dof_to_old_weighted_gap.end() ||
323 {
324 // If this is the first step or the previous step gap is not identified as in contact, apply
325 // regular conditions
326 _weighted_gap_ptr = &pr.second.first;
327 }
328 else
329 {
330 ADReal term = _dof_to_weighted_gap[pr.first].first * _newmark_gamma / (_newmark_beta * _dt);
332 term -= _dof_to_old_velocity[pr.first];
333 _dof_to_weighted_gap_dynamics[pr.first] = term;
334 // Enable the application of persistency condition
336 }
337
338 _normalization_ptr = &pr.second.second;
339
341 }
342}
343
344void
346{
347 // We may have wear depth information that should go to other processes that own the dofs
348 using Datum = std::pair<dof_id_type, ADReal>;
349 std::unordered_map<processor_id_type, std::vector<Datum>> push_data;
350
351 for (auto & pr : _dof_to_nodal_wear_depth)
352 {
353 const auto * const dof_object = pr.first;
354 const auto proc_id = dof_object->processor_id();
355 if (proc_id == this->processor_id())
356 continue;
357
358 push_data[proc_id].push_back(std::make_pair(dof_object->id(), std::move(pr.second)));
359 }
360
361 const auto & lm_mesh = _mesh.getMesh();
362
363 auto action_functor = [this, &lm_mesh](const processor_id_type libmesh_dbg_var(pid),
364 const std::vector<Datum> & sent_data)
365 {
366 mooseAssert(pid != this->processor_id(), "We do not send messages to ourself here");
367 for (auto & pr : sent_data)
368 {
369 const auto dof_id = pr.first;
370 const auto * const dof_object =
371 _nodal ? static_cast<const DofObject *>(lm_mesh.node_ptr(dof_id))
372 : static_cast<const DofObject *>(lm_mesh.elem_ptr(dof_id));
373 mooseAssert(dof_object, "This should be non-null");
374 _dof_to_nodal_wear_depth[dof_object] += std::move(pr.second);
375 }
376 };
377
378 TIMPI::push_parallel_vector_data(_communicator, push_data, action_functor);
379}
380
381void
383{
384 const auto & weighted_gap = *_weighted_gap_ptr;
385 const Real c = _normalize_c ? _c / *_normalization_ptr : _c;
386
387 const auto dof_index = dof->dof_number(_sys.number(), _var->number(), 0);
388 ADReal lm_value = (*_sys.currentSolution())(dof_index);
389 Moose::derivInsert(lm_value.derivatives(), dof_index, 1.);
390
391 const ADReal dof_residual = std::min(lm_value, weighted_gap * c);
392
394 std::array<ADReal, 1>{{dof_residual}},
395 std::array<dof_id_type, 1>{{dof_index}},
397}
398
399void
401{
402 if (mortar_type != Moose::MortarType::Lower)
403 return;
404
405 mooseAssert(_var, "LM variable is null");
406
407 for (_qp = 0; _qp < _qrule_msm->n_points(); _qp++)
408 {
410 for (_i = 0; _i < _test.size(); ++_i)
412 }
413}
414
415void
420
421void
423{
424 // During "computeResidual" and "computeJacobian" we are actually just computing properties on the
425 // mortar segment element mesh. We are *not* actually assembling into the residual/Jacobian. For
426 // the zero-penetration constraint, the property of interest is the map from node to weighted gap.
427 // Computation of the properties proceeds identically for residual and Jacobian evaluation hence
428 // why we simply call computeResidual here. We will assemble into the residual/Jacobian later from
429 // the post() method
430 computeResidual(mortar_type);
431}
DualNumber< Real, DNDerivativeType, true > ADReal
registerMooseObject("ContactApp", ComputeDynamicWeightedGapLMMechanicalContact)
void mooseError(Args &&... args)
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
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.
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)