meshingparameters from python as in gui

This commit is contained in:
Christopher Lackner 2019-07-29 07:11:57 +02:00
parent f7fcc67fc7
commit c22ec2dcc2
11 changed files with 62 additions and 23 deletions

View File

@ -694,12 +694,14 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails!
res["max"] = MoveToNumpy(max); res["max"] = MoveToNumpy(max);
return res; return res;
}, py::call_guard<py::gil_scoped_release>()) }, py::call_guard<py::gil_scoped_release>())
.def("GenerateMesh", [](shared_ptr<CSGeometry> geo, py::kwargs kwargs) .def("GenerateMesh", [](shared_ptr<CSGeometry> geo,
MeshingParameters* pars, py::kwargs kwargs)
{ {
MeshingParameters mp; MeshingParameters mp;
if(pars) mp = *pars;
{ {
py::gil_scoped_acquire aq; py::gil_scoped_acquire aq;
mp = CreateMPfromKwargs(kwargs); CreateMPfromKwargs(mp, kwargs);
} }
auto mesh = make_shared<Mesh>(); auto mesh = make_shared<Mesh>();
SetGlobalMesh (mesh); SetGlobalMesh (mesh);
@ -708,7 +710,8 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails!
geo->FindIdenticSurfaces(1e-8 * geo->MaxSize()); geo->FindIdenticSurfaces(1e-8 * geo->MaxSize());
geo->GenerateMesh (mesh, mp); geo->GenerateMesh (mesh, mp);
return mesh; return mesh;
}, meshingparameter_description.c_str(), }, py::arg("mp") = nullptr,
meshingparameter_description.c_str(),
py::call_guard<py::gil_scoped_release>()) py::call_guard<py::gil_scoped_release>())
; ;

View File

@ -363,12 +363,15 @@ DLL_HEADER void ExportGeom2d(py::module &m)
//cout << i << " : " << self.splines[i]->GetPoint(0.1) << " , " << self.splines[i]->GetPoint(0.5) << endl; //cout << i << " : " << self.splines[i]->GetPoint(0.1) << " , " << self.splines[i]->GetPoint(0.5) << endl;
} }
})) }))
.def("GenerateMesh", [](shared_ptr<SplineGeometry2d> self, py::kwargs kwargs) // If we change to c++17 this can become optional<MeshingParameters>
.def("GenerateMesh", [](shared_ptr<SplineGeometry2d> self,
MeshingParameters* pars, py::kwargs kwargs)
{ {
MeshingParameters mp; MeshingParameters mp;
if(pars) mp = *pars;
{ {
py::gil_scoped_acquire aq; py::gil_scoped_acquire aq;
mp = CreateMPfromKwargs(kwargs); CreateMPfromKwargs(mp, kwargs);
} }
auto mesh = make_shared<Mesh>(); auto mesh = make_shared<Mesh>();
mesh->SetGeometry(self); mesh->SetGeometry(self);
@ -376,9 +379,10 @@ DLL_HEADER void ExportGeom2d(py::module &m)
ng_geometry = self; ng_geometry = self;
self->GenerateMesh(mesh, mp); self->GenerateMesh(mesh, mp);
return mesh; return mesh;
}, py::call_guard<py::gil_scoped_release>(), }, py::arg("mp") = nullptr,
meshingparameter_description.c_str()) py::call_guard<py::gil_scoped_release>(),
; meshingparameter_description.c_str())
;
} }

View File

@ -857,12 +857,14 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
self.SetMaxHDomain(maxh); self.SetMaxHDomain(maxh);
}) })
.def ("GenerateVolumeMesh", .def ("GenerateVolumeMesh",
[](Mesh & self, py::kwargs kwargs) [](Mesh & self, MeshingParameters* pars,
py::kwargs kwargs)
{ {
MeshingParameters mp; MeshingParameters mp;
if(pars) mp = *pars;
{ {
py::gil_scoped_acquire acquire; py::gil_scoped_acquire acquire;
mp = CreateMPfromKwargs(kwargs); CreateMPfromKwargs(mp, kwargs);
} }
MeshVolume (mp, self); MeshVolume (mp, self);
OptimizeVolume (mp, self); OptimizeVolume (mp, self);
@ -1024,12 +1026,15 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
.def(py::init<>()) .def(py::init<>())
.def(py::init([](py::kwargs kwargs) .def(py::init([](py::kwargs kwargs)
{ {
return CreateMPfromKwargs(kwargs); MeshingParameters mp;
CreateMPfromKwargs(mp, kwargs);
return mp;
}), meshingparameter_description.c_str()) }), meshingparameter_description.c_str())
.def("__str__", &ToString<MP>) .def("__str__", &ToString<MP>)
.def_property("maxh", .def_property("maxh", [](const MP & mp ) { return mp.maxh; },
FunctionPointer ([](const MP & mp ) { return mp.maxh; }), [](MP & mp, double maxh) { return mp.maxh = maxh; })
FunctionPointer ([](MP & mp, double maxh) { return mp.maxh = maxh; })) .def_property("grading", [](const MP & mp ) { return mp.grading; },
[](MP & mp, double grading) { return mp.grading = grading; })
.def("RestrictH", FunctionPointer .def("RestrictH", FunctionPointer
([](MP & mp, double x, double y, double z, double h) ([](MP & mp, double x, double y, double z, double h)
{ {

View File

@ -80,9 +80,8 @@ elsizeweight: float = 0.2
)delimiter"; )delimiter";
inline MeshingParameters CreateMPfromKwargs(py::kwargs kwargs) inline void CreateMPfromKwargs(MeshingParameters& mp, py::kwargs kwargs)
{ {
MeshingParameters mp;
if(kwargs.contains("optimize3d")) if(kwargs.contains("optimize3d"))
mp.optimize3d = py::cast<string>(kwargs["optimize3d"]); mp.optimize3d = py::cast<string>(kwargs["optimize3d"]);
if(kwargs.contains("optsteps3d")) if(kwargs.contains("optsteps3d"))
@ -165,6 +164,5 @@ elsizeweight: float = 0.2
mp.inverttrigs = py::cast<bool>(kwargs["inverttrigs"]); mp.inverttrigs = py::cast<bool>(kwargs["inverttrigs"]);
if(kwargs.contains("autozrefine")) if(kwargs.contains("autozrefine"))
mp.autozrefine = py::cast<bool>(kwargs["autozrefine"]); mp.autozrefine = py::cast<bool>(kwargs["autozrefine"]);
return mp;
} }
} // namespace netgen } // namespace netgen

View File

@ -124,12 +124,14 @@ DLL_HEADER void ExportNgOCC(py::module &m)
res["max"] = MoveToNumpy(max); res["max"] = MoveToNumpy(max);
return res; return res;
}, py::call_guard<py::gil_scoped_release>()) }, py::call_guard<py::gil_scoped_release>())
.def("GenerateMesh", [](shared_ptr<OCCGeometry> geo, py::kwargs kwargs) .def("GenerateMesh", [](shared_ptr<OCCGeometry> geo,
MeshingParameters* pars, py::kwargs kwargs)
{ {
MeshingParameters mp; MeshingParameters mp;
if(pars) mp = *pars;
{ {
py::gil_scoped_acquire aq; py::gil_scoped_acquire aq;
mp = CreateMPfromKwargs(kwargs); CreateMPfromKwargs(mp, kwargs);
} }
auto mesh = make_shared<Mesh>(); auto mesh = make_shared<Mesh>();
SetGlobalMesh(mesh); SetGlobalMesh(mesh);
@ -137,7 +139,7 @@ DLL_HEADER void ExportNgOCC(py::module &m)
ng_geometry = geo; ng_geometry = geo;
geo->GenerateMesh(mesh,mp); geo->GenerateMesh(mesh,mp);
return mesh; return mesh;
}, }, py::arg("mp") = nullptr,
py::call_guard<py::gil_scoped_release>(), py::call_guard<py::gil_scoped_release>(),
meshingparameter_description.c_str()) meshingparameter_description.c_str())
; ;

View File

@ -78,12 +78,14 @@ DLL_HEADER void ExportSTL(py::module & m)
res["max"] = MoveToNumpy(max); res["max"] = MoveToNumpy(max);
return res; return res;
}, py::call_guard<py::gil_scoped_release>()) }, py::call_guard<py::gil_scoped_release>())
.def("GenerateMesh", [] (shared_ptr<STLGeometry> geo, py::kwargs kwargs) .def("GenerateMesh", [] (shared_ptr<STLGeometry> geo,
MeshingParameters* pars, py::kwargs kwargs)
{ {
MeshingParameters mp; MeshingParameters mp;
if(pars) mp = *pars;
{ {
py::gil_scoped_acquire aq; py::gil_scoped_acquire aq;
mp = CreateMPfromKwargs(kwargs); CreateMPfromKwargs(mp, kwargs);
} }
auto mesh = make_shared<Mesh>(); auto mesh = make_shared<Mesh>();
SetGlobalMesh(mesh); SetGlobalMesh(mesh);
@ -91,7 +93,7 @@ DLL_HEADER void ExportSTL(py::module & m)
ng_geometry = geo; ng_geometry = geo;
geo->GenerateMesh(mesh,mp); geo->GenerateMesh(mesh,mp);
return mesh; return mesh;
}, }, py::arg("mp") = nullptr,
py::call_guard<py::gil_scoped_release>(), py::call_guard<py::gil_scoped_release>(),
meshingparameter_description.c_str()) meshingparameter_description.c_str())
; ;

View File

@ -1,5 +1,6 @@
from .libngpy._csg import * from .libngpy._csg import *
from .libngpy._meshing import Pnt, Vec, Trafo from .libngpy._meshing import Pnt, Vec, Trafo
from .meshing import meshsize
try: try:
from . import csgvis from . import csgvis

View File

@ -1,4 +1,5 @@
from .libngpy._geom2d import SplineGeometry from .libngpy._geom2d import SplineGeometry
from .meshing import meshsize
unit_square = SplineGeometry() unit_square = SplineGeometry()
_pnts = [ (0,0), (1,0), (1,1), (0,1) ] _pnts = [ (0,0), (1,0), (1,1), (0,1) ]

View File

@ -1 +1,22 @@
from .libngpy._meshing import * from .libngpy._meshing import *
class _MeshsizeObject:
pass
meshsize = _MeshsizeObject()
meshsize.very_coarse = MeshingParameters(curvaturesafety=1,
segmentsperedge=0.3,
grading=0.7)
meshsize.coarse = MeshingParameters(curvaturesafety=1.5,
segmentsperedge=0.5,
grading=0.5)
meshsize.moderate = MeshingParameters(curvaturesafety=2,
segmentsperedge=1,
grading=0.3)
meshsize.fine = MeshingParameters(curvaturesafety=3,
segmentsperedge=2,
grading=0.2)
meshsize.very_fine = MeshingParameters(curvaturesafety=5,
segmentsperedge=3,
grading=0.1)

View File

@ -1 +1,2 @@
from .libngpy._NgOCC import * from .libngpy._NgOCC import *
from .meshing import meshsize

View File

@ -1 +1,2 @@
from netgen.libngpy._stl import * from netgen.libngpy._stl import *
from .meshing import meshsize