Garfield++ 5.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ComponentVoxel.hh
Go to the documentation of this file.
1#ifndef G_COMPONENT_VOXEL_H
2#define G_COMPONENT_VOXEL_H
3
4#include "Component.hh"
5
6namespace Garfield {
7
8/// Component for interpolating field maps stored in a regular mesh.
9
10class ComponentVoxel : public Component {
11 public:
12 /// Constructor
14 /// Destructor
16
17 /// Interpolate between field values at the element centres.
18 void EnableInterpolation(const bool on = true) { m_interpolate = on; }
19
20 /** Define the grid.
21 * \param nx,ny,nz number of bins along x, y, z.
22 * \param xmin,xmax range along \f$x\f$.
23 * \param ymin,ymax range along \f$y\f$.
24 * \param zmin,zmax range along \f$z\f$.
25 */
26 void SetMesh(const unsigned int nx, const unsigned int ny,
27 const unsigned int nz, const double xmin, const double xmax,
28 const double ymin, const double ymax, const double zmin,
29 const double zmax);
30 /** Import electric field and potential values from a file.
31 * The file is supposed to contain one line for each mesh point starting with
32 * - either two or three floating point numbers,
33 * specifying the coordinates (in cm) of the element centre or
34 * - two or three integers specifying the index of the element in the mesh,
35 *
36 * followed by
37 * - two or three floating point numbers for the electric field (in V/cm),
38 * and (depending on the values of withPotential and withRegion),
39 * - a floating point number specifying the potential (in V), and
40 * - an integer specifying the "region" of the element.
41 *
42 * Format types are:
43 * - "xy", "xyz": elements are specified by the coordinates of their centres
44 * - "ij", "ijk": elements are specified by their indices
45 */
46 bool LoadElectricField(const std::string& filename, const std::string& format,
47 const bool withPotential, const bool withRegion,
48 const double scaleX = 1., const double scaleE = 1.,
49 const double scaleP = 1.);
50 /// Import (prompt) weighting field from file.
51 bool LoadWeightingField(const std::string& filename, const std::string& format,
52 const bool withPotential,
53 const double scaleX = 1., const double scaleE = 1.,
54 const double scaleP = 1.);
55 /// Offset coordinates in the weighting field, such that the
56 /// same numerical weighting field map can be used for electrodes at
57 /// different positions.
58 void SetWeightingFieldOffset(const double x, const double y, const double z);
59
60 /// Import delayed weighting field from file.
61 bool LoadWeightingField(const std::string& filename, const std::string& format,
62 const double time, const bool withPotential,
63 const double scaleX = 1., const double scaleE = 1.,
64 const double scaleP = 1.);
65 /// Import magnetic field values from a file.
66 bool LoadMagneticField(const std::string& filename, const std::string& format,
67 const double scaleX = 1., const double scaleB = 1.);
68
69 /// Set the medium in region i.
70 void SetMedium(const unsigned int i, Medium* m);
71 /// Get the medium in region i.
72 Medium* GetMedium(const unsigned int i) const;
73 /// Print all regions.
74 void PrintRegions() const;
75
76 /// Return the indices of the element at a given point.
77 bool GetElement(const double xi, const double yi, const double zi,
78 unsigned int& i, unsigned int& j, unsigned int& k,
79 bool& xMirrored, bool& yMirrored, bool& zMirrored) const;
80 /// Return the field for an element with given index.
81 bool GetElement(const unsigned int i, const unsigned int j,
82 const unsigned int k, double& v, double& ex, double& ey,
83 double& ez) const;
84
85 void Clear() override { Reset(); }
86 void ElectricField(const double x, const double y, const double z, double& ex,
87 double& ey, double& ez, double& v, Medium*& m,
88 int& status) override;
89 void ElectricField(const double x, const double y, const double z, double& ex,
90 double& ey, double& ez, Medium*& m, int& status) override;
92 void WeightingField(const double x, const double y, const double z,
93 double& wx, double& wy, double& wz,
94 const std::string& label) override;
95 double WeightingPotential(const double x, const double y, const double z,
96 const std::string& label) override;
97 void DelayedWeightingField(const double x, const double y, const double z,
98 const double t, double& wx, double& wy, double& wz,
99 const std::string& label) override;
100 double DelayedWeightingPotential(const double x, const double y,
101 const double z, const double t,
102 const std::string& label) override;
103 void MagneticField(const double x, const double y, const double z, double& bx,
104 double& by, double& bz, int& status) override;
105 bool HasMagneticField() const override;
106
107 Medium* GetMedium(const double x, const double y, const double z) override;
108
109 bool GetVoltageRange(double& vmin, double& vmax) override;
110 bool GetElectricFieldRange(double& exmin, double& exmax, double& eymin,
111 double& eymax, double& ezmin, double& ezmax);
112 bool GetBoundingBox(double& xmin, double& ymin, double& zmin,
113 double& xmax, double& ymax, double& zmax) override;
114 bool GetElementaryCell(double& xmin, double& ymin, double& zmin,
115 double& xmax, double& ymax, double& zmax) override;
116
117 private:
118 std::vector<Medium*> m_media;
119 struct Element {
120 double fx, fy, fz; ///< Field
121 double v; ///< Potential
122 };
123
124 /// Region indices.
125 std::vector<std::vector<std::vector<int> > > m_regions;
126 /// Electric field values and potentials at each mesh element.
127 std::vector<std::vector<std::vector<Element> > > m_efields;
128 /// Magnetic field values at each mesh element.
129 std::vector<std::vector<std::vector<Element> > > m_bfields;
130 /// Prompt weighting field values and potentials at each mesh element.
131 std::vector<std::vector<std::vector<Element> > > m_wfields;
132 /// Delayed weighting field values and potentials at each mesh element.
133 std::vector<std::vector<std::vector<std::vector<Element> > > > m_wdfields;
134 std::vector<double> m_wdtimes;
135
136 // Dimensions of the mesh
137 unsigned int m_nX = 0, m_nY = 0, m_nZ = 0;
138 double m_xMin = 0., m_yMin = 0., m_zMin = 0.;
139 double m_xMax = 0., m_yMax = 0., m_zMax = 0.;
140 double m_dx = 0., m_dy = 0., m_dz = 0.;
141
142 bool m_interpolate = false;
143
144 bool m_hasMesh = false;
145 bool m_hasPotential = false;
146 bool m_hasEfield = false;
147 bool m_hasBfield = false;
148 bool m_hasWfield = false;
149
150 // Offset for weighting field
151 double m_wField_xOffset = 0.;
152 double m_wField_yOffset = 0.;
153 double m_wField_zOffset = 0.;
154
155 // Voltage range
156 double m_pMin = 0., m_pMax = 0.;
157
158 /// Read data from file.
159 bool LoadData(const std::string& filename, std::string format,
160 const bool withPotential, const bool withRegion,
161 const double scaleX, const double scaleF, const double scaleP,
162 std::vector<std::vector<std::vector<Element> > >& field);
163
164 void Reset() override;
165 void UpdatePeriodicity() override;
166
167 /// Look up/interpolate the field at a given point.
168 bool GetField(const double x, const double y, const double z,
169 const std::vector<std::vector<std::vector<Element> > >& field,
170 double& fx, double& fy, double& fz, double& p, int& region);
171 /// Reduce a coordinate to the basic cell (in case of periodicity).
172 double Reduce(const double xin, const double xmin, const double xmax,
173 const bool simplePeriodic, const bool mirrorPeriodic,
174 bool& isMirrored) const;
175 /// Set the dimensions of a table according to the mesh.
176 void Initialise(std::vector<std::vector<std::vector<Element> > >& fields);
177 void InitialiseRegions();
178};
179}
180#endif
bool HasMagneticField() const override
Does the component have a non-zero magnetic field?
void EnableInterpolation(const bool on=true)
Interpolate between field values at the element centres.
void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status) override
void Clear() override
Reset.
void SetWeightingFieldOffset(const double x, const double y, const double z)
void PrintRegions() const
Print all regions.
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 GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the bounding box coordinates.
bool GetElectricFieldRange(double &exmin, double &exmax, double &eymin, double &eymax, double &ezmin, double &ezmax)
Medium * GetMedium(const unsigned int i) const
Get the medium in region i.
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
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 GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
bool GetElementaryCell(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the coordinates of the elementary cell.
void SetMedium(const unsigned int i, Medium *m)
Set the medium in region i.
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
double DelayedWeightingPotential(const double x, const double y, const double z, const double t, const std::string &label) override
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 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)
double WeightingPotential(const double x, const double y, const double z, const std::string &label) override
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 LoadMagneticField(const std::string &filename, const std::string &format, const double scaleX=1., const double scaleB=1.)
Import magnetic field values from a file.
virtual void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status)=0
Component()=delete
Default constructor.
Abstract base class for media.
Definition Medium.hh:16