1#ifndef G_COMPONENT_GRID_H
2#define G_COMPONENT_GRID_H
25 bool SetMesh(
const unsigned int nx,
const unsigned int ny,
26 const unsigned int nz,
const double xmin,
const double xmax,
27 const double ymin,
const double ymax,
const double zmin,
30 bool GetMesh(
unsigned int& nx,
unsigned int& ny,
unsigned int& nz,
31 double& xmin,
double& xmax,
double& ymin,
double& ymax,
32 double& zmin,
double& zmax)
const;
60 const bool withPotential,
const bool withFlag,
61 const double scaleX = 1.,
const double scaleE = 1.,
62 const double scaleP = 1.);
66 const std::string& format,
const bool withPotential,
67 const double scaleX = 1.,
const double scaleE = 1.,
68 const double scaleP = 1.);
71 const std::string& format,
const double time,
72 const bool withPotential,
const double scaleX = 1.,
73 const double scaleE = 1.,
const double scaleP = 1.);
81 const double scaleX = 1.,
const double scaleB = 1.);
89 const std::string& fmt);
97 const std::string& filename,
98 const std::string& fmt);
102 const unsigned int k,
double& v,
double& ex,
double& ey,
120 const std::string& fmt,
121 const unsigned int col,
122 const double scaleX = 1.);
125 const std::string& fmt,
126 const unsigned int col,
127 const double scaleX = 1.);
136 const std::string& fmt,
137 const double scaleX = 1.,
138 const double scaleV = 1.e-9);
141 const std::string& fmt,
142 const double scaleX = 1.,
143 const double scaleV = 1.e-9);
146 void ElectricField(
const double x,
const double y,
const double z,
double& ex,
147 double& ey,
double& ez,
double& v,
Medium*& m,
148 int& status)
override;
149 void ElectricField(
const double x,
const double y,
const double z,
double& ex,
150 double& ey,
double& ez,
Medium*& m,
int& status)
override;
152 void WeightingField(
const double x,
const double y,
const double z,
153 double& wx,
double& wy,
double& wz,
154 const std::string& label)
override;
156 const std::string& label)
override;
158 const double t,
double& wx,
double& wy,
double& wz,
159 const std::string& label)
override;
161 const double z,
const double t,
162 const std::string& label)
override;
163 void MagneticField(
const double x,
const double y,
const double z,
double& bx,
164 double& by,
double& bz,
int& status)
override;
166 Medium*
GetMedium(
const double x,
const double y,
const double z)
override;
170 double& eymax,
double& ezmin,
double& ezmax);
172 double& xmax,
double& ymax,
double& zmax)
override;
174 double& xmax,
double& ymax,
double& zmax)
override;
179 return !(m_eAttachment.empty() && m_hAttachment.empty());
182 double& att)
override;
183 bool HoleAttachment(
const double x,
const double y,
const double z,
184 double& att)
override;
187 return !(m_eVelocity.empty() && m_hVelocity.empty());
190 double& vx,
double& vy,
double& vz)
override;
191 bool HoleVelocity(
const double x,
const double y,
const double z,
192 double& vx,
double& vy,
double& vz)
override;
204 enum class Coordinates {
208 Coordinates m_coordinates = Coordinates::Cartesian;
210 Medium* m_medium =
nullptr;
217 std::vector<std::vector<std::vector<Node> > > m_efields;
219 std::vector<std::vector<std::vector<Node> > > m_bfields;
221 std::vector<std::vector<std::vector<Node> > > m_wfields;
223 std::vector<std::vector<std::vector<std::vector<Node> > > > m_wdfields;
224 std::vector<double> m_wdtimes;
226 std::vector<std::vector<std::vector<double> > > m_eAttachment;
227 std::vector<std::vector<std::vector<double> > > m_hAttachment;
229 std::vector<std::vector<std::vector<Node> > > m_eVelocity;
230 std::vector<std::vector<std::vector<Node> > > m_hVelocity;
232 std::vector<std::vector<std::vector<bool> > > m_active;
235 std::array<unsigned int, 3> m_nX = {{1, 1, 1}};
236 std::array<double, 3> m_xMin = {{0., 0., 0.}};
237 std::array<double, 3> m_xMax = {{0., 0., 0.}};
238 std::array<double, 3> m_sX = {{0., 0., 0.}};
240 bool m_hasMesh =
false;
241 bool m_hasPotential =
false;
244 std::array<double, 3> m_wFieldOffset = {{0., 0., 0.}};
247 double m_pMin = 0., m_pMax = 0.;
250 bool LoadMesh(
const std::string& filename, std::string format,
251 const double scaleX);
254 bool LoadData(
const std::string& filename, std::string format,
255 const bool withPotential,
const bool withFlag,
256 const double scaleX,
const double scaleF,
const double scaleP,
257 std::vector<std::vector<std::vector<Node> > >& field);
259 bool LoadData(
const std::string& filename, std::string format,
261 std::vector<std::vector<std::vector<double> > >& tab,
262 const unsigned int col);
264 void Reset()
override;
265 void UpdatePeriodicity()
override;
268 bool GetField(
const double x,
const double y,
const double z,
269 const std::vector<std::vector<std::vector<Node> > >& field,
270 double& fx,
double& fy,
double& fz,
double& p,
bool& active);
272 bool GetData(
const double x,
const double y,
const double z,
273 const std::vector<std::vector<std::vector<double> > >& table,
277 double Reduce(
const double xin,
const double xmin,
const double xmax,
278 const bool simplePeriodic,
const bool mirrorPeriodic,
279 bool& isMirrored)
const;
281 void Initialise(std::vector<std::vector<std::vector<Node> > >& fields);
283 Format GetFormat(std::string fmt);
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)
~ComponentGrid()
Destructor.
void SetCylindricalCoordinates()
Use cylindrical coordinates.
bool HasVelocityMap() const override
Does the component have velocity maps?
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)
double DelayedWeightingPotential(const double x, const double y, const double z, const double t, const std::string &label) override
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.
bool SaveElectricField(Component *cmp, const std::string &filename, const std::string &fmt)
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
void Print()
Print information about the mesh and the available data.
bool GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
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 HoleVelocity(const double x, const double y, const double z, double &vx, double &vy, double &vz) override
Get the hole drift velocity.
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).
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.
void Clear() override
Reset.
bool HoleAttachment(const double x, const double y, const double z, double &att) override
Get the hole attachment coefficient.
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
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)
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.
bool HasAttachmentMap() const override
Does the component have attachment maps?
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.)
bool SaveWeightingField(Component *cmp, const std::string &id, const std::string &filename, const std::string &fmt)
Abstract base class for components.
virtual void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status)=0
Component()=delete
Default constructor.
Abstract base class for media.