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 bool IsWireCrossed(
const double x0,
const double y0,
const double z0,
30 const double x1,
const double y1,
const double z1,
31 double& xc,
double& yc,
double& zc,
const bool centre,
33 bool IsInTrapRadius(
const double q0,
const double x0,
const double y0,
34 const double z0,
double& xw,
double& yx,
45 bool AddSegment(
const double x0,
const double y0,
const double x1,
46 const double y1,
const double v,
const int ndiv = -1);
54 bool AddWire(
const double x,
const double y,
const double d,
const double v,
63 bool AddRegion(
const std::vector<double>& xp,
64 const std::vector<double>& yp,
Medium* medium,
65 const unsigned int bctype = 4,
const double v = 0.,
68 void SetRangeZ(
const double zmin,
const double zmax);
79 m_randomCollocation = on;
87 std::vector<double>& xv, std::vector<double>& yv,
88 Medium*& medium,
unsigned int& bctype,
double& v);
92 bool GetSegment(
const unsigned int i,
double& x0,
double& y0,
93 double& x1,
double& x2,
double& v)
const;
97 bool GetWire(
const unsigned int i,
double& x,
double& y,
double& d,
98 double& v,
double& q)
const;
102 bool GetElement(
const unsigned int i,
double& x0,
double& y0,
103 double& x1,
double& y1,
double& q)
const;
105 static const double InvEpsilon0;
106 static const double InvTwoPiEpsilon0;
109 unsigned int m_nDivisions = 5;
110 unsigned int m_nCollocationPoints = 1;
111 bool m_autoSize =
false;
112 bool m_randomCollocation =
false;
113 unsigned int m_nMaxIterations = 3;
116 Medium* m_medium =
nullptr;
118 bool m_useRangeZ =
false;
131 std::vector<double> xv;
132 std::vector<double> yv;
134 std::pair<BC, double> bc;
139 std::vector<Region> m_regions;
142 std::array<double, 2> x0;
143 std::array<double, 2> x1;
146 std::pair<BC, double> bc;
150 std::vector<Segment> m_segments;
160 std::vector<Wire> m_wires;
168 std::pair<BC, double> bc;
172 std::vector<Element> m_elements;
175 void EliminateOverlaps(std::vector<Segment>& segments);
177 bool Discretise(
const Segment& segment, std::vector<Element>& elements,
178 const double lambda,
const unsigned int ndiv);
180 bool ComputeInfluenceMatrix(std::vector<std::vector<double> >& infmat)
const;
181 bool InvertMatrix(std::vector<std::vector<double> >& influenceMatrix,
182 std::vector<std::vector<double> >& inverseMatrix)
const;
183 bool LUDecomposition(std::vector<std::vector<double> >& mat,
184 std::vector<int>& index)
const;
185 void LUSubstitution(
const std::vector<std::vector<double> >& mat,
186 const std::vector<int>& index,
187 std::vector<double>& col)
const;
189 bool Solve(
const std::vector<std::vector<double> >& inverseMatrix,
190 const std::vector<double>& bc);
191 bool CheckConvergence(
const double tol, std::vector<bool>& ok);
192 void SplitElement(Element& oldElement, std::vector<Element>& elements);
195 double LinePotential(
const double a,
const double x,
const double y)
const;
197 double WirePotential(
const double r0,
const double x,
const double y)
const;
199 void LineFlux(
const double a,
const double x,
const double y,
double& ex,
202 void WireFlux(
const double r0,
const double x,
const double y,
double& ex,
205 void Reset()
override;
206 void UpdatePeriodicity()
override;
208 void ToLocal(
const double xIn,
const double yIn,
209 const double cphi,
const double sphi,
210 double& xOut,
double& yOut)
const;
212 void ToGlobal(
const double xIn,
const double yIn,
213 const double cphi,
const double sphi,
214 double& xOut,
double& yOut)
const;
Abstract base class for components.
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).
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 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 media.