Garfield++ v2r0
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 "ComponentBase.hh"
5
6namespace Garfield {
7
8/// Interpolation in a three-dimensional field map created by Sentaurus Device.
9
11
12 public:
13 // Constructor
15 // Destructor
17
18 void ElectricField(const double x, const double y, const double z, double& ex,
19 double& ey, double& ez, double& v, Medium*& m,
20 int& status);
21 void ElectricField(const double x, const double y, const double z, double& ex,
22 double& ey, double& ez, Medium*& m, int& status);
23
24 Medium* GetMedium(const double x, const double y, const double z);
25
26 bool GetVoltageRange(double& vmin, double& vmax);
27 bool GetBoundingBox(double& xmin, double& ymin, double& zmin, double& xmax,
28 double& ymax, double& zmax);
29
30 // Import mesh and field map from files.
31 bool Initialise(const std::string& gridfilename,
32 const std::string& datafilename);
33
34 // List all currently defined regions.
35 void PrintRegions();
36 // Get the number of regions in the device.
37 unsigned int GetNumberOfRegions() const { return m_regions.size(); }
38 void GetRegion(const unsigned int ireg, std::string& name,
39 bool& active) const;
40 void SetDriftRegion(const unsigned int ireg);
41 void UnsetDriftRegion(const unsigned int ireg);
42 // Set/get the medium for a given region
43 void SetMedium(const unsigned int ireg, Medium* m);
44 bool GetMedium(const unsigned int ireg, Medium*& m) const;
45
46 int GetNumberOfElements() const { return m_elements.size(); }
47 bool GetElement(const unsigned int i, double& vol, double& dmin, double& dmax,
48 int& type) const;
49 bool GetElement(const unsigned int i, double& vol, double& dmin, double& dmax,
50 int& type, int& node1, int& node2, int& node3, int& node4,
51 int& node5, int& node6, int& node7, int& reg) const;
52 unsigned int GetNumberOfNodes() const { return m_vertices.size(); }
53 bool GetNode(const unsigned int i, double& x, double& y, double& z, double& v,
54 double& ex, double& ey, double& ez) const;
55
56 private:
57 // Max. number of vertices per element
58 static const int nMaxVertices = 7;
59
60 // Regions
61 struct Region {
62 // Name of region (from Tcad)
63 std::string name;
64 // Flag indicating if the region is active (i. e. a drift medium)
65 bool drift;
66 Medium* medium;
67 };
68 std::vector<Region> m_regions;
69
70 // Vertices
71 struct Vertex {
72 // Coordinates [cm]
73 double x, y, z;
74 // Potential [V] and electric field [V / cm]
75 double p, ex, ey, ez;
76 };
77 std::vector<Vertex> m_vertices;
78
79 // Elements
80 struct Element {
81 // Indices of vertices
82 int vertex[nMaxVertices];
83 // Type of element
84 // 1: Segment (line)
85 // 2: Triangle
86 // 3: Rectangle
87 // 4: Polygon
88 // 5: Tetrahedron
89 // 6: Pyramid
90 // 7: Prism
91 // 8: Brick
92 // 9: Tetrabrick
93 // 10: Polyhedron
94 // Only types 2 and 5 are supported by this class.
95 int type;
96 // Associated region
97 int region;
98 std::vector<int> neighbours;
99 // Bounding box
100 double xmin, xmax;
101 double ymin, ymax;
102 double zmin, zmax;
103 };
104 std::vector<Element> m_elements;
105
106 // Face
107 struct Face {
108 // Indices of edges
109 int edge[4];
110 int type;
111 };
112
113 // Voltage range
114 double m_pMin, m_pMax;
115
116 // Bounding box
117 double m_xMinBB, m_yMinBB, m_zMinBB;
118 double m_xMaxBB, m_yMaxBB, m_zMaxBB;
119
120 // Element from the previous call
121 int m_lastElement;
122
123 // Reset the component
124 void Reset();
125 // Periodicities
126 void UpdatePeriodicity();
127
128 bool CheckElement(const double x, const double y, const double z,
129 const Element& element, double w[nMaxVertices]) const {
130
131 bool inside = false;
132 switch (element.type) {
133 case 2:
134 if (CheckTriangle(x, y, z, element, w)) inside = true;
135 break;
136 case 5:
137 if (CheckTetrahedron(x, y, z, element, w)) inside = true;
138 break;
139 default:
140 std::cerr << m_className << "::CheckElement:\n"
141 << " Invalid element type (" << element.type << ").\n";
142 break;
143 }
144 return inside;
145 }
146 bool CheckTetrahedron(const double x, const double y, const double z,
147 const Element& element, double w[nMaxVertices]) const;
148 bool CheckTriangle(const double x, const double y, const double z,
149 const Element& element, double w[nMaxVertices]) const;
150
151 void FindNeighbours();
152 bool LoadGrid(const std::string& gridfilename);
153 bool LoadData(const std::string& datafilename);
154 bool ReadDataset(std::ifstream& datafile, const std::string& dataset);
155 void Cleanup();
156
157 void MapCoordinates(double& x, double& y, double& z,
158 bool& xmirr, bool& ymirr, bool& zmirr) const;
159 int FindRegion(const std::string& name) const;
160};
161}
162#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 UnsetDriftRegion(const unsigned int ireg)
void GetRegion(const unsigned int ireg, std::string &name, bool &active) const
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax)
Get the bounding box coordinates.
bool GetNode(const unsigned int i, double &x, double &y, double &z, double &v, double &ex, double &ey, double &ez) const
Medium * GetMedium(const double x, const double y, const double z)
Get the medium at a given location (x, y, z).
void SetDriftRegion(const unsigned int ireg)
bool GetVoltageRange(double &vmin, double &vmax)
Calculate the voltage range [V].
unsigned int GetNumberOfRegions() const
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, double &v, Medium *&m, int &status)
bool GetElement(const unsigned int i, double &vol, double &dmin, double &dmax, int &type) const
void SetMedium(const unsigned int ireg, Medium *m)
Abstract base class for media.
Definition: Medium.hh:11