Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ComponentTcad2d.hh
Go to the documentation of this file.
1#ifndef G_COMPONENT_TCAD_2D_H
2#define G_COMPONENT_TCAD_2D_H
3
4#include <array>
5
6#include "ComponentBase.hh"
7
8namespace Garfield {
9
10/// Interpolation in a two-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
23 void ElectricField(const double x, const double y, const double z, double& ex,
24 double& ey, double& ez, Medium*& m, int& status) override {
25 double v = 0.;
26 ElectricField(x, y, z, ex, ey, ez, v, m, status);
27 }
28
29 void WeightingField(const double x, const double y, const double z,
30 double& wx, double& wy, double& wz,
31 const std::string& label) override;
32 double WeightingPotential(const double x, const double y, const double z,
33 const std::string& label) override;
34
35 Medium* GetMedium(const double x, const double y, const double z) override;
36
37 bool GetVoltageRange(double& vmin, double& vmax) override;
38 bool GetBoundingBox(double& xmin, double& ymin, double& zmin, double& xmax,
39 double& ymax, double& zmax) override;
40 void SetRangeZ(const double zmin, const double zmax);
41
42 /** Import mesh and field map from files.
43 * \param gridfilename name of the .grd file containing the mesh
44 * \param datafilename name of the .dat file containing the nodal solution
45 */
46 bool Initialise(const std::string& gridfilename,
47 const std::string& datafilename);
48
49 /** Import field maps defining the weighting field and potential.
50 * \param datfile1 .dat file containing the field map at nominal bias.
51 * \param datfile2 .dat file containing the field map for a configuration
52 with the potential at the electrode to be read out
53 increased by a small voltage dv.
54 * \param dv increase in electrode potential between the two field maps.
55 *
56 * The field maps must use the same mesh as the drift field.
57 */
58 bool SetWeightingField(const std::string& datfile1,
59 const std::string& datfile2, const double dv);
60
61 /// List all currently defined regions.
62 void PrintRegions() const;
63 /// Get the number of regions in the device.
64 unsigned int GetNumberOfRegions() const { return m_regions.size(); }
65 void GetRegion(const unsigned int i, std::string& name, bool& active) const;
66 void SetDriftRegion(const unsigned int ireg);
67 void UnsetDriftRegion(const unsigned int ireg);
68 /// Set the medium for a given region.
69 void SetMedium(const unsigned int ireg, Medium* m);
70 /// Get the medium for a given region.
71 Medium* GetMedium(const unsigned int ireg) const;
72
73 // Retrieve information about the mesh.
74 unsigned int GetNumberOfElements() const { return m_elements.size(); }
75 bool GetElement(const unsigned int i, double& vol, double& dmin, double& dmax,
76 int& type) const;
77 bool GetElement(const unsigned int i, double& vol, double& dmin, double& dmax,
78 int& type, int& node1, int& node2, int& node3, int& node4,
79 int& reg) const;
80 unsigned int GetNumberOfNodes() const { return m_vertices.size(); }
81 bool GetNode(const unsigned int i, double& x, double& y, double& v,
82 double& ex, double& ey) const;
83
84 // Mobilities
85 bool GetMobility(const double x, const double y, const double z, double& emob,
86 double& hmob);
87
88 // Velocity field maps
89 void ElectronVelocity(const double x, const double y, const double z,
90 double& vx, double& vy, double& vz, Medium*& m,
91 int& status) override;
92 void HoleVelocity(const double x, const double y, const double z, double& vx,
93 double& vy, double& vz, Medium*& m, int& status) override;
94 // Lifetime field maps
95 bool GetElectronLifetime(const double x, const double y, const double z,
96 double& etau) override;
97 bool GetHoleLifetime(const double x, const double y, const double z,
98 double& htau) override;
99
100 // Trapping
101 int GetNumberOfDonors() { return m_donors.size(); }
102 int GetNumberOfAcceptors() { return m_acceptors.size(); }
103
104 bool GetDonorOccupation(const double x, const double y, const double z,
105 const unsigned int donorNumber,
106 double& occupationFraction);
107 bool GetAcceptorOccupation(const double x, const double y, const double z,
108 const unsigned int acceptorNumber,
109 double& occupationFraction);
110 bool SetDonor(const unsigned int donorNumber, const double eXsec,
111 const double hxSec, const double concentration);
112 bool SetAcceptor(const unsigned int acceptorNumber, const double eXsec,
113 const double hxSec, const double concentration);
114
115 bool ElectronAttachment(const double x, const double y, const double z,
116 double& eta) override;
117 bool HoleAttachment(const double x, const double y, const double z,
118 double& eta) override;
119
120 private:
121 // Max. number of vertices per element
122 static constexpr unsigned int nMaxVertices = 4;
123
124 // Regions
125 struct Region {
126 // Name of region (from Tcad)
127 std::string name;
128 // Flag indicating if the region is active (i. e. a drift medium)
129 bool drift;
130 Medium* medium;
131 };
132 std::vector<Region> m_regions;
133
134 // Vertices
135 struct Vertex {
136 // Coordinates [cm]
137 double x, y;
138 // Potential [V] and electric field [V / cm]
139 double p, ex, ey;
140 // Mobilities [cm2 / (V ns)]
141 double emob, hmob;
142 // Velocities [cm/ns]
143 double eVx, eVy;
144 double hVx, hVy;
145 // Lifetimes [1/ns]
146 double eTau, hTau;
147 // Trap occupations [dimensionless]
148 std::vector<float> donorOcc;
149 std::vector<float> acceptorOcc;
150 };
151 std::vector<Vertex> m_vertices;
152
153 // Weighting field and potential at each vertex.
154 std::vector<std::array<double, 2> > m_wf;
155 std::vector<double> m_wp;
156
157 // Elements
158 struct Element {
159 // Indices of vertices
160 int vertex[nMaxVertices];
161 // Type of element
162 // 0: Point
163 // 1: Segment (line)
164 // 2: Triangle
165 // 3: Rectangle
166 // 4: Polygon
167 // Types 1 - 3 are supported by this class.
168 int type;
169 // Associated region
170 int region;
171 std::vector<int> neighbours;
172 // Bounding box
173 double xmin, xmax;
174 double ymin, ymax;
175 };
176 std::vector<Element> m_elements;
177
178 struct Defect {
179 // Electron cross-section
180 double xsece;
181 // Hole cross-section
182 double xsech;
183 // Concentration
184 double conc;
185 };
186 std::vector<Defect> m_donors;
187 std::vector<Defect> m_acceptors;
188
189 // Available data.
190 bool m_hasPotential = false;
191 bool m_hasField = false;
192 bool m_hasElectronMobility = false;
193 bool m_hasHoleMobility = false;
194 bool m_hasElectronVelocity = false;
195 bool m_hasHoleVelocity = false;
196 bool m_hasElectronLifetime = false;
197 bool m_hasHoleLifetime = false;
198
199 // Are all the cross-sections and concentrations valid and set.
200 bool m_validTraps = false;
201
202 // Voltage range
203 double m_pMin = 0.;
204 double m_pMax = 0.;
205
206 // Bounding box
207 bool m_hasRangeZ = false;
208 double m_xMinBB, m_yMinBB, m_zMinBB;
209 double m_xMaxBB, m_yMaxBB, m_zMaxBB;
210
211 // Element from the previous call
212 int m_lastElement = 0;
213
214 void Reset() override;
215 void UpdatePeriodicity() override;
216 unsigned int FindElement(const double x, const double y,
217 std::array<double, nMaxVertices>& w) const;
218 // Check whether a point is inside a given element and calculate the
219 // shape functions if it is.
220 bool CheckElement(const double x, const double y, const Element& element,
221 std::array<double, nMaxVertices>& w) const;
222 bool CheckRectangle(const double x, const double y, const Element& element,
223 std::array<double, nMaxVertices>& w) const;
224 bool CheckTriangle(const double x, const double y, const Element& element,
225 std::array<double, nMaxVertices>& w) const;
226 bool CheckLine(const double x, const double y, const Element& element,
227 std::array<double, nMaxVertices>& w) const;
228
229 bool LoadGrid(const std::string& gridfilename);
230 bool LoadData(const std::string& datafilename);
231 bool ReadDataset(std::ifstream& datafile, const std::string& dataset);
232 bool LoadWeightingField(const std::string& datafilename,
233 std::vector<std::array<double, 2> >& wf,
234 std::vector<double>& wp);
235 void FindNeighbours();
236 void Cleanup();
237
238 int FindRegion(const std::string& name) const;
239
240 void MapCoordinates(double& x, double& y, bool& xmirr, bool& ymirr) const;
241 bool InsideBoundingBox(const double x, const double y,
242 const double z) const {
243 bool inside = true;
244 if (x < m_xMinBB || x > m_xMaxBB || y < m_yMinBB || y > m_yMaxBB ||
245 (m_hasRangeZ && (z < m_zMinBB || z > m_zMaxBB))) {
246 inside = false;
247 }
248 return inside;
249 }
250 bool CheckTraps() const;
251};
252}
253#endif
Abstract base class for components.
Interpolation in a two-dimensional field map created by Sentaurus Device.
unsigned int GetNumberOfElements() const
bool SetWeightingField(const std::string &datfile1, const std::string &datfile2, const double dv)
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the bounding box coordinates.
bool GetDonorOccupation(const double x, const double y, const double z, const unsigned int donorNumber, double &occupationFraction)
bool GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
void GetRegion(const unsigned int i, std::string &name, bool &active) const
bool GetNode(const unsigned int i, double &x, double &y, double &v, double &ex, double &ey) const
bool SetDonor(const unsigned int donorNumber, const double eXsec, const double hxSec, const double concentration)
bool Initialise(const std::string &gridfilename, const std::string &datafilename)
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
unsigned int GetNumberOfNodes() const
void SetRangeZ(const double zmin, const double zmax)
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status) override
void PrintRegions() const
List all currently defined regions.
bool GetHoleLifetime(const double x, const double y, const double z, double &htau) override
bool HoleAttachment(const double x, const double y, const double z, double &eta) override
Get the hole attachment coefficient.
Medium * GetMedium(const double x, const double y, const double z) override
Get the medium at a given location (x, y, z).
bool GetAcceptorOccupation(const double x, const double y, const double z, const unsigned int acceptorNumber, double &occupationFraction)
unsigned int GetNumberOfRegions() const
Get the number of regions in the device.
void HoleVelocity(const double x, const double y, const double z, double &vx, double &vy, double &vz, Medium *&m, int &status) override
Get the hole drift velocity.
bool GetElement(const unsigned int i, double &vol, double &dmin, double &dmax, int &type) const
void UnsetDriftRegion(const unsigned int ireg)
bool GetElectronLifetime(const double x, const double y, const double z, double &etau) override
bool ElectronAttachment(const double x, const double y, const double z, double &eta) override
Get the electron attachment coefficient.
void SetMedium(const unsigned int ireg, Medium *m)
Set the medium for a given region.
double WeightingPotential(const double x, const double y, const double z, const std::string &label) override
void SetDriftRegion(const unsigned int ireg)
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).
bool GetMobility(const double x, const double y, const double z, double &emob, double &hmob)
void ElectronVelocity(const double x, const double y, const double z, double &vx, double &vy, double &vz, Medium *&m, int &status) override
Get the electron drift velocity.
bool SetAcceptor(const unsigned int acceptorNumber, const double eXsec, const double hxSec, const double concentration)
Abstract base class for media.
Definition: Medium.hh:13