25#include "libmesh/mesh_tools.h"
26#include "libmesh/explicit_system.h"
27#include "libmesh/numeric_vector.h"
28#include "libmesh/elem.h"
29#include "libmesh/node.h"
30#include "libmesh/dof_map.h"
31#include "libmesh/edge_edge2.h"
32#include "libmesh/edge_edge3.h"
33#include "libmesh/face_tri3.h"
34#include "libmesh/face_tri6.h"
35#include "libmesh/face_tri7.h"
36#include "libmesh/face_quad4.h"
37#include "libmesh/face_quad8.h"
38#include "libmesh/face_quad9.h"
39#include "libmesh/exodusII_io.h"
40#include "libmesh/quadrature_gauss.h"
41#include "libmesh/quadrature_nodal.h"
42#include "libmesh/distributed_mesh.h"
43#include "libmesh/replicated_mesh.h"
44#include "libmesh/enum_to_string.h"
45#include "libmesh/statistics.h"
46#include "libmesh/equation_systems.h"
47#include "libmesh/fe_map.h"
49#include "metaphysicl/dualnumber.h"
63#if NANOFLANN_VERSION < 0x150
92 mooseError(
"No entries found in the secondary node -> nodal geometry map.");
95 auto & subproblem =
_amg.
_on_displaced ? cast_ref<SubProblem &>(*problem.getDisplacedProblem())
96 : cast_ref<SubProblem &>(problem);
97 auto & nodal_normals_es = subproblem.es();
99 const std::string nodal_normals_sys_name =
"nodal_normals";
103 for (
const auto s : make_range(nodal_normals_es.n_systems()))
104 if (!nodal_normals_es.get_system(s).is_initialized())
110 &nodal_normals_es.template add_system<ExplicitSystem>(nodal_normals_sys_name);
128 nodal_normals_es.reinit();
132 std::vector<dof_id_type> dof_indices_nnx, dof_indices_nny, dof_indices_nnz;
133 std::vector<dof_id_type> dof_indices_t1x, dof_indices_t1y, dof_indices_t1z;
134 std::vector<dof_id_type> dof_indices_t2x, dof_indices_t2y, dof_indices_t2z;
136 for (MeshBase::const_element_iterator el =
_amg.
_mesh.elements_begin(),
141 const Elem * elem = *el;
145 dof_map.dof_indices(elem, dof_indices_nny,
_nny_var_num);
146 dof_map.dof_indices(elem, dof_indices_nnz,
_nnz_var_num);
148 dof_map.dof_indices(elem, dof_indices_t1x,
_t1x_var_num);
149 dof_map.dof_indices(elem, dof_indices_t1y,
_t1y_var_num);
150 dof_map.dof_indices(elem, dof_indices_t1z,
_t1z_var_num);
152 dof_map.dof_indices(elem, dof_indices_t2x,
_t2x_var_num);
153 dof_map.dof_indices(elem, dof_indices_t2y,
_t2y_var_num);
154 dof_map.dof_indices(elem, dof_indices_t2z,
_t2z_var_num);
160 for (MooseIndex(elem->n_vertices()) n = 0; n < elem->n_vertices(); ++n)
188 std::set<std::string> sys_names = {nodal_normals_sys_name};
191 ExodusII_IO nodal_normals_writer(
_amg.
_mesh);
194 nodal_normals_writer.set_hdf5_writing(
false);
196 nodal_normals_writer.write_equation_systems(
197 "nodal_geometry_only.e", nodal_normals_es, &sys_names);
224 const std::pair<BoundaryID, BoundaryID> & boundary_key,
225 const std::pair<SubdomainID, SubdomainID> & subdomain_key,
229 const bool correct_edge_dropping,
230 const Real minimum_projection_angle,
231 const Mortar3DSubpatchPlane mortar_3d_subpatch_plane,
233 const bool triangulate_triangles,
234 const Mortar3DQuadraturePointMapping mortar_3d_qp_mapping)
239 _on_displaced(on_displaced),
244 _distributed(_mesh.mesh_dimension() == 3 ? true : (!_on_displaced && !_mesh.is_replicated())),
245 _correct_edge_dropping(correct_edge_dropping),
246 _minimum_projection_angle(minimum_projection_angle),
247 _mortar_3d_subpatch_plane(mortar_3d_subpatch_plane),
248 _triangulation_mode(triangulation_mode),
249 _triangulate_triangles(triangulate_triangles),
250 _mortar_3d_qp_mapping(mortar_3d_qp_mapping)
261 std::make_unique<DistributedMesh>(
_mesh.comm(),
_mesh.spatial_dimension());
264 std::make_unique<ReplicatedMesh>(
_mesh.comm(),
_mesh.spatial_dimension());
274 string_vec[2 * i] = std::to_string(primary_bnd_id);
275 string_vec[2 * i + 1] = std::to_string(secondary_bnd_id);
277 string_vec.back() =
_on_displaced ?
"displaced" :
"undisplaced";
278 return MooseUtils::join(string_vec,
"_");
323 mooseError(
"Mortar segment reference points were requested for mortar segment element ",
324 mortar_segment_elem.id(),
325 ", but the reference-interpolation mapping mode is not enabled.");
329 mooseError(
"No reference-point record was found for mortar segment element ",
330 mortar_segment_elem.id(),
331 ". The mortar segment info and reference-point maps are not aligned.");
333 return reference_points_it->second;
341 "Must specify secondary and primary boundary ids before building node-to-elem maps.");
344 for (
const auto & secondary_elem :
345 as_range(
_mesh.active_elements_begin(),
_mesh.active_elements_end()))
351 for (
const auto & nd : secondary_elem->node_ref_range())
354 vec.push_back(secondary_elem);
359 for (
const auto & primary_elem :
360 as_range(
_mesh.active_elements_begin(),
_mesh.active_elements_end()))
366 for (
const auto & nd : primary_elem->node_ref_range())
369 vec.push_back(primary_elem);
377 std::vector<Point> nodal_normals(secondary_elem.n_nodes());
378 for (
const auto n : make_range(secondary_elem.n_nodes()))
381 return nodal_normals;
386 dof_id_type secondary_elem_id)
const
389 "Map should locate secondary element");
394std::map<unsigned int, unsigned int>
397 std::map<unsigned int, unsigned int> secondary_ip_i_to_lower_secondary_i;
398 const Elem *
const secondary_ip = lower_secondary_elem.interior_parent();
399 mooseAssert(secondary_ip,
"This should be non-null");
401 for (
const auto i : make_range(lower_secondary_elem.n_nodes()))
403 const auto & nd = lower_secondary_elem.node_ref(i);
404 secondary_ip_i_to_lower_secondary_i[secondary_ip->get_node_index(&nd)] = i;
407 return secondary_ip_i_to_lower_secondary_i;
410std::map<unsigned int, unsigned int>
412 const Elem & lower_primary_elem,
413 const Elem & primary_elem,
416 std::map<unsigned int, unsigned int> primary_ip_i_to_lower_primary_i;
418 for (
const auto i : make_range(lower_primary_elem.n_nodes()))
420 const auto & nd = lower_primary_elem.node_ref(i);
421 primary_ip_i_to_lower_primary_i[primary_elem.get_node_index(&nd)] = i;
424 return primary_ip_i_to_lower_primary_i;
427std::array<MooseUtils::SemidynamicVector<Point, 9>, 2>
431 MooseUtils::SemidynamicVector<Point, 9> nodal_tangents_one(0);
432 MooseUtils::SemidynamicVector<Point, 9> nodal_tangents_two(0);
434 for (
const auto n : make_range(secondary_elem.n_nodes()))
436 const auto & tangent_vectors =
438 nodal_tangents_one.push_back(tangent_vectors[0]);
439 nodal_tangents_two.push_back(tangent_vectors[1]);
442 return {{nodal_tangents_one, nodal_tangents_two}};
447 const std::vector<Real> & oned_xi1_pts)
const
449 std::vector<Point> xi1_pts(oned_xi1_pts.size());
450 for (
const auto qp : index_range(oned_xi1_pts))
451 xi1_pts[qp] = oned_xi1_pts[qp];
458 const std::vector<Point> & xi1_pts)
const
460 const auto mortar_dim =
_mesh.mesh_dimension() - 1;
461 const auto num_qps = xi1_pts.size();
463 std::vector<Point> normals(num_qps);
465 for (
const auto n : make_range(secondary_elem.n_nodes()))
466 for (
const auto qp : make_range(num_qps))
472 secondary_elem.default_order(),
474 cast_ref<
const TypeVector<Real> &>(xi1_pts[qp]));
475 normals[qp] += phi * nodal_normals[n];
479 for (
auto & normal : normals)
490 dof_id_type local_id_index = 0;
491 std::size_t node_unique_id_offset = 0;
499 const auto primary_bnd_id = pr.first;
500 const auto secondary_bnd_id = pr.second;
501 const auto num_primary_nodes =
502 std::distance(
_mesh.bid_nodes_begin(primary_bnd_id),
_mesh.bid_nodes_end(primary_bnd_id));
503 const auto num_secondary_nodes = std::distance(
_mesh.bid_nodes_begin(secondary_bnd_id),
504 _mesh.bid_nodes_end(secondary_bnd_id));
505 mooseAssert(num_primary_nodes,
506 "There are no primary nodes on boundary ID "
507 << primary_bnd_id <<
". Does that bondary ID even exist on the mesh?");
508 mooseAssert(num_secondary_nodes,
509 "There are no secondary nodes on boundary ID "
510 << secondary_bnd_id <<
". Does that bondary ID even exist on the mesh?");
512 node_unique_id_offset += num_primary_nodes + 2 * num_secondary_nodes;
516 for (MeshBase::const_element_iterator el =
_mesh.active_elements_begin(),
517 end_el =
_mesh.active_elements_end();
521 const Elem * secondary_elem = *el;
527 std::vector<Node *> new_nodes;
528 for (MooseIndex(secondary_elem->n_nodes()) n = 0; n < secondary_elem->n_nodes(); ++n)
531 secondary_elem->point(n), secondary_elem->node_id(n), secondary_elem->processor_id()));
532 Node *
const new_node = new_nodes.back();
533 new_node->set_unique_id(new_node->id() + node_unique_id_offset);
536 std::unique_ptr<Elem> new_elem;
537 if (secondary_elem->default_order() == SECOND)
538 new_elem = std::make_unique<Edge3>();
540 new_elem = std::make_unique<Edge2>();
542 new_elem->processor_id() = secondary_elem->processor_id();
543 new_elem->subdomain_id() = secondary_elem->subdomain_id();
544 new_elem->set_id(local_id_index++);
545 new_elem->set_unique_id(new_elem->id());
547 for (MooseIndex(new_elem->n_nodes()) n = 0; n < new_elem->n_nodes(); ++n)
548 new_elem->set_node(n, new_nodes[n]);
559 std::make_pair(secondary_elem->node_ptr(0), secondary_elem)),
561 std::make_pair(secondary_elem->node_ptr(1), secondary_elem));
563 bool new_container_node0_found =
565 new_container_node1_found =
568 const Elem * node0_primary_candidate =
nullptr;
569 const Elem * node1_primary_candidate =
nullptr;
571 if (new_container_node0_found)
573 const auto & xi2_primary_elem_pair = new_container_it0->second;
574 msinfo.
xi2_a = xi2_primary_elem_pair.first;
575 node0_primary_candidate = xi2_primary_elem_pair.second;
578 if (new_container_node1_found)
580 const auto & xi2_primary_elem_pair = new_container_it1->second;
581 msinfo.
xi2_b = xi2_primary_elem_pair.first;
582 node1_primary_candidate = xi2_primary_elem_pair.second;
589 if (node0_primary_candidate == node1_primary_candidate)
604 auto val = pr.second;
606 const Node * primary_node = std::get<1>(key);
607 Real xi1 = val.first;
608 const Elem * secondary_elem = val.second;
614 auto && order = secondary_elem->default_order();
618 for (MooseIndex(secondary_elem->n_nodes()) n = 0; n < secondary_elem->n_nodes(); ++n)
623 Elem * current_mortar_segment =
nullptr;
626 for (
const auto & mortar_segment_candidate : mortar_segment_set)
632 catch (std::out_of_range &)
634 mooseError(
"MortarSegmentInfo not found for the mortar segment candidate");
636 if (info->xi1_a <= xi1 && xi1 <= info->xi1_b)
638 current_mortar_segment = mortar_segment_candidate;
644 if (current_mortar_segment ==
nullptr)
645 mooseError(
"Unable to find appropriate mortar segment during linear search!");
652 if (info->xi1_a == xi1 || xi1 == info->xi1_b)
657 "new_id must be the same on all processes");
658 Node *
const new_node =
660 new_node->set_unique_id(new_id + node_unique_id_offset);
665 const Point normal =
getNormals(*secondary_elem, std::vector<Real>({xi1}))[0];
669 this->_nodes_to_primary_elem_map.end())
670 mooseError(
"We should already have built this primary node to elem pair!");
671 const std::vector<const Elem *> & primary_node_neighbors =
675 if (primary_node_neighbors.size() == 0 || primary_node_neighbors.size() > 2)
676 mooseError(
"We must have either 1 or 2 primary side nodal neighbors, but we had ",
677 primary_node_neighbors.size());
684 const Elem * left_primary_elem = primary_node_neighbors[0];
685 const Elem * right_primary_elem =
686 (primary_node_neighbors.size() == 2) ? primary_node_neighbors[1] :
nullptr;
692 std::array<Real, 2> secondary_node_cps;
693 std::vector<Real> primary_node_cps(primary_node_neighbors.size());
696 for (
unsigned int nid = 0; nid < 2; ++nid)
697 secondary_node_cps[nid] = normal.cross(secondary_elem->point(nid) - new_pt)(2);
699 for (MooseIndex(primary_node_neighbors) mnn = 0; mnn < primary_node_neighbors.size(); ++mnn)
701 const Elem * primary_neigh = primary_node_neighbors[mnn];
702 Point opposite = (primary_neigh->node_ptr(0) == primary_node) ? primary_neigh->point(1)
703 : primary_neigh->point(0);
704 Point cp = normal.cross(opposite - new_pt);
705 primary_node_cps[mnn] = cp(2);
709 bool orientation1_valid =
false, orientation2_valid =
false;
711 if (primary_node_neighbors.size() == 2)
714 orientation1_valid = (secondary_node_cps[0] * primary_node_cps[0] > 0.) &&
715 (secondary_node_cps[1] * primary_node_cps[1] > 0.);
717 orientation2_valid = (secondary_node_cps[0] * primary_node_cps[1] > 0.) &&
718 (secondary_node_cps[1] * primary_node_cps[0] > 0.);
720 else if (primary_node_neighbors.size() == 1)
723 orientation1_valid = (secondary_node_cps[0] * primary_node_cps[0] > 0.);
724 orientation2_valid = (secondary_node_cps[1] * primary_node_cps[0] > 0.);
727 mooseError(
"Invalid primary node neighbors size ", primary_node_neighbors.size());
733 if (orientation1_valid && orientation2_valid)
735 "AutomaticMortarGeneration: Both orientations cannot simultaneously be valid.");
741 if (!orientation1_valid && !orientation2_valid)
743 static const auto invalid_orientation_id =
745 "AutomaticMortarGeneration",
746 "Unable to determine valid secondary-primary orientation. Consequently we will "
747 "consider projection of the primary node invalid and not split the mortar segment. "
748 "This situation can indicate there are very oblique projections between primary "
749 "(mortar) and secondary (non-mortar) surfaces for a good problem set up. It can also "
750 "mean your time step is too large.",
757 std::unique_ptr<Elem> new_elem_left;
759 new_elem_left = std::make_unique<Edge3>();
761 new_elem_left = std::make_unique<Edge2>();
763 new_elem_left->processor_id() = current_mortar_segment->processor_id();
764 new_elem_left->subdomain_id() = current_mortar_segment->subdomain_id();
765 new_elem_left->set_id(local_id_index++);
766 new_elem_left->set_unique_id(new_elem_left->id());
767 new_elem_left->set_node(0, current_mortar_segment->node_ptr(0));
768 new_elem_left->set_node(1, new_node);
771 std::unique_ptr<Elem> new_elem_right;
773 new_elem_right = std::make_unique<Edge3>();
775 new_elem_right = std::make_unique<Edge2>();
777 new_elem_right->processor_id() = current_mortar_segment->processor_id();
778 new_elem_right->subdomain_id() = current_mortar_segment->subdomain_id();
779 new_elem_right->set_id(local_id_index++);
780 new_elem_right->set_unique_id(new_elem_right->id());
781 new_elem_right->set_node(0, new_node);
782 new_elem_right->set_node(1, current_mortar_segment->node_ptr(1));
787 Point left_interior_point(0);
788 Real left_interior_xi = (xi1 + info->xi1_a) / 2;
791 Real current_left_interior_eta =
792 (2. * left_interior_xi - info->xi1_a - info->xi1_b) / (info->xi1_b - info->xi1_a);
794 for (MooseIndex(current_mortar_segment->n_nodes()) n = 0;
795 n < current_mortar_segment->n_nodes();
798 current_mortar_segment->point(n);
802 "new_id must be the same on all processes");
804 left_interior_point, new_interior_left_id, new_elem_left->processor_id());
805 new_elem_left->set_node(2, new_interior_node_left);
806 new_interior_node_left->set_unique_id(new_interior_left_id + node_unique_id_offset);
809 Point right_interior_point(0);
810 Real right_interior_xi = (xi1 + info->xi1_b) / 2;
812 Real current_right_interior_eta =
813 (2. * right_interior_xi - info->xi1_a - info->xi1_b) / (info->xi1_b - info->xi1_a);
815 for (MooseIndex(current_mortar_segment->n_nodes()) n = 0;
816 n < current_mortar_segment->n_nodes();
819 current_mortar_segment->point(n);
823 "new_id must be the same on all processes");
825 right_interior_point, new_interior_id_right, new_elem_right->processor_id());
826 new_elem_right->set_node(2, new_interior_node_right);
827 new_interior_node_right->set_unique_id(new_interior_id_right + node_unique_id_offset);
831 if (orientation2_valid)
832 std::swap(left_primary_elem, right_primary_elem);
836 if (left_primary_elem)
837 left_xi2 = (primary_node == left_primary_elem->node_ptr(0)) ? -1 : +1;
838 if (right_primary_elem)
839 right_xi2 = (primary_node == right_primary_elem->node_ptr(0)) ? -1 : +1;
848 mooseError(
"MortarSegmentInfo not found for current_mortar_segment.");
864 new_msinfo_left.
xi1_b = xi1;
865 new_msinfo_left.
xi2_b = left_xi2;
873 mortar_segment_set.insert(msm_new_elem);
883 new_msinfo_right.
xi1_b = current_msinfo.
xi1_b;
884 new_msinfo_right.
xi2_b = current_msinfo.
xi2_b;
886 new_msinfo_right.
xi1_a = xi1;
887 new_msinfo_right.
xi2_a = right_xi2;
892 mortar_segment_set.insert(msm_new_elem);
900 mortar_segment_set.erase(current_mortar_segment);
916 Elem * primary_elem =
const_cast<Elem *
>(msinfo.
primary_elem);
917 if (primary_elem ==
nullptr || abs(msinfo.
xi2_a) > 1.0 + TOLERANCE ||
918 abs(msinfo.
xi2_b) > 1.0 + TOLERANCE)
923 "We should have found the element");
924 auto & msm_set = it->second;
925 msm_set.erase(msm_elem);
948 std::unordered_set<Node *> msm_connected_nodes;
953 for (
auto & n : element->node_ref_range())
954 msm_connected_nodes.insert(&n);
957 if (!msm_connected_nodes.count(node))
966 "All mortar segment elements should have valid "
986 mortar_segment_mesh_writer.set_hdf5_writing(
false);
988 std::array<std::string, 3> file_pieces = {
991 "mortar_segment_mesh.e"};
992 mortar_segment_mesh_writer.write(MooseUtils::join(file_pieces,
"_"));
998 const bool use_reference_interpolation =
1013 dof_id_type local_secondary_sub_elems = 0, visible_primary_sub_elems = 0;
1016 for (
const auto *
const el :
1017 _mesh.active_local_subdomain_elements_ptr_range(secondary_sub_id))
1018 local_secondary_sub_elems += el->n_sub_elem();
1019 for (
const auto *
const el :
_mesh.active_subdomain_elements_ptr_range(primary_sub_id))
1020 visible_primary_sub_elems += el->n_sub_elem();
1022 const dof_id_type per_rank_bound = local_secondary_sub_elems * visible_primary_sub_elems * 9;
1023 std::vector<dof_id_type> per_rank_bounds;
1024 _mesh.comm().allgather(per_rank_bound, per_rank_bounds);
1025 dof_id_type start = 0;
1026 for (
const auto r : make_range(
_mesh.processor_id()))
1027 start += per_rank_bounds[r];
1034 dof_id_type next_elem_id = next_node_id;
1039 const auto primary_subd_id = pr.first;
1040 const auto secondary_subd_id = pr.second;
1045 3, mesh_adaptor, nanoflann::KDTreeSingleIndexAdaptorParams(10));
1048 kd_tree.buildIndex();
1053 auto get_sub_elem_geometric_normal = [](
const std::vector<Point> & nodes)
1057 if (nodes.size() == 3)
1059 dxdxi = nodes[1] - nodes[0];
1060 dxdeta = nodes[2] - nodes[0];
1062 else if (nodes.size() == 4)
1066 dxdxi = 0.25 * (nodes[1] + nodes[2] - nodes[0] - nodes[3]);
1067 dxdeta = 0.25 * (nodes[2] + nodes[3] - nodes[0] - nodes[1]);
1070 mooseError(
"GEOMETRIC_NORMAL 3D mortar subpatch plane construction only supports "
1071 "triangular and quadrilateral subpatches, but received ",
1075 Point geometric_normal = dxdxi.cross(dxdeta);
1076 const auto normal_norm = geometric_normal.norm();
1079 if (normal_norm <= TOLERANCE * dxdxi.norm() * dxdeta.norm())
1080 mooseError(
"GEOMETRIC_NORMAL 3D mortar subpatch plane construction encountered a "
1081 "degenerate subpatch.");
1083 geometric_normal /= normal_norm;
1084 return geometric_normal;
1090 for (MeshBase::const_element_iterator el =
_mesh.active_local_elements_begin(),
1091 end_el =
_mesh.active_local_elements_end();
1095 const Elem * secondary_side_elem = *el;
1097 const Real secondary_volume = secondary_side_elem->volume();
1100 if (secondary_side_elem->subdomain_id() != secondary_subd_id)
1103 auto [secondary_elem_to_msm_map_it, insertion_happened] =
1105 std::set<Elem *, CompareDofObjectsByID>{});
1106 libmesh_ignore(insertion_happened);
1107 auto & secondary_to_msm_element_set = secondary_elem_to_msm_map_it->second;
1109 std::vector<std::unique_ptr<MortarSegmentHelper>> mortar_segment_helper(
1110 secondary_side_elem->n_sub_elem());
1123 for (
auto sel : make_range(secondary_side_elem->n_sub_elem()))
1126 const auto sub_elem_nodes =
1132 std::vector<Point> nodes(sub_elem_nodes.size());
1135 for (
auto iv : make_range(sub_elem_nodes.size()))
1137 const auto n = sub_elem_nodes[iv];
1138 nodes[iv] = secondary_side_elem->point(n);
1139 center += secondary_side_elem->point(n);
1140 normal += nodal_normals[n];
1142 center /= sub_elem_nodes.size();
1143 normal = normal.unit();
1147 const Point averaged_normal = normal;
1148 normal = get_sub_elem_geometric_normal(nodes);
1149 if (normal * averaged_normal < 0)
1153 if (use_reference_interpolation)
1155 std::vector<Point> sub_elem_reference_points;
1156 sub_elem_reference_points.reserve(sub_elem_nodes.size());
1157 for (
const auto node_index : sub_elem_nodes)
1158 sub_elem_reference_points.push_back(secondary_side_elem->master_point(node_index));
1160 mortar_segment_helper[sel] =
1161 std::make_unique<MortarSegmentHelper>(std::move(nodes),
1162 std::move(sub_elem_reference_points),
1169 mortar_segment_helper[sel] = std::make_unique<MortarSegmentHelper>(
1181 std::array<Real, 3> query_pt;
1183 switch (secondary_side_elem->type())
1187 center_point = mortar_segment_helper[0]->center();
1188 query_pt = {{center_point(0), center_point(1), center_point(2)}};
1192 center_point = mortar_segment_helper[1]->center();
1193 query_pt = {{center_point(0), center_point(1), center_point(2)}};
1196 center_point = mortar_segment_helper[4]->center();
1197 query_pt = {{center_point(0), center_point(1), center_point(2)}};
1200 center_point = secondary_side_elem->point(8);
1201 query_pt = {{center_point(0), center_point(1), center_point(2)}};
1205 "Face element type: ", secondary_side_elem->type(),
"not supported for 3D mortar");
1211 const std::size_t num_results = 3;
1214 std::vector<size_t> ret_index(num_results);
1215 std::vector<Real> out_dist_sqr(num_results);
1216 nanoflann::KNNResultSet<Real> result_set(num_results);
1217 result_set.init(&ret_index[0], &out_dist_sqr[0]);
1221 std::set<const Elem *, CompareDofObjectsByID> processed_primary_elems;
1225 bool primary_elem_found =
false;
1226 std::set<const Elem *, CompareDofObjectsByID> primary_elem_candidates;
1227 const bool use_geometric_subpatch_normals =
1231 const Real minimum_subpatch_normal_alignment =
1236 for (
auto r : make_range(result_set.size()))
1239 mooseAssert(abs((
_mesh.point(ret_index[r]) - center_point).norm_sq() - out_dist_sqr[r]) <=
1241 "Lower-dimensional element squared distance verification failed.");
1244 std::vector<const Elem *> & node_elems =
1248 for (
auto elem : node_elems)
1249 primary_elem_candidates.insert(elem);
1259 while (!primary_elem_candidates.empty())
1261 const Elem * primary_elem_candidate = *primary_elem_candidates.begin();
1264 if (processed_primary_elems.count(primary_elem_candidate))
1266 primary_elem_candidates.erase(primary_elem_candidate);
1271 std::vector<Point> nodal_points;
1274 std::vector<std::vector<unsigned int>> elem_to_node_map;
1277 std::vector<std::pair<unsigned int, unsigned int>> sub_elem_map;
1278 std::vector<std::array<Point, 3>> elem_to_secondary_reference_points;
1279 std::vector<std::array<Point, 3>> elem_to_primary_reference_points;
1285 for (
auto p_el : make_range(primary_elem_candidate->n_sub_elem()))
1288 const auto sub_elem_nodes =
1292 std::vector<Point> primary_sub_elem(sub_elem_nodes.size());
1293 for (
auto iv : make_range(sub_elem_nodes.size()))
1295 const auto n = sub_elem_nodes[iv];
1296 primary_sub_elem[iv] = primary_elem_candidate->point(n);
1298 Point primary_sub_elem_normal;
1299 if (use_geometric_subpatch_normals)
1300 primary_sub_elem_normal = get_sub_elem_geometric_normal(primary_sub_elem);
1302 std::vector<Point> sub_elem_reference_points;
1303 if (use_reference_interpolation)
1305 sub_elem_reference_points.reserve(sub_elem_nodes.size());
1306 for (
const auto node_index : sub_elem_nodes)
1307 sub_elem_reference_points.push_back(primary_elem_candidate->master_point(node_index));
1311 for (
auto s_el : make_range(secondary_side_elem->n_sub_elem()))
1316 if (use_geometric_subpatch_normals &&
1317 std::abs(primary_sub_elem_normal * mortar_segment_helper[s_el]->normal()) <
1318 minimum_subpatch_normal_alignment)
1328 const auto segments_before_helper = elem_to_node_map.size();
1329 if (use_reference_interpolation)
1330 mortar_segment_helper[s_el]->getMortarSegments(primary_sub_elem,
1331 sub_elem_reference_points,
1334 elem_to_secondary_reference_points,
1335 elem_to_primary_reference_points,
1336 TOLERANCE * secondary_volume);
1338 mortar_segment_helper[s_el]->getMortarSegments(
1339 primary_sub_elem, nodal_points, elem_to_node_map);
1342 for (
auto i = segments_before_helper; i < elem_to_node_map.size(); ++i)
1343 sub_elem_map.push_back(std::make_pair(s_el, p_el));
1348 processed_primary_elems.insert(primary_elem_candidate);
1349 primary_elem_candidates.erase(primary_elem_candidate);
1352 if (!elem_to_node_map.empty())
1354 if (sub_elem_map.size() != elem_to_node_map.size())
1355 mooseError(
"The mortar segment subpatch map is not aligned with the mortar segment "
1356 "connectivity map.");
1357 if (use_reference_interpolation &&
1358 (elem_to_secondary_reference_points.size() != elem_to_node_map.size() ||
1359 elem_to_primary_reference_points.size() != elem_to_node_map.size()))
1360 mooseError(
"The mortar segment reference-point maps are not aligned with the mortar "
1361 "segment connectivity map.");
1365 bool seed_breadth_first_search =
false;
1366 std::vector<bool> retained_mortar_segments(elem_to_node_map.size(),
false);
1367 for (
const auto el : index_range(elem_to_node_map))
1369 const auto & node_map = elem_to_node_map[el];
1370 if (node_map.size() != 3)
1372 "Active mortar segments only supports TRI elements, 3 nodes expected but: ",
1376 const Point e1 = nodal_points[node_map[1]] - nodal_points[node_map[0]];
1377 const Point e2 = nodal_points[node_map[2]] - nodal_points[node_map[0]];
1378 retained_mortar_segments[el] =
1379 0.5 * e1.cross(e2).norm() / secondary_volume >= TOLERANCE;
1380 seed_breadth_first_search = seed_breadth_first_search || retained_mortar_segments[el];
1383 if (seed_breadth_first_search)
1387 if (!primary_elem_found)
1389 primary_elem_found =
true;
1390 primary_elem_candidates.clear();
1394 for (
auto neighbor : primary_elem_candidate->neighbor_ptr_range())
1397 if (neighbor ==
nullptr || neighbor->subdomain_id() != primary_subd_id)
1400 if (processed_primary_elems.count(neighbor))
1403 primary_elem_candidates.insert(neighbor);
1410 std::vector<Node *> new_nodes;
1413 std::vector<bool> retained_nodes(nodal_points.size(),
false);
1414 for (
const auto el : index_range(elem_to_node_map))
1415 if (retained_mortar_segments[el])
1416 for (
const auto node : elem_to_node_map[el])
1417 retained_nodes[node] =
true;
1419 new_nodes.resize(nodal_points.size(),
nullptr);
1420 for (
const auto node : index_range(nodal_points))
1421 if (retained_nodes[node])
1423 nodal_points[node], next_node_id++, secondary_side_elem->processor_id());
1426 for (
auto el : index_range(elem_to_node_map))
1428 if (!retained_mortar_segments[el])
1431 std::unique_ptr<Elem> new_elem;
1432 if (elem_to_node_map[el].size() == 3)
1433 new_elem = std::make_unique<Tri3>();
1435 mooseError(
"Active mortar segments only supports TRI elements, 3 nodes expected "
1437 elem_to_node_map[el].size(),
1440 new_elem->processor_id() = secondary_side_elem->processor_id();
1441 new_elem->subdomain_id() = secondary_side_elem->subdomain_id();
1442 new_elem->set_id(next_elem_id++);
1445 for (
auto i : index_range(elem_to_node_map[el]))
1446 new_elem->set_node(i, new_nodes[elem_to_node_map[el][i]]);
1449 if (new_elem->volume() / secondary_volume < TOLERANCE)
1455 msm_new_elem->set_extra_integer(secondary_sub_elem, sub_elem_map[el].first);
1456 msm_new_elem->set_extra_integer(primary_sub_elem, sub_elem_map[el].second);
1467 if (use_reference_interpolation)
1470 elem_to_primary_reference_points[el]};
1475 secondary_to_msm_element_set.insert(msm_new_elem);
1486 if (use_geometric_subpatch_normals)
1490 if (secondary_to_msm_element_set.empty())
1492 mooseWarning(
"Some secondary elements on mortar interface were unable to identify"
1493 " a corresponding primary element; this may be expected depending on"
1494 " problem geometry but may indicate a failure of the element search"
1498 for (
auto sel : make_range(secondary_side_elem->n_sub_elem()))
1499 if (mortar_segment_helper[sel]->remainder() == 1.0)
1501 mooseWarning(
"Some secondary elements on mortar interface were unable to identify"
1502 " a corresponding primary element; this may be expected depending on"
1503 " problem geometry but may indicate a failure of the element search"
1506 if (secondary_to_msm_element_set.empty())
1511 mooseAssert(!use_reference_interpolation ||
1513 "Mortar segment info and reference-point maps must remain aligned.");
1527 if (msm_el->type() != TRI3)
1528 msm_el->subdomain_id()++;
1534 if (msm_el->type() != TRI3)
1535 msm_el->subdomain_id()--;
1550 std::unordered_map<processor_id_type, std::vector<std::pair<dof_id_type, dof_id_type>>>
1561 const Elem * secondary_elem = pr.second.secondary_elem;
1562 const Elem * primary_elem = pr.second.primary_elem;
1567 std::set<processor_id_type> secondary_face_coupling_processors{
1568 secondary_elem->processor_id(),
1569 secondary_elem->interior_parent()->processor_id(),
1570 primary_elem->interior_parent()->processor_id()};
1571 for (
const auto n : secondary_elem->node_index_range())
1572 secondary_face_coupling_processors.insert(secondary_elem->node_ptr(n)->processor_id());
1575 for (
const auto processor : secondary_face_coupling_processors)
1576 coupling_info[processor].emplace_back(secondary_elem->id(),
1577 secondary_elem->interior_parent()->id());
1580 for (
const auto processor : secondary_face_coupling_processors)
1581 coupling_info[processor].emplace_back(secondary_elem->id(),
1582 primary_elem->interior_parent()->id());
1585 for (
const auto processor : secondary_face_coupling_processors)
1586 coupling_info[processor].emplace_back(secondary_elem->id(), primary_elem->id());
1589 coupling_info[secondary_elem->interior_parent()->processor_id()].emplace_back(
1590 secondary_elem->interior_parent()->id(), secondary_elem->id());
1593 coupling_info[secondary_elem->interior_parent()->processor_id()].emplace_back(
1594 secondary_elem->interior_parent()->id(), primary_elem->interior_parent()->id());
1597 coupling_info[primary_elem->interior_parent()->processor_id()].emplace_back(
1598 primary_elem->interior_parent()->id(), secondary_elem->id());
1601 coupling_info[primary_elem->interior_parent()->processor_id()].emplace_back(
1602 primary_elem->interior_parent()->id(), secondary_elem->interior_parent()->id());
1606 for (
auto & [_, couplings] : coupling_info)
1608 std::sort(couplings.begin(), couplings.end());
1609 couplings.erase(std::unique(couplings.begin(), couplings.end()), couplings.end());
1613 auto action_functor =
1614 [
this](processor_id_type,
1615 const std::vector<std::pair<dof_id_type, dof_id_type>> & coupling_info)
1617 for (
auto [i, j] : coupling_info)
1636 const auto is_secondary = [
this](
const Elem *
const elem)
1638 const auto pid =
_mesh.processor_id();
1639 std::unordered_set<const Elem *> secondary_elems_read;
1641 for (
const Elem *
const secondary_elem :
1642 as_range(
_mesh.active_subdomain_elements_begin(secondary_subdomain_id),
1643 _mesh.active_subdomain_elements_end(secondary_subdomain_id)))
1644 if (secondary_elem->processor_id() == pid ||
1645 secondary_elem->interior_parent()->processor_id() == pid)
1646 secondary_elems_read.insert(secondary_elem);
1648 if (
const Elem *
const elem =
_mesh.query_elem_ptr(elem_id);
1649 elem && elem->processor_id() == pid)
1650 for (
const auto coupled_elem_id : coupled_elem_ids)
1651 if (
const Elem *
const coupled_elem =
_mesh.query_elem_ptr(coupled_elem_id);
1652 coupled_elem && is_secondary(coupled_elem))
1653 secondary_elems_read.insert(coupled_elem);
1655 std::unordered_set<const Elem *> secondary_elems_queried;
1656 std::unordered_map<processor_id_type, std::vector<dof_id_type>> secondary_elems_to_query;
1657 for (
const Elem *
const secondary_elem : secondary_elems_read)
1659 std::set<const Elem *> point_neighbors;
1660 secondary_elem->find_point_neighbors(point_neighbors);
1661 point_neighbors.insert(secondary_elem);
1662 for (
const Elem *
const neigh : point_neighbors)
1663 if (neigh->active() && is_secondary(neigh) && neigh->processor_id() != pid &&
1664 secondary_elems_queried.insert(neigh).second)
1665 secondary_elems_to_query[neigh->processor_id()].push_back(neigh->id());
1668 auto gather_functor = [
this](processor_id_type,
1669 const std::vector<dof_id_type> & secondary_elem_ids,
1670 std::vector<std::vector<dof_id_type>> & coupled_elem_ids)
1672 coupled_elem_ids.resize(secondary_elem_ids.size());
1673 for (
const auto i : index_range(secondary_elem_ids))
1676 coupled_elem_ids[i].assign(it->second.begin(), it->second.end());
1678 auto act_on_data_functor = [
this](processor_id_type,
1679 const std::vector<dof_id_type> & secondary_elem_ids,
1680 const std::vector<std::vector<dof_id_type>> & coupled_elem_ids)
1682 for (
const auto i : index_range(secondary_elem_ids))
1684 coupled_elem_ids[i].end());
1686 std::vector<dof_id_type> * example =
nullptr;
1688 _mesh.comm(), secondary_elems_to_query, gather_functor, act_on_data_functor, example);
1691std::vector<AutomaticMortarGeneration::MsmSubdomainStats>
1694 std::vector<MsmSubdomainStats> result;
1698 std::unordered_map<dof_id_type, Real> primary_elems_to_volume;
1702 for (
const auto *
const secondary_el :
1703 _mesh.active_local_subdomain_element_ptr_range(secondary_subd_id))
1705 secondary.push_back(secondary_el->volume());
1710 for (
const auto *
const msm_elem : it->second)
1712 msm.push_back(msm_elem->volume());
1716 if (msm_info.primary_elem)
1718 if (msm_info.primary_elem->subdomain_id() != primary_subd_id)
1719 mooseError(
"Unhandled primary-secondary pairing when computing mortar segment "
1720 "statistics. This could happen if you have the same secondary "
1721 "lower-dimensional subdomain ID paired with multiple lower-dimensional "
1722 "primary subdomain IDs. Contact a MOOSE developer for help.");
1723 if (
const auto [it, inserted] =
1724 primary_elems_to_volume.emplace(msm_info.primary_elem->id(), Real{});
1726 it->second = msm_info.primary_elem->volume();
1729 MooseUtils::absoluteFuzzyEqual(it->second, msm_info.primary_elem->volume()),
1730 "Volumes should be consistent");
1735 _mesh.comm().set_union(primary_elems_to_volume);
1736 _mesh.comm().allgather(cast_ref<std::vector<Real> &>(secondary));
1737 _mesh.comm().allgather(cast_ref<std::vector<Real> &>(msm));
1738 primary.reserve(primary_elems_to_volume.size());
1739 for (
const auto [_, volume] : primary_elems_to_volume)
1740 primary.push_back(volume);
1744 const auto max_volume = [](
const auto & volumes)
1745 {
return volumes.empty() ? Real(0) : volumes.maximum(); };
1746 const auto min_volume = [](
const auto & volumes)
1747 {
return volumes.empty() ? Real(0) : volumes.minimum(); };
1764 result.push_back(stats);
1769 primary_elems_to_volume.clear();
1780 if (
_mesh.processor_id() != 0)
1783 Moose::out <<
"Mortar Interface Statistics:" << std::endl;
1784 for (
const auto & stats : all_stats)
1786 std::vector<std::string> col_names = {
"mesh",
"n_elems",
"max",
"min",
"median"};
1787 std::vector<std::string> subds = {
"secondary_lower",
"primary_lower",
"mortar_segment"};
1788 std::vector<size_t> n_elems = {
1789 stats.secondary_lower_n_elems, stats.primary_lower_n_elems, stats.msm_n_elems};
1790 std::vector<Real> maxs = {
1791 stats.secondary_lower_max_volume, stats.primary_lower_max_volume, stats.msm_max_volume};
1792 std::vector<Real> mins = {
1793 stats.secondary_lower_min_volume, stats.primary_lower_min_volume, stats.msm_min_volume};
1794 std::vector<Real> medians = {stats.secondary_lower_median_volume,
1795 stats.primary_lower_median_volume,
1796 stats.msm_median_volume};
1800 for (
auto i : index_range(subds))
1803 table.
addData<std::string>(col_names[0], subds[i]);
1804 table.
addData<
size_t>(col_names[1], n_elems[i]);
1805 table.
addData<Real>(col_names[2], maxs[i]);
1806 table.
addData<Real>(col_names[3], mins[i]);
1807 table.
addData<Real>(col_names[4], medians[i]);
1810 Moose::out <<
"secondary subdomain: " << stats.secondary_subd_id
1811 <<
" \tprimary subdomain: " << stats.primary_subd_id << std::endl;
1828 const Real tol = (
dim() == 3) ? 0.1 : TOLERANCE;
1831 std::unordered_set<dof_id_type> inactive_node_ids;
1833 std::unordered_map<const Elem *, Real> active_volume{};
1836 for (
const auto el :
_mesh.active_subdomain_elements_ptr_range(pr.second))
1837 active_volume[el] = 0.;
1845 active_volume[secondary_elem] += msm_elem->volume();
1851 for (
const auto el :
_mesh.active_local_subdomain_elements_ptr_range(pr.second))
1853 if (abs(active_volume[el] / el->volume() - 1.0) > tol)
1856 for (
auto n : make_range(el->n_nodes()))
1857 inactive_node_ids.insert(el->node_id(n));
1863 std::unordered_map<processor_id_type, std::vector<dof_id_type>> proc_to_inactive_nodes;
1864 for (
const auto node_id : inactive_node_ids)
1865 proc_to_inactive_nodes[
_mesh.node_ptr(node_id)->processor_id()].push_back(node_id);
1868 auto action_functor = [
this](
const processor_id_type,
const std::vector<dof_id_type> & sent_data)
1870 for (
const auto node_id : sent_data)
1891 std::unordered_set<dof_id_type> active_local_nodes;
1899 for (
auto n : make_range(secondary_elem->n_nodes()))
1900 active_local_nodes.insert(secondary_elem->node_id(n));
1904 std::unordered_set<dof_id_type> local_nodes;
1906 for (
const auto el :
_mesh.active_local_subdomain_elements_ptr_range(
1908 for (
const auto n : make_range(el->n_nodes()))
1909 local_nodes.insert(el->node_id(n));
1912 std::unordered_map<processor_id_type, std::vector<std::pair<dof_id_type, unsigned char>>>
1914 for (
const auto node_id : local_nodes)
1915 proc_to_nodes[
_mesh.node_ptr(node_id)->processor_id()].emplace_back(
1916 node_id, active_local_nodes.count(node_id));
1918 std::unordered_set<dof_id_type> candidate_nodes, active_nodes;
1919 auto action_functor = [&candidate_nodes, &active_nodes](
1920 const processor_id_type,
1921 const std::vector<std::pair<dof_id_type, unsigned char>> & sent_data)
1923 for (
const auto & [node_id, active] : sent_data)
1925 candidate_nodes.insert(node_id);
1927 active_nodes.insert(node_id);
1934 for (
const auto node_id : candidate_nodes)
1935 if (!active_nodes.count(node_id))
1944 std::unordered_set<const Elem *> active_local_elems;
1950 const Real tol = (
dim() == 3) ? 0.1 : TOLERANCE;
1952 std::unordered_map<const Elem *, Real> active_volume;
1961 active_volume[secondary_elem] += msm_elem->volume();
1972 if (abs(active_volume[secondary_elem] / secondary_elem->volume() - 1.0) > tol)
1976 active_local_elems.insert(secondary_elem);
1982 for (
const auto el :
_mesh.active_local_subdomain_elements_ptr_range(
1984 if (active_local_elems.find(el) == active_local_elems.end())
1992 const auto dim =
_mesh.mesh_dimension();
1994 mooseAssert(
dim == 2 ||
dim == 3,
1995 "AutomaticMortarGeneration::computeNodalGeometry() is only valid for "
1996 "mortar constraints on 2D or 3D meshes.");
2005 std::map<dof_id_type, std::vector<std::pair<Point, Real>>> node_to_normals_map;
2013 for (MeshBase::const_element_iterator el =
_mesh.active_elements_begin(),
2014 end_el =
_mesh.active_elements_end();
2018 const Elem * secondary_elem = *el;
2026 FEType nnx_fe_type(secondary_elem->default_order(), LAGRANGE);
2027 std::unique_ptr<FEBase> nnx_fe_face(FEBase::build(
dim, nnx_fe_type));
2028 nnx_fe_face->attach_quadrature_rule(&qface);
2029 const auto & face_normals = nnx_fe_face->get_normals();
2030 const auto & face_points = nnx_fe_face->get_xyz();
2032 const auto & JxW = nnx_fe_face->get_JxW();
2036 const Elem * interior_parent = secondary_elem->interior_parent();
2037 mooseAssert(interior_parent,
2038 "No interior parent exists for element "
2039 << secondary_elem->id()
2040 <<
". There may be a problem with your sideset set-up.");
2048 auto s = interior_parent->which_side_am_i(secondary_elem);
2051 nnx_fe_face->reinit(interior_parent, s);
2056 const auto qpoint_to_secondary_node =
2059 mooseAssert(face_normals.size() == face_points.size() && JxW.size() == face_points.size(),
2060 "Face nodal geometry vectors must have the same size.");
2062 for (
const auto qp : make_range(face_points.size()))
2064 const auto n = qpoint_to_secondary_node[qp];
2065 auto & normals_and_weights_vec = node_to_normals_map[secondary_elem->node_id(n)];
2066 normals_and_weights_vec.push_back(std::make_pair(sign * face_normals[qp], JxW[qp]));
2071 for (
const auto & pr : node_to_normals_map)
2074 const auto & node_id = pr.first;
2075 const auto & normals_and_weights_vec = pr.second;
2078 for (
const auto & norm_and_weight : normals_and_weights_vec)
2079 nodal_normal += norm_and_weight.first * norm_and_weight.second;
2080 nodal_normal = nodal_normal.unit();
2090 const std::function<
ADPoint(
const Node &)> & coordinate,
2091 std::unordered_map<const Node *, ADRealVectorValue> & nodal_normals)
const
2093 const auto dim =
_mesh.mesh_dimension();
2094 mooseAssert(
dim == 2 ||
dim == 3,
"AD nodal normals are only valid for 2D or 3D mortar.");
2100 std::unordered_map<const Node *, ADRealVectorValue> weighted_area_vectors;
2101 std::unordered_map<const Node *, Real> weighted_area_magnitudes;
2104 std::map<Order, std::unique_ptr<FEBase>> fe_faces;
2108 for (
const Elem *
const secondary_elem :
2109 as_range(
_mesh.active_subdomain_elements_begin(secondary_subdomain_id),
2110 _mesh.active_subdomain_elements_end(secondary_subdomain_id)))
2112 const Elem *
const interior_parent = secondary_elem->interior_parent();
2113 mooseAssert(interior_parent,
2114 "No interior parent exists for element "
2115 << secondary_elem->id()
2116 <<
". There may be a problem with your sideset set-up.");
2118 const Real element_size = secondary_elem->hmax();
2119 if (element_size <= 0)
2120 mooseError(
"Cannot compute an AD nodal normal for secondary mortar element ",
2121 secondary_elem->id(),
2122 " because it has a non-positive characteristic length.");
2124 const auto side = interior_parent->which_side_am_i(secondary_elem);
2125 auto & fe_face = fe_faces[secondary_elem->default_order()];
2128 fe_face = FEBase::build(
dim, FEType(secondary_elem->default_order(), LAGRANGE));
2129 fe_face->attach_quadrature_rule(&qface);
2132 const auto & face_normals = fe_face->get_normals();
2133 const auto & face_points = fe_face->get_xyz();
2134 const auto & map_dpsidxi = fe_face->get_fe_map().get_dpsidxi();
2135 const auto *
const map_dpsideta =
dim == 3 ? &fe_face->get_fe_map().get_dpsideta() :
nullptr;
2137 fe_face->reinit(interior_parent, side);
2139 const auto qpoint_to_secondary_node =
2142 mooseAssert(face_normals.size() == face_points.size() &&
2143 qweights.size() == face_points.size(),
2144 "Face nodal geometry vectors and quadrature weights must have the same size.");
2147 auto parent_side_elem = interior_parent->build_side_ptr(side);
2148 const unsigned int n_mapping_shape_functions =
2150 parent_side_elem->default_order())
2152 parent_side_elem->default_order());
2153 if (map_dpsidxi.size() != n_mapping_shape_functions ||
2154 (map_dpsideta && map_dpsideta->size() != n_mapping_shape_functions))
2155 mooseError(
"The parent-side geometric map for secondary mortar element ",
2156 secondary_elem->id(),
2158 libMesh::Utility::enum_to_string<ElemType>(secondary_elem->type()),
2159 " does not have one mapping shape function per element node.");
2160 mooseAssert(n_mapping_shape_functions <= parent_side_elem->
n_nodes(),
2161 "The mapping basis must not index past the side element's nodes.");
2163 std::vector<ADPoint> side_points;
2164 side_points.reserve(n_mapping_shape_functions);
2165 for (
const auto side_node_index : make_range(n_mapping_shape_functions))
2166 side_points.push_back(coordinate(parent_side_elem->node_ref(side_node_index)));
2168 for (
const auto qp : index_range(face_points))
2170 const auto secondary_node_index = qpoint_to_secondary_node[qp];
2171 const Node *
const secondary_node = secondary_elem->node_ptr(secondary_node_index);
2175 for (
const auto side_node_index : make_range(n_mapping_shape_functions))
2177 tangent_xi.
add_scaled(side_points[side_node_index], map_dpsidxi[side_node_index][qp]);
2179 tangent_eta.
add_scaled(side_points[side_node_index],
2180 (*map_dpsideta)[side_node_index][qp]);
2184 : tangent_xi.
cross(tangent_eta);
2186 const Real degeneracy_tolerance =
2187 dim == 2 ? TOLERANCE * element_size : TOLERANCE * element_size * element_size;
2188 if (area <= degeneracy_tolerance)
2189 mooseError(
"Cannot compute an AD nodal normal on degenerate secondary mortar element ",
2190 secondary_elem->id(),
2196 const Real orientation =
2199 weighted_area_vectors[secondary_node] += sign * orientation * qweights[qp] * area_vector;
2200 weighted_area_magnitudes[secondary_node] += std::abs(qweights[qp]) * area;
2204 nodal_normals.clear();
2205 nodal_normals.reserve(weighted_area_vectors.size());
2206 for (
auto & [secondary_node, weighted_area_vector] : weighted_area_vectors)
2209 const Real weighted_area_magnitude = libmesh_map_find(weighted_area_magnitudes, secondary_node);
2210 if (weighted_area_vector_norm <= TOLERANCE * weighted_area_magnitude)
2211 mooseError(
"Cannot compute a normalized AD nodal normal for secondary node ",
2212 secondary_node->id(),
2213 " because its incident face contributions cancel to a near-zero weighted normal.");
2215 auto nodal_normal = weighted_area_vector.unit();
2220 "The stored and AD secondary nodal normals must use the same geometry state.");
2223 for (
const auto component : make_range(
Moose::dim))
2224 nodal_normal(component).value() = stored_normal(component);
2225 nodal_normals.emplace(secondary_node, std::move(nodal_normal));
2242 const Node & secondary_node,
2243 const Node & primary_node,
2244 const std::vector<const Elem *> * secondary_node_neighbors,
2245 const std::vector<const Elem *> * primary_node_neighbors,
2246 const VectorValue<Real> & nodal_normal,
2247 const Elem & candidate_element,
2248 std::set<const Elem *> & rejected_elem_candidates)
2250 if (!secondary_node_neighbors)
2252 if (!primary_node_neighbors)
2255 std::vector<bool> primary_elems_mapped(primary_node_neighbors->size(),
false);
2283 std::array<Real, 2> secondary_node_neighbor_cps, primary_node_neighbor_cps;
2285 for (
const auto nn : index_range(*secondary_node_neighbors))
2287 const Elem *
const secondary_neigh = (*secondary_node_neighbors)[nn];
2288 const Point opposite = (secondary_neigh->node_ptr(0) == &secondary_node)
2289 ? secondary_neigh->point(1)
2290 : secondary_neigh->point(0);
2291 const Point cp = nodal_normal.cross(opposite - secondary_node);
2292 secondary_node_neighbor_cps[nn] = cp(2);
2295 for (
const auto nn : index_range(*primary_node_neighbors))
2297 const Elem *
const primary_neigh = (*primary_node_neighbors)[nn];
2298 const Point opposite = (primary_neigh->node_ptr(0) == &primary_node) ? primary_neigh->point(1)
2299 : primary_neigh->point(0);
2300 const Point cp = nodal_normal.cross(opposite - primary_node);
2301 primary_node_neighbor_cps[nn] = cp(2);
2305 bool found_match =
false;
2306 for (
const auto snn : index_range(*secondary_node_neighbors))
2307 for (
const auto mnn : index_range(*primary_node_neighbors))
2308 if (secondary_node_neighbor_cps[snn] * primary_node_neighbor_cps[mnn] > 0)
2311 if (primary_elems_mapped[mnn])
2313 primary_elems_mapped[mnn] =
true;
2317 const Real xi2 = (&primary_node == (*primary_node_neighbors)[mnn]->node_ptr(0)) ? -1 : +1;
2318 const auto secondary_key =
2319 std::make_pair(&secondary_node, (*secondary_node_neighbors)[snn]);
2320 const auto primary_val = std::make_pair(xi2, (*primary_node_neighbors)[mnn]);
2325 (&secondary_node == (*secondary_node_neighbors)[snn]->node_ptr(0)) ? -1 : +1;
2327 const auto primary_key =
2328 std::make_tuple(primary_node.id(), &primary_node, (*primary_node_neighbors)[mnn]);
2329 const auto secondary_val = std::make_pair(xi1, (*secondary_node_neighbors)[snn]);
2337 rejected_elem_candidates.insert(&candidate_element);
2344 if (secondary_node_neighbors->size() == 1 && primary_node_neighbors->size() == 2)
2345 for (
const auto i : index_range(primary_elems_mapped))
2346 if (!primary_elems_mapped[i])
2349 std::make_tuple(primary_node.id(), &primary_node, (*primary_node_neighbors)[i]),
2350 std::make_pair(1,
nullptr));
2358 SubdomainID lower_dimensional_primary_subdomain_id,
2359 SubdomainID lower_dimensional_secondary_subdomain_id)
2366 3, mesh_adaptor, nanoflann::KDTreeSingleIndexAdaptorParams(10));
2369 kd_tree.buildIndex();
2371 for (MeshBase::const_element_iterator el =
_mesh.active_elements_begin(),
2372 end_el =
_mesh.active_elements_end();
2376 const Elem * secondary_side_elem = *el;
2379 if (secondary_side_elem->subdomain_id() != lower_dimensional_secondary_subdomain_id)
2386 for (MooseIndex(secondary_side_elem->n_vertices()) n = 0; n < secondary_side_elem->n_vertices();
2389 const Node * secondary_node = secondary_side_elem->node_ptr(n);
2393 const std::vector<const Elem *> & secondary_node_neighbors =
2398 bool is_mapped =
true;
2399 for (MooseIndex(secondary_node_neighbors) snn = 0; snn < secondary_node_neighbors.size();
2402 auto secondary_key = std::make_pair(secondary_node, secondary_node_neighbors[snn]);
2418 std::array<Real, 3> query_pt = {
2419 {(*secondary_node)(0), (*secondary_node)(1), (*secondary_node)(2)}};
2425 const std::size_t num_results = 3;
2428 std::vector<size_t> ret_index(num_results);
2429 std::vector<Real> out_dist_sqr(num_results);
2430 nanoflann::KNNResultSet<Real> result_set(num_results);
2431 result_set.init(&ret_index[0], &out_dist_sqr[0]);
2435 bool projection_succeeded =
false;
2439 std::set<const Elem *> rejected_primary_elem_candidates;
2445 for (MooseIndex(result_set) r = 0; r < result_set.size(); ++r)
2448 mooseAssert(abs((
_mesh.point(ret_index[r]) - *secondary_node).norm_sq() -
2449 out_dist_sqr[r]) <= TOLERANCE,
2450 "Lower-dimensional element squared distance verification failed.");
2454 std::vector<const Elem *> & primary_elem_candidates =
2458 for (MooseIndex(primary_elem_candidates) e = 0; e < primary_elem_candidates.size(); ++e)
2460 const Elem * primary_elem_candidate = primary_elem_candidates[e];
2463 if (rejected_primary_elem_candidates.count(primary_elem_candidate))
2467 const auto order = primary_elem_candidate->default_order();
2469 unsigned int current_iterate = 0, max_iterates = 10;
2474 VectorValue<DualNumber<Real>> x2(0);
2475 for (MooseIndex(primary_elem_candidate->n_nodes()) n = 0;
2476 n < primary_elem_candidate->n_nodes();
2480 const auto u = x2 - (*secondary_node);
2481 const auto F = u(0) * nodal_normal(1) - u(1) * nodal_normal(0);
2486 if (F.derivatives())
2488 Real dxi2 = -F.value() / F.derivatives();
2496 current_iterate = max_iterates;
2497 }
while (++current_iterate < max_iterates);
2499 Real xi2 = xi2_dn.value();
2512 if ((current_iterate < max_iterates) && (std::abs(xi2) <= 1. + 5 *
_xi_tolerance) &&
2513 (abs((primary_elem_candidate->point(0) - primary_elem_candidate->point(1)).unit() *
2523 const Node * primary_node = (xi2 < 0) ? primary_elem_candidate->node_ptr(0)
2524 : primary_elem_candidate->node_ptr(1);
2525 const bool created_mortar_segment =
2528 &secondary_node_neighbors,
2531 *primary_elem_candidate,
2532 rejected_primary_elem_candidates);
2534 if (!created_mortar_segment)
2540 for (MooseIndex(secondary_node_neighbors) nn = 0;
2541 nn < secondary_node_neighbors.size();
2544 const Elem * neigh = secondary_node_neighbors[nn];
2545 for (MooseIndex(neigh->n_vertices()) nid = 0; nid < neigh->n_vertices(); ++nid)
2547 const Node * neigh_node = neigh->node_ptr(nid);
2548 if (secondary_node == neigh_node)
2550 auto key = std::make_pair(neigh_node, neigh);
2551 auto val = std::make_pair(xi2, primary_elem_candidate);
2558 projection_succeeded =
true;
2563 rejected_primary_elem_candidates.insert(primary_elem_candidate);
2566 if (projection_succeeded)
2570 if (!projection_succeeded)
2574 _console <<
"Failed to find primary Elem into which secondary node "
2575 << cast_ref<const Point &>(*secondary_node) <<
", id '" << secondary_node->id()
2576 <<
"', projects onto\n"
2595 <<
" secondary nodes were successfully projected\n"
2612 SubdomainID lower_dimensional_primary_subdomain_id,
2613 SubdomainID lower_dimensional_secondary_subdomain_id)
2620 3, mesh_adaptor, nanoflann::KDTreeSingleIndexAdaptorParams(10));
2623 kd_tree.buildIndex();
2625 std::unordered_set<dof_id_type> primary_nodes_visited;
2627 for (
const auto & primary_side_elem :
_mesh.active_element_ptr_range())
2630 if (primary_side_elem->subdomain_id() != lower_dimensional_primary_subdomain_id)
2635 for (MooseIndex(primary_side_elem->n_vertices()) n = 0; n < primary_side_elem->n_vertices();
2639 const Node * primary_node = primary_side_elem->node_ptr(n);
2642 const std::vector<const Elem *> & primary_node_neighbors =
2650 std::make_tuple(primary_node->id(), primary_node, primary_node_neighbors[0]);
2651 if (!primary_nodes_visited.insert(primary_node->id()).second ||
2656 Real query_pt[3] = {(*primary_node)(0), (*primary_node)(1), (*primary_node)(2)};
2662 const size_t num_results = 3;
2665 std::vector<size_t> ret_index(num_results);
2666 std::vector<Real> out_dist_sqr(num_results);
2667 nanoflann::KNNResultSet<Real> result_set(num_results);
2668 result_set.init(&ret_index[0], &out_dist_sqr[0]);
2672 bool projection_succeeded =
false;
2677 std::set<const Elem *> rejected_secondary_elem_candidates;
2681 for (MooseIndex(result_set) r = 0; r < result_set.size(); ++r)
2684 mooseAssert(abs((
_mesh.point(ret_index[r]) - *primary_node).norm_sq() - out_dist_sqr[r]) <=
2686 "Lower-dimensional element squared distance verification failed.");
2690 const std::vector<const Elem *> & secondary_elem_candidates =
2694 for (MooseIndex(secondary_elem_candidates) e = 0; e < secondary_elem_candidates.size(); ++e)
2696 const Elem * secondary_elem_candidate = secondary_elem_candidates[e];
2699 if (rejected_secondary_elem_candidates.count(secondary_elem_candidate))
2702 std::vector<Point> nodal_normals(secondary_elem_candidate->n_nodes());
2703 for (
const auto n : make_range(secondary_elem_candidate->n_nodes()))
2711 auto && order = secondary_elem_candidate->default_order();
2712 unsigned int current_iterate = 0, max_iterates = 10;
2714 VectorValue<DualNumber<Real>> normals(0);
2722 VectorValue<DualNumber<Real>> x1(0);
2723 for (MooseIndex(secondary_elem_candidate->n_nodes()) n = 0;
2724 n < secondary_elem_candidate->n_nodes();
2728 x1 += phi * secondary_elem_candidate->point(n);
2729 normals += phi * nodal_normals[n];
2732 const auto u = x1 - (*primary_node);
2734 const auto F = u(0) * normals(1) - u(1) * normals(0);
2742 Real dxi1 = -F.value() / F.derivatives();
2747 }
while (++current_iterate < max_iterates);
2749 Real xi1 = xi1_dn.value();
2753 if ((current_iterate < max_iterates) && (abs(xi1) <= 1. +
_xi_tolerance) &&
2754 (abs((primary_side_elem->point(0) - primary_side_elem->point(1)).unit() *
2768 const Node & secondary_node = (xi1 < 0) ? secondary_elem_candidate->node_ref(0)
2769 : secondary_elem_candidate->node_ref(1);
2770 bool created_mortar_segment =
false;
2777 &primary_node_neighbors,
2779 *secondary_elem_candidate,
2780 rejected_secondary_elem_candidates);
2782 rejected_secondary_elem_candidates.insert(secondary_elem_candidate);
2784 if (!created_mortar_segment)
2800 const Elem * neigh = primary_node_neighbors[0];
2801 for (MooseIndex(neigh->n_vertices()) nid = 0; nid < neigh->n_vertices(); ++nid)
2803 const Node * neigh_node = neigh->node_ptr(nid);
2804 if (primary_node == neigh_node)
2806 auto key = std::make_tuple(neigh_node->id(), neigh_node, neigh);
2807 auto val = std::make_pair(xi1, secondary_elem_candidate);
2813 projection_succeeded =
true;
2819 rejected_secondary_elem_candidates.insert(secondary_elem_candidate);
2823 if (projection_succeeded)
2827 if (!projection_succeeded &&
_debug)
2829 _console <<
"\nFailed to find point from which primary node "
2830 << cast_ref<const Point &>(*primary_node) <<
" was projected." << std::endl
2837std::vector<AutomaticMortarGeneration::MortarFilterIter>
2844 const auto & secondary_elems = secondary_it->second;
2845 std::vector<MortarFilterIter> ret;
2846 ret.reserve(secondary_elems.size());
2848 for (
const auto i : index_range(secondary_elems))
2850 auto *
const secondary_elem = secondary_elems[i];
2856 mooseAssert(secondary_elem->active(),
2857 "We loop over active elements when building the mortar segment mesh, so we golly "
2858 "well hope this is active.");
2859 mooseAssert(!msm_it->second.empty(),
2860 "We should have removed all secondaries from this map if they do not have any "
2861 "mortar segments associated with them.");
2862 ret.push_back(msm_it);
subdomain_id_type SubdomainID
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
libMesh::VectorValue< ADReal > ADRealVectorValue
AD Array typedefs.
libMesh::VectorValue< ADReal > ADPoint
MortarSegmentTriangulationMode
nanoflann::KDTreeSingleIndexAdaptor< subdomain_adatper_t, NanoflannMeshSubdomainAdaptor< 3 >, 3 > subdomain_kd_tree_t
This class is a container/interface for the objects involved in automatic generation of mortar spaces...
const Elem * getSecondaryLowerdElemFromSecondaryElem(dof_id_type secondary_elem_id) const
Return lower dimensional secondary element given its interior parent.
Real _newton_tolerance
Newton solve tolerance for node projections.
std::unordered_map< const Node *, Point > _secondary_node_to_nodal_normal
Container for storing the nodal normal vector associated with each secondary node.
const MortarSegmentReferencePoints & mortarSegmentReferencePoints(const Elem &mortar_segment_elem) const
Return the parent-face reference coordinates for a mortar segment.
std::unordered_map< const Elem *, unsigned int > _lower_elem_to_side_id
Keeps track of the mapping between lower-dimensional elements and the side_id of the interior_parent ...
bool _nonlocal_secondary_couplings
Whether buildCouplingInformation() also gathers the couplings of nonlocal secondary lower-dimensional...
std::unordered_map< const Elem *, MortarSegmentReferencePoints > _msm_elem_to_reference_points
Reference-coordinate data used only by the reference-interpolation mapping mode.
std::unordered_set< dof_id_type > _projected_secondary_nodes
Debugging container for printing information about fraction of successful projections for secondary n...
std::unordered_map< dof_id_type, std::vector< const Elem * > > _nodes_to_secondary_elem_map
Map from nodes to connected lower-dimensional elements on the secondary/primary subdomains.
std::set< BoundaryID > _secondary_requested_boundary_ids
The boundary ids corresponding to all the secondary surfaces.
std::unordered_map< dof_id_type, std::vector< const Elem * > > _nodes_to_primary_elem_map
Real _xi_tolerance
Tolerance for checking projection xi values.
void outputMortarMesh()
Write the mortar segment mesh to exodus.
void computeNodalGeometry()
Computes and stores the nodal normal/tangent vectors in a local data structure instead of using the E...
const Mortar3DQuadraturePointMapping _mortar_3d_qp_mapping
Method used to map 3D mortar segment quadrature points to primary and secondary faces.
void msmStatistics()
Prints mortar segment mesh statistics to console (calls computeMsmStatistics internally)
std::vector< std::pair< BoundaryID, BoundaryID > > _primary_secondary_boundary_id_pairs
A list of primary/secondary boundary id pairs corresponding to each side of the mortar interface.
std::unique_ptr< InputParameters > _output_params
Storage for the input parameters used by the mortar nodal geometry output.
void buildMortarSegmentMesh()
Builds the mortar segment mesh once the secondary and primary node projections have been completed.
std::unordered_set< const Node * > _inactive_local_lm_nodes
List of inactive lagrange multiplier nodes owned by this processor (for nodal variables)
const bool _periodic
Whether this object will be generating a mortar segment mesh for periodic constraints.
void projectSecondaryNodes()
Project secondary nodes (find xi^(2) values) to the closest points on the primary surface.
void buildMortarSegmentMesh3d()
Builds the mortar segment mesh once the secondary and primary node projections have been completed.
void computeInactiveLMElems()
Get list of secondary elems without any corresponding primary elements.
std::set< SubdomainID > _secondary_boundary_subdomain_ids
The secondary/primary lower-dimensional boundary subdomain ids are the secondary/primary boundary ids...
const bool _correct_edge_dropping
Flag to enable regressed treatment of edge dropping where all LM DoFs on edge dropping element are st...
void buildCouplingInformation()
build the _mortar_interface_coupling data
const Mortar3DSubpatchPlane _mortar_3d_subpatch_plane
Method used to define the local projection planes for 3D secondary subpatches.
std::vector< Point > getNormals(const Elem &secondary_elem, const std::vector< Point > &xi1_pts) const
Compute the normals at given reference points on a secondary element.
std::set< SubdomainID > _secondary_ip_sub_ids
All the secondary interior parent subdomain IDs associated with the mortar mesh.
void initOutput()
initialize mortar-mesh based output
std::unordered_map< const Node *, std::array< Point, 2 > > _secondary_node_to_hh_nodal_tangents
Container for storing the nodal tangent/binormal vectors associated with each secondary node (Househo...
bool processAlignedNodes(const Node &secondary_node, const Node &primary_node, const std::vector< const Elem * > *secondary_node_neighbors, const std::vector< const Elem * > *primary_node_neighbors, const VectorValue< Real > &nodal_normal, const Elem &candidate_element, std::set< const Elem * > &rejected_element_candidates)
Process aligned nodes.
void projectSecondaryNodesSinglePair(SubdomainID lower_dimensional_primary_subdomain_id, SubdomainID lower_dimensional_secondary_subdomain_id)
Helper function responsible for projecting secondary nodes onto primary elements for a single primary...
std::vector< MsmSubdomainStats > computeMsmStatistics()
Computes mortar segment mesh statistics and returns one entry per subdomain pair.
MeshBase & _mesh
Reference to the mesh stored in equation_systems.
const bool _debug
Whether to print debug output.
std::vector< std::pair< SubdomainID, SubdomainID > > _primary_secondary_subdomain_id_pairs
A list of primary/secondary subdomain id pairs corresponding to each side of the mortar interface.
std::map< unsigned int, unsigned int > getSecondaryIpToLowerElementMap(const Elem &lower_secondary_elem) const
Compute on-the-fly mapping from secondary interior parent nodes to lower dimensional nodes.
void buildNodeToElemMaps()
Once the secondary_requested_boundary_ids and primary_requested_boundary_ids containers have been fil...
std::unique_ptr< MeshBase > _mortar_segment_mesh
1D Mesh of mortar segment elements which gets built by the call to build_mortar_segment_mesh().
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::string mortarInterfaceName() const
std::optional< dof_id_type > _msm_node_id_start
Cached per-rank starting ID for 3D MSM nodes/elements.
void clear()
Clears the mortar segment mesh and accompanying data structures.
MooseApp & _app
The Moose app.
std::unordered_map< dof_id_type, std::unordered_set< dof_id_type > > _mortar_interface_coupling
Used by the AugmentSparsityOnInterface functor to determine whether a given Elem is coupled to any ot...
std::map< unsigned int, unsigned int > getPrimaryIpToLowerElementMap(const Elem &primary_elem, const Elem &primary_elem_ip, const Elem &lower_secondary_elem) const
Compute on-the-fly mapping from primary interior parent nodes to its corresponding lower dimensional ...
std::unordered_map< std::pair< const Node *, const Elem * >, std::pair< Real, const Elem * > > _secondary_node_and_elem_to_xi2_primary_elem
Similar to the map above, but associates a (Secondary Node, Secondary Elem) pair to a (xi^(2),...
std::unordered_map< const Elem *, MortarSegmentInfo > _msm_elem_to_info
Map between Elems in the mortar segment mesh and their info structs.
AutomaticMortarGeneration(MooseApp &app, MeshBase &mesh_in, const std::pair< BoundaryID, BoundaryID > &boundary_key, const std::pair< SubdomainID, SubdomainID > &subdomain_key, bool on_displaced, bool periodic, const bool debug, const bool correct_edge_dropping, const Real minimum_projection_angle, const Mortar3DSubpatchPlane mortar_3d_subpatch_plane, const MortarSegmentTriangulationMode triangulation_mode, const bool triangulate_triangles, const Mortar3DQuadraturePointMapping mortar_3d_qp_mapping=Mortar3DQuadraturePointMapping::NORMAL_PROJECTION)
Must be constructed with a reference to the Mesh we are generating mortar spaces for.
std::map< std::tuple< dof_id_type, const Node *, const Elem * >, std::pair< Real, const Elem * > > _primary_node_and_elem_to_xi1_secondary_elem
Same type of container, but for mapping (Primary Node ID, Primary Node, Primary Elem) -> (xi^(1),...
const bool _on_displaced
Whether this object is on the displaced mesh.
std::unordered_set< const Elem * > _inactive_local_lm_elems
List of inactive lagrange multiplier nodes (for elemental variables)
void computeIncorrectEdgeDroppingInactiveLMNodes()
Computes inactive secondary nodes when incorrect edge dropping behavior is enabled (any node touching...
const bool _distributed
Whether the mortar segment mesh is distributed.
std::array< MooseUtils::SemidynamicVector< Point, 9 >, 2 > getNodalTangents(const Elem &secondary_elem) const
Compute the two nodal tangents, which are built on-the-fly.
std::set< SubdomainID > _primary_ip_sub_ids
All the primary interior parent subdomain IDs associated with the mortar mesh.
std::unordered_map< dof_id_type, const Elem * > _secondary_element_to_secondary_lowerd_element
Map from full dimensional secondary element id to lower dimensional secondary element.
const bool _triangulate_triangles
Whether already-triangular clipped polygons should still be centroid-subdivided.
std::set< SubdomainID > _primary_boundary_subdomain_ids
void projectPrimaryNodesSinglePair(SubdomainID lower_dimensional_primary_subdomain_id, SubdomainID lower_dimensional_secondary_subdomain_id)
Helper function used internally by AutomaticMortarGeneration::project_primary_nodes().
const MortarSegmentTriangulationMode _triangulation_mode
Triangulation mode used for clipped 3D mortar polygons.
std::set< BoundaryID > _primary_requested_boundary_ids
The boundary ids corresponding to all the primary surfaces.
std::unordered_set< dof_id_type > _failed_secondary_node_projections
Secondary nodes that failed to project.
std::vector< Point > getNodalNormals(const Elem &secondary_elem) const
std::unordered_map< dof_id_type, std::set< Elem *, CompareDofObjectsByID > > _secondary_elems_to_mortar_segments
We maintain a mapping from lower-dimensional secondary elements in the original mesh to (sets of) ele...
const std::unordered_map< dof_id_type, std::set< Elem *, CompareDofObjectsByID > > & secondariesToMortarSegments() const
void projectPrimaryNodes()
(Inverse) project primary nodes to the points on the secondary surface where they would have come fro...
void computeInactiveLMNodes()
Get list of secondary nodes that don't contribute to interaction with any primary element.
const Real _minimum_projection_angle
Parameter to control which angle (in degrees) is admissible for the creation of mortar segments.
An inteface for the _console for outputting to the Console object.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Base class for MOOSE-based applications.
std::string getOutputFileBase(bool for_non_moose_build_output=false) const
Get the output file base name.
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
FEProblemBase & feProblem() const
SolutionInvalidity & solutionInvalidity()
Get the SolutionInvalidity for this app.
static const std::string name_param
The name of the parameter that contains the object name.
static const std::string type_param
The name of the parameter that contains the object type.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
T getCheckedPointerParam(const std::string &name, const std::string &error_string="") const
Verifies that the requested parameter exists and is not NULL and returns it to the caller.
static const std::string app_param
The name of the parameter that contains the MooseApp.
Provides a way for users to bail out of the current solve.
MooseApp & _app
The MOOSE application this is associated with.
MortarNodalGeometryOutput(const InputParameters ¶ms)
unsigned int _t1z_var_num
unsigned int _t1x_var_num
unsigned int _t2z_var_num
unsigned int _nny_var_num
unsigned int _t2y_var_num
static InputParameters validParams()
AutomaticMortarGeneration & _amg
The mortar generation object that we will query for nodal normal and tangent information.
unsigned int _nnz_var_num
unsigned int _nnx_var_num
unsigned int _t2x_var_num
libMesh::System * _nodal_normals_system
Member variables for geometry debug output.
unsigned int _t1y_var_num
void output() override
Overload this function with the desired output activities.
Special adaptor that works with subdomains of the Mesh.
void addOutput(std::shared_ptr< Output > output)
Adds an existing output object to the warehouse.
Based class for output objects.
static InputParameters validParams()
void flagInvalidSolutionInternal(const InvalidSolutionID _invalid_solution_id)
Increments solution invalid occurrences for each solution id.
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
unsigned int n_dofs(const ElemType t, const Order o)
const std::vector< Real > & get_weights() const
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
std::unique_ptr< NumericVector< Number > > solution
const DofMap & get_dof_map() const
TypeVector< typename CompareTypes< T, T2 >::supertype > cross(const TypeVector< T2 > &v) const
LIBMESH_DEVICE_INLINE void add_scaled(const TypeVector< T2 > &, const T &)
InvalidSolutionID registerInvalidity(const std::string &object_type, const std::string &message, const bool warning)
Call to register an invalid calculation.
std::vector< unsigned int > nodalQuadraturePointToNodeMap(const Elem &elem, const std::vector< Point > &q_points)
Match the points of a nodal quadrature rule (e.g.
std::vector< unsigned int > getMortarSubElementNodeIndices(const Elem &parent_elem, unsigned int sub_elem)
Return the node indices for a first-order sub-element of a parent face.
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.
T fe_lagrange_2D_shape(const libMesh::ElemType type, const Order order, const unsigned int i, const VectorType< T > &p)
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
T fe_lagrange_1D_shape(const Order order, const unsigned int i, const T &xi)
void pull_parallel_vector_data(const Communicator &comm, const MapToVectors &queries, GatherFunctor &gather_data, const ActionFunctor &act_on_data, const datum *example)
void push_parallel_vector_data(const Communicator &comm, MapToVectors &&data, const ActionFunctor &act_on_data)
SolutionInvalidityRegistry & getSolutionInvalidityRegistry()
Get the global SolutionInvalidityRegistry singleton.
SearchParams SearchParameters
Statistics for one primary-secondary subdomain pair.
SubdomainID primary_subd_id
Real secondary_lower_median_volume
std::size_t primary_lower_n_elems
std::size_t secondary_lower_n_elems
Real secondary_lower_max_volume
SubdomainID secondary_subd_id
Real primary_lower_min_volume
Real primary_lower_max_volume
Real secondary_lower_min_volume
Real primary_lower_median_volume
Holds xi^(1), xi^(2), and other data for a given mortar segment.
const Elem * primary_elem
static const Real invalid_xi
const Elem * secondary_elem
Parent-face reference coordinates associated with the vertices of one triangular mortar segment.
const dof_id_type n_nodes