Garfield++ 5.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
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 int 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. If requested,
43 /// use the tesselated approximation of the solid (if applicable).
44 virtual bool IsInside(const double x, const double y, const double z,
45 const bool tesselated = false) const = 0;
46 /// Return the bounding box of the solid.
47 virtual bool GetBoundingBox(double& xmin, double& ymin, double& zmin,
48 double& xmax, double& ymax,
49 double& zmax) const = 0;
50 /// Return true if the solid is a box.
51 virtual bool IsBox() const { return false; }
52 /// Return true if the solid is a tube.
53 virtual bool IsTube() const { return false; }
54 /// Return true if the solid is a sphere.
55 virtual bool IsSphere() const { return false; }
56 /// Return true if the solid is a hole.
57 virtual bool IsHole() const { return false; }
58 /// Return true if the solid is a ridge.
59 virtual bool IsRidge() const { return false; }
60 /// Return true if the solid is an extrusion.
61 virtual bool IsExtrusion() const { return false; }
62 /// Return true if the solid is a wire.
63 virtual bool IsWire() const { return false; }
64
65 /// Set a label.
66 void SetLabel(const std::string& label) { m_label = label; }
67 /// Return the label.
68 std::string GetLabel() const { return m_label; }
69
70 /// Retrieve the centre point of the solid.
71 bool GetCentre(double& x, double& y, double& z) const {
72 x = m_cX;
73 y = m_cY;
74 z = m_cZ;
75 return true;
76 }
77 /// Retrieve the direction vector.
78 bool GetDirection(double& dx, double& dy, double& dz) const {
79 dx = m_dX;
80 dy = m_dY;
81 dz = m_dZ;
82 return true;
83 }
84 /// Retrieve the orientation (azimuthal and polar angles) of the solid.
85 bool GetOrientation(double& ctheta, double& stheta, double& cphi,
86 double& sphi) const {
87 ctheta = m_cTheta;
88 stheta = m_sTheta;
89 cphi = m_cPhi;
90 sphi = m_sPhi;
91 return true;
92 }
93
94 /// Return the half-length along x.
95 virtual double GetHalfLengthX() const {
96 return NotImplemented("GetHalfLengthX");
97 }
98 /// Return the half-length along y.
99 virtual double GetHalfLengthY() const {
100 return NotImplemented("GetHalfLengthY");
101 }
102 /// Return the half-length along z.
103 virtual double GetHalfLengthZ() const {
104 return NotImplemented("GetHalfLengthZ");
105 }
106 /// Return the inner radius.
107 virtual double GetInnerRadius() const {
108 return NotImplemented("GetInnerRadius");
109 }
110 /// Return the outer radius.
111 virtual double GetOuterRadius() const {
112 return NotImplemented("GetOuterRadius");
113 }
114 /// Return the radius.
115 virtual double GetRadius() const { return NotImplemented("GetRadius"); }
116 /// Return the lower radius (of a hole).
117 virtual double GetLowerRadius() const {
118 return NotImplemented("GetLowerRadius");
119 }
120 /// Return the upper radius (of a hole).
121 virtual double GetUpperRadius() const {
122 return NotImplemented("GetUpperRadius");
123 }
124 /// Return the x-offset of a ridge.
125 virtual double GetRidgeOffset() const {
126 return NotImplemented("GetRidgeOffset");
127 }
128 /// Return the height of a ridge.
129 virtual double GetRidgeHeight() const {
130 return NotImplemented("GetRidgeHeight");
131 }
132 /// Get the vertices defining an extrusion.
133 virtual bool GetProfile(std::vector<double>& xv,
134 std::vector<double>& yv) const;
135
136 /// Get the ID of the solid.
137 unsigned int GetId() const { return m_id; }
138
139 /// Retrieve the surface panels of the solid.
140 virtual bool SolidPanels(std::vector<Panel>& panels) = 0;
141
142 /// Set the discretisation level (for all panels).
143 virtual void SetDiscretisationLevel(const double dis) = 0;
144 /// Retrieve the discretisation level of a panel.
145 virtual double GetDiscretisationLevel(const Panel& panel) = 0;
146
147 virtual void Cut(const double x0, const double y0, const double z0,
148 const double xn, const double yn, const double zn,
149 std::vector<Panel>& panels) = 0;
150
161
162 /// Apply Dirichlet boundary conditions (fixed voltage).
163 void SetBoundaryPotential(const double v) {
164 m_volt = v;
166 }
167 /// Apply fixed-charge boundary conditions.
168 void SetBoundaryChargeDensity(const double q) {
169 m_charge = q;
171 }
172 /// Make the potential at the surface of the solid floating.
174 /// Make the surfaces of the solid dielectric-dielectric interfaces.
178
179 /// Retrieve the type of boundary condition.
181 /// Retrieve the potential.
182 double GetBoundaryPotential() const { return m_volt; }
183 /// Retrieve the surface charge density.
184 double GetBoundaryChargeDensity() const { return m_charge; }
185
186 /// Switch debugging messages on/off.
187 void EnableDebugging(const bool on = true) { m_debug = on; }
188
189 /// Set the colour of the solid.
190 void SetColour(const int col) { m_colour = col; }
191 /// Get the colour of the solid.
192 int GetColour() const { return m_colour; }
193
194 static bool Intersect(const double x1, const double y1, const double z1,
195 const double x2, const double y2, const double z2,
196 const double x0, const double y0, const double z0,
197 const double a, const double b, const double c,
198 double& xc, double& yc, double& zc);
199
200 protected:
201 /// Centre of the solid.
202 double m_cX = 0., m_cY = 0., m_cZ = 0.;
203
204 /// Direction vector.
205 double m_dX = 0., m_dY = 0., m_dZ = 1.;
206 /// Azimuthal angle.
207 double m_cPhi = 1., m_sPhi = 0.;
208 /// Polar angle.
209 double m_cTheta = 1., m_sTheta = 0.;
210
211 /// Class name.
212 std::string m_className = "Solid";
213
214 /// Label.
215 std::string m_label = "";
216
217 /// Debug flag.
218 bool m_debug = false;
219
220 /// Type of boundary condition.
222 /// Potential at the surface.
223 double m_volt = 0.;
224 /// Surface charge density.
225 double m_charge = 0.;
226 /// Dielectric constant.
227 double m_eps = 0.;
228
229 /// Colour.
230 int m_colour = -1;
231
232 /// Transform a point from global coordinates (x, y, z)
233 /// to local coordinates (u, v, w).
234 void ToLocal(const double x, const double y, const double z, double& u,
235 double& v, double& w) const {
236 const double dx = x - m_cX;
237 const double dy = y - m_cY;
238 const double dz = z - m_cZ;
239
240 u = m_cPhi * m_cTheta * dx + m_sPhi * m_cTheta * dy - m_sTheta * dz;
241 v = -m_sPhi * dx + m_cPhi * dy;
242 w = m_cPhi * m_sTheta * dx + m_sPhi * m_sTheta * dy + m_cTheta * dz;
243 }
244 /// Transform a point from local coordinates (u, v, w)
245 /// to global coordinates (x, y, z).
246 void ToGlobal(const double u, const double v, const double w, double& x,
247 double& y, double& z) const {
248 x = m_cX + m_cPhi * m_cTheta * u - m_sPhi * v + m_cPhi * m_sTheta * w;
249 y = m_cY + m_sPhi * m_cTheta * u + m_cPhi * v + m_sPhi * m_sTheta * w;
250 z = m_cZ - m_sTheta * u + m_cTheta * w;
251 }
252 /// Transform a vector from global to local coordinates.
253 void VectorToLocal(const double x, const double y, const double z,
254 double& u, double& v, double& w) {
255 u = m_cPhi * m_cTheta * x + m_sPhi * m_cTheta * y - m_sTheta * z;
256 v = -m_sPhi * x + m_cPhi * y;
257 w = m_cPhi * m_sTheta * x + m_sPhi * m_sTheta * y + m_cTheta * z;
258 }
259
260 void SetDirection(const double dx, const double dy, const double dz);
261
262 private:
263 double NotImplemented(const std::string& fcn) const;
264 /// ID counter.
265 static unsigned int s_id;
266 /// ID of the solid.
267 unsigned int m_id;
268
269};
270}
271
272#endif
void SetBoundaryChargeDensity(const double q)
Apply fixed-charge boundary conditions.
Definition Solid.hh:168
double m_dZ
Definition Solid.hh:205
void EnableDebugging(const bool on=true)
Switch debugging messages on/off.
Definition Solid.hh:187
virtual double GetUpperRadius() const
Return the upper radius (of a hole).
Definition Solid.hh:121
double m_charge
Surface charge density.
Definition Solid.hh:225
virtual bool IsTube() const
Return true if the solid is a tube.
Definition Solid.hh:53
virtual bool IsRidge() const
Return true if the solid is a ridge.
Definition Solid.hh:59
double m_cZ
Definition Solid.hh:202
virtual double GetHalfLengthX() const
Return the half-length along x.
Definition Solid.hh:95
virtual bool IsHole() const
Return true if the solid is a hole.
Definition Solid.hh:57
std::string GetLabel() const
Return the label.
Definition Solid.hh:68
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:253
void SetBoundaryPotential(const double v)
Apply Dirichlet boundary conditions (fixed voltage).
Definition Solid.hh:163
double m_eps
Dielectric constant.
Definition Solid.hh:227
double m_cTheta
Polar angle.
Definition Solid.hh:209
virtual double GetHalfLengthZ() const
Return the half-length along z.
Definition Solid.hh:103
virtual ~Solid()
Destructor.
Definition Solid.hh:40
virtual bool IsBox() const
Return true if the solid is a box.
Definition Solid.hh:51
virtual double GetHalfLengthY() const
Return the half-length along y.
Definition Solid.hh:99
static bool Intersect(const double x1, const double y1, const double z1, const double x2, const double y2, const double z2, const double x0, const double y0, const double z0, const double a, const double b, const double c, double &xc, double &yc, double &zc)
Definition Solid.cc:52
double m_dX
Direction vector.
Definition Solid.hh:205
std::string m_label
Label.
Definition Solid.hh:215
virtual bool IsExtrusion() const
Return true if the solid is an extrusion.
Definition Solid.hh:61
bool GetCentre(double &x, double &y, double &z) const
Retrieve the centre point of the solid.
Definition Solid.hh:71
virtual double GetDiscretisationLevel(const Panel &panel)=0
Retrieve the discretisation level of a panel.
unsigned int GetId() const
Get the ID of the solid.
Definition Solid.hh:137
double GetBoundaryChargeDensity() const
Retrieve the surface charge density.
Definition Solid.hh:184
bool GetDirection(double &dx, double &dy, double &dz) const
Retrieve the direction vector.
Definition Solid.hh:78
void ToLocal(const double x, const double y, const double z, double &u, double &v, double &w) const
Definition Solid.hh:234
void SetDirection(const double dx, const double dy, const double dz)
Definition Solid.cc:12
virtual bool GetProfile(std::vector< double > &xv, std::vector< double > &yv) const
Get the vertices defining an extrusion.
Definition Solid.cc:40
BoundaryCondition GetBoundaryConditionType() const
Retrieve the type of boundary condition.
Definition Solid.hh:180
Solid(const double cx, const double cy, const double cz, const std::string &name)
Constructor.
Definition Solid.hh:33
int m_colour
Colour.
Definition Solid.hh:230
virtual double GetRidgeOffset() const
Return the x-offset of a ridge.
Definition Solid.hh:125
double m_volt
Potential at the surface.
Definition Solid.hh:223
BoundaryCondition m_bctype
Type of boundary condition.
Definition Solid.hh:221
virtual double GetLowerRadius() const
Return the lower radius (of a hole).
Definition Solid.hh:117
virtual void Cut(const double x0, const double y0, const double z0, const double xn, const double yn, const double zn, std::vector< Panel > &panels)=0
virtual double GetOuterRadius() const
Return the outer radius.
Definition Solid.hh:111
double m_sPhi
Definition Solid.hh:207
double GetBoundaryPotential() const
Retrieve the potential.
Definition Solid.hh:182
void SetBoundaryParallelField()
Definition Solid.hh:176
bool GetOrientation(double &ctheta, double &stheta, double &cphi, double &sphi) const
Retrieve the orientation (azimuthal and polar angles) of the solid.
Definition Solid.hh:85
virtual bool IsWire() const
Return true if the solid is a wire.
Definition Solid.hh:63
void SetBoundaryPerpendicularField()
Definition Solid.hh:177
void ToGlobal(const double u, const double v, const double w, double &x, double &y, double &z) const
Definition Solid.hh:246
int GetColour() const
Get the colour of the solid.
Definition Solid.hh:192
virtual bool IsInside(const double x, const double y, const double z, const bool tesselated=false) const =0
virtual void SetDiscretisationLevel(const double dis)=0
Set the discretisation level (for all panels).
double m_sTheta
Definition Solid.hh:209
double m_cY
Definition Solid.hh:202
bool m_debug
Debug flag.
Definition Solid.hh:218
virtual double GetRadius() const
Return the radius.
Definition Solid.hh:115
virtual bool IsSphere() const
Return true if the solid is a sphere.
Definition Solid.hh:55
void SetColour(const int col)
Set the colour of the solid.
Definition Solid.hh:190
virtual bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const =0
Return the bounding box of the solid.
void SetLabel(const std::string &label)
Set a label.
Definition Solid.hh:66
double m_dY
Definition Solid.hh:205
double m_cX
Centre of the solid.
Definition Solid.hh:202
virtual double GetInnerRadius() const
Return the inner radius.
Definition Solid.hh:107
virtual double GetRidgeHeight() const
Return the height of a ridge.
Definition Solid.hh:129
double m_cPhi
Azimuthal angle.
Definition Solid.hh:207
void SetBoundaryFloat()
Make the potential at the surface of the solid floating.
Definition Solid.hh:173
virtual bool SolidPanels(std::vector< Panel > &panels)=0
Retrieve the surface panels of the solid.
std::string m_className
Class name.
Definition Solid.hh:212
Solid()=delete
Default constructor.
void SetBoundaryDielectric()
Make the surfaces of the solid dielectric-dielectric interfaces.
Definition Solid.hh:175
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
std::vector< double > xv
X-coordinates of vertices.
Definition Solid.hh:15
std::vector< double > yv
Y-coordinates of vertices.
Definition Solid.hh:17
int colour
Colour index.
Definition Solid.hh:21