Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ComponentNeBem3dMap.hh
Go to the documentation of this file.
1#ifndef G_COMPONENT_NEBEM3DMAP_H
2#define G_COMPONENT_NEBEM3DMAP_H
3
4#include "ComponentBase.hh"
5
6namespace Garfield {
7
8/// Component for interpolating field maps stored in a mesh generated by neBEM.
9
11 public:
12 /// Constructor
14 /// Destructor
16
17 void ElectricField(const double x, const double y, const double z, double& ex,
18 double& ey, double& ez, double& v, Medium*& m,
19 int& status) override;
20 void ElectricField(const double x, const double y, const double z, double& ex,
21 double& ey, double& ez, Medium*& m, int& status) override;
22
23 void WeightingField(const double x, const double y, const double z,
24 double& wx, double& wy, double& wz,
25 const std::string& label) override;
26 double WeightingPotential(const double x, const double y, const double z,
27 const std::string& label) override;
28
29 void MagneticField(const double x, const double y, const double z, double& bx,
30 double& by, double& bz, int& status) override;
31
32 /// Offset coordinates in the weighting field, such that the
33 /// same numerical weighting field map can be used for electrodes at
34 /// different positions.
35 void SetWeightingFieldOffset(const double x, const double y, const double z);
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 /// Map related information.
46 bool LoadMapInfo(const std::string& MapInfoFile, std::string& MapVersion,
47 int& OptMap, int& OptStaggerMap, unsigned int& NbOfXCells,
48 unsigned int& NbOfYCells, unsigned int& NbOfZCells,
49 double& Xmin, double& Xmax, double& Ymin, double& Ymax,
50 double& Zmin, double& Zmax, double& XStagger,
51 double& YStagger, double& ZStagger,
52 std::string& MapDataFile);
53 /** Define the grid.
54 * \param nx,ny,nz number of bins along x, y, z.
55 * \param xmin,xmax range along \f$x\f$.
56 * \param ymin,ymax range along \f$y\f$.
57 * \param zmin,zmax range along \f$z\f$.
58 */
59 void SetMesh(const unsigned int nx, const unsigned int ny,
60 const unsigned int nz, const double xmin, const double xmax,
61 const double ymin, const double ymax, const double zmin,
62 const double zmax);
63 /** Import electric field and potential values from a file.
64 * The file is supposed to contain one line for each mesh point starting with
65 * - either two or three floating point numbers,
66 * specifying the coordinates (in cm) of the element centre or
67 * - two or three integers specifying the index of the element in the mesh,
68 *
69 * followed by
70 * - two or three floating point numbers for the electric field (in V/cm),
71 * and (depending on the values of withPotential and withRegion),
72 * - a floating point number specifying the potential (in V), and
73 * - an integer specifying the "region" of the element.
74 *
75 * Format types are:
76 * - "xy", "xyz": elements are specified by the coordinates of their centres
77 * - "ij", "ijk": elements are specified by their indices
78 */
79 bool LoadElectricField(const std::string& filename, const std::string& format,
80 const bool withPotential, const bool withRegion,
81 const double scaleX = 1., const double scaleE = 1.,
82 const double scaleP = 1.);
83 /// Import magnetic field values from a file.
84 bool LoadMagneticField(const std::string& filename, const std::string& format,
85 const double scaleX = 1., const double scaleB = 1.);
86
87 /// Return the indices of the element at a given point.
88 bool GetElement(const double xi, const double yi, const double zi,
89 unsigned int& i, unsigned int& j, unsigned int& k,
90 bool& xMirrored, bool& yMirrored, bool& zMirrored) const;
91 /// Return the field for an element with given index.
92 bool GetElement(const unsigned int i, const unsigned int j,
93 const unsigned int k, double& v, double& ex, double& ey,
94 double& ez) const;
95
96 /// Set the medium in region i.
97 void SetMedium(const unsigned int i, Medium* m);
98 /// Get the medium in region i.
99 Medium* GetMedium(const unsigned int i) const;
100 /// Print all regions.
101 void PrintRegions() const;
102
103 private:
104 std::vector<Medium*> m_media;
105 struct Element {
106 double fx, fy, fz; //< Field
107 double v; //< Potential
108 };
109 /// Electric field values and potentials at each mesh element.
110 std::vector<std::vector<std::vector<Element> > > m_efields;
111 /// Magnetic field values at each mesh element.
112 std::vector<std::vector<std::vector<Element> > > m_bfields;
113 /// Region indices.
114 std::vector<std::vector<std::vector<int> > > m_regions;
115 // Dimensions of the mesh
116 unsigned int m_nX = 0, m_nY = 0, m_nZ = 0;
117 double m_xMin = 0., m_yMin = 0., m_zMin = 0.;
118 double m_xMax = 0., m_yMax = 0., m_zMax = 0.;
119
120 bool m_hasMesh = false;
121 bool m_hasPotential = false;
122 bool m_hasEfield = false;
123 bool m_hasBfield = false;
124
125 // Offset for weighting field
126 double m_wField_xOffset = 0.;
127 double m_wField_yOffset = 0.;
128 double m_wField_zOffset = 0.;
129
130 // Voltage range
131 double m_pMin = 0., m_pMax = 0.;
132
133 /// Read data from file.
134 bool LoadData(const std::string& filename, std::string format,
135 const bool withPotential, const bool withRegion,
136 const double scaleX, const double scaleF, const double scaleP,
137 const char field);
138
139 void Reset() override;
140 void UpdatePeriodicity() override;
141
142 /// Reduce a coordinate to the basic cell (in case of periodicity).
143 double Reduce(const double xin, const double xmin, const double xmax,
144 const bool simplePeriodic, const bool mirrorPeriodic,
145 bool& isMirrored) const;
146
147 /// Interpolate tri-linear
148 double TriLinInt(const double xd, const double yd, const double zd,
149 const double c000, const double c100, const double c010,
150 const double c001, const double c110, const double c101,
151 const double c011, const double c111);
152};
153}
154#endif
Abstract base class for components.
Component for interpolating field maps stored in a mesh generated by neBEM.
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.
void SetMedium(const unsigned int i, Medium *m)
Set the medium in region i.
void MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status) override
void PrintRegions() const
Print all regions.
bool LoadMapInfo(const std::string &MapInfoFile, std::string &MapVersion, int &OptMap, int &OptStaggerMap, unsigned int &NbOfXCells, unsigned int &NbOfYCells, unsigned int &NbOfZCells, double &Xmin, double &Xmax, double &Ymin, double &Ymax, double &Zmin, double &Zmax, double &XStagger, double &YStagger, double &ZStagger, std::string &MapDataFile)
Map related information.
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 GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the bounding box coordinates.
double WeightingPotential(const double x, const double y, const double z, const std::string &label) override
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
Medium * GetMedium(const double x, const double y, const double z) override
Get the medium at a given location (x, y, 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 GetElectricFieldRange(double &exmin, double &exmax, double &eymin, double &eymax, double &ezmin, double &ezmax)
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 GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
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)
void SetWeightingFieldOffset(const double x, const double y, const double z)
Abstract base class for media.
Definition: Medium.hh:13