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

Sphere. More...

#include <SolidSphere.hh>

+ Inheritance diagram for Garfield::SolidSphere:

Public Member Functions

 SolidSphere (const double cx, const double cy, const double cz, const double r)
 Constructor from centre and outer radius.
 
 SolidSphere (const double cx, const double cy, const double cz, const double rmin, const double rmax)
 Constructor from centre and inner/outer radii.
 
 ~SolidSphere ()
 Destructor.
 
bool IsInside (const double x, const double y, const double z, const bool tesselated) const override
 
bool GetBoundingBox (double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const override
 Return the bounding box of the solid.
 
bool IsSphere () const override
 Return true if the solid is a sphere.
 
void SetRadius (const double r)
 Set the radius of the sphere.
 
void SetRadii (const double rmin, const double rmax)
 Set the inner and outer radius of the sphere.
 
double GetRadius () const override
 Return the radius.
 
double GetInnerRadius () const override
 Return the inner radius.
 
double GetOuterRadius () const override
 Return the outer radius.
 
void SetMeridians (const unsigned int n)
 
bool SolidPanels (std::vector< Panel > &panels) override
 Retrieve the surface panels of the solid.
 
void SetDiscretisationLevel (const double dis) override
 Set the discretisation level (for all panels).
 
double GetDiscretisationLevel (const Panel &panel) override
 Retrieve the discretisation level of a panel.
 
void Cut (const double x0, const double y0, const double z0, const double xn, const double yn, const double zn, std::vector< Panel > &panels) override
 
- 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 bool tesselated=false) const =0
 
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.
 
virtual bool IsExtrusion () const
 Return true if the solid is an extrusion.
 
virtual bool IsWire () const
 Return true if the solid is a wire.
 
void SetLabel (const std::string &label)
 Set a label.
 
std::string GetLabel () const
 Return the label.
 
bool GetCentre (double &x, double &y, double &z) const
 Retrieve the centre point of the solid.
 
bool GetDirection (double &dx, double &dy, double &dz) const
 Retrieve the direction vector.
 
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.
 
virtual bool GetProfile (std::vector< double > &xv, std::vector< double > &yv) const
 Get the vertices defining an extrusion.
 
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 void SetDiscretisationLevel (const double dis)=0
 Set the discretisation level (for all panels).
 
virtual double GetDiscretisationLevel (const Panel &panel)=0
 Retrieve the discretisation level of a panel.
 
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
 
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.
 
void SetColour (const int col)
 Set the colour of the solid.
 
int GetColour () const
 Get the colour of the solid.
 

Additional Inherited Members

- Public Types inherited from Garfield::Solid
enum  BoundaryCondition {
  Unknown = 0 , Voltage , Charge , Float ,
  Dielectric , DielectricCharge , ParallelField , PerpendicularField
}
 
- Static Public Member Functions inherited from Garfield::Solid
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)
 
- 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.
 
std::string m_label = ""
 Label.
 
bool m_debug = false
 Debug flag.
 
BoundaryCondition m_bctype = Unknown
 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.
 
int m_colour = -1
 Colour.
 

Detailed Description

Sphere.

Definition at line 12 of file SolidSphere.hh.

Constructor & Destructor Documentation

◆ SolidSphere() [1/2]

Garfield::SolidSphere::SolidSphere ( const double  cx,
const double  cy,
const double  cz,
const double  r 
)

Constructor from centre and outer radius.

Definition at line 28 of file SolidSphere.cc.

30 : Solid(cx, cy, cz, "SolidSphere") {
31 SetRadius(r);
32 UpdatePanels();
33}
void SetRadius(const double r)
Set the radius of the sphere.
Definition: SolidSphere.cc:73
Solid()=delete
Default constructor.

◆ SolidSphere() [2/2]

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

Constructor from centre and inner/outer radii.

Definition at line 35 of file SolidSphere.cc.

37 : Solid(cx, cy, cz, "SolidSphere") {
38 SetRadii(rmin, rmax);
39 UpdatePanels();
40}
void SetRadii(const double rmin, const double rmax)
Set the inner and outer radius of the sphere.
Definition: SolidSphere.cc:83

◆ ~SolidSphere()

Garfield::SolidSphere::~SolidSphere ( )
inline

Destructor.

