tree_node.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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 #ifndef LIBMESH_TREE_NODE_H
21 #define LIBMESH_TREE_NODE_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/point.h"
26 
27 // C++ includes
28 #include <cstddef>
29 #include <vector>
30 
31 namespace libMesh
32 {
33 
34 // Forward Declarations
35 class MeshBase;
36 class Node;
37 class Elem;
38 
45 template <unsigned int N>
46 class TreeNode
47 {
48 public:
49 
50 
56  TreeNode (const MeshBase& m,
57  const unsigned int tbs,
58  const TreeNode<N> *p = NULL);
59 
65  ~TreeNode ();
66 
71  bool is_root() const { return (parent == NULL); }
72 
77  bool active() const { return children.empty(); }
78 
82  void insert (const Node* nd);
83 
87  void insert (const Elem* nd);
88 
93  void refine ();
94 
98  void set_bounding_box (const std::pair<Point, Point>& bbox);
99 
104  bool bounds_node (const Node* nd) const
105  { libmesh_assert(nd); return bounds_point(*nd); }
106 
111  bool bounds_point (const Point &p) const;
112 
116  unsigned int level () const;
117 
122  void print_nodes(std::ostream& out=libMesh::out) const;
123 
128  void print_elements(std::ostream& out=libMesh::out) const;
129 
133  void transform_nodes_to_elements (std::vector<std::vector<const Elem*> >&
134  nodes_to_elem);
135 
140  unsigned int n_active_bins() const;
141 
145  const Elem* find_element (const Point& p) const;
146 
147 
148 private:
149 
150 
154  const Elem* find_element_in_children (const Point& p) const;
155 
159  std::pair<Point, Point> create_bounding_box (const unsigned int c) const;
160 
164  const MeshBase& mesh;
165 
170  const unsigned int tgt_bin_size;
171 
176 
181  std::vector<TreeNode<N>* > children;
182 
188  std::pair<Point, Point> bounding_box;
189 
193  std::vector<const Elem*> elements;
194 
198  std::vector<const Node*> nodes;
199 
204 
205 };
206 
207 
208 
209 
210 
211 // ------------------------------------------------------------
212 // TreeNode class inline methods
213 template <unsigned int N>
214 inline
216  const unsigned int tbs,
217  const TreeNode<N>* p) :
218  mesh (m),
219  tgt_bin_size (tbs),
220  parent (p),
221  contains_ifems (false)
222 {
223  // libmesh_assert our children are empty, thus we are active.
224  libmesh_assert (children.empty());
225  libmesh_assert (this->active());
226 
227  // Reserve space for the nodes & elements
228  nodes.reserve (tgt_bin_size);
229  elements.reserve (tgt_bin_size);
230 }
231 
232 
233 
234 template <unsigned int N>
235 inline
237 {
238  // When we are destructed we must delete all of our
239  // children. They will this delete their children,
240  // All the way down the line...
241  for (unsigned int c=0; c<children.size(); c++)
242  delete children[c];
243 }
244 
245 
246 
247 template <unsigned int N>
248 inline
249 unsigned int TreeNode<N>::level () const
250 {
251  if (parent != NULL)
252  return parent->level()+1;
253 
254  // if we have no parent, we are a level-0 box
255  return 0;
256 }
257 
258 
259 } // namespace libMesh
260 
261 
262 #endif // LIBMESH_TREE_NODE_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:07 UTC

Hosted By:
SourceForge.net Logo