libMesh
tree.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 // C++ includes
21 
22 // Local includes
23 #include "libmesh/tree.h"
24 #include "libmesh/mesh_base.h"
25 #include "libmesh/mesh_tools.h"
26 
27 namespace libMesh
28 {
29 
30 
31 
32 // ------------------------------------------------------------
33 // Tree class method
34 
35 // constructor
36 template <unsigned int N>
38  unsigned int target_bin_size,
39  const Trees::BuildType bt) :
40  TreeBase(m),
41  root(m,target_bin_size),
42  build_type(bt)
43 {
44  // Set the root node bounding box equal to the bounding
45  // box for the entire domain.
46  root.set_bounding_box (MeshTools::create_bounding_box(mesh));
47 
48  if (build_type == Trees::NODES)
49  {
50  // Add all the nodes to the root node. It will
51  // automagically build the tree for us.
52  for (const auto & node : mesh.node_ptr_range())
53  {
54 #ifndef NDEBUG
55  bool node_was_inserted =
56 #endif
57  root.insert (node);
58  libmesh_assert(node_was_inserted);
59  }
60 
61  // Now the tree contains the nodes.
62  // However, we want element pointers, so here we
63  // convert between the two.
64  std::vector<std::vector<const Elem *>> nodes_to_elem;
65 
67  root.transform_nodes_to_elements (nodes_to_elem);
68  }
69 
70  else if (build_type == Trees::ELEMENTS)
71  {
72  // Add all active elements to the root node. It will
73  // automatically build the tree for us.
74  for (const auto & elem : mesh.active_element_ptr_range())
75  {
76 #ifndef NDEBUG
77  bool elem_was_inserted =
78 #endif
79  root.insert (elem);
80  libmesh_assert(elem_was_inserted);
81  }
82  }
83 
85  {
86  // Add all active, local elements to the root node. It will
87  // automatically build the tree for us.
88  for (const auto & elem : mesh.active_local_element_ptr_range())
89  {
90 #ifndef NDEBUG
91  bool elem_was_inserted =
92 #endif
93  root.insert (elem);
94  libmesh_assert(elem_was_inserted);
95  }
96  }
97 
98  else
99  libmesh_error_msg("Unknown build_type = " << build_type);
100 }
101 
102 
103 
104 // copy-constructor is not implemented
105 template <unsigned int N>
106 Tree<N>::Tree (const Tree<N> & other_tree) :
107  TreeBase (other_tree),
108  root (other_tree.root),
109  build_type (other_tree.build_type)
110 {
111  libmesh_not_implemented();
112 }
113 
114 
115 
116 
117 
118 
119 template <unsigned int N>
120 void Tree<N>::print_nodes(std::ostream & my_out) const
121 {
122  my_out << "Printing nodes...\n";
123  root.print_nodes(my_out);
124 }
125 
126 
127 
128 template <unsigned int N>
129 void Tree<N>::print_elements(std::ostream & my_out) const
130 {
131  my_out << "Printing elements...\n";
132  root.print_elements(my_out);
133 }
134 
135 
136 
137 template <unsigned int N>
138 const Elem *
140  const std::set<subdomain_id_type> * allowed_subdomains,
141  Real relative_tol) const
142 {
143  return root.find_element(p, allowed_subdomains, relative_tol);
144 }
145 
146 
147 
148 template <unsigned int N>
149 const Elem *
151  const std::set<subdomain_id_type> * allowed_subdomains,
152  Real relative_tol) const
153 {
154  return this->find_element(p, allowed_subdomains, relative_tol);
155 }
156 
157 
158 // ------------------------------------------------------------
159 // Explicit Instantiations
160 template class Tree<2>;
161 template class Tree<4>;
162 template class Tree<8>;
163 
164 } // namespace libMesh
TreeNode< N > root
The tree root.
Definition: tree.h:102
This class defines a tree that may be used for fast point location in space.
Definition: tree.h:44
libMesh::BoundingBox create_bounding_box(const MeshBase &mesh)
The same functionality as the deprecated MeshTools::bounding_box().
Definition: mesh_tools.C:329
virtual const Elem * find_element(const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=libmesh_nullptr, Real relative_tol=TOLERANCE) const libmesh_override
Definition: tree.C:139
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
void build_nodes_to_elem_map(const MeshBase &mesh, std::vector< std::vector< dof_id_type >> &nodes_to_elem_map)
After calling this function the input vector nodes_to_elem_map will contain the node to element conne...
Definition: mesh_tools.C:257
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
The libMesh namespace provides an interface to certain functionality in the library.
This is the MeshBase class.
Definition: mesh_base.h:68
libmesh_assert(j)
const MeshBase & mesh
Constant reference to a mesh.
Definition: tree_base.h:110
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
virtual SimpleRange< node_iterator > node_ptr_range()=0
virtual void print_elements(std::ostream &my_out=libMesh::out) const libmesh_override
Prints the nodes.
Definition: tree.C:129
virtual void print_nodes(std::ostream &my_out=libMesh::out) const libmesh_override
Prints the nodes.
Definition: tree.C:120
Tree(const MeshBase &m, unsigned int target_bin_size, Trees::BuildType bt=Trees::NODES)
Constructor.
Definition: tree.C:37
This is the base class for trees, it allows pointer usage of trees.
Definition: tree_base.h:65
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Elem * operator()(const Point &p, const std::set< subdomain_id_type > *allowed_subdomains=libmesh_nullptr, Real relative_tol=TOLERANCE) const
Definition: tree.C:150
BuildType
enum defining how to build the tree.
Definition: tree_base.h:55
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
const Trees::BuildType build_type
How the tree is built.
Definition: tree.h:107