Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ComponentTcadBase.hh
Go to the documentation of this file.
1#ifndef G_COMPONENT_TCAD_BASE_H
2#define G_COMPONENT_TCAD_BASE_H
3
4#include <algorithm>
5#include <array>
6
7#include "Component.hh"
8
9namespace Garfield {
10
11/// Interpolation in a field map created by Sentaurus Device.
12
13template<size_t N>
15 public:
16 /// Default constructor
18 /// Constructor
19 ComponentTcadBase(const std::string& name) : Component(name) {
20 m_regions.reserve(10);
21 m_vertices.reserve(10000);
22 m_elements.reserve(10000);
23 }
24 /// Destructor
25 virtual ~ComponentTcadBase() {}
26
27 void WeightingField(const double x, const double y, const double z,
28 double& wx, double& wy, double& wz,
29 const std::string& label) override;
30 double WeightingPotential(const double x, const double y, const double z,
31 const std::string& label) override;
32
33 bool GetVoltageRange(double& vmin, double& vmax) override;
34
35 /** Import mesh and field map from files.
36 * \param gridfilename name of the .grd file containing the mesh
37 * \param datafilename name of the .dat file containing the nodal solution
38 */
39 bool Initialise(const std::string& gridfilename,
40 const std::string& datafilename);
41
42 /** Import field maps defining the weighting field and potential.
43 * \param datfile1 .dat file containing the field map at nominal bias.
44 * \param datfile2 .dat file containing the field map for a configuration
45 with the potential at the electrode to be read out
46 increased by a small voltage dv.
47 * \param dv increase in electrode potential between the two field maps.
48 * \param label name of the electrode
49 *
50 * The field maps must use the same mesh as the drift field.
51 */
52 bool SetWeightingField(const std::string& datfile1,
53 const std::string& datfile2, const double dv,
54 const std::string& label);
55 /// Shift the maps of weighting field/potential for a given electrode
56 /// with respect to the original mesh. If the electrode does not exist
57 /// yet, a new one will be added to the list.
58 bool SetWeightingFieldShift(const std::string& label,
59 const double x, const double y, const double z);
60
61 /// List all currently defined regions.
62 void PrintRegions() const;
63 /// Get the number of regions in the device.
64 size_t GetNumberOfRegions() const { return m_regions.size(); }
65 /// Get the name and "active volume" flag of a region.
66 void GetRegion(const size_t ireg, std::string& name, bool& active) const;
67 /// Make a region active ("driftable").
68 void SetDriftRegion(const size_t ireg);
69 /// Make a region inactive.
70 void UnsetDriftRegion(const size_t ireg);
71 /// Set the medium to be associated to a given region.
72 void SetMedium(const size_t ireg, Medium* m);
73
74 /// Get the number of elements in the mesh.
75 size_t GetNumberOfElements() const { return m_elements.size(); }
76 /// Get the number of vertices in the mesh.
77 size_t GetNumberOfNodes() const { return m_vertices.size(); }
78
79 /// Switch use of the imported velocity map on/off.
80 void EnableVelocityMap(const bool on);
81 bool HasVelocityMap() const override {
82 return m_useVelocityMap && !(m_eVelocity.empty() && m_hVelocity.empty());
83 }
84 bool ElectronVelocity(const double x, const double y, const double z,
85 double& vx, double& vy, double& vz) override;
86 bool HoleVelocity(const double x, const double y, const double z,
87 double& vx, double& vy, double& vz) override;
88
89 /// Get the number of donor states found in the map.
90 size_t GetNumberOfDonors() { return m_donors.size(); }
91 /// Get the number of acceptor states found in the map.
92 size_t GetNumberOfAcceptors() { return m_acceptors.size(); }
93
94 /** Set the properties of a donor-type defect state.
95 * \param donorNumber index of the donor
96 * \param exsec cross-section [cm2] for electrons
97 * \param hxsec cross-section [cm2] for holes
98 * \param concentration defect density [cm-3]
99 */
100 bool SetDonor(const size_t donorNumber, const double exsec,
101 const double hxsec, const double concentration);
102 /// Set the properties of an acceptor-type defect state.
103 bool SetAcceptor(const size_t acceptorNumber, const double exsec,
104 const double hxsec, const double concentration);
105
106 /// Switch use of the imported trapping map on/off.
107 void EnableAttachmentMap(const bool on) { m_useAttachmentMap = on; }
108 bool HasAttachmentMap() const override {
109 return (m_useAttachmentMap && !(m_acceptors.empty() && m_donors.empty()));
110 }
111 bool ElectronAttachment(const double x, const double y, const double z,
112 double& eta) override;
113 bool HoleAttachment(const double x, const double y, const double z,
114 double& eta) override;
115
116 bool GetElectronLifetime(const double x, const double y, const double z,
117 double& etau) override;
118 bool GetHoleLifetime(const double x, const double y, const double z,
119 double& htau) override;
120
121 // Mobilities
122 bool GetElectronMobility(const double x, const double y, const double z,
123 double& mob);
124 bool GetHoleMobility(const double x, const double y, const double z,
125 double& mob);
126 protected:
127 // Max. number of vertices per element
128 static constexpr size_t nMaxVertices = 4;
129
130 // Regions
131 struct Region {
132 // Name of region (from Tcad)
133 std::string name;
134 // Flag indicating if the region is active (i. e. a drift medium)
135 bool drift;
137 };
138 std::vector<Region> m_regions;
139
140 // Vertex coordinates [cm].
141 std::vector<std::array<double, N> > m_vertices;
142
143 // Elements
144 struct Element {
145 // Indices of vertices
146 unsigned int vertex[nMaxVertices];
147 // Type of element
148 // 0: Point
149 // 1: Segment (line)
150 // 2: Triangle
151 // 3: Rectangle
152 // 4: Polygon
153 // 5: Tetrahedron
154 // 6: Pyramid
155 // 7: Prism
156 // 8: Brick
157 // 9: Tetrabrick
158 // 10: Polyhedron
159 // In 2D, types 1 - 3 are supported.
160 // In 3D, only types 2 and 5 are supported.
161 unsigned int type;
162 // Associated region
163 unsigned int region;
164 // Bounding box
165 std::array<float, N> bbMin;
166 std::array<float, N> bbMax;
167 };
168 std::vector<Element> m_elements;
169
170 // Potential [V] at each vertex.
171 std::vector<double> m_epot;
172 // Electric field [V / cm].
173 std::vector<std::array<double, N> > m_efield;
174
175 // Weighting field and potential at each vertex.
176 std::vector<std::array<double, N> > m_wfield;
177 std::vector<double> m_wpot;
178 // Weighting field labels and offsets.
179 std::vector<std::string> m_wlabel;
180 std::vector<std::array<double, 3> > m_wshift;
181
182 // Velocities [cm / ns]
183 std::vector<std::array<double, N> > m_eVelocity;
184 std::vector<std::array<double, N> > m_hVelocity;
185 // Mobilities [cm2 / (V ns)]
186 std::vector<double> m_eMobility;
187 std::vector<double> m_hMobility;
188 // Lifetimes [ns]
189 std::vector<double> m_eLifetime;
190 std::vector<double> m_hLifetime;
191 // Trap occupations [dimensionless]
192 std::vector<std::vector<float> > m_donorOcc;
193 std::vector<std::vector<float> > m_acceptorOcc;
194 // Attachment coefficients [1 / cm]
195 std::vector<double> m_eAttachment;
196 std::vector<double> m_hAttachment;
197
198 struct Defect {
199 // Electron cross-section
200 double xsece;
201 // Hole cross-section
202 double xsech;
203 // Concentration
204 double conc;
205 };
206 std::vector<Defect> m_donors;
207 std::vector<Defect> m_acceptors;
208
209 // Use velocity map or not.
210 bool m_useVelocityMap = false;
211 // Use trapping map or not.
212 bool m_useAttachmentMap = false;
213
214 // Bounding box.
215 std::array<double, 3> m_bbMin = {{0., 0., 0.}};
216 std::array<double, 3> m_bbMax = {{0., 0., 0.}};
217
218 // Voltage range
219 double m_pMin = 0.;
220 double m_pMax = 0.;
221
222 void UpdatePeriodicity() override;
223
224 void Cleanup();
225
226 static unsigned int ElementVertices(const Element& element) {
227 return std::min(element.type + 1, 4U);
228 }
229 virtual bool Interpolate(const double x, const double y, const double z,
230 const std::vector<double>& field, double& f) = 0;
231 virtual bool Interpolate(const double x, const double y, const double z,
232 const std::vector<std::array<double, N> >& field,
233 double& fx, double& fy, double& fz) = 0;
234 virtual void FillTree() = 0;
235
236 size_t FindRegion(const std::string& name) const;
237 void MapCoordinates(std::array<double, N>& x,
238 std::array<bool, N>& mirr) const;
239 bool InBoundingBox(const std::array<double, N>& x) const {
240 for (size_t i = 0; i < N; ++i) {
241 if (x[i] < m_bbMin[i] || x[i] > m_bbMax[i]) return false;
242 }
243 return true;
244 }
245 void UpdateAttachment();
246
247 bool LoadGrid(const std::string& gridfilename);
248 bool LoadData(const std::string& datafilename);
249 bool ReadDataset(std::ifstream& datafile, const std::string& dataset);
250 bool LoadWeightingField(const std::string& datafilename,
251 std::vector<std::array<double, N> >& wf,
252 std::vector<double>& wp);
253};
254}
255#endif
Interpolation in a field map created by Sentaurus Device.
bool GetElectronLifetime(const double x, const double y, const double z, double &etau) override
bool InBoundingBox(const std::array< double, N > &x) const
std::vector< double > m_hMobility
bool LoadGrid(const std::string &gridfilename)
void GetRegion(const size_t ireg, std::string &name, bool &active) const
Get the name and "active volume" flag of a region.
void UnsetDriftRegion(const size_t ireg)
Make a region inactive.
ComponentTcadBase(const std::string &name)
Constructor.
std::vector< Defect > m_acceptors
virtual void FillTree()=0
std::vector< std::vector< float > > m_acceptorOcc
double WeightingPotential(const double x, const double y, const double z, const std::string &label) override
std::vector< std::string > m_wlabel
size_t FindRegion(const std::string &name) const
std::vector< std::array< double, 3 > > m_wshift
virtual bool Interpolate(const double x, const double y, const double z, const std::vector< double > &field, double &f)=0
bool GetElectronMobility(const double x, const double y, const double z, double &mob)
bool HasVelocityMap() const override
Does the component have velocity maps?
std::vector< std::vector< float > > m_donorOcc
std::vector< std::array< double, N > > m_vertices
bool GetHoleMobility(const double x, const double y, const double z, double &mob)
bool SetWeightingField(const std::string &datfile1, const std::string &datfile2, const double dv, const std::string &label)
std::vector< Element > m_elements
void EnableVelocityMap(const bool on)
Switch use of the imported velocity map on/off.
bool GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
bool HoleAttachment(const double x, const double y, const double z, double &eta) override
Get the hole attachment coefficient.
std::vector< double > m_eAttachment
std::vector< Region > m_regions
bool LoadWeightingField(const std::string &datafilename, std::vector< std::array< double, N > > &wf, std::vector< double > &wp)
std::vector< std::array< double, N > > m_hVelocity
static unsigned int ElementVertices(const Element &element)
std::array< double, 3 > m_bbMax
bool ReadDataset(std::ifstream &datafile, const std::string &dataset)
size_t GetNumberOfNodes() const
Get the number of vertices in the mesh.
static constexpr size_t nMaxVertices
size_t GetNumberOfRegions() const
Get the number of regions in the device.
std::vector< double > m_epot
bool LoadData(const std::string &datafilename)
std::vector< std::array< double, N > > m_efield
std::vector< std::array< double, N > > m_eVelocity
std::vector< double > m_hLifetime
size_t GetNumberOfDonors()
Get the number of donor states found in the map.
bool GetHoleLifetime(const double x, const double y, const double z, double &htau) override
void MapCoordinates(std::array< double, N > &x, std::array< bool, N > &mirr) const
void PrintRegions() const
List all currently defined regions.
std::vector< double > m_wpot
void EnableAttachmentMap(const bool on)
Switch use of the imported trapping map on/off.
virtual bool Interpolate(const double x, const double y, const double z, const std::vector< std::array< double, N > > &field, double &fx, double &fy, double &fz)=0
bool SetAcceptor(const size_t acceptorNumber, const double exsec, const double hxsec, const double concentration)
Set the properties of an acceptor-type defect state.
ComponentTcadBase()=delete
Default constructor.
bool ElectronAttachment(const double x, const double y, const double z, double &eta) override
Get the electron attachment coefficient.
std::vector< Defect > m_donors
size_t GetNumberOfElements() const
Get the number of elements in the mesh.
size_t GetNumberOfAcceptors()
Get the number of acceptor states found in the map.
bool HasAttachmentMap() const override
Does the component have attachment maps?
bool SetWeightingFieldShift(const std::string &label, const double x, const double y, const double z)
bool Initialise(const std::string &gridfilename, const std::string &datafilename)
std::vector< double > m_eMobility
virtual ~ComponentTcadBase()
Destructor.
void UpdatePeriodicity() override
Verify periodicities.
bool ElectronVelocity(const double x, const double y, const double z, double &vx, double &vy, double &vz) override
Get the electron drift velocity.
void SetDriftRegion(const size_t ireg)
Make a region active ("driftable").
bool HoleVelocity(const double x, const double y, const double z, double &vx, double &vy, double &vz) override
Get the hole drift velocity.
std::vector< std::array< double, N > > m_wfield
bool SetDonor(const size_t donorNumber, const double exsec, const double hxsec, const double concentration)
void SetMedium(const size_t ireg, Medium *m)
Set the medium to be associated to a given region.
void WeightingField(const double x, const double y, const double z, double &wx, double &wy, double &wz, const std::string &label) override
std::vector< double > m_hAttachment
std::array< double, 3 > m_bbMin
std::vector< double > m_eLifetime
Abstract base class for components.
Definition: Component.hh:13
Abstract base class for media.
Definition: Medium.hh:13