Garfield++ v2r0
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 "ComponentBase.hh"
5
6namespace Garfield {
7
8/// Component for interpolating field maps stored in a regular mesh.
9
11
12 public:
13 /// Constructor
15 /// Destructor
17
18 void ElectricField(const double x, const double y, const double z, double& ex,
19 double& ey, double& ez, double& v, Medium*& m,
20 int& status);
21 void ElectricField(const double x, const double y, const double z, double& ex,
22 double& ey, double& ez, Medium*& m, int& status);
23
24 void WeightingField(const double x, const double y, const double z,
25 double& wx, double& wy, double& wz,
26 const std::string& label);
27
28 void MagneticField(const double x, const double y, const double z,
29 double& bx, double& by, double& bz, int& status);
30
31 /// Offset coordinates in the weighting field, such that the
32 /// same numerical weighting field map can be used for electrodes at
33 /// different positions.
34 void SetWeightingFieldOffset(const double x, const double y, const double z);
35
36 Medium* GetMedium(const double x, const double y, const double z);
37
38 bool GetVoltageRange(double& vmin, double& vmax);
39 bool GetElectricFieldRange(double& exmin, double& exmax, double& eymin,
40 double& eymax, double& ezmin, double& ezmax);
41 bool GetBoundingBox(double& xmin, double& ymin, double& zmin, double& xmax,
42 double& ymax, double& zmax);
43
44 /** Define the grid.
45 * \param nx,ny,nz number of bins along x, y, z.
46 * \param xmin,xmax range along \f$x\f$.
47 * \param ymin,ymax range along \f$y\f$.
48 * \param zmin,zmax range along \f$z\f$.
49 */
50 void SetMesh(const unsigned int nx, const unsigned int ny,
51 const unsigned int nz, const double xmin, const double xmax,
52 const double ymin, const double ymax, const double zmin,
53 const double zmax);
54 /** Import electric field and potential values from a file.
55 * The file is supposed to contain one line for each mesh point starting with
56 * - either two or three floating point numbers,
57 * specifying the coordinates (in cm) of the element centre or
58 * - two or three integers specifying the index of the element in the mesh,
59 *
60 * followed by
61 * - two or three floating point numbers for the electric field (in V/cm),
62 * and (depending on the values of withPotential and withRegion),
63 * - a floating point number specifying the potential (in V), and
64 * - an integer specifying the "region" of the element.
65 *
66 * Format types are:
67 * - "xy", "xyz": elements are specified by the coordinates of their centres
68 * - "ij", "ijk": elements are specified by their indices
69 */
70 bool LoadElectricField(const std::string& filename, const std::string& format,
71 const bool withPotential, const bool withRegion,
72 const double scaleX = 1., const double scaleE = 1.,
73 const double scaleP = 1.);
74 /// Import magnetic field values from a file.
75 bool LoadMagneticField(const std::string& filename, const std::string& format,
76 const double scaleX = 1., const double scaleB = 1.);
77
78 /// Return the indices of the element at a given point.
79 bool GetElement(const double xi, const double yi, const double zi,
80 unsigned int& i, unsigned int& j, unsigned int& k,
81 bool& xMirrored, bool& yMirrored, bool& zMirrored) const;
82 /// Return the field for an element with given index.
83 bool GetElement(const unsigned int i, const unsigned int j,
84 const unsigned int k, double& v, double& ex, double& ey,
85 double& ez) const;
86
87 /// Set the medium in region i.
88 void SetMedium(const unsigned int i, Medium* m);
89 /// Get the medium in region i.
90 Medium* GetMedium(const unsigned int i) const;
91 /// Print all regions.
92 void PrintRegions() const;
93
94 private:
95 std::vector<Medium*> m_media;
96 struct Element {
97 double fx, fy, fz; //< Field
98 double v; //< Potential
99 };
100 /// Electric field values and potentials at each mesh element.
101 std::vector<std::vector<std::vector<Element> > > m_efields;
102 /// Magnetic field values at each mesh element.
103 std::vector<std::vector<std::vector<Element> > > m_bfields;
104 /// Region indices.
105 std::vector<std::vector<std::vector<int> > > m_regions;
106 // Dimensions of the mesh
107 unsigned int m_nX, m_nY, m_nZ;
108 double m_xMin, m_yMin, m_zMin;
109 double m_xMax, m_yMax, m_zMax;
110
111 bool m_hasMesh;
112 bool m_hasPotential;
113 bool m_hasEfield;
114 bool m_hasBfield;
115
116 // Offset for weighting field
117 double m_wField_xOffset;
118 double m_wField_yOffset;
119 double m_wField_zOffset;
120
121 // Voltage range
122 double m_pMin, m_pMax;
123
124 /// Read data from file.
125 bool LoadData(const std::string& filename, std::string format,
126 const bool withPotential, const bool withRegion,
127 const double scaleX, const double scaleF, const double scaleP,
128 const char field);
129 /// Reset the component.
130 void Reset();
131 /// Periodicities.
132 void UpdatePeriodicity();
133 /// Reduce a coordinate to the basic cell (in case of periodicity).
134 double Reduce(const double xin, const double xmin, const double xmax,
135 const bool simplePeriodic, const bool mirrorPeriodic,
136 bool& isMirrored) const;
137};
138}
139#endif
Abstract base class for components.
Component for interpolating field maps stored in a regular mesh.
ComponentVoxel()
Constructor.
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label)
void SetWeightingFieldOffset(const double x, const double y, const double z)
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
Get the bounding box coordinates.
void PrintRegions() const
Print all regions.
bool GetElectricFieldRange(double &exmin, double &exmax, double &eymin, double &eymax, double &ezmin, double &ezmax)
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)
Calculate the voltage range [V].
void SetMedium(const unsigned int i, Medium *m)
Set the medium in region i.
Medium * GetMedium(const double x, const double y, const double z)
Get the medium at a given location (x, y, z).
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, double &v, Medium *&m, int &status)
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 MagneticField(const double x, const double y, const double z, double &bx, double &by, double &bz, int &status)
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.
Abstract base class for media.
Definition: Medium.hh:11