From 091494c6b3c41f42c997eeade5c90a44d2c1590f Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Thu, 25 Jul 2019 23:25:58 +0200 Subject: [PATCH] cleanup python export, generate mesh functions not monkeypatched --- libsrc/core/utils.hpp | 15 +++ libsrc/csg/python_csg.cpp | 31 +++--- libsrc/geom2d/python_geom2d.cpp | 16 ++- libsrc/meshing/meshtype.hpp | 30 +++--- libsrc/meshing/python_mesh.cpp | 35 +------ libsrc/meshing/python_mesh.hpp | 170 ++++++++++++++++++++++++++++++++ libsrc/occ/python_occ.cpp | 59 ++++++----- libsrc/stlgeom/python_stl.cpp | 51 +++++----- python/CMakeLists.txt | 2 +- python/NgOCC.py | 13 +-- python/csg.py | 25 +---- python/geom2d.py | 29 ++---- python/meshing.py | 2 +- python/occ.py | 1 + python/stl.py | 11 --- 15 files changed, 314 insertions(+), 176 deletions(-) create mode 100644 libsrc/meshing/python_mesh.hpp create mode 100644 python/occ.py diff --git a/libsrc/core/utils.hpp b/libsrc/core/utils.hpp index 35877d42..e20bb977 100644 --- a/libsrc/core/utils.hpp +++ b/libsrc/core/utils.hpp @@ -103,6 +103,21 @@ namespace ngcore void operator delete[] (void * p) { aligned_free(p); } }; + // Two helper functions for string checking + inline bool StartsWith(std::string str, std::string start) + { + if(start.size() > str.size()) + return false; + return std::equal(start.begin(), start.end(), str.begin()); + } + + inline bool EndsWith(std::string str, std::string end) + { + if(end.size() > str.size()) + return false; + return std::equal(end.rbegin(), end.rend(), str.rbegin()); + } + } // namespace ngcore #endif // NETGEN_CORE_UTILS_HPP diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp index 603ff98c..2a2ca033 100644 --- a/libsrc/csg/python_csg.cpp +++ b/libsrc/csg/python_csg.cpp @@ -3,6 +3,7 @@ #include <../general/ngpython.hpp> #include #include +#include "../meshing/python_mesh.hpp" using namespace netgen; @@ -693,26 +694,22 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails! res["max"] = MoveToNumpy(max); return res; }, py::call_guard()) - ; - - m.def("GenerateMesh", FunctionPointer - ([](shared_ptr geo, MeshingParameters & param) + .def("GenerateMesh", [](shared_ptr geo, py::kwargs kwargs) { - auto dummy = make_shared(); - SetGlobalMesh (dummy); - dummy->SetGeometry(geo); + MeshingParameters mp; + { + py::gil_scoped_acquire aq; + mp = CreateMPfromKwargs(kwargs); + } + auto mesh = make_shared(); + SetGlobalMesh (mesh); + mesh->SetGeometry(geo); ng_geometry = geo; geo->FindIdenticSurfaces(1e-8 * geo->MaxSize()); - try - { - geo->GenerateMesh (dummy, param); - } - catch (NgException ex) - { - cout << "Caught NgException: " << ex.What() << endl; - } - return dummy; - }),py::call_guard()) + geo->GenerateMesh (mesh, mp); + return mesh; + }, meshingparameter_description.c_str(), + py::call_guard()) ; m.def("Save", FunctionPointer diff --git a/libsrc/geom2d/python_geom2d.cpp b/libsrc/geom2d/python_geom2d.cpp index d04b8cd7..49e8ae9b 100644 --- a/libsrc/geom2d/python_geom2d.cpp +++ b/libsrc/geom2d/python_geom2d.cpp @@ -2,6 +2,7 @@ #include <../general/ngpython.hpp> #include +#include "../meshing/python_mesh.hpp" #include #include @@ -362,16 +363,21 @@ DLL_HEADER void ExportGeom2d(py::module &m) //cout << i << " : " << self.splines[i]->GetPoint(0.1) << " , " << self.splines[i]->GetPoint(0.5) << endl; } })) - .def("GenerateMesh", [](shared_ptr self, MeshingParameters & mparam) + .def("GenerateMesh", [](shared_ptr self, py::kwargs kwargs) { - shared_ptr mesh = make_shared (); + MeshingParameters mp; + { + py::gil_scoped_acquire aq; + mp = CreateMPfromKwargs(kwargs); + } + auto mesh = make_shared(); mesh->SetGeometry(self); SetGlobalMesh (mesh); ng_geometry = self; - self->GenerateMesh(mesh, mparam); + self->GenerateMesh(mesh, mp); return mesh; - },py::call_guard()) - + }, py::call_guard(), + meshingparameter_description.c_str()) ; } diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 68fee518..bbc5b527 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -1191,7 +1191,7 @@ namespace netgen /// power of error (to approximate max err optimization) double opterrpow = 2; /// do block filling ? - int blockfill = 1; + bool blockfill = true; /// block filling up to distance double filldist = 0.1; /// radius of local environment (times h) @@ -1199,11 +1199,11 @@ namespace netgen /// radius of active environment (times h) double relinnersafety = 3; /// use local h ? - int uselocalh = 1; + bool uselocalh = true; /// grading for local h double grading = 0.3; /// use delaunay meshing - int delaunay = 1; + bool delaunay = true; /// maximal mesh size double maxh = 1e10; /// minimal mesh size @@ -1211,19 +1211,19 @@ namespace netgen /// file for meshsize string meshsizefilename = ""; /// start surfacemeshing from everywhere in surface - int startinsurface = 0; + bool startinsurface = false; /// check overlapping surfaces (debug) - int checkoverlap = 1; + bool checkoverlap = true; /// check overlapping surface mesh before volume meshing - int checkoverlappingboundary = 1; + bool checkoverlappingboundary = true; /// check chart boundary (sometimes too restrictive) - int checkchartboundary = 1; + bool checkchartboundary = true; /// safety factor for curvatures (elements per radius) double curvaturesafety = 2; /// minimal number of segments per edge double segmentsperedge = 1; /// use parallel threads - int parthread = 0; + bool parthread = 0; /// weight of element size w.r.t element shape double elsizeweight = 0.2; /// init with default values @@ -1246,29 +1246,29 @@ namespace netgen /// if non-zero, baseelement must have baseelnp points int baseelnp = 0; /// quality tolerances are handled less careful - int sloppy = 1; + bool sloppy = true; /// limit for max element angle (150-180) double badellimit = 175; - bool check_impossible = 0; + bool check_impossible = false; int only3D_domain_nr = 0; /// - int secondorder = 0; + bool secondorder = false; /// high order element curvature int elementorder = 1; /// quad-dominated surface meshing - int quad = 0; + bool quad = false; /// bool try_hexes = false; /// - int inverttets = 0; + bool inverttets = false; /// - int inverttrigs = 0; + bool inverttrigs = false; /// - int autozrefine = 0; + bool autozrefine = false; /// MeshingParameters (); /// diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 448775d8..8b6dd1c8 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -2,6 +2,7 @@ #include <../general/ngpython.hpp> #include +#include "python_mesh.hpp" #include #include "meshing.hpp" @@ -1026,38 +1027,12 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) ; typedef MeshingParameters MP; - py::class_ (m, "MeshingParameters") + auto mp = py::class_ (m, "MeshingParameters") .def(py::init<>()) - .def(py::init([](double maxh, bool quad_dominated, int optsteps2d, int optsteps3d, - MESHING_STEP perfstepsend, int only3D_domain, const string & meshsizefilename, - double grading, double curvaturesafety, double segmentsperedge) + .def(py::init([](py::kwargs kwargs) { - MP * instance = new MeshingParameters; - instance->maxh = maxh; - instance->quad = int(quad_dominated); - instance->optsteps2d = optsteps2d; - instance->optsteps3d = optsteps3d; - instance->only3D_domain_nr = only3D_domain; - instance->perfstepsend = perfstepsend; - instance->meshsizefilename = meshsizefilename; - - instance->grading = grading; - instance->curvaturesafety = curvaturesafety; - instance->segmentsperedge = segmentsperedge; - return instance; - }), - py::arg("maxh")=1000, - py::arg("quad_dominated")=false, - py::arg("optsteps2d") = 3, - py::arg("optsteps3d") = 3, - py::arg("perfstepsend") = MESHCONST_OPTVOLUME, - py::arg("only3D_domain") = 0, - py::arg("meshsizefilename") = "", - py::arg("grading")=0.3, - py::arg("curvaturesafety")=2, - py::arg("segmentsperedge")=1, - "create meshing parameters" - ) + return CreateMPfromKwargs(kwargs); + }), meshingparameter_description.c_str()) .def("__str__", &ToString) .def_property("maxh", FunctionPointer ([](const MP & mp ) { return mp.maxh; }), diff --git a/libsrc/meshing/python_mesh.hpp b/libsrc/meshing/python_mesh.hpp new file mode 100644 index 00000000..4a61effd --- /dev/null +++ b/libsrc/meshing/python_mesh.hpp @@ -0,0 +1,170 @@ + +#include +#include "meshing.hpp" + +namespace netgen +{ + // TODO: Clarify a lot of these parameters + static string meshingparameter_description = R"delimiter( +Meshing Parameters +------------------- + +maxh: float = 1e10 + Global upper bound for mesh size. + +grading: float = 0.3 + Mesh grading how fast the local mesh size can change. + +meshsizefilename: str = None + Load meshsize from file. Can set local mesh size for points + and along edges. File must have the format: + + nr_points + x1, y1, z1, meshsize + x2, y2, z2, meshsize + ... + xn, yn, zn, meshsize + + nr_edges + x11, y11, z11, x12, y12, z12, meshsize + ... + xn1, yn1, zn1, xn2, yn2, zn2, meshsize + +segmentsperedge: float = 1. + Minimal number of segments per edge. + +quad: bool = False + Quad-dominated surface meshing. + +blockfill: bool = True + Do fast blockfilling. + +filldist: float = 0.1 + Block fill up to distance + +delaunay: bool = True + Use delaunay meshing. + +Optimization Parameters +----------------------- + +optimize3d: str = "cmdmustm" + 3d optimization strategy: + m .. move nodes + M .. move nodes, cheap functional + s .. swap faces + c .. combine elements + d .. divide elements + p .. plot, no pause + P .. plot, Pause + h .. Histogramm, no pause + H .. Histogramm, pause + +optsteps3d: int = 3 + Number of 3d optimization steps. + +optimize2d: str = "smsmsmSmSmSm" + 2d optimization strategy: + s .. swap, opt 6 lines/node + S .. swap, optimal elements + m .. move nodes + p .. plot, no pause + P .. plot, pause + c .. combine + +optsteps2d: int = 3 + Number of 2d optimization steps. + +elsizeweight: float = 0.2 + Weight of element size w.r.t. element shape in optimization. + +)delimiter"; + + MeshingParameters CreateMPfromKwargs(py::kwargs kwargs) + { + MeshingParameters mp; + if(kwargs.contains("optimize3d")) + mp.optimize3d = py::cast(kwargs["optimize3d"]); + if(kwargs.contains("optsteps3d")) + mp.optsteps3d = py::cast(kwargs["optsteps3d"]); + if(kwargs.contains("optimize2d")) + mp.optimize2d = py::cast(kwargs["optimize2d"]); + if(kwargs.contains("optsteps2d")) + mp.optsteps2d = py::cast(kwargs["optsteps2d"]); + if(kwargs.contains("opterrpow")) + mp.opterrpow = py::cast(kwargs["opterrpow"]); + if(kwargs.contains("blockfill")) + mp.blockfill = py::cast(kwargs["blockfill"]); + if(kwargs.contains("filldist")) + mp.filldist = py::cast(kwargs["filldist"]); + if(kwargs.contains("safety")) + mp.safety = py::cast(kwargs["safety"]); + if(kwargs.contains("relinnersafety")) + mp.relinnersafety = py::cast(kwargs["relinnersafety"]); + if(kwargs.contains("uselocalh")) + mp.uselocalh = py::cast(kwargs["uselocalh"]); + if(kwargs.contains("grading")) + mp.grading = py::cast(kwargs["grading"]); + if(kwargs.contains("delaunay")) + mp.delaunay = py::cast(kwargs["delaunay"]); + if(kwargs.contains("maxh")) + mp.maxh = py::cast(kwargs["maxh"]); + if(kwargs.contains("minh")) + mp.minh = py::cast(kwargs["minh"]); + if(kwargs.contains("meshsizefilename")) + mp.meshsizefilename = py::cast(kwargs["meshsizefilename"]); + if(kwargs.contains("startinsurface")) + mp.startinsurface = py::cast(kwargs["startinsurface"]); + if(kwargs.contains("checkoverlap")) + mp.checkoverlap = py::cast(kwargs["checkoverlap"]); + if(kwargs.contains("checkoverlappingboundary")) + mp.checkoverlappingboundary = py::cast(kwargs["checkoverlappingboundary"]); + if(kwargs.contains("checkchartboundary")) + mp.checkchartboundary = py::cast(kwargs["checkchartboundary"]); + if(kwargs.contains("curvaturesafety")) + mp.curvaturesafety = py::cast(kwargs["curvaturesafety"]); + if(kwargs.contains("segmentsperedge")) + mp.segmentsperedge = py::cast(kwargs["segmentsperedge"]); + if(kwargs.contains("parthread")) + mp.parthread = py::cast(kwargs["parthread"]); + if(kwargs.contains("elsizeweight")) + mp.elsizeweight = py::cast(kwargs["elsizeweight"]); + if(kwargs.contains("perfstepsstart")) + mp.perfstepsstart = py::cast(kwargs["perfstepsstart"]); + if(kwargs.contains("perfstepsend")) + mp.perfstepsend = py::cast(kwargs["perfstepsend"]); + if(kwargs.contains("giveuptol2d")) + mp.giveuptol2d = py::cast(kwargs["giveuptol2d"]); + if(kwargs.contains("giveuptol")) + mp.giveuptol = py::cast(kwargs["giveuptol"]); + if(kwargs.contains("maxoutersteps")) + mp.maxoutersteps = py::cast(kwargs["maxoutersteps"]); + if(kwargs.contains("starshapeclass")) + mp.starshapeclass = py::cast(kwargs["starshapeclass"]); + if(kwargs.contains("baseelnp")) + mp.baseelnp = py::cast(kwargs["baseelnp"]); + if(kwargs.contains("sloppy")) + mp.sloppy = py::cast(kwargs["sloppy"]); + if(kwargs.contains("badellimit")) + mp.badellimit = py::cast(kwargs["badellimit"]); + if(kwargs.contains("check_impossible")) + mp.check_impossible = py::cast(kwargs["check_impossible"]); + if(kwargs.contains("only3D_domain_nr")) + mp.only3D_domain_nr = py::cast(kwargs["only3D_domain_nr"]); + if(kwargs.contains("secondorder")) + mp.secondorder = py::cast(kwargs["secondorder"]); + if(kwargs.contains("elementorder")) + mp.elementorder = py::cast(kwargs["elementorder"]); + if(kwargs.contains("quad")) + mp.quad = py::cast(kwargs["quad"]); + if(kwargs.contains("try_hexes")) + mp.try_hexes = py::cast(kwargs["try_hexes"]); + if(kwargs.contains("inverttets")) + mp.inverttets = py::cast(kwargs["inverttets"]); + if(kwargs.contains("inverttrigs")) + mp.inverttrigs = py::cast(kwargs["inverttrigs"]); + if(kwargs.contains("autozrefine")) + mp.autozrefine = py::cast(kwargs["autozrefine"]); + return mp; + } +} // namespace netgen diff --git a/libsrc/occ/python_occ.cpp b/libsrc/occ/python_occ.cpp index 18514c8e..971c7730 100644 --- a/libsrc/occ/python_occ.cpp +++ b/libsrc/occ/python_occ.cpp @@ -3,6 +3,7 @@ #include <../general/ngpython.hpp> #include +#include "../meshing/python_mesh.hpp" #include #include @@ -19,6 +20,21 @@ DLL_HEADER void ExportNgOCC(py::module &m) { py::class_, NetgenGeometry> (m, "OCCGeometry", R"raw_string(Use LoadOCCGeometry to load the geometry from a *.step file.)raw_string") .def(py::init<>()) + .def(py::init([] (const string& filename) + { + shared_ptr geo; + if(EndsWith(filename, ".step") || EndsWith(filename, ".stp")) + geo.reset(LoadOCC_STEP(filename.c_str())); + else if(EndsWith(filename, ".brep")) + geo.reset(LoadOCC_BREP(filename.c_str())); + else if(EndsWith(filename, ".iges")) + geo.reset(LoadOCC_IGES(filename.c_str())); + else + throw Exception("Cannot load file " + filename + "\nValid formats are: step, stp, brep, iges"); + ng_geometry = geo; + return geo; + }), py::arg("filename"), + "Load OCC geometry from step, brep or iges file") .def(NGSPickle()) .def("Heal",[](OCCGeometry & self, double tolerance, bool fixsmalledges, bool fixspotstripfaces, bool sewfaces, bool makesolids, bool splitpartitions) { @@ -108,34 +124,33 @@ DLL_HEADER void ExportNgOCC(py::module &m) res["max"] = MoveToNumpy(max); return res; }, py::call_guard()) - ; - m.def("LoadOCCGeometry",FunctionPointer([] (const string & filename) + .def("GenerateMesh", [](shared_ptr geo, py::kwargs kwargs) + { + MeshingParameters mp; + { + py::gil_scoped_acquire aq; + mp = CreateMPfromKwargs(kwargs); + } + auto mesh = make_shared(); + SetGlobalMesh(mesh); + mesh->SetGeometry(geo); + ng_geometry = geo; + geo->GenerateMesh(mesh,mp); + return mesh; + }, + py::call_guard(), + meshingparameter_description.c_str()) + ; + + m.def("LoadOCCGeometry",[] (const string & filename) { - cout << "load OCC geometry"; + cout << "WARNING: LoadOCCGeometry is deprecated! Just use the OCCGeometry(filename) constructor. It is able to read brep and iges files as well!" << endl; ifstream ist(filename); OCCGeometry * instance = new OCCGeometry(); instance = LoadOCC_STEP(filename.c_str()); ng_geometry = shared_ptr(instance, NOOP_Deleter); return ng_geometry; - }),py::call_guard()); - m.def("GenerateMesh", FunctionPointer([] (shared_ptr geo, MeshingParameters ¶m) - { - auto mesh = make_shared(); - SetGlobalMesh(mesh); - mesh->SetGeometry(geo); - ng_geometry = geo; - - try - { - geo->GenerateMesh(mesh,param); - } - catch (NgException ex) - { - cout << "Caught NgException: " << ex.What() << endl; - } - return mesh; - }),py::call_guard()) - ; + },py::call_guard()); } PYBIND11_MODULE(libNgOCC, m) { diff --git a/libsrc/stlgeom/python_stl.cpp b/libsrc/stlgeom/python_stl.cpp index 0d2bb32f..113f6ef6 100644 --- a/libsrc/stlgeom/python_stl.cpp +++ b/libsrc/stlgeom/python_stl.cpp @@ -4,6 +4,7 @@ #include <../general/ngpython.hpp> #include #include +#include "../meshing/python_mesh.hpp" #ifdef WIN32 #define DLL_HEADER __declspec(dllexport) @@ -21,6 +22,12 @@ DLL_HEADER void ExportSTL(py::module & m) { py::class_, NetgenGeometry> (m,"STLGeometry") .def(py::init<>()) + .def(py::init<>([](const string& filename) + { + ifstream ist(filename); + return shared_ptr(STLGeometry::Load(ist)); + }), py::arg("filename"), + py::call_guard()) .def(NGSPickle()) .def("_visualizationData", [](shared_ptr stl_geo) { @@ -71,29 +78,29 @@ DLL_HEADER void ExportSTL(py::module & m) res["max"] = MoveToNumpy(max); return res; }, py::call_guard()) + .def("GenerateMesh", [] (shared_ptr geo, py::kwargs kwargs) + { + MeshingParameters mp; + { + py::gil_scoped_acquire aq; + mp = CreateMPfromKwargs(kwargs); + } + auto mesh = make_shared(); + SetGlobalMesh(mesh); + mesh->SetGeometry(geo); + ng_geometry = geo; + geo->GenerateMesh(mesh,mp); + return mesh; + }, + py::call_guard(), + meshingparameter_description.c_str()) ; - m.def("LoadSTLGeometry", FunctionPointer([] (const string & filename) - { - ifstream ist(filename); - return shared_ptr(STLGeometry::Load(ist)); - }),py::call_guard()); - m.def("GenerateMesh", FunctionPointer([] (shared_ptr geo, MeshingParameters ¶m) - { - auto mesh = make_shared(); - SetGlobalMesh(mesh); - mesh->SetGeometry(geo); - ng_geometry = geo; - try - { - geo->GenerateMesh(mesh,param); - } - catch (NgException ex) - { - cout << "Caught NgException: " << ex.What() << endl; - } - return mesh; - }),py::call_guard()) - ; + m.def("LoadSTLGeometry", [] (const string & filename) + { + cout << "WARNING: LoadSTLGeometry is deprecated, use the STLGeometry(filename) constructor instead!" << endl; + ifstream ist(filename); + return shared_ptr(STLGeometry::Load(ist)); + },py::call_guard()); } PYBIND11_MODULE(libstl, m) { diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 9f4bc635..477befea 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -7,7 +7,7 @@ configure_file(__init__.py ${CMAKE_CURRENT_BINARY_DIR}/__init__.py @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/__init__.py - meshing.py csg.py geom2d.py stl.py gui.py NgOCC.py read_gmsh.py + meshing.py csg.py geom2d.py stl.py gui.py NgOCC.py occ.py read_gmsh.py DESTINATION ${NG_INSTALL_DIR_PYTHON}/${NG_INSTALL_SUFFIX} COMPONENT netgen ) diff --git a/python/NgOCC.py b/python/NgOCC.py index 40f0a51d..da228cdd 100644 --- a/python/NgOCC.py +++ b/python/NgOCC.py @@ -1,10 +1,7 @@ -from netgen.libngpy._NgOCC import * -from netgen.libngpy._meshing import MeshingParameters -def NgOCC_meshing_func (geom, **args): - if "mp" in args: - return GenerateMesh (geom, args["mp"]) - else: - return GenerateMesh (geom, MeshingParameters (**args)) +import logging +logger = logging.getLogger(__name__) -OCCGeometry.GenerateMesh = NgOCC_meshing_func +logger.warn("This module is deprecated and just a wrapper for netgen.occ, import netgen.occ instead") + +from .occ import * diff --git a/python/csg.py b/python/csg.py index f9333179..b53201d7 100644 --- a/python/csg.py +++ b/python/csg.py @@ -1,34 +1,18 @@ -from netgen.libngpy._csg import * -from netgen.libngpy._meshing import MeshingParameters -from netgen.libngpy._meshing import Pnt -from netgen.libngpy._meshing import Vec -from netgen.libngpy._meshing import Trafo - +from .libngpy._csg import * +from .libngpy._meshing import Pnt, Vec, Trafo try: - import libngpy.csgvis as csgvis - from libngpy.csgvis import MouseMove + from . import csgvis + from .csgvis import MouseMove CSGeometry.VS = csgvis.VS SetBackGroundColor = csgvis.SetBackGroundColor del csgvis def VS (obj): return obj.VS() - except: pass - -def csg_meshing_func (geom, **args): - if "mp" in args: - return GenerateMesh (geom, args["mp"]) - else: - return GenerateMesh (geom, MeshingParameters (**args)) -# return GenerateMesh (geom, MeshingParameters (**args)) - -CSGeometry.GenerateMesh = csg_meshing_func - - unit_cube = CSGeometry() p1 = Plane(Pnt(0,0,0),Vec(-1,0,0)).bc("back") p2 = Plane(Pnt(1,1,1),Vec(1,0,0)).bc("front") @@ -37,5 +21,4 @@ p4 = Plane(Pnt(1,1,1),Vec(0,1,0)).bc("right") p5 = Plane(Pnt(0,0,0),Vec(0,0,-1)).bc("bottom") p6 = Plane(Pnt(1,1,1),Vec(0,0,1)).bc("top") unit_cube.Add (p1*p2*p3*p4*p5*p6, col=(0,0,1)) -# unit_cube.Add (OrthoBrick(Pnt(0,0,0), Pnt(1,1,1))) diff --git a/python/geom2d.py b/python/geom2d.py index 34b37870..e5ade0be 100644 --- a/python/geom2d.py +++ b/python/geom2d.py @@ -1,24 +1,11 @@ -from netgen.libngpy._geom2d import * -from netgen.libngpy._meshing import * - -tmp_generate_mesh = SplineGeometry.GenerateMesh - -def geom2d_meshing_func (geom, **args): - if "mp" in args: - return tmp_generate_mesh (geom, args["mp"]) - else: - return tmp_generate_mesh (geom, MeshingParameters (**args)) - - -SplineGeometry.GenerateMesh = geom2d_meshing_func - +from .libngpy._geom2d import SplineGeometry unit_square = SplineGeometry() -pnts = [ (0,0), (1,0), (1,1), (0,1) ] -lines = [ (0,1,1,"bottom"), (1,2,2,"right"), (2,3,3,"top"), (3,0,4,"left") ] -pnums = [unit_square.AppendPoint(*p) for p in pnts] -for l1,l2,bc,bcname in lines: - unit_square.Append( ["line", pnums[l1], pnums[l2]], bc=bcname) +_pnts = [ (0,0), (1,0), (1,1), (0,1) ] +_lines = [ (0,1,1,"bottom"), (1,2,2,"right"), (2,3,3,"top"), (3,0,4,"left") ] +_pnums = [unit_square.AppendPoint(*p) for p in _pnts] +for l1,l2,bc,bcname in _lines: + unit_square.Append( ["line", _pnums[l1], _pnums[l2]], bc=bcname) def MakeRectangle (geo, p1, p2, bc=None, bcs=None, **args): @@ -141,8 +128,4 @@ SplineGeometry.AddSegment = lambda *args, **kwargs : SplineGeometry.Append(*args SplineGeometry.AddPoint = lambda *args, **kwargs : SplineGeometry.AppendPoint(*args, **kwargs) SplineGeometry.CreatePML = CreatePML -__all__ = ['SplineGeometry', 'unit_square'] - - - diff --git a/python/meshing.py b/python/meshing.py index f6ad65ce..7312d686 100644 --- a/python/meshing.py +++ b/python/meshing.py @@ -1 +1 @@ -from netgen.libngpy._meshing import * +from .libngpy._meshing import * diff --git a/python/occ.py b/python/occ.py new file mode 100644 index 00000000..f4764182 --- /dev/null +++ b/python/occ.py @@ -0,0 +1 @@ +from .libngpy._NgOCC import * diff --git a/python/stl.py b/python/stl.py index 032f2b69..66304d1b 100644 --- a/python/stl.py +++ b/python/stl.py @@ -1,12 +1 @@ from netgen.libngpy._stl import * -from netgen.libngpy._meshing import MeshingParameters - - -def stl_meshing_func (geom, **args): - if "mp" in args: - return GenerateMesh (geom, args["mp"]) - else: - return GenerateMesh (geom, MeshingParameters (**args)) -# return GenerateMesh (geom, MeshingParameters (**args)) - -STLGeometry.GenerateMesh = stl_meshing_func