Garfield 0.3
Toolkit for the detailed simulation of particle detectors based on ionization measurement in gases and semiconductors
Loading...
Searching...
No Matches
TetrahedralTree.hh
Go to the documentation of this file.
1// Include this header if we're compiling with the GPU or this is the first time
2// without
3#if defined(__GPUCOMPILE__) || !defined(TETRAHEDRAL_TREE_H)
4
5#if !defined(__GPUCOMPILE__) && !defined(TETRAHEDRAL_TREE_H)
6#define TETRAHEDRAL_TREE_H
7#endif
8
10#include "Garfield/Vector.hh"
11
12#if defined(__GPUCOMPILE__)
13#include "GPUInterface.hh"
14#else
15class TetrahedralTreeGPU;
16#endif
17
18#include <cstddef>
19#include <utility>
20#include <vector>
21
22namespace Garfield {
23
24#ifdef __GPUCOMPILE__
26#else
28#endif
29
42class GARFIELD_CLASS_NAME(TetrahedralTree) {
43 public:
44#ifdef __GPUCOMPILE__
45 // Constructor
46 GARFIELD_CLASS_NAME(TetrahedralTree)() = default;
47
48 // Destructor
49 ~GARFIELD_CLASS_NAME(TetrahedralTree)() = default;
50#else
51 // Constructor
52 GARFIELD_CLASS_NAME(TetrahedralTree)(const Vec3& origin,
53 const Vec3& halfDimension);
54
56 ~GARFIELD_CLASS_NAME(TetrahedralTree)();
57#endif
58
59#ifndef __GPUCOMPILE__
60 // Insert a mesh node (a vertex/point) to the tree
61 void InsertMeshNode(Vec3 point, const int index);
62
64 void InsertMeshElement(const double bb[6], const int index);
65
67 double CreateGPUTransferObject(TetrahedralTreeGPU*& tree_gpu);
68#endif
69
70 private:
71 static std::vector<int> emptyBlock;
72
73 // Physical centre of this tree node.
74 Vec3 m_origin;
75 // Half the width/height/depth of this tree node.
76 Vec3 m_halfDimension;
77 // Storing min and max points for convenience
78 Vec3 m_min, m_max;
79
80 // The tree has up to eight children and can additionally store
81 // a list of mesh nodes and mesh elements.
82 // Pointers to child octants.
83 GARFIELD_CLASS_NAME(TetrahedralTree) * children[8];
84
85 // Children follow a predictable pattern to make accesses simple.
86 // Here, - means less than 'origin' in that dimension, + means greater than.
87 // child: 0 1 2 3 4 5 6 7
88 // x: - - - - + + + +
89 // y: - - + + - - + +
90 // z: - + - + - + - +
91
92#ifndef __GPUCOMPILE__
93 std::vector<std::pair<Vec3, int> > nodes;
94#endif
95
96#ifdef __GPUCOMPILE__
97 int* elements{nullptr};
98 int numelements{0};
99#else
100 std::vector<int> elements;
101#endif
102
103 static const size_t BlockCapacity = 10;
104
105#ifndef __GPUCOMPILE__
106 // Check if the given box overlaps with this tree node.
107 bool DoesBoxOverlap(const double bb[6]) const;
108#endif
109 // Check if this tree node is a leaf or intermediate node.
110 __DEVICE__ bool IsLeafNode() const;
111
112 public:
113// Get all tetrahedra linked to a block corresponding to the given point
114#ifdef __GPUCOMPILE__
115 __device__ void GetElementsInBlock(const Vec3& point,
116 const int*& tet_list_elems,
117 int& num_elems) const;
118#else
119 const std::vector<int>& GetElementsInBlock(const Vec3& point) const;
120#endif
121
122 private:
123 __DEVICE__ int GetOctantContainingPoint(const Vec3& point) const;
124 // Get a block containing the input point
125 __DEVICE__ const GARFIELD_CLASS_NAME(TetrahedralTree) *
126 GetBlockFromPoint(const Vec3& point) const;
127 // A helper function used by the function above.
128 // Called recursively on the child nodes.
129 __DEVICE__ const GARFIELD_CLASS_NAME(TetrahedralTree) *
130 GetBlockFromPointHelper(const Vec3& point) const;
131
132#ifdef __GPUCOMPILE__
133 friend class TetrahedralTree;
134#endif
135};
136
137} // namespace Garfield
138
139#endif
#define GARFIELD_CLASS_NAME(name)
#define __DEVICE__
#define __device__
Definition Vector.hh:12
class GARFIELD_CLASS_NAME(Component)
Abstract base class for components.
Definition Component.hh:31
Vec3Impl< double > Vec3