From 5bcf28d19654f4de8cc646133389ba072b186e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20Sch=C3=B6berl?= Date: Fri, 30 Oct 2015 19:50:40 +0100 Subject: [PATCH] mesh size and bcnames for 2d geometries --- libsrc/geom2d/genmesh2d.cpp | 18 +++---- libsrc/geom2d/geometry2d.cpp | 36 ++++++++++--- libsrc/geom2d/geometry2d.hpp | 5 +- libsrc/geom2d/python_geom2d.cpp | 92 ++++++++++++++++++++------------- python/__init__.py | 2 +- python/geom2d.py | 4 +- 6 files changed, 100 insertions(+), 57 deletions(-) diff --git a/libsrc/geom2d/genmesh2d.cpp b/libsrc/geom2d/genmesh2d.cpp index 1792b0f9..5e703ece 100644 --- a/libsrc/geom2d/genmesh2d.cpp +++ b/libsrc/geom2d/genmesh2d.cpp @@ -355,15 +355,12 @@ namespace netgen { PrintMessage (1, "Generate Mesh from spline geometry"); - double h = mp.maxh; - Box<2> bbox = geometry.GetBoundingBox (); - if (bbox.Diam() < h) - { - h = bbox.Diam(); - mp.maxh = h; - } + if (bbox.Diam() < mp.maxh) + mp.maxh = bbox.Diam(); + + // double h = mp.maxh; // mesh = make_shared(); mesh->SetDimension (2); @@ -372,11 +369,11 @@ namespace netgen Point3d pmax(bbox.PMax()(0), bbox.PMax()(1), bbox.Diam()); mesh->SetLocalH (pmin, pmax, mp.grading); - mesh->SetGlobalH (h); + mesh->SetGlobalH (mp.maxh); - geometry.PartitionBoundary (mp, h, *mesh); + geometry.PartitionBoundary (mp, mp.maxh, *mesh); PrintMessage (3, "Boundary mesh done, np = ", mesh->GetNP()); @@ -517,7 +514,8 @@ namespace netgen for (int domnr = 1; domnr <= maxdomnr; domnr++) { if (geometry.GetDomainTensorMeshing (domnr)) continue; - + + double h = mp.maxh; if ( geometry.GetDomainMaxh ( domnr ) > 0 ) h = geometry.GetDomainMaxh(domnr); diff --git a/libsrc/geom2d/geometry2d.cpp b/libsrc/geom2d/geometry2d.cpp index cb7631d0..74f79c1f 100644 --- a/libsrc/geom2d/geometry2d.cpp +++ b/libsrc/geom2d/geometry2d.cpp @@ -887,24 +887,47 @@ namespace netgen - - string SplineGeometry2d :: GetBCName( const int bcnr ) const + void SplineGeometry2d :: SetBCName (int bcnr, string name) { - if ( bcnames.Size() >= bcnr) + if (bcnr < 1) + throw NgException ("Illegal nr in SetBCName"); + int new_to_add = bcnr - bcnames.Size(); + for (int i = 0; i < new_to_add; i++) + bcnames.Append (new string("default")); + delete bcnames[bcnr-1]; + bcnames[bcnr-1] = new string(name); + } + + string SplineGeometry2d :: GetBCName( int bcnr ) const + { + if (bcnames.Size() >= bcnr) if (bcnames[bcnr-1] ) return *bcnames[bcnr-1]; return "default"; } - string * SplineGeometry2d :: BCNamePtr( const int bcnr ) + string * SplineGeometry2d :: BCNamePtr( int bcnr ) { if ( bcnr > bcnames.Size() ) - return 0; + return nullptr; else return bcnames[bcnr-1]; } + int SplineGeometry2d :: GetBCNumber (string name) const + { + for (int i = 0; i < bcnames.Size(); i++) + if (*bcnames[i] == name) + return i+1; + return 0; + } + + int SplineGeometry2d :: AddBCName (string name) + { + bcnames.Append (new string(name)); + return bcnames.Size(); + } @@ -951,9 +974,10 @@ namespace netgen maxh[i] = 1e99; if (domnr >= 1) - maxh[domnr] = h; + maxh[domnr-1] = h; else throw NgException ("material index out of range"); + cout << "maxh = " << maxh << endl; } diff --git a/libsrc/geom2d/geometry2d.hpp b/libsrc/geom2d/geometry2d.hpp index 47ffec2e..69378a3e 100644 --- a/libsrc/geom2d/geometry2d.hpp +++ b/libsrc/geom2d/geometry2d.hpp @@ -182,7 +182,10 @@ namespace netgen } - string GetBCName ( const int bcnr ) const; + string GetBCName (int bcnr) const; + void SetBCName (int bcnr, string name); + int GetBCNumber (string name) const; // 0 if not exists + int AddBCName (string name); string * BCNamePtr ( const int bcnr ); diff --git a/libsrc/geom2d/python_geom2d.cpp b/libsrc/geom2d/python_geom2d.cpp index e4289e65..fa89ed15 100644 --- a/libsrc/geom2d/python_geom2d.cpp +++ b/libsrc/geom2d/python_geom2d.cpp @@ -19,7 +19,9 @@ DLL_HEADER void ExportGeom2d() { ModuleScope module("geom2d"); - bp::class_, boost::noncopyable>("SplineGeometry") + bp::class_, boost::noncopyable> + ("SplineGeometry", + "a 2d boundary representation geometry model by lines and splines") .def("__init__", bp::make_constructor (FunctionPointer ([](const string & filename) @@ -45,43 +47,57 @@ DLL_HEADER void ExportGeom2d() return self.geompoints.Size()-1; }), (bp::arg("self"), bp::arg("x"), bp::arg("y"), bp::arg("maxh") = 1e99)) - .def("Append", FunctionPointer([](SplineGeometry2d &self, bp::list segment, int leftdomain, int rightdomain, int bc) + .def("Append", FunctionPointer([](SplineGeometry2d &self, bp::list segment, int leftdomain, int rightdomain, bp::object bc) { - bp::extract segtype(segment[0]); + bp::extract segtype(segment[0]); + + SplineSegExt * seg; + if (segtype().compare("line") == 0) + { + bp::extract point_index1(segment[1]); + bp::extract point_index2(segment[2]); + //point_index1.check() + + LineSeg<2> * l = new LineSeg<2>(self.GetPoint(point_index1()), self.GetPoint(point_index2())); + seg = new SplineSegExt(*l); + } + else if (segtype().compare("spline3") == 0) + { + bp::extract point_index1(segment[1]); + bp::extract point_index2(segment[2]); + bp::extract point_index3(segment[3]); + + SplineSeg3<2> * seg3 = new SplineSeg3<2>(self.GetPoint(point_index1()), self.GetPoint(point_index2()), self.GetPoint(point_index3())); + seg = new SplineSegExt(*seg3); + } + else + { + cout << "Appended segment is not a line or a spline3" << endl; + } + seg->leftdom = leftdomain; + seg->rightdom = rightdomain; + seg->hmax = 1e99; + seg->reffak = 1; + seg->copyfrom = -1; + if (bp::extract(bc).check()) + seg->bc = bp::extract(bc)(); + else if (bp::extract(bc).check()) + { + string bcname = bp::extract(bc)(); + int bcnum = self.GetBCNumber(bcname); + if (bcnum == 0) + bcnum = self.AddBCName(bcname); + seg->bc = bcnum; + } + else + seg->bc = self.GetNSplines()+1; + self.AppendSegment(seg); + }), (bp::arg("self"), bp::arg("point_indices"), bp::arg("leftdomain") = 1, bp::arg("rightdomain") = 0, + bp::arg("bc")=bp::object())) - SplineSegExt * seg; - if (segtype().compare("line") == 0) - { - bp::extract point_index1(segment[1]); - bp::extract point_index2(segment[2]); - //point_index1.check() - - LineSeg<2> * l = new LineSeg<2>(self.GetPoint(point_index1()), self.GetPoint(point_index2())); - seg = new SplineSegExt(*l); - } - else if (segtype().compare("spline3") == 0) - { - bp::extract point_index1(segment[1]); - bp::extract point_index2(segment[2]); - bp::extract point_index3(segment[3]); - - SplineSeg3<2> * seg3 = new SplineSeg3<2>(self.GetPoint(point_index1()), self.GetPoint(point_index2()), self.GetPoint(point_index3())); - seg = new SplineSegExt(*seg3); - } - else - { - cout << "Appended segment is not a line or a spline3" << endl; - } - seg->leftdom = leftdomain; - seg->rightdom = rightdomain; - seg->hmax = 1e99; - seg->reffak = 1; - seg->copyfrom = -1; - seg->bc = (bc >= 0) ? bc : self.GetNSplines(); - self.AppendSegment(seg); - }), (bp::arg("self"), bp::arg("point_indices"), bp::arg("leftdomain") = 1, bp::arg("rightdomain") = 0, bp::arg("bc")=-1)) - .def("AppendSegment", FunctionPointer([](SplineGeometry2d &self, bp::list point_indices, int leftdomain, int rightdomain) - { + + .def("AppendSegment", FunctionPointer([](SplineGeometry2d &self, bp::list point_indices, int leftdomain, int rightdomain) + { int npts = bp::len(point_indices); SplineSegExt * seg; //int a = bp::extract(point_indices[0]); @@ -130,6 +146,10 @@ DLL_HEADER void ExportGeom2d() .def("SetMaterial", &SplineGeometry2d::SetMaterial) + .def("SetDomainMaxH", &SplineGeometry2d::SetDomainMaxh) + + + .def("PlotData", FunctionPointer([](SplineGeometry2d &self) diff --git a/python/__init__.py b/python/__init__.py index 7434af52..910e9147 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -9,7 +9,7 @@ if __platform.startswith('win'): # from libngpy import * import libngpy - + from . import csg from . import meshing diff --git a/python/geom2d.py b/python/geom2d.py index 842d2532..5478063a 100644 --- a/python/geom2d.py +++ b/python/geom2d.py @@ -1,8 +1,6 @@ from libngpy.geom2d import * from libngpy.meshing import * - - tmp_generate_mesh = SplineGeometry.GenerateMesh def geom2d_meshing_func (geom, **args): @@ -22,7 +20,7 @@ pnums = [unit_square.AppendPoint(*p) for p in pnts] for l1,l2,bc in lines: unit_square.Append( ["line", pnums[l1], pnums[l2]], bc=bc) -all = ['SplineGeometry', 'unit_square'] +__all__ = ['SplineGeometry', 'unit_square']