libMesh
point_neighbor_coupling.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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/point_neighbor_coupling.h"
22 
23 #include "libmesh/elem.h"
24 #include "libmesh/periodic_boundaries.h"
25 #include "libmesh/remote_elem.h"
26 #include "libmesh/libmesh_logging.h"
27 
28 // C++ Includes
29 #include <unordered_set>
30 
31 namespace libMesh
32 {
33 
35 {
36  // Unless we have periodic boundary conditions, we don't need
37  // anything precomputed.
38 #ifdef LIBMESH_ENABLE_PERIODIC
39  if (_periodic_bcs && !_periodic_bcs->empty())
40 #endif
41  {
42  // If we do have periodic boundary conditions, we'll need a master
43  // point locator, so we'd better have a mesh to build it on.
45 
46  // Make sure an up-to-date master point locator has been
47  // constructed; we'll need to grab sub-locators soon.
49  }
50 }
51 
52 
53 
54 void PointNeighborCoupling::operator()
55  (const MeshBase::const_element_iterator & range_begin,
56  const MeshBase::const_element_iterator & range_end,
58  map_type & coupled_elements)
59 {
60  LOG_SCOPE("operator()", "PointNeighborCoupling");
61 
62 #ifdef LIBMESH_ENABLE_PERIODIC
63  bool check_periodic_bcs =
64  (_periodic_bcs && !_periodic_bcs->empty());
65  std::unique_ptr<PointLocatorBase> point_locator;
66  if (check_periodic_bcs)
67  {
68  libmesh_assert(_mesh);
69  point_locator = _mesh->sub_point_locator();
70  }
71 #endif
72 
73  if (!this->_n_levels)
74  {
75  for (const auto & elem : as_range(range_begin, range_end))
76  if (elem->processor_id() != p)
77  coupled_elements.insert (std::make_pair(elem,_dof_coupling));
78 
79  return;
80  }
81 
82  typedef std::unordered_set<const Elem*> set_type;
83  set_type next_elements_to_check(range_begin, range_end);
84  set_type elements_to_check;
85  set_type elements_checked;
86 
87  for (unsigned int i=0; i != this->_n_levels; ++i)
88  {
89  elements_to_check.swap(next_elements_to_check);
90  next_elements_to_check.clear();
91  elements_checked.insert(elements_to_check.begin(), elements_to_check.end());
92 
93  for (const auto & elem : elements_to_check)
94  {
95  std::set<const Elem *> point_neighbors;
96 
97  if (elem->processor_id() != p)
98  coupled_elements.insert (std::make_pair(elem,_dof_coupling));
99 
100 #ifdef LIBMESH_ENABLE_PERIODIC
101  // We might have a periodic neighbor here
102  if (check_periodic_bcs)
103  {
104  libmesh_not_implemented();
105  }
106  else
107 #endif
108  {
109  elem->find_point_neighbors(point_neighbors);
110  }
111 
112  for (const auto & neighbor : point_neighbors)
113  {
114  if (!elements_checked.count(neighbor))
115  next_elements_to_check.insert(neighbor);
116 
117  if (neighbor->processor_id() != p)
118  coupled_elements.insert
119  (std::make_pair(neighbor, _dof_coupling));
120  }
121  }
122  }
123 }
124 
125 
126 } // namespace libMesh
libMesh::PointNeighborCoupling::_mesh
const MeshBase * _mesh
Definition: point_neighbor_coupling.h:111
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::GhostingFunctor::map_type
std::unordered_map< const Elem *, const CouplingMatrix * > map_type
What elements do we care about and what variables do we care about on each element?
Definition: ghosting_functor.h:171
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::PointNeighborCoupling::_periodic_bcs
const PeriodicBoundaries * _periodic_bcs
Definition: point_neighbor_coupling.h:109
libMesh::processor_id_type
uint8_t processor_id_type
Definition: id_types.h:104
libMesh::as_range
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::PointNeighborCoupling::mesh_reinit
virtual void mesh_reinit() override
If we have periodic boundaries, then we'll need the mesh to have an updated point locator whenever we...
Definition: point_neighbor_coupling.C:34
libMesh::MeshBase::const_element_iterator
The definition of the const_element_iterator struct.
Definition: mesh_base.h:1891
libMesh::MeshBase::sub_point_locator
std::unique_ptr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:672