meshingparameter only visible in nglib and const ref to funcs

This commit is contained in:
Christopher Lackner 2019-08-06 10:42:53 +02:00
parent 218bd4c5d2
commit fc1a3da429
13 changed files with 55 additions and 51 deletions

View File

@ -12,10 +12,11 @@ namespace netgen
// extern double teterrpow; // 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); static Timer t("MeshVolume"); RegionTimer reg(t);
MeshingParameters mp = c_mp; // copy mp to change them here
int oldne; int oldne;
int meshed; int meshed;
@ -637,7 +638,7 @@ namespace netgen
MESHING3_RESULT OptimizeVolume (MeshingParameters & mp, MESHING3_RESULT OptimizeVolume (const MeshingParameters & mp,
Mesh & mesh3d) Mesh & mesh3d)
// const CSGeometry * geometry) // const CSGeometry * geometry)
{ {

View File

@ -16,13 +16,13 @@ class Mesh;
// class CSGeometry; // class CSGeometry;
/// Build tet-mesh /// 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 /// Build mixed-element mesh
// MESHING3_RESULT MeshMixedVolume (MeshingParameters & mp, Mesh& mesh3d); // MESHING3_RESULT MeshMixedVolume (MeshingParameters & mp, Mesh& mesh3d);
/// Optimize tet-mesh /// 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); // const CSGeometry * geometry = NULL);
DLL_HEADER void RemoveIllegalElements (Mesh & mesh3d); DLL_HEADER void RemoveIllegalElements (Mesh & mesh3d);

View File

@ -1298,7 +1298,7 @@ namespace netgen
NgArray<MeshSizePoint> meshsize_points; NgArray<MeshSizePoint> meshsize_points;
void (*render_function)(bool) = NULL; void (*render_function)(bool) = NULL;
void Render(bool blocking = false) void Render(bool blocking = false) const
{ {
if (render_function) if (render_function)
(*render_function)(blocking); (*render_function)(blocking);

View File

@ -1023,7 +1023,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
{ {
MeshingParameters mp; MeshingParameters mp;
if(other) mp = *other; if(other) mp = *other;
CreateMPfromKwargs(mp, kwargs); CreateMPfromKwargs(mp, kwargs, false);
return mp; return mp;
}), py::arg("mp")=nullptr, meshingparameter_description.c_str()) }), py::arg("mp")=nullptr, meshingparameter_description.c_str())
.def("__str__", &ToString<MP>) .def("__str__", &ToString<MP>)

View File

@ -80,7 +80,7 @@ elsizeweight: float = 0.2
)delimiter"; )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")) if(kwargs.contains("optimize3d"))
mp.optimize3d = py::cast<string>(kwargs.attr("pop")("optimize3d")); mp.optimize3d = py::cast<string>(kwargs.attr("pop")("optimize3d"));
@ -165,6 +165,10 @@ elsizeweight: float = 0.2
if(kwargs.contains("autozrefine")) if(kwargs.contains("autozrefine"))
mp.autozrefine = py::cast<bool>(kwargs.attr("pop")("autozrefine")); mp.autozrefine = py::cast<bool>(kwargs.attr("pop")("autozrefine"));
if(kwargs.size()) if(kwargs.size())
mp.geometrySpecificParameters = make_any<py::kwargs>(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 } // namespace netgen

View File

