Garfield 0.3
Toolkit for the detailed simulation of particle detectors based on ionization 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 <string>
5#include <vector>
6
7namespace Garfield {
8
10
11struct Panel {
13 double a, b, c;
15 std::vector<double> xv;
17 std::vector<double> yv;
19 std::vector<double> zv;
21 int colour;
23 int volume;
24};
25
27
28class Solid {
29 public:
31 Solid() = delete;
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
40 virtual ~Solid() {}
41
44 virtual bool IsInside(const double x, const double y, const double z,
45 const bool tesselated = false) const = 0;
47 virtual bool GetBoundingBox(double& xmin, double& ymin, double& zmin,
48 double& xmax, double& ymax,
49 double& zmax) const = 0;
51 virtual bool IsBox() const { return false; }
53 virtual bool IsTube() const { return false; }
55 virtual bool IsSphere() const { return false; }
57 virtual bool IsHole() const { return false; }
59 virtual bool IsRidge() const { return false; }
61 virtual bool IsExtrusion() const { return false; }
63 virtual bool IsWire() const { return false; }
64
66 void SetLabel(const std::string& label) { m_label = label; }
68 std::string GetLabel() const { return m_label; }
69
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
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
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
95 virtual double GetHalfLengthX() const {
96 return NotImplemented("GetHalfLengthX");
97 }
98
99 virtual double GetHalfLengthY() const {
100 return NotImplemented("GetHalfLengthY");
101 }
102
103 virtual double GetHalfLengthZ() const {
104 return NotImplemented("GetHalfLengthZ");
105 }
106
107 virtual double GetInnerRadius() const {
108 return NotImplemented("GetInnerRadius");
109 }
110
111 virtual double GetOuterRadius() const {
112 return NotImplemented("GetOuterRadius");
113 }
114
115 virtual double GetRadius() const { return NotImplemented("GetRadius"); }
117 virtual double GetLowerRadius() const {
118 return NotImplemented("GetLowerRadius");
119 }
120
121 virtual double GetUpperRadius() const {
122 return NotImplemented("GetUpperRadius");
123 }
124
125 virtual double GetRidgeOffset() const {
126 return NotImplemented("GetRidgeOffset");
127 }
128
129 virtual double GetRidgeHeight() const {
130 return NotImplemented("GetRidgeHeight");
131 }
132
133 virtual bool GetProfile(std::vector<double>& xv,
134 std::vector<double>& yv) const;
135
137 unsigned int GetId() const { return m_id; }
138
140 virtual bool SolidPanels(std::vector<Panel>& panels) = 0;
141
143 virtual void SetDiscretisationLevel(const double dis) = 0;
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
163 void SetBoundaryPotential(const double v) {
164 m_volt = v;
166 }
167
168 void SetBoundaryChargeDensity(const double q) {
169 m_charge = q;
171 }
172
178
182 double GetBoundaryPotential() const { return m_volt; }
184 double GetBoundaryChargeDensity() const { return m_charge; }
185
187 void EnableDebugging(const bool on = true) { m_debug = on; }
188
190 void SetColour(const int col) { m_colour = col; }
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:
202 double m_cX = 0., m_cY = 0., m_cZ = 0.;
203
205 double m_dX = 0., m_dY = 0., m_dZ = 1.;
207 double m_cPhi = 1., m_sPhi = 0.;
209 double m_cTheta = 1., m_sTheta = 0.;
210
212 std::string m_className = "Solid";
213
215 std::string m_label = "";
216
218 bool m_debug = false;
219
223 double m_volt = 0.;
225 double m_charge = 0.;
227 double m_eps = 0.;
228
230 int m_colour = -1;
231
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
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
253 void VectorToLocal(const double x, const double y, const double z, double& u,
254 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;
265 static unsigned int s_id;
267 unsigned int m_id;
268};
269} // namespace Garfield
270
271#endif
void SetBoundaryChargeDensity(const double q)
Apply fixed-charge boundary conditions.
Definition Solid.hh:168
double m_dZ
Definition Solid.hh:205
double NotImplemented(const std::string &fcn) const
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
static unsigned int s_id
ID counter.
Definition Solid.hh:265
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
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
virtual bool GetProfile(std::vector< double > &xv, std::vector< double > &yv) const
Get the vertices defining an extrusion.
void ToLocal(const double x, const double y, const double z, double &u, double &v, double &w) const
Transform a point from global coordinates (x, y, z) to local coordinates (u, v, w).
Definition Solid.hh:234
void SetDirection(const double dx, const double dy, const double dz)
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
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)
virtual bool IsWire() const
Return true if the solid is a wire.
Definition Solid.hh:63
void SetBoundaryPerpendicularField()
Definition Solid.hh:177
unsigned int m_id
ID of the solid.
Definition Solid.hh:267
void ToGlobal(const double u, const double v, const double w, double &x, double &y, double &z) const
Transform a point from local coordinates (u, v, w) to global coordinates (x, y, z).
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
Check whether a given point is inside the solid.
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