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::ComponentVoxel Class Reference

Component for interpolating field maps stored in a regular mesh. More...

#include <ComponentVoxel.hh>

+ Inheritance diagram for Garfield::ComponentVoxel:

Public Member Functions

 ComponentVoxel ()
 Constructor.
 
 ~ComponentVoxel ()
 Destructor.
 
void Clear () override
 Reset.
 
void ElectricField (const double x, const double y, const double z, double &ex, double &ey, double &ez, double &v, Medium *&m, int &status) override
 Calculate the drift field [V/cm] and potential [V] at (x, y, z).
 
void ElectricField (const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status) override
 
void WeightingField (const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
 
double WeightingPotential (const double x, const double y, const double z, const std::string &label) override
 
void DelayedWeightingField (const double x, const double y, const double z, const double t, double &wx, double &wy, double &wz, const std::string &label) override
 
void MagneticField (const double x, const double y, const double z, double &bx, double &by, double &bz, int &status) override
 
void EnableInterpolation (const bool on=true)
 Interpolate between field values at the element centres.
 
void SetWeightingFieldOffset (const double x, const double y, const double z)
 
MediumGetMedium (const double x, const double y, const double z) override
 Get the medium at a given location (x, y, z).
 
bool GetVoltageRange (double &vmin, double &vmax) override
 Calculate the voltage range [V].
 
bool GetElectricFieldRange (double &exmin, double &exmax, double &eymin, double &eymax, double &ezmin, double &ezmax)
 
bool GetBoundingBox (double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
 Get the bounding box coordinates.
 
void SetMesh (const unsigned int nx, const unsigned int ny, const unsigned int nz, const double xmin, const double xmax, const double ymin, const double ymax, const double zmin, const double zmax)
 
bool LoadElectricField (const std::string &filename, const std::string &format, const bool withPotential, const bool withRegion, const double scaleX=1., const double scaleE=1., const double scaleP=1.)
 
bool LoadWeightingField (const std::string &filename, const std::string &format, const bool withPotential, const double scaleX=1., const double scaleE=1., const double scaleP=1.)
 Import (prompt) weighting field from file.
 
bool LoadWeightingField (const std::string &filename, const std::string &format, const double time, const bool withPotential, const double scaleX=1., const double scaleE=1., const double scaleP=1.)
 Import delayed weighting field from file.
 
bool LoadMagneticField (const std::string &filename, const std::string &format, const double scaleX=1., const double scaleB=1.)
 Import magnetic field values from a file.
 
bool GetElement (const double xi, const double yi, const double zi, unsigned int &i, unsigned int &j, unsigned int &k, bool &xMirrored, bool &yMirrored, bool &zMirrored) const
 Return the indices of the element at a given point.
 
bool GetElement (const unsigned int i, const unsigned int j, const unsigned int k, double &v, double &ex, double &ey, double &ez) const
 Return the field for an element with given index.
 
void SetMedium (const unsigned int i, Medium *m)
 Set the medium in region i.
 
MediumGetMedium (const unsigned int i) const
 Get the medium in region i.
 
void PrintRegions () const
 Print all regions.
 
- Public Member Functions inherited from Garfield::ComponentBase
 ComponentBase ()
 Constructor.
 
virtual ~ComponentBase ()
 Destructor.
 
virtual void SetGeometry (GeometryBase *geo)
 Define the geometry.
 
virtual void Clear ()
 Reset.
 
virtual MediumGetMedium (const double x, const double y, const double z)
 Get the medium at a given location (x, y, z).
 
virtual void ElectricField (const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status)=0
 
virtual void ElectricField (const double x, const double y, const double z, double &ex, double &ey, double &ez, double &v, Medium *&m, int &status)=0
 Calculate the drift field [V/cm] and potential [V] at (x, y, z).
 
virtual bool GetVoltageRange (double &vmin, double &vmax)=0
 Calculate the voltage range [V].
 
virtual void WeightingField (const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label)
 
virtual double WeightingPotential (const double x, const double y, const double z, const std::string &label)
 
virtual void DelayedWeightingField (const double x, const double y, const double z, const double t, double &wx, double &wy, double &wz, const std::string &label)
 
virtual void MagneticField (const double x, const double y, const double z, double &bx, double &by, double &bz, int &status)
 
void SetMagneticField (const double bx, const double by, const double bz)
 Set a constant magnetic field.
 
virtual bool IsReady ()
 Ready for use?
 
virtual bool GetBoundingBox (double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
 Get the bounding box coordinates.
 
double IntegrateFluxCircle (const double xc, const double yc, const double r, const unsigned int nI=50)
 
double IntegrateFluxSphere (const double xc, const double yc, const double zc, const double r, const unsigned int nI=20)
 
double IntegrateFlux (const double x0, const double y0, const double z0, const double dx1, const double dy1, const double dz1, const double dx2, const double dy2, const double dz2, const unsigned int nU=20, const unsigned int nV=20)
 
virtual bool IsWireCrossed (const double x0, const double y0, const double z0, const double x1, const double y1, const double z1, double &xc, double &yc, double &zc, const bool centre, double &rc)
 
virtual bool IsInTrapRadius (const double q0, const double x0, const double y0, const double z0, double &xw, double &yw, double &rw)
 
void EnablePeriodicityX (const bool on=true)
 Enable simple periodicity in the $x$ direction.
 
void DisablePeriodicityX ()
 
void EnablePeriodicityY (const bool on=true)
 Enable simple periodicity in the $y$ direction.
 
void DisablePeriodicityY ()
 
void EnablePeriodicityZ (const bool on=true)
 Enable simple periodicity in the $z$ direction.
 
void DisablePeriodicityZ ()
 
void EnableMirrorPeriodicityX (const bool on=true)
 Enable mirror periodicity in the $x$ direction.
 
void DisableMirrorPeriodicityX ()
 
void EnableMirrorPeriodicityY (const bool on=true)
 Enable mirror periodicity in the $y$ direction.
 
void DisableMirrorPeriodicityY ()
 
void EnableMirrorPeriodicityZ (const bool on=true)
 Enable mirror periodicity in the $y$ direction.
 
void DisableMirrorPeriodicityZ ()
 
void EnableAxialPeriodicityX (const bool on=true)
 Enable axial periodicity in the $x$ direction.
 
void DisableAxialPeriodicityX ()
 
void EnableAxialPeriodicityY (const bool on=true)
 Enable axial periodicity in the $y$ direction.
 
void DisableAxialPeriodicityY ()
 
void EnableAxialPeriodicityZ (const bool on=true)
 Enable axial periodicity in the $z$ direction.
 
void DisableAxialPeriodicityZ ()
 
void EnableRotationSymmetryX (const bool on=true)
 Enable rotation symmetry around the $x$ axis.
 
void DisableRotationSymmetryX ()
 
void EnableRotationSymmetryY (const bool on=true)
 Enable rotation symmetry around the $y$ axis.
 
void DisableRotationSymmetryY ()
 
void EnableRotationSymmetryZ (const bool on=true)
 Enable rotation symmetry around the $z$ axis.
 
void DisableRotationSymmetryZ ()
 
void EnableDebugging ()
 Switch on debugging messages.
 
void DisableDebugging ()
 Switch off debugging messages.
 
void ActivateTraps ()
 Request trapping to be taken care of by the component (for TCAD).
 
void DeactivateTraps ()
 
bool IsTrapActive ()
 
void ActivateVelocityMap ()
 Request velocity to be taken care of by the component (for TCAD).
 
void DectivateVelocityMap ()
 
bool IsVelocityActive ()
 
virtual bool ElectronAttachment (const double, const double, const double, double &eta)
 Get the electron attachment coefficient.
 
virtual bool HoleAttachment (const double, const double, const double, double &eta)
 Get the hole attachment coefficient.
 
virtual void ElectronVelocity (const double, const double, const double, double &vx, double &vy, double &vz, Medium *&, int &status)
 Get the electron drift velocity.
 
virtual void HoleVelocity (const double, const double, const double, double &vx, double &vy, double &vz, Medium *&, int &status)
 Get the hole drift velocity.
 
virtual bool GetElectronLifetime (const double, const double, const double, double &etau)
 
virtual bool GetHoleLifetime (const double, const double, const double, double &htau)
 

Additional Inherited Members

virtual void Reset ()=0
 Reset the component.
 
virtual void UpdatePeriodicity ()=0
 Verify periodicities.
 
- Protected Attributes inherited from Garfield::ComponentBase
std::string m_className = "ComponentBase"
 Class name.
 
GeometryBasem_geometry = nullptr
 Pointer to the geometry.
 
bool m_ready = false
 Ready for use?
 
bool m_activeTraps = false
 Does the component have traps?
 
bool m_hasVelocityMap = false
 Does the component have velocity maps?
 
std::array< bool, 3 > m_periodic = {{false, false, false}}
 Simple periodicity in x, y, z.
 
std::array< bool, 3 > m_mirrorPeriodic = {{false, false, false}}
 Mirror periodicity in x, y, z.
 
std::array< bool, 3 > m_axiallyPeriodic = {{false, false, false}}
 Axial periodicity in x, y, z.
 
std::array< bool, 3 > m_rotationSymmetric = {{false, false, false}}
 Rotation symmetry around x-axis, y-axis, z-axis.
 
double m_bx0 = 0.
 
double m_by0 = 0.
 
double m_bz0 = 0.
 
bool m_debug = false
 Switch on/off debugging messages.
 

Detailed Description

Component for interpolating field maps stored in a regular mesh.

Definition at line 10 of file ComponentVoxel.hh.

Constructor & Destructor Documentation

◆ ComponentVoxel()

Garfield::ComponentVoxel::ComponentVoxel ( )

Constructor.

Definition at line 14 of file ComponentVoxel.cc.

14 : ComponentBase() {
15 m_className = "ComponentVoxel";
16}
ComponentBase()
Constructor.
Definition: ComponentBase.cc:9
std::string m_className
Class name.

◆ ~ComponentVoxel()

Garfield::ComponentVoxel::~ComponentVoxel ( )
inline

Destructor.

Definition at line 15 of file ComponentVoxel.hh.

15{}

Member Function Documentation

◆ Clear()

void Garfield::ComponentVoxel::Clear ( )
inlineoverridevirtual

Reset.

Reimplemented from Garfield::ComponentBase.

Definition at line 17 of file ComponentVoxel.hh.

17{ Reset(); }

◆ DelayedWeightingField()

void Garfield::ComponentVoxel::DelayedWeightingField ( const double  x,
const double  y,
const double  z,
const double  t,
double &  wx,
double &  wy,
double &  wz,
const std::string &  label 
)
overridevirtual

Calculate the delayed weighting field at a given point and time and for a given electrode.

Parameters
x,y,zcoordinates [cm].
ttime [ns].
wx,wy,wzcomponents of the weighting field [1/cm].
labelname of the electrode

Reimplemented from Garfield::ComponentBase.

Definition at line 84 of file ComponentVoxel.cc.

87 {
88
89 wx = wy = wz = 0.;
90 if (m_wdtimes.empty()) return;
91 // Assume no weighting field for times outside the range of available maps.
92 if (t < m_wdtimes.front() || t > m_wdtimes.back()) return;
93
94 const double xx = x - m_wField_xOffset;
95 const double yy = y - m_wField_yOffset;
96 const double zz = z - m_wField_zOffset;
97
98 const auto it1 = std::upper_bound(m_wdtimes.cbegin(), m_wdtimes.cend(), t);
99 const auto it0 = std::prev(it1);
100
101 const double dt = t - *it0;
102 double wp = 0.;
103 int region = 0;
104 const unsigned int i0 = it0 - m_wdtimes.cbegin();
105 double wx0 = 0., wy0 = 0., wz0 = 0.;
106 if (!GetField(xx, yy, zz, m_wdfields[i0], wx0, wy0, wz0, wp, region)) {
107 return;
108 }
109 if (dt < Small || it1 == m_wdtimes.cend()) {
110 wx = wx0;
111 wy = wy0;
112 wz = wz0;
113 return;
114 }
115 const unsigned int i1 = it1 - m_wdtimes.cbegin();
116 double wx1 = 0., wy1 = 0., wz1 = 0.;
117 if (!GetField(xx, yy, zz, m_wdfields[i1], wx1, wy1, wz1, wp, region)) {
118 return;
119 }
120 const double f1 = dt / (*it1 - *it0);
121 const double f0 = 1. - f1;
122 wx = f0 * wx0 + f1 * wx1;
123 wy = f0 * wy0 + f1 * wy1;
124 wz = f0 * wz0 + f1 * wz1;
125}

◆ ElectricField() [1/2]

void Garfield::ComponentVoxel::ElectricField ( const double  x,
const double  y,
const double  z,
double &  ex,
double &  ey,
double &  ez,
double &  v,
Medium *&  m,
int &  status 
)
overridevirtual

Calculate the drift field [V/cm] and potential [V] at (x, y, z).

Implements Garfield::ComponentBase.

Definition at line 18 of file ComponentVoxel.cc.

21 {
22 m = nullptr;
23 status = 0;
24
25 // Make sure the field map has been loaded.
26 if (!m_ready) {
27 std::cerr << m_className << "::ElectricField:\n"
28 << " Field map is not available for interpolation.\n";
29 status = -10;
30 return;
31 }
32
33 status = 0;
34 int region = -1;
35 if (!GetField(x, y, z, m_efields, ex, ey, ez, p, region)) {
36 status = -6;
37 return;
38 }
39
40 if (region < 0 || region > (int)m_media.size()) {
41 m = nullptr;
42 status = -5;
43 return;
44 }
45 m = m_media[region];
46 if (!m) status = -5;
47}
bool m_ready
Ready for use?

Referenced by ElectricField().

◆ ElectricField() [2/2]

void Garfield::ComponentVoxel::ElectricField ( const double  x,
const double  y,
const double  z,
double &  ex,
double &  ey,
double &  ez,
Medium *&  m,
int &  status 
)
overridevirtual

Calculate the drift field at given point.

Parameters
x,y,zcoordinates [cm].
ex,ey,ezcomponents of the electric field [V/cm].
mpointer to the medium at this location.
statusstatus flag

Status flags:

        0: Inside an active medium
      > 0: Inside a wire of type X
-4 ... -1: On the side of a plane where no wires are
       -5: Inside the mesh but not in an active medium
       -6: Outside the mesh
      -10: Unknown potential type (should not occur)
    other: Other cases (should not occur)

Implements Garfield::ComponentBase.

Definition at line 49 of file ComponentVoxel.cc.

51 {
52 double v = 0.;
53 ElectricField(x, y, z, ex, ey, ez, v, m, status);
54}
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, double &v, Medium *&m, int &status) override
Calculate the drift field [V/cm] and potential [V] at (x, y, z).

◆ EnableInterpolation()

void Garfield::ComponentVoxel::EnableInterpolation ( const bool  on = true)
inline

Interpolate between field values at the element centres.

Definition at line 38 of file ComponentVoxel.hh.

38{ m_interpolate = on; }

◆ GetBoundingBox()

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

Get the bounding box coordinates.

Reimplemented from Garfield::ComponentBase.

Definition at line 567 of file ComponentVoxel.cc.

568 {
569 if (!m_ready) return false;
570 if (m_periodic[0] || m_mirrorPeriodic[0]) {
571 xmin = -INFINITY;
572 xmax = +INFINITY;
573 } else {
574 xmin = m_xMin;
575 xmax = m_xMax;
576 }
577
578 if (m_periodic[1] || m_mirrorPeriodic[1]) {
579 ymin = -INFINITY;
580 ymax = +INFINITY;
581 } else {
582 ymin = m_yMin;
583 ymax = m_yMax;
584 }
585
586 if (m_periodic[2] || m_mirrorPeriodic[2]) {
587 zmin = -INFINITY;
588 zmax = +INFINITY;
589 } else {
590 zmin = m_zMin;
591 zmax = m_zMax;
592 }
593 return true;
594}
std::array< bool, 3 > m_periodic
Simple periodicity in x, y, z.
std::array< bool, 3 > m_mirrorPeriodic
Mirror periodicity in x, y, z.

◆ GetElectricFieldRange()

bool Garfield::ComponentVoxel::GetElectricFieldRange ( double &  exmin,
double &  exmax,
double &  eymin,
double &  eymax,
double &  ezmin,
double &  ezmax 
)

Definition at line 603 of file ComponentVoxel.cc.

605 {
606 if (!m_ready) {
607 std::cerr << m_className << "::GetElectricFieldRange:\n"
608 << " Field map is not ready for interpolation.\n";
609 return false;
610 }
611
612 exmin = exmax = m_efields[0][0][0].fx;
613 eymin = eymax = m_efields[0][0][0].fy;
614 ezmin = ezmax = m_efields[0][0][0].fz;
615 for (unsigned int i = 0; i < m_nX; ++i) {
616 for (unsigned int j = 0; j < m_nY; ++j) {
617 for (unsigned int k = 0; k < m_nZ; ++k) {
618 const Element& element = m_efields[i][j][k];
619 if (element.fx < exmin) exmin = element.fx;
620 if (element.fx > exmax) exmax = element.fx;
621 if (element.fy < eymin) eymin = element.fy;
622 if (element.fy > eymax) eymax = element.fy;
623 if (element.fz < ezmin) ezmin = element.fz;
624 if (element.fz > ezmax) ezmax = element.fz;
625 }
626 }
627 }
628 return true;
629}

◆ GetElement() [1/2]

bool Garfield::ComponentVoxel::GetElement ( const double  xi,
const double  yi,
const double  zi,
unsigned int &  i,
unsigned int &  j,
unsigned int &  k,
bool &  xMirrored,
bool &  yMirrored,
bool &  zMirrored 
) const

Return the indices of the element at a given point.

Definition at line 808 of file ComponentVoxel.cc.

812 {
813 if (!m_hasMesh) {
814 std::cerr << m_className << "::GetElement: Mesh is not set.\n";
815 return false;
816 }
817
818 // Reduce the point to the basic cell (in case of periodicity) and
819 // check if it is inside the mesh.
820 const double x =
821 Reduce(xi, m_xMin, m_xMax, m_periodic[0], m_mirrorPeriodic[0], xMirrored);
822 if (x < m_xMin || x > m_xMax) return false;
823 const double y =
824 Reduce(yi, m_yMin, m_yMax, m_periodic[1], m_mirrorPeriodic[1], yMirrored);
825 if (y < m_yMin || y > m_yMax) return false;
826 const double z =
827 Reduce(zi, m_zMin, m_zMax, m_periodic[2], m_mirrorPeriodic[2], zMirrored);
828 if (z < m_zMin || z > m_zMax) return false;
829
830 // Get the indices.
831 i = (unsigned int)((x - m_xMin) / m_dx);
832 j = (unsigned int)((y - m_yMin) / m_dy);
833 k = (unsigned int)((z - m_zMin) / m_dz);
834 if (i >= m_nX) i = m_nX - 1;
835 if (j >= m_nY) j = m_nY - 1;
836 if (k >= m_nZ) k = m_nZ - 1;
837 return true;
838}

Referenced by GetMedium().

◆ GetElement() [2/2]

bool Garfield::ComponentVoxel::GetElement ( const unsigned int  i,
const unsigned int  j,
const unsigned int  k,
double &  v,
double &  ex,
double &  ey,
double &  ez 
) const

Return the field for an element with given index.

Definition at line 840 of file ComponentVoxel.cc.

842 {
843 v = ex = ey = ez = 0.;
844 if (!m_ready) {
845 if (!m_hasMesh) {
846 std::cerr << m_className << "::GetElement: Mesh not set.\n";
847 return false;
848 }
849 std::cerr << m_className << "::GetElement: Field map not set.\n";
850 return false;
851 }
852 if (i >= m_nX || j >= m_nY || k >= m_nZ) {
853 std::cerr << m_className << "::GetElement: Index out of range.\n";
854 return false;
855 }
856 const Element& element = m_efields[i][j][k];
857 v = element.v;
858 ex = element.fx;
859 ey = element.fy;
860 ez = element.fz;
861 return true;
862}

◆ GetMedium() [1/2]

Medium * Garfield::ComponentVoxel::GetMedium ( const double  x,
const double  y,
const double  z 
)
overridevirtual

Get the medium at a given location (x, y, z).

Reimplemented from Garfield::ComponentBase.

Definition at line 149 of file ComponentVoxel.cc.

150 {
151 // Make sure the field map has been loaded.
152 if (!m_ready) {
153 std::cerr << m_className << "::GetMedium:\n"
154 << " Field map is not available for interpolation.\n";
155 return nullptr;
156 }
157
158 unsigned int i, j, k;
159 bool xMirrored, yMirrored, zMirrored;
160 if (!GetElement(x, y, z, i, j, k, xMirrored, yMirrored, zMirrored)) {
161 return nullptr;
162 }
163 const int region = m_regions[i][j][k];
164 if (region < 0 || region > (int)m_media.size()) return nullptr;
165 return m_media[region];
166}
bool GetElement(const double xi, const double yi, const double zi, unsigned int &i, unsigned int &j, unsigned int &k, bool &xMirrored, bool &yMirrored, bool &zMirrored) const
Return the indices of the element at a given point.

◆ GetMedium() [2/2]

Medium * Garfield::ComponentVoxel::GetMedium ( const unsigned int  i) const

Get the medium in region i.

Definition at line 662 of file ComponentVoxel.cc.

662 {
663 if (i > m_media.size()) {
664 std::cerr << m_className << "::GetMedium: Index out of range.\n";
665 return nullptr;
666 }
667 return m_media[i];
668}

◆ GetVoltageRange()

bool Garfield::ComponentVoxel::GetVoltageRange ( double &  vmin,
double &  vmax 
)
overridevirtual

Calculate the voltage range [V].

Implements Garfield::ComponentBase.

Definition at line 596 of file ComponentVoxel.cc.

596 {
597 if (!m_ready) return false;
598 vmin = m_pMin;
599 vmax = m_pMax;
600 return true;
601}

◆ LoadElectricField()

bool Garfield::ComponentVoxel::LoadElectricField ( const std::string &  filename,
const std::string &  format,
const bool  withPotential,
const bool  withRegion,
const double  scaleX = 1.,
const double  scaleE = 1.,
const double  scaleP = 1. 
)

Import electric field and potential values from a file. The file is supposed to contain one line for each mesh point starting with

  • either two or three floating point numbers, specifying the coordinates (in cm) of the element centre or
  • two or three integers specifying the index of the element in the mesh,

followed by

  • two or three floating point numbers for the electric field (in V/cm), and (depending on the values of withPotential and withRegion),
  • a floating point number specifying the potential (in V), and
  • an integer specifying the "region" of the element.

Format types are:

  • "xy", "xyz": elements are specified by the coordinates of their centres
  • "ij", "ijk": elements are specified by their indices

Definition at line 204 of file ComponentVoxel.cc.

208 {
209 m_ready = false;
210 m_efields.clear();
211 m_hasPotential = m_hasEfield = false;
212 if (!m_hasMesh) {
213 std::cerr << m_className << "::LoadElectricField:\n"
214 << " Mesh is not set. Call SetMesh first.\n";
215 return false;
216 }
217
218 // Set up the grid.
219 Initialise(m_efields);
220 InitialiseRegions();
221
222 m_pMin = m_pMax = 0.;
223 if (withP) {
224 m_pMin = 1.;
225 m_pMax = -1.;
226 }
227 if (!LoadData(fname, fmt, withP, withR, scaleX, scaleE, scaleP, m_efields)) {
228 return false;
229 }
230 m_hasEfield = true;
231 m_ready = true;
232 if (withP) m_hasPotential = true;
233 return true;
234}

◆ LoadMagneticField()

bool Garfield::ComponentVoxel::LoadMagneticField ( const std::string &  filename,
const std::string &  format,
const double  scaleX = 1.,
const double  scaleB = 1. 
)

Import magnetic field values from a file.

Definition at line 292 of file ComponentVoxel.cc.

295 {
296 m_hasBfield = false;
297 if (!m_hasMesh) {
298 std::cerr << m_className << "::LoadMagneticField:\n"
299 << " Mesh is not set. Call SetMesh first.\n";
300 return false;
301 }
302
303 // Set up the grid.
304 Initialise(m_bfields);
305 InitialiseRegions();
306
307 // Read the file.
308 if (!LoadData(fname, fmt, false, false, scaleX, scaleB, 1., m_bfields)) {
309 return false;
310 }
311 m_hasBfield = true;
312 return true;
313}

◆ LoadWeightingField() [1/2]

bool Garfield::ComponentVoxel::LoadWeightingField ( const std::string &  filename,
const std::string &  format,
const bool  withPotential,
const double  scaleX = 1.,
const double  scaleE = 1.,
const double  scaleP = 1. 
)

Import (prompt) weighting field from file.

Definition at line 236 of file ComponentVoxel.cc.

241 {
242 m_hasWfield = false;
243 if (!m_hasMesh) {
244 std::cerr << m_className << "::LoadWeightingField:\n"
245 << " Mesh is not set. Call SetMesh first.\n";
246 return false;
247 }
248
249 // Set up the grid.
250 Initialise(m_wfields);
251 if (m_regions.empty()) InitialiseRegions();
252
253 // Read the file.
254 if (!LoadData(fname, fmt, withP, false, scaleX, scaleE, scaleP, m_wfields)) {
255 return false;
256 }
257 m_hasWfield = true;
258 return true;
259}

◆ LoadWeightingField() [2/2]

bool Garfield::ComponentVoxel::LoadWeightingField ( const std::string &  filename,
const std::string &  format,
const double  time,
const bool  withPotential,
const double  scaleX = 1.,
const double  scaleE = 1.,
const double  scaleP = 1. 
)

Import delayed weighting field from file.

Definition at line 260 of file ComponentVoxel.cc.

264 {
265
266 if (!m_hasMesh) {
267 std::cerr << m_className << "::LoadWeightingField:\n"
268 << " Mesh is not set. Call SetMesh first.\n";
269 return false;
270 }
271
272 std::vector<std::vector<std::vector<Element> > > wfield;
273 Initialise(wfield);
274 if (m_regions.empty()) InitialiseRegions();
275
276 // Read the file.
277 if (!LoadData(fname, fmt, withP, false, scaleX, scaleE, scaleP, wfield)) {
278 return false;
279 }
280 if (m_wdtimes.empty() || t > m_wdtimes.back()) {
281 m_wdtimes.push_back(t);
282 m_wdfields.push_back(std::move(wfield));
283 } else {
284 const auto it = std::upper_bound(m_wdtimes.cbegin(), m_wdtimes.cend(), t);
285 const auto n = std::distance(m_wdtimes.cbegin(), it);
286 m_wdtimes.insert(it, t);
287 m_wdfields.insert(m_wdfields.cbegin() + n, std::move(wfield));
288 }
289 return true;
290}

◆ MagneticField()

void Garfield::ComponentVoxel::MagneticField ( const double  x,
const double  y,
const double  z,
double &  bx,
double &  by,
double &  bz,
int &  status 
)
overridevirtual

Calculate the magnetic field at a given point.

Parameters
x,y,zcoordinates [cm].
bx,by,bzcomponents of the magnetic field [Tesla].
statusstatus flag.

Reimplemented from Garfield::ComponentBase.

Definition at line 134 of file ComponentVoxel.cc.

136 {
137 status = 0;
138 if (!m_hasBfield) {
139 return ComponentBase::MagneticField(x, y, z, bx, by, bz, status);
140 }
141
142 int region = -1;
143 double p = 0.;
144 if (!GetField(x, y, z, m_bfields, bx, by, bz, p, region)) {
145 status = -6;
146 }
147}
virtual void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status)

◆ PrintRegions()

void Garfield::ComponentVoxel::PrintRegions ( ) const

Print all regions.

Definition at line 631 of file ComponentVoxel.cc.

631 {
632 // Do not proceed if not properly initialised.
633 if (!m_ready) {
634 std::cerr << m_className << "::PrintRegions:\n"
635 << " Field map not yet initialised.\n";
636 return;
637 }
638
639 if (m_media.empty()) {
640 std::cerr << m_className << "::PrintRegions: No regions defined.\n";
641 return;
642 }
643
644 std::cout << m_className << "::PrintRegions:\n";
645 std::cout << " Index Medium\n";
646 const unsigned int nMedia = m_media.size();
647 for (unsigned int i = 0; i < nMedia; ++i) {
648 const std::string name = m_media[i] ? m_media[i]->GetName() : "none";
649 std::cout << " " << i << " " << name << "\n";
650 }
651}

◆ SetMedium()

void Garfield::ComponentVoxel::SetMedium ( const unsigned int  i,
Medium m 
)

Set the medium in region i.

Definition at line 653 of file ComponentVoxel.cc.

653 {
654 if (!m) {
655 std::cerr << m_className << "::SetMedium: Null pointer.\n";
656 if (m_media.empty()) return;
657 }
658 if (i >= m_media.size()) m_media.resize(i + 1, nullptr);
659 m_media[i] = m;
660}

◆ SetMesh()

void Garfield::ComponentVoxel::SetMesh ( const unsigned int  nx,
const unsigned int  ny,
const unsigned int  nz,
const double  xmin,
const double  xmax,
const double  ymin,
const double  ymax,
const double  zmin,
const double  zmax 
)

Define the grid.

Parameters
nx,ny,nznumber of bins along x, y, z.
xmin,xmaxrange along $x$.
ymin,ymaxrange along $y$.
zmin,zmaxrange along $z$.

Definition at line 168 of file ComponentVoxel.cc.

172 {
173 Reset();
174 if (nx == 0 || ny == 0 || nz == 0) {
175 std::cerr << m_className << "::SetMesh:\n"
176 << " Number of mesh elements must be positive.\n";
177 return;
178 }
179 if (xmin >= xmax) {
180 std::cerr << m_className << "::SetMesh: Invalid x range.\n";
181 return;
182 } else if (ymin >= ymax) {
183 std::cerr << m_className << "::SetMesh: Invalid y range.\n";
184 return;
185 } else if (zmin >= zmax) {
186 std::cerr << m_className << "::SetMesh: Invalid z range.\n";
187 return;
188 }
189 m_nX = nx;
190 m_nY = ny;
191 m_nZ = nz;
192 m_xMin = xmin;
193 m_yMin = ymin;
194 m_zMin = zmin;
195 m_xMax = xmax;
196 m_yMax = ymax;
197 m_zMax = zmax;
198 m_dx = (m_xMax - m_xMin) / m_nX;
199 m_dy = (m_yMax - m_yMin) / m_nY;
200 m_dz = (m_zMax - m_zMin) / m_nZ;
201 m_hasMesh = true;
202}

◆ SetWeightingFieldOffset()

void Garfield::ComponentVoxel::SetWeightingFieldOffset ( const double  x,
const double  y,
const double  z 
)

Offset coordinates in the weighting field, such that the same numerical weighting field map can be used for electrodes at different positions.

Definition at line 127 of file ComponentVoxel.cc.

128 {
129 m_wField_xOffset = x;
130 m_wField_yOffset = y;
131 m_wField_zOffset = z;
132}

◆ WeightingField()

void Garfield::ComponentVoxel::WeightingField ( const double  x,
const double  y,
const double  z,
double &  wx,
double &  wy,
double &  wz,
const std::string &  label 
)
overridevirtual

Calculate the weighting field at a given point and for a given electrode.

Parameters
x,y,zcoordinates [cm].
wx,wy,wzcomponents of the weighting field [1/cm].
labelname of the electrode

Reimplemented from Garfield::ComponentBase.

Definition at line 56 of file ComponentVoxel.cc.

58 {
59
60 wx = wy = wz = 0.;
61 if (!m_hasWfield) return;
62 const double xx = x - m_wField_xOffset;
63 const double yy = y - m_wField_yOffset;
64 const double zz = z - m_wField_zOffset;
65 double wp = 0.;
66 int region = 0;
67 GetField(xx, yy, zz, m_wfields, wx, wy, wz, wp, region);
68}

◆ WeightingPotential()

double Garfield::ComponentVoxel::WeightingPotential ( const double  x,
const double  y,
const double  z,
const std::string &  label 
)
overridevirtual

Calculate the weighting potential at a given point.

Parameters
x,y,zcoordinates [cm].
labelname of the electrode.
Returns
weighting potential [dimensionless].

Reimplemented from Garfield::ComponentBase.

Definition at line 70 of file ComponentVoxel.cc.

72 {
73 if (!m_hasWfield) return 0.;
74 const double xx = x - m_wField_xOffset;
75 const double yy = y - m_wField_yOffset;
76 const double zz = z - m_wField_zOffset;
77 double wx = 0., wy = 0., wz = 0.;
78 double wp = 0.;
79 int region = 0;
80 if (!GetField(xx, yy, zz, m_wfields, wx, wy, wz, wp, region)) return 0.;
81 return wp;
82}

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