libMesh
periodic_boundaries.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 // Local Includes
19 #include "libmesh/libmesh_config.h"
20 
21 #ifdef LIBMESH_ENABLE_PERIODIC
22 
23 #include "libmesh/periodic_boundaries.h"
24 #include "libmesh/point_locator_base.h"
25 #include "libmesh/elem.h"
26 #include "libmesh/periodic_boundary.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
libMesh::invalid_uint
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:249
libMesh::PeriodicBoundaryBase::get_corresponding_pos
virtual Point get_corresponding_pos(const Point &pt) const =0
This function should be overridden by derived classes to define how one finds corresponding nodes on ...
libMesh::Elem::build_side_ptr
virtual std::unique_ptr< Elem > build_side_ptr(const unsigned int i, bool proxy=true)=0
libMesh::PeriodicBoundaryBase
The base class for defining periodic boundaries.
Definition: periodic_boundary_base.h:48
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
end
IterBase * end
Also have a polymorphic pointer to the end object, this prevents iterating past the end.
Definition: variant_filter_iterator.h:343
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::boundary_id_type
int8_t boundary_id_type
Definition: id_types.h:51
libMesh::PeriodicBoundaries::boundary
PeriodicBoundaryBase * boundary(boundary_id_type id)
Definition: periodic_boundaries.C:40
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::PeriodicBoundaries::~PeriodicBoundaries
~PeriodicBoundaries()
Definition: periodic_boundaries.C:32
libMesh::PointLocatorBase::get_mesh
const MeshBase & get_mesh() const
Get a const reference to this PointLocator's mesh.
Definition: point_locator_base.C:106
libMesh::PeriodicBoundaries::neighbor
const Elem * neighbor(boundary_id_type boundary_id, const PointLocatorBase &point_locator, const Elem *e, unsigned int side) const
Definition: periodic_boundaries.C:61
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
libMesh::PeriodicBoundaryBase::pairedboundary
boundary_id_type pairedboundary
Definition: periodic_boundary_base.h:58
libMesh::PointLocatorBase
This is the base class for point locators.
Definition: point_locator_base.h:62