Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Solid.hh
Go to the documentation of this file.
1#ifndef G_SOLID_H
2#define G_SOLID_H
3
4#include <vector>
5#include <array>
6
7namespace Garfield {
8
9/// Surface panel.
10
11struct Panel {
12 /// Perpendicular vector
13 double a, b, c;
14 /// X-coordinates of vertices
15 std::vector<double> xv;
16 /// Y-coordinates of vertices
17 std::vector<double> yv;
18 /// Z-coordinates of vertices
19 std::vector<double> zv;
20 /// Colour index
21 double colour;
22 /// Reference to solid to which the panel belongs
23 int volume;
24};
25
26/// Abstract base class for solids.
27
28class Solid {
29 public:
30 /// Default constructor.
31 Solid() = delete;
32 /// Constructor.
33 Solid(const double cx, const double cy, const double cz,
34 const std::string& name)
35 : m_cX(cx), m_cY(cy), m_cZ(cz), m_className(name) {
36 m_id = s_id++;
37 }
38
39 /// Destructor
40 virtual ~Solid() {}
41
42 /// Check whether a given point is inside the solid.
43 virtual bool IsInside(const double x, const double y,
44 const double z) const = 0;
45 /// Return the bounding box of the solid.
46 virtual bool GetBoundingBox(double& xmin, double& ymin, double& zmin,
47 double& xmax, double& ymax,
48 double& zmax) const = 0;
49 /// Return true if the solid is a box.
50 virtual bool IsBox() const { return false; }
51 /// Return true if the solid is a tube.
52 virtual bool IsTube() const { return false; }
53 /// Return true if the solid is a sphere.
54 virtual bool IsSphere() const { return false; }
55 /// Return true if the solid is a hole.
56 virtual bool IsHole() const { return false; }
57 /// Return true if the solid is a ridge.
58 virtual bool IsRidge() const { return false; }
59
60 /// Retrieve the centre point of the solid.
61 bool GetCentre(double& x, double& y, double& z) const {
62 x = m_cX;
63 y = m_cY;
64 z = m_cZ;
65 return true;
66 }
67 /// Retrieve the orientation (azimuthal and polar angles) of the solid.
68 bool GetOrientation(double& ctheta, double& stheta, double& cphi,
69 double& sphi) const {
70 ctheta = m_cTheta;
71 stheta = m_sTheta;
72 cphi = m_cPhi;
73 sphi = m_sPhi;
74 return true;
75 }
76
77 /// Return the half-length along x.
78 virtual double GetHalfLengthX() const {
79 return NotImplemented("GetHalfLengthX");
80 }
81 /// Return the half-length along y.
82 virtual double GetHalfLengthY() const {
83 return NotImplemented("GetHalfLengthY");
84 }
85 /// Return the half-length along z.
86 virtual double GetHalfLengthZ() const {
87 return NotImplemented("GetHalfLengthZ");
88 }
89 /// Return the inner radius.
90 virtual double GetInnerRadius() const {
91 return NotImplemented("GetInnerRadius");
92 }
93 /// Return the outer radius.
94 virtual double GetOuterRadius() const {
95 return NotImplemented("GetOuterRadius");
96 }
97 /// Return the radius.
98 virtual double GetRadius() const { return NotImplemented("GetRadius"); }
99 /// Return the lower radius (of a hole).
100 virtual double GetLowerRadius() const {
101 return NotImplemented("GetLowerRadius");
102 }
103 /// Return the upper radius (of a hole).
104 virtual double GetUpperRadius() const {
105 return NotImplemented("GetUpperRadius");
106 }
107 /// Return the x-offset of a ridge.
108 virtual double GetRidgeOffset() const {
109 return NotImplemented("GetRidgeOffset");
110 }
111 /// Return the height of a ridge.
112 virtual double GetRidgeHeight() const {
113 return NotImplemented("GetRidgeHeight");
114 }
115
116 /// Get the ID of the solid.
117 unsigned int GetId() const { return m_id; }
118
119 /// Retrieve the surface panels of the solid.
120 virtual bool SolidPanels(std::vector<Panel>& panels) = 0;
121
122 /// Retrieve the discretization level of a panel.
123 virtual double GetDiscretisationLevel(const Panel& panel) = 0;
124
133 };
134
135 /// Apply Dirichlet boundary conditions (fixed voltage).
136 void SetBoundaryPotential(const double v) {
137 m_volt = v;
139 }
140 /// Apply fixed-charge boundary conditions.
141 void SetBoundaryChargeDensity(const double q) {
142 m_charge = q;
144 }
145 /// Make the potential at the surface of the solid floating.
147 /// Make the surfaces of the solid dielectric-dielectric interfaces.
151
152 /// Retrieve the type of boundary condition.
154 /// Retrieve the potential.
155 double GetBoundaryPotential() const { return m_volt; }
156 /// Retrieve the surface charge density.
157 double GetBoundaryChargeDensity() const { return m_charge; }
158
159 /// Switch debugging messages on/off.
160 void EnableDebugging(const bool on = true) { m_debug = on; }
161
162 protected:
163 /// Centre of the solid.
164 double m_cX = 0., m_cY = 0., m_cZ = 0.;
165
166 /// Direction vector.
167 double m_dX = 0., m_dY = 0., m_dZ = 1.;
168 /// Azimuthal angle.
169 double m_cPhi = 1., m_sPhi = 0.;
170 /// Polar angle.
171 double m_cTheta = 1., m_sTheta = 0.;
172
173 /// Class name.
174 std::string m_className = "Solid";
175
176 /// Debug flag.
177 bool m_debug = false;
178
179 /// Type of boundary condition.
181 /// Potential at the surface.
182 double m_volt = 0.;
183 /// Surface charge density.
184 double m_charge = 0.;
185 /// Dielectric constant.
186 double m_eps = 0.;
187
188 /// Transform a point from global coordinates (x, y, z)
189 /// to local coordinates (u, v, w).
190 void ToLocal(const double x, const double y, const double z, double& u,
191 double& v, double& w) const {
192 const double dx = x - m_cX;
193 const double dy = y - m_cY;
194 const double dz = z - m_cZ;
195
196 u = m_cPhi * m_cTheta * dx + m_sPhi * m_cTheta * dy - m_sTheta * dz;
197 v = -m_sPhi * dx + m_cPhi * dy;
198 w = m_cPhi * m_sTheta * dx + m_sPhi * m_sTheta * dy + m_cTheta * dz;
199 }
200 /// Transform a point from local coordinates (u, v, w)
201 /// to global coordinates (x, y, z).
202 void ToGlobal(const double u, const double v, const double w, double& x,
203 double& y, double& z) const {
204 x = m_cX + m_cPhi * m_cTheta * u - m_sPhi * v + m_cPhi * m_sTheta * w;
205 y = m_cY + m_sPhi * m_cTheta * u + m_cPhi * v + m_sPhi * m_sTheta * w;
206 z = m_cZ - m_sTheta * u + m_cTheta * w;
207 }
208 /// Transform a vector from global to local coordinates.
209 void VectorToLocal(const double x, const double y, const double z,
210 double& u, double& v, double& w) {
211 u = m_cPhi * m_cTheta * x + m_sPhi * m_cTheta * y - m_sTheta * z;
212 v = -m_sPhi * x + m_cPhi * y;
213 w = m_cPhi * m_sTheta * x + m_sPhi * m_sTheta * y + m_cTheta * z;
214 }
215
216 void SetDirection(const double dx, const double dy, const double dz);
217
218 private:
219 double NotImplemented(const std::string& fcn) const;
220 /// ID counter.
221 static unsigned int s_id;
222 /// ID of the solid.
223 unsigned int m_id;
224};
225}
226
227#endif
Abstract base class for solids.
Definition: Solid.hh:28
void SetBoundaryChargeDensity(const double q)
Apply fixed-charge boundary conditions.
Definition: Solid.hh:141
double m_dZ
Definition: Solid.hh:167
void EnableDebugging(const bool on=true)
Switch debugging messages on/off.
Definition: Solid.hh:160
virtual double GetUpperRadius() const
Return the upper radius (of a hole).
Definition: Solid.hh:104
double m_charge
Surface charge density.
Definition: Solid.hh:184
virtual bool IsTube() const
Return true if the solid is a tube.
Definition: Solid.hh:52
virtual bool IsRidge() const
Return true if the solid is a ridge.
Definition: Solid.hh:58
double m_cZ
Definition: Solid.hh:164
virtual double GetHalfLengthX() const
Return the half-length along x.
Definition: Solid.hh:78
virtual bool IsHole() const
Return true if the solid is a hole.
Definition: Solid.hh:56
void VectorToLocal(const double x, const double y, const double z, double &u, double &v, double &w)
Transform a vector from global to local coordinates.
Definition: Solid.hh:209
void SetBoundaryPotential(const double v)
Apply Dirichlet boundary conditions (fixed voltage).
Definition: Solid.hh:136
double m_eps
Dielectric constant.
Definition: Solid.hh:186
double m_cTheta
Polar angle.
Definition: Solid.hh:171
virtual double GetHalfLengthZ() const
Return the half-length along z.
Definition: Solid.hh:86
virtual ~Solid()
Destructor.
Definition: Solid.hh:40
virtual bool IsInside(const double x, const double y, const double z) const =0
Check whether a given point is inside the solid.
virtual bool IsBox() const
Return true if the solid is a box.
Definition: Solid.hh:50
virtual double GetHalfLengthY() const
Return the half-length along y.
Definition: Solid.hh:82
double m_dX
Direction vector.
Definition: Solid.hh:167
bool GetCentre(double &x, double &y, double &z) const
Retrieve the centre point of the solid.
Definition: Solid.hh:61
virtual double GetDiscretisationLevel(const Panel &panel)=0
Retrieve the discretization level of a panel.
unsigned int GetId() const
Get the ID of the solid.
Definition: Solid.hh:117
double GetBoundaryChargeDensity() const
Retrieve the surface charge density.
Definition: Solid.hh:157
@ DielectricCharge
Definition: Solid.hh:130
@ PerpendicularField
Definition: Solid.hh:132
void ToLocal(const double x, const double y, const double z, double &u, double &v, double &w) const
Definition: Solid.hh:190
void SetDirection(const double dx, const double dy, const double dz)
Definition: Solid.cc:12
BoundaryCondition GetBoundaryConditionType() const
Retrieve the type of boundary condition.
Definition: Solid.hh:153
Solid(const double cx, const double cy, const double cz, const std::string &name)
Constructor.
Definition: Solid.hh:33
virtual double GetRidgeOffset() const
Return the x-offset of a ridge.
Definition: Solid.hh:108
double m_volt
Potential at the surface.
Definition: Solid.hh:182
BoundaryCondition m_bctype
Type of boundary condition.
Definition: Solid.hh:180
virtual double GetLowerRadius() const
Return the lower radius (of a hole).
Definition: Solid.hh:100
virtual double GetOuterRadius() const
Return the outer radius.
Definition: Solid.hh:94
double m_sPhi
Definition: Solid.hh:169
double GetBoundaryPotential() const
Retrieve the potential.
Definition: Solid.hh:155
void SetBoundaryParallelField()
Definition: Solid.hh:149
bool GetOrientation(double &ctheta, double &stheta, double &cphi, double &sphi) const
Retrieve the orientation (azimuthal and polar angles) of the solid.
Definition: Solid.hh:68
void SetBoundaryPerpendicularField()
Definition: Solid.hh:150
void ToGlobal(const double u, const double v, const double w, double &x, double &y, double &z) const
Definition: Solid.hh:202
double m_sTheta
Definition: Solid.hh:171
double m_cY
Definition: Solid.hh:164
bool m_debug
Debug flag.
Definition: Solid.hh:177
virtual double GetRadius() const
Return the radius.
Definition: Solid.hh:98
virtual bool IsSphere() const
Return true if the solid is a sphere.
Definition: Solid.hh:54
virtual bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const =0
Return the bounding box of the solid.
double m_dY
Definition: Solid.hh:167
double m_cX
Centre of the solid.
Definition: Solid.hh:164
virtual double GetInnerRadius() const
Return the inner radius.
Definition: Solid.hh:90
virtual double GetRidgeHeight() const
Return the height of a ridge.
Definition: Solid.hh:112
double m_cPhi
Azimuthal angle.
Definition: Solid.hh:169
void SetBoundaryFloat()
Make the potential at the surface of the solid floating.
Definition: Solid.hh:146
virtual bool SolidPanels(std::vector< Panel > &panels)=0
Retrieve the surface panels of the solid.
std::string m_className
Class name.
Definition: Solid.hh:174
Solid()=delete
Default constructor.
void SetBoundaryDielectric()
Make the surfaces of the solid dielectric-dielectric interfaces.
Definition: Solid.hh:148
Surface panel.
Definition: Solid.hh:11
std::vector< double > zv
Z-coordinates of vertices.
Definition: Solid.hh:19
int volume
Reference to solid to which the panel belongs.
Definition: Solid.hh:23
double a
Perpendicular vector.
Definition: Solid.hh:13
double c
Definition: Solid.hh:13
double colour
Colour index.
Definition: Solid.hh:21
double b
Definition: Solid.hh:13
std::vector< double > xv
X-coordinates of vertices.
Definition: Solid.hh:15
std::vector< double > yv
Y-coordinates of vertices.
Definition: Solid.hh:17