@ -13,9 +13,8 @@
namespace netgen namespace netgen
{ {
static void STLFindEdges (STLGeometry & geom, static void STLFindEdges (STLGeometry & geom, Mesh & mesh,
class Mesh & mesh, const MeshingParameters& mparam)
MeshingParameters& mparam)
{ {
double h = mparam.maxh; 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 retrynr);
int STLSurfaceMeshing (STLGeometry & geom, class Mesh & mesh, MeshingParameters& mparam) int STLSurfaceMeshing (STLGeometry & geom, class Mesh & mesh, const MeshingParameters& mparam)
{ {
PrintFnStart("Do Surface Meshing"); PrintFnStart("Do Surface Meshing");
@ -527,8 +526,8 @@ int STLSurfaceMeshing (STLGeometry & geom, class Mesh & mesh, MeshingParameters&
void STLSurfaceMeshing1 (STLGeometry & geom, void STLSurfaceMeshing1 (STLGeometry & geom,
class Mesh & mesh, Mesh & mesh,
MeshingParameters& mparam, const MeshingParameters& mparam,
int retrynr) int retrynr)
{ {
static int timer1 = NgProfiler::CreateTimer ("STL surface meshing1"); static int timer1 = NgProfiler::CreateTimer ("STL surface meshing1");
@ -742,8 +741,8 @@ void STLSurfaceMeshing1 (STLGeometry & geom,
void STLSurfaceOptimization (STLGeometry & geom, void STLSurfaceOptimization (STLGeometry & geom,
class Mesh & mesh, Mesh & mesh,
MeshingParameters & mparam) const MeshingParameters & mparam)
{ {
PrintFnStart("optimize STL Surface"); PrintFnStart("optimize STL Surface");

View File

@ -194,36 +194,28 @@ DLL_HEADER void ExportSTL(py::module & m)
MeshingParameters* pars, py::kwargs kwargs) MeshingParameters* pars, py::kwargs kwargs)
{ {
MeshingParameters mp; MeshingParameters mp;
{ { py::gil_scoped_acquire aq;
py::gil_scoped_acquire aq;
STLParameters stlparam; STLParameters stlparam;
if(pars) if(pars)
{ {
if(pars->geometrySpecificParameters.has_value() && if(pars->geometrySpecificParameters.has_value() &&
(pars->geometrySpecificParameters.type() == typeid(py::kwargs))) (pars->geometrySpecificParameters.type() == typeid(py::kwargs)))
{ {
py::gil_scoped_acquire aq; auto mp_kwargs = any_cast<py::kwargs>(pars->geometrySpecificParameters);
py::kwargs mp_kwargs = any_cast<py::kwargs>(pars->geometrySpecificParameters);
py::print("geometry specific kwargs:", mp_kwargs); py::print("geometry specific kwargs:", mp_kwargs);
CreateSTLParametersFromKwargs(stlparam, mp_kwargs); CreateSTLParametersFromKwargs(stlparam, mp_kwargs);
pars->geometrySpecificParameters.reset(); pars->geometrySpecificParameters.reset();
} }
mp = *pars; mp = *pars;
} }
CreateMPfromKwargs(mp, kwargs);
CreateSTLParametersFromKwargs(stlparam, kwargs); CreateSTLParametersFromKwargs(stlparam, kwargs);
if(kwargs.size()) CreateMPfromKwargs(mp, kwargs); // this will throw if any kwargs are not passed
{
cout << "WARNING: Given meshing arguments that are ignored:";
for(auto& key : kwargs)
py::print(key);
}
mp.geometrySpecificParameters = stlparam; mp.geometrySpecificParameters = stlparam;
} }
auto mesh = make_shared<Mesh>(); auto mesh = make_shared<Mesh>();
SetGlobalMesh(mesh);
mesh->SetGeometry(geo); mesh->SetGeometry(geo);
ng_geometry = geo; ng_geometry = geo;
SetGlobalMesh(mesh);
geo->GenerateMesh(mesh,mp); geo->GenerateMesh(mesh,mp);
return mesh; return mesh;
}, py::arg("mp") = nullptr, }, py::arg("mp") = nullptr,

View File

@ -14,14 +14,10 @@ int usechartnormal = 1;
void STLMeshing (STLGeometry & geom, void STLMeshing (STLGeometry & geom,
Mesh & mesh, Mesh & mesh,
const MeshingParameters& mparam) const MeshingParameters& mparam,
const STLParameters& stlpar)
{ {
geom.Clear(); geom.Clear();
STLParameters stlpar = stlparam;
if(mparam.geometrySpecificParameters.has_value() && mparam.geometrySpecificParameters.type().name() == typeid(STLParameters).name())
{
stlpar = any_cast<STLParameters>(mparam.geometrySpecificParameters);
}
geom.BuildEdges(stlpar); geom.BuildEdges(stlpar);
geom.MakeAtlas(mesh, mparam, stlpar); geom.MakeAtlas(mesh, mparam, stlpar);
if (multithread.terminate) { return; } if (multithread.terminate) { return; }
@ -101,7 +97,12 @@ void STLGeometry :: Save (string filename) const
int STLGeometry :: GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam) int STLGeometry :: GenerateMesh (shared_ptr<Mesh> & 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<STLParameters>(mparam.geometrySpecificParameters);
}
return STLMeshingDummy (this, mesh, mparam, stlpar);
} }

View File

@ -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> & mesh, MeshingParameters & mparam); extern int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr<Mesh> & mesh, const MeshingParameters & mparam,
const STLParameters& stlpar);
} }

View File

@ -1345,7 +1345,8 @@ void STLGeometry :: RestrictHChartDistOneChart(int chartnum, NgArray<int>& acttr
} }
int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr<Mesh> & mesh, MeshingParameters & mparam) int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr<Mesh> & mesh, const MeshingParameters & mparam,
const STLParameters& stlparam)
{ {
if (mparam.perfstepsstart > mparam.perfstepsend) return 0; if (mparam.perfstepsstart > mparam.perfstepsend) return 0;
@ -1372,7 +1373,7 @@ int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr<Mesh> & mesh, MeshingP
//mesh->DeleteMesh(); //mesh->DeleteMesh();
STLMeshing (*stlgeometry, *mesh, mparam); STLMeshing (*stlgeometry, *mesh, mparam, stlparam);
stlgeometry->edgesfound = 1; stlgeometry->edgesfound = 1;
stlgeometry->surfacemeshed = 0; stlgeometry->surfacemeshed = 0;
@ -1471,13 +1472,14 @@ int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr<Mesh> & mesh, MeshingP
mesh -> LoadLocalMeshSize (mparam.meshsizefilename); mesh -> LoadLocalMeshSize (mparam.meshsizefilename);
mesh -> CalcLocalHFromSurfaceCurvature (mparam.grading, mesh -> CalcLocalHFromSurfaceCurvature (mparam.grading,
stlparam.resthsurfmeshcurvfac); stlparam.resthsurfmeshcurvfac);
mparam.optimize2d = "cmsmSm"; MeshingParameters mpar = mparam;
STLSurfaceOptimization (*stlgeometry, *mesh, mparam); mpar.optimize2d = "cmsmSm";
STLSurfaceOptimization (*stlgeometry, *mesh, mpar);
#ifdef STAT_STREAM #ifdef STAT_STREAM
(*statout) << GetTime() << " & "; (*statout) << GetTime() << " & ";
#endif #endif
mparam.Render(); mpar.Render();
} }
stlgeometry->surfaceoptimized = 1; stlgeometry->surfaceoptimized = 1;
} }

