libMesh
overlap_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 
19 
20 // Local Includes
21 #include "libmesh/overlap_coupling.h"
22 
23 #include "libmesh/elem.h"
24 #include "libmesh/enum_quadrature_type.h"
25 #include "libmesh/periodic_boundaries.h"
26 #include "libmesh/remote_elem.h"
27 #include "libmesh/libmesh_logging.h"
28 
29 // C++ Includes
30 #include <unordered_set>
31 
32 namespace libMesh
33 {
34 
36  _dof_coupling(nullptr)
37 {
41 }
42 
43 
44 
46  GhostingFunctor(other),
47  _dof_coupling(other._dof_coupling)
48 {
49  for (auto i : make_range(2))
50  if (other._q_rules[i].get())
51  _q_rules[i] = other._q_rules[i]->clone();
52 }
53 
54 
55 
57  (std::unique_ptr<QBase> new_q_rule)
58 {
59  libmesh_assert(new_q_rule.get());
60  const unsigned int dim = new_q_rule->get_dim();
61  _q_rules[dim-1] = std::move(new_q_rule);
62 }
63 
64 
65 
67 {
68  // We'll need a master point locator, so we'd better have a mesh
69  // to build it on.
71 
72  // Make sure an up-to-date master point locator has been
73  // constructed; we'll need to grab sub-locators soon.
75 }
76 
77 
78 
79 void OverlapCoupling::operator()
80  (const MeshBase::const_element_iterator & range_begin,
81  const MeshBase::const_element_iterator & range_end,
83  map_type & coupled_elements)
84 {
85  LOG_SCOPE("operator()", "OverlapCoupling");
86 
87  std::unique_ptr<PointLocatorBase> point_locator
88  = _mesh->sub_point_locator();
89 
90  const std::vector<Point> & xyz = this->_fe_map.get_xyz();
91 
92  for (const auto & elem : as_range(range_begin, range_end))
93  {
94  const unsigned int dim = elem->dim();
95 
96  QBase & qrule = *_q_rules[dim-1];
97  qrule.init(*elem);
98 
99  _fe_map.init_reference_to_physical_map(dim, qrule.get_points(), elem);
100  _fe_map.compute_map(dim, qrule.get_weights(), elem, /*d2phi=*/ false);
101 
102  std::set<const Elem *> overlapping_elements;
103  for (const Point & qp : xyz)
104  (*point_locator)(qp, overlapping_elements);
105 
106  // We should at least find ourselves
107  libmesh_assert(overlapping_elements.count(elem));
108 
109  for (const Elem * e : overlapping_elements)
110  if (e->processor_id() != p)
111  coupled_elements.emplace(e, _dof_coupling);
112  }
113 }
114 
115 
116 } // namespace libMesh
This abstract base class defines the interface by which library code and user code can report associa...
std::unique_ptr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:1638
The definition of the const_element_iterator struct.
Definition: mesh_base.h:2216
unsigned int dim
virtual void mesh_reinit() override
We need an updated point locator to see what other elements might share each quadrature point...
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
const std::vector< Real > & get_weights() const
Definition: quadrature.h:168
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?
The libMesh namespace provides an interface to certain functionality in the library.
OverlapCoupling()
Constructor.
uint8_t processor_id_type
Definition: id_types.h:104
std::array< std::unique_ptr< QBase >, 3 > _q_rules
This class implements ghosting of elements that overlap or touch at at least one sampled point...
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
libmesh_assert(ctx)
const std::vector< Point > & get_points() const
Definition: quadrature.h:156
void set_quadrature_rule(std::unique_ptr< QBase > new_q_rule)
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:140
virtual void init(const Elem &e, unsigned int p_level=invalid_uint)
Initializes the data structures for a quadrature rule for the element e.
Definition: quadrature.C:65
static std::unique_ptr< QBase > build(std::string_view name, const unsigned int dim, const Order order=INVALID_ORDER)
Builds a specific quadrature rule based on the name string.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
The QBase class provides the basic functionality from which various quadrature rules can be derived...
Definition: quadrature.h:61