1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2020 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_BASE_H
21 #define LIBMESH_TREE_BASE_H
22 
23 // Local includes
24 #include "libmesh/reference_counted_object.h"
25 #include "libmesh/id_types.h" // subdomain_id_type
26 #include "libmesh/libmesh_common.h" // TOLERANCE
27 
28 // C++ includes
29 #include <set>
30 #include <ostream>
31 
32 namespace libMesh
33 {
34 
35 
36 // Forward Declarations
37 class TreeBase;
38 class MeshBase;
39 class Point;
40 class Elem;
41 
42 
43 namespace Trees
44 {
45 /**
46  * \p enum defining how to build the tree.  \p NODES will populate the
47  * tree with nodes and then replace the nodes with element
48  * connectivity, \p ELEMENTS will populate the tree with the elements
49  * directly.  LOCAL_ELEMENTS will populate the tree only with elements
50  * from the current processor.  This experimental capability may be
51  * useful if you do not wish to include off-processor elements in the
52  * search for a Point.
53  *
54  * \author Daniel Dreyer
55  * \date 2003
56  * \brief Base class for different Tree types.
57  */
58 enum BuildType {NODES=0,
59                 ELEMENTS,
60                 LOCAL_ELEMENTS,
61                 INVALID_BUILD_TYPE };
62 }
63 
64 /**
65  * This is the base class for trees, it allows pointer
66  * usage of trees.
67  */
68 class TreeBase : public ReferenceCountedObject<TreeBase>
69 {
70 protected:
71   /**
72    * Constructor.  Protected.
73    */
74   explicit
TreeBase(const MeshBase & m)75   TreeBase (const MeshBase & m) : mesh(m) {}
76 
77 public:
78   /**
79    * Destructor.
80    */
81   virtual ~TreeBase() = default;
82 
83   /**
84    * Prints the nodes.
85    */
86   virtual void print_nodes(std::ostream & out=libMesh::out) const = 0;
87 
88   /**
89    * Prints the nodes.
90    */
91   virtual void print_elements(std::ostream & out=libMesh::out) const = 0;
92 
93   /**
94    * \returns The number of active bins.
95    */
96   virtual unsigned int n_active_bins() const = 0;
97 
98   /**
99    * \returns A pointer to the element containing point p,
100    * optionally restricted to a set of allowed subdomains,
101    * optionally using a non-zero relative tolerance for searches.
102    */
103   virtual const Elem * find_element(const Point & p,
104                                     const std::set<subdomain_id_type> * allowed_subdomains = nullptr,
105                                     Real relative_tol = TOLERANCE) const = 0;
106 
107   /**
108    * Fills \p candidate_elements with any elements containing the
109    * specified point \p p,
110    * optionally restricted to a set of allowed subdomains,
111    * optionally using a non-default relative tolerance for searches.
112    */
113   virtual void find_elements(const Point & p,
114                              std::set<const Elem *> & candidate_elements,
115                              const std::set<subdomain_id_type> * allowed_subdomains = nullptr,
116                              Real relative_tol = TOLERANCE) const = 0;
117 
118 protected:
119 
120   /**
121    * Constant reference to a mesh.  Declared
122    * at construction.
123    */
124   const MeshBase & mesh;
125 };
126 
127 } // namespace libMesh
128 
129 
130 #endif // LIBMESH_TREE_BASE_H
131