From 7804ece54b1bbc3d2de35a76be2a1e8af9dc385c Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Sun, 31 Aug 2014 12:12:31 +0000 Subject: [PATCH] python export --- libsrc/meshing/meshclass.cpp | 6 +-- libsrc/meshing/meshclass.hpp | 2 +- libsrc/meshing/meshfunc2d.cpp | 2 +- libsrc/meshing/meshtype.cpp | 75 +++++++++++++++--------------- libsrc/meshing/meshtype.hpp | 76 +++++++++++++++++-------------- libsrc/meshing/python_mesh.cpp | 1 + libsrc/stlgeom/meshstlsurface.cpp | 2 +- ng/ngpkg.cpp | 3 +- python/exportNeutral.py | 26 +++++++++++ python/mesh.py | 46 ++----------------- 10 files changed, 118 insertions(+), 121 deletions(-) create mode 100644 python/exportNeutral.py diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index e1c74708..031283b5 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -2922,15 +2922,15 @@ namespace netgen } - void Mesh :: LoadLocalMeshSize (const char * meshsizefilename) + void Mesh :: LoadLocalMeshSize (const string & meshsizefilename) { // Philippose - 10/03/2009 // Improve error checking when loading and reading // the local mesh size file - if (!meshsizefilename) return; + if (meshsizefilename.empty()) return; - ifstream msf(meshsizefilename); + ifstream msf(meshsizefilename.c_str()); // Philippose - 09/03/2009 // Adding print message information in case the specified diff --git a/libsrc/meshing/meshclass.hpp b/libsrc/meshing/meshclass.hpp index 8ed0ec1d..c3db17dd 100644 --- a/libsrc/meshing/meshclass.hpp +++ b/libsrc/meshing/meshclass.hpp @@ -389,7 +389,7 @@ namespace netgen /// DLL_HEADER void RestrictLocalH (resthtype rht, int nr, double loch); /// - DLL_HEADER void LoadLocalMeshSize (const char * meshsizefilename); + DLL_HEADER void LoadLocalMeshSize (const string & meshsizefilename); /// DLL_HEADER void SetGlobalH (double h); /// diff --git a/libsrc/meshing/meshfunc2d.cpp b/libsrc/meshing/meshfunc2d.cpp index c3f2573e..e4549d2d 100644 --- a/libsrc/meshing/meshfunc2d.cpp +++ b/libsrc/meshing/meshfunc2d.cpp @@ -11,7 +11,7 @@ namespace netgen mesh.CalcSurfacesOfNode(); - const char * optstr = mp.optimize2d; + const char * optstr = mp.optimize2d.c_str(); int optsteps = mp.optsteps2d; for (int i = 1; i <= optsteps; i++) diff --git a/libsrc/meshing/meshtype.cpp b/libsrc/meshing/meshtype.cpp index aceedd5b..9687290a 100644 --- a/libsrc/meshing/meshtype.cpp +++ b/libsrc/meshing/meshtype.cpp @@ -2513,41 +2513,41 @@ namespace netgen MeshingParameters :: MeshingParameters () { - optimize3d = "cmdmustm"; + // optimize3d = "cmdmustm"; //optimize3d = "cmdmstm"; - optsteps3d = 3; - optimize2d = "smsmsmSmSmSm"; + // optsteps3d = 3; + // optimize2d = "smsmsmSmSmSm"; // optsteps2d = 3; - opterrpow = 2; - blockfill = 1; - filldist = 0.1; - safety = 5; - relinnersafety = 3; - uselocalh = 1; - grading = 0.3; - delaunay = 1; - maxh = 1e10; - minh = 0; - meshsizefilename = NULL; - startinsurface = 0; - checkoverlap = 1; - checkoverlappingboundary = 1; - checkchartboundary = 1; - curvaturesafety = 2; - segmentsperedge = 1; - parthread = 0; + // opterrpow = 2; + // blockfill = 1; + // filldist = 0.1; + // safety = 5; + // relinnersafety = 3; + // uselocalh = 1; + // grading = 0.3; + // delaunay = 1; + // maxh = 1e10; + // minh = 0; + // meshsizefilename = NULL; + // startinsurface = 0; + // checkoverlap = 1; + // checkoverlappingboundary = 1; + // checkchartboundary = 1; + // curvaturesafety = 2; + // segmentsperedge = 1; + // parthread = 0; - elsizeweight = 0.2; - giveuptol2d = 200; - giveuptol = 10; - maxoutersteps = 10; - starshapeclass = 5; - baseelnp = 0; - sloppy = 1; + // elsizeweight = 0.2; + // giveuptol2d = 200; + // giveuptol = 10; + // maxoutersteps = 10; + // starshapeclass = 5; + // baseelnp = 0; + // sloppy = 1; - badellimit = 175; - check_impossible = 0; - secondorder = 0; + // badellimit = 175; + // check_impossible = 0; + // secondorder = 0; } void MeshingParameters :: Print (ostream & ost) const @@ -2565,12 +2565,9 @@ namespace netgen << " uselocalh = " << uselocalh << endl << " grading = " << grading << endl << " delaunay = " << delaunay << endl - << " maxh = " << maxh << endl; - if(meshsizefilename) - ost << " meshsizefilename = " << meshsizefilename << endl; - else - ost << " meshsizefilename = NULL" << endl; - ost << " startinsurface = " << startinsurface << endl + << " maxh = " << maxh << endl + << " meshsizefilename = " << meshsizefilename << endl + << " startinsurface = " << startinsurface << endl << " checkoverlap = " << checkoverlap << endl << " checkchartboundary = " << checkchartboundary << endl << " curvaturesafety = " << curvaturesafety << endl @@ -2591,6 +2588,7 @@ namespace netgen << " inverttrigs = " << inverttrigs << endl; } + /* void MeshingParameters :: CopyFrom(const MeshingParameters & other) { //strcpy(optimize3d,other.optimize3d); @@ -2610,6 +2608,7 @@ namespace netgen maxh = other.maxh; //strcpy(const_cast(meshsizefilename), other.meshsizefilename); //const_cast(meshsizefilename) = other.meshsizefilename; //??? + meshsizefilename = other.meshsizefilename; startinsurface = other.startinsurface; checkoverlap = other.checkoverlap; checkoverlappingboundary = other.checkoverlappingboundary; @@ -2631,7 +2630,7 @@ namespace netgen inverttets = other.inverttets; inverttrigs = other.inverttrigs; } - + */ DebugParameters :: DebugParameters () { diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index b68ce3ea..c1813849 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -999,6 +999,13 @@ namespace netgen class DLL_HEADER MeshingParameters { public: + + + + + + + /** 3d optimization strategy: // m .. move nodes @@ -1011,7 +1018,7 @@ namespace netgen // h .. Histogramm, no pause // H .. Histogramm, pause */ - string optimize3d; + string optimize3d = "cmdmustm"; /// number of 3d optimization steps int optsteps3d = 3; /** @@ -1023,71 +1030,71 @@ namespace netgen // P .. plot, pause // c .. combine **/ - const char * optimize2d; + string optimize2d = "smsmsmSmSmSm"; /// number of 2d optimization steps - int optsteps2d; + int optsteps2d = 3; /// power of error (to approximate max err optimization) - double opterrpow; + double opterrpow = 2; /// do block filling ? - int blockfill; + int blockfill = 1; /// block filling up to distance - double filldist; + double filldist = 0.1; /// radius of local environment (times h) - double safety; + double safety = 5; /// radius of active environment (times h) - double relinnersafety; + double relinnersafety = 3; /// use local h ? - int uselocalh; + int uselocalh = 1; /// grading for local h - double grading; + double grading = 0.3; /// use delaunay meshing - int delaunay; + int delaunay = 1; /// maximal mesh size - double maxh; + double maxh = 1e10; /// minimal mesh size - double minh; + double minh = 0.0; /// file for meshsize - const char * meshsizefilename; + string meshsizefilename = ""; /// start surfacemeshing from everywhere in surface - int startinsurface; + int startinsurface = 0; /// check overlapping surfaces (debug) - int checkoverlap; + int checkoverlap = 1; /// check overlapping surface mesh before volume meshing - int checkoverlappingboundary; + int checkoverlappingboundary = 1; /// check chart boundary (sometimes too restrictive) - int checkchartboundary; + int checkchartboundary = 1; /// safty factor for curvatures (elemetns per radius) - double curvaturesafety; + double curvaturesafety = 2; /// minimal number of segments per edge - double segmentsperedge; + double segmentsperedge = 1; /// use parallel threads - int parthread; + int parthread = 0; /// weight of element size w.r.t element shape - double elsizeweight; + double elsizeweight = 0.2; /// init with default values /// from mp3: /// give up quality class, 2d meshing - int giveuptol2d; + int giveuptol2d = 200; /// give up quality class, 3d meshing - int giveuptol; + int giveuptol = 10; /// maximal outer steps - int maxoutersteps; + int maxoutersteps = 10; /// class starting star-shape filling - int starshapeclass; + int starshapeclass = 5; /// if non-zero, baseelement must have baseelnp points - int baseelnp; + int baseelnp = 0; /// quality tolerances are handled less careful - int sloppy; + int sloppy = 1; /// limit for max element angle (150-180) - double badellimit; + double badellimit = 175; - bool check_impossible; + bool check_impossible = 0; /// - int secondorder; + int secondorder = 0; /// high order element curvature int elementorder; /// quad-dominated surface meshing @@ -1101,9 +1108,12 @@ namespace netgen /// MeshingParameters (); /// + MeshingParameters (const MeshingParameters & mp2) = default; + /// void Print (ostream & ost) const; - - void CopyFrom(const MeshingParameters & other); + /// + // void CopyFrom(const MeshingParameters & other); + void (*render_function)() = NULL; void Render() diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index d1aca4fd..465d0af3 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -100,6 +100,7 @@ void ExportNetgenMeshing() ; bp::class_("Element3D") + .add_property("index", &Element::GetIndex, &Element::SetIndex) .add_property("vertices", FunctionPointer ([](const Element & self) -> bp::list { diff --git a/libsrc/stlgeom/meshstlsurface.cpp b/libsrc/stlgeom/meshstlsurface.cpp index 53cd79e7..0ab58429 100644 --- a/libsrc/stlgeom/meshstlsurface.cpp +++ b/libsrc/stlgeom/meshstlsurface.cpp @@ -756,7 +756,7 @@ void STLSurfaceOptimization (STLGeometry & geom, PrintMessage(5,"optimize string = ", meshparam.optimize2d, " elsizew = ", meshparam.elsizeweight); for (int i = 1; i <= meshparam.optsteps2d; i++) - for (size_t j = 1; j <= strlen(meshparam.optimize2d); j++) + for (size_t j = 1; j <= meshparam.optimize2d.length(); j++) { if (multithread.terminate) break; diff --git a/ng/ngpkg.cpp b/ng/ngpkg.cpp index b3e2354b..cbb5f0c9 100644 --- a/ng/ngpkg.cpp +++ b/ng/ngpkg.cpp @@ -1130,8 +1130,7 @@ namespace netgen mparam.minh = atof (Tcl_GetVar (interp, "::options.minmeshsize", 0)); mparam.meshsizefilename = Tcl_GetVar (interp, "::options.meshsizefilename", 0); - if (!strlen (mparam.meshsizefilename)) - mparam.meshsizefilename = NULL; + // if (!strlen (mparam.meshsizefilename)) mparam.meshsizefilename = NULL; mparam.curvaturesafety = atof (Tcl_GetVar (interp, "::options.curvaturesafety", 0)); mparam.segmentsperedge = atof (Tcl_GetVar (interp, "::options.segmentsperedge", 0)); diff --git a/python/exportNeutral.py b/python/exportNeutral.py new file mode 100644 index 00000000..ad58ea41 --- /dev/null +++ b/python/exportNeutral.py @@ -0,0 +1,26 @@ +import sys + +def Export (mesh, filename): + """ export Netgen mesh to neutral format """ + + print ("export mesh in neutral format to file = ", filename) + + f = open (filename, 'w') + + points = mesh.Points() + print (len(points), file=f) + for p in points: + print (p.p[0], p.p[1], p.p[2], file=f) + + + volels = mesh.Elements3D(); + print (len(volels), file=f) + for el in volels: + print (el.index, end=" ", file=f) + for j in el.vertices: + print (j.nr, end=" ", file=f) + print(file=f) + + + + diff --git a/python/mesh.py b/python/mesh.py index 4dc09c41..f599c39a 100644 --- a/python/mesh.py +++ b/python/mesh.py @@ -5,55 +5,17 @@ from libmesh.meshing import * from libcsg.csg import * -geo = CSGeometry("cube.geo") -geo.ntlo - +geo = CSGeometry("shaft.geo") param = MeshingParameters() -# param.maxh = 100 +param.maxh = 10 print (param) m1 = GenerateMesh (geo, param) -for el in m1.Elements3D(): - vi = el.vertices - for j in vi: - print (j.nr, m1[j].p) - print () - - -print ("num points = ", len (m1.Points())) - -for p in m1.Points(): - print (p.p) - - -m2 = Mesh() - -for p in m1.Points(): - l = p.p - print (l) - m2.Add ( MeshPoint (Point(l[0],l[1],l[2])) ) - -print ("Mesh2 is ", m2) +import exportNeutral +exportNeutral.Export (m1, "shaft.mesh") -# els = [ i for i in m1.Elements3D() ] -# for i in els: -# print (i.vertices) - -# m1.Save("pymesh.vol") - -# mesh = Mesh() -# mesh.Load ("shaft.vol.gz") -# els = mesh.Elements3D() - - -#cnt = 0 -# for el in mesh.Elements3D(): -# print ("el ", cnt, " has vertices " , el.vertices) -# cnt = cnt+1 - -