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"
23#include "metaphysicl/parallel_dynamic_array_wrapper.h"
25#include "metaphysicl/parallel_semidynamicsparsenumberarray.h"
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");
41 ret.
set<VariableName>(
"secondary_variable") = disp_x_name[0];
42 ret.
set<VariableName>(
"primary_variable") = disp_x_name[0];
52 params.
set<
bool>(
"_compute_primal_gradients") =
false;
54 "Computes the normal contact mortar constraints for dynamic simulations");
57 "capture_tolerance>=0",
58 "Parameter describing a gap threshold for the application of "
59 "the persistency constraint in dynamic simulations.");
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");
71 params.
addCoupledVar(
"disp_z",
"The z displacement variable");
73 "c", 1e6,
"Parameter for balancing the size of the gap and contact pressure");
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).");
83 params.
set<
bool>(
"ghost_point_neighbors") =
true;
84 params.
set<
bool>(
"use_displaced_mesh") =
true;
85 params.
set<
bool>(
"interpolate_normals") =
false;
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),
121 mooseError(
"Dynamic mortar contact constraints requires the use of Lagrange multipliers dual "
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.");
147 const auto & secondary_ip_lowerd_map =
151 std::array<ADReal, 3> primary_disp{
160 const ADReal & prim_x = primary_disp[0];
161 const ADReal & prim_y = primary_disp[1];
162 const ADReal * prim_z =
nullptr;
164 prim_z = &primary_disp[2];
166 const ADReal & sec_x = secondary_disp[0];
167 const ADReal & sec_y = secondary_disp[1];
168 const ADReal * sec_z =
nullptr;
170 sec_z = &secondary_disp[2];
172 std::array<ADReal, 3> primary_disp_dot{
174 std::array<ADReal, 3> secondary_disp_dot{
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;
184 prim_z_dot = &primary_disp_dot[2];
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;
190 sec_z_dot = &secondary_disp_dot[2];
194 gap_vec(0).derivatives() = prim_x.derivatives() - sec_x.derivatives();
195 gap_vec(1).derivatives() = prim_y.derivatives() - sec_y.derivatives();
201 gap_vec(2).derivatives() = prim_z->derivatives() - sec_z->derivatives();
220 "We should never call computeQpResidual for ComputeDynamicWeightedGapLMMechanicalContact");
227 "Making sure that _normals is the expected size");
258 mooseError(
"This object does not support recovering");
339 const std::unordered_set<const Node *> & inactive_lm_nodes)
349 if ((inactive_lm_nodes.find(
static_cast<const Node *
>(pr.first)) != inactive_lm_nodes.end()) ||
387 using Datum = std::pair<dof_id_type, ADReal>;
388 std::unordered_map<processor_id_type, std::vector<Datum>> push_data;
392 const auto *
const dof_object = pr.first;
393 const auto proc_id = dof_object->processor_id();
397 push_data[proc_id].push_back(std::make_pair(dof_object->id(), std::move(pr.second)));
402 auto action_functor = [
this, &lm_mesh](
const processor_id_type libmesh_dbg_var(pid),
403 const std::vector<Datum> & sent_data)
405 mooseAssert(pid != this->
processor_id(),
"We do not send messages to ourself here");
406 for (
auto & pr : sent_data)
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");
430 const ADReal dof_residual = std::min(lm_value, weighted_gap *
c);
433 std::array<ADReal, 1>{{dof_residual}},
434 std::array<dof_id_type, 1>{{dof_index}},
441 if (mortar_type != Moose::MortarType::Lower)
444 mooseAssert(
_var,
"LM variable is null");
DualNumber< Real, DNDerivativeType, true > ADReal
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)
bool isRecovering() const
void mooseError(Args &&... args) const
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
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 checkNodalNormalDisplacements(const MooseBase &object, const std::array< const MooseVariable *, 3 > &disp_vars, const std::array< std::string, 3 > ¶m_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)