11 const double rt,
const double lz)
12 :
Solid(cx, cy, cz,
"SolidTube"),
19 const double rt,
const double lz,
20 const double dx,
const double dy,
const double dz)
25void SolidTube::UpdatePolygon() {
26 std::lock_guard<std::mutex> guard(m_mutex);
27 const unsigned int nP = 4. * (m_n - 1);
28 const double alpha = Pi / nP;
29 const double calpha = cos(alpha);
33 const double f = 2. / (1. + asinh(tan(alpha)) * calpha / tan(alpha));
41 for (
unsigned int i = 0; i < nP; ++i) {
42 const double phi = m_rot + HalfPi * i / (m_n - 1.);
43 const double cphi = cos(phi);
44 const double sphi = sin(phi);
45 m_xp.push_back(m_rp * cphi);
46 m_yp.push_back(m_rp * sphi);
51 const bool tesselated)
const {
53 double u = x, v = y, w = z;
56 if (fabs(w) > m_lZ)
return false;
58 const double rho = sqrt(u * u + v * v);
59 if (!tesselated)
return (rho <= m_rMax);
61 if (rho > m_rp)
return false;
62 if (rho < m_ri)
return true;
70 double& xmax,
double& ymax,
double& zmax)
const {
81 const double dd = sqrt(m_rMax * m_rMax + m_lZ * m_lZ);
93 std::cerr <<
"SolidTube::SetRadius: Radius must be > 0.\n";
102 std::cerr <<
"SolidTube::SetHalfLength: Half-length must be > 0.\n";
111 std::cerr <<
"SolidTube::SetSectors: Number must be > 0.\n";
120 const auto id =
GetId();
121 const auto nPanels = panels.size();
125 std::cerr <<
"SolidTube::SolidPanels:\n"
126 <<
" Zero norm direction vector; no panels generated.\n";
131 const unsigned int nPoints = 4 * (m_n - 1);
134 std::vector<double> xv;
135 std::vector<double> yv;
136 std::vector<double> zv;
137 for (
unsigned int i = 1; i <= nPoints; i++) {
138 const double alpha = m_rot + HalfPi * (i - 1.) / (m_n - 1.);
141 ToGlobal(r * cos(alpha), r * sin(alpha), m_lZ, x, y, z);
155 panels.push_back(std::move(panel));
159 std::vector<double> xv;
160 std::vector<double> yv;
161 std::vector<double> zv;
162 for (
unsigned int i = 1; i <= nPoints; i++) {
163 const double alpha = m_rot + HalfPi * (i - 1.) / (m_n - 1.);
166 ToGlobal(r * cos(alpha), r * sin(alpha), -m_lZ, x, y, z);
180 panels.push_back(std::move(panel));
183 double u = r * cos(m_rot);
184 double v = r * sin(m_rot);
186 double xv0, yv0, zv0;
187 ToGlobal(u, v, -m_lZ, xv0, yv0, zv0);
188 double xv1, yv1, zv1;
189 ToGlobal(u, v, +m_lZ, xv1, yv1, zv1);
191 for (
unsigned int i = 2; i <= nPoints + 1; i++) {
193 double alpha = m_rot + HalfPi * (i - 1.) / (m_n - 1.);
197 double xv2, yv2, zv2;
198 ToGlobal(u, v, +m_lZ, xv2, yv2, zv2);
199 double xv3, yv3, zv3;
200 ToGlobal(u, v, -m_lZ, xv3, yv3, zv3);
203 alpha = m_rot + HalfPi * (i - 1.5) / (m_n - 1.);
204 const double cAlpha = cos(alpha);
205 const double sAlpha = sin(alpha);
209 panel.
xv = {xv0, xv1, xv2, xv3};
210 panel.
yv = {yv0, yv1, yv2, yv3};
211 panel.
zv = {zv0, zv1, zv2, zv3};
214 panels.push_back(std::move(panel));
223 std::cout <<
"SolidTube::SolidPanels: " << panels.size() - nPanels
231 double u = 0., v = 0., w = 0.;
234 if (w > std::max(std::abs(u), std::abs(v))) {
236 }
else if (w < -std::max(std::abs(u), std::abs(v))) {
243 const double xn,
const double yn,
const double zn,
244 std::vector<Panel>& panels) {
249 std::vector<double> xv;
250 std::vector<double> yv;
251 std::vector<double> zv;
253 const unsigned int nPoints = 4 * (m_n - 1);
254 const double dphi = HalfPi / (m_n - 1.);
256 for (
const auto zLid : {-m_lZ, +m_lZ}) {
258 ToGlobal(r * cos(m_rot), r * sin(m_rot), zLid, x1, y1, z1);
260 for (
unsigned int i = 2; i <= nPoints + 1; ++i) {
261 const double phi = m_rot + (i - 1.) * dphi;
263 ToGlobal(r * cos(phi), r * sin(phi), zLid, x2, y2, z2);
266 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0,
267 xn, yn, zn, xc, yc, zc)) {
279 for (
unsigned int i = 2; i <= nPoints + 1; ++i) {
281 const double phi = m_rot + (i - 1.) * dphi;
282 const double u = r * cos(phi);
283 const double v = r * sin(phi);
290 if (
Intersect(x1, y1, z1, x2, y2, z2, x0, y0, z0, xn, yn, zn, xc, yc, zc)) {
299 if (xv.size() >= 3) {
309 panels.push_back(std::move(panel));
bool SolidPanels(std::vector< Panel > &panels) override
Retrieve the surface panels of the solid.
double GetDiscretisationLevel(const Panel &panel) override
Retrieve the discretisation level of a panel.
void SetSectors(const unsigned int n)
SolidTube(const double cx, const double cy, const double cz, const double r, const double lz)
Constructor from centre, outer radius, and half-length.
void SetHalfLength(const double lz)
void SetRadius(const double r)
void Cut(const double x0, const double y0, const double z0, const double xn, const double yn, const double zn, std::vector< Panel > &panels) override
bool IsInside(const double x, const double y, const double z, const bool tesselated) const override
bool GetBoundingBox(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const override
Return the bounding box of the solid.
Abstract base class for solids.
void VectorToLocal(const double x, const double y, const double z, double &u, double &v, double &w)
Transform a vector from global to local coordinates.
double m_cTheta
Polar angle.
static bool Intersect(const double x1, const double y1, const double z1, const double x2, const double y2, const double z2, const double x0, const double y0, const double z0, const double a, const double b, const double c, double &xc, double &yc, double &zc)
double m_dX
Direction vector.
unsigned int GetId() const
Get the ID of the solid.
void ToLocal(const double x, const double y, const double z, double &u, double &v, double &w) const
void SetDirection(const double dx, const double dy, const double dz)
void ToGlobal(const double u, const double v, const double w, double &x, double &y, double &z) const
double m_cX
Centre of the solid.
double m_cPhi
Azimuthal angle.
void EliminateButterflies(std::vector< double > &xp, std::vector< double > &yp, std::vector< double > &zp)
void Inside(const std::vector< double > &xpl, const std::vector< double > &ypl, const double x, const double y, bool &inside, bool &edge)
std::vector< double > zv
Z-coordinates of vertices.
int volume
Reference to solid to which the panel belongs.
double a
Perpendicular vector.
std::vector< double > xv
X-coordinates of vertices.
std::vector< double > yv
Y-coordinates of vertices.