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

Component for interpolating field maps on a regular mesh. More...

#include <ComponentGrid.hh>

+ Inheritance diagram for Garfield::ComponentGrid:

Public Member Functions

 ComponentGrid ()
 Constructor.
 
 ~ComponentGrid ()
 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
 
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 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 GetMesh (unsigned int &nx, unsigned int &ny, unsigned int &nz, double &xmin, double &xmax, double &ymin, double &ymax, double &zmin, double &zmax) const
 Retrieve the parameters of the grid.
 
bool LoadElectricField (const std::string &filename, const std::string &format, const bool withPotential, const bool withFlag, 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.
 
void SetWeightingFieldOffset (const double x, const double y, const double z)
 
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 SaveElectricField (ComponentBase *cmp, const std::string &filename, const std::string &format)
 
bool SaveWeightingField (ComponentBase *cmp, const std::string &id, const std::string &filename, const std::string &format)
 
bool GetElectricField (const unsigned int i, const unsigned int j, const unsigned int k, double &v, double &ex, double &ey, double &ez) const
 Return the field at a given node.
 
void SetMedium (Medium *m)
 Set the medium.
 
MediumGetMedium () const
 Get the medium.
 
- 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 on a regular mesh.

Definition at line 10 of file ComponentGrid.hh.

Constructor & Destructor Documentation

◆ ComponentGrid()

Garfield::ComponentGrid::ComponentGrid ( )

Constructor.

Definition at line 67 of file ComponentGrid.cc.

67 : ComponentBase() {
68 m_className = "ComponentGrid";
69}
ComponentBase()
Constructor.
Definition: ComponentBase.cc:9
std::string m_className
Class name.

◆ ~ComponentGrid()

Garfield::ComponentGrid::~ComponentGrid ( )
inline

Destructor.

Definition at line 15 of file ComponentGrid.hh.

15{}

Member Function Documentation

◆ Clear()

void Garfield::ComponentGrid::Clear ( )
inlineoverridevirtual

Reset.

Reimplemented from Garfield::ComponentBase.

Definition at line 17 of file ComponentGrid.hh.

17{ Reset(); }

◆ DelayedWeightingField()

void Garfield::ComponentGrid::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 134 of file ComponentGrid.cc.

137 {
138
139 wx = wy = wz = 0.;
140 if (m_wdtimes.empty()) return;
141 // Assume no weighting field for times outside the range of available maps.
142 if (t < m_wdtimes.front() || t > m_wdtimes.back()) return;
143
144 const double xx = x - m_wField_xOffset;
145 const double yy = y - m_wField_yOffset;
146 const double zz = z - m_wField_zOffset;
147
148 const auto it1 = std::upper_bound(m_wdtimes.cbegin(), m_wdtimes.cend(), t);
149 const auto it0 = std::prev(it1);
150
151 const double dt = t - *it0;
152 double wp = 0.;
153 const unsigned int i0 = it0 - m_wdtimes.cbegin();
154 double wx0 = 0., wy0 = 0., wz0 = 0.;
155 bool active = true;
156 if (!GetField(xx, yy, zz, m_wdfields[i0], wx0, wy0, wz0, wp, active)) return;
157
158 if (dt < Small || it1 == m_wdtimes.cend()) {
159 wx = wx0;
160 wy = wy0;
161 wz = wz0;
162 return;
163 }
164 const unsigned int i1 = it1 - m_wdtimes.cbegin();
165 double wx1 = 0., wy1 = 0., wz1 = 0.;
166 if (!GetField(xx, yy, zz, m_wdfields[i1], wx1, wy1, wz1, wp, active)) return;
167
168 const double f1 = dt / (*it1 - *it0);
169 const double f0 = 1. - f1;
170 wx = f0 * wx0 + f1 * wx1;
171 wy = f0 * wy0 + f1 * wy1;
172 wz = f0 * wz0 + f1 * wz1;
173}

◆ ElectricField() [1/2]

void Garfield::ComponentGrid::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 71 of file ComponentGrid.cc.

74 {
75 m = nullptr;
76 status = 0;
77
78 // Make sure the field map has been loaded.
79 if (!m_ready) {
80 PrintNotReady(m_className + "::ElectricField");
81 status = -10;
82 return;
83 }
84
85 status = 0;
86 bool active = true;
87 if (!GetField(x, y, z, m_efields, ex, ey, ez, p, active)) {
88 status = -11;
89 return;
90 }
91 if (!active) {
92 status = -5;
93 return;
94 }
95 m = m_medium;
96 if (!m) status = -5;
97}
bool m_ready
Ready for use?

Referenced by ElectricField().

◆ ElectricField() [2/2]

void Garfield::ComponentGrid::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 99 of file ComponentGrid.cc.

101 {
102 double v = 0.;
103 ElectricField(x, y, z, ex, ey, ez, v, m, status);
104}
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).

