Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
Garfield::SolidTube Class Reference

Cylindrical tube. More...

#include <SolidTube.hh>

+ Inheritance diagram for Garfield::SolidTube:

Public Member Functions

 SolidTube (const double cx, const double cy, const double cz, const double rmin, const double rmax, const double lz)
 Constructor from centre, inner/outer radii, and half-length.
 
 SolidTube (const double cx, const double cy, const double cz, const double r, const double lz)
 Constructor from centre, outer radius, and half-length.
 
 SolidTube (const double cx, const double cy, const double cz, const double rmin, const double rmax, const double lz, const double dx, const double dy, const double dz)
 Constructor from centre, inner/outer radii, half-length and orientation.
 
 SolidTube (const double cx, const double cy, const double cz, const double r, const double lz, const double dx, const double dy, const double dz)
 Constructor from centre, outer radius, half-length and orientation.
 
 ~SolidTube ()
 Destructor.
 
bool IsInside (const double x, const double y, const double z) const override
 Check whether a given point is inside the solid.
 
bool GetBoundingBox (double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const override
 Return the bounding box of the solid.
 
bool IsTube () const override
 Return true if the solid is a tube.
 
void SetHalfLength (const double lz)
 
void SetInnerRadius (const double rmin)
 
void SetOuterRadius (const double rmax)
 
void SetRadius (const double r)
 
double GetHalfLengthZ () const override
 Return the half-length along z.
 
double GetInnerRadius () const override
 Return the inner radius.
 
double GetOuterRadius () const override
 Return the outer radius.
 
double GetRadius () const override
 Return the radius.
 
void SetSectors (const unsigned int n)
 
void SetRotation (const double angle)
 
void SetAverageRadius (const bool average)
 
void SetToplid (const bool toplid)
 Request the cylinder to be closed with a (polygonal) lid at +z.
 
void SetBottomlid (const bool bottomlid)
 Request the cylinder to be closed with a (polygonal) lid at -z.
 
unsigned int GetSectors () const
 
double GetRotation () const
 
bool GetAverage () const
 
bool SolidPanels (std::vector< Panel > &panels) override
 Retrieve the surface panels of the solid.
 
double GetDiscretisationLevel (const Panel &panel) override
 Retrieve the discretization level of a panel.
 
- Public Member Functions inherited from Garfield::Solid
 Solid ()=delete
 Default constructor.
 
 Solid (const double cx, const double cy, const double cz, const std::string &name)
 Constructor.
 
virtual ~Solid ()
 Destructor.
 
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 GetBoundingBox (double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const =0
 Return the bounding box of the solid.
 
virtual bool IsBox () const
 Return true if the solid is a box.
 
virtual bool IsTube () const
 Return true if the solid is a tube.
 
virtual bool IsSphere () const
 Return true if the solid is a sphere.
 
virtual bool IsHole () const
 Return true if the solid is a hole.
 
virtual bool IsRidge () const
 Return true if the solid is a ridge.
 
bool GetCentre (double &x, double &y, double &z) const
 Retrieve the centre point of the solid.
 
bool GetOrientation (double &ctheta, double &stheta, double &cphi, double &sphi) const
 Retrieve the orientation (azimuthal and polar angles) of the solid.
 
virtual double GetHalfLengthX () const
 Return the half-length along x.
 
virtual double GetHalfLengthY () const
 Return the half-length along y.
 
virtual double GetHalfLengthZ () const
 Return the half-length along z.
 
virtual double GetInnerRadius () const
 Return the inner radius.
 
virtual double GetOuterRadius () const
 Return the outer radius.
 
virtual double GetRadius () const
 Return the radius.
 
virtual double GetLowerRadius () const
 Return the lower radius (of a hole).
 
virtual double GetUpperRadius () const
 Return the upper radius (of a hole).
 
virtual double GetRidgeOffset () const
 Return the x-offset of a ridge.
 
virtual double GetRidgeHeight () const
 Return the height of a ridge.
 
unsigned int GetId () const
 Get the ID of the solid.
 
virtual bool SolidPanels (std::vector< Panel > &panels)=0
 Retrieve the surface panels of the solid.
 
virtual double GetDiscretisationLevel (const Panel &panel)=0
 Retrieve the discretization level of a panel.
 
void SetBoundaryPotential (const double v)
 Apply Dirichlet boundary conditions (fixed voltage).
 
void SetBoundaryChargeDensity (const double q)
 Apply fixed-charge boundary conditions.
 
void SetBoundaryFloat ()
 Make the potential at the surface of the solid floating.
 
void SetBoundaryDielectric ()
 Make the surfaces of the solid dielectric-dielectric interfaces.
 
void SetBoundaryParallelField ()
 
void SetBoundaryPerpendicularField ()
 
BoundaryCondition GetBoundaryConditionType () const
 Retrieve the type of boundary condition.
 
double GetBoundaryPotential () const
 Retrieve the potential.
 
double GetBoundaryChargeDensity () const
 Retrieve the surface charge density.
 
void EnableDebugging (const bool on=true)
 Switch debugging messages on/off.
 

Additional Inherited Members

- Public Types inherited from Garfield::Solid
enum  BoundaryCondition {
  Voltage = 1 , Charge , Float , Dielectric ,
  DielectricCharge , ParallelField , PerpendicularField
}
 
- Protected Member Functions inherited from Garfield::Solid
void ToLocal (const double x, const double y, const double z, double &u, double &v, double &w) const
 
void ToGlobal (const double u, const double v, const double w, double &x, double &y, double &z) const
 
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.
 
void SetDirection (const double dx, const double dy, const double dz)
 
- Protected Attributes inherited from Garfield::Solid
double m_cX = 0.
 Centre of the solid.
 
double m_cY = 0.
 
double m_cZ = 0.
 
double m_dX = 0.
 Direction vector.
 
double m_dY = 0.
 
double m_dZ = 1.
 
double m_cPhi = 1.
 Azimuthal angle.
 
double m_sPhi = 0.
 
double m_cTheta = 1.
 Polar angle.
 
double m_sTheta = 0.
 
std::string m_className = "Solid"
 Class name.
 
bool m_debug = false
 Debug flag.
 
BoundaryCondition m_bctype = Voltage
 Type of boundary condition.
 
double m_volt = 0.
 Potential at the surface.
 
double m_charge = 0.
 Surface charge density.
 
double m_eps = 0.
 Dielectric constant.
 

Detailed Description

Cylindrical tube.

Definition at line 10 of file SolidTube.hh.

Constructor & Destructor Documentation

◆ SolidTube() [1/4]

Garfield::SolidTube::SolidTube ( const double  cx,
const double  cy,
const double  cz,
const double  rmin,
const double  rmax,
const double  lz 
)

Constructor from centre, inner/outer radii, and half-length.

Definition at line 9 of file SolidTube.cc.

11 : Solid(cx, cy, cz, "SolidTube"),
12 m_rMin(rmin),
13 m_rMax(rmax),
14 m_r(rmax),
15 m_lZ(lz) {}
Solid()=delete
Default constructor.

◆ SolidTube() [2/4]

Garfield::SolidTube::SolidTube ( const double  cx,
const double  cy,
const double  cz,
const double  r,
const double  lz 
)

Constructor from centre, outer radius, and half-length.

Definition at line 24 of file SolidTube.cc.

26 : SolidTube(cx, cy, cz, 0., r, lz) {}
SolidTube(const double cx, const double cy, const double cz, const double rmin, const double rmax, const double lz)
Constructor from centre, inner/outer radii, and half-length.
Definition: SolidTube.cc:9

◆ SolidTube() [3/4]

Garfield::SolidTube::SolidTube ( const double  cx,
const double  cy,
const double  cz,
const double  rmin,
const double  rmax,
const double  lz,
const double  dx,
const double  dy,
const double  dz 
)

Constructor from centre, inner/outer radii, half-length and orientation.

Definition at line 17 of file SolidTube.cc.

20 : SolidTube(cx, cy, cz, rmin, rmax, lz) {
21 SetDirection(dx, dy, dz);
22}
void SetDirection(const double dx, const double dy, const double dz)
Definition: Solid.cc:12

◆ SolidTube() [4/4]

Garfield::SolidTube::SolidTube ( const double  cx,
const double  cy,
const double  cz,
const double  r,
const double  lz,
const double  dx,
const double  dy,
const double  dz 
)

Constructor from centre, outer radius, half-length and orientation.

Definition at line 28 of file SolidTube.cc.

31 : SolidTube(cx, cy, cz, 0., r, lz, dx, dy, dz) {}

◆ ~SolidTube()

Garfield::SolidTube::~SolidTube ( )
inline

Destructor.

Definition at line 26 of file SolidTube.hh.

26{}

Member Function Documentation

◆ GetAverage()

bool Garfield::SolidTube::GetAverage ( ) const
inline

Definition at line 65 of file SolidTube.hh.

65{ return m_average; }

◆ GetBoundingBox()

bool Garfield::SolidTube::GetBoundingBox ( double &  xmin,
double &  ymin,
double &  zmin,
double &  xmax,
double &  ymax,
double &  zmax 
) const
overridevirtual

Return the bounding box of the solid.

Implements Garfield::Solid.

Definition at line 62 of file SolidTube.cc.

63 {
64 if (m_cTheta == 1. && m_cPhi == 1.) {
65 xmin = m_cX - m_rMax;
66 xmax = m_cX + m_rMax;
67 ymin = m_cY - m_rMax;
68 ymax = m_cY + m_rMax;
69 zmin = m_cZ - m_lZ;
70 zmax = m_cZ + m_lZ;
71 return true;
72 }
73
74 const double dd = sqrt(m_rMax * m_rMax + m_lZ * m_lZ);
75 xmin = m_cX - dd;
76 xmax = m_cX + dd;
77 ymin = m_cY - dd;
78 ymax = m_cY + dd;
79 zmin = m_cZ - dd;
80 zmax = m_cZ + dd;
81 return true;
82}
double m_cZ
Definition: Solid.hh:164
double m_cTheta
Polar angle.
Definition: Solid.hh:171
double m_cY
Definition: Solid.hh:164
double m_cX
Centre of the solid.
Definition: Solid.hh:164
double m_cPhi
Azimuthal angle.
Definition: Solid.hh:169
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:314

◆ GetDiscretisationLevel()

double Garfield::SolidTube::GetDiscretisationLevel ( const Panel panel)
overridevirtual

Retrieve the discretization level of a panel.

Implements Garfield::Solid.

Definition at line 260 of file SolidTube.cc.

260 {
261
262 // Transform the normal vector to local coordinates.
263 double u = 0., v = 0., w = 0.;
264 VectorToLocal(panel.a, panel.b, panel.c, u, v, w);
265 // Identify the vector.
266 if (w > std::max(std::abs(u), std::abs(v))) {
267 return m_dis[0];
268 } else if (w < -std::max(std::abs(u), std::abs(v))) {
269 return m_dis[1];
270 }
271 return m_dis[2];
272}
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

◆ GetHalfLengthZ()

double Garfield::SolidTube::GetHalfLengthZ ( ) const
inlineoverridevirtual

Return the half-length along z.

Reimplemented from Garfield::Solid.

Definition at line 38 of file SolidTube.hh.

38{ return m_lZ; }

◆ GetInnerRadius()

double Garfield::SolidTube::GetInnerRadius ( ) const
inlineoverridevirtual

Return the inner radius.

Reimplemented from Garfield::Solid.

Definition at line 39 of file SolidTube.hh.

39{ return m_rMin; }

◆ GetOuterRadius()

double Garfield::SolidTube::GetOuterRadius ( ) const
inlineoverridevirtual

Return the outer radius.

Reimplemented from Garfield::Solid.

Definition at line 40 of file SolidTube.hh.

40{ return m_rMax; }

◆ GetRadius()

double Garfield::SolidTube::GetRadius ( ) const
inlineoverridevirtual

Return the radius.

Reimplemented from Garfield::Solid.

Definition at line 41 of file SolidTube.hh.

41{ return m_r; }

◆ GetRotation()

double Garfield::SolidTube::GetRotation ( ) const
inline

Definition at line 64 of file SolidTube.hh.

64{ return m_rot; }

◆ GetSectors()

unsigned int Garfield::SolidTube::GetSectors ( ) const
inline

Definition at line 63 of file SolidTube.hh.

63{ return m_n; }

◆ IsInside()

bool Garfield::SolidTube::IsInside ( const double  x,
const double  y,
const double  z 
) const
overridevirtual

Check whether a given point is inside the solid.

Implements Garfield::Solid.

Definition at line 33 of file SolidTube.cc.

33 {
34 // Transform the point to local coordinates.
35 double u = x, v = y, w = z;
36 ToLocal(x, y, z, u, v, w);
37
38 if (fabs(w) > m_lZ) {
39 if (m_debug) {
40 std::cout << "SolidTube::IsInside: (" << x << ", " << y << ", " << z
41 << ") is outside.\n";
42 }
43 return false;
44 }
45
46 const double r = sqrt(u * u + v * v);
47 if (r >= m_rMin && r <= m_rMax) {
48 if (m_debug) {
49 std::cout << "SolidTube::IsInside: (" << x << ", " << y << ", " << z
50 << ") is inside.\n";
51 }
52 return true;
53 }
54
55 if (m_debug) {
56 std::cout << "SolidTube::IsInside: (" << x << ", " << y << ", " << z
57 << ") is outside.\n";
58 }
59 return false;
60}
void ToLocal(const double x, const double y, const double z, double &u, double &v, double &w) const
Definition: Solid.hh:190
bool m_debug
Debug flag.
Definition: Solid.hh:177
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:615

◆ IsTube()

bool Garfield::SolidTube::IsTube ( ) const
inlineoverridevirtual

Return true if the solid is a tube.

Reimplemented from Garfield::Solid.

Definition at line 31 of file SolidTube.hh.

31{ return true; }

◆ SetAverageRadius()

void Garfield::SolidTube::SetAverageRadius ( const bool  average)
inline

By default, the polygon used for approximating the cylinder when calculating surface panels is inscribed in a circle of the specified radius. If the "average-radius" flag is activated, then the radius will be interpreted as the mean radius of the polygon that approximates the cylinder.

Definition at line 57 of file SolidTube.hh.

57{ m_average = average; }

◆ SetBottomlid()

void Garfield::SolidTube::SetBottomlid ( const bool  bottomlid)
inline

Request the cylinder to be closed with a (polygonal) lid at -z.

Definition at line 61 of file SolidTube.hh.

61{ m_bottomlid = bottomlid; }

◆ SetHalfLength()

void Garfield::SolidTube::SetHalfLength ( const double  lz)

Definition at line 118 of file SolidTube.cc.

118 {
119 if (lz <= 0.) {
120 std::cerr << "SolidTube::SetHalfLength: Half-length must be > 0.\n";
121 return;
122 }
123 m_lZ = lz;
124}

◆ SetInnerRadius()

void Garfield::SolidTube::SetInnerRadius ( const double  rmin)

Definition at line 84 of file SolidTube.cc.

84 {
85 if (rmin <= 0.) {
86 std::cerr << "SolidTube::SetInnerRadius: Radius must be > 0.\n";
87 return;
88 }
89 if (rmin >= m_rMax) {
90 std::cerr << "SolidTube::SetInnerRadius:\n";
91 std::cerr << " Inner radius must be smaller than outer radius.\n";
92 return;
93 }
94 m_rMin = rmin;
95}

◆ SetOuterRadius()

void Garfield::SolidTube::SetOuterRadius ( const double  rmax)

Definition at line 97 of file SolidTube.cc.

97 {
98 if (rmax <= 0.) {
99 std::cerr << "SolidTube::SetOuterRadius: Radius must be > 0.\n";
100 return;
101 }
102 if (rmax <= m_rMin) {
103 std::cerr << "SolidTube::SetOuterRadius:\n";
104 std::cerr << " Outer radius must be greater than inner radius.\n";
105 return;
106 }
107 m_rMax = rmax;
108}

◆ SetRadius()

void Garfield::SolidTube::SetRadius ( const double  r)

Definition at line 110 of file SolidTube.cc.

110 {
111 if (r <= 0.) {
112 std::cerr << "SolidTube::SetRadius: Radius must be > 0.\n";
113 return;
114 }
115 m_r = r;
116}

◆ SetRotation()

void Garfield::SolidTube::SetRotation ( const double  angle)
inline

Specify a rotation angle (radian) of the cylinder. Such a rotation is meaningful only if the number of sectors (when approximating the circle with a polygon) has been chosen small.

Definition at line 51 of file SolidTube.hh.

51{ m_rot = angle; }

◆ SetSectors()

void Garfield::SolidTube::SetSectors ( const unsigned int  n)

When calculating the surface panels, the cylinder is approximated as a polygon with a finite number of panels. The number of corners of the polygon equals $4(n - 1)$. Thus, $n = 2$ will produce a square, $n = 3$ an octagon etc.

Definition at line 126 of file SolidTube.cc.

126 {
127 if (n < 1) {
128 std::cerr << "SolidTube::SetSectors: Number must be > 0.\n";
129 return;
130 }
131 m_n = n;
132}

◆ SetToplid()

void Garfield::SolidTube::SetToplid ( const bool  toplid)
inline

Request the cylinder to be closed with a (polygonal) lid at +z.

Definition at line 59 of file SolidTube.hh.

59{ m_toplid = toplid; }

◆ SolidPanels()

bool Garfield::SolidTube::SolidPanels ( std::vector< Panel > &  panels)
overridevirtual

Retrieve the surface panels of the solid.

Implements Garfield::Solid.

Definition at line 134 of file SolidTube.cc.

134 {
135 // AROT Rotation angle: m_rot
136 // N Number of sectors: m_n
137 // R Radius of cylinder: m_r
138 // ZL half-length m_lZ
139 // X0 centre m_cX
140 // Y0 centre m_cY
141 // Z0 centre m_cZ
142 // A direction vector m_dX
143 // B direction vector m_dY
144 // C direction vector m_dZ
145
146 const auto id = GetId();
147 const unsigned int nPanels = panels.size();
148 // Direction vector.
149 const double fnorm = sqrt(m_dX * m_dX + m_dY * m_dY + m_dZ * m_dZ);
150 if (fnorm <= 0) {
151 std::cerr << "SolidTube::SolidPanels:\n"
152 << " Zero norm direction vector; no panels generated.\n";
153 return false;
154 }
155
156 // Set the mean or the outer radius.
157 double r = m_r;
158 if (m_average) {
159 const double alpha = Pi / (4. * (m_n - 1.));
160 r = 2 * m_r / (1. + asinh(tan(alpha)) * cos(alpha) / tan(alpha));
161 }
162
163 const unsigned int nPoints = 4 * (m_n - 1);
164 // Create the top lid.
165 if (m_toplid) {
166 std::vector<double> xv;
167 std::vector<double> yv;
168 std::vector<double> zv;
169 for (unsigned int i = 1; i <= nPoints; i++) {
170 const double alpha = m_rot + HalfPi * (i - 1.) / (m_n - 1.);
171 double x, y, z;
172 ToGlobal(r * cos(alpha), r * sin(alpha), m_lZ, x, y, z);
173 // Rotate into place.
174 xv.push_back(x);
175 yv.push_back(y);
176 zv.push_back(z);
177 }
178 Panel newpanel;
179 newpanel.a = m_cPhi * m_sTheta;
180 newpanel.b = m_sPhi * m_sTheta;
181 newpanel.c = m_cTheta;
182 newpanel.xv = xv;
183 newpanel.yv = yv;
184 newpanel.zv = zv;
185 newpanel.colour = 0;
186 newpanel.volume = id;
187 panels.push_back(std::move(newpanel));
188 }
189 // Create the bottom lid.
190 if (m_bottomlid) {
191 std::vector<double> xv;
192 std::vector<double> yv;
193 std::vector<double> zv;
194 for (unsigned int i = 1; i <= nPoints; i++) {
195 const double alpha = m_rot + HalfPi * (i - 1.) / (m_n - 1.);
196 double x, y, z;
197 ToGlobal(r * cos(alpha), r * sin(alpha), -m_lZ, x, y, z);
198 // Rotate into place.
199 xv.push_back(x);
200 yv.push_back(y);
201 zv.push_back(z);
202 }
203 Panel newpanel;
204 newpanel.a = -m_cPhi * m_sTheta;
205 newpanel.b = -m_sPhi * m_sTheta;
206 newpanel.c = -m_cTheta;
207 newpanel.xv = xv;
208 newpanel.yv = yv;
209 newpanel.zv = zv;
210 newpanel.colour = 0;
211 newpanel.volume = id;
212 panels.push_back(std::move(newpanel));
213 }
214 // Create the side panels.
215 double u = r * cos(m_rot);
216 double v = r * sin(m_rot);
217 // Rotate into place.
218 double xv0, yv0, zv0;
219 ToGlobal(u, v, -m_lZ, xv0, yv0, zv0);
220 double xv1, yv1, zv1;
221 ToGlobal(u, v, +m_lZ, xv1, yv1, zv1);
222 // Go around the cylinder.
223 for (unsigned int i = 2; i <= nPoints + 1; i++) {
224 // Bottom and top of the line along the axis of the cylinder.
225 double alpha = m_rot + HalfPi * (i - 1.) / (m_n - 1.);
226 u = r * cos(alpha);
227 v = r * sin(alpha);
228 // Rotate into place.
229 double xv2, yv2, zv2;
230 ToGlobal(u, v, +m_lZ, xv2, yv2, zv2);
231 double xv3, yv3, zv3;
232 ToGlobal(u, v, -m_lZ, xv3, yv3, zv3);
233 // Store the plane.
234 Panel newpanel;
235 alpha = m_rot + HalfPi * (i - 1.5) / (m_n - 1.);
236 const double cAlpha = cos(alpha);
237 const double sAlpha = sin(alpha);
238 newpanel.a = m_cPhi * m_cTheta * cAlpha - m_sPhi * sAlpha;
239 newpanel.b = m_sPhi * m_cTheta * cAlpha + m_cPhi * sAlpha;
240 newpanel.c = -m_sTheta * cAlpha;
241 newpanel.xv = {xv0, xv1, xv2, xv3};
242 newpanel.yv = {yv0, yv1, yv2, yv3};
243 newpanel.zv = {zv0, zv1, zv2, zv3};
244 newpanel.colour = 0;
245 newpanel.volume = id;
246 panels.push_back(std::move(newpanel));
247 // Shift the points.
248 xv0 = xv3;
249 yv0 = yv3;
250 zv0 = zv3;
251 xv1 = xv2;
252 yv1 = yv2;
253 zv1 = zv2;
254 }
255 std::cout << "SolidTube::SolidPanels: " << panels.size() - nPanels
256 << " panels.\n";
257 return true;
258}
double m_dZ
Definition: Solid.hh:167
double m_dX
Direction vector.
Definition: Solid.hh:167
unsigned int GetId() const
Get the ID of the solid.
Definition: Solid.hh:117
double m_sPhi
Definition: Solid.hh:169
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_dY
Definition: Solid.hh:167
DoubleAc cos(const DoubleAc &f)
Definition: DoubleAc.cpp:432
DoubleAc sin(const DoubleAc &f)
Definition: DoubleAc.cpp:384

The documentation for this class was generated from the following files: