$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 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 #include <set> 00031 00032 namespace libMesh 00033 { 00034 00035 // Forward Declarations 00036 class MeshBase; 00037 class Node; 00038 class Elem; 00039 00046 template <unsigned int N> 00047 class TreeNode 00048 { 00049 public: 00055 TreeNode (const MeshBase& m, 00056 unsigned int tbs, 00057 const TreeNode<N> *p = NULL); 00058 00064 ~TreeNode (); 00065 00070 bool is_root() const { return (parent == NULL); } 00071 00076 bool active() const { return children.empty(); } 00077 00083 bool insert (const Node* nd); 00084 00090 bool insert (const Elem* nd); 00091 00096 void refine (); 00097 00101 void set_bounding_box (const std::pair<Point, Point>& bbox); 00102 00107 bool bounds_node (const Node* nd, 00108 Real relative_tol = 0) const; 00109 00114 bool bounds_point (const Point &p, 00115 Real relative_tol = 0) const; 00116 00120 unsigned int level () const; 00121 00126 void print_nodes(std::ostream& out=libMesh::out) const; 00127 00132 void print_elements(std::ostream& out=libMesh::out) const; 00133 00137 void transform_nodes_to_elements (std::vector<std::vector<const Elem*> >& nodes_to_elem); 00138 00143 unsigned int n_active_bins() const; 00144 00149 const Elem* find_element (const Point& p, 00150 const std::set<subdomain_id_type>* allowed_subdomains = NULL, 00151 Real relative_tol = TOLERANCE) const; 00152 00153 00154 private: 00159 const Elem* find_element_in_children (const Point& p, 00160 const std::set<subdomain_id_type>* allowed_subdomains, 00161 Real relative_tol) const; 00162 00166 std::pair<Point, Point> create_bounding_box (unsigned int c) const; 00167 00171 const MeshBase& mesh; 00172 00176 const TreeNode<N> *parent; 00177 00182 std::vector<TreeNode<N>* > children; 00183 00189 std::pair<Point, Point> bounding_box; 00190 00194 std::vector<const Elem*> elements; 00195 00199 std::vector<const Node*> nodes; 00200 00205 const unsigned int tgt_bin_size; 00206 00210 bool contains_ifems; 00211 }; 00212 00213 00214 00215 00216 00217 // ------------------------------------------------------------ 00218 // TreeNode class inline methods 00219 template <unsigned int N> 00220 inline 00221 TreeNode<N>::TreeNode (const MeshBase& m, 00222 unsigned int tbs, 00223 const TreeNode<N>* p) : 00224 mesh (m), 00225 parent (p), 00226 tgt_bin_size (tbs), 00227 contains_ifems (false) 00228 { 00229 // libmesh_assert our children are empty, thus we are active. 00230 libmesh_assert (children.empty()); 00231 libmesh_assert (this->active()); 00232 00233 // Reserve space for the nodes & elements 00234 nodes.reserve (tgt_bin_size); 00235 elements.reserve (tgt_bin_size); 00236 } 00237 00238 00239 00240 template <unsigned int N> 00241 inline 00242 TreeNode<N>::~TreeNode () 00243 { 00244 // When we are destructed we must delete all of our 00245 // children. They will this delete their children, 00246 // All the way down the line... 00247 for (unsigned int c=0; c<children.size(); c++) 00248 delete children[c]; 00249 } 00250 00251 00252 00253 template <unsigned int N> 00254 inline 00255 unsigned int TreeNode<N>::level () const 00256 { 00257 if (parent != NULL) 00258 return parent->level()+1; 00259 00260 // if we have no parent, we are a level-0 box 00261 return 0; 00262 } 00263 00264 00265 } // namespace libMesh 00266 00267 00268 #endif // LIBMESH_TREE_NODE_H