https://mooseframework.inl.gov
Loading...
Searching...
No Matches
WeightedVelocitiesUserObject.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 "MooseVariableField.h"
12#include "SubProblem.h"
13#include "SystemBase.h"
14#include "MortarUtils.h"
15#include "MooseUtils.h"
16#include "MortarContactUtils.h"
18#include "libmesh/quadrature.h"
19
22{
24 params.addRequiredParam<VariableName>("secondary_variable",
25 "Primal variable on secondary surface.");
26 params.addParam<VariableName>(
27 "primary_variable",
28 "Primal variable on primary surface. If this parameter is not provided then the primary "
29 "variable will be initialized to the secondary variable");
30 return params;
31}
32
34 : WeightedGapUserObject(parameters),
35 // Must explicitly call this method on parameters due to GCC 14 bug
36 // in mail-archive.com/[email protected]/msg878282.html
37 _sys(*parameters.getCheckedPointerParam<SystemBase *>("_sys")),
38 _secondary_var(
39 isParamValid("secondary_variable")
40 ? _sys.getActualFieldVariable<Real>(_tid, parameters.getMooseType("secondary_variable"))
41 : _sys.getActualFieldVariable<Real>(_tid, parameters.getMooseType("primary_variable"))),
42 _primary_var(
43 isParamValid("primary_variable")
44 ? _sys.getActualFieldVariable<Real>(_tid, parameters.getMooseType("primary_variable"))
45 : _secondary_var),
46 _secondary_x_dot(_secondary_var.adUDot()),
47 _primary_x_dot(_primary_var.adUDotNeighbor()),
48 _secondary_y_dot(adCoupledDot("disp_y")),
49 _primary_y_dot(adCoupledNeighborValueDot("disp_y")),
50 _secondary_z_dot(_has_disp_z ? &adCoupledDot("disp_z") : nullptr),
51 _primary_z_dot(_has_disp_z ? &adCoupledNeighborValueDot("disp_z") : nullptr),
52 _3d(_has_disp_z)
53{
54 if (!getParam<bool>("use_displaced_mesh"))
55 paramError("use_displaced_mesh",
56 "'use_displaced_mesh' must be true for the WeightedVelocitiesUserObject object");
57}
58
61 unsigned int /*direction*/) const
62{
63 mooseError("Nodal tangential pressure is not available for user object '", name(), "'.");
64}
65
66const std::array<ADRealVectorValue, 2> &
67WeightedVelocitiesUserObject::contactTangents(const Elem & lower_secondary_elem,
68 const unsigned int nodal_index) const
69{
70 mooseAssert(nodal_index < lower_secondary_elem.n_nodes(),
71 "Nodal tangent index must refer to a node on the secondary element.");
73 "AD contact tangents should only be requested while recording nodal-normal "
74 "derivatives.");
75 const Node * const node = lower_secondary_elem.node_ptr(nodal_index);
76 auto it = _ad_nodal_tangents.find(node);
77 if (it == _ad_nodal_tangents.end())
79 .emplace(node,
81 contactNormal(lower_secondary_elem, nodal_index)))
82 .first;
83
84#ifndef NDEBUG
85 // A cached frame must belong to the current geometry. The tolerance matches the stored versus AD
86 // nodal normal check in AutomaticMortarGeneration::computeADNodalNormals.
87 const auto & stored_tangents = amg().getNodalTangents(lower_secondary_elem);
88 for (const auto direction : make_range(2))
89 mooseAssert(
90 (MetaPhysicL::raw_value(it->second[direction]) - stored_tangents[direction][nodal_index])
91 .norm() < 1e-10,
92 "The stored and AD secondary nodal tangents must use the same geometry state.");
93#endif
94
95 return it->second;
96}
97
98void
100{
101 // Compute the value of _qp_gap
103
104 // Trim derivatives
105 const auto & primary_ip_lowerd_map = amg().getPrimaryIpToLowerElementMap(
107 const auto & secondary_ip_lowerd_map =
109
110 std::array<const MooseVariable *, 3> var_array{{_disp_x_var, _disp_y_var, _disp_z_var}};
111 std::array<ADReal, 3> primary_disp_dot{
112 {_primary_x_dot[_qp], _primary_y_dot[_qp], _has_disp_z ? (*_primary_z_dot)[_qp] : 0}};
113 std::array<ADReal, 3> secondary_disp_dot{
114 {_secondary_x_dot[_qp], _secondary_y_dot[_qp], _has_disp_z ? (*_secondary_z_dot)[_qp] : 0}};
115
116 trimInteriorNodeDerivatives(primary_ip_lowerd_map, var_array, primary_disp_dot, false);
117 trimInteriorNodeDerivatives(secondary_ip_lowerd_map, var_array, secondary_disp_dot, true);
118
119 const ADReal & prim_x_dot = primary_disp_dot[0];
120 const ADReal & prim_y_dot = primary_disp_dot[1];
121 const ADReal * prim_z_dot = nullptr;
122 if (_has_disp_z)
123 prim_z_dot = &primary_disp_dot[2];
124
125 const ADReal & sec_x_dot = secondary_disp_dot[0];
126 const ADReal & sec_y_dot = secondary_disp_dot[1];
127 const ADReal * sec_z_dot = nullptr;
128 if (_has_disp_z)
129 sec_z_dot = &secondary_disp_dot[2];
130
131 // Build relative velocity vector
132 ADRealVectorValue relative_velocity;
133
134 if (_3d)
135 relative_velocity = {sec_x_dot - prim_x_dot, sec_y_dot - prim_y_dot, *sec_z_dot - *prim_z_dot};
136 else
137 relative_velocity = {sec_x_dot - prim_x_dot, sec_y_dot - prim_y_dot, 0.0};
138
139 // Geometry is averaged and used at the nodes for constraint enforcement.
140 _qp_real_tangential_velocity_nodal = relative_velocity;
141 _qp_tangential_velocity_nodal = relative_velocity * (_JxW_msm[_qp] * _coord[_qp]);
142}
143
144void
146{
148
149 // Get the _dof_to_weighted_tangential_velocity map
150 const DofObject * const dof =
151 _is_weighted_gap_nodal ? cast_ptr<const DofObject *>(_lower_secondary_elem->node_ptr(_i))
152 : cast_ptr<const DofObject *>(_lower_secondary_elem);
153
155 {
156 const auto & tangents = contactTangents(*_lower_secondary_elem, _i);
157 for (const auto direction : make_range(_3d ? 2 : 1))
158 {
159 _dof_to_weighted_tangential_velocity[dof][direction] +=
160 (*_test)[_i][_qp] * _qp_tangential_velocity_nodal * tangents[direction];
161 _dof_to_real_tangential_velocity[dof][direction] +=
162 (*_test)[_i][_qp] * _qp_real_tangential_velocity_nodal * tangents[direction];
163 }
164 }
165 else
166 {
167 const auto & nodal_tangents = amg().getNodalTangents(*_lower_secondary_elem);
168
170 (*_test)[_i][_qp] * _qp_tangential_velocity_nodal * nodal_tangents[0][_i];
172 (*_test)[_i][_qp] * _qp_real_tangential_velocity_nodal * nodal_tangents[0][_i];
173
174 // Get the _dof_to_weighted_tangential_velocity map for a second direction
175 if (_3d)
176 {
178 (*_test)[_i][_qp] * _qp_tangential_velocity_nodal * nodal_tangents[1][_i];
179
181 (*_test)[_i][_qp] * _qp_real_tangential_velocity_nodal * nodal_tangents[1][_i];
182 }
183 }
184}
185
186void
193
194void
201
202void
204{
206
207 // If the constraint is performed by the owner, then we don't need any data sent back; the owner
208 // will take care of it. But if the constraint is not performed by the owner and we might have to
209 // do some of the constraining ourselves, then we need data sent back to us
210 const bool send_data_back = !constrainedByOwner();
211
214 _nodal,
216 send_data_back);
219}
DualNumber< Real, DNDerivativeType, true > ADReal
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
std::array< MooseUtils::SemidynamicVector< Point, 9 >, 2 > getNodalTangents(const Elem &secondary_elem) const
void addRequiredParam(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)
const std::string & name() const
void paramError(const std::string &param, Args... args) const
void mooseError(Args &&... args) const
Elem const *const & _lower_secondary_elem
const AutomaticMortarGeneration & amg() const
Elem const *const & _lower_primary_elem
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 MooseMesh & mesh()=0
SubProblem & _subproblem
Creates dof object to weighted gap map.
static InputParameters validParams()
bool shouldRecordNodalNormalDerivatives() const
Whether the current assembly records nodal-normal derivatives for this object's system.
unsigned int _i
Test function index.
const MooseVariable *const _disp_x_var
The x displacement variable.
virtual void computeQpProperties()
Computes properties that are functions only of the current quadrature point (_qp),...
const bool _has_disp_z
For 2D mortar contact no displacement will be specified, so const pointers used.
virtual void finalize() override
unsigned int _qp
Quadrature point index for the mortar segments.
const MooseArray< Real > & _coord
Member for handling change of coordinate systems (xyz, rz, spherical)
const MooseVariable *const _disp_y_var
The y displacement variable.
const ADRealVectorValue & contactNormal(const Elem &lower_secondary_elem, unsigned int nodal_index) const
Return the cached contact normal for the supplied lower-dimensional secondary element node.
const MooseVariable *const _disp_z_var
The z displacement variable.
virtual void computeQpIProperties()
Computes properties that are functions both of _qp and _i, for example the weighted gap.
virtual void initialize() override
bool _is_weighted_gap_nodal
Whether the weighted gap is associated with nodes or elements (like for a CONSTANT MONOMIAL Lagrange ...
virtual bool constrainedByOwner() const =0
const bool _nodal
Whether the dof objects are nodal; if they're not, then they're elemental.
WeightedVelocitiesUserObject(const InputParameters &parameters)
const std::array< ADRealVectorValue, 2 > & contactTangents(const Elem &lower_secondary_elem, unsigned int nodal_index) const
Return contact tangents for the supplied lower-dimensional secondary element node.
virtual void computeQpProperties() override
Computes properties that are functions only of the current quadrature point (_qp),...
std::unordered_map< const DofObject *, std::array< ADReal, 2 > > _dof_to_weighted_tangential_velocity
A map from node to two weighted tangential velocities.
const ADVariableValue & _primary_y_dot
y-velocity on the primary face
const ADVariableValue & _primary_x_dot
x-velocity on the primary face
virtual void computeQpIProperties() override
Computes properties that are functions both of _qp and _i, for example the weighted gap.
const ADVariableValue & _secondary_x_dot
x-velocity on the secondary face
ADRealVectorValue _qp_real_tangential_velocity_nodal
The value of the real tangential velocity vectors at the current node.
ADRealVectorValue _qp_tangential_velocity_nodal
The value of the tangential velocity vectors at the current node.
bool _3d
Automatic flag to determine whether we are doing three-dimensional work.
const ADVariableValue & _secondary_y_dot
y-velocity on the secondary face
std::unordered_map< const DofObject *, std::array< ADReal, 2 > > _dof_to_real_tangential_velocity
A map from node to two interpolated, physical tangential velocities.
virtual ADReal nodalTangentialPressure(const Node &node, unsigned int direction) const
std::unordered_map< const Node *, std::array< ADRealVectorValue, 2 > > _ad_nodal_tangents
AD contact tangent frames, keyed on the secondary node and reused by every test function and quadratu...
const Parallel::Communicator & _communicator
auto raw_value(const Eigen::Map< T > &in)
void communicateVelocities(std::unordered_map< const DofObject *, T > &dof_map, const MooseMesh &mesh, const bool nodal, const Parallel::Communicator &communicator, const bool send_data_back)
This function is used to communicate velocities across processes.
std::array< Vector, 2 > householderTangents(const Vector &normal)