From b82d89a7687844497855271965e5483fa1cbad10 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteer Date: Mon, 31 Aug 2015 17:45:34 -0400 Subject: [PATCH 1/5] python - set background color --- libsrc/csg/vscsg.cpp | 2 ++ python/csg.py | 1 + 2 files changed, 3 insertions(+) diff --git a/libsrc/csg/vscsg.cpp b/libsrc/csg/vscsg.cpp index 152c7aaf..cb4154fa 100644 --- a/libsrc/csg/vscsg.cpp +++ b/libsrc/csg/vscsg.cpp @@ -503,6 +503,8 @@ DLL_HEADER void ExportCSGVis() .def("Draw", &VisualSceneGeometry::DrawScene) ; + bp::def("SetBackGroundColor", &VisualSceneGeometry::SetBackGroundColor); + bp::def("VS", FunctionPointer ([](CSGeometry & geom) { diff --git a/python/csg.py b/python/csg.py index 7998b29e..9e2159e2 100644 --- a/python/csg.py +++ b/python/csg.py @@ -14,6 +14,7 @@ if __platform.startswith('win'): CSGeometry.VS = csgvis.VS +SetBackGroundColor = csgvis.SetBackGroundColor del csgvis def VS (obj): From 21bb5c61c308e6bb4012e593a9f8896caf70f581 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteer Date: Mon, 31 Aug 2015 17:47:27 -0400 Subject: [PATCH 2/5] cone in python --- libsrc/csg/python_csg.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp index 275c53e4..be35ad58 100644 --- a/libsrc/csg/python_csg.cpp +++ b/libsrc/csg/python_csg.cpp @@ -251,6 +251,12 @@ DLL_HEADER void ExportCSG() Solid * sol = new Solid (sp); return make_shared (sol); })); + bp::def ("Cone", FunctionPointer([](Point<3> a, Point<3> b, double ra, double rb) + { + Cone * cyl = new Cone (a, b, ra, rb); + Solid * sol = new Solid (cyl); + return make_shared (sol); + })); bp::def ("Cylinder", FunctionPointer([](Point<3> a, Point<3> b, double r) { Cylinder * cyl = new Cylinder (a, b, r); From d167f1261aea4fb1ee84410418dfaa63e8a54f3d Mon Sep 17 00:00:00 2001 From: Matthias Hochsteer Date: Mon, 31 Aug 2015 17:48:05 -0400 Subject: [PATCH 3/5] python - visibility and transparency of csg objects --- libsrc/csg/python_csg.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp index be35ad58..1362a614 100644 --- a/libsrc/csg/python_csg.cpp +++ b/libsrc/csg/python_csg.cpp @@ -356,6 +356,7 @@ DLL_HEADER void ExportCSG() } delete bcname; } + return tlonr; }), (bp::arg("self"), bp::arg("solid"), bp::arg("bcmod")=bp::list()) @@ -381,7 +382,36 @@ DLL_HEADER void ExportCSG() }), (bp::arg("self"), bp::arg("solid1"), bp::arg("solid2"), bp::arg("reflevels")=2) ) - + .def("GetTransparent", FunctionPointer + ([] (CSGeometry & self, int tlonr) + { + return self.GetTopLevelObject(tlonr)->GetTransparent(); + }), + (bp::arg("self"), bp::arg("tlonr")) + ) + .def("SetTransparent", FunctionPointer + ([] (CSGeometry & self, int tlonr, bool transparent) + { + self.GetTopLevelObject(tlonr)->SetTransparent(transparent); + }), + (bp::arg("self"), bp::arg("tlonr"), bp::arg("transparent")) + ) + + .def("GetVisible", FunctionPointer + ([] (CSGeometry & self, int tlonr) + { + return self.GetTopLevelObject(tlonr)->GetVisible(); + }), + (bp::arg("self"), bp::arg("tlonr")) + ) + .def("SetVisible", FunctionPointer + ([] (CSGeometry & self, int tlonr, bool visible) + { + self.GetTopLevelObject(tlonr)->SetVisible(visible); + }), + (bp::arg("self"), bp::arg("tlonr"), bp::arg("visible")) + ) + .add_property ("ntlo", &CSGeometry::GetNTopLevelObjects) ; From c8e51c4ebc598d19d99deb2675334ba84f9f122a Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Mon, 31 Aug 2015 18:24:52 -0400 Subject: [PATCH 4/5] python - CloseSurfaces with user-defined slices --- libsrc/csg/python_csg.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp index 1362a614..26850a6e 100644 --- a/libsrc/csg/python_csg.cpp +++ b/libsrc/csg/python_csg.cpp @@ -362,6 +362,42 @@ DLL_HEADER void ExportCSG() (bp::arg("self"), bp::arg("solid"), bp::arg("bcmod")=bp::list()) ) + .def("CloseSurfaces", FunctionPointer + ([] (CSGeometry & self, shared_ptr s1, shared_ptr s2, bp::list aslices ) + { + Array si1, si2; + s1->GetSolid()->GetSurfaceIndices (si1); + s2->GetSolid()->GetSurfaceIndices (si2); + cout << "surface ids1 = " << si1 << endl; + cout << "surface ids2 = " << si2 << endl; + + Flags flags; + + try + { + int n = bp::len(aslices); + Array slices(n); + for(int i=0; i(aslices[i])(); + } + flags.SetFlag("slices", slices); + } + catch( bp::error_already_set const & ) { + cout << "caught python error:" << endl; + PyErr_Print(); + } + + const TopLevelObject * domain = nullptr; + self.AddIdentification + (new CloseSurfaceIdentification + (self.GetNIdentifications()+1, self, + self.GetSurface (si1[0]), self.GetSurface (si2[0]), + domain, + flags)); + }), + (bp::arg("self"), bp::arg("solid1"), bp::arg("solid2"), bp::arg("slices")) + ) .def("CloseSurfaces", FunctionPointer ([] (CSGeometry & self, shared_ptr s1, shared_ptr s2, int reflevels) { From 7d3041e841c92b8df759f413bf3a21b1dfeb58aa Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Tue, 1 Sep 2015 10:35:03 -0400 Subject: [PATCH 5/5] Boundary layers with user-defined heights/materials --- libsrc/meshing/boundarylayer.cpp | 19 +++++++++++++++---- libsrc/meshing/boundarylayer.hpp | 2 ++ libsrc/meshing/python_mesh.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/libsrc/meshing/boundarylayer.cpp b/libsrc/meshing/boundarylayer.cpp index 1ca3589e..643f0922 100644 --- a/libsrc/meshing/boundarylayer.cpp +++ b/libsrc/meshing/boundarylayer.cpp @@ -155,6 +155,7 @@ namespace netgen int prismlayers = blp.prismlayers; double hfirst = blp.hfirst; double growthfactor = blp.growthfactor; + Array heights (blp.heights); bool grow_edges = false; // grow layer at edges @@ -179,13 +180,20 @@ namespace netgen double layerht = hfirst; - if(growthfactor == 1) + if(heights.Size()>0) { - layerht = layer * hfirst; + layerht = heights[layer-1]; } else { - layerht = hfirst*(pow(growthfactor,(layer+1)) - 1)/(growthfactor - 1); + if(growthfactor == 1) + { + layerht = layer * hfirst; + } + else + { + layerht = hfirst*(pow(growthfactor,(layer+1)) - 1)/(growthfactor - 1); + } } cout << "Layer Height = " << layerht << endl; @@ -510,7 +518,10 @@ namespace netgen Element el(types[classify]); for (int i = 0; i < 6; i++) el[i] = nums[vertices[classify][i]]; - el.SetIndex(blp.new_matnr); + if(blp.new_matnrs.Size() > 0) + el.SetIndex(blp.new_matnrs[layer-1]); + else + el.SetIndex(blp.new_matnr); // cout << "el = " << el << endl; if (classify != 0) mesh.AddVolumeElement(el); diff --git a/libsrc/meshing/boundarylayer.hpp b/libsrc/meshing/boundarylayer.hpp index cbad16af..442de314 100644 --- a/libsrc/meshing/boundarylayer.hpp +++ b/libsrc/meshing/boundarylayer.hpp @@ -13,6 +13,8 @@ class BoundaryLayerParameters public: // parameters by Philippose .. Array surfid; + Array heights; + Array new_matnrs; int prismlayers = 1; int bulk_matnr = 1; int new_matnr = 1; diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index e27d3433..8134d345 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -338,6 +338,37 @@ DLL_HEADER void ExportNetgenMeshing() })) .def ("BoundaryLayer", FunctionPointer + ([](Mesh & self, int bc, bp::list thicknesses, int volnr, bp::list materials) + { + int n = bp::len(thicknesses); + BoundaryLayerParameters blp; + + for (int i = 1; i <= self.GetNFD(); i++) + if (self.GetFaceDescriptor(i).BCProperty() == bc) + blp.surfid.Append (i); + + cout << "add layer at surfaces: " << blp.surfid << endl; + + blp.prismlayers = n; + blp.growthfactor = 1.0; + + // find max domain nr + int maxind = 0; + for (ElementIndex ei = 0; ei < self.GetNE(); ei++) + maxind = max (maxind, self[ei].GetIndex()); + cout << "maxind = " << maxind << endl; + for ( int i=0; i(thicknesses[i])()) ; + blp.new_matnrs.Append( maxind+1+i ); + self.SetMaterial (maxind+1+i, bp::extract(materials[i])().c_str()); + } + blp.bulk_matnr = volnr; + GenerateBoundaryLayer (self, blp); + } + )) + + .def ("BoundaryLayer", FunctionPointer ([](Mesh & self, int bc, double thickness, int volnr, string material) { BoundaryLayerParameters blp;