◆ GetBoundingBox()

bool Garfield::ComponentGrid::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 1001 of file ComponentGrid.cc.

1002 {
1003 if (!m_ready) return false;
1004 if (m_periodic[0] || m_mirrorPeriodic[0]) {
1005 xmin = -INFINITY;
1006 xmax = +INFINITY;
1007 } else {
1008 xmin = m_xMin;
1009 xmax = m_xMax;
1010 }
1011
1012 if (m_periodic[1] || m_mirrorPeriodic[1]) {
1013 ymin = -INFINITY;
1014 ymax = +INFINITY;
1015 } else {
1016 ymin = m_yMin;
1017 ymax = m_yMax;
1018 }
1019
1020 if (m_periodic[2] || m_mirrorPeriodic[2]) {
1021 zmin = -INFINITY;
1022 zmax = +INFINITY;
1023 } else {
1024 zmin = m_zMin;
1025 zmax = m_zMax;
1026 }
1027 return true;
1028}
std::array< bool, 3 > m_periodic
Simple periodicity in x, y, z.
std::array< bool, 3 > m_mirrorPeriodic
Mirror periodicity in x, y, z.

◆ GetElectricField()

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

Return the field at a given node.

Definition at line 1164 of file ComponentGrid.cc.

1166 {
1167 v = ex = ey = ez = 0.;
1168 if (!m_ready) {
1169 if (!m_hasMesh) {
1170 std::cerr << m_className << "::GetElectricField: Mesh not set.\n";
1171 return false;
1172 }
1173 PrintNotReady(m_className + "::GetElectricField");
1174 return false;
1175 }
1176 if (i >= m_nX || j >= m_nY || k >= m_nZ) {
1177 std::cerr << m_className << "::GetElectricField: Index out of range.\n";
1178 return false;
1179 }
1180 const Node& node = m_efields[i][j][k];
1181 v = node.v;
1182 ex = node.fx;
1183 ey = node.fy;
1184 ez = node.fz;
1185 return true;
1186}

◆ GetElectricFieldRange()

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

Definition at line 1037 of file ComponentGrid.cc.

1039 {
1040 if (!m_ready) {
1041 PrintNotReady(m_className + "::GetElectricFieldRange");
1042 return false;
1043 }
1044
1045 exmin = exmax = m_efields[0][0][0].fx;
1046 eymin = eymax = m_efields[0][0][0].fy;
1047 ezmin = ezmax = m_efields[0][0][0].fz;
1048 for (unsigned int i = 0; i < m_nX; ++i) {
1049 for (unsigned int j = 0; j < m_nY; ++j) {
1050 for (unsigned int k = 0; k < m_nZ; ++k) {
1051 const Node& node = m_efields[i][j][k];
1052 if (node.fx < exmin) exmin = node.fx;
1053 if (node.fx > exmax) exmax = node.fx;
1054 if (node.fy < eymin) eymin = node.fy;
1055 if (node.fy > eymax) eymax = node.fy;
1056 if (node.fz < ezmin) ezmin = node.fz;
1057 if (node.fz > ezmax) ezmax = node.fz;
1058 }
1059 }
1060 }
1061 return true;
1062}

◆ GetMedium() [1/2]

Medium * Garfield::ComponentGrid::GetMedium ( ) const
inline

Get the medium.

Definition at line 126 of file ComponentGrid.hh.

126{ return m_medium; }

◆ GetMedium() [2/2]

Medium * Garfield::ComponentGrid::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 197 of file ComponentGrid.cc.

