diff --git a/libsrc/meshing/meshfunc.cpp b/libsrc/meshing/meshfunc.cpp index b7d91a14..25a7e8b7 100644 --- a/libsrc/meshing/meshfunc.cpp +++ b/libsrc/meshing/meshfunc.cpp @@ -12,10 +12,11 @@ namespace netgen // extern double teterrpow; - MESHING3_RESULT MeshVolume (MeshingParameters & mp, Mesh& mesh3d) + MESHING3_RESULT MeshVolume (const MeshingParameters & c_mp, Mesh& mesh3d) { static Timer t("MeshVolume"); RegionTimer reg(t); - + + MeshingParameters mp = c_mp; // copy mp to change them here int oldne; int meshed; @@ -637,7 +638,7 @@ namespace netgen - MESHING3_RESULT OptimizeVolume (MeshingParameters & mp, + MESHING3_RESULT OptimizeVolume (const MeshingParameters & mp, Mesh & mesh3d) // const CSGeometry * geometry) { diff --git a/libsrc/meshing/meshfunc.hpp b/libsrc/meshing/meshfunc.hpp index 7eaaa238..fdbdef4e 100644 --- a/libsrc/meshing/meshfunc.hpp +++ b/libsrc/meshing/meshfunc.hpp @@ -16,13 +16,13 @@ class Mesh; // class CSGeometry; /// Build tet-mesh -DLL_HEADER MESHING3_RESULT MeshVolume (MeshingParameters & mp, Mesh& mesh3d); +DLL_HEADER MESHING3_RESULT MeshVolume (const MeshingParameters & mp, Mesh& mesh3d); /// Build mixed-element mesh // MESHING3_RESULT MeshMixedVolume (MeshingParameters & mp, Mesh& mesh3d); /// Optimize tet-mesh -DLL_HEADER MESHING3_RESULT OptimizeVolume (MeshingParameters & mp, Mesh& mesh3d); +DLL_HEADER MESHING3_RESULT OptimizeVolume (const MeshingParameters & mp, Mesh& mesh3d); // const CSGeometry * geometry = NULL); DLL_HEADER void RemoveIllegalElements (Mesh & mesh3d); diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 63e0515b..e52d9840 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -1298,7 +1298,7 @@ namespace netgen NgArray meshsize_points; void (*render_function)(bool) = NULL; - void Render(bool blocking = false) + void Render(bool blocking = false) const { if (render_function) (*render_function)(blocking); diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 1428a9cf..16f1b269 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -1023,7 +1023,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) { MeshingParameters mp; if(other) mp = *other; - CreateMPfromKwargs(mp, kwargs); + CreateMPfromKwargs(mp, kwargs, false); return mp; }), py::arg("mp")=nullptr, meshingparameter_description.c_str()) .def("__str__", &ToString) diff --git a/libsrc/meshing/python_mesh.hpp b/libsrc/meshing/python_mesh.hpp index 45a2b9aa..cbcda74e 100644 --- a/libsrc/meshing/python_mesh.hpp +++ b/libsrc/meshing/python_mesh.hpp @@ -80,7 +80,7 @@ elsizeweight: float = 0.2 )delimiter"; - inline void CreateMPfromKwargs(MeshingParameters& mp, py::kwargs kwargs) +inline void CreateMPfromKwargs(MeshingParameters& mp, py::kwargs kwargs, bool throw_if_not_all_parsed=true) { if(kwargs.contains("optimize3d")) mp.optimize3d = py::cast(kwargs.attr("pop")("optimize3d")); @@ -165,6 +165,10 @@ elsizeweight: float = 0.2 if(kwargs.contains("autozrefine")) mp.autozrefine = py::cast(kwargs.attr("pop")("autozrefine")); if(kwargs.size()) - mp.geometrySpecificParameters = make_any(std::move(kwargs)); + { + if(throw_if_not_all_parsed) + throw Exception(string("Not all kwargs given to GenerateMesh could be parsed:") + string(py::str(kwargs))); + mp.geometrySpecificParameters = kwargs; + } } } // namespace netgen diff --git a/libsrc/stlgeom/meshstlsurface.cpp b/libsrc/stlgeom/meshstlsurface.cpp index f6bfc411..8e32fd81 100644 --- a/libsrc/stlgeom/meshstlsurface.cpp +++ b/libsrc/stlgeom/meshstlsurface.cpp @@ -13,9 +13,8 @@ namespace netgen { -static void STLFindEdges (STLGeometry & geom, - class Mesh & mesh, - MeshingParameters& mparam) +static void STLFindEdges (STLGeometry & geom, Mesh & mesh, + const MeshingParameters& mparam) { double h = mparam.maxh; @@ -230,11 +229,11 @@ static void STLFindEdges (STLGeometry & geom, -void STLSurfaceMeshing1 (STLGeometry & geom, class Mesh & mesh, MeshingParameters& mparam, +void STLSurfaceMeshing1 (STLGeometry & geom, class Mesh & mesh, const MeshingParameters& mparam, int retrynr); -int STLSurfaceMeshing (STLGeometry & geom, class Mesh & mesh, MeshingParameters& mparam) +int STLSurfaceMeshing (STLGeometry & geom, class Mesh & mesh, const MeshingParameters& mparam) { PrintFnStart("Do Surface Meshing"); @@ -527,8 +526,8 @@ int STLSurfaceMeshing (STLGeometry & geom, class Mesh & mesh, MeshingParameters& void STLSurfaceMeshing1 (STLGeometry & geom, - class Mesh & mesh, - MeshingParameters& mparam, + Mesh & mesh, + const MeshingParameters& mparam, int retrynr) { static int timer1 = NgProfiler::CreateTimer ("STL surface meshing1"); @@ -742,8 +741,8 @@ void STLSurfaceMeshing1 (STLGeometry & geom, void STLSurfaceOptimization (STLGeometry & geom, - class Mesh & mesh, - MeshingParameters & mparam) + Mesh & mesh, + const MeshingParameters & mparam) { PrintFnStart("optimize STL Surface"); diff --git a/libsrc/stlgeom/python_stl.cpp b/libsrc/stlgeom/python_stl.cpp index e61ec46b..180b5e56 100644 --- a/libsrc/stlgeom/python_stl.cpp +++ b/libsrc/stlgeom/python_stl.cpp @@ -194,36 +194,28 @@ DLL_HEADER void ExportSTL(py::module & m) MeshingParameters* pars, py::kwargs kwargs) { MeshingParameters mp; - { - py::gil_scoped_acquire aq; + { py::gil_scoped_acquire aq; STLParameters stlparam; if(pars) { if(pars->geometrySpecificParameters.has_value() && (pars->geometrySpecificParameters.type() == typeid(py::kwargs))) { - py::gil_scoped_acquire aq; - py::kwargs mp_kwargs = any_cast(pars->geometrySpecificParameters); + auto mp_kwargs = any_cast(pars->geometrySpecificParameters); py::print("geometry specific kwargs:", mp_kwargs); CreateSTLParametersFromKwargs(stlparam, mp_kwargs); pars->geometrySpecificParameters.reset(); } mp = *pars; } - CreateMPfromKwargs(mp, kwargs); CreateSTLParametersFromKwargs(stlparam, kwargs); - if(kwargs.size()) - { - cout << "WARNING: Given meshing arguments that are ignored:"; - for(auto& key : kwargs) - py::print(key); - } + CreateMPfromKwargs(mp, kwargs); // this will throw if any kwargs are not passed mp.geometrySpecificParameters = stlparam; } auto mesh = make_shared(); - SetGlobalMesh(mesh); mesh->SetGeometry(geo); ng_geometry = geo; + SetGlobalMesh(mesh); geo->GenerateMesh(mesh,mp); return mesh; }, py::arg("mp") = nullptr, diff --git a/libsrc/stlgeom/stlgeom.cpp b/libsrc/stlgeom/stlgeom.cpp index 31c512b3..dd5694df 100644 --- a/libsrc/stlgeom/stlgeom.cpp +++ b/libsrc/stlgeom/stlgeom.cpp @@ -14,14 +14,10 @@ int usechartnormal = 1; void STLMeshing (STLGeometry & geom, Mesh & mesh, - const MeshingParameters& mparam) + const MeshingParameters& mparam, + const STLParameters& stlpar) { geom.Clear(); - STLParameters stlpar = stlparam; - if(mparam.geometrySpecificParameters.has_value() && mparam.geometrySpecificParameters.type().name() == typeid(STLParameters).name()) - { - stlpar = any_cast(mparam.geometrySpecificParameters); - } geom.BuildEdges(stlpar); geom.MakeAtlas(mesh, mparam, stlpar); if (multithread.terminate) { return; } @@ -101,7 +97,12 @@ void STLGeometry :: Save (string filename) const int STLGeometry :: GenerateMesh (shared_ptr & mesh, MeshingParameters & mparam) { - return STLMeshingDummy (this, mesh, mparam); + STLParameters stlpar = stlparam; + if(mparam.geometrySpecificParameters.has_value() && mparam.geometrySpecificParameters.type().name() == typeid(STLParameters).name()) + { + stlpar = any_cast(mparam.geometrySpecificParameters); + } + return STLMeshingDummy (this, mesh, mparam, stlpar); } diff --git a/libsrc/stlgeom/stlgeom.hpp b/libsrc/stlgeom/stlgeom.hpp index 5e1ecc27..05b03fd8 100644 --- a/libsrc/stlgeom/stlgeom.hpp +++ b/libsrc/stlgeom/stlgeom.hpp @@ -40,7 +40,7 @@ namespace netgen } */ - extern DLL_HEADER MeshingParameters mparam; +// extern DLL_HEADER MeshingParameters mparam; @@ -468,7 +468,8 @@ namespace netgen - extern int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr & mesh, MeshingParameters & mparam); +extern int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr & mesh, const MeshingParameters & mparam, + const STLParameters& stlpar); } diff --git a/libsrc/stlgeom/stlgeommesh.cpp b/libsrc/stlgeom/stlgeommesh.cpp index 426f7bac..6260e793 100644 --- a/libsrc/stlgeom/stlgeommesh.cpp +++ b/libsrc/stlgeom/stlgeommesh.cpp @@ -1345,7 +1345,8 @@ void STLGeometry :: RestrictHChartDistOneChart(int chartnum, NgArray& acttr } -int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr & mesh, MeshingParameters & mparam) +int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr & mesh, const MeshingParameters & mparam, + const STLParameters& stlparam) { if (mparam.perfstepsstart > mparam.perfstepsend) return 0; @@ -1372,7 +1373,7 @@ int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr & mesh, MeshingP //mesh->DeleteMesh(); - STLMeshing (*stlgeometry, *mesh, mparam); + STLMeshing (*stlgeometry, *mesh, mparam, stlparam); stlgeometry->edgesfound = 1; stlgeometry->surfacemeshed = 0; @@ -1471,13 +1472,14 @@ int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr & mesh, MeshingP mesh -> LoadLocalMeshSize (mparam.meshsizefilename); mesh -> CalcLocalHFromSurfaceCurvature (mparam.grading, stlparam.resthsurfmeshcurvfac); - mparam.optimize2d = "cmsmSm"; - STLSurfaceOptimization (*stlgeometry, *mesh, mparam); + MeshingParameters mpar = mparam; + mpar.optimize2d = "cmsmSm"; + STLSurfaceOptimization (*stlgeometry, *mesh, mpar); #ifdef STAT_STREAM (*statout) << GetTime() << " & "; #endif - mparam.Render(); + mpar.Render(); } stlgeometry->surfaceoptimized = 1; } diff --git a/libsrc/stlgeom/stlpkg.cpp b/libsrc/stlgeom/stlpkg.cpp index 1372702f..7864a688 100644 --- a/libsrc/stlgeom/stlpkg.cpp +++ b/libsrc/stlgeom/stlpkg.cpp @@ -21,6 +21,7 @@ namespace netgen { DLL_HEADER extern shared_ptr ng_geometry; DLL_HEADER extern shared_ptr mesh; + DLL_HEADER extern MeshingParameters mparam; static VisualSceneSTLGeometry vsstlgeom; static VisualSceneSTLMeshing vsstlmeshing; diff --git a/libsrc/stlgeom/stltool.hpp b/libsrc/stlgeom/stltool.hpp index f617d275..4464bac1 100644 --- a/libsrc/stlgeom/stltool.hpp +++ b/libsrc/stlgeom/stltool.hpp @@ -278,17 +278,18 @@ DLL_HEADER extern STLParameters stlparam; void STLMeshing (STLGeometry & geom, - class Mesh & mesh, - const MeshingParameters& mparam); + Mesh & mesh, + const MeshingParameters& mparam, + const STLParameters& stlpar); int STLSurfaceMeshing (STLGeometry & geom, - class Mesh & mesh, - MeshingParameters& mparam); + Mesh & mesh, + const MeshingParameters& mparam); void STLSurfaceOptimization (STLGeometry & geom, - class Mesh & mesh, - class MeshingParameters & mparam); + Mesh & mesh, + const MeshingParameters & mparam); diff --git a/nglib/nglib.cpp b/nglib/nglib.cpp index e44b58c4..293cfa55 100644 --- a/nglib/nglib.cpp +++ b/nglib/nglib.cpp @@ -30,6 +30,8 @@ namespace netgen { extern void MeshFromSpline2D (SplineGeometry2d & geometry, shared_ptr & mesh, MeshingParameters & mp); + extern MeshingParameters mparam; + extern STLParameters stlparam; } @@ -667,7 +669,7 @@ namespace nglib } */ - STLMeshing (*stlgeometry, *me, mparam); + STLMeshing (*stlgeometry, *me, mparam, stlparam); stlgeometry->edgesfound = 1; stlgeometry->surfacemeshed = 0;