View File

@ -21,6 +21,7 @@ namespace netgen
{ {
DLL_HEADER extern shared_ptr<NetgenGeometry> ng_geometry; DLL_HEADER extern shared_ptr<NetgenGeometry> ng_geometry;
DLL_HEADER extern shared_ptr<Mesh> mesh; DLL_HEADER extern shared_ptr<Mesh> mesh;
DLL_HEADER extern MeshingParameters mparam;
static VisualSceneSTLGeometry vsstlgeom; static VisualSceneSTLGeometry vsstlgeom;
static VisualSceneSTLMeshing vsstlmeshing; static VisualSceneSTLMeshing vsstlmeshing;

View File

@ -278,17 +278,18 @@ DLL_HEADER extern STLParameters stlparam;
void STLMeshing (STLGeometry & geom, void STLMeshing (STLGeometry & geom,
class Mesh & mesh, Mesh & mesh,
const MeshingParameters& mparam); const MeshingParameters& mparam,
const STLParameters& stlpar);
int STLSurfaceMeshing (STLGeometry & geom, int STLSurfaceMeshing (STLGeometry & geom,
class Mesh & mesh, Mesh & mesh,
MeshingParameters& mparam); const MeshingParameters& mparam);
void STLSurfaceOptimization (STLGeometry & geom, void STLSurfaceOptimization (STLGeometry & geom,
class Mesh & mesh, Mesh & mesh,
class MeshingParameters & mparam); const MeshingParameters & mparam);

View File

@ -30,6 +30,8 @@ namespace netgen {
extern void MeshFromSpline2D (SplineGeometry2d & geometry, extern void MeshFromSpline2D (SplineGeometry2d & geometry,
shared_ptr<Mesh> & mesh, shared_ptr<Mesh> & mesh,
MeshingParameters & mp); 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->edgesfound = 1;
stlgeometry->surfacemeshed = 0; stlgeometry->surfacemeshed = 0;