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;
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)
{

View File

@ -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);

View File

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

View File

@ -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<MP>)

View File

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

View File

@ -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");

View File

@ -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<py::kwargs>(pars->geometrySpecificParameters);
auto mp_kwargs = any_cast<py::kwargs>(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<Mesh>();
SetGlobalMesh(mesh);
mesh->SetGeometry(geo);
ng_geometry = geo;
SetGlobalMesh(mesh);
geo->GenerateMesh(mesh,mp);
return mesh;
}, py::arg("mp") = nullptr,

View File

@ -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<STLParameters>(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> & 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;
@ -1372,7 +1373,7 @@ int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr<Mesh> & 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> & 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;
}

View File

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

View File

@ -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);

View File

@ -30,6 +30,8 @@ namespace netgen {
extern void MeshFromSpline2D (SplineGeometry2d & geometry,
shared_ptr<Mesh> & 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;