17#include "libmesh/elem.h"
18#include "libmesh/mesh_base.h"
19#include "libmesh/boundary_info.h"
24AugmentSparsityOnInterface::validParams()
28 "The name of the primary boundary sideset.");
30 "The name of the secondary boundary sideset.");
32 "The name of the primary lower dimensional subdomain.");
34 "The name of the secondary lower dimensional subdomain.");
36 "ghost_point_neighbors",
38 "Whether we should ghost point neighbors of secondary lower-dimensional elements and "
39 "also their interior parents and mortar interface couples for applications such as mortar "
40 "nodal auxiliary kernels and nodal-normal contact Jacobians.");
42 "ghost_higher_d_neighbors",
44 "Whether we should ghost higher-dimensional neighbors. This is necessary when we are doing "
45 "second order mortar with finite volume primal variables, because in order for the method to "
46 "be second order we must use cell gradients, which couples in the neighbor cells.");
54 params.
set<
bool>(
"attach_geometric_early") =
false;
60 _primary_boundary_name(getParam<BoundaryName>(
"primary_boundary")),
61 _secondary_boundary_name(getParam<BoundaryName>(
"secondary_boundary")),
62 _primary_subdomain_name(getParam<SubdomainName>(
"primary_subdomain")),
63 _secondary_subdomain_name(getParam<SubdomainName>(
"secondary_subdomain")),
65 _ghost_point_neighbors(getParam<bool>(
"ghost_point_neighbors")),
66 _ghost_higher_d_neighbors(getParam<bool>(
"ghost_higher_d_neighbors"))
72 _primary_boundary_name(other._primary_boundary_name),
73 _secondary_boundary_name(other._secondary_boundary_name),
74 _primary_subdomain_name(other._primary_subdomain_name),
75 _secondary_subdomain_name(other._secondary_subdomain_name),
76 _is_coupling_functor(other._is_coupling_functor),
77 _ghost_point_neighbors(other._ghost_point_neighbors),
78 _ghost_higher_d_neighbors(other._ghost_higher_d_neighbors)
83AugmentSparsityOnInterface::internalInitWithMesh(
const MeshBase &)
88AugmentSparsityOnInterface::getInfo()
const
90 std::ostringstream oss;
91 oss <<
"AugmentSparsityOnInterface";
96AugmentSparsityOnInterface::ghostMortarInterfaceCouplings(
97 const processor_id_type p,
98 const Elem *
const elem,
99 map_type & coupled_elements,
104 auto find_it = mic.find(elem->id());
105 if (find_it == mic.end())
108 const auto & coupled_set = find_it->second;
110 for (
const auto coupled_elem_id : coupled_set)
114 const Elem *
const coupled_elem =
_mesh->query_elem_ptr(coupled_elem_id);
115 if (coupled_elem && coupled_elem->processor_id() != p)
116 coupled_elements.emplace(coupled_elem, _null_mat);
121AugmentSparsityOnInterface::ghostLowerDSecondaryElemPointNeighbors(
122 const processor_id_type p,
123 const Elem *
const query_elem,
124 map_type & coupled_elements,
131 std::vector<const Elem *> secondary_lower_elem_candidates;
132 if (query_elem->subdomain_id() == secondary_subdomain_id)
133 secondary_lower_elem_candidates.push_back(query_elem);
136 for (
const auto side : query_elem->side_index_range())
137 if (const Elem * const lower_elem =
_moose_mesh->getLowerDElem(query_elem, side);
138 lower_elem && lower_elem->subdomain_id() == secondary_subdomain_id)
139 secondary_lower_elem_candidates.push_back(lower_elem);
142 if (
const auto find_it = mic.find(query_elem->id()); find_it != mic.end())
143 for (
const auto coupled_elem_id : find_it->second)
144 if (const Elem * const coupled_elem =
_mesh->query_elem_ptr(coupled_elem_id);
145 coupled_elem && coupled_elem->subdomain_id() == secondary_subdomain_id)
146 secondary_lower_elem_candidates.push_back(coupled_elem);
150 std::set<dof_id_type> secondary_lower_elems_handled;
151 for (
const Elem *
const candidate : secondary_lower_elem_candidates)
153 if (candidate->subactive())
157 std::vector<const Elem *> active_secondary_lower_elems;
158 candidate->active_family_tree(active_secondary_lower_elems);
159 for (
const Elem *
const secondary_lower_elem : active_secondary_lower_elems)
163 if (secondary_lower_elem->subdomain_id() != secondary_subdomain_id ||
164 !secondary_lower_elems_handled.insert(secondary_lower_elem->id()).second)
167 std::set<const Elem *> secondary_lower_elem_point_neighbors;
168 secondary_lower_elem->find_point_neighbors(secondary_lower_elem_point_neighbors);
169 secondary_lower_elem_point_neighbors.insert(secondary_lower_elem);
171 for (
const Elem *
const neigh : secondary_lower_elem_point_neighbors)
173 if (!neigh->active() || neigh->subdomain_id() != secondary_subdomain_id)
177 if (neigh->processor_id() != p)
178 coupled_elements.emplace(neigh, _null_mat);
182 const Elem *
const interior_parent = neigh->interior_parent();
183 mooseAssert(interior_parent,
184 "A lower-dimensional secondary mortar element must have an interior parent.");
185 if (interior_parent->processor_id() != p)
186 coupled_elements.emplace(interior_parent, _null_mat);
188 ghostMortarInterfaceCouplings(p, neigh, coupled_elements, amg);
195AugmentSparsityOnInterface::ghostHigherDNeighbors(
const processor_id_type p,
196 const Elem *
const query_elem,
197 map_type & coupled_elements,
207 if (query_elem->subdomain_id() != secondary_subdomain_id)
210 const BoundaryInfo & binfo =
_mesh->get_boundary_info();
211 const auto which_side = query_elem->interior_parent()->which_side_am_i(query_elem);
212 if (!binfo.has_boundary_id(query_elem->interior_parent(), which_side, secondary_boundary_id))
216 auto find_it = mic.find(query_elem->id());
217 if (find_it == mic.end())
221 const auto & lower_d_coupled_set = find_it->second;
222 for (
const auto coupled_elem_id : lower_d_coupled_set)
224 auto *
const coupled_elem =
_mesh->elem_ptr(coupled_elem_id);
225 if (coupled_elem->dim() == query_elem->dim())
229 std::vector<const Elem *> active_neighbors;
231 for (
auto s : coupled_elem->side_index_range())
233 const Elem *
const neigh = coupled_elem->neighbor_ptr(s);
235 if (!neigh || neigh == remote_elem)
240 neigh->active_family_tree_by_neighbor(active_neighbors, coupled_elem);
242 for (
const auto & neighbor : active_neighbors)
246 neighbor->subdomain_id() != secondary_subdomain_id,
247 "Ensure that we aren't missing potential erasures from the secondary-to-msms map");
248 coupled_elements.emplace(neighbor, _null_mat);
256 const MeshBase::const_element_iterator & range_end,
257 const processor_id_type p,
258 map_type & coupled_elements)
264 const auto primary_boundary_id = generating_mesh
267 const auto secondary_boundary_id = generating_mesh
270 const auto primary_subdomain_id = generating_mesh
273 const auto secondary_subdomain_id = generating_mesh
279 std::make_pair(primary_boundary_id, secondary_boundary_id),
280 std::make_pair(primary_subdomain_id, secondary_subdomain_id),
293 for (
const Elem *
const elem :
_mesh->active_element_ptr_range())
300 if (elem->on_boundary())
301 coupled_elements.insert(std::make_pair(elem, _null_mat));
302 else if (
const Elem *
const ip = elem->interior_parent())
304 if (ip->on_boundary())
305 coupled_elements.insert(std::make_pair(elem, _null_mat));
314 "Primary boundary id should exist by now.");
316 "Secondary boundary id should exist by now.");
318 "Primary subdomain id should exist by now.");
320 "Secondary subdomain id should exist by now.");
323 const BoundaryInfo & binfo =
_mesh->get_boundary_info();
325 for (
auto side : elem->side_index_range())
327 (binfo.has_boundary_id(elem, side, primary_boundary_id) ||
328 binfo.has_boundary_id(elem, side, secondary_boundary_id)))
329 coupled_elements.insert(
std::make_pair(elem, _null_mat));
332 if ((elem->processor_id() != p) && (elem->subdomain_id() == primary_subdomain_id ||
333 elem->subdomain_id() == secondary_subdomain_id))
335 coupled_elements.insert(std::make_pair(elem, _null_mat));
339 const Elem *
const ip = elem->interior_parent();
341 "We should have set interior parents for all of our lower-dimensional mortar "
343 auto side = ip->which_side_am_i(elem);
344 auto bnd_id = elem->subdomain_id() == primary_subdomain_id ? primary_boundary_id
345 : secondary_boundary_id;
346 mooseAssert(
_mesh->get_boundary_info().has_boundary_id(ip, side, bnd_id),
347 "The interior parent for the lower-dimensional element does not lie on the "
358 for (
const Elem *
const elem :
as_range(range_begin, range_end))
360 ghostMortarInterfaceCouplings(p, elem, coupled_elements, *amg);
362 if (_ghost_point_neighbors)
363 ghostLowerDSecondaryElemPointNeighbors(
364 p, elem, coupled_elements, secondary_subdomain_id, *amg);
365 if (_ghost_higher_d_neighbors)
366 ghostHigherDNeighbors(
367 p, elem, coupled_elements, secondary_boundary_id, secondary_subdomain_id, *amg);
377 if (_primary_boundary_name == asoi->_primary_boundary_name &&
378 _secondary_boundary_name == asoi->_secondary_boundary_name &&
379 _primary_subdomain_name == asoi->_primary_subdomain_name &&
380 _secondary_subdomain_name == asoi->_secondary_subdomain_name &&
381 _ghost_point_neighbors >= asoi->_ghost_point_neighbors &&
382 _ghost_higher_d_neighbors >= asoi->_ghost_higher_d_neighbors &&
baseGreaterEqual(*asoi))
388std::unique_ptr<GhostingFunctor>
registerMooseObject("MooseApp", AugmentSparsityOnInterface)
boundary_id_type BoundaryID
subdomain_id_type SubdomainID
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
AugmentSparsityOnInterface(MeshBase &mesh, boundary_id_type crack_boundary_lower, boundary_id_type crack_boundary_upper)
virtual std::unique_ptr< GhostingFunctor > clone() const override
virtual void operator()(const MeshBase::const_element_iterator &range_begin, const MeshBase::const_element_iterator &range_end, processor_id_type p, map_type &coupled_elements) override
This class is a container/interface for the objects involved in automatic generation of mortar spaces...
const std::unordered_map< dof_id_type, std::unordered_set< dof_id_type > > & mortarInterfaceCoupling() const
FEProblemBase & feProblem()
Return a reference to this Executioner's FEProblemBase instance.
const AutomaticMortarGeneration & getMortarInterface(const std::pair< BoundaryID, BoundaryID > &primary_secondary_boundary_pair, const std::pair< SubdomainID, SubdomainID > &primary_secondary_subdomain_pair, bool on_displaced) const
Return the undisplaced or displaced mortar generation object associated with the provided boundaries ...
std::unique_ptr< T > copyConstruct(const T &object)
Copy constructs the object object.
Executioner * getExecutioner() const
Retrieve the Executioner for this App.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
const MeshBase * getMeshPtr() const
SubdomainID getSubdomainID(const SubdomainName &subdomain_name) const
Get the associated subdomain ID for the subdomain name.
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
MooseApp & _app
The MOOSE application this is associated with.
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
const bool _use_displaced_mesh
Which system this should go to (undisplaced or displaced)
virtual bool baseGreaterEqual(const RelationshipManager &rhs) const
Whether the base class provides more or the same amount and type of ghosting as the rhs.
static InputParameters validParams()
MooseMesh * _moose_mesh
Pointer to the MooseMesh object.
processor_id_type processor_id() const
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
RelationshipManagerType
Main types of Relationship Managers.
const BoundaryID INVALID_BOUNDARY_ID
const SubdomainID INVALID_BLOCK_ID
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)