198 {
199 // Make sure the field map has been loaded.
200 if (!m_ready) {
201 PrintNotReady(m_className + "::GetMedium");
202 return nullptr;
203 }
204
205 if (!m_periodic[0] && !m_mirrorPeriodic[0] && (x < m_xMin || x > m_xMax)) {
206 return nullptr;
207 }
208 if (!m_periodic[1] && !m_mirrorPeriodic[1] && (y < m_yMin || x > m_yMax)) {
209 return nullptr;
210 }
211 if (!m_periodic[2] && !m_mirrorPeriodic[2] && (z < m_zMin || x > m_zMax)) {
212 return nullptr;
213 }
214 if (m_active.empty()) return m_medium;
215
216 bool mirrored = false;
217 const double xx =
218 Reduce(x, m_xMin, m_xMax, m_periodic[0], m_mirrorPeriodic[0], mirrored);
219 const double yy =
220 Reduce(y, m_yMin, m_yMax, m_periodic[1], m_mirrorPeriodic[1], mirrored);
221 const double zz =
222 Reduce(z, m_zMin, m_zMax, m_periodic[2], m_mirrorPeriodic[2], mirrored);
223 // Get the indices.
224 const double sx = (xx - m_xMin) / m_dx;
225 const double sy = (yy - m_yMin) / m_dy;
226 const double sz = (zz - m_zMin) / m_dz;
227 const unsigned int i0 = static_cast<unsigned int>(std::floor(sx));
228 const unsigned int j0 = static_cast<unsigned int>(std::floor(sy));
229 const unsigned int k0 = static_cast<unsigned int>(std::floor(sz));
230 const unsigned int i1 = std::min(i0 + 1, m_nX - 1);
231 const unsigned int j1 = std::min(j0 + 1, m_nY - 1);
232 const unsigned int k1 = std::min(k0 + 1, m_nZ - 1);
233 if (m_active[i0][j0][k0] && m_active[i0][j0][k1] &&
234 m_active[i0][j1][k0] && m_active[i0][j1][k1] &&
235 m_active[i1][j0][k0] && m_active[i1][j0][k1] &&
236 m_active[i1][j1][k0] && m_active[i1][j1][k1]) {
237 return m_medium;
238 }
239 return nullptr;
240}

◆ GetMesh()

bool Garfield::ComponentGrid::GetMesh ( unsigned int &  nx,
unsigned int &  ny,
unsigned int &  nz,
double &  xmin,
double &  xmax,
double &  ymin,
double &  ymax,
double &  zmin,
double &  zmax 
) const

Retrieve the parameters of the grid.

Definition at line 279 of file ComponentGrid.cc.

282 {
283
284 if (!m_hasMesh) return false;
285 nx = m_nX;
286 ny = m_nY;
287 nz = m_nZ;
288 xmin = m_xMin;
289 ymin = m_yMin;
290 zmin = m_zMin;
291 xmax = m_xMax;
292 ymax = m_yMax;
293 zmax = m_zMax;
294 return true;
295}

◆ GetVoltageRange()

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

Calculate the voltage range [V].

Implements Garfield::ComponentBase.

Definition at line 1030 of file ComponentGrid.cc.

1030 {
1031 if (!m_ready) return false;
1032 vmin = m_pMin;
1033 vmax = m_pMax;
1034 return true;
1035}

◆ LoadElectricField()

