Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ComponentNeBem3d.hh
Go to the documentation of this file.
1#ifndef G_COMPONENT_NEBEM_3D_H
2#define G_COMPONENT_NEBEM_3D_H
3#include "ComponentBase.hh"
4
5namespace Garfield {
6
7/// Interface to neBEM.
8
10 public:
11 /// Constructor
13 /// Destructor
15
16 void ElectricField(const double x, const double y, const double z, double& ex,
17 double& ey, double& ez, Medium*& m, int& status) override;
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) override;
21 bool GetVoltageRange(double& vmin, double& vmax) override;
22
23 unsigned int GetNumberOfPrimitives() const { return m_primitives.size(); }
24 bool GetPrimitive(const unsigned int i, double& a, double& b, double& c,
25 std::vector<double>& xv, std::vector<double>& yv,
26 std::vector<double>& zv, int& interface, double& v,
27 double& q, double& lambda) const;
28 unsigned int GetNumberOfElements() const { return m_elements.size(); }
29 bool GetElement(const unsigned int i,
30 std::vector<double>& xv, std::vector<double>& yv,
31 std::vector<double>& zv, int& interface, double& bc,
32 double& lambda) const;
33
34 void Reset() override;
35 void UpdatePeriodicity() override;
36
37 /// Retrieve surface panels, remove contacts and cut polygons to rectangles
38 /// and right-angle triangles.
39 bool Initialise();
40
41 /// Set the default value of the target linear size of the elements
42 /// produced by neBEM's discretisation process.
43 void SetTargetElementSize(const double length);
44
45 private:
46 struct Primitive {
47 /// Perpendicular vector
48 double a, b, c;
49 /// X-coordinates of vertices
50 std::vector<double> xv;
51 /// Y-coordinates of vertices
52 std::vector<double> yv;
53 /// Z-coordinates of vertices
54 std::vector<double> zv;
55 /// Interface type.
56 int interface;
57 /// Potential
58 double v;
59 /// Charge
60 double q;
61 /// Ratio of dielectric constants
62 double lambda;
63 /// Target element size.
64 double elementSize;
65 };
66 /// List of primitives.
67 std::vector<Primitive> m_primitives;
68
69 struct Element {
70 /// Local origin.
71 std::array<double, 3> origin;
72 double lx;
73 double lz;
74 /// Area.
75 double dA;
76 /// Direction cosines.
77 std::array<std::array<double, 3>, 3> dcos;
78 /// X-coordinates of vertices
79 std::vector<double> xv;
80 /// Y-coordinates of vertices
81 std::vector<double> yv;
82 /// Z-coordinates of vertices
83 std::vector<double> zv;
84 /// Interface type.
85 int interface;
86 /// Ratio of dielectric permittivities.
87 double lambda;
88 /// Collocation point.
89 std::array<double, 3> collocationPoint;
90 /// Boundary condition.
91 double bc;
92 /// Fixed charge density.
93 double assigned;
94 /// Solution (accumulated charge).
95 double solution;
96 };
97 /// List of elements.
98 std::vector<Element> m_elements;
99
100 static constexpr double MinDist = 1.e-6;
101 /// Target size of elements [cm].
102 double m_targetElementSize = 50.0e-4;
103 /// Smallest number of elements produced along the axis of a primitive.
104 unsigned int m_minNbElementsOnLength = 1;
105 /// Largest number of elements produced along the axis of a primitive.
106 unsigned int m_maxNbElementsOnLength = 100;
107
108 /// Isolate the parts of polygon 1 that are not hidden by 2 and vice versa.
109 bool EliminateOverlaps(const Panel& panel1, const Panel& panel2,
110 std::vector<Panel>& panelsOut,
111 std::vector<int>& itypo);
112
113 bool TraceEnclosed(const std::vector<double>& xl1,
114 const std::vector<double>& yl1,
115 const std::vector<double>& xl2,
116 const std::vector<double>& yl2, const Panel& originalPanel,
117 std::vector<Panel>& newPanels) const;
118
119 void TraceNonOverlap(
120 const std::vector<double>& xp1, const std::vector<double>& yp1,
121 const std::vector<double>& xl1, const std::vector<double>& yl1,
122 const std::vector<double>& xl2, const std::vector<double>& yl2,
123 const std::vector<int>& flags1, const std::vector<int>& flags2,
124 const std::vector<int>& links1, const std::vector<int>& links2,
125 std::vector<bool>& mark1, int ip1, const Panel& originalPanel,
126 std::vector<Panel>& newPanels) const;
127
128 void TraceOverlap(
129 const std::vector<double>& xp1, const std::vector<double>& yp1,
130 const std::vector<double>& xp2, const std::vector<double>& yp2,
131 const std::vector<double>& xl1, const std::vector<double>& yl1,
132 const std::vector<double>& xl2, const std::vector<double>& yl2,
133 const std::vector<int>& flags1, const std::vector<int>& links1,
134 const std::vector<int>& links2, std::vector<bool>& mark1, int ip1,
135 int ip2, const Panel& originalPanel, std::vector<Panel>& newPanels) const;
136
137 /// Split a polygon into rectangles and right-angled triangles.
138 bool MakePrimitives(const Panel& panelIn,
139 std::vector<Panel>& panelsOut) const;
140
141 /// Check whether a polygon contains parallel lines.
142 /// If it does, split it in rectangular and non-rectangular parts.
143 bool SplitTrapezium(const Panel panelIn, std::vector<Panel>& stack,
144 std::vector<Panel>& panelsOut, const double epsang) const;
145
146 unsigned int NbOfSegments(const double length, const double target) const;
147 bool DiscretizeWire(const Primitive& primitive, const double targetSize,
148 std::vector<Element>& elements) const;
149 bool DiscretizeTriangle(const Primitive& primitive, const double targetSize,
150 std::vector<Element>& elements) const;
151 bool DiscretizeRectangle(const Primitive& prim, const double targetSize,
152 std::vector<Element>& elements) const;
153 int InterfaceType(const Solid::BoundaryCondition bc) const;
154};
155}
156
157#endif
Abstract base class for components.
unsigned int GetNumberOfPrimitives() const
void Reset() override
Reset the component.
void UpdatePeriodicity() override
Verify periodicities.
bool GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
bool GetElement(const unsigned int i, std::vector< double > &xv, std::vector< double > &yv, std::vector< double > &zv, int &interface, double &bc, double &lambda) const
void SetTargetElementSize(const double length)
bool GetPrimitive(const unsigned int i, double &a, double &b, double &c, std::vector< double > &xv, std::vector< double > &yv, std::vector< double > &zv, int &interface, double &v, double &q, double &lambda) const
unsigned int GetNumberOfElements() const
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status) override
Abstract base class for media.
Definition: Medium.hh:13