tree_node.h
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_TREE_NODE_H 00021 #define LIBMESH_TREE_NODE_H 00022 00023 // Local includes 00024 #include "libmesh/libmesh_common.h" 00025 #include "libmesh/point.h" 00026 00027 // C++ includes 00028 #include <cstddef> 00029 #include <vector> 00030 00031 namespace libMesh 00032 { 00033 00034 // Forward Declarations 00035 class MeshBase; 00036 class Node; 00037 class Elem; 00038 00045 template <unsigned int N> 00046 class TreeNode 00047 { 00048 public: 00049 00050 00056 TreeNode (const MeshBase& m, 00057 const unsigned int tbs, 00058 const TreeNode<N> *p = NULL); 00059 00065 ~TreeNode (); 00066 00071 bool is_root() const { return (parent == NULL); } 00072 00077 bool active() const { return children.empty(); } 00078 00082 void insert (const Node* nd); 00083 00087 void insert (const Elem* nd); 00088 00093 void refine (); 00094 00098 void set_bounding_box (const std::pair<Point, Point>& bbox); 00099 00104 bool bounds_node (const Node* nd) const 00105 { libmesh_assert(nd); return bounds_point(*nd); } 00106 00111 bool bounds_point (const Point &p) const; 00112 00116 unsigned int level () const; 00117 00122 void print_nodes(std::ostream& out=libMesh::out) const; 00123 00128 void print_elements(std::ostream& out=libMesh::out) const; 00129 00133 void transform_nodes_to_elements (std::vector<std::vector<const Elem*> >& 00134 nodes_to_elem); 00135 00140 unsigned int n_active_bins() const; 00141 00145 const Elem* find_element (const Point& p) const; 00146 00147 00148 private: 00149 00150 00154 const Elem* find_element_in_children (const Point& p) const; 00155 00159 std::pair<Point, Point> create_bounding_box (const unsigned int c) const; 00160 00164 const MeshBase& mesh; 00165 00170 const unsigned int tgt_bin_size; 00171 00175 const TreeNode<N> *parent; 00176 00181 std::vector<TreeNode<N>* > children; 00182 00188 std::pair<Point, Point> bounding_box; 00189 00193 std::vector<const Elem*> elements; 00194 00198 std::vector<const Node*> nodes; 00199 00203 bool contains_ifems; 00204 00205 }; 00206 00207 00208 00209 00210 00211 // ------------------------------------------------------------ 00212 // TreeNode class inline methods 00213 template <unsigned int N> 00214 inline 00215 TreeNode<N>::TreeNode (const MeshBase& m, 00216 const unsigned int tbs, 00217 const TreeNode<N>* p) : 00218 mesh (m), 00219 tgt_bin_size (tbs), 00220 parent (p), 00221 contains_ifems (false) 00222 { 00223 // libmesh_assert our children are empty, thus we are active. 00224 libmesh_assert (children.empty()); 00225 libmesh_assert (this->active()); 00226 00227 // Reserve space for the nodes & elements 00228 nodes.reserve (tgt_bin_size); 00229 elements.reserve (tgt_bin_size); 00230 } 00231 00232 00233 00234 template <unsigned int N> 00235 inline 00236 TreeNode<N>::~TreeNode () 00237 { 00238 // When we are destructed we must delete all of our 00239 // children. They will this delete their children, 00240 // All the way down the line... 00241 for (unsigned int c=0; c<children.size(); c++) 00242 delete children[c]; 00243 } 00244 00245 00246 00247 template <unsigned int N> 00248 inline 00249 unsigned int TreeNode<N>::level () const 00250 { 00251 if (parent != NULL) 00252 return parent->level()+1; 00253 00254 // if we have no parent, we are a level-0 box 00255 return 0; 00256 } 00257 00258 00259 } // namespace libMesh 00260 00261 00262 #endif // LIBMESH_TREE_NODE_H
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:49 UTC
Hosted By: