1#ifndef G_COMPONENT_FIELD_MAP_H
2#define G_COMPONENT_FIELD_MAP_H
58 bool GetElement(
const size_t i,
double& vol,
double& dmin,
61 virtual bool GetElement(
const size_t i,
size_t& mat,
bool& drift,
62 std::vector<size_t>& nodes)
const;
64 virtual bool GetNode(
const size_t i,
double& x,
double& y,
double& z)
const;
69 m_checkMultipleElement = on;
79 m_useTetrahedralTree = on;
88 Medium*
GetMedium(
const double x,
const double y,
const double z)
override;
89 void ElectricField(
const double x,
const double y,
const double z,
double& ex,
90 double& ey,
double& ez,
Medium*& m,
int& status)
override;
91 void ElectricField(
const double x,
const double y,
const double z,
double& ex,
92 double& ey,
double& ez,
double& v,
Medium*& m,
93 int& status)
override;
95 void WeightingField(
const double x,
const double y,
const double z,
96 double& wx,
double& wy,
double& wz,
97 const std::string& label)
override;
100 const std::string& label)
override;
103 const std::string& label)
override;
111 bool GetBoundingBox(
double& xmin,
double& ymin,
double& zmin,
double& xmax,
112 double& ymax,
double& zmax)
override;
114 double& ymax,
double& zmax)
override;
130 const std::string& labelSource,
const double x,
131 const double y,
const double z,
132 const double alpha,
const double beta,
162 std::vector<std::array<std::array<double, 3>, 4> >
m_w12;
174 std::map<std::string, std::vector<double> >
m_wpot;
176 std::map<std::string, std::vector<std::vector<double> > >
m_dwpot;
194 TMatrixD
rot = TMatrixD(3,3);
213 std::array<double, 3>
m_mapna = {{0., 0., 0.}};
214 std::array<double, 3>
m_cells = {{0., 0., 0.}};
236 void Reset()
override;
255 int Field(
const double x,
const double y,
const double z,
256 double& fx,
double& fy,
double& fz,
int& iel,
257 const std::vector<double>& potentials)
const;
259 double Potential(
const double x,
const double y,
const double z,
260 const std::vector<double>& potentials)
const;
262 static double Potential3(
const std::array<double, 6>& v,
263 const std::array<double, 3>& t);
265 static void Field3(
const std::array<double, 6>& v,
266 const std::array<double, 3>& t,
double jac[4][4],
267 const double det,
double& ex,
double& ey);
269 static double Potential5(
const std::array<double, 8>& v,
270 const std::array<double, 2>& t);
272 static void Field5(
const std::array<double, 8>& v,
273 const std::array<double, 2>& t,
double jac[4][4],
274 const double det,
double& ex,
double& ey);
276 static double Potential13(
const std::array<double, 10>& v,
277 const std::array<double, 4>& t);
279 static void Field13(
const std::array<double, 10>& v,
280 const std::array<double, 4>& t,
double jac[4][4],
281 const double det,
double& ex,
double& ey,
double& ez);
283 int FindElement5(
const double x,
const double y,
double& t1,
284 double& t2,
double& t3,
double& t4,
double jac[4][4],
287 int FindElement13(
const double x,
const double y,
const double z,
double& t1,
288 double& t2,
double& t3,
double& t4,
double jac[4][4],
292 double& t1,
double& t2,
double& t3, TMatrixD*& jac,
293 std::vector<TMatrixD*>& dN)
const;
296 void MapCoordinates(
double& xpos,
double& ypos,
double& zpos,
bool& xmirrored,
297 bool& ymirrored,
bool& zmirrored,
double& rcoordinate,
298 double& rotation)
const;
300 void UnmapFields(
double& ex,
double& ey,
double& ez,
301 const double xpos,
const double ypos,
const double zpos,
302 const bool xmirrored,
const bool ymirrored,
303 const bool zmirrored,
const double rcoordinate,
304 const double rotation)
const;
306 static int ReadInteger(
char* token,
int def,
bool& error);
307 static double ReadDouble(
char* token,
double def,
bool& error);
310 virtual void GetAspectRatio(
const size_t i,
double& dmin,
double& dmax)
const;
315 const std::string& filename)
const;
316 void PrintElement(
const std::string& header,
const double x,
const double y,
317 const double z,
const double t1,
const double t2,
318 const double t3,
const double t4,
const size_t i,
319 const std::vector<double>& potential)
const;
326 bool m_checkMultipleElement =
false;
329 bool m_useTetrahedralTree =
true;
330 std::unique_ptr<TetrahedralTree> m_octree;
333 bool m_cacheElemBoundingBoxes =
false;
336 int Coordinates3(
const double x,
const double y,
337 double& t1,
double& t2,
double& t3,
double& t4,
338 double jac[4][4],
double& det,
339 const std::array<double, 8>& xn,
340 const std::array<double, 8>& yn)
const;
342 int Coordinates4(
const double x,
const double y,
343 double& t1,
double& t2,
double& t3,
double& t4,
345 const std::array<double, 8>& xn,
346 const std::array<double, 8>& yn)
const;
348 int Coordinates5(
const double x,
const double y,
349 double& t1,
double& t2,
double& t3,
double& t4,
350 double jac[4][4],
double& det,
351 const std::array<double, 8>& xn,
352 const std::array<double, 8>& yn)
const;
354 void Coordinates12(
const double x,
const double y,
const double z,
355 double& t1,
double& t2,
double& t3,
double& t4,
356 const std::array<double, 10>& xn,
357 const std::array<double, 10>& yn,
358 const std::array<double, 10>& zn,
359 const std::array<std::array<double, 3>, 4>& w)
const;
362 int Coordinates13(
const double x,
const double y,
const double z,
363 double& t1,
double& t2,
double& t3,
double& t4,
364 double jac[4][4],
double& det,
365 const std::array<double, 10>& xn,
366 const std::array<double, 10>& yn,
367 const std::array<double, 10>& zn,
368 const std::array<std::array<double, 3>, 4>& w)
const;
370 int CoordinatesCube(
const double x,
const double y,
const double z,
371 double& t1,
double& t2,
double& t3, TMatrixD*& jac,
372 std::vector<TMatrixD*>& dN,
const Element& element)
const;
375 static void Jacobian3(
const std::array<double, 8>& xn,
376 const std::array<double, 8>& yn,
377 const double u,
const double v,
const double w,
378 double& det,
double jac[4][4]);
380 static void Jacobian5(
const std::array<double, 8>& xn,
381 const std::array<double, 8>& yn,
382 const double u,
const double v,
383 double& det,
double jac[4][4]);
385 static void Jacobian13(
const std::array<double, 10>& xn,
386 const std::array<double, 10>& yn,
387 const std::array<double, 10>& zn,
388 const double fourt0,
const double fourt1,
389 const double fourt2,
const double fourt3,
390 double& det,
double jac[4][4]);
392 void JacobianCube(
const Element& element,
const double t1,
const double t2,
393 const double t3, TMatrixD*& jac,
394 std::vector<TMatrixD*>& dN)
const;
396 static std::array<std::array<double, 3>, 4> Weights12(
397 const std::array<double, 10>& xn,
const std::array<double, 10>& yn,
398 const std::array<double, 10>& zn);
401 void CalculateElementBoundingBoxes();
404 bool InitializeTetrahedralTree();
virtual void GetAspectRatio(const size_t i, double &dmin, double &dmax) const
static double Potential3(const std::array< double, 6 > &v, const std::array< double, 3 > &t)
Interpolate the potential in a triangle.
int FindElement5(const double x, const double y, double &t1, double &t2, double &t3, double &t4, double jac[4][4], double &det) const
Find the element for a point in curved quadratic quadrilaterals.
double GetConductivity(const size_t imat) const
Return the conductivity of a field map material.
virtual bool GetNode(const size_t i, double &x, double &y, double &z) const
double DelayedWeightingPotential(double x, double y, double z, const double t, const std::string &label) override
double WeightingPotential(const double x, const double y, const double z, const std::string &label) override
void PrintRange()
Show x, y, z, V and angular ranges.
void PrintMaterials()
List all currently defined materials.
bool GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
bool SetDefaultDriftMedium()
Find lowest epsilon, check for eps = 0, set default drift media flags.
std::map< std::string, WeightingFieldCopy > m_wfieldCopies
static void Field5(const std::array< double, 8 > &v, const std::array< double, 2 > &t, double jac[4][4], const double det, double &ex, double &ey)
Interpolate the field in a curved quadrilateral.
void TimeInterpolation(const double t, double &f0, double &f1, int &i0, int &i1)
Interpolation of potential between two time slices.
void NotDriftMedium(const size_t imat)
Flag a field map materials as a non-drift medium.
std::array< double, 3 > m_mapamin
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status) override
static double ReadDouble(char *token, double def, bool &error)
void EnableDeleteBackgroundElements(const bool on=true)
Option to eliminate mesh elements in conductors (default: on).
double GetPotential(const size_t i) const
virtual double GetElementVolume(const size_t i) const
int FindElement13(const double x, const double y, const double z, double &t1, double &t2, double &t3, double &t4, double jac[4][4], double &det) const
Find the element for a point in curved quadratic tetrahedra.
void DriftMedium(const size_t imat)
Flag a field map material as a drift medium.
void MapCoordinates(double &xpos, double &ypos, double &zpos, bool &xmirrored, bool &ymirrored, bool &zmirrored, double &rcoordinate, double &rotation) const
Move (xpos, ypos, zpos) to field map coordinates.
std::vector< std::array< double, 3 > > m_bbMax
void PrintWarning(const std::string &header)
std::array< double, 3 > m_maxBoundingBox
std::array< double, 3 > m_mapmin
std::vector< double > m_pot
void SetMedium(const size_t imat, Medium *medium)
Associate a field map material with a Medium object.
size_t GetNumberOfMaterials() const
Return the number of materials in the field map.
std::array< double, 3 > m_minBoundingBox
static double ScalingFactor(std::string unit)
double Potential(const double x, const double y, const double z, const std::vector< double > &potentials) const
Compute the electrostatic/weighting potential.
void UpdatePeriodicity() override
Verify periodicities.
double GetPermittivity(const size_t imat) const
Return the relative permittivity of a field map material.
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the bounding box coordinates.
void UpdatePeriodicityCommon()
static int ReadInteger(char *token, int def, bool &error)
std::vector< Material > m_materials
virtual size_t GetNumberOfElements() const
Return the number of mesh elements.
static void Field3(const std::array< double, 6 > &v, const std::array< double, 3 > &t, double jac[4][4], const double det, double &ex, double &ey)
Interpolate the field in a triangle.
virtual size_t GetNumberOfNodes() const
void UnmapFields(double &ex, double &ey, double &ez, const double xpos, const double ypos, const double zpos, const bool xmirrored, const bool ymirrored, const bool zmirrored, const double rcoordinate, const double rotation) const
Move (ex, ey, ez) to global coordinates.
static void Field13(const std::array< double, 10 > &v, const std::array< double, 4 > &t, double jac[4][4], const double det, double &ex, double &ey, double &ez)
Interpolate the field in a curved quadratic tetrahedron.
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
static double Potential5(const std::array< double, 8 > &v, const std::array< double, 2 > &t)
Interpolate the potential in a curved quadrilateral.
void CopyWeightingPotential(const std::string &label, const std::string &labelSource, const double x, const double y, const double z, const double alpha, const double beta, const double gamma)
virtual ~ComponentFieldMap()
Destructor.
static double Potential13(const std::array< double, 10 > &v, const std::array< double, 4 > &t)
Interpolate the potential in a curved quadratic tetrahedron.
int Field(const double x, const double y, const double z, double &fx, double &fy, double &fz, int &iel, const std::vector< double > &potentials) const
Compute the electric/weighting field.
bool m_printConvergenceWarnings
std::array< double, 3 > m_mapna
std::vector< std::array< std::array< double, 3 >, 4 > > m_w12
ComponentFieldMap()=delete
Default constructor.
void EnableTetrahedralTreeForElementSearch(const bool on=true)
std::vector< Node > m_nodes
bool GetElement(const size_t i, double &vol, double &dmin, double &dmax) const
Return the volume and aspect ratio of a mesh element.
void PrintCouldNotOpen(const std::string &header, const std::string &filename) const
std::map< std::string, std::vector< double > > m_wpot
bool Check()
Check element aspect ratio.
int FindElementCube(const double x, const double y, const double z, double &t1, double &t2, double &t3, TMatrixD *&jac, std::vector< TMatrixD * > &dN) const
Find the element for a point in a cube.
std::vector< double > m_wdtimes
void UpdatePeriodicity2d()
std::vector< int > m_elementIndices
void SetGas(Medium *medium)
bool GetElementaryCell(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the coordinates of the elementary cell.
std::vector< Element > m_elements
std::array< double, 3 > m_mapamax
std::array< double, 3 > m_cells
void EnableConvergenceWarnings(const bool on=true)
std::array< bool, 3 > m_setang
std::vector< bool > m_degenerate
Medium * GetMedium(const size_t imat) const
Return the Medium associated to a field map material.
ElementType m_elementType
bool IsInBoundingBox(const double x, const double y, const double z) const
void PrintElement(const std::string &header, const double x, const double y, const double z, const double t1, const double t2, const double t3, const double t4, const size_t i, const std::vector< double > &potential) const
void EnableCheckMapIndices(const bool on=true)
std::array< double, 3 > m_mapmax
std::map< std::string, std::vector< std::vector< double > > > m_dwpot
void Reset() override
Reset the component.
std::vector< std::array< double, 3 > > m_bbMin
void PrintNotReady(const std::string &header) const
virtual void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status)=0
virtual Medium * GetMedium(const double x, const double y, const double z)
Get the medium at a given location (x, y, z).
Component()=delete
Default constructor.
Abstract base class for media.