bool Garfield::ComponentGrid::LoadElectricField ( const std::string &  filename,
const std::string &  format,
const bool  withPotential,
const bool  withFlag,
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 grid point starting with

  • either two or three floating point numbers, specifying the coordinates (in cm) of the grid node or
  • two or three integers specifying the index of the node,

followed by

  • two or three floating point numbers for the electric field (in V/cm), and (depending on the value of withPotential and withFlag),
  • a floating point number specifying the potential (in V), and
  • an integer flag indicating whether the point is in an active region (1) or not (0).

Format types are:

  • "xy", "xyz": nodes are specified by their coordinates
  • "ij", "ijk": nodes are specified by their indices

Definition at line 297 of file ComponentGrid.cc.

301 {
302 m_ready = false;
303 m_hasPotential = m_hasEfield = false;
304 m_active.assign(m_nX, std::vector<std::vector<bool> >(m_nY, std::vector<bool>(m_nZ, true)));
305 // Read the file.
306 m_pMin = withP ? +1. : 0.;
307 m_pMax = withP ? -1. : 0.;
308 if (!LoadData(fname, fmt, withP, withFlag,
309 scaleX, scaleE, scaleP, m_efields)) {
310 return false;
311 }
312 m_hasEfield = true;
313 m_ready = true;
314 if (withP) m_hasPotential = true;
315 return true;
316}

◆ LoadMagneticField()

bool Garfield::ComponentGrid::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 355 of file ComponentGrid.cc.

358 {
359 m_hasBfield = false;
360 // Read the file.
361 if (!LoadData(fname, fmt, false, false, scaleX, scaleB, 1., m_bfields)) {
362 return false;
363 }
364 m_hasBfield = true;
365 return true;
366}

◆ LoadWeightingField() [1/2]

bool Garfield::ComponentGrid::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 318 of file ComponentGrid.cc.

323 {
324 m_hasWfield = false;
325 // Read the file.
326 if (!LoadData(fname, fmt, withP, false, scaleX, scaleE, scaleP, m_wfields)) {
327 return false;
328 }
329 m_hasWfield = true;
330 return true;
331}

◆ LoadWeightingField() [2/2]

bool Garfield::ComponentGrid::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 332 of file ComponentGrid.cc.

336 {
337
338 std::vector<std::vector<std::vector<Node> > > wfield;
339 // Read the file.
340 if (!LoadData(fname, fmt, withP, false, scaleX, scaleE, scaleP, wfield)) {
341 return false;
342 }
343 if (m_wdtimes.empty() || t > m_wdtimes.back()) {
344 m_wdtimes.push_back(t);
345 m_wdfields.push_back(std::move(wfield));
346 } else {
347 const auto it = std::upper_bound(m_wdtimes.cbegin(), m_wdtimes.cend(), t);
348 const auto n = std::distance(m_wdtimes.cbegin(), it);
349 m_wdtimes.insert(it, t);
350 m_wdfields.insert(m_wdfields.cbegin() + n, std::move(wfield));
351 }
352 return true;
353}

◆ MagneticField()

void Garfield::ComponentGrid::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 182 of file ComponentGrid.cc.

184 {
185 status = 0;
186 if (!m_hasBfield) {
187 return ComponentBase::MagneticField(x, y, z, bx, by, bz, status);
188 }
189
190 double p = 0.;
191 bool active = true;
192 if (!GetField(x, y, z, m_bfields, bx, by, bz, p, active)) {
193 status = -11;
194 }
195}
virtual void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status)

◆ SaveElectricField()

bool Garfield::ComponentGrid::SaveElectricField ( ComponentBase cmp,
const std::string &  filename,
const std::string &  format 
)

Export the electric field and potential of a component to a text file.

Parameters
cmpComponent object for which to export the field/potential
filenamename of the text file
format"xy", "xyz", "ij" or "ijk", see LoadElectricField

Definition at line 368 of file ComponentGrid.cc.

