From e2cf4ea59196bc62781e6677b0bff6b4b97c5032 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Sat, 30 Aug 2014 00:15:59 +0000 Subject: [PATCH] closed modules --- configure.ac | 5 +- libsrc/csg/Makefile.am | 3 +- libsrc/csg/algprim.cpp | 3 +- libsrc/csg/algprim.hpp | 4 +- libsrc/csg/csgpkg.cpp | 8 +- libsrc/csg/edgeflw.cpp | 15 ++-- libsrc/csg/edgeflw.hpp | 4 +- libsrc/csg/genmesh.cpp | 29 +++--- libsrc/csg/meshsurf.cpp | 4 +- libsrc/csg/meshsurf.hpp | 4 +- libsrc/csg/python_csg.cpp | 95 ++++++++++++++++++++ libsrc/csg/specpoin.hpp | 2 +- libsrc/csg/surface.cpp | 5 +- libsrc/csg/surface.hpp | 4 +- libsrc/interface/nginterface.cpp | 9 +- libsrc/interface/writeOpenFOAM15x.cpp | 2 + libsrc/interface/writediffpack.cpp | 2 +- libsrc/interface/writeelmer.cpp | 3 +- libsrc/interface/writefeap.cpp | 2 + libsrc/interface/writegmsh.cpp | 5 +- libsrc/interface/writegmsh2.cpp | 4 +- libsrc/interface/writejcm.cpp | 2 +- libsrc/interface/writeuser.cpp | 11 ++- libsrc/interface/writeuser.hpp | 20 ++--- libsrc/meshing/Makefile.am | 5 +- libsrc/meshing/bisect.cpp | 2 +- libsrc/meshing/bisect.hpp | 6 +- libsrc/meshing/global.cpp | 29 ++++++ libsrc/meshing/meshclass.cpp | 17 ++-- libsrc/meshing/meshing.hpp | 2 +- libsrc/meshing/meshtool.cpp | 2 +- libsrc/meshing/meshtool.hpp | 2 +- libsrc/meshing/meshtype.hpp | 7 ++ libsrc/meshing/python_mesh.cpp | 125 ++++++++++++++++++++++++++ libsrc/meshing/smoothing3.cpp | 2 +- ng/ngappinit.cpp | 2 + ng/ngpkg.cpp | 11 ++- nglib/nglib.cpp | 12 +-- 38 files changed, 382 insertions(+), 87 deletions(-) create mode 100644 libsrc/csg/python_csg.cpp create mode 100644 libsrc/meshing/python_mesh.cpp diff --git a/configure.ac b/configure.ac index e0a7d84f..b75e5530 100644 --- a/configure.ac +++ b/configure.ac @@ -15,6 +15,7 @@ AC_DISABLE_STATIC AC_LANG([C++]) AC_PROG_CXX +AX_CXX_COMPILE_STDCXX_11 AC_OPENMP CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS" @@ -147,13 +148,15 @@ AC_ARG_ENABLE([mkl], AM_PATH_PYTHON([3.2]) AX_PYTHON_DEVEL([>= '3.2']) +AX_BOOST_BASE([1.55]) +AX_BOOST_PYTHON pythonon=false AC_ARG_ENABLE([python], [AS_HELP_STRING([--enable-python],[link boost python, necessary for ngsolve])], [if test "$enableval" = yes; then pythonon=true; else pythonon=false; fi] [CXXFLAGS+=" $PYTHON_CPPFLAGS -DNGPYTHON"] - [LDFLAGS+=" $PYTHON_LDFLAGS"] + [LDFLAGS+=" $PYTHON_LDFLAGS -l$BOOST_PYTHON_LIB"] ) diff --git a/libsrc/csg/Makefile.am b/libsrc/csg/Makefile.am index dc40cec9..b0fe2dd6 100644 --- a/libsrc/csg/Makefile.am +++ b/libsrc/csg/Makefile.am @@ -15,7 +15,8 @@ libcsg_la_SOURCES = algprim.cpp brick.cpp \ bspline2d.cpp csgeom.cpp csgparser.cpp curve2d.cpp edgeflw.cpp \ explicitcurve2d.cpp extrusion.cpp gencyl.cpp genmesh.cpp identify.cpp \ manifold.cpp meshsurf.cpp polyhedra.cpp revolution.cpp singularref.cpp \ -solid.cpp specpoin.cpp spline3d.cpp surface.cpp triapprox.cpp +solid.cpp specpoin.cpp spline3d.cpp surface.cpp triapprox.cpp zrefine.cpp \ +python_csg.cpp libcsg_la_LIBADD = $(top_builddir)/libsrc/meshing/libmesh.la diff --git a/libsrc/csg/algprim.cpp b/libsrc/csg/algprim.cpp index 31f014cc..17dff2fe 100644 --- a/libsrc/csg/algprim.cpp +++ b/libsrc/csg/algprim.cpp @@ -1404,7 +1404,8 @@ namespace netgen double Cone :: LocH (const Point<3> & p, double /* x */, - double /* c */, double hmax) const + double /* c */, + const MeshingParameters & mparam, double hmax) const { //double bloch = Surface::LocH (p, x, c, hmax); Vec<3> g; diff --git a/libsrc/csg/algprim.hpp b/libsrc/csg/algprim.hpp index 82cd58e7..8d7ca839 100644 --- a/libsrc/csg/algprim.hpp +++ b/libsrc/csg/algprim.hpp @@ -341,7 +341,9 @@ namespace netgen virtual double HesseNorm () const; virtual double LocH (const Point<3> & p, double x, - double c, double hmax) const; + double c, + const MeshingParameters & mparam, + double hmax) const; /// virtual Point<3> GetSurfacePoint () const; diff --git a/libsrc/csg/csgpkg.cpp b/libsrc/csg/csgpkg.cpp index 589d12ff..4ccce206 100644 --- a/libsrc/csg/csgpkg.cpp +++ b/libsrc/csg/csgpkg.cpp @@ -511,9 +511,9 @@ namespace netgen return TCL_ERROR; } - double globh = mparam.maxh; + // double globh = mparam.maxh; for (int i = 1; i <= geometry->singedges.Size(); i++) - geometry->singedges.Get(i)->SetMeshSize (*mesh, globh); + geometry->singedges.Get(i)->SetMeshSize (*mesh, 1e99 /* globh*/); return TCL_OK; } @@ -529,9 +529,9 @@ namespace netgen return TCL_ERROR; } - double globh = mparam.maxh; + // double globh = mparam.maxh; for (int i = 1; i <= geometry->singpoints.Size(); i++) - geometry->singpoints.Get(i)->SetMeshSize (*mesh, globh); + geometry->singpoints.Get(i)->SetMeshSize (*mesh, 1e99 /* globh */ ); return TCL_OK; } diff --git a/libsrc/csg/edgeflw.cpp b/libsrc/csg/edgeflw.cpp index edb943f3..d567532b 100644 --- a/libsrc/csg/edgeflw.cpp +++ b/libsrc/csg/edgeflw.cpp @@ -10,8 +10,9 @@ namespace netgen EdgeCalculation :: EdgeCalculation (const CSGeometry & ageometry, - Array & aspecpoints) - : geometry(ageometry), specpoints(aspecpoints) + Array & aspecpoints, + MeshingParameters & amparam) + : geometry(ageometry), specpoints(aspecpoints), mparam(amparam) { Box<3> bbox = geometry.BoundingBox(); @@ -698,8 +699,8 @@ namespace netgen // (*testout) << "geometry.GetSurface(s1) -> LocH (p, 3, 1, h) " << geometry.GetSurface(s1) -> LocH (p, 3, 1, h) // << " geometry.GetSurface(s2) -> LocH (p, 3, 1, h) " << geometry.GetSurface(s2) -> LocH (p, 3, 1, h) << endl; - loch = min2 (geometry.GetSurface(s1) -> LocH (p, 3, 1, h), - geometry.GetSurface(s2) -> LocH (p, 3, 1, h)); + loch = min2 (geometry.GetSurface(s1) -> LocH (p, 3, 1, mparam, h), + geometry.GetSurface(s2) -> LocH (p, 3, 1, mparam, h)); @@ -848,8 +849,8 @@ namespace netgen } */ - loch = min2 (geometry.GetSurface(s1_rep) -> LocH (np, 3, 1, h), - geometry.GetSurface(s2_rep) -> LocH (np, 3, 1, h)); + loch = min2 (geometry.GetSurface(s1_rep) -> LocH (np, 3, 1, mparam, h), + geometry.GetSurface(s2_rep) -> LocH (np, 3, 1, mparam, h)); loch = max2 (loch, mparam.minh); if (uselocalh) @@ -1736,7 +1737,7 @@ namespace netgen Vec<3> nv = s -> GetNormalVector (p1); double hloc = - min2 (s->LocH (p1, 3, 1, h), mesh.GetH(p1)); + min2 (s->LocH (p1, 3, 1, mparam, h), mesh.GetH(p1)); diff --git a/libsrc/csg/edgeflw.hpp b/libsrc/csg/edgeflw.hpp index 4c2fc949..f9bfdb97 100644 --- a/libsrc/csg/edgeflw.hpp +++ b/libsrc/csg/edgeflw.hpp @@ -42,10 +42,12 @@ namespace netgen int cntedge; double ideps; + MeshingParameters & mparam; public: EdgeCalculation (const CSGeometry & ageometry, - Array & aspecpoints); + Array & aspecpoints, + MeshingParameters & amparam); ~EdgeCalculation(); diff --git a/libsrc/csg/genmesh.cpp b/libsrc/csg/genmesh.cpp index 5e891639..9684e7ea 100644 --- a/libsrc/csg/genmesh.cpp +++ b/libsrc/csg/genmesh.cpp @@ -60,9 +60,10 @@ namespace netgen - static void FindEdges (CSGeometry & geom, Mesh & mesh, const bool setmeshsize = false) + static void FindEdges (CSGeometry & geom, Mesh & mesh, MeshingParameters & mparam, + const bool setmeshsize = false) { - EdgeCalculation ec (geom, specpoints); + EdgeCalculation ec (geom, specpoints, mparam); ec.SetIdEps(geom.GetIdEps()); ec.Calc (mparam.maxh, mesh); @@ -215,11 +216,11 @@ namespace netgen } + + - - - static void MeshSurface (CSGeometry & geom, Mesh & mesh) + static void MeshSurface (CSGeometry & geom, Mesh & mesh, MeshingParameters & mparam) { const char * savetask = multithread.task; multithread.task = "Surface meshing"; @@ -561,8 +562,7 @@ namespace netgen PrintMessage (3, (mesh.GetNSE() - oldnf), " elements, ", mesh.GetNP(), " points"); - extern void Render(); - Render(); + mparam.Render(); } mesh.Compress(); @@ -639,8 +639,7 @@ namespace netgen PrintMessage (3, (mesh.GetNSE() - oldnf), " elements, ", mesh.GetNP(), " points"); } - extern void Render(); - Render(); + mparam.Render(); } while (changed); @@ -709,7 +708,7 @@ namespace netgen if (perfstepsstart <= MESHCONST_MESHEDGES) { - FindEdges (geom, *mesh, true); + FindEdges (geom, *mesh, mparam, true); if (multithread.terminate) return TCL_OK; #ifdef LOG_STREAM (*logout) << "Edges meshed" << endl @@ -728,14 +727,14 @@ namespace netgen FindPoints (geom, *mesh); if (multithread.terminate) return TCL_OK; - FindEdges (geom, *mesh, true); + FindEdges (geom, *mesh, mparam, true); if (multithread.terminate) return TCL_OK; mesh->DeleteMesh(); FindPoints (geom, *mesh); if (multithread.terminate) return TCL_OK; - FindEdges (geom, *mesh); + FindEdges (geom, *mesh, mparam); if (multithread.terminate) return TCL_OK; } } @@ -746,7 +745,7 @@ namespace netgen if (perfstepsstart <= MESHCONST_MESHSURFACE) { - MeshSurface (geom, *mesh); + MeshSurface (geom, *mesh, mparam); if (multithread.terminate) return TCL_OK; #ifdef LOG_STREAM @@ -762,10 +761,10 @@ namespace netgen FindPoints (geom, *mesh); if (multithread.terminate) return TCL_OK; - FindEdges (geom, *mesh); + FindEdges (geom, *mesh, mparam); if (multithread.terminate) return TCL_OK; - MeshSurface (geom, *mesh); + MeshSurface (geom, *mesh, mparam); if (multithread.terminate) return TCL_OK; } diff --git a/libsrc/csg/meshsurf.cpp b/libsrc/csg/meshsurf.cpp index 19e12eb2..b04d478a 100644 --- a/libsrc/csg/meshsurf.cpp +++ b/libsrc/csg/meshsurf.cpp @@ -17,7 +17,7 @@ Meshing2Surfaces :: Meshing2Surfaces (const Surface & asurface) Meshing2Surfaces :: Meshing2Surfaces (const Surface & asurf, const MeshingParameters & mp, const Box<3> & abb) - : Meshing2(mp, abb), surface(asurf) + : Meshing2(mp, abb), surface(asurf), mparam (mp) { ; } @@ -58,7 +58,7 @@ int Meshing2Surfaces :: TransformFromPlain (Point2d & planepoint, double Meshing2Surfaces :: CalcLocalH (const Point3d & p, double gh) const { - return surface.LocH (p, 3, 1, gh); + return surface.LocH (p, 3, 1, mparam, gh); /* double loch = mesh.lochfunc->GetH(p); if (gh < loch) loch = gh; diff --git a/libsrc/csg/meshsurf.hpp b/libsrc/csg/meshsurf.hpp index e6c69225..39fb24bb 100644 --- a/libsrc/csg/meshsurf.hpp +++ b/libsrc/csg/meshsurf.hpp @@ -9,7 +9,9 @@ namespace netgen { /// const Surface & surface; - + + /// should be movec to base ... + const MeshingParameters & mparam; public: /// // Meshing2Surfaces (const Surface & asurf); diff --git a/libsrc/csg/python_csg.cpp b/libsrc/csg/python_csg.cpp new file mode 100644 index 00000000..09d68b95 --- /dev/null +++ b/libsrc/csg/python_csg.cpp @@ -0,0 +1,95 @@ +#include + +#include + + +using namespace netgen; +namespace bp = boost::python; + + +////////////////////////////////////////////////////////////////////// +// Lambda to function pointer conversion +template +struct function_traits + : public function_traits {}; + +template +struct function_traits { + typedef ReturnType (*pointer)(Args...); + typedef ReturnType return_type; +}; + +template +typename function_traits::pointer +FunctionPointer (const Function& lambda) { + return static_cast::pointer>(lambda); +} + + +template +inline string ToString (const T& t) +{ + stringstream ss; + ss << t; + return ss.str(); +} + + + +namespace netgen +{ + extern CSGeometry * ParseCSG (istream & istr); +} + +void ExportCSG() +{ + + std::string nested_name = "csg"; + if( bp::scope() ) + nested_name = bp::extract(bp::scope().attr("__name__") + ".csg"); + + bp::object module(bp::handle<>(bp::borrowed(PyImport_AddModule(nested_name.c_str())))); + + cout << "exporting csg " << nested_name << endl; + bp::object parent = bp::scope() ? bp::scope() : bp::import("__main__"); + parent.attr("csg") = module ; + + bp::scope local_scope(module); + + + + bp::class_ ("CSGeometry") + .def("__init__", bp::make_constructor (FunctionPointer + ([](const string & filename) + { + cout << "load geometry"; + ifstream ist(filename); + shared_ptr geom(ParseCSG(ist)); + geom -> FindIdenticSurfaces(1e-8 * geom->MaxSize()); + return geom; + }))) + .add_property ("ntlo", &CSGeometry::GetNTopLevelObjects) + ; + + + bp::def("GenerateMesh", FunctionPointer + ([](CSGeometry & geo, MeshingParameters & param) + { + Mesh * dummy = NULL; + cout << "Genrate Mesh, params = "; // << param << endl; + geo.GenerateMesh (dummy, param, 0, 6); + return shared_ptr (dummy); + })); + +} + + + + + +BOOST_PYTHON_MODULE(libcsg) { + ExportCSG(); +} + + + diff --git a/libsrc/csg/specpoin.hpp b/libsrc/csg/specpoin.hpp index a6d850c9..5b44f6a0 100644 --- a/libsrc/csg/specpoin.hpp +++ b/libsrc/csg/specpoin.hpp @@ -11,7 +11,7 @@ namespace netgen { - extern DLL_HEADER MeshingParameters mparam; + // extern DLL_HEADER MeshingParameters mparam; /* diff --git a/libsrc/csg/surface.cpp b/libsrc/csg/surface.cpp index fe0415ec..db315e99 100644 --- a/libsrc/csg/surface.cpp +++ b/libsrc/csg/surface.cpp @@ -163,8 +163,9 @@ MaxCurvatureLoc (const Point<3> & /* c */ , double /* rad */) const -double Surface :: LocH (const Point<3> & p, double x, - double c, double hmax) const +double Surface :: LocH (const Point<3> & p, double x, double c, + const MeshingParameters & mparam, + double hmax) const // finds h <= hmax, s.t. h * \kappa_x*h < c { /* diff --git a/libsrc/csg/surface.hpp b/libsrc/csg/surface.hpp index 21821241..f98eeb5c 100644 --- a/libsrc/csg/surface.hpp +++ b/libsrc/csg/surface.hpp @@ -176,7 +176,9 @@ namespace netgen \[ h \times \kappa (x) \leq c \qquad \mbox{in} B(x, h), \] where kappa(x) is the curvature in x. */ virtual double LocH (const Point<3> & p, double x, - double c, double hmax) const; + double c, + const MeshingParameters & mparam, + double hmax) const; /** Gets Approximation by triangles, diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index 066ffe46..330770b8 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -61,7 +61,12 @@ void RunParallel ( void* (*fun)(void *), void * in) #else // For #ifdef _MSC_VER // #include - + +namespace netgen +{ + MeshingParameters mparam; +} + static pthread_t meshingthread; void RunParallel ( void * (*fun)(void *), void * in) { @@ -99,8 +104,6 @@ namespace netgen { #include "writeuser.hpp" - MeshingParameters mparam; - // global variable mesh (should not be used in libraries) AutoPtr mesh; // NetgenGeometry * ng_geometry = NULL; // new NetgenGeometry; diff --git a/libsrc/interface/writeOpenFOAM15x.cpp b/libsrc/interface/writeOpenFOAM15x.cpp index a2541dae..d485a26b 100644 --- a/libsrc/interface/writeOpenFOAM15x.cpp +++ b/libsrc/interface/writeOpenFOAM15x.cpp @@ -35,6 +35,8 @@ namespace netgen { #include "writeuser.hpp" + extern MeshingParameters & mparam; + // Global arrays used to maintain the owner, neighbour and face lists // so that they are accessible across functions static Array owner_facelist; diff --git a/libsrc/interface/writediffpack.cpp b/libsrc/interface/writediffpack.cpp index 07a21b2a..c7bf4989 100644 --- a/libsrc/interface/writediffpack.cpp +++ b/libsrc/interface/writediffpack.cpp @@ -20,7 +20,7 @@ namespace netgen void WriteDiffPackFormat (const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const string & filename) { // double scale = globflags.GetNumFlag ("scale", 1); diff --git a/libsrc/interface/writeelmer.cpp b/libsrc/interface/writeelmer.cpp index 664a6dad..22644190 100644 --- a/libsrc/interface/writeelmer.cpp +++ b/libsrc/interface/writeelmer.cpp @@ -17,10 +17,11 @@ namespace netgen { #include "writeuser.hpp" + extern MeshingParameters & mparam; void WriteElmerFormat (const Mesh &mesh, - const string &filename) + const string &filename) { cout << "write elmer mesh files" << endl; int np = mesh.GetNP(); diff --git a/libsrc/interface/writefeap.cpp b/libsrc/interface/writefeap.cpp index 85681aa0..975ffa14 100644 --- a/libsrc/interface/writefeap.cpp +++ b/libsrc/interface/writefeap.cpp @@ -16,6 +16,8 @@ namespace netgen { + extern MeshingParameters & mparam; + #include "writeuser.hpp" diff --git a/libsrc/interface/writegmsh.cpp b/libsrc/interface/writegmsh.cpp index 93def677..431b55bd 100644 --- a/libsrc/interface/writegmsh.cpp +++ b/libsrc/interface/writegmsh.cpp @@ -22,6 +22,7 @@ namespace netgen { #include "writeuser.hpp" + extern MeshingParameters & mparam; /* @@ -30,8 +31,8 @@ namespace netgen */ void WriteGmshFormat (const Mesh & mesh, - const CSGeometry & geom, - const string & filename) + const NetgenGeometry & geom, + const string & filename) { ofstream outfile (filename.c_str()); outfile.precision(6); diff --git a/libsrc/interface/writegmsh2.cpp b/libsrc/interface/writegmsh2.cpp index 5ec3dc8f..8d7ad858 100644 --- a/libsrc/interface/writegmsh2.cpp +++ b/libsrc/interface/writegmsh2.cpp @@ -25,6 +25,8 @@ namespace netgen { #include "writeuser.hpp" + extern MeshingParameters & mparam; + // Mapping of entities from Netgen definitions to GMSH definitions enum GMSH_ELEMENTS {GMSH_TRIG = 2, GMSH_TRIG6 = 9, GMSH_QUAD = 3, GMSH_QUAD8 = 16, @@ -46,7 +48,7 @@ namespace netgen * */ void WriteGmsh2Format (const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const string & filename) { ofstream outfile (filename.c_str()); diff --git a/libsrc/interface/writejcm.cpp b/libsrc/interface/writejcm.cpp index 7517b179..69ed2b7a 100644 --- a/libsrc/interface/writejcm.cpp +++ b/libsrc/interface/writejcm.cpp @@ -16,7 +16,7 @@ namespace netgen #include "writeuser.hpp" void WriteJCMFormat (const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const string & filename) { if (mesh.GetDimension() != 3) diff --git a/libsrc/interface/writeuser.cpp b/libsrc/interface/writeuser.cpp index 92ee1bf8..96cd5af4 100644 --- a/libsrc/interface/writeuser.cpp +++ b/libsrc/interface/writeuser.cpp @@ -14,6 +14,8 @@ namespace netgen { #include "writeuser.hpp" + extern MeshingParameters & mparam; + void RegisterUserFormats (Array & names, Array & extensions) @@ -157,7 +159,7 @@ bool WriteUserFormat (const string & format, */ void WriteNeutralFormat (const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const string & filename) { cout << "write neutral, new" << endl; @@ -617,7 +619,7 @@ void WriteVRMLFormat (const Mesh & mesh, * FEPP .. a finite element package developed at University Linz, Austria */ void WriteFEPPFormat (const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const string & filename) { @@ -708,7 +710,7 @@ void WriteFEPPFormat (const Mesh & mesh, } */ - + /* // write CSG surfaces if (&geom && geom.GetNSurf() >= ns) { @@ -717,6 +719,7 @@ void WriteFEPPFormat (const Mesh & mesh, geom.GetSurface(mesh.GetFaceDescriptor(i).SurfNr())->Print(outfile); } else + */ outfile << "0" << endl; } @@ -747,7 +750,7 @@ void WriteFEPPFormat (const Mesh & mesh, */ void WriteEdgeElementFormat (const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const string & filename) { cout << "write edge element format" << endl; diff --git a/libsrc/interface/writeuser.hpp b/libsrc/interface/writeuser.hpp index 7021a5f6..a1e27c86 100644 --- a/libsrc/interface/writeuser.hpp +++ b/libsrc/interface/writeuser.hpp @@ -11,7 +11,7 @@ extern void WriteFile (int typ, const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const char * filename, const char * geomfile = NULL, double h = 0); @@ -29,7 +29,7 @@ void ReadFile (Mesh & mesh, extern void WriteNeutralFormat (const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const string & filename); extern @@ -57,19 +57,19 @@ void WriteVRMLFormat (const Mesh & mesh, extern void WriteFEPPFormat (const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const string & filename); extern void WriteGmshFormat (const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const string & filename); // Philippose - 29/01/2009 // Added GMSH v2.xx Mesh Export support void WriteGmsh2Format (const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const string & filename); @@ -78,7 +78,7 @@ void WriteGmsh2Format (const Mesh & mesh, extern void WriteOpenFOAM15xFormat (const Mesh & mesh, const string & casename, - const bool compressed); + const bool compressed); extern @@ -87,13 +87,13 @@ void WriteUserChemnitz (const Mesh & mesh, extern void WriteJCMFormat (const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const string & filename); extern void WriteDiffPackFormat (const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const string & filename); extern @@ -102,7 +102,7 @@ void WriteTochnogFormat (const Mesh & mesh, extern void WriteTecPlotFormat (const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const string & filename); extern @@ -128,7 +128,7 @@ void WriteElmerFormat (const Mesh & mesh, extern void WriteEdgeElementFormat (const Mesh & mesh, - const CSGeometry & geom, + const NetgenGeometry & geom, const string & filename); diff --git a/libsrc/meshing/Makefile.am b/libsrc/meshing/Makefile.am index 3ea043cc..88549516 100644 --- a/libsrc/meshing/Makefile.am +++ b/libsrc/meshing/Makefile.am @@ -27,8 +27,9 @@ libmesh_la_SOURCES = adfront2.cpp adfront3.cpp bisect.cpp boundarylayer.cpp \ pyramid2rls.cpp pyramidrls.cpp quadrls.cpp refine.cpp \ ruler2.cpp ruler3.cpp secondorder.cpp smoothing2.5.cpp \ smoothing2.cpp smoothing3.cpp specials.cpp tetrarls.cpp \ - topology.cpp triarls.cpp validate.cpp zrefine.cpp bcfunctions.cpp \ - parallelmesh.cpp paralleltop.cpp paralleltop.hpp basegeom.cpp + topology.cpp triarls.cpp validate.cpp bcfunctions.cpp \ + parallelmesh.cpp paralleltop.cpp paralleltop.hpp basegeom.cpp \ + python_mesh.cpp libmesh_la_LIBADD = $(top_builddir)/libsrc/linalg/libla.la \ $(top_builddir)/libsrc/gprim/libgprim.la \ diff --git a/libsrc/meshing/bisect.cpp b/libsrc/meshing/bisect.cpp index da8270a5..da993a2f 100644 --- a/libsrc/meshing/bisect.cpp +++ b/libsrc/meshing/bisect.cpp @@ -1909,7 +1909,7 @@ namespace netgen - void BisectTetsCopyMesh (Mesh & mesh, const class CSGeometry *, + void BisectTetsCopyMesh (Mesh & mesh, const NetgenGeometry *, BisectionOptions & opt, const Array< Array* > & idmaps, const string & refinfofile) diff --git a/libsrc/meshing/bisect.hpp b/libsrc/meshing/bisect.hpp index 2da9b97e..8d375a12 100644 --- a/libsrc/meshing/bisect.hpp +++ b/libsrc/meshing/bisect.hpp @@ -23,12 +23,8 @@ public: }; -/* -extern void BisectTets (Mesh &, const CSGeometry *, - BisectionOptions & opt); -*/ -extern void BisectTetsCopyMesh (Mesh &, const class CSGeometry *, +extern void BisectTetsCopyMesh (Mesh &, const NetgenGeometry *, BisectionOptions & opt); extern void ZRefinement (Mesh &, const class NetgenGeometry *, diff --git a/libsrc/meshing/global.cpp b/libsrc/meshing/global.cpp index 477c84e8..7208c24f 100644 --- a/libsrc/meshing/global.cpp +++ b/libsrc/meshing/global.cpp @@ -27,6 +27,35 @@ namespace netgen string ngdir = "."; + // parallel netgen + int id = 0, ntasks = 1; + + + void Ng_PrintDest(const char * s) + { + if (id == 0) + (*mycout) << s << flush; + } + + DLL_HEADER void MyError(const char * ch) + { + cout << ch; + (*testout) << "Error !!! " << ch << endl << flush; + } + + static clock_t starttimea; + void ResetTime () + { + starttimea = clock(); + } + + double GetTime () + { + return double(clock() - starttimea) / CLOCKS_PER_SEC; + } + + + Array tets_in_qualclass; int h_argc = 0; diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 79ac1545..e1c74708 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -773,12 +773,20 @@ namespace netgen void Mesh :: Load (const string & filename) { + cout << "filename = " << filename << endl; + istream * infile = NULL; - ifstream infile(filename.c_str()); - if (!infile.good()) + if (filename.find(".vol.gz") != string::npos) + infile = new igzstream (filename.c_str()); + else + infile = new ifstream (filename.c_str()); + + // ifstream infile(filename.c_str()); + if (! (infile -> good()) ) throw NgException ("mesh file not found"); - Load(infile); + Load(*infile); + delete infile; } @@ -786,7 +794,6 @@ namespace netgen void Mesh :: Load (istream & infile) { - char str[100]; int i, n; @@ -798,11 +805,11 @@ namespace netgen facedecoding.SetSize(0); bool endmesh = false; + while (infile.good() && !endmesh) { infile >> str; - if (strcmp (str, "dimension") == 0) { infile >> dimension; diff --git a/libsrc/meshing/meshing.hpp b/libsrc/meshing/meshing.hpp index 7fd9c196..c1c3dbd1 100644 --- a/libsrc/meshing/meshing.hpp +++ b/libsrc/meshing/meshing.hpp @@ -14,7 +14,7 @@ namespace netgen { // extern int printmessage_importance; - class CSGeometry; + // class CSGeometry; class NetgenGeometry; } diff --git a/libsrc/meshing/meshtool.cpp b/libsrc/meshing/meshtool.cpp index 271b8747..b807cb1a 100644 --- a/libsrc/meshing/meshtool.cpp +++ b/libsrc/meshing/meshtool.cpp @@ -749,7 +749,7 @@ namespace netgen void SaveVolumeMesh (const Mesh & mesh, - const CSGeometry & geometry, + const NetgenGeometry & geometry, char * filename) { INDEX i; diff --git a/libsrc/meshing/meshtool.hpp b/libsrc/meshing/meshtool.hpp index b6472ce0..1da22bb0 100644 --- a/libsrc/meshing/meshtool.hpp +++ b/libsrc/meshing/meshtool.hpp @@ -38,7 +38,7 @@ extern void SaveVolumeMesh ( /// void SaveVolumeMesh (const Mesh & mesh, - const class CSGeometry & geometry, + const class NetgenGeometry & geometry, char * filename); /// diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 04485eb4..ba01c166 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -1104,6 +1104,13 @@ namespace netgen void Print (ostream & ost) const; void CopyFrom(const MeshingParameters & other); + + void (*render_function)() = NULL; + void Render() + { + if (render_function) + (*render_function)(); + } }; diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp new file mode 100644 index 00000000..dfe7b4d8 --- /dev/null +++ b/libsrc/meshing/python_mesh.cpp @@ -0,0 +1,125 @@ +#include + +#include +#include "meshing.hpp" + + +using namespace netgen; +namespace bp = boost::python; + + +////////////////////////////////////////////////////////////////////// +// Lambda to function pointer conversion +template +struct function_traits + : public function_traits {}; + +template +struct function_traits { + typedef ReturnType (*pointer)(Args...); + typedef ReturnType return_type; +}; + +template +typename function_traits::pointer +FunctionPointer (const Function& lambda) { + return static_cast::pointer>(lambda); +} + + +template +inline string ToString (const T& t) +{ + stringstream ss; + ss << t; + return ss.str(); +} + + + +template +void ExportArray () +{ + string name = string("Array_") + typeid(T).name(); + bp::class_,boost::noncopyable>(name.c_str()) + .def ("__len__", &Array::Size) + .def ("__getitem__", + FunctionPointer ([](Array & self, int i) -> T& + { + if (i < 0 || i >= self.Size()) + bp::exec("raise IndexError()\n"); + return self[i]; + }), + bp::return_value_policy()) + ; +} + + + +void ExportNetgenMeshing() +{ + + std::string nested_name = "meshing"; + if( bp::scope() ) + nested_name = bp::extract(bp::scope().attr("__name__") + ".meshing"); + + bp::object module(bp::handle<>(bp::borrowed(PyImport_AddModule(nested_name.c_str())))); + + cout << "exporting meshing " << nested_name << endl; + bp::object parent = bp::scope() ? bp::scope() : bp::import("__main__"); + parent.attr("meshing") = module ; + + bp::scope local_scope(module); + + bp::class_("PointId") + .def("__repr__", &ToString) + .def("__str__", &ToString) + .add_property("nr", &PointIndex::operator int) + ; + + bp::class_("Element3D") + .add_property("vertices", + FunctionPointer ([](const Element & self) -> bp::list + { + bp::list li; + for (int i = 0; i < self.GetNV(); i++) + li.append (self[i]); + return li; + })) + ; + + ExportArray(); + ; + + + bp::class_,boost::noncopyable>("Mesh") + .def("__str__", &ToString) + .def("Load", static_cast(&Mesh::Load)) + .def("Save", static_cast(&Mesh::Save)) + + .def("Elements3D", + static_cast&(Mesh::*)()> (& &Mesh::VolumeElements), + bp::return_value_policy()) + + /* + .def("Elements2D", &Mesh::SurfaceElements, + bp::return_value_policy()) + */ + + ; + + + bp::class_ ("MeshingParameters") + ; +} + + + +BOOST_PYTHON_MODULE(libmesh) { + ExportNetgenMeshing(); +} + + + + + diff --git a/libsrc/meshing/smoothing3.cpp b/libsrc/meshing/smoothing3.cpp index 20c8e461..8cb318ea 100644 --- a/libsrc/meshing/smoothing3.cpp +++ b/libsrc/meshing/smoothing3.cpp @@ -1172,7 +1172,7 @@ FuncDeriv (const Vector & x, const Vector & dir, double & deriv) const #ifdef SOLIDGEOMxxxx -void Mesh :: ImproveMesh (const CSGeometry & geometry, OPTIMIZEGOAL goal) +void Mesh :: ImproveMesh (const CSG eometry & geometry, OPTIMIZEGOAL goal) { INDEX i, eli; int j; diff --git a/ng/ngappinit.cpp b/ng/ngappinit.cpp index 95c1f71b..20578617 100644 --- a/ng/ngappinit.cpp +++ b/ng/ngappinit.cpp @@ -11,10 +11,12 @@ #include #endif +/* namespace netgen { int id = 0, ntasks = 1; } +*/ #ifdef PARALLEL #include diff --git a/ng/ngpkg.cpp b/ng/ngpkg.cpp index 04d96f70..b3e2354b 100644 --- a/ng/ngpkg.cpp +++ b/ng/ngpkg.cpp @@ -36,6 +36,7 @@ extern bool nodisplay; namespace netgen { + extern MeshingParameters mparam; #include "../libsrc/interface/writeuser.hpp" #include "demoview.hpp" } @@ -156,7 +157,7 @@ namespace netgen */ } - DLL_HEADER void MyError(const char * ch) + DLL_HEADER void MyError2(const char * ch) { cout << ch; (*testout) << "Error !!! " << ch << endl << flush; @@ -164,13 +165,13 @@ namespace netgen #endif static clock_t starttimea; - void ResetTime () + void ResetTime2 () { starttimea = clock(); } #ifndef SMALLLIB - DLL_HEADER double GetTime () + DLL_HEADER double GetTime2 () { return double(clock() - starttimea) / CLOCKS_PER_SEC; } @@ -1127,6 +1128,7 @@ namespace netgen { mparam.maxh = atof (Tcl_GetVar (interp, "::options.meshsize", 0)); mparam.minh = atof (Tcl_GetVar (interp, "::options.minmeshsize", 0)); + mparam.meshsizefilename = Tcl_GetVar (interp, "::options.meshsizefilename", 0); if (!strlen (mparam.meshsizefilename)) mparam.meshsizefilename = NULL; @@ -1356,6 +1358,9 @@ namespace netgen multithread.running = 1; multithread.terminate = 0; + + extern void Render(); + mparam.render_function = &Render; for (int i = 0; i < geometryregister.Size(); i++) geometryregister[i] -> SetParameters (interp); diff --git a/nglib/nglib.cpp b/nglib/nglib.cpp index 7576f86b..6f11017d 100644 --- a/nglib/nglib.cpp +++ b/nglib/nglib.cpp @@ -45,11 +45,12 @@ namespace netgen #endif +/* namespace netgen { int id = 0, ntasks = 1; } - +*/ /* @@ -1176,7 +1177,7 @@ namespace netgen { char geomfilename[255]; - DLL_HEADER void MyError (const char * ch) + DLL_HEADER void MyError2 (const char * ch) { cerr << ch; } @@ -1185,7 +1186,7 @@ namespace netgen //Destination for messages, errors, ... - DLL_HEADER void Ng_PrintDest(const char * s) + DLL_HEADER void Ng_PrintDest2(const char * s) { #ifdef PARALLEL int id = 0; @@ -1196,13 +1197,12 @@ namespace netgen } - - + /* DLL_HEADER double GetTime () { return 0; } - + */