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"
22#include "metaphysicl/parallel_dynamic_array_wrapper.h"
24#include "metaphysicl/parallel_semidynamicsparsenumberarray.h"
32assignVarsInParamsCartesianWeightedGap(
const 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");
40 ret.
set<VariableName>(
"secondary_variable") = disp_x_name[0];
41 ret.
set<VariableName>(
"primary_variable") = disp_x_name[0];
52 params.
set<
bool>(
"_compute_primal_gradients") =
false;
53 params.
addClassDescription(
"Computes the weighted gap that will later be used to enforce the "
54 "zero-penetration mechanical contact conditions");
59 params.
addCoupledVar(
"disp_z",
"The z displacement variable");
61 "c", 1e6,
"Parameter for balancing the size of the gap and contact pressure");
63 "Mechanical contact Lagrange multiplier along the x Cartesian axis");
65 "lm_y",
"Mechanical contact Lagrange multiplier along the y Cartesian axis.");
67 "Mechanical contact Lagrange multiplier along the z Cartesian axis.");
70 params.
set<
bool>(
"ghost_point_neighbors") =
true;
71 params.
set<
bool>(
"interpolate_normals") =
false;
75 "Whether to normalize c by weighting function norm. When unnormalized "
76 "the value of c effectively depends on element size since in the constraint we compare nodal "
77 "Lagrange Multiplier values to integrated gap values (LM nodal value is independent of "
78 "element size, where integrated values are dependent on element size).");
79 params.
set<
bool>(
"use_displaced_mesh") =
true;
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),
101 _lm_vars.push_back(getVar(
"lm_x", 0));
102 _lm_vars.push_back(getVar(
"lm_y", 0));
104 if (isParamValid(
"lm_z") ^ _has_disp_z)
106 "In three-dimensions, both the Z Lagrange multiplier and the Z displacement need to "
110 _lm_vars.push_back(getVar(
"lm_z", 0));
112 if (!getParam<bool>(
"use_displaced_mesh"))
114 "use_displaced_mesh",
115 "'use_displaced_mesh' must be true for the ComputeWeightedGapLMMechanicalContact object");
117 if (getParam<bool>(
"interpolate_normals"))
118 paramError(
"interpolate_normals",
119 "Mechanical mortar contact uses normalized secondary nodal normals and cannot be "
120 "combined with quadrature-point normal interpolation.");
122 for (
const auto i : index_range(_lm_vars))
123 if (!_lm_vars[i]->isNodal())
124 if (_lm_vars[i]->feType().order != static_cast<Order>(0))
125 mooseError(
"Normal contact constraints only support elemental variables of CONSTANT order");
140 mooseError(
"We should never call computeQpResidual for ComputeWeightedGapLMMechanicalContact");
151 const auto & secondary_ip_lowerd_map =
155 std::array<ADReal, 3> primary_disp{
164 const ADReal & prim_x = primary_disp[0];
165 const ADReal & prim_y = primary_disp[1];
166 const ADReal * prim_z =
nullptr;
168 prim_z = &primary_disp[2];
170 const ADReal & sec_x = secondary_disp[0];
171 const ADReal & sec_y = secondary_disp[1];
172 const ADReal * sec_z =
nullptr;
174 sec_z = &secondary_disp[2];
179 gap_vec(0).derivatives() = prim_x.derivatives() - sec_x.derivatives();
180 gap_vec(1).derivatives() = prim_y.derivatives() - sec_y.derivatives();
182 gap_vec(2).derivatives() = prim_z->derivatives() - sec_z->derivatives();
195 "Making sure that _normals is the expected size");
198 const DofObject * dof =
_lm_vars[0]->isNodal()
238 if (mortar_type != Moose::MortarType::Lower)
241 for (
const auto i : index_range(
_lm_vars))
243 mooseAssert(
_lm_vars[i],
"LM variable is null");
255 const DofObject * dof =
_lm_vars[0]->isNodal()
271const std::array<ADRealVectorValue, 2> &
311 const std::unordered_set<const Node *> & inactive_lm_nodes)
318 if ((inactive_lm_nodes.find(
static_cast<const Node *
>(pr.first)) != inactive_lm_nodes.end()) ||
337 const Real scaling_factor_x =
_lm_vars[0]->scalingFactor();
338 const Real scaling_factor_y =
_lm_vars[1]->scalingFactor();
339 Real scaling_factor_z = 1;
347 dof_id_type dof_index_z(-1);
354 scaling_factor_z =
_lm_vars[2]->scalingFactor();
360 ADReal normal_pressure_value = lm_x * normal(0) + lm_y * normal(1);
361 ADReal tangential_pressure_value = lm_x * tangents[0](0) + lm_y * tangents[0](1);
363 ADReal tangential_pressure_value_dir = 0;
367 normal_pressure_value += lm_z * normal(2);
368 tangential_pressure_value += lm_z * tangents[0](2);
369 tangential_pressure_value_dir =
370 lm_x * tangents[1](0) + lm_y * tangents[1](1) + lm_z * tangents[1](2);
373 ADReal normal_dof_residual = std::min(normal_pressure_value, weighted_gap *
c);
374 ADReal tangential_dof_residual = tangential_pressure_value;
392 unsigned int component_normal = 0;
393 if (std::abs(ny) > 0.57735)
394 component_normal = 1;
395 else if (std::abs(nz) > 0.57735)
396 component_normal = 2;
398 libmesh_ignore(component_normal);
402 std::array<ADReal, 1>{{normal_dof_residual}},
403 std::array<dof_id_type, 1>{{component_normal == 0
405 : (component_normal == 1 ? dof_index_y : dof_index_z)}},
406 component_normal == 0 ? scaling_factor_x
407 : (component_normal == 1 ? scaling_factor_y : scaling_factor_z));
411 std::array<ADReal, 1>{{tangential_dof_residual}},
412 std::array<dof_id_type, 1>{
413 {(component_normal == 0 || component_normal == 2) ? dof_index_y : dof_index_x}},
414 (component_normal == 0 || component_normal == 2) ? scaling_factor_y : scaling_factor_x);
419 std::array<ADReal, 1>{{tangential_pressure_value_dir}},
420 std::array<dof_id_type, 1>{
421 {(component_normal == 0 || component_normal == 1) ? dof_index_z : dof_index_x}},
422 (component_normal == 0 || component_normal == 1) ? scaling_factor_z : scaling_factor_x);
DualNumber< Real, DNDerivativeType, true > ADReal
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
static const Elem & primaryInteriorParentOrSelf(const Elem &lower_primary_elem)
void mooseError(Args &&... args) const
const std::array< ADRealVectorValue, 2 > & tangents(const AutomaticMortarGeneration &amg, const Node &node, const Point &stored_normal, bool do_derivatives)
const ADRealVectorValue & normal(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 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)