periodic_boundaries.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 // Local Includes
19 #include "libmesh/libmesh_config.h"
20 
21 #ifdef LIBMESH_ENABLE_PERIODIC
22 
25 #include "libmesh/elem.h"
27 #include "libmesh/mesh_base.h"
28 
29 namespace libMesh
30 {
31 
33 {
34  for (auto & pr : *this)
35  delete pr.second;
36 }
37 
38 
39 
41 {
42  iterator i = this->find(id);
43  if (i == this->end())
44  return nullptr;
45  return i->second;
46 }
47 
48 
49 
51 {
52  const_iterator i = this->find(id);
53  if (i == this->end())
54  return nullptr;
55  return i->second;
56 }
57 
58 
59 
60 
62  const PointLocatorBase & point_locator,
63  const Elem * e,
64  unsigned int side) const
65 {
66  // Find a point on that side (and only that side)
67 
68  Point p = e->build_side_ptr(side)->centroid();
69 
70  const PeriodicBoundaryBase * b = this->boundary(boundary_id);
71  libmesh_assert (b);
72  p = b->get_corresponding_pos(p);
73 
74  std::set<const Elem *> candidate_elements;
75  point_locator.operator()(p, candidate_elements);
76 
77  // We might have found multiple elements, e.g. if two distinct periodic
78  // boundaries are overlapping (see systems_of_equations_ex9, for example).
79  // As a result, we need to search for the element that has boundary_id.
80  const MeshBase & mesh = point_locator.get_mesh();
81  for(const Elem * elem_it : candidate_elements)
82  {
83  unsigned int s_neigh =
84  mesh.get_boundary_info().side_with_boundary_id(elem_it, b->pairedboundary);
85 
86  // If s_neigh is not invalid then we have found an element that contains
87  // boundary_id, so return this element
88  if(s_neigh != libMesh::invalid_uint)
89  {
90  return elem_it;
91  }
92  }
93 
94  libmesh_error_msg("Periodic boundary neighbor not found");
95  return nullptr;
96 }
97 
98 } // namespace libMesh
99 
100 
101 
102 
103 
104 #endif // LIBMESH_ENABLE_PERIODIC
const unsigned int invalid_uint
Definition: libmesh.h:245
unsigned short int side
Definition: xdr_io.C:50
The base class for all geometric element types.
Definition: elem.h:100
MeshBase & mesh
PeriodicBoundaryBase * boundary(boundary_id_type id)
IterBase * end
Base class for Mesh.
Definition: mesh_base.h:77
virtual std::unique_ptr< Elem > build_side_ptr(const unsigned int i, bool proxy=true)=0
virtual Point get_corresponding_pos(const Point &pt) const =0
int8_t boundary_id_type
Definition: id_types.h:51
const Elem * neighbor(boundary_id_type boundary_id, const PointLocatorBase &point_locator, const Elem *e, unsigned int side) const
Base class for all PeriodicBoundary implementations.
A geometric point in (x,y,z) space.
Definition: point.h:38
const MeshBase & get_mesh() const