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::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.
 
bool GetElementaryCell (double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
 Get the coordinates of the elementary cell.
 
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::Component
 Component ()=delete
 Default constructor.
 
 Component (const std::string &name)
 Constructor.
 
virtual ~Component ()
 Destructor.
 
virtual void SetGeometry (Geometry *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 double DelayedWeightingPotential (const double x, const double y, const double z, const double t, 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.
 
virtual bool GetElementaryCell (double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
 Get the coordinates of the elementary cell.
 
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 IntegrateFluxParallelogram (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)
 
double IntegrateWeightingFluxParallelogram (const std::string &label, 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)
 
double IntegrateFluxLine (const double x0, const double y0, const double z0, const double x1, const double y1, const double z1, const double xp, const double yp, const double zp, const unsigned int nI, const int isign=0)
 
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 EnablePeriodicityY (const bool on=true)
 Enable simple periodicity in the $y$ direction.
 
void EnablePeriodicityZ (const bool on=true)
 Enable simple periodicity in the $z$ direction.
 
void IsPeriodic (bool &perx, bool &pery, bool &perz)
 Return periodicity flags.
 
void EnableMirrorPeriodicityX (const bool on=true)
 Enable mirror periodicity in the $x$ direction.
 
void EnableMirrorPeriodicityY (const bool on=true)
 Enable mirror periodicity in the $y$ direction.
 
void EnableMirrorPeriodicityZ (const bool on=true)
 Enable mirror periodicity in the $y$ direction.
 
void IsMirrorPeriodic (bool &perx, bool &pery, bool &perz)
 Return mirror periodicity flags.
 
void EnableAxialPeriodicityX (const bool on=true)
 Enable axial periodicity in the $x$ direction.
 
void EnableAxialPeriodicityY (const bool on=true)
 Enable axial periodicity in the $y$ direction.
 
void EnableAxialPeriodicityZ (const bool on=true)
 Enable axial periodicity in the $z$ direction.
 
void IsAxiallyPeriodic (bool &perx, bool &pery, bool &perz)
 Return axial periodicity flags.
 
void EnableRotationSymmetryX (const bool on=true)
 Enable rotation symmetry around the $x$ axis.
 
void EnableRotationSymmetryY (const bool on=true)
 Enable rotation symmetry around the $y$ axis.
 
void EnableRotationSymmetryZ (const bool on=true)
 Enable rotation symmetry around the $z$ axis.
 
void IsRotationSymmetric (bool &rotx, bool &roty, bool &rotz)
 Return rotation symmetry flags.
 
void EnableDebugging ()
 Switch on debugging messages.
 
void DisableDebugging ()
 Switch off debugging messages.
 
virtual bool HasAttachmentMap () const
 Does the component have attachment maps?
 
virtual bool HasVelocityMap () const
 Does the component have velocity maps?
 
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 bool ElectronVelocity (const double, const double, const double, double &vx, double &vy, double &vz)
 Get the electron drift velocity.
 
virtual bool HoleVelocity (const double, const double, const double, double &vx, double &vy, double &vz)
 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::Component
std::string m_className = "Component"
 Class name.
 
Geometrym_geometry = nullptr
 Pointer to the geometry.
 
std::array< double, 3 > m_b0 = {{0., 0., 0.}}
 Constant magnetic field.
 
bool m_ready = false
 Ready for use?
 
bool m_debug = false
 Switch on/off debugging messages.
 
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.
 

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: Component("Voxel") {}
Component()=delete
Default constructor.

◆ ~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::Component.

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::Component.

Definition at line 82 of file ComponentVoxel.cc.

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

◆ 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::Component.

Definition at line 16 of file ComponentVoxel.cc.

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

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::Component.

Definition at line 47 of file ComponentVoxel.cc.

49 {
50 double v = 0.;
51 ElectricField(x, y, z, ex, ey, ez, v, m, status);
52}
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::Component.

Definition at line 564 of file ComponentVoxel.cc.

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

◆ GetElectricFieldRange()

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

Definition at line 613 of file ComponentVoxel.cc.

615 {
616 if (!m_ready) {
617 std::cerr << m_className << "::GetElectricFieldRange:\n"
618 << " Field map is not ready for interpolation.\n";
619 return false;
620 }
621
622 exmin = exmax = m_efields[0][0][0].fx;
623 eymin = eymax = m_efields[0][0][0].fy;
624 ezmin = ezmax = m_efields[0][0][0].fz;
625 for (unsigned int i = 0; i < m_nX; ++i) {
626 for (unsigned int j = 0; j < m_nY; ++j) {
627 for (unsigned int k = 0; k < m_nZ; ++k) {
628 const Element& element = m_efields[i][j][k];
629 if (element.fx < exmin) exmin = element.fx;
630 if (element.fx > exmax) exmax = element.fx;
631 if (element.fy < eymin) eymin = element.fy;
632 if (element.fy > eymax) eymax = element.fy;
633 if (element.fz < ezmin) ezmin = element.fz;
634 if (element.fz > ezmax) ezmax = element.fz;
635 }
636 }
637 }
638 return true;
639}
Definition: neBEM.h:155

◆ 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 818 of file ComponentVoxel.cc.

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

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 850 of file ComponentVoxel.cc.

852 {
853 v = ex = ey = ez = 0.;
854 if (!m_ready) {
855 if (!m_hasMesh) {
856 std::cerr << m_className << "::GetElement: Mesh not set.\n";
857 return false;
858 }
859 std::cerr << m_className << "::GetElement: Field map not set.\n";
860 return false;
861 }
862 if (i >= m_nX || j >= m_nY || k >= m_nZ) {
863 std::cerr << m_className << "::GetElement: Index out of range.\n";
864 return false;
865 }
866 const Element& element = m_efields[i][j][k];
867 v = element.v;
868 ex = element.fx;
869 ey = element.fy;
870 ez = element.fz;
871 return true;
872}

◆ GetElementaryCell()

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

Get the coordinates of the elementary cell.

Reimplemented from Garfield::Component.

Definition at line 593 of file ComponentVoxel.cc.

595 {
596 if (!m_ready) return false;
597 xmin = m_xMin;
598 xmax = m_xMax;
599 ymin = m_yMin;
600 ymax = m_yMax;
601 zmin = m_zMin;
602 zmax = m_zMax;
603 return true;
604}

◆ 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::Component.

Definition at line 147 of file ComponentVoxel.cc.

148 {
149 // Make sure the field map has been loaded.
150 if (!m_ready) {
151 std::cerr << m_className << "::GetMedium:\n"
152 << " Field map is not available for interpolation.\n";
153 return nullptr;
154 }
155
156 unsigned int i, j, k;
157 bool xMirrored, yMirrored, zMirrored;
158 if (!GetElement(x, y, z, i, j, k, xMirrored, yMirrored, zMirrored)) {
159 return nullptr;
160 }
161 const int region = m_regions[i][j][k];
162 if (region < 0 || region > (int)m_media.size()) return nullptr;
163 return m_media[region];
164}
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 672 of file ComponentVoxel.cc.

672 {
673 if (i >= m_media.size()) {
674 std::cerr << m_className << "::GetMedium: Index out of range.\n";
675 return nullptr;
676 }
677 return m_media[i];
678}

◆ GetVoltageRange()

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

Calculate the voltage range [V].

Implements Garfield::Component.

Definition at line 606 of file ComponentVoxel.cc.

606 {
607 if (!m_ready) return false;
608 vmin = m_pMin;
609 vmax = m_pMax;
610 return true;
611}

◆ 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 202 of file ComponentVoxel.cc.

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

◆ 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 290 of file ComponentVoxel.cc.

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

◆ 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 234 of file ComponentVoxel.cc.

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

◆ 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 258 of file ComponentVoxel.cc.

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

◆ 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::Component.

Definition at line 132 of file ComponentVoxel.cc.

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

◆ PrintRegions()

void Garfield::ComponentVoxel::PrintRegions ( ) const

Print all regions.

Definition at line 641 of file ComponentVoxel.cc.

641 {
642 // Do not proceed if not properly initialised.
643 if (!m_ready) {
644 std::cerr << m_className << "::PrintRegions:\n"
645 << " Field map not yet initialised.\n";
646 return;
647 }
648
649 if (m_media.empty()) {
650 std::cerr << m_className << "::PrintRegions: No regions defined.\n";
651 return;
652 }
653
654 std::cout << m_className << "::PrintRegions:\n";
655 std::cout << " Index Medium\n";
656 const unsigned int nMedia = m_media.size();
657 for (unsigned int i = 0; i < nMedia; ++i) {
658 const std::string name = m_media[i] ? m_media[i]->GetName() : "none";
659 std::cout << " " << i << " " << name << "\n";
660 }
661}

◆ SetMedium()

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

Set the medium in region i.

Definition at line 663 of file ComponentVoxel.cc.

663 {
664 if (!m) {
665 std::cerr << m_className << "::SetMedium: Null pointer.\n";
666 if (m_media.empty()) return;
667 }
668 if (i >= m_media.size()) m_media.resize(i + 1, nullptr);
669 m_media[i] = m;
670}

◆ 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 166 of file ComponentVoxel.cc.

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

◆ 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 125 of file ComponentVoxel.cc.

126 {
127 m_wField_xOffset = x;
128 m_wField_yOffset = y;
129 m_wField_zOffset = z;
130}

◆ 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::Component.

Definition at line 54 of file ComponentVoxel.cc.

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

◆ 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::Component.

Definition at line 68 of file ComponentVoxel.cc.

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

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