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::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.
 
 ~SolidSphere ()
 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 IsSphere () const override
 Return true if the solid is a sphere.
 
void SetRadius (const double r)
 Set the radius of the sphere.
 
double GetRadius () const override
 Return the radius.
 
void SetMeridians (const unsigned int n)
 
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

Sphere.

Definition at line 10 of file SolidSphere.hh.

Constructor & Destructor Documentation

◆ SolidSphere()

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

Constructor.

Definition at line 10 of file SolidSphere.cc.

12 : Solid(cx, cy, cz, "SolidSphere") {
13 SetRadius(r);
14}
void SetRadius(const double r)
Set the radius of the sphere.
Definition: SolidSphere.cc:59
Solid()=delete
Default constructor.

◆ ~SolidSphere()

Garfield::SolidSphere::~SolidSphere ( )
inline

Destructor.

Definition at line 16 of file SolidSphere.hh.

16{}

Member Function Documentation

◆ 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 47 of file SolidSphere.cc.

49 {
50 xmin = m_cX - m_r;
51 xmax = m_cX + m_r;
52 ymin = m_cY - m_r;
53 ymax = m_cY + m_r;
54 zmin = m_cZ - m_r;
55 zmax = m_cZ + m_r;
56 return true;
57}
double m_cZ
Definition: Solid.hh:164
double m_cY
Definition: Solid.hh:164
double m_cX
Centre of the solid.
Definition: Solid.hh:164

◆ GetDiscretisationLevel()

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

Retrieve the discretization level of a panel.

Implements Garfield::Solid.

Definition at line 157 of file SolidSphere.cc.

157 {
158 return m_dis;
159}

◆ GetRadius()

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

Return the radius.

Reimplemented from Garfield::Solid.

Definition at line 26 of file SolidSphere.hh.

26{ return m_r; }

◆ IsInside()

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

17 {
18 // Transform the point to local coordinates.
19 const double dx = x - m_cX;
20 const double dy = y - m_cY;
21 const double dz = z - m_cZ;
22
23 if (fabs(dx) > m_r || fabs(dy) > m_r || fabs(dz) > m_r) {
24 if (m_debug) {
25 std::cout << "SolidSphere::IsInside: (" << x << ", " << y << ", " << z
26 << ") is outside.\n";
27 }
28 return false;
29 }
30
31 const double r = sqrt(dx * dx + dy * dy + dz * dz);
32 if (r <= m_r) {
33 if (m_debug) {
34 std::cout << "SolidSphere::IsInside: (" << x << ", " << y << ", " << z
35 << ") is inside.\n";
36 }
37 return true;
38 }
39
40 if (m_debug) {
41 std::cout << "SolidSphere::IsInside: (" << x << ", " << y << ", " << z
42 << ") is outside.\n";
43 }
44 return false;
45}
bool m_debug
Debug flag.
Definition: Solid.hh:177
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 21 of file SolidSphere.hh.

21{ return true; }

◆ 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. N specifies the number of meridians and also the number of parallels.

Definition at line 67 of file SolidSphere.cc.

67 {
68 if (n < 3) {
69 std::cerr << "SolidSphere::SetMeridians: Number must be >= 3.\n";
70 return;
71 }
72 m_n = n;
73}

◆ SetRadius()

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

Set the radius of the sphere.

Definition at line 59 of file SolidSphere.cc.

59 {
60 if (r <= 0.) {
61 std::cerr << "SolidSphere::SetRadius: Radius must be > 0.\n";
62 return;
63 }
64 m_r = r;
65}

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 75 of file SolidSphere.cc.

