1#ifndef G_COMPONENT_NEBEM_2D_H
2#define G_COMPONENT_NEBEM_2D_H
17 Medium*
GetMedium(
const double x,
const double y,
const double z)
override;
19 void ElectricField(
const double x,
const double y,
const double z,
double& ex,
20 double& ey,
double& ez,
Medium*& m,
int& status)
override;
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)
override;
27 double& xmax,
double& ymax,
double& zmax)
override;
29 double& xmax,
double& ymax,
double& zmax)
override;
31 bool IsWireCrossed(
const double x0,
const double y0,
const double z0,
32 const double x1,
const double y1,
const double z1,
33 double& xc,
double& yc,
double& zc,
const bool centre,
35 bool IsInTrapRadius(
const double q0,
const double x0,
const double y0,
36 const double z0,
double& xw,
double& yx,
47 bool AddSegment(
const double x0,
const double y0,
const double x1,
48 const double y1,
const double v,
const int ndiv = -1);
56 bool AddWire(
const double x,
const double y,
const double d,
const double v,
65 bool AddRegion(
const std::vector<double>& xp,
66 const std::vector<double>& yp,
Medium* medium,
67 const unsigned int bctype = 4,
const double v = 0.,
70 const double a,
const double b,
73 void SetRangeZ(
const double zmin,
const double zmax);
84 m_randomCollocation = on;
92 std::vector<double>& xv, std::vector<double>& yv,
93 Medium*& medium,
unsigned int& bctype,
double& v);
97 bool GetSegment(
const unsigned int i,
double& x0,
double& y0,
98 double& x1,
double& x2,
double& v)
const;
102 bool GetWire(
const unsigned int i,
double& x,
double& y,
double& d,
103 double& v,
double& q)
const;
107 bool GetElement(
const unsigned int i,
double& x0,
double& y0,
108 double& x1,
double& y1,
double& q)
const;
110 static const double InvEpsilon0;
111 static const double InvTwoPiEpsilon0;
114 unsigned int m_nDivisions = 5;
115 unsigned int m_nCollocationPoints = 1;
116 bool m_autoSize =
false;
117 bool m_randomCollocation =
false;
118 unsigned int m_nMaxIterations = 3;
121 Medium* m_medium =
nullptr;
123 bool m_useRangeZ =
false;
136 std::vector<double> xv;
137 std::vector<double> yv;
139 std::pair<BC, double> bc;
144 std::vector<Region> m_regions;
147 std::array<double, 2> x0;
148 std::array<double, 2> x1;
151 std::pair<BC, double> bc;
155 std::vector<Segment> m_segments;
165 std::vector<Wire> m_wires;
173 std::pair<BC, double> bc;
177 std::vector<Element> m_elements;
185 std::vector<SpaceCharge> m_spaceCharge;
188 void EliminateOverlaps(std::vector<Segment>& segments);
190 bool Discretise(
const Segment& segment, std::vector<Element>& elements,
191 const double lambda,
const unsigned int ndiv);
193 bool ComputeInfluenceMatrix(std::vector<std::vector<double> >& infmat)
const;
194 bool InvertMatrix(std::vector<std::vector<double> >& influenceMatrix,
195 std::vector<std::vector<double> >& inverseMatrix)
const;
196 bool LUDecomposition(std::vector<std::vector<double> >& mat,
197 std::vector<int>& index)
const;
198 void LUSubstitution(
const std::vector<std::vector<double> >& mat,
199 const std::vector<int>& index,
200 std::vector<double>& col)
const;
202 bool Solve(
const std::vector<std::vector<double> >& inverseMatrix,
203 const std::vector<double>& bc);
204 bool CheckConvergence(
const double tol, std::vector<bool>& ok);
205 void SplitElement(
Element& oldElement, std::vector<Element>& elements);
208 double LinePotential(
const double a,
const double x,
const double y)
const;
210 double WirePotential(
const double r0,
const double x,
const double y)
const;
212 void LineField(
const double a,
const double x,
const double y,
double& ex,
215 void WireField(
const double r0,
const double x,
const double y,
double& ex,
219 double BoxPotential(
const double a,
const double b,
220 const double x,
const double y,
const double v0)
const;
222 void BoxField(
const double a,
const double b,
223 const double x,
const double y,
224 double& ex,
double& ey)
const;
226 void Reset()
override;
227 void UpdatePeriodicity()
override;
229 void ToLocal(
const double xIn,
const double yIn,
230 const double cphi,
const double sphi,
231 double& xOut,
double& yOut)
const;
233 void ToGlobal(
const double xIn,
const double yIn,
234 const double cphi,
const double sphi,
235 double& xOut,
double& yOut)
const;
238 int Field(
const double x,
const double y,
const double z,
double& ex,
239 double& ey,
double& ez,
double& v, Medium*& m,
const bool opt);
Two-dimensional implementation of the nearly exact Boundary Element Method.
unsigned int GetNumberOfSegments() const
Return the number of conducting straight-line segments.
void SetNumberOfDivisions(const unsigned int ndiv)
Set the default number of elements per segment.
bool AddSegment(const double x0, const double y0, const double x1, const double y1, const double v, const int ndiv=-1)
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status) override
bool GetVoltageRange(double &vmin, double &vmax) override
Calculate the voltage range [V].
bool GetSegment(const unsigned int i, double &x0, double &y0, double &x1, double &x2, double &v) const
Return the coordinates and voltage of a given straight-line segment.
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the bounding box coordinates.
void EnableRandomCollocation(const bool on=true)
void SetRangeZ(const double zmin, const double zmax)
Set the extent of the drift region along z.
void EnableAutoResizing(const bool on=true)
void SetNumberOfCollocationPoints(const unsigned int ncoll)
unsigned int GetNumberOfRegions() const
Return the number of regions.
bool IsWireCrossed(const double x0, const double y0, const double z0, const double x1, const double y1, const double z1, double &xc, double &yc, double &zc, const bool centre, double &rc) override
unsigned int GetNumberOfElements() const
Return the number of boundary elements.
bool Initialise()
Discretise the geometry and compute the solution.
bool GetRegion(const unsigned int i, std::vector< double > &xv, std::vector< double > &yv, Medium *&medium, unsigned int &bctype, double &v)
Return the properties of a given region.
void SetMedium(Medium *medium)
Set the "background" medium.
Medium * GetMedium(const double x, const double y, const double z) override
Get the medium at a given location (x, y, z).
void AddChargeDistribution(const double x, const double y, const double a, const double b, const double rho)
bool GetWire(const unsigned int i, double &x, double &y, double &d, double &v, double &q) const
Return the coordinates, diameter, potential and charge of a given wire.
~ComponentNeBem2d()
Destructor.
bool AddWire(const double x, const double y, const double d, const double v, const int ntrap=5)
ComponentNeBem2d()
Constructor.
void SetMaxNumberOfIterations(const unsigned int niter)
unsigned int GetNumberOfWires() const
Return the number of wires.
bool IsInTrapRadius(const double q0, const double x0, const double y0, const double z0, double &xw, double &yx, double &rw) override
bool AddRegion(const std::vector< double > &xp, const std::vector< double > &yp, Medium *medium, const unsigned int bctype=4, const double v=0., const int ndiv=-1)
bool GetElementaryCell(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
Get the coordinates of the elementary cell.
bool GetElement(const unsigned int i, double &x0, double &y0, double &x1, double &y1, double &q) const
Return the coordinates and charge of a given boundary element.
Abstract base class for components.
Abstract base class for media.