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