1#if defined(__GPUCOMPILE__) || !defined(G_COMPONENT_FIELD_MAP_H)
3#if !defined(__GPUCOMPILE__) && !defined(G_COMPONENT_FIELD_MAP_H)
4#define G_COMPONENT_FIELD_MAP_H
60 using Component::GetMedium;
67 std::vector<size_t>& nodes)
const override;
69 bool& drift)
const override;
71 bool GetElement(
const size_t i,
double& vol,
double& dmin,
74 bool GetNode(
const size_t i,
double& x,
double& y,
double& z)
const override;
99 Medium*
GetMedium(
const double x,
const double y,
const double z)
override;
100 void ElectricField(
const double x,
const double y,
const double z,
double& ex,
101 double& ey,
double& ez, Medium*& m,
int& status)
override;
102 void ElectricField(
const double x,
const double y,
const double z,
double& ex,
103 double& ey,
double& ez,
double& v, Medium*& m,
104 int& status)
override;
105 using Component::ElectricField;
109 double& wx,
double& wy,
double& wz,
113 const std::string& label)
override;
115 const std::string& label)
override;
118 const std::string& label)
override;
120 const std::string& label,
121 std::vector<double>& dwp)
override;
131 double& ymax,
double& zmax)
override;
133 double& ymax,
double& zmax)
override;
153 const std::string& labelSource,
const double x,
154 const double y,
const double z,
const double alpha,
155 const double beta,
const double gamma);
203 cuda_t***
m_w12 =
nullptr;
205std::vector<std::array<std::array<double, 3>, 4> >
m_w12;
221#ifndef __GPUCOMPILE__
225 std::map<std::string, std::vector<double> >
m_wpot;
227 std::map<std::string, std::vector<std::vector<double> > >
m_dwpot;
229double*
m_pot =
nullptr;
235int* m_num_entries_wpot =
nullptr;
261#ifndef __GPUCOMPILE__
266 TMatrixD
rot = TMatrixD(3, 3);
295#ifndef __GPUCOMPILE__
296 std::array<double, 3>
m_mapna = {{0., 0., 0.}};
297 std::array<double, 3>
m_cells = {{0., 0., 0.}};
340 int Field(
const double x,
const double y,
const double z,
double& fx,
341 double& fy,
double& fz,
int& iel,
343 const double* potentials,
const int numPotentials
345 const std::vector<double>& potentials
348#ifndef __GPUCOMPILE__
350 double Potential(
const double x,
const double y,
const double z,
351 const std::vector<double>& potentials)
const;
354 const std::array<double, 3>& t);
356 static void Field3(
const std::array<double, 6>& v,
357 const std::array<double, 3>& t,
double jac[4][4],
358 const double det,
double& ex,
double& ey);
361 const std::array<double, 2>& t);
363 static void Field5(
const std::array<double, 8>& v,
364 const std::array<double, 2>& t,
double jac[4][4],
365 const double det,
double& ex,
double& ey);
368 const std::array<double, 4>& t);
372#ifndef __GPUCOMPILE__
373 const std::array<double, 10>& v,
const std::array<double, 4>& t,
375 const double v[10],
const double t[4],
377 double jac[4][4],
const double det,
double& ex,
double& ey,
double& ez);
378#ifndef __GPUCOMPILE__
380 int FindElement5(
const double x,
const double y,
double& t1,
double& t2,
381 double& t3,
double& t4,
double jac[4][4],
double& det)
const;
385 int FindElement13(
const double x,
const double y,
const double z,
double& t1,
386 double& t2,
double& t3,
double& t4,
double jac[4][4],
388#ifndef __GPUCOMPILE__
391 double& t1,
double& t2,
double& t3, TMatrixD*& jac,
392 std::vector<TMatrixD*>& dN)
const;
398 bool& ymirrored,
bool& zmirrored,
double& rcoordinate,
399 double& rotation)
const;
402 void UnmapFields(
double& ex,
double& ey,
double& ez,
const double xpos,
403 const double ypos,
const double zpos,
const bool xmirrored,
404 const bool ymirrored,
const bool zmirrored,
405 const double rcoordinate,
const double rotation)
const;
407#ifndef __GPUCOMPILE__
409 static double ReadDouble(
char* token,
double def,
bool& error);
417 const std::string& filename)
const;
418 void PrintElement(
const std::string& header,
const double x,
const double y,
419 const double z,
const double t1,
const double t2,
420 const double t3,
const double t4,
const size_t i,
421 const std::vector<double>& potential)
const;
440#ifndef __GPUCOMPILE__
442 int Coordinates3(
const double x,
const double y,
double& t1,
double& t2,
443 double& t3,
double& t4,
double jac[4][4],
double& det,
444 const std::array<double, 8>& xn,
445 const std::array<double, 8>& yn)
const;
447 int Coordinates4(
const double x,
const double y,
double& t1,
double& t2,
448 double& t3,
double& t4,
double& det,
449 const std::array<double, 8>& xn,
450 const std::array<double, 8>& yn)
const;
452 int Coordinates5(
const double x,
const double y,
double& t1,
double& t2,
453 double& t3,
double& t4,
double jac[4][4],
double& det,
454 const std::array<double, 8>& xn,
455 const std::array<double, 8>& yn)
const;
460 void Coordinates12(
const double x,
const double y,
const double z,
double& t1,
461 double& t2,
double& t3,
double& t4,
463 const double xn[10],
const double yn[10],
464 const double zn[10],
const double w[4][3]
466 const std::array<double, 10>& xn,
467 const std::array<double, 10>& yn,
468 const std::array<double, 10>& zn,
469 const std::array<std::array<double, 3>, 4>& w
475 int Coordinates13(
const double x,
const double y,
const double z,
double& t1,
476 double& t2,
double& t3,
double& t4,
double jac[4][4],
479 const double xn[10],
const double yn[10],
480 const double zn[10], cuda_t** w
482 const std::array<double, 10>& xn,
483 const std::array<double, 10>& yn,
484 const std::array<double, 10>& zn,
485 const std::array<std::array<double, 3>, 4>& w
489#ifndef __GPUCOMPILE__
492 double& t1,
double& t2,
double& t3, TMatrixD*& jac,
493 std::vector<TMatrixD*>& dN,
const Element& element)
const;
497 const std::array<double, 8>& yn,
const double u,
498 const double v,
const double w,
double& det,
502 const std::array<double, 8>& yn,
const double u,
503 const double v,
double& det,
double jac[4][4]);
510 const double xn[10],
const double yn[10],
const double zn[10],
512 const std::array<double, 10>& xn,
const std::array<double, 10>& yn,
513 const std::array<double, 10>& zn,
515 const double fourt0,
const double fourt1,
const double fourt2,
516 const double fourt3,
double& det,
double jac[4][4]);
518#ifndef __GPUCOMPILE__
521 const double t3, TMatrixD*& jac,
522 std::vector<TMatrixD*>& dN)
const;
525 const std::array<double, 10>& xn,
const std::array<double, 10>& yn,
526 const std::array<double, 10>& zn);
#define GARFIELD_CLASS_NAME(name)
static double Potential3(const std::array< double, 6 > &v, const std::array< double, 3 > &t)
Interpolate the potential in a triangle.
std::map< std::string, std::vector< double > > GetWeightingPotentials()
bool m_checkMultipleElement
Scan for multiple elements that contain a point.
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.
std::unique_ptr< GARFIELD_CLASS_NAME(TetrahedralTree)> m_octree
double GetConductivity(const size_t imat) const
Return the conductivity of a field map material.
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 ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, double &v, Medium *&m, int &status) override
void PrintMaterials()
List all currently defined materials.
bool GetVoltageRange(double &vmin, double &vmax) override
bool SetDefaultDriftMedium()
Find lowest epsilon, check for eps = 0, set default drift media flags.
std::map< std::string, WeightingFieldCopy > m_wfieldCopies
void TimeInterpolation(const double t, double &f0, double &f1, int &i0, int &i1)
Interpolation of potential between two time slices.
static double Potential5(const std::array< double, 8 > &v, const std::array< double, 2 > &t)
Interpolate the potential in a curved quadrilateral.
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
void EnableDeleteBackgroundElements(const bool on=true)
Option to eliminate mesh elements in conductors (default: on).
double GetPotential(const size_t i) const
Return the potential at a given node.
__DEVICE__ 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.
void JacobianCube(const Element &element, const double t1, const double t2, const double t3, TMatrixD *&jac, std::vector< TMatrixD * > &dN) const
Calculate Jacobian for a cube.
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.
void DriftMedium(const size_t imat)
Flag a field map material as a drift medium.
std::vector< std::array< double, 3 > > m_bbMax
void PrintWarning(const std::string &header)
bool GetElementNodes(const size_t i, std::vector< size_t > &nodes) const override
static double Potential13(const std::array< double, 10 > &v, const std::array< double, 4 > &t)
Interpolate the potential in a curved quadratic tetrahedron.
bool GetElementRegion(const size_t i, size_t &mat, bool &drift) const override
Medium * GetMedium(const double x, const double y, const double z) override
std::array< double, 3 > m_maxBoundingBox
bool m_useTetrahedralTree
std::array< double, 3 > m_mapmin
std::vector< double > m_pot
__DEVICE__ 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.
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
double Potential(const double x, const double y, const double z, const std::vector< double > &potentials) const
Compute the electrostatic/weighting potential.
static double ScalingFactor(std::string unit)
bool m_cacheElemBoundingBoxes
Flag to check if bounding boxes of elements are cached.
void UpdatePeriodicity() override
size_t GetNumberOfNodes() const override
static double ReadDouble(char *token, double def, bool &error)
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
void UpdatePeriodicityCommon()
ComponentFieldMap(const std::string &name)
Constructor.
std::vector< Material > m_materials
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.
size_t GetNumberOfElements() const override
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)
Makes a weighting potential copy of a imported map which can be translated and rotated.
virtual void GetAspectRatio(const size_t i, double &dmin, double &dmax) const
virtual ~ComponentFieldMap()
Destructor.
int Coordinates5(const double x, const double y, double &t1, double &t2, double &t3, double &t4, double jac[4][4], double &det, const std::array< double, 8 > &xn, const std::array< double, 8 > &yn) const
Calculate local coordinates for curved quadratic quadrilaterals.
bool m_printConvergenceWarnings
std::array< double, 3 > m_mapna
virtual double GetElementVolume(const size_t i) const
std::vector< std::array< std::array< double, 3 >, 4 > > m_w12
ComponentFieldMap()=delete
Default constructor.
void EnableTetrahedralTreeForElementSearch(const bool on=true)
Enable or disable the usage of the tetrahedral tree for searching the element in the mesh.
__DEVICE__ int Coordinates13(const double x, const double y, const double z, double &t1, double &t2, double &t3, double &t4, double jac[4][4], double &det, const std::array< double, 10 > &xn, const std::array< double, 10 > &yn, const std::array< double, 10 > &zn, const std::array< std::array< double, 3 >, 4 > &w) const
Calculate local coordinates for curved quadratic tetrahedra.
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.
__DEVICE__ void Coordinates12(const double x, const double y, const double z, double &t1, double &t2, double &t3, double &t4, const std::array< double, 10 > &xn, const std::array< double, 10 > &yn, const std::array< double, 10 > &zn, const std::array< std::array< double, 3 >, 4 > &w) const
Calculate local coordinates in linear tetrahedra.
__DEVICE__ void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
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.
static std::array< std::array< double, 3 >, 4 > Weights12(const std::array< double, 10 > &xn, const std::array< double, 10 > &yn, const std::array< double, 10 > &zn)
bool InitializeTetrahedralTree()
Initialize the tetrahedral tree.
int Coordinates3(const double x, const double y, double &t1, double &t2, double &t3, double &t4, double jac[4][4], double &det, const std::array< double, 8 > &xn, const std::array< double, 8 > &yn) const
Calculate local coordinates for curved quadratic triangles.
static void Jacobian5(const std::array< double, 8 > &xn, const std::array< double, 8 > &yn, const double u, const double v, double &det, double jac[4][4])
Calculate Jacobian for curved quadratic quadrilaterals.
void DelayedWeightingPotentials(const double x, const double y, const double z, const std::string &label, std::vector< double > &dwp) override
void UpdatePeriodicity2d()
std::vector< int > m_elementIndices
static int ReadInteger(char *token, int def, bool &error)
void SetGas(Medium *medium)
Associate all field map materials with a relative permittivity of unity to a given Medium class.
bool GetElementaryCell(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
std::vector< Element > m_elements
int CoordinatesCube(const double x, const double y, const double z, double &t1, double &t2, double &t3, TMatrixD *&jac, std::vector< TMatrixD * > &dN, const Element &element) const
Calculate local coordinates for a cube.
std::array< double, 3 > m_mapamax
bool GetNode(const size_t i, double &x, double &y, double &z) const override
static __DEVICE__ void Jacobian13(const std::array< double, 10 > &xn, const std::array< double, 10 > &yn, const std::array< double, 10 > &zn, const double fourt0, const double fourt1, const double fourt2, const double fourt3, double &det, double jac[4][4])
Calculate Jacobian for curved quadratic tetrahedra.
std::array< double, 3 > m_cells
void CalculateElementBoundingBoxes()
Calculate the bounding boxes of all elements after initialization.
void EnableConvergenceWarnings(const bool on=true)
Enable or disable warnings that the calculation of the local coordinates did not achieve the requeste...
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
__DEVICE__ 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 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)
int Coordinates4(const double x, const double y, double &t1, double &t2, double &t3, double &t4, double &det, const std::array< double, 8 > &xn, const std::array< double, 8 > &yn) const
Calculate local coordinates for linear quadrilaterals.
std::array< double, 3 > m_mapmax
__DEVICE__ 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.
std::map< std::string, std::vector< std::vector< double > > > m_dwpot
static void Jacobian3(const std::array< double, 8 > &xn, const std::array< double, 8 > &yn, const double u, const double v, const double w, double &det, double jac[4][4])
Calculate Jacobian for curved quadratic triangles.
double CreateGPUTransferObject(ComponentGPU *&comp_gpu) override
Create and initialise GPU Transfer class.
std::vector< std::array< double, 3 > > m_bbMin
void PrintNotReady(const std::string &header) const
static __DEVICE__ 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.