From d1eb16badfbe3ae03cb97c03bdc22bc0d02fed9b Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Mon, 26 Nov 2018 11:41:25 +0100 Subject: [PATCH 1/2] allow curved bboundaries using splinesurfaces with ellipticcylinder cuttings --- libsrc/csg/algprim.cpp | 8 ++++++++ libsrc/csg/algprim.hpp | 3 ++- libsrc/csg/python_csg.cpp | 17 +++++++++++++---- libsrc/csg/splinesurface.cpp | 25 ++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/libsrc/csg/algprim.cpp b/libsrc/csg/algprim.cpp index 30dd780e..aa08c245 100644 --- a/libsrc/csg/algprim.cpp +++ b/libsrc/csg/algprim.cpp @@ -1236,7 +1236,15 @@ namespace netgen return max2(bb/(aa*aa),aa/(bb*bb)); } + int EllipticCylinder :: IsIdentic(const Surface& s2, int& inv, double eps) const + { + const EllipticCylinder* ps2 = dynamic_cast(&s2); + if (!ps2) return 0; + if((vl - ps2->vl).Length() > eps || (vs - ps2->vs).Length() > eps || (a-ps2->a).Length() > eps) + return 0; + return 1; + } Point<3> EllipticCylinder :: GetSurfacePoint () const { diff --git a/libsrc/csg/algprim.hpp b/libsrc/csg/algprim.hpp index 98715fd3..30b46a0b 100644 --- a/libsrc/csg/algprim.hpp +++ b/libsrc/csg/algprim.hpp @@ -267,7 +267,8 @@ namespace netgen const Box<3> & bbox, double facets) const; - + virtual int IsIdentic (const Surface & s2, int & inv, double eps) const; + virtual double MaxCurvature () const; virtual double MaxCurvatureLoc (const Point<3> & /* c */ , diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp index b99ea2d5..f63cc192 100644 --- a/libsrc/csg/python_csg.cpp +++ b/libsrc/csg/python_csg.cpp @@ -235,13 +235,17 @@ DLL_HEADER void ExportCSG(py::module &m) return self.GetNP()-1; }), py::arg("x"),py::arg("y"),py::arg("z"),py::arg("hpref")=false) - .def("AddSegment", FunctionPointer - ([] (SplineSurface & self, int i1, int i2, string bcname, double maxh) + .def("AddSegment", [] (SplineSurface & self, int i1, int i2, string bcname, double maxh) { auto seg = make_shared>(self.GetPoint(i1),self.GetPoint(i2)); self.AppendSegment(seg,bcname,maxh); - }), + }, py::arg("pnt1"),py::arg("pnt2"),py::arg("bcname")="default", py::arg("maxh")=-1.) + .def("AddSegment", [] (SplineSurface& self, int i1, int i2, int i3, string bcname, double maxh) + { + auto seg = make_shared>(self.GetPoint(i1), self.GetPoint(i2), self.GetPoint(i3)); + self.AppendSegment(seg, bcname, maxh); + }, py::arg("pnt1"),py::arg("pnt2"), py::arg("pnt3"),py::arg("bcname")="default", py::arg("maxh")=-1.) ; py::class_> (m, "Solid") @@ -477,7 +481,12 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails! self.GetTopLevelObject(tlonr) -> SetBCProp(surf->GetBase()->GetBCProperty()); self.GetTopLevelObject(tlonr) -> SetBCName(surf->GetBase()->GetBCName()); self.GetTopLevelObject(tlonr) -> SetMaxH(surf->GetBase()->GetMaxH()); - for(auto p : surf->GetPoints()) + Array> non_midpoints; + for(auto spline : surf->GetSplines()) + { + non_midpoints.Append(spline->GetPoint(0)); + } + for(auto p : non_midpoints) self.AddUserPoint(p); self.AddSplineSurface(surf); }), diff --git a/libsrc/csg/splinesurface.cpp b/libsrc/csg/splinesurface.cpp index e8119db1..3d555c70 100644 --- a/libsrc/csg/splinesurface.cpp +++ b/libsrc/csg/splinesurface.cpp @@ -62,7 +62,30 @@ void SplineSurface :: AppendPoint(const Point<3> & p, const double reffac, const cuttings->Append(plane); } else - throw NgException("Spline type not implemented for SplineSurface!"); + { + auto spline3 = dynamic_cast*>(spline.get()); + if(spline3) + { + auto p1 = Point<3>(spline3->StartPI()); + Project(p1); + auto p2 = Point<3>(spline3->TangentPoint()); + Project(p2); + auto p3 = Point<3>(spline3->EndPI()); + Project(p3); + Vec<3> v1 = p2-p1; + Vec<3> v2 = p2-p3; + Point<3> mid = p1 - v2; + cout << "mid point = " << mid << endl; + cout << "v1 = " << v1 << endl; + cout << "v2 = " << v2 << endl; + auto cyl = make_shared(mid, v1, v2); + if(maxh[i] > 0) + cyl->SetMaxH(maxh[i]); + cuttings->Append(cyl); + } + else + throw NgException("Spline type not implemented for SplineSurface!"); + } } all_cuts = cuttings; return cuttings; From c4adaf7077d8d1f1be6b0cce6697ba93d455a6ab Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Thu, 13 Dec 2018 14:39:13 +0100 Subject: [PATCH 2/2] default constructor for splinesurface --- libsrc/csg/splinesurface.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libsrc/csg/splinesurface.hpp b/libsrc/csg/splinesurface.hpp index 07a7eb8a..a6e8a596 100644 --- a/libsrc/csg/splinesurface.hpp +++ b/libsrc/csg/splinesurface.hpp @@ -19,6 +19,8 @@ namespace netgen SplineSurface(shared_ptr abaseprimitive, shared_ptr>> acuts) : OneSurfacePrimitive(), baseprimitive(abaseprimitive), cuts(acuts) { ; } + // default constructor for archive + SplineSurface() {} virtual ~SplineSurface() { ; } const auto & GetSplines() const { return splines; }