libMesh
point_neighbor_coupling.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 
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.
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  UniquePtr<PointLocatorBase> point_locator;
65  if (check_periodic_bcs)
66  {
68  point_locator = _mesh->sub_point_locator();
69  }
70 #endif
71 
72  if (!this->_n_levels)
73  {
74  for (MeshBase::const_element_iterator elem_it = range_begin;
75  elem_it != range_end; ++elem_it)
76  {
77  const Elem * const elem = *elem_it;
78 
79  if (elem->processor_id() != p)
80  coupled_elements.insert (std::make_pair(elem,_dof_coupling));
81  }
82  return;
83  }
84 
85  typedef std::unordered_set<const Elem*> set_type;
86  set_type next_elements_to_check(range_begin, range_end);
87  set_type elements_to_check;
88  set_type elements_checked;
89 
90  for (unsigned int i=0; i != this->_n_levels; ++i)
91  {
92  elements_to_check.swap(next_elements_to_check);
93  next_elements_to_check.clear();
94  elements_checked.insert(elements_to_check.begin(), elements_to_check.end());
95 
96  for (set_type::const_iterator
97  elem_it = elements_to_check.begin(),
98  elem_end = elements_to_check.end();
99  elem_it != elem_end; ++elem_it)
100  {
101  std::set<const Elem *> point_neighbors;
102 
103  const Elem * const elem = *elem_it;
104 
105  if (elem->processor_id() != p)
106  coupled_elements.insert (std::make_pair(elem,_dof_coupling));
107 
108 #ifdef LIBMESH_ENABLE_PERIODIC
109  // We might have a periodic neighbor here
110  if (check_periodic_bcs)
111  {
112  libmesh_not_implemented();
113  }
114  else
115 #endif
116  {
117  elem->find_point_neighbors(point_neighbors);
118  }
119 
120  for (std::set<const Elem *>::const_iterator
121  it = point_neighbors.begin(),
122  end_it = point_neighbors.end();
123  it != end_it; ++it)
124  {
125  const Elem * neighbor = *it;
126 
127  if (!elements_checked.count(neighbor))
128  next_elements_to_check.insert(neighbor);
129 
130  if (neighbor->processor_id() != p)
131  coupled_elements.insert
132  (std::make_pair(neighbor, _dof_coupling));
133  }
134  }
135  }
136 }
137 
138 
139 } // namespace libMesh
The definition of the const_element_iterator struct.
Definition: mesh_base.h:1494
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
uint8_t processor_id_type
Definition: id_types.h:99
The libMesh namespace provides an interface to certain functionality in the library.
void find_point_neighbors(const Point &p, std::set< const Elem * > &neighbor_set) const
This function finds all active elements (including this one) which are in the same manifold as this e...
Definition: elem.C:605
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
const PeriodicBoundaries * _periodic_bcs
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?
virtual void mesh_reinit() libmesh_override
If we have periodic boundaries, then we&#39;ll need the mesh to have an updated point locator whenever we...
UniquePtr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:534
processor_id_type processor_id() const
Definition: dof_object.h:694