Merge branch 'use_segmentindex' into boundarylayers

This commit is contained in:
Christopher Lackner 2020-11-17 15:25:19 +01:00
commit 0d48924392
4 changed files with 30 additions and 12 deletions

View File

@ -250,13 +250,20 @@ IntersectionType IntersectSplineSegment( const Spline & s, const Point<2> & r0,
double det = b_*b_ - 4*a_*c_; double det = b_*b_ - 4*a_*c_;
if(det<0.0) if(det<0.0)
return NO_INTERSECTION; return NO_INTERSECTION;
double sqrt_det = sqrt(det);
double t1 = 1.0/(2*a_) * (-b_ + sqrt_det);
double t2 = 1.0/(2*a_) * (-b_ - sqrt_det);
double t = min(t1,t2); double t;
if(t<alpha)
t = max(t1,t2); if(fabs(a_)>EPSILON)
{
double sqrt_det = sqrt(det);
double t1 = 1.0/(2*a_) * (-b_ + sqrt_det);
double t2 = 1.0/(2*a_) * (-b_ - sqrt_det);
t = min(t1, t2);
if(t<alpha)
t = max(t1,t2);
}
else // degenerate quadratic equation
t = -c_/b_;
if(t+EPSILON<alpha) if(t+EPSILON<alpha)
return NO_INTERSECTION; return NO_INTERSECTION;
@ -288,10 +295,17 @@ IntersectionType IntersectSplineSegment1( const Spline & s, const Point<2> & r0,
double det = b_*b_ - 4*a_*c_; double det = b_*b_ - 4*a_*c_;
if(det<0.0) if(det<0.0)
return NO_INTERSECTION; return NO_INTERSECTION;
double sqrt_det = sqrt(det); double sqrt_det = sqrt(det);
double vbeta[2]; double vbeta[2];
vbeta[0] = 1.0/(2*a_) * (-b_ + sqrt_det);
vbeta[1] = 1.0/(2*a_) * (-b_ - sqrt_det); if(fabs(a_)>EPSILON)
{
vbeta[0] = 1.0/(2*a_) * (-b_ + sqrt_det);
vbeta[1] = 1.0/(2*a_) * (-b_ - sqrt_det);
}
else // degenrate quadratic equation
vbeta[0] = vbeta[1] = -c_/b_;
int dim = fabs(vr[0]) > fabs(vr[1]) ? 0 : 1; int dim = fabs(vr[0]) > fabs(vr[1]) ? 0 : 1;
double valpha[2]; double valpha[2];

View File

@ -38,7 +38,7 @@ namespace netgen
NgMPI_Comm comm; NgMPI_Comm comm;
/// line-segments at edges /// line-segments at edges
Array<Segment> segments; Array<Segment, SegmentIndex> segments;
/// surface elements, 2d-inner elements /// surface elements, 2d-inner elements
Array<Element2d, SurfaceElementIndex> surfelements; Array<Element2d, SurfaceElementIndex> surfelements;
/// volume elements /// volume elements

View File

@ -306,13 +306,17 @@ namespace netgen
SegmentIndex & operator= (const SegmentIndex & ai) SegmentIndex & operator= (const SegmentIndex & ai)
{ i = ai.i; return *this; } { i = ai.i; return *this; }
SegmentIndex & operator= (int ai) { i = ai; return *this; } SegmentIndex & operator= (int ai) { i = ai; return *this; }
operator int () const { return i; } constexpr operator int () const { return i; }
SegmentIndex& operator++ () { ++i; return *this; } SegmentIndex& operator++ () { ++i; return *this; }
SegmentIndex& operator-- () { --i; return *this; } SegmentIndex& operator-- () { --i; return *this; }
SegmentIndex operator++ (int) { return i++; } SegmentIndex operator++ (int) { return i++; }
SegmentIndex operator-- (int) { return i--; } SegmentIndex operator-- (int) { return i--; }
}; };
inline void SetInvalid (SegmentIndex & id) { id = -1; }
inline bool IsInvalid (SegmentIndex & id) { return id == -1; }
inline istream & operator>> (istream & ist, SegmentIndex & pi) inline istream & operator>> (istream & ist, SegmentIndex & pi)
{ {
int i; ist >> i; pi = i; return ist; int i; ist >> i; pi = i; return ist;

View File

@ -603,7 +603,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
ExportArray<Element,size_t>(m); ExportArray<Element,size_t>(m);
ExportArray<Element2d,SurfaceElementIndex>(m); ExportArray<Element2d,SurfaceElementIndex>(m);
ExportArray<Segment,size_t>(m); ExportArray<Segment,SegmentIndex>(m);
ExportArray<Element0d>(m); ExportArray<Element0d>(m);
ExportArray<MeshPoint,PointIndex>(m); ExportArray<MeshPoint,PointIndex>(m);
ExportArray<FaceDescriptor>(m); ExportArray<FaceDescriptor>(m);
@ -823,7 +823,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
py::return_value_policy::reference) py::return_value_policy::reference)
.def("Elements1D", .def("Elements1D",
static_cast<Array<Segment>&(Mesh::*)()> (&Mesh::LineSegments), static_cast<Array<Segment, SegmentIndex>&(Mesh::*)()> (&Mesh::LineSegments),
py::return_value_policy::reference) py::return_value_policy::reference)
.def("Elements0D", FunctionPointer([] (Mesh & self) -> Array<Element0d>& .def("Elements0D", FunctionPointer([] (Mesh & self) -> Array<Element0d>&