1#ifndef G_COMPONENT_NEBEM_2D_H
2#define G_COMPONENT_NEBEM_2D_H
27 bool AddSegment(
const double x0,
const double y0,
const double x1,
28 const double y1,
const double v,
const int ndiv = -1);
36 bool AddWire(
const double x,
const double y,
const double d,
const double v,
45 bool AddRegion(
const std::vector<double>& xp,
const std::vector<double>& yp,
46 Medium* medium,
const unsigned int bctype = 4,
47 const double v = 0.,
const int ndiv = -1);
49 const double b,
const double rho);
51 void SetRangeZ(
const double zmin,
const double zmax);
69 bool GetRegion(
const unsigned int i, std::vector<double>& xv,
70 std::vector<double>& yv, Medium*& medium,
unsigned int& bctype,
75 bool GetSegment(
const unsigned int i,
double& x0,
double& y0,
double& x1,
76 double& x2,
double& v)
const;
80 bool GetWire(
const unsigned int i,
double& x,
double& y,
double& d,
double& v,
85 bool GetElement(
const unsigned int i,
double& x0,
double& y0,
double& x1,
86 double& y1,
double& q)
const;
88 Medium*
GetMedium(
const double x,
const double y,
const double z)
override;
90 void ElectricField(
const double x,
const double y,
const double z,
double& ex,
91 double& ey,
double& ez, Medium*& m,
int& status)
override;
92 void ElectricField(
const double x,
const double y,
const double z,
double& ex,
93 double& ey,
double& ez,
double& v, Medium*& m,
94 int& status)
override;
95 using Component::ElectricField;
99 double& ymax,
double& zmax)
override;
101 double& ymax,
double& zmax)
override;
103 bool CrossedWire(
const double x0,
const double y0,
const double z0,
104 const double x1,
const double y1,
const double z1,
105 double& xc,
double& yc,
double& zc,
const bool centre,
106 double& rc)
override;
108 const double z0,
double& xw,
double& yx,
109 double& rw)
override;
138 std::vector<double>
xv;
139 std::vector<double>
yv;
141 std::pair<BC, double>
bc;
149 std::array<double, 2>
x0;
150 std::array<double, 2>
x1;
153 std::pair<BC, double>
bc;
175 std::pair<BC, double>
bc;
193 const double lambda,
const unsigned int ndiv);
197 std::vector<std::vector<double> >& inverseMatrix)
const;
199 std::vector<int>& index)
const;
201 const std::vector<int>& index,
202 std::vector<double>& col)
const;
204 bool Solve(
const std::vector<std::vector<double> >& inverseMatrix,
205 const std::vector<double>& bc);
212 double WirePotential(
const double r0,
const double x,
const double y)
const;
214 void LineField(
const double a,
const double x,
const double y,
double& ex,
217 void WireField(
const double r0,
const double x,
const double y,
double& ex,
222 const double y,
const double v0)
const;
224 void BoxField(
const double a,
const double b,
const double x,
const double y,
225 double& ex,
double& ey)
const;
230 void ToLocal(
const double xIn,
const double yIn,
const double cphi,
231 const double sphi,
double& xOut,
double& yOut)
const;
233 void ToGlobal(
const double xIn,
const double yIn,
const double cphi,
234 const double sphi,
double& xOut,
double& yOut)
const;
237 int Field(
const double x,
const double y,
const double z,
double& ex,
238 double& ey,
double& ez,
double& v, Medium*& m,
const bool opt);
unsigned int GetNumberOfSegments() const
Return the number of conducting straight-line segments.
bool Solve(const std::vector< std::vector< double > > &inverseMatrix, const std::vector< double > &bc)
double m_zmax
Upper z limit.
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)
Add a conducting straight-line segment.
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, Medium *&m, int &status) override
std::vector< Wire > m_wires
Wires.
bool LUDecomposition(std::vector< std::vector< double > > &mat, std::vector< int > &index) const
void SplitElement(Element &oldElement, std::vector< Element > &elements)
bool GetVoltageRange(double &vmin, double &vmax) override
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.
void EliminateOverlaps(std::vector< Segment > &segments)
Split/merge overlapping segments.
double WirePotential(const double r0, const double x, const double y) const
Potential of a thin wire with radius r0.
void WireField(const double r0, const double x, const double y, double &ex, double &ey) const
Field of a thin wire with radius r0.
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
bool CheckConvergence(const double tol, std::vector< bool > &ok)
void EnableRandomCollocation(const bool on=true)
std::vector< Segment > m_segments
User-specified conducting straight-line segments.
unsigned int m_nCollocationPoints
void SetRangeZ(const double zmin, const double zmax)
Set the extent of the drift region along z.
unsigned int m_nMaxIterations
void EnableAutoResizing(const bool on=true)
void SetNumberOfCollocationPoints(const unsigned int ncoll)
bool Discretise(const Segment &segment, std::vector< Element > &elements, const double lambda, const unsigned int ndiv)
Create elements from a straight-line segment.
unsigned int GetNumberOfRegions() const
Return the number of regions.
double LinePotential(const double a, const double x, const double y) const
Potential of a line segment (half-width a) in local coordinates.
void ToGlobal(const double xIn, const double yIn, const double cphi, const double sphi, double &xOut, double &yOut) const
Rotation from local to global coordinates.
void ElectricField(const double x, const double y, const double z, double &ex, double &ey, double &ez, double &v, Medium *&m, int &status) override
std::vector< Element > m_elements
Straight-line boundary elements.
bool InvertMatrix(std::vector< std::vector< double > > &influenceMatrix, std::vector< std::vector< double > > &inverseMatrix) const
bool Initialise()
Discretise the geometry and compute the solution.
bool InTrapRadius(const double q0, const double x0, const double y0, const double z0, double &xw, double &yx, double &rw) override
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.
int Field(const double x, const double y, const double z, double &ex, double &ey, double &ez, double &v, Medium *&m, const bool opt)
Evaluation of the electric field (and optionally potential).
unsigned int m_nDivisions
Default number elements per segment.
void SetMedium(Medium *medium)
Set the "background" medium.
BC
Boundary condition type.
@ Floating
Floating conductor (not implemented).
@ Charge
Fixed charge density (not implemented).
@ Voltage
Fixed potential.
@ Dielectric
Dielectric-dielectric interface.
Medium * GetMedium(const double x, const double y, const double z) override
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.
void BoxField(const double a, const double b, const double x, const double y, double &ex, double &ey) const
Field of a uniformly charged rectangle.
bool AddWire(const double x, const double y, const double d, const double v, const int ntrap=5)
Add a wire.
size_t GetNumberOfElements() const override
Return the number of boundary elements.
void ToLocal(const double xIn, const double yIn, const double cphi, const double sphi, double &xOut, double &yOut) const
Rotation from global to local coordinates.
static const double InvTwoPiEpsilon0
ComponentNeBem2d()
Constructor.
void SetMaxNumberOfIterations(const unsigned int niter)
void UpdatePeriodicity() override
bool CrossedWire(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
double BoxPotential(const double a, const double b, const double x, const double y, const double v0) const
Potential of a uniformly charged rectangle.
bool ComputeInfluenceMatrix(std::vector< std::vector< double > > &infmat) const
void LineField(const double a, const double x, const double y, double &ex, double &ey) const
Field of a line segment (half-width a) in local coordinates.
Medium * m_medium
Background medium.
std::vector< Region > m_regions
Regions.
std::vector< SpaceCharge > m_spaceCharge
unsigned int GetNumberOfWires() const
Return the number of wires.
double m_zmin
Lower z limit.
void LUSubstitution(const std::vector< std::vector< double > > &mat, const std::vector< int > &index, std::vector< double > &col) const
bool m_useRangeZ
Flag whether a z-range has been defined by the user.
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)
Add a region bounded by a polygon.
static const double InvEpsilon0
bool GetElementaryCell(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) override
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.
double lambda
Ratio of dielectric permittivities.
std::pair< BC, double > bc
Boundary condition.
double y
Coordinates of the element centre (collocation point).
double q
Charge density (solution).
int ndiv
Number of elements per edge segment.
Medium * medium
Medium associated to the region.
std::vector< double > xv
x-coordinates of the vertices.
unsigned int depth
Level in the hierarchy.
std::pair< BC, double > bc
Applied boundary condition.
std::vector< double > yv
y-coordinates of the vertices.
std::pair< BC, double > bc
Applied boundary condition.
int ndiv
Number of elements.
std::array< double, 2 > x0
Coordinates of the start point.
std::array< double, 2 > x1
Coordinates of the end point.
double y
Coordinates of the centre.
int ntrap
Trap radius (in units of the wire radius).
double y
Coordinates of the centre.