$extrastylesheet
tree.C
Go to the documentation of this file.
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 // C++ includes
00021 
00022 // Local includes
00023 #include "libmesh/tree.h"
00024 #include "libmesh/mesh_base.h"
00025 #include "libmesh/mesh_tools.h"
00026 
00027 namespace libMesh
00028 {
00029 
00030 
00031 
00032 // ------------------------------------------------------------
00033 // Tree class method
00034 
00035 // constructor
00036 template <unsigned int N>
00037 Tree<N>::Tree (const MeshBase& m,
00038                unsigned int target_bin_size,
00039                const Trees::BuildType bt) :
00040   TreeBase(m),
00041   root(m,target_bin_size),
00042   build_type(bt)
00043 {
00044   // Set the root node bounding box equal to the bounding
00045   // box for the entire domain.
00046   root.set_bounding_box (MeshTools::bounding_box(mesh));
00047 
00048   if (build_type == Trees::NODES)
00049     {
00050       // Add all the nodes to the root node.  It will
00051       // automagically build the tree for us.
00052       MeshBase::const_node_iterator       it  = mesh.nodes_begin();
00053       const MeshBase::const_node_iterator end = mesh.nodes_end();
00054 
00055       for (; it != end; ++it)
00056         {
00057 #ifndef NDEBUG
00058           bool node_was_inserted =
00059 #endif
00060             root.insert (*it);
00061           libmesh_assert(node_was_inserted);
00062         }
00063 
00064       // Now the tree contains the nodes.
00065       // However, we want element pointers, so here we
00066       // convert between the two.
00067       std::vector<std::vector<const Elem*> > nodes_to_elem;
00068 
00069       MeshTools::build_nodes_to_elem_map (mesh, nodes_to_elem);
00070       root.transform_nodes_to_elements (nodes_to_elem);
00071     }
00072 
00073   else if (build_type == Trees::ELEMENTS)
00074     {
00075       // Add all active elements to the root node.  It will
00076       // automatically build the tree for us.
00077       MeshBase::const_element_iterator       it  = mesh.active_elements_begin();
00078       const MeshBase::const_element_iterator end = mesh.active_elements_end();
00079 
00080       for (; it != end; ++it)
00081         {
00082 #ifndef NDEBUG
00083           bool elem_was_inserted =
00084 #endif
00085             root.insert (*it);
00086           libmesh_assert(elem_was_inserted);
00087         }
00088     }
00089 
00090   else if (build_type == Trees::LOCAL_ELEMENTS)
00091     {
00092       // Add all active, local elements to the root node.  It will
00093       // automatically build the tree for us.
00094       MeshBase::const_element_iterator       it  = mesh.active_local_elements_begin();
00095       const MeshBase::const_element_iterator end = mesh.active_local_elements_end();
00096 
00097       for (; it != end; ++it)
00098         {
00099 #ifndef NDEBUG
00100           bool elem_was_inserted =
00101 #endif
00102             root.insert (*it);
00103           libmesh_assert(elem_was_inserted);
00104         }
00105     }
00106 
00107   else
00108     libmesh_error_msg("Unknown build_type = " << build_type);
00109 }
00110 
00111 
00112 
00113 // copy-constructor is not implemented
00114 template <unsigned int N>
00115 Tree<N>::Tree (const Tree<N>& other_tree) :
00116   TreeBase   (other_tree),
00117   root       (other_tree.root),
00118   build_type (other_tree.build_type)
00119 {
00120   libmesh_not_implemented();
00121 }
00122 
00123 
00124 
00125 
00126 
00127 
00128 template <unsigned int N>
00129 void Tree<N>::print_nodes(std::ostream& my_out) const
00130 {
00131   my_out << "Printing nodes...\n";
00132   root.print_nodes(my_out);
00133 }
00134 
00135 
00136 
00137 template <unsigned int N>
00138 void Tree<N>::print_elements(std::ostream& my_out) const
00139 {
00140   my_out << "Printing elements...\n";
00141   root.print_elements(my_out);
00142 }
00143 
00144 
00145 
00146 template <unsigned int N>
00147 const Elem*
00148 Tree<N>::find_element
00149 (const Point& p,
00150  const std::set<subdomain_id_type> *allowed_subdomains,
00151  Real relative_tol) const
00152 {
00153   return root.find_element(p, allowed_subdomains, relative_tol);
00154 }
00155 
00156 
00157 
00158 template <unsigned int N>
00159 const Elem*
00160 Tree<N>::operator() (const Point& p,
00161                      const std::set<subdomain_id_type> *allowed_subdomains,
00162                      Real relative_tol) const
00163 {
00164   return this->find_element(p, allowed_subdomains, relative_tol);
00165 }
00166 
00167 
00168 // ------------------------------------------------------------
00169 // Explicit Instantiations
00170 template class Tree<2>;
00171 template class Tree<4>;
00172 template class Tree<8>;
00173 
00174 } // namespace libMesh