369 {
370
371 if (!cmp) {
372 std::cerr << m_className << "::SaveElectricField: Null pointer.\n";
373 return false;
374 }
375 if (!m_hasMesh) {
376 std::cerr << m_className << "::SaveElectricField: Mesh not set.\n";
377 return false;
378 }
379 const unsigned int fmt = GetFormat(format);
380 if (fmt == 0) {
381 std::cerr << m_className << "::SaveElectricField:\n"
382 << " Unknown format (" << format << ").\n";
383 return false;
384 }
385 std::ofstream outfile;
386 outfile.open(filename.c_str(), std::ios::out);
387 if (!outfile) {
388 std::cerr << m_className << "::SaveElectricField:\n"
389 << " Could not open file " << filename << ".\n";
390 return false;
391 }
392 std::cout << m_className << "::SaveElectricField:\n"
393 << " Exporting field/potential to " << filename << ".\n"
394 << " Be patient...\n";
395 PrintProgress(0.);
396 outfile << "# XMIN = " << m_xMin << ", XMAX = " << m_xMax << ", NX = "
397 << m_nX << "\n";
398 outfile << "# YMIN = " << m_yMin << ", YMAX = " << m_yMax << ", NY = "
399 << m_nY << "\n";
400 outfile << "# ZMIN = " << m_zMin << ", ZMAX = " << m_zMax << ", NZ = "
401 << m_nZ << "\n";
402
403 const unsigned int nValues = m_nX * m_nY * m_nZ;
404 const unsigned int nPrint = std::pow(10, static_cast<unsigned int>(
405 std::max(std::floor(std::log10(nValues)) - 1, 1.)));
406 unsigned int nLines = 0;
407 Medium* medium = nullptr;
408 int status = 0;
409 for (unsigned int i = 0; i < m_nX; ++i) {
410 const double x = m_xMin + i * m_dx;
411 for (unsigned int j = 0; j < m_nY; ++j) {
412 const double y = m_yMin + j * m_dy;
413 for (unsigned int k = 0; k < m_nZ; ++k) {
414 const double z = m_zMin + k * m_dz;
415 if (fmt == 1) {
416 outfile << x << " " << y << " ";
417 } else if (fmt == 2) {
418 outfile << x << " " << y << " " << z << " ";
419 } else if (fmt == 3) {
420 outfile << i << " " << j << " ";
421 } else if (fmt == 4) {
422 outfile << i << " " << j << " " << k << " ";
423 } else if (fmt == 5) {
424 outfile << y << " " << x << " " << z << " ";
425 }
426 double ex = 0., ey = 0., ez = 0., v = 0.;
427 cmp->ElectricField(x, y, z, ex, ey, ez, v, medium, status);
428 outfile << ex << " " << ey << " " << ez << " " << v << "\n";
429 ++nLines;
430 if (nLines % nPrint == 0) PrintProgress(double(nLines) / nValues);
431 }
432 }
433 }
434 outfile.close();
435 std::cout << std::endl << m_className << "::SaveElectricField: Done.\n";
436 return true;
437}

◆ SaveWeightingField()

bool Garfield::ComponentGrid::SaveWeightingField ( ComponentBase cmp,
const std::string &  id,
const std::string &  filename,
const std::string &  format 
)

Export the weighting field and potential of a component to a text file.

Parameters
cmpComponent object for which to export the field/potential
ididentifier of the weighting field
filenamename of the text file
format"xy", "xyz", "ij" or "ijk", see LoadElectricField

Definition at line 439 of file ComponentGrid.cc.

441 {
442
443 if (!cmp) {
444 std::cerr << m_className << "::SaveWeightingField: Null pointer.\n";
445 return false;
446 }
447 if (!m_hasMesh) {
448 std::cerr << m_className << "::SaveWeightingField: Mesh not set.\n";
449 return false;
450 }
451 const unsigned int fmt = GetFormat(format);
452 if (fmt == 0) {
453 std::cerr << m_className << "::SaveWeightingField:\n"
454 << " Unknown format (" << format << ").\n";
455 return false;
456 }
457 std::ofstream outfile;
458 outfile.open(filename.c_str(), std::ios::out);
459 if (!outfile) {
460 std::cerr << m_className << "::SaveWeightingField:\n"
461 << " Could not open file " << filename << ".\n";
462 return false;
463 }
464 std::cout << m_className << "::SaveWeightingField:\n"
465 << " Exporting field/potential to " << filename << ".\n"
466 << " Be patient...\n";
467 PrintProgress(0.);
468 outfile << "# XMIN = " << m_xMin << ", XMAX = " << m_xMax << ", NX = "
469 << m_nX << "\n";
470 outfile << "# YMIN = " << m_yMin << ", YMAX = " << m_yMax << ", NY = "
471 << m_nY << "\n";
472 outfile << "# ZMIN = " << m_zMin << ", ZMAX = " << m_zMax << ", NZ = "
473 << m_nZ << "\n";
474 const unsigned int nValues = m_nX * m_nY * m_nZ;
475 const unsigned int nPrint = std::pow(10, static_cast<unsigned int>(
476 std::max(std::floor(std::log10(nValues)) - 1, 1.)));
477 unsigned int nLines = 0;
478 for (unsigned int i = 0; i < m_nX; ++i) {
479 const double x = m_xMin + i * m_dx;
480 for (unsigned int j = 0; j < m_nY; ++j) {
481 const double y = m_yMin + j * m_dy;
482 for (unsigned int k = 0; k < m_nZ; ++k) {
483 const double z = m_zMin + k * m_dz;
484 if (fmt == 1) {
485 outfile << x << " " << y << " ";
486 } else if (fmt == 2) {
487 outfile << x << " " << y << " " << z << " ";
488 } else if (fmt == 3) {
489 outfile << i << " " << j << " ";
490 } else if (fmt == 4) {
491 outfile << i << " " << j << " " << k << " ";
492 } else if (fmt == 5) {
493 outfile << y << " " << x << " " << z << " ";
494 }
495 double wx = 0., wy = 0., wz = 0.;
496 cmp->WeightingField(x, y, z, wx, wy, wz, id);
497 const double v = cmp->WeightingPotential(x, y, z, id);
498 outfile << wx << " " << wy << " " << wz << " " << v << "\n";
499 ++nLines;
500 if (nLines % nPrint == 0) PrintProgress(double(nLines) / nValues);
501 }
502 }
503 }
504 outfile.close();
505 std::cout << std::endl << m_className << "::SaveWeightingField: Done.\n";
506 return true;
507}

