Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation 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 "ComponentBase.hh"
5
6namespace Garfield {
7
8/// Component for interpolating field maps on a regular mesh.
9
11 public:
12 /// Constructor
14 /// Destructor
16
17 void Clear() override { Reset(); }
18
19 void ElectricField(const double x, const double y, const double z, double& ex,
20 double& ey, double& ez, double& v, Medium*& m,
21 int& status) override;
22 void ElectricField(const double x, const double y, const double z, double& ex,
23 double& ey, double& ez, Medium*& m, int& status) override;
24
25 void WeightingField(const double x, const double y, const double z,
26 double& wx, double& wy, double& wz,
27 const std::string& label) override;
28 double WeightingPotential(const double x, const double y, const double z,
29 const std::string& label) override;
30 void DelayedWeightingField(const double x, const double y, const double z,
31 const double t, double& wx, double& wy, double& wz,
32 const std::string& label) override;
33
34 void MagneticField(const double x, const double y, const double z, double& bx,
35 double& by, double& bz, int& status) override;
36
37 Medium* GetMedium(const double x, const double y, const double z) override;
38
39 bool GetVoltageRange(double& vmin, double& vmax) override;
40 bool GetElectricFieldRange(double& exmin, double& exmax, double& eymin,
41 double& eymax, double& ezmin, double& ezmax);
42 bool GetBoundingBox(double& xmin, double& ymin, double& zmin, double& xmax,
43 double& ymax, double& zmax) override;
44
45 /** Define the grid.
46 * \param nx,ny,nz number of nodes along \f$x, y, z\f$.
47 * \param xmin,xmax range along \f$x\f$.
48 * \param ymin,ymax range along \f$y\f$.
49 * \param zmin,zmax range along \f$z\f$.
50 */
51 bool SetMesh(const unsigned int nx, const unsigned int ny,
52 const unsigned int nz, const double xmin, const double xmax,
53 const double ymin, const double ymax, const double zmin,
54 const double zmax);
55 /// Retrieve the parameters of the grid.
56 bool GetMesh(unsigned int& nx, unsigned int& ny, unsigned int& nz,
57 double& xmin, double& xmax, double& ymin, double& ymax,
58 double& zmin, double& zmax) const;
59 /** Import electric field and potential values from a file.
60 * The file is supposed to contain one line for each grid point starting with
61 * - either two or three floating point numbers,
62 * specifying the coordinates (in cm) of the grid node or
63 * - two or three integers specifying the index of the node,
64 *
65 * followed by
66 * - two or three floating point numbers for the electric field (in V/cm),
67 * and (depending on the value of withPotential and withFlag),
68 * - a floating point number specifying the potential (in V), and
69 * - an integer flag indicating whether the point is in an active region (1)
70 * or not (0).
71 *
72 * Format types are:
73 * - "xy", "xyz": nodes are specified by their coordinates
74 * - "ij", "ijk": nodes are specified by their indices
75 */
76 bool LoadElectricField(const std::string& filename, const std::string& format,
77 const bool withPotential, const bool withFlag,
78 const double scaleX = 1.,
79 const double scaleE = 1., const double scaleP = 1.);
80
81 /// Import (prompt) weighting field from file.
82 bool LoadWeightingField(const std::string& filename, const std::string& format,
83 const bool withPotential,
84 const double scaleX = 1., const double scaleE = 1.,
85 const double scaleP = 1.);
86 /// Import delayed weighting field from file.
87 bool LoadWeightingField(const std::string& filename, const std::string& format,
88 const double time, const bool withPotential,
89 const double scaleX = 1., const double scaleE = 1.,
90 const double scaleP = 1.);
91 /// Offset coordinates in the weighting field, such that the
92 /// same numerical weighting field map can be used for electrodes at
93 /// different positions.
94 void SetWeightingFieldOffset(const double x, const double y, const double z);
95
96
97 /// Import magnetic field values from a file.
98 bool LoadMagneticField(const std::string& filename, const std::string& format,
99 const double scaleX = 1., const double scaleB = 1.);
100
101 /** Export the electric field and potential of a component to a text file.
102 * \param cmp Component object for which to export the field/potential
103 * \param filename name of the text file
104 * \param format "xy", "xyz", "ij" or "ijk", see @ref LoadElectricField
105 */
106 bool SaveElectricField(ComponentBase* cmp, const std::string& filename,
107 const std::string& format);
108 /** Export the weighting field and potential of a component to a text file.
109 * \param cmp Component object for which to export the field/potential
110 * \param id identifier of the weighting field
111 * \param filename name of the text file
112 * \param format "xy", "xyz", "ij" or "ijk", see @ref LoadElectricField
113 */
114 bool SaveWeightingField(ComponentBase* cmp, const std::string& id,
115 const std::string& filename,
116 const std::string& format);
117
118 /// Return the field at a given node.
119 bool GetElectricField(const unsigned int i, const unsigned int j,
120 const unsigned int k, double& v, double& ex, double& ey,
121 double& ez) const;
122
123 /// Set the medium.
124 void SetMedium(Medium* m);
125 /// Get the medium.
126 Medium* GetMedium() const { return m_medium; }
127
128 private:
129 Medium* m_medium = nullptr;
130 struct Node {
131 double fx, fy, fz; //< Field
132 double v; //< Potential
133 };
134
135 /// Electric field values and potentials.
136 std::vector<std::vector<std::vector<Node> > > m_efields;
137 /// Magnetic field values.
138 std::vector<std::vector<std::vector<Node> > > m_bfields;
139 /// Prompt weighting field values and potentials.
140 std::vector<std::vector<std::vector<Node> > > m_wfields;
141 /// Delayed weighting field values and potentials.
142 std::vector<std::vector<std::vector<std::vector<Node> > > > m_wdfields;
143 std::vector<double> m_wdtimes;
144 /// Active medium flag.
145 std::vector<std::vector<std::vector<bool> > > m_active;
146
147 // Dimensions of the mesh
148 unsigned int m_nX = 0, m_nY = 0, m_nZ = 0;
149 double m_xMin = 0., m_yMin = 0., m_zMin = 0.;
150 double m_xMax = 0., m_yMax = 0., m_zMax = 0.;
151 double m_dx = 0., m_dy = 0., m_dz = 0.;
152
153 bool m_hasMesh = false;
154 bool m_hasPotential = false;
155 bool m_hasEfield = false;
156 bool m_hasBfield = false;
157 bool m_hasWfield = false;
158
159 // Offset for weighting field
160 double m_wField_xOffset = 0.;
161 double m_wField_yOffset = 0.;
162 double m_wField_zOffset = 0.;
163
164 // Voltage range
165 double m_pMin = 0., m_pMax = 0.;
166
167 /// Read/determine mesh parameters from file.
168 bool LoadMesh(const std::string& filename, std::string format,
169 const double scaleX);
170 /// Read data from file.
171 bool LoadData(const std::string& filename, std::string format,
172 const bool withPotential, const bool withFlag,
173 const double scaleX, const double scaleF, const double scaleP,
174 std::vector<std::vector<std::vector<Node> > >& field);
175
176 void Reset() override;
177 void UpdatePeriodicity() override;
178
179 /// Look up/interpolate the field at a given point.
180 bool GetField(const double x, const double y, const double z,
181 const std::vector<std::vector<std::vector<Node> > >& field,
182 double& fx, double& fy, double& fz, double& p, bool& active);
183 /// Reduce a coordinate to the basic cell (in case of periodicity).
184 double Reduce(const double xin, const double xmin, const double xmax,
185 const bool simplePeriodic, const bool mirrorPeriodic,
186 bool& isMirrored) const;
187 /// Set the dimensions of a table according to the mesh.
188 void Initialise(std::vector<std::vector<std::vector<Node> > >& fields);
189};
190}
191#endif
Abstract base class for components.
Component for interpolating field maps on a regular mesh.
~ComponentGrid()
Destructor.
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 SaveElectricField(ComponentBase *cmp, const std::string &filename, const std::string &format)
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.)
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 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.
double WeightingPotential(const double x, const double y, const double z, const std::string &label) override
bool GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
bool SaveWeightingField(ComponentBase *cmp, const std::string &id, const std::string &filename, const std::string &format)
void SetMedium(Medium *m)
Set the medium.
Medium * GetMedium() const
Get the medium.
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 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.
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 Clear() override
Reset.
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
void SetWeightingFieldOffset(const double x, const double y, const double z)
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
Abstract base class for media.
Definition: Medium.hh:13