1#ifndef G_COMPONENT_FIELD_MAP_H
2#define G_COMPONENT_FIELD_MAP_H
37 double& xmax,
double& ymax,
double& zmax)
override;
39 double& xmax,
double& ymax,
double& zmax)
override;
68 bool GetElement(
const size_t i,
double& vol,
double& dmin,
double& dmax);
70 virtual bool GetElement(
const size_t i,
size_t& mat,
bool& drift,
71 std::vector<size_t>& nodes)
const;
73 virtual bool GetNode(
const size_t i,
double& x,
double& y,
double& z)
const;
77 m_checkMultipleElement = on;
78 if (on) m_lastElement = -1;
88 m_useTetrahedralTree = on;
122 std::vector<double>
w;
124 std::vector<std::vector<double>>
dw;
179 void Reset()
override;
191 int FindElement5(
const double x,
const double y,
const double z,
double& t1,
192 double& t2,
double& t3,
double& t4,
double jac[4][4],
195 int FindElement13(
const double x,
const double y,
const double z,
double& t1,
196 double& t2,
double& t3,
double& t4,
double jac[4][4],
200 double& t1,
double& t2,
double& t3, TMatrixD*& jac,
201 std::vector<TMatrixD*>& dN);
204 void MapCoordinates(
double& xpos,
double& ypos,
double& zpos,
bool& xmirrored,
205 bool& ymirrored,
bool& zmirrored,
double& rcoordinate,
206 double& rotation)
const;
208 void UnmapFields(
double& ex,
double& ey,
double& ez,
double& xpos,
209 double& ypos,
double& zpos,
bool& xmirrored,
bool& ymirrored,
210 bool& zmirrored,
double& rcoordinate,
211 double& rotation)
const;
213 int ReadInteger(
char* token,
int def,
bool& error);
214 double ReadDouble(
char* token,
double def,
bool& error);
226 const std::string& filename)
const;
227 void PrintElement(
const std::string& header,
const double x,
const double y,
228 const double z,
const double t1,
const double t2,
229 const double t3,
const double t4,
const Element& element,
230 const unsigned int n,
const int iw = -1)
const;
234 bool m_checkMultipleElement =
false;
237 bool m_useTetrahedralTree =
true;
238 std::unique_ptr<TetrahedralTree> m_octree;
241 bool m_cacheElemBoundingBoxes =
false;
244 int m_lastElement = -1;
247 int Coordinates3(
double x,
double y,
double z,
double& t1,
double& t2,
248 double& t3,
double& t4,
double jac[4][4],
double& det,
251 int Coordinates4(
const double x,
const double y,
const double z,
double& t1,
252 double& t2,
double& t3,
double& t4,
double& det,
255 int Coordinates5(
const double x,
const double y,
const double z,
double& t1,
256 double& t2,
double& t3,
double& t4,
double jac[4][4],
257 double& det,
const Element& element)
const;
259 void Coordinates12(
const double x,
const double y,
const double z,
double& t1,
260 double& t2,
double& t3,
double& t4,
263 int Coordinates13(
const double x,
const double y,
const double z,
double& t1,
264 double& t2,
double& t3,
double& t4,
double jac[4][4],
265 double& det,
const Element& element)
const;
267 int CoordinatesCube(
const double x,
const double y,
const double z,
268 double& t1,
double& t2,
double& t3, TMatrixD*& jac,
269 std::vector<TMatrixD*>& dN,
const Element& element)
const;
272 void Jacobian3(
const Element& element,
const double u,
const double v,
273 const double w,
double& det,
double jac[4][4])
const;
275 void Jacobian5(
const Element& element,
const double u,
const double v,
276 double& det,
double jac[4][4])
const;
278 void Jacobian13(
const Element& element,
const double t,
const double u,
279 const double v,
const double w,
double& det,
280 double jac[4][4])
const;
282 void JacobianCube(
const Element& element,
const double t1,
const double t2,
283 const double t3, TMatrixD*& jac,
284 std::vector<TMatrixD*>& dN)
const;
287 void CalculateElementBoundingBoxes();
290 bool InitializeTetrahedralTree();
Base class for components based on finite-element field maps.
void DriftMedium(const unsigned int imat)
Flag a field map material as a drift medium.
virtual bool GetNode(const size_t i, double &x, double &y, double &z) const
void PrintRange()
Show x, y, z, V and angular ranges.
virtual double GetElementVolume(const unsigned int i)=0
void SetMedium(const unsigned int imat, Medium *medium)
Associate a field map material with a Medium class.
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::array< double, 3 > m_mapamin
double ReadDouble(char *token, double def, bool &error)
void EnableDeleteBackgroundElements(const bool on=true)
Option to eliminate mesh elements in conductors (default: on).
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 PrintWarning(const std::string &header)
virtual void GetAspectRatio(const unsigned int i, double &dmin, double &dmax)=0
std::array< double, 3 > m_maxBoundingBox
std::array< double, 3 > m_mapmin
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)
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the bounding box coordinates.
void UpdatePeriodicityCommon()
int ReadInteger(char *token, int def, bool &error)
std::vector< Material > m_materials
virtual size_t GetNumberOfElements() const
Return the number of mesh elements.
virtual size_t GetNumberOfNodes() const
int FindElementCube(const double x, const double y, const double z, double &t1, double &t2, double &t3, TMatrixD *&jac, std::vector< TMatrixD * > &dN)
Find the element for a point in a cube.
std::vector< bool > m_wfieldsOk
virtual ~ComponentFieldMap()
Destructor.
size_t GetWeightingFieldIndex(const std::string &label) const
bool m_printConvergenceWarnings
std::array< double, 3 > m_mapna
double GetConductivity(const unsigned int imat) const
Return the conductivity of a field map material.
ComponentFieldMap()=delete
Default constructor.
void EnableTetrahedralTreeForElementSearch(const bool on=true)
std::vector< bool > m_dwfieldsOk
std::vector< Node > m_nodes
void PrintCouldNotOpen(const std::string &header, const std::string &filename) const
int FindElement5(const double x, const double y, const double z, double &t1, double &t2, double &t3, double &t4, double jac[4][4], double &det)
Find the element for a point in curved quadratic quadrilaterals.
double GetPermittivity(const unsigned int imat) const
Return the permittivity of a field map material.
std::vector< double > m_wdtimes
void UpdatePeriodicity2d()
std::vector< std::string > m_wfields
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)
Find the element for a point in curved quadratic tetrahedra.
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
Medium * GetMedium(const unsigned int i) const
Return the Medium associated to a field map material.
void NotDriftMedium(const unsigned int imat)
Flag a field map materials as a non-drift medium.
std::array< double, 3 > m_mapamax
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 Element &element, const unsigned int n, const int iw=-1) const
std::array< double, 3 > m_cells
void EnableConvergenceWarnings(const bool on=true)
std::array< bool, 3 > m_setang
virtual void SetRange()
Calculate x, y, z, V and angular ranges.
bool GetElement(const size_t i, double &vol, double &dmin, double &dmax)
Return the volume and aspect ratio of a mesh element.
bool IsInBoundingBox(const double x, const double y, const double z) const
void EnableCheckMapIndices(const bool on=true)
std::array< double, 3 > m_mapmax
void Reset() override
Reset the component.
void UnmapFields(double &ex, double &ey, double &ez, double &xpos, double &ypos, double &zpos, bool &xmirrored, bool &ymirrored, bool &zmirrored, double &rcoordinate, double &rotation) const
Move (ex, ey, ez) to global coordinates.
void PrintNotReady(const std::string &header) const
size_t GetOrCreateWeightingFieldIndex(const std::string &label)
Abstract base class for components.
virtual Medium * GetMedium(const double x, const double y, const double z)
Get the medium at a given location (x, y, z).
Abstract base class for media.
Draw the mesh of a field-map component.
std::array< float, 3 > bbMax
std::array< float, 3 > bbMin
std::vector< std::vector< double > > dw