75 {
76 const auto id = GetId();
77 const unsigned int nPanels = panels.size();
78 // Loop over the sphere.
79 for (unsigned int i = 1; i <= m_n; ++i) {
80 const double phi0 = TwoPi * (i - 1.) / m_n;
81 const double phi1 = TwoPi * double(i) / m_n;
82 const double cphi0 = cos(phi0);
83 const double sphi0 = sin(phi0);
84 const double cphi1 = cos(phi1);
85 const double sphi1 = sin(phi1);
86 for (unsigned int j = 1; j <= m_n; ++j) {
87 const double theta0 = -HalfPi + Pi * (j - 1.) / m_n;
88 const double theta1 = -HalfPi + Pi * double(j) / m_n;
89 const double ctheta0 = cos(theta0);
90 const double stheta0 = sin(theta0);
91 const double ctheta1 = cos(theta1);
92 const double stheta1 = sin(theta1);
93 Panel newpanel;
94 // Corners of this parcel.
95 if (j == 1) {
96 const double xv0 = m_cX + m_r * cphi0 * ctheta0;
97 const double yv0 = m_cY + m_r * sphi0 * ctheta0;
98 const double zv0 = m_cZ + m_r * stheta0;
99 const double xv1 = m_cX + m_r * cphi1 * ctheta1;
100 const double yv1 = m_cY + m_r * sphi1 * ctheta1;
101 const double zv1 = m_cZ + m_r * stheta1;
102 const double xv2 = m_cX + m_r * cphi0 * ctheta1;
103 const double yv2 = m_cY + m_r * sphi0 * ctheta1;
104 const double zv2 = m_cZ + m_r * stheta1;
105 newpanel.xv = {xv0, xv1, xv2};
106 newpanel.yv = {yv0, yv1, yv2};
107 newpanel.zv = {zv0, zv1, zv2};
108 } else if (j == m_n) {
109 const double xv0 = m_cX + m_r * cphi0 * ctheta0;
110 const double yv0 = m_cY + m_r * sphi0 * ctheta0;
111 const double zv0 = m_cZ + m_r * stheta0;
112 const double xv1 = m_cX + m_r * cphi1 * ctheta0;
113 const double yv1 = m_cY + m_r * sphi1 * ctheta0;
114 const double zv1 = m_cZ + m_r * stheta0;
115 const double xv2 = m_cX + m_r * cphi1 * ctheta1;
116 const double yv2 = m_cY + m_r * sphi1 * ctheta1;
117 const double zv2 = m_cZ + m_r * stheta1;
118 newpanel.xv = {xv0, xv1, xv2};
119 newpanel.yv = {yv0, yv1, yv2};
120 newpanel.zv = {zv0, zv1, zv2};
121 } else {
122 const double xv0 = m_cX + m_r * cphi0 * ctheta0;
123 const double yv0 = m_cY + m_r * sphi0 * ctheta0;
124 const double zv0 = m_cZ + m_r * stheta0;
125 const double xv1 = m_cX + m_r * cphi1 * ctheta0;
126 const double yv1 = m_cY + m_r * sphi1 * ctheta0;
127 const double zv1 = m_cZ + m_r * stheta0;
128 const double xv2 = m_cX + m_r * cphi1 * ctheta1;
129 const double yv2 = m_cY + m_r * sphi1 * ctheta1;
130 const double zv2 = m_cZ + m_r * stheta1;
131 const double xv3 = m_cX + m_r * cphi0 * ctheta1;
132 const double yv3 = m_cY + m_r * sphi0 * ctheta1;
133 const double zv3 = m_cZ + m_r * stheta1;
134 newpanel.xv = {xv0, xv1, xv2, xv3};
135 newpanel.yv = {yv0, yv1, yv2, yv3};
136 newpanel.zv = {zv0, zv1, zv2, zv3};
137 }
138 // Inclination angle in theta.
139 const double alpha =
140 atan2((ctheta0 - ctheta1) * sqrt((1. + cos(phi1 - phi0)) / 2),
141 stheta1 - stheta0);
142 const double calpha = cos(alpha);
143 const double salpha = sin(alpha);
144 // Store the panel.
145 newpanel.a = cos(0.5 * (phi0 + phi1)) * calpha;
146 newpanel.b = sin(0.5 * (phi0 + phi1)) * calpha;
147 newpanel.c = salpha;
148 newpanel.volume = id;
149 panels.push_back(std::move(newpanel));
150 }
151 }
152 std::cout << "SolidSphere::SolidPanels: " << panels.size() - nPanels
153 << " panels.\n";
154 return true;
155}
unsigned int GetId() const
Get the ID of the solid.
Definition: Solid.hh:117
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: