Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ComponentNeBem2d.hh
Go to the documentation of this file.
1// Two-dimensional implementation of nearly exact Boundary Element Method
2
3#ifndef G_COMPONENT_NEBEM_2D_H
4#define G_COMPONENT_NEBEM_2D_H
5
6#include "ComponentBase.hh"
7
8namespace Garfield {
9
11
12 public:
13 // Constructor
16
17 // Calculate the drift field [V/cm] at (x, y, z)
18 void ElectricField(const double x, const double y, const double z, double& ex,
19 double& ey, double& ez, Medium*& m, int& status);
20 // Calculate the drift field [V/cm] and potential [V] at (x, y, z)
21 void ElectricField(const double x, const double y, const double z, double& ex,
22 double& ey, double& ez, double& v, Medium*& m,
23 int& status);
24 // Calculate the voltage range [V]
25 bool GetVoltageRange(double& vmin, double& vmax);
26
27 void SetProjectionX() { projAxis = 0; }
28 void SetProjectionY() { projAxis = 1; }
29 void SetProjectionZ() { projAxis = 2; }
30
31 void AddPanel(const double x0, const double y0, const double x1,
32 const double y1, const int bctype, const double bcval,
33 const double lambda);
34 void AddWire(const double x0, const double y0, const double d,
35 const double bcval);
36
37 void SetNumberOfDivisions(const int ndiv);
38 void SetNumberOfCollocationPoints(const int ncoll);
39 void SetMinimumElementSize(const double min);
40 void EnableAutoResizing() { autoSize = true; }
41 void DisableAutoResizing() { autoSize = false; }
42 void EnableRandomCollocation() { randomCollocation = true; }
43 void DisableRandomCollocation() { randomCollocation = false; }
44 void SetMaxNumberOfIterations(const int niter);
45
46 int GetNumberOfPanels() { return nPanels; }
47 int GetNumberOfWires() { return nWires; }
48 int GetNumberOfElements() { return nElements; }
49
50 private:
51 static const int Local2Global = -1;
52 static const int Global2Local = 1;
53
54 // Influence matrix
55 std::vector<std::vector<double> > influenceMatrix;
56 // Inverse of the influence matrix
57 std::vector<std::vector<double> > inverseMatrix;
58 // Right hand side vector (boundary conditions)
59 std::vector<double> boundaryConditions;
60 // Temporary arrays used during LU decomposition
61 std::vector<double> col;
62 std::vector<int> index;
63
64 int projAxis;
65 int nDivisions;
66 int nCollocationPoints;
67 double minSize;
68 bool autoSize;
69 bool randomCollocation;
70 int nMaxIterations;
71
72 int nPanels;
73 struct panel {
74 // Coordinates of boundary points
75 double x0, y0;
76 double x1, y1;
77 // Boundary condition type and value
78 // 0: conductor (fixed potential), 1: conductor (floating),
79 // 2: DD interface, 3: known charge density
80 int bcType;
81 double bcValue;
82 // Ratio of relative dielectric permittivities
83 double lambda;
84 };
85 std::vector<panel> panels;
86
87 int nWires;
88 struct wire {
89 // Center point
90 double cX, cY;
91 // Diameter
92 double d;
93 // Boundary condition
94 double bcValue;
95 };
96 std::vector<wire> wires;
97
98 int nElements;
99 // Array of boundary elements
100 struct element {
101 // Geometric type
102 // 0: line, 1: (thin) wire
103 int geoType;
104 // Center point
105 double cX, cY;
106 // Half length
107 double len;
108 // Rotation angle
109 double phi;
110 // Charge density
111 double solution;
112 // Boundary condition type and value
113 int bcType;
114 double bcValue;
115 // Ratio of relative dielectric permittivities
116 double lambda;
117 };
118 std::vector<element> elements;
119
120 bool matrixInversionFlag;
121
122 bool Initialise();
123 bool Discretise();
124 bool ComputeInfluenceMatrix();
125 void SplitElement(const int iel);
126 bool InvertMatrix();
127 bool LUDecomposition();
128 void LUSubstitution();
129 bool GetBoundaryConditions();
130 bool Solve();
131 bool CheckConvergence();
132
133 void Rotate(const double xIn, const double yIn, const double phi,
134 const int opt, double& xOut, double& yOut);
135
136 // Compute the potential
137 bool ComputePotential(const int gt, const double len, const double x,
138 const double y, double& p) {
139
140 switch (gt) {
141 case 0:
142 p = LinePotential(len, x, y);
143 break;
144 case 1:
145 p = WirePotential(len, x, y);
146 break;
147 default:
148 return false;
149 }
150 return true;
151 }
152
153 // Compute the field
154 bool ComputeFlux(const int gt, const double len, const double rot,
155 const double x, const double y, double& ex, double& ey) {
156
157 double fx, fy;
158 switch (gt) {
159 case 0:
160 LineFlux(len, x, y, fx, fy);
161 break;
162 case 1:
163 WireFlux(len, x, y, fx, fy);
164 break;
165 default:
166 return false;
167 }
168 // Transformation to global coordinate system
169 Rotate(fx, fy, rot, Local2Global, ex, ey);
170 return true;
171 }
172
173 double LinePotential(const double a, const double x, const double y);
174 double WirePotential(const double r0, const double x, const double y);
175 void LineFlux(const double a, const double x, const double y, double& ex,
176 double& ey);
177 void WireFlux(const double r0, const double x, const double y, double& ex,
178 double& ey);
179
180 void Reset();
181 void UpdatePeriodicity();
182};
183}
184
185#endif
void SetNumberOfDivisions(const int ndiv)
void SetMaxNumberOfIterations(const int niter)
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status)
void AddWire(const double x0, const double y0, const double d, const double bcval)
void SetNumberOfCollocationPoints(const int ncoll)
void AddPanel(const double x0, const double y0, const double x1, const double y1, const int bctype, const double bcval, const double lambda)
bool GetVoltageRange(double &vmin, double &vmax)
void SetMinimumElementSize(const double min)