◆ SetMedium()

void Garfield::ComponentGrid::SetMedium ( Medium m)

Set the medium.

Definition at line 1064 of file ComponentGrid.cc.

1064 {
1065 if (!m) {
1066 std::cerr << m_className << "::SetMedium: Null pointer.\n";
1067 }
1068 m_medium = m;
1069}

◆ SetMesh()

bool Garfield::ComponentGrid::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 nodes along $x, y, z$.
xmin,xmaxrange along $x$.
ymin,ymaxrange along $y$.
zmin,zmaxrange along $z$.

Definition at line 242 of file ComponentGrid.cc.

246 {
247 Reset();
248 if (nx == 0 || ny == 0 || nz == 0) {
249 std::cerr << m_className << "::SetMesh:\n"
250 << " Number of mesh elements must be positive.\n";
251 return false;
252 }
253 if (xmin >= xmax) {
254 std::cerr << m_className << "::SetMesh: Invalid x range.\n";
255 return false;
256 } else if (ymin >= ymax) {
257 std::cerr << m_className << "::SetMesh: Invalid y range.\n";
258 return false;
259 } else if (zmin >= zmax) {
260 std::cerr << m_className << "::SetMesh: Invalid z range.\n";
261 return false;
262 }
263 m_nX = nx;
264 m_nY = ny;
265 m_nZ = nz;
266 m_xMin = xmin;
267 m_yMin = ymin;
268 m_zMin = zmin;
269 m_xMax = xmax;
270 m_yMax = ymax;
271 m_zMax = zmax;
272 m_dx = m_nX > 1 ? (m_xMax - m_xMin) / (m_nX - 1) : (m_xMax - m_xMin);
273 m_dy = m_nY > 1 ? (m_yMax - m_yMin) / (m_nY - 1) : (m_yMax - m_yMin);
274 m_dz = m_nZ > 1 ? (m_zMax - m_zMin) / (m_nZ - 1) : (m_zMax - m_zMin);
275 m_hasMesh = true;
276 return true;
277}

◆ SetWeightingFieldOffset()

void Garfield::ComponentGrid::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 175 of file ComponentGrid.cc.

176 {
177 m_wField_xOffset = x;
178 m_wField_yOffset = y;
179 m_wField_zOffset = z;
180}

◆ WeightingField()

void Garfield::ComponentGrid::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 106 of file ComponentGrid.cc.

108 {
109
110 wx = wy = wz = 0.;
111 if (!m_hasWfield) return;
112 const double xx = x - m_wField_xOffset;
113 const double yy = y - m_wField_yOffset;
114 const double zz = z - m_wField_zOffset;
115 double wp = 0.;
116 bool active = true;
117 GetField(xx, yy, zz, m_wfields, wx, wy, wz, wp, active);
118}

◆ WeightingPotential()

double Garfield::ComponentGrid::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 120 of file ComponentGrid.cc.

122 {
123 if (!m_hasWfield) return 0.;
124 const double xx = x - m_wField_xOffset;
125 const double yy = y - m_wField_yOffset;
126 const double zz = z - m_wField_zOffset;
127 double wx = 0., wy = 0., wz = 0.;
128 double wp = 0.;
129 bool active = true;
130 if (!GetField(xx, yy, zz, m_wfields, wx, wy, wz, wp, active)) return 0.;
131 return wp;
132}

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