libMesh
non_manifold_coupling.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 // libMesh includes
19 #include "libmesh/elem.h"
20 #include "libmesh/non_manifold_coupling.h"
21 #include "libmesh/simple_range.h" // as_range()
22 
23 namespace libMesh
24 {
25 
29  _stem(MeshTools::SidesToElemMap::build(mesh))
30 {
31  // We call MeshBase::reinit_ghosting_functors() in MeshBase::prepare_for_use(),
32  // so it _should_ be safe to omit this call to SidesToElemMap::build() here,
33  // but to be on the safe side, we'll construct it both here and during any call
34  // to mesh_reinit().
35 }
36 
37 std::unique_ptr<GhostingFunctor>
39 {
40  return std::make_unique<NonManifoldGhostingFunctor>(*this);
41 }
42 
43 void
45 {
47 }
48 
49 void
51 {
52  this->mesh_reinit();
53 }
54 
55 void
57 {
58  this->mesh_reinit();
59 }
60 
61 void
63  const MeshBase::const_element_iterator & range_begin,
64  const MeshBase::const_element_iterator & range_end,
66  map_type & coupled_elements)
67 {
68  // This code is just for geometric coupling, so we use a null
69  // CouplingMatrix pointer. We'll declare that here so as to avoid
70  // confusing the emplace() calls later.
71  CouplingMatrix * nullcm = nullptr;
72 
73  for (const auto & elem : as_range(range_begin, range_end))
74  {
75  // The idea here is that the input range [range_begin,
76  // range_end] is a list of Elems whose DOFs we already know we
77  // want to ghost (if they aren't already owned by processor p,
78  // we don't need to worry about ghosting "local" Elem DOFs)
79  // Therefore, we always put *all* the non-local Elems in the
80  // input range into the output "coupled_elements" map. The
81  // purpose of the rest of this of this function is then to
82  // determine which *additional* elements should be ghosted,
83  // given that we care about the entire input range.
84  if (elem->processor_id() != p)
85  coupled_elements.emplace(elem, nullcm);
86 
87  // For each side of "elem", look up that (elem, side) pair in
88  // the SidesToElemMap and then add all the Elem pointers from
89  // that list to the coupled_elements map.
90  for (auto s : elem->side_index_range())
91  for (const auto & neigh : as_range(_stem.get_connected_elems(elem, s)))
92  if (neigh->processor_id() != p)
93  coupled_elements.emplace(neigh, nullcm);
94  }
95 }
96 
97 } // namespace libMesh
This abstract base class defines the interface by which library code and user code can report associa...
The definition of the const_element_iterator struct.
Definition: mesh_base.h:2216
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
For the specified range of active elements, query the SidesToElemMap and add all side neighbors to th...
MeshBase & mesh
virtual std::unique_ptr< GhostingFunctor > clone() const override
clone() just calls the copy ctor.
std::map< const Elem *, const CouplingMatrix *, CompareDofObjectsByPIDAndThenID > map_type
What elements do we care about and what variables do we care about on each element?
std::pair< ElemIter, ElemIter > get_connected_elems(const Elem *elem, unsigned int side) const
Return an iterator pair defining the range of Elems connected to "side" of "elem".
The libMesh namespace provides an interface to certain functionality in the library.
NonManifoldGhostingFunctor(const MeshBase &mesh)
Constructor.
uint8_t processor_id_type
Definition: id_types.h:104
This is the MeshBase class.
Definition: mesh_base.h:75
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.
Definition: simple_range.h:57
virtual void delete_remote_elements() override
When remote elements are deleted, we should remove them from the information in the SidesToElemMap...
MeshTools::SidesToElemMap _stem
Quickly-searchable map from (elem, side) pair to list of connected Elems.
static SidesToElemMap build(const MeshBase &mesh)
Static build function.
virtual void redistribute() override
When the Mesh is redistributed, we may need to update the information in the SidesToElemMap by removi...
virtual void mesh_reinit() override
If the Mesh changes, we&#39;ll need to clear the SidesToElemMap and recreate it, since all the neighbor i...
This class defines a coupling matrix.