https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MortarNodalFrames.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
10#include "MortarNodalFrames.h"
13#include "MooseVariableFE.h"
14#include "SystemBase.h"
15
16namespace Moose
17{
18namespace Mortar
19{
21nodalCoordinate(const Node & node, const std::array<const MooseVariable *, 3> & disp_vars)
22{
23 ADPoint point = node;
24
25 for (const auto component : index_range(disp_vars))
26 if (const auto * const variable = disp_vars[component])
27 {
28 const auto sys_num = variable->sys().number();
29 const auto var_num = variable->number();
30 // Enriched elements can have mapping nodes without independent displacement degrees of
31 // freedom. Their positions enter the geometric map, but they contribute no independent
32 // displacement derivative.
33 if (node.n_dofs(sys_num, var_num))
35 point(component).derivatives(), node.dof_number(sys_num, var_num, 0), 1.0);
36 }
37
38 return point;
39}
40
41bool
42supportsNodalNormalDerivatives(const std::array<const MooseVariable *, 3> & disp_vars,
43 const SystemBase & sys)
44{
45 for (const auto * const variable : disp_vars)
46 if (variable && (!variable->isNodal() || &variable->sys() != &sys))
47 return false;
48 return true;
49}
50
51void
53 const std::array<const MooseVariable *, 3> & disp_vars,
54 const std::array<std::string, 3> & param_names,
55 const SystemBase & sys)
56{
57 for (const auto component : index_range(disp_vars))
58 if (const auto * const variable = disp_vars[component])
59 {
60 if (!variable->isNodal())
61 object.paramError(param_names[component],
62 "Nodal-normal derivatives require a nodal displacement variable.");
63 if (&variable->sys() != &sys)
64 object.paramError(param_names[component],
65 "Nodal-normal derivatives require displacement variables in the "
66 "nonlinear system assembled by this contact object.");
67 }
68}
69
72 const Node & node,
73 const Point & stored_normal,
74 const bool do_derivatives)
75{
76 if (const auto it = _normals.find(&node); it != _normals.end())
77 return it->second;
78
79 if (!do_derivatives)
80 return _normals.emplace(&node, stored_normal).first->second;
81
82 amg.computeADNodalNormals([this](const Node & coordinate_node)
83 { return nodalCoordinate(coordinate_node, _disp_vars); },
84 _normals);
85 return libmesh_map_find(_normals, &node);
86}
87
88const std::array<ADRealVectorValue, 2> &
90 const Node & node,
91 const Point & stored_normal,
92 const bool do_derivatives)
93{
94 auto it = _tangents.find(&node);
95 if (it == _tangents.end())
96 it = _tangents
97 .emplace(&node,
98 Moose::Mortar::nodalTangents(normal(amg, node, stored_normal, do_derivatives),
99 amg.dim()))
100 .first;
101 return it->second;
102}
103
104std::vector<ADRealVectorValue>
106 const Elem & secondary_elem,
107 const std::vector<Point> & xi_pts,
108 const std::vector<Point> & stored_normals,
109 const bool do_derivatives)
110{
111 mooseAssert(xi_pts.size() == stored_normals.size(),
112 "There must be one stored normal per reference point.");
113 if (!do_derivatives)
114 return {stored_normals.begin(), stored_normals.end()};
115
116 const auto stored_nodal_normals = amg.getNodalNormals(secondary_elem);
117 const auto mortar_dim = secondary_elem.dim();
118 std::vector<ADRealVectorValue> normals(xi_pts.size());
119 for (const auto n : make_range(secondary_elem.n_nodes()))
120 {
121 const auto & nodal_normal =
122 normal(amg, secondary_elem.node_ref(n), stored_nodal_normals[n], do_derivatives);
123 for (const auto qp : index_range(xi_pts))
124 {
125 const auto phi =
126 (mortar_dim == 1)
127 ? Moose::fe_lagrange_1D_shape(secondary_elem.default_order(), n, xi_pts[qp](0))
128 : Moose::fe_lagrange_2D_shape(secondary_elem.type(),
129 secondary_elem.default_order(),
130 n,
131 cast_ref<const TypeVector<Real> &>(xi_pts[qp]));
132 normals[qp] += phi * nodal_normal;
133 }
134 }
135
136 // getNormals() flips the interpolated normals of a periodic interface. Matching the stored
137 // values keeps the residual unchanged whichever convention the interface uses.
138 for (const auto qp : index_range(normals))
139 if (MetaPhysicL::raw_value(normals[qp]) * stored_normals[qp] < 0)
140 normals[qp] *= -1;
141
142 return normals;
143}
144
145void
147{
148 _normals.clear();
149 _tangents.clear();
150}
151}
152}
This class is a container/interface for the objects involved in automatic generation of mortar spaces...
void computeADNodalNormals(const std::function< ADPoint(const Node &)> &coordinate, std::unordered_map< const Node *, ADRealVectorValue > &nodal_normals) const
Build the normalized JxW-weighted secondary nodal normals from AD nodal coordinates.
std::vector< Point > getNodalNormals(const Elem &secondary_elem) const
Base class for everything in MOOSE with a name and a type.
Definition MooseBase.h:50
std::vector< ADRealVectorValue > interpolatedNormals(const AutomaticMortarGeneration &amg, const Elem &secondary_elem, const std::vector< Point > &xi_pts, const std::vector< Point > &stored_normals, bool do_derivatives)
Interpolate the nodal normals of secondary_elem to reference points in the same way as AutomaticMorta...
std::unordered_map< const Node *, ADRealVectorValue > _normals
const std::array< const MooseVariable *, 3 > _disp_vars
const std::array< ADRealVectorValue, 2 > & tangents(const AutomaticMortarGeneration &amg, const Node &node, const Point &stored_normal, bool do_derivatives)
std::unordered_map< const Node *, std::array< ADRealVectorValue, 2 > > _tangents
const ADRealVectorValue & normal(const AutomaticMortarGeneration &amg, const Node &node, const Point &stored_normal, bool do_derivatives)
Base class for a system (of equations)
Definition SystemBase.h:87
auto raw_value(const Eigen::Map< T > &in)
ADPoint nodalCoordinate(const Node &node, const std::array< const MooseVariable *, 3 > &disp_vars)
void checkNodalNormalDisplacements(const MooseBase &object, const std::array< const MooseVariable *, 3 > &disp_vars, const std::array< std::string, 3 > &param_names, const SystemBase &sys)
Error unless supportsNodalNormalDerivatives() holds.
bool supportsNodalNormalDerivatives(const std::array< const MooseVariable *, 3 > &disp_vars, const SystemBase &sys)
std::array< Vector, 2 > nodalTangents(const Vector &normal, const unsigned int dim)
Construct the two tangent vectors used by mortar from a unit normal on a dim dimensional mesh.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
T fe_lagrange_2D_shape(const libMesh::ElemType type, const Order order, const unsigned int i, const VectorType< T > &p)
T fe_lagrange_1D_shape(const Order order, const unsigned int i, const T &xi)
void derivInsert(SemiDynamicSparseNumberArray< Real, libMesh::dof_id_type, NWrapper< N > > &derivs, libMesh::dof_id_type index, Real value)
Definition ADReal.h:21