Definition at line 21 of file SolidSphere.hh.

21{}

Member Function Documentation

◆ Cut()

void Garfield::SolidSphere::Cut ( const double  x0,
const double  y0,
const double  z0,
const double  xn,
const double  yn,
const double  zn,
std::vector< Panel > &  panels 
)
overridevirtual

Implements Garfield::Solid.

Definition at line 219 of file SolidSphere.cc.

221 {
222
223 //-----------------------------------------------------------------------
224 // PLASPC - Cuts sphere IVOL with a plane.
225 //-----------------------------------------------------------------------
226 std::vector<double> xv;
227 std::vector<double> yv;
228 std::vector<double> zv;
229 // Loop over the sphere.
230 const double r = m_rMax;
231 for (unsigned int i = 1; i <= m_n; ++i) {
232 // phi-Coordinates.
233 const double phi0 = TwoPi * (i - 1.) / m_n;
234 const double phi1 = TwoPi * i / m_n;
235 for (unsigned int j = 1; j <= m_n; ++j) {
236 // theta-Coordinates.
237 const double theta0 = -HalfPi + Pi * (j - 1.) / m_n;
238 const double theta1 = -HalfPi + Pi * j / m_n;
239 // Reference point of this square.
240 const double x1 = x0 + r * cos(phi0) * cos(theta0);
241 const double y1 = y0 + r * sin(phi0) * cos(theta0);
242 const double z1 = z0 + r * sin(theta0);
243 // The meridian segment, doesn't exist at the S pole.
244 if (j > 0) {
245 const double x2 = x0 + r * cos(phi1) * cos(theta0);
246 const double y2 = y0 + r * sin(phi1) * cos(theta0);
247 const double z2 = z0 + r * sin(theta0);
248 // Cut with the plane.
249 double xc, yc, zc;
250 if (Intersect(x1, y1, z1, x2, y2, z2,
251 x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
252 xv.push_back(xc);
253 yv.push_back(yc);
254 zv.push_back(zc);
255 }
256 }
257 // The latitude.
258 const double x2 = x0 + r * cos(phi0) * cos(theta1);
259 const double y2 = y0 + r * sin(phi0) * cos(theta1);
260 const double z2 = z0 + r * sin(theta1);
261 // Cut with the plane.
262 double xc, yc, zc;
263 if (Intersect(x1, y1, z1, x2, y2, z2,
264 x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
265 xv.push_back(xc);
266 yv.push_back(yc);
267 zv.push_back(zc);
268 }
269 }
270 }
271 // Get rid of butterflies.
273
274 if (xv.size() >= 3) {
275 Panel panel;
276 panel.a = xn;
277 panel.b = yn;
278 panel.c = zn;
279 panel.xv = xv;
280 panel.yv = yv;
281 panel.zv = zv;
282 panel.colour = m_colour;
283 panel.volume = GetId();
284 panels.push_back(std::move(panel));
285 }
286}
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
unsigned int GetId() const
Get the ID of the solid.
Definition: Solid.hh:137
int m_colour
Colour.
Definition: Solid.hh:230
void EliminateButterflies(std::vector< double > &xp, std::vector< double > &yp, std::vector< double > &zp)
Definition: Polygon.cc:355
DoubleAc cos(const DoubleAc &f)
Definition: DoubleAc.cpp:432
DoubleAc sin(const DoubleAc &f)
Definition: DoubleAc.cpp:384

◆ GetBoundingBox()

bool Garfield::SolidSphere::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 61 of file SolidSphere.cc.

63 {
64 xmin = m_cX - m_rMax;
65 xmax = m_cX + m_rMax;
66 ymin = m_cY - m_rMax;
67 ymax = m_cY + m_rMax;
68 zmin = m_cZ - m_rMax;
69 zmax = m_cZ + m_rMax;
70 return true;
71}
double m_cZ
Definition: Solid.hh:202
double m_cY
Definition: Solid.hh:202
double m_cX
Centre of the solid.
Definition: Solid.hh:202

◆ GetDiscretisationLevel()

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

Retrieve the discretisation level of a panel.

Implements Garfield::Solid.

Definition at line 215 of file SolidSphere.cc.

215 {
216 return m_dis;
217}

◆ GetInnerRadius()

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

Return the inner radius.

Reimplemented from Garfield::Solid.

Definition at line 35 of file SolidSphere.hh.

35{ return m_rMin; }

◆ GetOuterRadius()

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

Return the outer radius.

Reimplemented from Garfield::Solid.

Definition at line 36 of file SolidSphere.hh.

36{ return m_rMax; }

◆ GetRadius()

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

Return the radius.

Reimplemented from Garfield::Solid.

Definition at line 34 of file SolidSphere.hh.

34{ return m_rMax; }

◆ IsInside()

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

Check whether a given point is inside the solid. If requested, use the tesselated approximation of the solid (if applicable).

Implements Garfield::Solid.

Definition at line 42 of file SolidSphere.cc.

43 {
44 // Transform the point to local coordinates.
45 const double dx = x - m_cX;
46 const double dy = y - m_cY;
47 const double dz = z - m_cZ;
48
49 if (fabs(dx) > m_rMax || fabs(dy) > m_rMax || fabs(dz) > m_rMax) {
50 return false;
51 }
52 const double r = sqrt(dx * dx + dy * dy + dz * dz);
53 if (!tesselated) return (r >= m_rMin && r <= m_rMax);
54 if (r > m_rMax || !InPolyhedron(m_panelsO, dx, dy, dz)) return false;
55 if (m_rMin > 0.) {
56 return (r >= m_rMin || !InPolyhedron(m_panelsI, dx, dy, dz, true));
57 }
58 return true;
59}
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:615
DoubleAc sqrt(const DoubleAc &f)
Definition: DoubleAc.cpp:314

◆ IsSphere()

bool Garfield::SolidSphere::IsSphere ( ) const
inlineoverridevirtual

Return true if the solid is a sphere.

Reimplemented from Garfield::Solid.

Definition at line 27 of file SolidSphere.hh.

27{ return true; }

◆ SetDiscretisationLevel()

void Garfield::SolidSphere::SetDiscretisationLevel ( const double  dis)
inlineoverridevirtual

Set the discretisation level (for all panels).

Implements Garfield::Solid.

Definition at line 44 of file SolidSphere.hh.

44{ m_dis = dis; }

◆ SetMeridians()

void Garfield::SolidSphere::SetMeridians ( const unsigned int  n)

When calculating surface panels, the sphere is approximated by a set of parallelograms, much the same way maps are drawn ("UV sphere"). N specifies the number of meridians and also the number of parallels.

Definition at line 98 of file SolidSphere.cc.

98 {
99 if (n < 3) {
100 std::cerr << "SolidSphere::SetMeridians: Number must be >= 3.\n";
101 return;
102 }
103 m_n = n;
104 UpdatePanels();
105}

◆ SetRadii()

void Garfield::SolidSphere::SetRadii ( const double  rmin,
const double  rmax 
)

Set the inner and outer radius of the sphere.

Definition at line 83 of file SolidSphere.cc.

83 {
84 if (rmax <= 0.) {
85 std::cerr << "SolidSphere::SetRadii: Outer radius must be > 0.\n";
86 return;
87 }
88 if (rmin >= rmax) {
89 std::cerr << "SolidSphere::SetRadii:\n"
90 << " Outer radius must be > inner radius.\n";
91 return;
92 }
93 m_rMin = rmin;
94 m_rMax = rmax;
95 UpdatePanels();
96}

Referenced by SolidSphere().

◆ SetRadius()

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

Set the radius of the sphere.

Definition at line 73 of file SolidSphere.cc.

73 {
74 if (r <= 0.) {
75 std::cerr << "SolidSphere::SetRadius: Radius must be > 0.\n";
76 return;
77 }
78 m_rMax = r;
79 m_rMin = 0.;
80 UpdatePanels();
81}

Referenced by SolidSphere().

◆ SolidPanels()

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

Retrieve the surface panels of the solid.

Implements Garfield::Solid.

Definition at line 107 of file SolidSphere.cc.

107 {
108
109 const auto nPanels = panels.size();
110 panels.insert(panels.begin(), m_panelsO.begin(), m_panelsO.end());
111 panels.insert(panels.begin(), m_panelsI.begin(), m_panelsI.end());
112 std::cout << "SolidSphere::SolidPanels: " << panels.size() - nPanels
113 << " panels.\n";
114 return true;
115}

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