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#include <cmath>
8
10
11namespace Garfield {
12
14
15class ComponentGrid : public Component {
16 public:
21
28 bool SetMesh(const unsigned int nx, const unsigned int ny,
29 const unsigned int nz, const double xmin, const double xmax,
30 const double ymin, const double ymax, const double zmin,
31 const double zmax);
33 bool GetMesh(unsigned int& nx, unsigned int& ny, unsigned int& nz,
34 double& xmin, double& xmax, double& ymin, double& ymax,
35 double& zmin, double& zmax) const;
40
62 bool LoadElectricField(const std::string& filename, const std::string& format,
63 const bool withPotential, const bool withFlag,
64 const double scaleX = 1., const double scaleE = 1.,
65 const double scaleP = 1.);
66
68 bool LoadWeightingField(const std::string& filename,
69 const std::string& format, const bool withPotential,
70 const double scaleX = 1., const double scaleE = 1.,
71 const double scaleP = 1.);
73 bool LoadWeightingField(const std::string& filename,
74 const std::string& format, const double time,
75 const bool withPotential, const double scaleX = 1.,
76 const double scaleE = 1., const double scaleP = 1.);
80 void SetWeightingFieldOffset(const double x, const double y, const double z);
81
83 bool LoadMagneticField(const std::string& filename, const std::string& format,
84 const double scaleX = 1., const double scaleB = 1.);
85
91 bool SaveElectricField(Component* cmp, const std::string& filename,
92 const std::string& fmt);
93
94 bool SaveElectricFieldROOT(Component* cmp, const std::string& filename,
95 const std::string& fmt);
96
101
108 bool SaveWeightingField(Component* cmp, const std::string& id,
109 const std::string& filename, const std::string& fmt);
110
112 bool GetElectricField(const unsigned int i, const unsigned int j,
113 const unsigned int k, double& v, double& ex, double& ey,
114 double& ez) const;
115
119 Medium* GetMedium() const { return m_medium; }
120
122 void Print();
123
130 bool LoadElectronAttachment(const std::string& fname, const std::string& fmt,
131 const unsigned int col, const double scaleX = 1.);
133 bool LoadHoleAttachment(const std::string& fname, const std::string& fmt,
134 const unsigned int col, const double scaleX = 1.);
135
142 bool LoadElectronVelocity(const std::string& fname, const std::string& fmt,
143 const double scaleX = 1.,
144 const double scaleV = 1.e-9);
146 bool LoadHoleVelocity(const std::string& fname, const std::string& fmt,
147 const double scaleX = 1., const double scaleV = 1.e-9);
148
149 void Clear() override { Reset(); }
150 void ElectricField(const double x, const double y, const double z, double& ex,
151 double& ey, double& ez, double& v, Medium*& m,
152 int& status) override;
153 void ElectricField(const double x, const double y, const double z, double& ex,
154 double& ey, double& ez, Medium*& m, int& status) override;
156 void WeightingField(const double x, const double y, const double z,
157 double& wx, double& wy, double& wz,
158 const std::string& label) override;
159 double WeightingPotential(const double x, const double y, const double z,
160 const std::string& label) override;
161 void DelayedWeightingField(const double x, const double y, const double z,
162 const double t, double& wx, double& wy, double& wz,
163 const std::string& label) override;
164 double DelayedWeightingPotential(const double x, const double y,
165 const double z, const double t,
166 const std::string& label) override;
167 void MagneticField(const double x, const double y, const double z, double& bx,
168 double& by, double& bz, int& status) override;
169
170 Medium* GetMedium(const double x, const double y, const double z) override;
171
172 bool GetVoltageRange(double& vmin, double& vmax) override;
173 bool GetElectricFieldRange(double& exmin, double& exmax, double& eymin,
174 double& eymax, double& ezmin, double& ezmax);
175 bool GetBoundingBox(double& xmin, double& ymin, double& zmin, double& xmax,
176 double& ymax, double& zmax) override;
177 bool GetElementaryCell(double& xmin, double& ymin, double& zmin, double& xmax,
178 double& ymax, double& zmax) override;
179
180 bool HasMagneticField() const override;
181
182 bool HasAttachmentMap() const override {
183 return !(m_eAttachment.empty() && m_hAttachment.empty());
184 }
185 bool ElectronAttachment(const double x, const double y, const double z,
186 double& att) override;
187 bool HoleAttachment(const double x, const double y, const double z,
188 double& att) override;
189 bool HasMobilityMap() const override {
190 return !(m_eMobility.empty() && m_hMobility.empty());
191 }
192 bool ElectronMobility(const double x, const double y, const double z,
193 double& mu) override;
194 bool HoleMobility(const double x, const double y, const double z,
195 double& mu) override;
196
197 bool HasVelocityMap() const override {
198 return !(m_eVelocity.empty() && m_hVelocity.empty());
199 }
200 bool ElectronVelocity(const double x, const double y, const double z,
201 double& vx, double& vy, double& vz) override;
202 bool HoleVelocity(const double x, const double y, const double z, double& vx,
203 double& vy, double& vz) override;
204 struct Node {
205 double fx, fy, fz;
206 double v;
207 };
208
209 void GetFieldOnGrid(std::vector<std::vector<
210 std::vector<ComponentGrid::Node> > >& efields){
211 efields = m_efields;
212 };
213
214 bool AddElectricField(ComponentGrid* cmp, const double scale = 1.,
215 const double xShift = 0.,
216 const double yShift = 0.,
217 const double zShift = 0.);
218
220 bool AddElectricField(Component* cmp, const double scale);
221
223 bool GetNodeIndex(double x, const double y, const double z, unsigned int& i, unsigned int& j, unsigned int& k);
224
225 private:
226 enum class Format { Unknown, XY, XZ, XYZ, IJ, IK, IJK, YXZ };
229
230 Medium* m_medium = nullptr;
231
233 std::vector<std::vector<std::vector<Node> > > m_efields;
235 std::vector<std::vector<std::vector<Node> > > m_bfields;
237 std::vector<std::vector<std::vector<Node> > > m_wfields;
239 std::vector<std::vector<std::vector<std::vector<Node> > > > m_wdfields;
241 std::vector<std::vector<std::vector<double> > > m_eAttachment;
242 std::vector<std::vector<std::vector<double> > > m_hAttachment;
244 std::vector<std::vector<std::vector<double> > > m_eMobility;
245 std::vector<std::vector<std::vector<double> > > m_hMobility;
247 std::vector<std::vector<std::vector<Node> > > m_eVelocity;
248 std::vector<std::vector<std::vector<Node> > > m_hVelocity;
250 std::vector<std::vector<std::vector<bool> > > m_active;
251
252 // Dimensions of the mesh
253 std::array<unsigned int, 3> m_nX = {{1, 1, 1}};
254 std::array<double, 3> m_xMin = {{0., 0., 0.}};
255 std::array<double, 3> m_xMax = {{0., 0., 0.}};
256 std::array<double, 3> m_sX = {{0., 0., 0.}};
257
258 bool m_hasMesh = false;
259 bool m_hasPotential = false;
260
261 // Offset for weighting field
262 std::array<double, 3> m_wFieldOffset = {{0., 0., 0.}};
263
264 // Voltage range
265 double m_pMin = 0., m_pMax = 0.;
266
268 bool LoadMesh(const std::string& filename, std::string format,
269 const double scaleX);
270
272 bool LoadData(const std::string& filename, std::string format,
273 const bool withPotential, const bool withFlag,
274 const double scaleX, const double scaleF, const double scaleP,
275 std::vector<std::vector<std::vector<Node> > >& field);
277 bool LoadData(const std::string& filename, std::string format,
278 const double scaleX,
279 std::vector<std::vector<std::vector<double> > >& tab,
280 const unsigned int col);
281
282 void Reset() override;
283 void UpdatePeriodicity() override;
284
286 bool GetField(const double x, const double y, const double z,
287 const std::vector<std::vector<std::vector<Node> > >& field,
288 double& fx, double& fy, double& fz, double& p, bool& active);
290 bool GetData(const double x, const double y, const double z,
291 const std::vector<std::vector<std::vector<double> > >& table,
292 double& value);
293
295 double Reduce(const double xin, const double xmin, const double xmax,
296 const bool simplePeriodic, const bool mirrorPeriodic,
297 bool& isMirrored) const;
299 void Initialise(std::vector<std::vector<std::vector<Node> > >& fields);
301 Format GetFormat(std::string fmt);
302};
303} // namespace Garfield
304#endif
bool ElectronVelocity(const double x, const double y, const double z, double &vx, double &vy, double &vz) override
Get the electron drift velocity.
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
Does the component have velocity maps?
void UpdatePeriodicity() override
Verify periodicities.
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.
bool SaveElectricField(Component *cmp)
Export the electric field and potential of a component.
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
Calculate the delayed weighting potential at a given point and time and for a given electrode.
bool HasMagneticField() const override
Does the component have a non-zero magnetic field?
bool GetElementaryCell(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the coordinates of the elementary cell.
void Initialise(std::vector< std::vector< std::vector< Node > > > &fields)
Set the dimensions of a table according to the mesh.
void GetFieldOnGrid(std::vector< std::vector< std::vector< ComponentGrid::Node > > > &efields)
Get field values on all nodes.
std::vector< std::vector< std::vector< Node > > > m_wfields
Prompt weighting field values and potentials.
bool AddElectricField(ComponentGrid *cmp, const double scale=1., const double xShift=0., const double yShift=0., const double zShift=0.)
Add the field values of cmp to current grid.
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
Get the bounding box coordinates.
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
Get the hole Mobility coefficient.
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
Reset the component.
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
Calculate the delayed weighting field at a given point and time and for a given electrode.
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
Does the component have maps of the low-field mobility?
Medium * GetMedium(const double x, const double y, const double z) override
Get the medium at a given location (x, y, z).
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
Calculate the drift field at given point.
double WeightingPotential(const double x, const double y, const double z, const std::string &label) override
Calculate the weighting potential at a given point.
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
Calculate the voltage range [V].
bool ElectronMobility(const double x, const double y, const double z, double &mu) override
std::vector< std::vector< std::vector< Node > > > m_hVelocity
bool SaveElectricFieldROOT(Component *cmp, const std::string &filename, const std::string &fmt)
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
Get the hole drift velocity.
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
Calculate the drift field [V/cm] and potential [V] at (x, y, z).
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.
void Clear() override
Reset.
bool AddElectricField(Component *cmp, const double scale)
Add the field values of cmp to current grid.
bool HoleAttachment(const double x, const double y, const double z, double &att) override
Get the hole attachment coefficient.
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
Calculate the magnetic field at a given point.
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
Get the electron attachment coefficient.
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
Does the component have maps of the attachment coefficient?
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
Calculate the weighting field at a given point and for a given electrode.
bool GetNodeIndex(double x, const double y, const double z, unsigned int &i, unsigned int &j, unsigned int &k)
Gives the closest node index (i, j, k) to coordinate (x, y, z).
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.
virtual void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status)=0
Calculate the drift field at given point.
Component()=delete
Default constructor.
Abstract base class for components.
Definition Medium.hh:17