Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ComponentTcad3d.hh
Go to the documentation of this file.
1#ifndef G_COMPONENT_TCAD_3D_H
2#define G_COMPONENT_TCAD_3D_H
3
4#include <array>
5
6#include "ComponentBase.hh"
7
8namespace Garfield {
9
10/// Interpolation in a three-dimensional field map created by Sentaurus Device.
11
13 public:
14 /// Constructor
16 /// Destructor
18
19 void ElectricField(const double x, const double y, const double z, double& ex,
20 double& ey, double& ez, double& v, Medium*& m,
21 int& status) override;
22 void ElectricField(const double x, const double y, const double z, double& ex,
23 double& ey, double& ez, Medium*& m, int& status) override;
24
25 void WeightingField(const double x, const double y, const double z,
26 double& wx, double& wy, double& wz,
27 const std::string& label) override;
28 double WeightingPotential(const double x, const double y, const double z,
29 const std::string& label) override;
30
31 Medium* GetMedium(const double x, const double y, const double z) override;
32
33 bool GetVoltageRange(double& vmin, double& vmax) override;
34 bool GetBoundingBox(double& xmin, double& ymin, double& zmin, double& xmax,
35 double& ymax, double& zmax) override;
36
37 /** Import mesh and field map from files.
38 * \param gridfilename name of the .grd file containing the mesh
39 * \param datafilename name of the .dat file containing the nodal solution
40 */
41 bool Initialise(const std::string& gridfilename,
42 const std::string& datafilename);
43
44 /** Import field maps defining the weighting field and potential.
45 * \param datfile1 .dat file containing the field map at nominal bias.
46 * \param datfile2 .dat file containing the field map for a configuration
47 with the potential at the electrode to be read out
48 increased by a small voltage dv.
49 * \param dv increase in electrode potential between the two field maps.
50 *
51 * The field maps must use the same mesh as the drift field.
52 */
53 bool SetWeightingField(const std::string& datfile1,
54 const std::string& datfile2, const double dv);
55
56 /// List all currently defined regions.
57 void PrintRegions();
58 /// Get the number of regions in the device.
59 unsigned int GetNumberOfRegions() const { return m_regions.size(); }
60 void GetRegion(const unsigned int ireg, std::string& name,
61 bool& active) const;
62 void SetDriftRegion(const unsigned int ireg);
63 void UnsetDriftRegion(const unsigned int ireg);
64 /// Set the medium for a given region
65 void SetMedium(const unsigned int ireg, Medium* m);
66 /// Get the medium for a given region
67 bool GetMedium(const unsigned int ireg, Medium*& m) const;
68
69 int GetNumberOfElements() const { return m_elements.size(); }
70 bool GetElement(const unsigned int i, double& vol, double& dmin, double& dmax,
71 int& type) const;
72 bool GetElement(const unsigned int i, double& vol, double& dmin, double& dmax,
73 int& type, int& node1, int& node2, int& node3, int& node4,
74 int& node5, int& node6, int& node7, int& reg) const;
75 unsigned int GetNumberOfNodes() const { return m_vertices.size(); }
76 bool GetNode(const unsigned int i, double& x, double& y, double& z, double& v,
77 double& ex, double& ey, double& ez) const;
78
79 private:
80 // Max. number of vertices per element
81 static constexpr int nMaxVertices = 7;
82
83 // Regions
84 struct Region {
85 // Name of region (from Tcad)
86 std::string name;
87 // Flag indicating if the region is active (i. e. a drift medium)
88 bool drift;
89 Medium* medium;
90 };
91 std::vector<Region> m_regions;
92
93 // Vertices
94 struct Vertex {
95 // Coordinates [cm]
96 double x, y, z;
97 // Potential [V] and electric field [V / cm]
98 double p, ex, ey, ez;
99 };
100 std::vector<Vertex> m_vertices;
101
102 // Weighting field and potential at each vertex.
103 std::vector<std::array<double, 3> > m_wf;
104 std::vector<double> m_wp;
105
106 // Elements
107 struct Element {
108 // Indices of vertices
109 int vertex[nMaxVertices];
110 // Type of element
111 // 1: Segment (line)
112 // 2: Triangle
113 // 3: Rectangle
114 // 4: Polygon
115 // 5: Tetrahedron
116 // 6: Pyramid
117 // 7: Prism
118 // 8: Brick
119 // 9: Tetrabrick
120 // 10: Polyhedron
121 // Only types 2 and 5 are supported by this class.
122 int type;
123 // Associated region
124 int region;
125 std::vector<int> neighbours;
126 // Bounding box
127 double xmin, xmax;
128 double ymin, ymax;
129 double zmin, zmax;
130 };
131 std::vector<Element> m_elements;
132
133 // Face
134 struct Face {
135 // Indices of edges
136 int edge[4];
137 int type;
138 };
139
140 // Voltage range
141 double m_pMin = 0.;
142 double m_pMax = 0.;
143
144 // Bounding box
145 double m_xMinBB, m_yMinBB, m_zMinBB;
146 double m_xMaxBB, m_yMaxBB, m_zMaxBB;
147
148 // Element from the previous call
149 int m_lastElement = 0;
150
151 void Reset() override;
152 void UpdatePeriodicity() override;
153
154 unsigned int FindElement(const double x, const double y, const double z,
155 std::array<double, nMaxVertices>& w) const;
156 bool CheckElement(const double x, const double y, const double z,
157 const Element& element,
158 std::array<double, nMaxVertices>& w) const {
159 bool inside = false;
160 switch (element.type) {
161 case 2:
162 if (CheckTriangle(x, y, z, element, w)) inside = true;
163 break;
164 case 5:
165 if (CheckTetrahedron(x, y, z, element, w)) inside = true;
166 break;
167 default:
168 std::cerr << m_className << "::CheckElement:\n"
169 << " Invalid element type (" << element.type << ").\n";
170 break;
171 }
172 return inside;
173 }
174 bool CheckTetrahedron(const double x, const double y, const double z,
175 const Element& element,
176 std::array<double, nMaxVertices>& w) const;
177 bool CheckTriangle(const double x, const double y, const double z,
178 const Element& element,
179 std::array<double, nMaxVertices>& w) const;
180
181 void FindNeighbours();
182 bool LoadGrid(const std::string& gridfilename);
183 bool LoadData(const std::string& datafilename);
184 bool ReadDataset(std::ifstream& datafile, const std::string& dataset);
185 bool LoadWeightingField(const std::string& datafilename,
186 std::vector<std::array<double, 3> >& wf,
187 std::vector<double>& wp);
188 void Cleanup();
189
190 void MapCoordinates(double& x, double& y, double& z, bool& xmirr, bool& ymirr,
191 bool& zmirr) const;
192 int FindRegion(const std::string& name) const;
193};
194}
195#endif
Abstract base class for components.
std::string m_className
Class name.
Interpolation in a three-dimensional field map created by Sentaurus Device.
unsigned int GetNumberOfNodes() const
bool Initialise(const std::string &gridfilename, const std::string &datafilename)
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).
void UnsetDriftRegion(const unsigned int ireg)
void GetRegion(const unsigned int ireg, std::string &name, bool &active) const
double WeightingPotential(const double x, const double y, const double z, const std::string &label) override
bool GetNode(const unsigned int i, double &x, double &y, double &z, double &v, double &ex, double &ey, double &ez) const
void SetDriftRegion(const unsigned int ireg)
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the bounding box coordinates.
void PrintRegions()
List all currently defined regions.
Medium * GetMedium(const double x, const double y, const double z) override
Get the medium at a given location (x, y, z).
bool GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
bool SetWeightingField(const std::string &datfile1, const std::string &datfile2, const double dv)
unsigned int GetNumberOfRegions() const
Get the number of regions in the device.
bool GetElement(const unsigned int i, double &vol, double &dmin, double &dmax, int &type) const
void SetMedium(const unsigned int ireg, Medium *m)
Set the medium for a given region.
Abstract base class for media.
Definition: Medium.hh:13