Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2025 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> 37 12547 : Tree<N>::Tree (const MeshBase & m, 38 : unsigned int target_bin_size, 39 : const Trees::BuildType bt) : 40 : TreeBase(m), 41 11535 : root(m,target_bin_size), 42 12547 : build_type(bt) 43 : { 44 : // Set the root node bounding box equal to the bounding 45 : // box for the entire domain. 46 12547 : root.set_bounding_box (MeshTools::create_bounding_box(mesh)); 47 : 48 12547 : 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 8196 : for (const auto & node : mesh.node_ptr_range()) 53 : { 54 : #ifndef NDEBUG 55 2578 : bool node_was_inserted = 56 : #endif 57 4092 : root.insert (node); 58 2578 : 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 4 : std::unordered_map<dof_id_type, std::vector<const Elem *>> nodes_to_elem; 65 : 66 6 : MeshTools::build_nodes_to_elem_map (mesh, nodes_to_elem); 67 6 : root.transform_nodes_to_elements (nodes_to_elem); 68 : } 69 : 70 12541 : 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 2507863 : for (const auto & elem : mesh.active_element_ptr_range()) 75 : { 76 : #ifndef NDEBUG 77 182595 : bool elem_was_inserted = 78 : #endif 79 1235876 : root.insert (elem); 80 182595 : libmesh_assert(elem_was_inserted); 81 : } 82 : } 83 : 84 0 : else if (build_type == Trees::LOCAL_ELEMENTS) 85 : { 86 : // Add all active, local elements to the root node. It will 87 : // automatically build the tree for us. 88 0 : for (const auto & elem : mesh.active_local_element_ptr_range()) 89 : { 90 : #ifndef NDEBUG 91 0 : bool elem_was_inserted = 92 : #endif 93 0 : root.insert (elem); 94 0 : libmesh_assert(elem_was_inserted); 95 : } 96 : } 97 : 98 : else 99 0 : libmesh_error_msg("Unknown build_type = " << build_type); 100 12547 : } 101 : 102 : 103 : 104 : template <unsigned int N> 105 0 : void Tree<N>::print_nodes(std::ostream & my_out) const 106 : { 107 0 : my_out << "Printing nodes...\n"; 108 0 : root.print_nodes(my_out); 109 0 : } 110 : 111 : 112 : 113 : template <unsigned int N> 114 0 : void Tree<N>::print_elements(std::ostream & my_out) const 115 : { 116 0 : my_out << "Printing elements...\n"; 117 0 : root.print_elements(my_out); 118 0 : } 119 : 120 : 121 : 122 : template <unsigned int N> 123 : const Elem * 124 718491 : Tree<N>::find_element (const Point & p, 125 : const std::set<subdomain_id_type> * allowed_subdomains, 126 : Real relative_tol) const 127 : { 128 718491 : return root.find_element(p, allowed_subdomains, relative_tol); 129 : } 130 : 131 : 132 : 133 : template <unsigned int N> 134 : void 135 256693 : Tree<N>::find_elements (const Point & p, 136 : std::set<const Elem *> & candidate_elements, 137 : const std::set<subdomain_id_type> * allowed_subdomains, 138 : Real relative_tol) const 139 : { 140 256693 : return root.find_elements(p, candidate_elements, allowed_subdomains, relative_tol); 141 : } 142 : 143 : 144 : 145 : template <unsigned int N> 146 : const Elem * 147 0 : Tree<N>::operator() (const Point & p, 148 : const std::set<subdomain_id_type> * allowed_subdomains, 149 : Real relative_tol) const 150 : { 151 0 : return this->find_element(p, allowed_subdomains, relative_tol); 152 : } 153 : 154 : 155 : // ------------------------------------------------------------ 156 : // Explicit Instantiations 157 : template class LIBMESH_EXPORT Tree<2>; 158 : template class LIBMESH_EXPORT Tree<4>; 159 : template class LIBMESH_EXPORT Tree<8>; 160 : 161 : } // namespace libMesh