Garfield 0.3
Toolkit for the detailed simulation of particle detectors based on ionization measurement in gases and semiconductors
Loading...
Searching...
No Matches
ComponentGrid.hh
Go to the documentation of this file.
1#ifndef G_COMPONENT_GRID_H
2#define G_COMPONENT_GRID_H
3
4#include <array>
5#include <string>
6#include <vector>
7
9
10namespace Garfield {
11
13
14class ComponentGrid : public Component {
15 public:
20
27 bool SetMesh(const unsigned int nx, const unsigned int ny,
28 const unsigned int nz, const double xmin, const double xmax,
29 const double ymin, const double ymax, const double zmin,
30 const double zmax);
32 bool GetMesh(unsigned int& nx, unsigned int& ny, unsigned int& nz,
33 double& xmin, double& xmax, double& ymin, double& ymax,
34 double& zmin, double& zmax) const;
39
61 bool LoadElectricField(const std::string& filename, const std::string& format,
62 const bool withPotential, const bool withFlag,
63 const double scaleX = 1., const double scaleE = 1.,
64 const double scaleP = 1.);
65
67 bool LoadWeightingField(const std::string& filename,
68 const std::string& format, const bool withPotential,
69 const double scaleX = 1., const double scaleE = 1.,
70 const double scaleP = 1.);
72 bool LoadWeightingField(const std::string& filename,
73 const std::string& format, const double time,
74 const bool withPotential, const double scaleX = 1.,
75 const double scaleE = 1., const double scaleP = 1.);
79 void SetWeightingFieldOffset(const double x, const double y, const double z);
80
82 bool LoadMagneticField(const std::string& filename, const std::string& format,
83 const double scaleX = 1., const double scaleB = 1.);
84
90 bool SaveElectricField(Component* cmp, const std::string& filename,
91 const std::string& fmt);
98 bool SaveWeightingField(Component* cmp, const std::string& id,
99 const std::string& filename, const std::string& fmt);
100
102 bool GetElectricField(const unsigned int i, const unsigned int j,
103 const unsigned int k, double& v, double& ex, double& ey,
104 double& ez) const;
105
107 void SetMedium(Medium* m);
109 Medium* GetMedium() const { return m_medium; }
110
112 void Print();
113
120 bool LoadElectronAttachment(const std::string& fname, const std::string& fmt,
121 const unsigned int col, const double scaleX = 1.);
123 bool LoadHoleAttachment(const std::string& fname, const std::string& fmt,
124 const unsigned int col, const double scaleX = 1.);
125
132 bool LoadElectronVelocity(const std::string& fname, const std::string& fmt,
133 const double scaleX = 1.,
134 const double scaleV = 1.e-9);
136 bool LoadHoleVelocity(const std::string& fname, const std::string& fmt,
137 const double scaleX = 1., const double scaleV = 1.e-9);
138
139 void Clear() override { Reset(); }
140 void ElectricField(const double x, const double y, const double z, double& ex,
141 double& ey, double& ez, double& v, Medium*& m,
142 int& status) override;
143 void ElectricField(const double x, const double y, const double z, double& ex,
144 double& ey, double& ez, Medium*& m, int& status) override;
145 using Component::ElectricField;
146 void WeightingField(const double x, const double y, const double z,
147 double& wx, double& wy, double& wz,
148 const std::string& label) override;
149 double WeightingPotential(const double x, const double y, const double z,
150 const std::string& label) override;
151 void DelayedWeightingField(const double x, const double y, const double z,
152 const double t, double& wx, double& wy, double& wz,
153 const std::string& label) override;
154 double DelayedWeightingPotential(const double x, const double y,
155 const double z, const double t,
156 const std::string& label) override;
157 void MagneticField(const double x, const double y, const double z, double& bx,
158 double& by, double& bz, int& status) override;
159
160 Medium* GetMedium(const double x, const double y, const double z) override;
161
162 bool GetVoltageRange(double& vmin, double& vmax) override;
163 bool GetElectricFieldRange(double& exmin, double& exmax, double& eymin,
164 double& eymax, double& ezmin, double& ezmax);
165 bool GetBoundingBox(double& xmin, double& ymin, double& zmin, double& xmax,
166 double& ymax, double& zmax) override;
167 bool GetElementaryCell(double& xmin, double& ymin, double& zmin, double& xmax,
168 double& ymax, double& zmax) override;
169
170 bool HasMagneticField() const override;
171
172 bool HasAttachmentMap() const override {
173 return !(m_eAttachment.empty() && m_hAttachment.empty());
174 }
175 bool ElectronAttachment(const double x, const double y, const double z,
176 double& att) override;
177 bool HoleAttachment(const double x, const double y, const double z,
178 double& att) override;
179 bool HasMobilityMap() const override {
180 return !(m_eMobility.empty() && m_hMobility.empty());
181 }
182 bool ElectronMobility(const double x, const double y, const double z,
183 double& mu) override;
184 bool HoleMobility(const double x, const double y, const double z,
185 double& mu) override;
186
187 bool HasVelocityMap() const override {
188 return !(m_eVelocity.empty() && m_hVelocity.empty());
189 }
190 bool ElectronVelocity(const double x, const double y, const double z,
191 double& vx, double& vy, double& vz) override;
192 bool HoleVelocity(const double x, const double y, const double z, double& vx,
193 double& vy, double& vz) override;
194
195 private:
196 enum class Format { Unknown, XY, XZ, XYZ, IJ, IK, IJK, YXZ };
199
200 Medium* m_medium = nullptr;
201 struct Node {
202 double fx, fy, fz;
203 double v;
204 };
205
207 std::vector<std::vector<std::vector<Node> > > m_efields;
209 std::vector<std::vector<std::vector<Node> > > m_bfields;
211 std::vector<std::vector<std::vector<Node> > > m_wfields;
213 std::vector<std::vector<std::vector<std::vector<Node> > > > m_wdfields;
215 std::vector<std::vector<std::vector<double> > > m_eAttachment;
216 std::vector<std::vector<std::vector<double> > > m_hAttachment;
218 std::vector<std::vector<std::vector<double> > > m_eMobility;
219 std::vector<std::vector<std::vector<double> > > m_hMobility;
221 std::vector<std::vector<std::vector<Node> > > m_eVelocity;
222 std::vector<std::vector<std::vector<Node> > > m_hVelocity;
224 std::vector<std::vector<std::vector<bool> > > m_active;
225
226 // Dimensions of the mesh
227 std::array<unsigned int, 3> m_nX = {{1, 1, 1}};
228 std::array<double, 3> m_xMin = {{0., 0., 0.}};
229 std::array<double, 3> m_xMax = {{0., 0., 0.}};
230 std::array<double, 3> m_sX = {{0., 0., 0.}};
231
232 bool m_hasMesh = false;
233 bool m_hasPotential = false;
234
235 // Offset for weighting field
236 std::array<double, 3> m_wFieldOffset = {{0., 0., 0.}};
237
238 // Voltage range
239 double m_pMin = 0., m_pMax = 0.;
240
242 bool LoadMesh(const std::string& filename, std::string format,
243 const double scaleX);
244
246 bool LoadData(const std::string& filename, std::string format,
247 const bool withPotential, const bool withFlag,
248 const double scaleX, const double scaleF, const double scaleP,
249 std::vector<std::vector<std::vector<Node> > >& field);
251 bool LoadData(const std::string& filename, std::string format,
252 const double scaleX,
253 std::vector<std::vector<std::vector<double> > >& tab,
254 const unsigned int col);
255
256 void Reset() override;
257 void UpdatePeriodicity() override;
258
260 bool GetField(const double x, const double y, const double z,
261 const std::vector<std::vector<std::vector<Node> > >& field,
262 double& fx, double& fy, double& fz, double& p, bool& active);
264 bool GetData(const double x, const double y, const double z,
265 const std::vector<std::vector<std::vector<double> > >& table,
266 double& value);
267
269 double Reduce(const double xin, const double xmin, const double xmax,
270 const bool simplePeriodic, const bool mirrorPeriodic,
271 bool& isMirrored) const;
273 void Initialise(std::vector<std::vector<std::vector<Node> > >& fields);
275 Format GetFormat(std::string fmt);
276};
277} // namespace Garfield
278#endif
bool ElectronVelocity(const double x, const double y, const double z, double &vx, double &vy, double &vz) override
bool LoadElectronVelocity(const std::string &fname, const std::string &fmt, const double scaleX=1., const double scaleV=1.e-9)
Import a map of electron drift velocities from a file.
void SetCylindricalCoordinates()
Use cylindrical coordinates.
bool HasVelocityMap() const override
void UpdatePeriodicity() override
std::vector< std::vector< std::vector< double > > > m_hMobility
bool GetField(const double x, const double y, const double z, const std::vector< std::vector< std::vector< Node > > > &field, double &fx, double &fy, double &fz, double &p, bool &active)
Interpolation of the field and potential at a given point.
std::vector< std::vector< std::vector< std::vector< Node > > > > m_wdfields
Delayed weighting field values and potentials.
std::vector< std::vector< std::vector< Node > > > m_eVelocity
Velocity maps for electrons and holes.
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)
Define the grid.
std::vector< std::vector< std::vector< bool > > > m_active
Active medium flag.
double DelayedWeightingPotential(const double x, const double y, const double z, const double t, const std::string &label) override
bool HasMagneticField() const override
bool GetElementaryCell(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
void Initialise(std::vector< std::vector< std::vector< Node > > > &fields)
Set the dimensions of a table according to the mesh.
std::vector< std::vector< std::vector< Node > > > m_wfields
Prompt weighting field values and potentials.
std::array< double, 3 > m_wFieldOffset
bool SaveElectricField(Component *cmp, const std::string &filename, const std::string &fmt)
Export the electric field and potential of a component to a text file.
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
ComponentGrid()
Constructor.
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.)
Import electric field and potential values from a file.
bool HoleMobility(const double x, const double y, const double z, double &mu) override
bool LoadData(const std::string &filename, std::string format, const double scaleX, std::vector< std::vector< std::vector< double > > > &tab, const unsigned int col)
Load scalar data (e. g. attachment coefficients) from file.
void Reset() 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
std::vector< std::vector< std::vector< Node > > > m_efields
Electric field values and potentials.
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.
std::array< double, 3 > m_xMax
bool HasMobilityMap() const override
Medium * GetMedium(const double x, const double y, const double z) override
double Reduce(const double xin, const double xmin, const double xmax, const bool simplePeriodic, const bool mirrorPeriodic, bool &isMirrored) const
Reduce a coordinate to the basic cell (in case of periodicity).
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.
std::vector< std::vector< std::vector< Node > > > m_bfields
Magnetic field values.
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status) override
double WeightingPotential(const double x, const double y, const double z, const std::string &label) override
bool LoadData(const std::string &filename, std::string format, const bool withPotential, const bool withFlag, const double scaleX, const double scaleF, const double scaleP, std::vector< std::vector< std::vector< Node > > > &field)
Read electric field and potential from file.
void Print()
Print information about the mesh and the available data.
bool GetVoltageRange(double &vmin, double &vmax) override
bool ElectronMobility(const double x, const double y, const double z, double &mu) override
std::vector< std::vector< std::vector< Node > > > m_hVelocity
void SetMedium(Medium *m)
Set the medium.
Medium * GetMedium() const
Get the medium.
std::vector< std::vector< std::vector< double > > > m_hAttachment
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 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.
bool HoleVelocity(const double x, const double y, const double z, double &vx, double &vy, double &vz) override
std::array< double, 3 > m_sX
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.
Format GetFormat(std::string fmt)
Decode a format string.
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, double &v, Medium *&m, int &status) override
bool LoadHoleVelocity(const std::string &fname, const std::string &fmt, const double scaleX=1., const double scaleV=1.e-9)
Import a map of hole drift velocities from a file.
bool GetData(const double x, const double y, const double z, const std::vector< std::vector< std::vector< double > > > &table, double &value)
Interpolation in a table of scalars.
bool HoleAttachment(const double x, const double y, const double z, double &att) override
bool LoadMesh(const std::string &filename, std::string format, const double scaleX)
Read/determine mesh parameters from file.
bool GetElectricFieldRange(double &exmin, double &exmax, double &eymin, double &eymax, double &ezmin, double &ezmax)
void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status) override
std::array< double, 3 > m_xMin
std::array< unsigned int, 3 > m_nX
bool ElectronAttachment(const double x, const double y, const double z, double &att) override
void SetCartesianCoordinates()
Use Cartesian coordinates (default).
void 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 us...
bool LoadHoleAttachment(const std::string &fname, const std::string &fmt, const unsigned int col, const double scaleX=1.)
Import hole attachment coefficients from a file.
std::vector< std::vector< std::vector< double > > > m_eMobility
Mobility maps for electrons and holes.
bool HasAttachmentMap() const override
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
bool LoadElectronAttachment(const std::string &fname, const std::string &fmt, const unsigned int col, const double scaleX=1.)
Import electron attachment coefficients from a file.
bool SaveWeightingField(Component *cmp, const std::string &id, const std::string &filename, const std::string &fmt)
Export the weighting field and potential of a component to a text file.
std::vector< std::vector< std::vector< double > > > m_eAttachment
Attachment maps for electrons and holes.