Garfield++ v2r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ComponentFieldMap.hh
Go to the documentation of this file.
1#ifndef G_COMPONENT_FIELD_MAP_H
2#define G_COMPONENT_FIELD_MAP_H
3
4#include <iostream>
5#include "ComponentBase.hh"
6#include "TMatrixD.h"
7#include "TetrahedralTree.hh"
8
9namespace Garfield {
10
11/// Base class for components based on finite-element field maps.
12
14
15 public:
16 /// Constructor
18 /// Destructor
19 virtual ~ComponentFieldMap();
20
21 /// Calculate x, y, z, V and angular ranges.
22 virtual void SetRange();
23 /// Show x, y, z, V and angular ranges
24 void PrintRange();
25
26 virtual bool IsInBoundingBox(const double x, const double y, const double z) const;
27 virtual bool GetBoundingBox(double& xmin, double& ymin, double& zmin,
28 double& xmax, double& ymax, double& zmax);
29
30 virtual bool GetVoltageRange(double& vmin, double& vmax) {
31 vmin = mapvmin;
32 vmax = mapvmax;
33 return true;
34 }
35
36 /// List all currently defined materials
37 void PrintMaterials();
38 /// Flag a field map material as a drift medium.
39 void DriftMedium(const unsigned int imat);
40 /// Flag a field map materials as a non-drift medium.
41 void NotDriftMedium(const unsigned int imat);
42 /// Return the number of materials in the field map.
43 unsigned int GetNumberOfMaterials() const { return m_nMaterials; }
44 /// Return the permittivity of a field map material.
45 double GetPermittivity(const unsigned int imat) const;
46 /// Return the conductivity of a field map material.
47 double GetConductivity(const unsigned int imat) const;
48 /// Associate a field map material with a Medium class.
49 void SetMedium(const unsigned int imat, Medium* medium);
50 /// Return the Medium associated to a field map material.
51 Medium* GetMedium(const unsigned int i) const;
52
53 Medium* GetMedium(const double x, const double y, const double z) = 0;
54 unsigned int GetNumberOfMedia() const { return m_nMaterials; }
55
56 /// Return the number of mesh elements.
57 int GetNumberOfElements() const { return nElements; }
58 /// Return the volume and aspect ratio of a mesh element.
59 bool GetElement(const unsigned int i, double& vol, double& dmin,
60 double& dmax);
61
62 virtual void ElectricField(const double x, const double y, const double z,
63 double& ex, double& ey, double& ez, Medium*& m,
64 int& status) = 0;
65 virtual void ElectricField(const double x, const double y, const double z,
66 double& ex, double& ey, double& ez, double& v,
67 Medium*& m, int& status) = 0;
68
69 virtual void WeightingField(const double x, const double y, const double z,
70 double& wx, double& wy, double& wz,
71 const std::string& label) = 0;
72
73 virtual double WeightingPotential(const double x, const double y,
74 const double z,
75 const std::string& label) = 0;
76
77 // Options
79 m_checkMultipleElement = true;
80 m_lastElement = -1;
81 }
82 void DisableCheckMapIndices() { m_checkMultipleElement = false; }
85
86 /// Enable or disable the usage of the tetrahedral tree
87 /// for searching the element in the mesh.
88 void EnableTetrahedralTreeForElementSearch(const bool on = true) {
89 m_useTetrahedralTree = on;
90 }
91
92 friend class ViewFEMesh;
93
94 protected:
95 bool m_is3d;
96
97 // Elements
99 struct Element {
100 // Nodes
101 int emap[10];
102 // Material
103 unsigned int matmap;
105 // Bounding box of the element
106 double xmin, ymin, zmin, xmax, ymax, zmax;
107 };
108 std::vector<Element> elements;
109
110 // Nodes
112 struct Node {
113 // Coordinates
114 double x, y, z;
115 // Potential
116 double v;
117 // Weighting potentials
118 std::vector<double> w;
119 };
120 std::vector<Node> nodes;
121
122 // Materials
123 unsigned int m_nMaterials;
124 struct Material {
125 // Permittivity
126 double eps;
127 // Resistivity
128 double ohm;
130 // Associated medium
132 };
133 std::vector<Material> materials;
134
136 std::vector<std::string> wfields;
137 std::vector<bool> wfieldsOk;
138
139 // Bounding box
143
144 // Ranges and periodicities
150
152 double mapsx, mapsy, mapsz;
153
156
157 // Option to delete meshing in conductors
159
160 // Warnings flag
162 unsigned int m_nWarnings;
163
164 // Reset the component
165 void Reset() {};
166
167 // Periodicities
168 virtual void UpdatePeriodicity() = 0;
169 void UpdatePeriodicity2d();
171
172 /// Find the element for a point in curved quadratic quadrilaterals.
173 int FindElement5(const double x, const double y, const double z, double& t1,
174 double& t2, double& t3, double& t4, double jac[4][4],
175 double& det);
176 /// Find the element for a point in curved quadratic tetrahedra.
177 int FindElement13(const double x, const double y, const double z, double& t1,
178 double& t2, double& t3, double& t4, double jac[4][4],
179 double& det);
180 /// Find the element for a point in a cube.
181 int FindElementCube(const double x, const double y, const double z,
182 double& t1, double& t2, double& t3, TMatrixD*& jac,
183 std::vector<TMatrixD*>& dN);
184
185 /// Move (xpos, ypos, zpos) to field map coordinates.
186 void MapCoordinates(double& xpos, double& ypos, double& zpos, bool& xmirrored,
187 bool& ymirrored, bool& zmirrored, double& rcoordinate,
188 double& rotation) const;
189 /// Move (ex, ey, ez) to global coordinates.
190 void UnmapFields(double& ex, double& ey, double& ez, double& xpos,
191 double& ypos, double& zpos, bool& xmirrored, bool& ymirrored,
192 bool& zmirrored, double& rcoordinate, double& rotation) const;
193
194 int ReadInteger(char* token, int def, bool& error);
195 double ReadDouble(char* token, double def, bool& error);
196
197 virtual double GetElementVolume(const unsigned int i) = 0;
198 virtual void GetAspectRatio(const unsigned int i, double& dmin,
199 double& dmax) = 0;
200
201 void PrintWarning(const std::string& header) {
202 if (!m_warning || m_nWarnings > 10) return;
203 std::cerr << m_className << "::" << header << ":\n"
204 << " Warnings have been issued for this field map.\n";
205 ++m_nWarnings;
206 }
207 void PrintNotReady(const std::string& header) const {
208 std::cerr << m_className << "::" << header << ":\n"
209 << " Field map not yet initialised.\n";
210 }
211 void PrintElement(const std::string& header, const double x, const double y,
212 const double z, const double t1, const double t2,
213 const double t3, const double t4, const unsigned int i,
214 const unsigned int n, const int iw = -1) const;
215
216 private:
217 /// Scan for multiple elements that contain a point
218 bool m_checkMultipleElement;
219
220 // Tetrahedral tree
221 bool m_useTetrahedralTree;
222 bool m_isTreeInitialized;
223 TetrahedralTree* m_tetTree;
224
225 /// Flag to check if bounding boxes of elements are cached
226 bool m_cacheElemBoundingBoxes;
227
228 /// Keep track of the last element found.
229 int m_lastElement;
230
231 /// Calculate local coordinates for curved quadratic triangles.
232 int Coordinates3(double x, double y, double z, double& t1, double& t2,
233 double& t3, double& t4, double jac[4][4], double& det,
234 const unsigned int imap) const;
235 /// Calculate local coordinates for linear quadrilaterals.
236 int Coordinates4(const double x, const double y, const double z, double& t1,
237 double& t2, double& t3, double& t4, double jac[4][4],
238 double& det, const unsigned int imap) const;
239 /// Calculate local coordinates for curved quadratic quadrilaterals.
240 int Coordinates5(const double x, const double y, const double z, double& t1,
241 double& t2, double& t3, double& t4, double jac[4][4],
242 double& det, const unsigned int imap) const;
243 /// Calculate local coordinates in linear tetrahedra.
244 int Coordinates12(const double x, const double y, const double z, double& t1,
245 double& t2, double& t3, double& t4,
246 const unsigned int imap) const;
247 /// Calculate local coordinates for curved quadratic tetrahedra.
248 int Coordinates13(const double x, const double y, const double z, double& t1,
249 double& t2, double& t3, double& t4, double jac[4][4],
250 double& det, const unsigned int imap) const;
251 /// Calculate local coordinates for a cube.
252 int CoordinatesCube(const double x, const double y, const double z,
253 double& t1, double& t2, double& t3, TMatrixD*& jac,
254 std::vector<TMatrixD*>& dN,
255 const unsigned int imap) const;
256
257 /// Calculate Jacobian for curved quadratic triangles.
258 void Jacobian3(const unsigned int i, const double u, const double v,
259 const double w, double& det, double jac[4][4]) const;
260 /// Calculate Jacobian for curved quadratic quadrilaterals.
261 void Jacobian5(const unsigned int i, const double u, const double v,
262 double& det, double jac[4][4]) const;
263 /// Calculate Jacobian for curved quadratic tetrahedra.
264 void Jacobian13(const unsigned int i, const double t, const double u,
265 const double v, const double w, double& det,
266 double jac[4][4]) const;
267 /// Calculate Jacobian for a cube.
268 void JacobianCube(const unsigned int i, const double t1, const double t2,
269 const double t3, TMatrixD*& jac,
270 std::vector<TMatrixD*>& dN) const;
271
272 /// Calculate the bounding boxes of all elements after initialization.
273 void CalculateElementBoundingBoxes();
274
275 /// Initialize the tetrahedral tree.
276 bool InitializeTetrahedralTree();
277
278};
279}
280
281#endif
Abstract base class for components.
std::string m_className
Class name.
Base class for components based on finite-element field maps.
Medium * GetMedium(const double x, const double y, const double z)=0
Get the medium at a given location (x, y, z).
void DriftMedium(const unsigned int imat)
Flag a field map material as a drift medium.
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.
int GetNumberOfElements() const
Return the number of mesh elements.
double ReadDouble(char *token, double def, bool &error)
virtual void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label)=0
virtual bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
Get the bounding box coordinates.
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
int ReadInteger(char *token, int def, bool &error)
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.
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 unsigned int i, const unsigned int n, const int iw=-1) const
virtual ~ComponentFieldMap()
Destructor.
virtual void UpdatePeriodicity()=0
Verify periodicities.
unsigned int GetNumberOfMaterials() const
Return the number of materials in the field map.
double GetConductivity(const unsigned int imat) const
Return the conductivity of a field map material.
void EnableTetrahedralTreeForElementSearch(const bool on=true)
unsigned int GetNumberOfMedia() const
void Reset()
Geometry checks.
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< Material > materials
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.
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.
virtual bool GetVoltageRange(double &vmin, double &vmax)
Calculate the voltage range [V].
virtual void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status)=0
virtual double WeightingPotential(const double x, const double y, const double z, const std::string &label)=0
bool GetElement(const unsigned int i, double &vol, double &dmin, double &dmax)
Return the volume and aspect ratio of a mesh element.
virtual void SetRange()
Calculate x, y, z, V and angular ranges.
std::vector< Element > elements
virtual void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, double &v, Medium *&m, int &status)=0
virtual bool IsInBoundingBox(const double x, const double y, const double z) const
std::vector< std::string > wfields
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
Abstract base class for media.
Definition: Medium.hh:11
Helper class for searches in field maps.
Draw the mesh of a field-map component.
Definition: ViewFEMesh.hh:26