mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
cleanup python export, generate mesh functions not monkeypatched
This commit is contained in:
parent
c454163821
commit
091494c6b3
@ -103,6 +103,21 @@ namespace ngcore
|
||||
void operator delete[] (void * p) { aligned_free(p); }
|
||||
};
|
||||
|
||||
// Two helper functions for string checking
|
||||
inline bool StartsWith(std::string str, std::string start)
|
||||
{
|
||||
if(start.size() > str.size())
|
||||
return false;
|
||||
return std::equal(start.begin(), start.end(), str.begin());
|
||||
}
|
||||
|
||||
inline bool EndsWith(std::string str, std::string end)
|
||||
{
|
||||
if(end.size() > str.size())
|
||||
return false;
|
||||
return std::equal(end.rbegin(), end.rend(), str.rbegin());
|
||||
}
|
||||
|
||||
} // namespace ngcore
|
||||
|
||||
#endif // NETGEN_CORE_UTILS_HPP
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <../general/ngpython.hpp>
|
||||
#include <core/python_ngcore.hpp>
|
||||
#include <csg.hpp>
|
||||
#include "../meshing/python_mesh.hpp"
|
||||
|
||||
|
||||
using namespace netgen;
|
||||
@ -693,26 +694,22 @@ However, when r = 0, the top part becomes a point(tip) and meshing fails!
|
||||
res["max"] = MoveToNumpy(max);
|
||||
return res;
|
||||
}, py::call_guard<py::gil_scoped_release>())
|
||||
;
|
||||
|
||||
m.def("GenerateMesh", FunctionPointer
|
||||
([](shared_ptr<CSGeometry> geo, MeshingParameters & param)
|
||||
.def("GenerateMesh", [](shared_ptr<CSGeometry> geo, py::kwargs kwargs)
|
||||
{
|
||||
auto dummy = make_shared<Mesh>();
|
||||
SetGlobalMesh (dummy);
|
||||
dummy->SetGeometry(geo);
|
||||
MeshingParameters mp;
|
||||
{
|
||||
py::gil_scoped_acquire aq;
|
||||
mp = CreateMPfromKwargs(kwargs);
|
||||
}
|
||||
auto mesh = make_shared<Mesh>();
|
||||
SetGlobalMesh (mesh);
|
||||
mesh->SetGeometry(geo);
|
||||
ng_geometry = geo;
|
||||
geo->FindIdenticSurfaces(1e-8 * geo->MaxSize());
|
||||
try
|
||||
{
|
||||
geo->GenerateMesh (dummy, param);
|
||||
}
|
||||
catch (NgException ex)
|
||||
{
|
||||
cout << "Caught NgException: " << ex.What() << endl;
|
||||
}
|
||||
return dummy;
|
||||
}),py::call_guard<py::gil_scoped_release>())
|
||||
geo->GenerateMesh (mesh, mp);
|
||||
return mesh;
|
||||
}, meshingparameter_description.c_str(),
|
||||
py::call_guard<py::gil_scoped_release>())
|
||||
;
|
||||
|
||||
m.def("Save", FunctionPointer
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <../general/ngpython.hpp>
|
||||
#include <core/python_ngcore.hpp>
|
||||
#include "../meshing/python_mesh.hpp"
|
||||
|
||||
#include <meshing.hpp>
|
||||
#include <geometry2d.hpp>
|
||||
@ -362,16 +363,21 @@ DLL_HEADER void ExportGeom2d(py::module &m)
|
||||
//cout << i << " : " << self.splines[i]->GetPoint(0.1) << " , " << self.splines[i]->GetPoint(0.5) << endl;
|
||||
}
|
||||
}))
|
||||
.def("GenerateMesh", [](shared_ptr<SplineGeometry2d> self, MeshingParameters & mparam)
|
||||
.def("GenerateMesh", [](shared_ptr<SplineGeometry2d> self, py::kwargs kwargs)
|
||||
{
|
||||
shared_ptr<Mesh> mesh = make_shared<Mesh> ();
|
||||
MeshingParameters mp;
|
||||
{
|
||||
py::gil_scoped_acquire aq;
|
||||
mp = CreateMPfromKwargs(kwargs);
|
||||
}
|
||||
auto mesh = make_shared<Mesh>();
|
||||
mesh->SetGeometry(self);
|
||||
SetGlobalMesh (mesh);
|
||||
ng_geometry = self;
|
||||
self->GenerateMesh(mesh, mparam);
|
||||
self->GenerateMesh(mesh, mp);
|
||||
return mesh;
|
||||
},py::call_guard<py::gil_scoped_release>())
|
||||
|
||||
}, py::call_guard<py::gil_scoped_release>(),
|
||||
meshingparameter_description.c_str())
|
||||
;
|
||||
|
||||
}
|
||||
|
@ -1191,7 +1191,7 @@ namespace netgen
|
||||
/// power of error (to approximate max err optimization)
|
||||
double opterrpow = 2;
|
||||
/// do block filling ?
|
||||
int blockfill = 1;
|
||||
bool blockfill = true;
|
||||
/// block filling up to distance
|
||||
double filldist = 0.1;
|
||||
/// radius of local environment (times h)
|
||||
@ -1199,11 +1199,11 @@ namespace netgen
|
||||
/// radius of active environment (times h)
|
||||
double relinnersafety = 3;
|
||||
/// use local h ?
|
||||
int uselocalh = 1;
|
||||
bool uselocalh = true;
|
||||
/// grading for local h
|
||||
double grading = 0.3;
|
||||
/// use delaunay meshing
|
||||
int delaunay = 1;
|
||||
bool delaunay = true;
|
||||
/// maximal mesh size
|
||||
double maxh = 1e10;
|
||||
/// minimal mesh size
|
||||
@ -1211,19 +1211,19 @@ namespace netgen
|
||||
/// file for meshsize
|
||||
string meshsizefilename = "";
|
||||
/// start surfacemeshing from everywhere in surface
|
||||
int startinsurface = 0;
|
||||
bool startinsurface = false;
|
||||
/// check overlapping surfaces (debug)
|
||||
int checkoverlap = 1;
|
||||
bool checkoverlap = true;
|
||||
/// check overlapping surface mesh before volume meshing
|
||||
int checkoverlappingboundary = 1;
|
||||
bool checkoverlappingboundary = true;
|
||||
/// check chart boundary (sometimes too restrictive)
|
||||
int checkchartboundary = 1;
|
||||
bool checkchartboundary = true;
|
||||
/// safety factor for curvatures (elements per radius)
|
||||
double curvaturesafety = 2;
|
||||
/// minimal number of segments per edge
|
||||
double segmentsperedge = 1;
|
||||
/// use parallel threads
|
||||
int parthread = 0;
|
||||
bool parthread = 0;
|
||||
/// weight of element size w.r.t element shape
|
||||
double elsizeweight = 0.2;
|
||||
/// init with default values
|
||||
@ -1246,29 +1246,29 @@ namespace netgen
|
||||
/// if non-zero, baseelement must have baseelnp points
|
||||
int baseelnp = 0;
|
||||
/// quality tolerances are handled less careful
|
||||
int sloppy = 1;
|
||||
bool sloppy = true;
|
||||
|
||||
/// limit for max element angle (150-180)
|
||||
double badellimit = 175;
|
||||
|
||||
bool check_impossible = 0;
|
||||
bool check_impossible = false;
|
||||
|
||||
int only3D_domain_nr = 0;
|
||||
|
||||
///
|
||||
int secondorder = 0;
|
||||
bool secondorder = false;
|
||||
/// high order element curvature
|
||||
int elementorder = 1;
|
||||
/// quad-dominated surface meshing
|
||||
int quad = 0;
|
||||
bool quad = false;
|
||||
///
|
||||
bool try_hexes = false;
|
||||
///
|
||||
int inverttets = 0;
|
||||
bool inverttets = false;
|
||||
///
|
||||
int inverttrigs = 0;
|
||||
bool inverttrigs = false;
|
||||
///
|
||||
int autozrefine = 0;
|
||||
bool autozrefine = false;
|
||||
///
|
||||
MeshingParameters ();
|
||||
///
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <../general/ngpython.hpp>
|
||||
#include <core/python_ngcore.hpp>
|
||||
#include "python_mesh.hpp"
|
||||
|
||||
#include <mystdlib.h>
|
||||
#include "meshing.hpp"
|
||||
@ -1026,38 +1027,12 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
||||
;
|
||||
|
||||
typedef MeshingParameters MP;
|
||||
py::class_<MP> (m, "MeshingParameters")
|
||||
auto mp = py::class_<MP> (m, "MeshingParameters")
|
||||
.def(py::init<>())
|
||||
.def(py::init([](double maxh, bool quad_dominated, int optsteps2d, int optsteps3d,
|
||||
MESHING_STEP perfstepsend, int only3D_domain, const string & meshsizefilename,
|
||||
double grading, double curvaturesafety, double segmentsperedge)
|
||||
.def(py::init([](py::kwargs kwargs)
|
||||
{
|
||||
MP * instance = new MeshingParameters;
|
||||
instance->maxh = maxh;
|
||||
instance->quad = int(quad_dominated);
|
||||
instance->optsteps2d = optsteps2d;
|
||||
instance->optsteps3d = optsteps3d;
|
||||
instance->only3D_domain_nr = only3D_domain;
|
||||
instance->perfstepsend = perfstepsend;
|
||||
instance->meshsizefilename = meshsizefilename;
|
||||
|
||||
instance->grading = grading;
|
||||
instance->curvaturesafety = curvaturesafety;
|
||||
instance->segmentsperedge = segmentsperedge;
|
||||
return instance;
|
||||
}),
|
||||
py::arg("maxh")=1000,
|
||||
py::arg("quad_dominated")=false,
|
||||
py::arg("optsteps2d") = 3,
|
||||
py::arg("optsteps3d") = 3,
|
||||
py::arg("perfstepsend") = MESHCONST_OPTVOLUME,
|
||||
py::arg("only3D_domain") = 0,
|
||||
py::arg("meshsizefilename") = "",
|
||||
py::arg("grading")=0.3,
|
||||
py::arg("curvaturesafety")=2,
|
||||
py::arg("segmentsperedge")=1,
|
||||
"create meshing parameters"
|
||||
)
|
||||
return CreateMPfromKwargs(kwargs);
|
||||
}), meshingparameter_description.c_str())
|
||||
.def("__str__", &ToString<MP>)
|
||||
.def_property("maxh",
|
||||
FunctionPointer ([](const MP & mp ) { return mp.maxh; }),
|
||||
|
170
libsrc/meshing/python_mesh.hpp
Normal file
170
libsrc/meshing/python_mesh.hpp
Normal file
@ -0,0 +1,170 @@
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
#include "meshing.hpp"
|
||||
|
||||
namespace netgen
|
||||
{
|
||||
// TODO: Clarify a lot of these parameters
|
||||
static string meshingparameter_description = R"delimiter(
|
||||
Meshing Parameters
|
||||
-------------------
|
||||
|
||||
maxh: float = 1e10
|
||||
Global upper bound for mesh size.
|
||||
|
||||
grading: float = 0.3
|
||||
Mesh grading how fast the local mesh size can change.
|
||||
|
||||
meshsizefilename: str = None
|
||||
Load meshsize from file. Can set local mesh size for points
|
||||
and along edges. File must have the format:
|
||||
|
||||
nr_points
|
||||
x1, y1, z1, meshsize
|
||||
x2, y2, z2, meshsize
|
||||
...
|
||||
xn, yn, zn, meshsize
|
||||
|
||||
nr_edges
|
||||
x11, y11, z11, x12, y12, z12, meshsize
|
||||
...
|
||||
xn1, yn1, zn1, xn2, yn2, zn2, meshsize
|
||||
|
||||
segmentsperedge: float = 1.
|
||||
Minimal number of segments per edge.
|
||||
|
||||
quad: bool = False
|
||||
Quad-dominated surface meshing.
|
||||
|
||||
blockfill: bool = True
|
||||
Do fast blockfilling.
|
||||
|
||||
filldist: float = 0.1
|
||||
Block fill up to distance
|
||||
|
||||
delaunay: bool = True
|
||||
Use delaunay meshing.
|
||||
|
||||
Optimization Parameters
|
||||
-----------------------
|
||||
|
||||
optimize3d: str = "cmdmustm"
|
||||
3d optimization strategy:
|
||||
m .. move nodes
|
||||
M .. move nodes, cheap functional
|
||||
s .. swap faces
|
||||
c .. combine elements
|
||||
d .. divide elements
|
||||
p .. plot, no pause
|
||||
P .. plot, Pause
|
||||
h .. Histogramm, no pause
|
||||
H .. Histogramm, pause
|
||||
|
||||
optsteps3d: int = 3
|
||||
Number of 3d optimization steps.
|
||||
|
||||
optimize2d: str = "smsmsmSmSmSm"
|
||||
2d optimization strategy:
|
||||
s .. swap, opt 6 lines/node
|
||||
S .. swap, optimal elements
|
||||
m .. move nodes
|
||||
p .. plot, no pause
|
||||
P .. plot, pause
|
||||
c .. combine
|
||||
|
||||
optsteps2d: int = 3
|
||||
Number of 2d optimization steps.
|
||||
|
||||
elsizeweight: float = 0.2
|
||||
Weight of element size w.r.t. element shape in optimization.
|
||||
|
||||
)delimiter";
|
||||
|
||||
MeshingParameters CreateMPfromKwargs(py::kwargs kwargs)
|
||||
{
|
||||
MeshingParameters mp;
|
||||
if(kwargs.contains("optimize3d"))
|
||||
mp.optimize3d = py::cast<string>(kwargs["optimize3d"]);
|
||||
if(kwargs.contains("optsteps3d"))
|
||||
mp.optsteps3d = py::cast<int>(kwargs["optsteps3d"]);
|
||||
if(kwargs.contains("optimize2d"))
|
||||
mp.optimize2d = py::cast<string>(kwargs["optimize2d"]);
|
||||
if(kwargs.contains("optsteps2d"))
|
||||
mp.optsteps2d = py::cast<int>(kwargs["optsteps2d"]);
|
||||
if(kwargs.contains("opterrpow"))
|
||||
mp.opterrpow = py::cast<double>(kwargs["opterrpow"]);
|
||||
if(kwargs.contains("blockfill"))
|
||||
mp.blockfill = py::cast<bool>(kwargs["blockfill"]);
|
||||
if(kwargs.contains("filldist"))
|
||||
mp.filldist = py::cast<double>(kwargs["filldist"]);
|
||||
if(kwargs.contains("safety"))
|
||||
mp.safety = py::cast<double>(kwargs["safety"]);
|
||||
if(kwargs.contains("relinnersafety"))
|
||||
mp.relinnersafety = py::cast<double>(kwargs["relinnersafety"]);
|
||||
if(kwargs.contains("uselocalh"))
|
||||
mp.uselocalh = py::cast<bool>(kwargs["uselocalh"]);
|
||||
if(kwargs.contains("grading"))
|
||||
mp.grading = py::cast<double>(kwargs["grading"]);
|
||||
if(kwargs.contains("delaunay"))
|
||||
mp.delaunay = py::cast<bool>(kwargs["delaunay"]);
|
||||
if(kwargs.contains("maxh"))
|
||||
mp.maxh = py::cast<double>(kwargs["maxh"]);
|
||||
if(kwargs.contains("minh"))
|
||||
mp.minh = py::cast<double>(kwargs["minh"]);
|
||||
if(kwargs.contains("meshsizefilename"))
|
||||
mp.meshsizefilename = py::cast<string>(kwargs["meshsizefilename"]);
|
||||
if(kwargs.contains("startinsurface"))
|
||||
mp.startinsurface = py::cast<bool>(kwargs["startinsurface"]);
|
||||
if(kwargs.contains("checkoverlap"))
|
||||
mp.checkoverlap = py::cast<bool>(kwargs["checkoverlap"]);
|
||||
if(kwargs.contains("checkoverlappingboundary"))
|
||||
mp.checkoverlappingboundary = py::cast<bool>(kwargs["checkoverlappingboundary"]);
|
||||
if(kwargs.contains("checkchartboundary"))
|
||||
mp.checkchartboundary = py::cast<bool>(kwargs["checkchartboundary"]);
|
||||
if(kwargs.contains("curvaturesafety"))
|
||||
mp.curvaturesafety = py::cast<double>(kwargs["curvaturesafety"]);
|
||||
if(kwargs.contains("segmentsperedge"))
|
||||
mp.segmentsperedge = py::cast<double>(kwargs["segmentsperedge"]);
|
||||
if(kwargs.contains("parthread"))
|
||||
mp.parthread = py::cast<bool>(kwargs["parthread"]);
|
||||
if(kwargs.contains("elsizeweight"))
|
||||
mp.elsizeweight = py::cast<double>(kwargs["elsizeweight"]);
|
||||
if(kwargs.contains("perfstepsstart"))
|
||||
mp.perfstepsstart = py::cast<int>(kwargs["perfstepsstart"]);
|
||||
if(kwargs.contains("perfstepsend"))
|
||||
mp.perfstepsend = py::cast<int>(kwargs["perfstepsend"]);
|
||||
if(kwargs.contains("giveuptol2d"))
|
||||
mp.giveuptol2d = py::cast<int>(kwargs["giveuptol2d"]);
|
||||
if(kwargs.contains("giveuptol"))
|
||||
mp.giveuptol = py::cast<int>(kwargs["giveuptol"]);
|
||||
if(kwargs.contains("maxoutersteps"))
|
||||
mp.maxoutersteps = py::cast<int>(kwargs["maxoutersteps"]);
|
||||
if(kwargs.contains("starshapeclass"))
|
||||
mp.starshapeclass = py::cast<int>(kwargs["starshapeclass"]);
|
||||
if(kwargs.contains("baseelnp"))
|
||||
mp.baseelnp = py::cast<int>(kwargs["baseelnp"]);
|
||||
if(kwargs.contains("sloppy"))
|
||||
mp.sloppy = py::cast<bool>(kwargs["sloppy"]);
|
||||
if(kwargs.contains("badellimit"))
|
||||
mp.badellimit = py::cast<double>(kwargs["badellimit"]);
|
||||
if(kwargs.contains("check_impossible"))
|
||||
mp.check_impossible = py::cast<bool>(kwargs["check_impossible"]);
|
||||
if(kwargs.contains("only3D_domain_nr"))
|
||||
mp.only3D_domain_nr = py::cast<int>(kwargs["only3D_domain_nr"]);
|
||||
if(kwargs.contains("secondorder"))
|
||||
mp.secondorder = py::cast<bool>(kwargs["secondorder"]);
|
||||
if(kwargs.contains("elementorder"))
|
||||
mp.elementorder = py::cast<int>(kwargs["elementorder"]);
|
||||
if(kwargs.contains("quad"))
|
||||
mp.quad = py::cast<bool>(kwargs["quad"]);
|
||||
if(kwargs.contains("try_hexes"))
|
||||
mp.try_hexes = py::cast<bool>(kwargs["try_hexes"]);
|
||||
if(kwargs.contains("inverttets"))
|
||||
mp.inverttets = py::cast<bool>(kwargs["inverttets"]);
|
||||
if(kwargs.contains("inverttrigs"))
|
||||
mp.inverttrigs = py::cast<bool>(kwargs["inverttrigs"]);
|
||||
if(kwargs.contains("autozrefine"))
|
||||
mp.autozrefine = py::cast<bool>(kwargs["autozrefine"]);
|
||||
return mp;
|
||||
}
|
||||
} // namespace netgen
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <../general/ngpython.hpp>
|
||||
#include <core/python_ngcore.hpp>
|
||||
#include "../meshing/python_mesh.hpp"
|
||||
|
||||
#include <meshing.hpp>
|
||||
#include <occgeom.hpp>
|
||||
@ -19,6 +20,21 @@ DLL_HEADER void ExportNgOCC(py::module &m)
|
||||
{
|
||||
py::class_<OCCGeometry, shared_ptr<OCCGeometry>, NetgenGeometry> (m, "OCCGeometry", R"raw_string(Use LoadOCCGeometry to load the geometry from a *.step file.)raw_string")
|
||||
.def(py::init<>())
|
||||
.def(py::init([] (const string& filename)
|
||||
{
|
||||
shared_ptr<OCCGeometry> geo;
|
||||
if(EndsWith(filename, ".step") || EndsWith(filename, ".stp"))
|
||||
geo.reset(LoadOCC_STEP(filename.c_str()));
|
||||
else if(EndsWith(filename, ".brep"))
|
||||
geo.reset(LoadOCC_BREP(filename.c_str()));
|
||||
else if(EndsWith(filename, ".iges"))
|
||||
geo.reset(LoadOCC_IGES(filename.c_str()));
|
||||
else
|
||||
throw Exception("Cannot load file " + filename + "\nValid formats are: step, stp, brep, iges");
|
||||
ng_geometry = geo;
|
||||
return geo;
|
||||
}), py::arg("filename"),
|
||||
"Load OCC geometry from step, brep or iges file")
|
||||
.def(NGSPickle<OCCGeometry>())
|
||||
.def("Heal",[](OCCGeometry & self, double tolerance, bool fixsmalledges, bool fixspotstripfaces, bool sewfaces, bool makesolids, bool splitpartitions)
|
||||
{
|
||||
@ -108,34 +124,33 @@ DLL_HEADER void ExportNgOCC(py::module &m)
|
||||
res["max"] = MoveToNumpy(max);
|
||||
return res;
|
||||
}, py::call_guard<py::gil_scoped_release>())
|
||||
;
|
||||
m.def("LoadOCCGeometry",FunctionPointer([] (const string & filename)
|
||||
.def("GenerateMesh", [](shared_ptr<OCCGeometry> geo, py::kwargs kwargs)
|
||||
{
|
||||
MeshingParameters mp;
|
||||
{
|
||||
py::gil_scoped_acquire aq;
|
||||
mp = CreateMPfromKwargs(kwargs);
|
||||
}
|
||||
auto mesh = make_shared<Mesh>();
|
||||
SetGlobalMesh(mesh);
|
||||
mesh->SetGeometry(geo);
|
||||
ng_geometry = geo;
|
||||
geo->GenerateMesh(mesh,mp);
|
||||
return mesh;
|
||||
},
|
||||
py::call_guard<py::gil_scoped_release>(),
|
||||
meshingparameter_description.c_str())
|
||||
;
|
||||
|
||||
m.def("LoadOCCGeometry",[] (const string & filename)
|
||||
{
|
||||
cout << "load OCC geometry";
|
||||
cout << "WARNING: LoadOCCGeometry is deprecated! Just use the OCCGeometry(filename) constructor. It is able to read brep and iges files as well!" << endl;
|
||||
ifstream ist(filename);
|
||||
OCCGeometry * instance = new OCCGeometry();
|
||||
instance = LoadOCC_STEP(filename.c_str());
|
||||
ng_geometry = shared_ptr<OCCGeometry>(instance, NOOP_Deleter);
|
||||
return ng_geometry;
|
||||
}),py::call_guard<py::gil_scoped_release>());
|
||||
m.def("GenerateMesh", FunctionPointer([] (shared_ptr<OCCGeometry> geo, MeshingParameters ¶m)
|
||||
{
|
||||
auto mesh = make_shared<Mesh>();
|
||||
SetGlobalMesh(mesh);
|
||||
mesh->SetGeometry(geo);
|
||||
ng_geometry = geo;
|
||||
|
||||
try
|
||||
{
|
||||
geo->GenerateMesh(mesh,param);
|
||||
}
|
||||
catch (NgException ex)
|
||||
{
|
||||
cout << "Caught NgException: " << ex.What() << endl;
|
||||
}
|
||||
return mesh;
|
||||
}),py::call_guard<py::gil_scoped_release>())
|
||||
;
|
||||
},py::call_guard<py::gil_scoped_release>());
|
||||
}
|
||||
|
||||
PYBIND11_MODULE(libNgOCC, m) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <../general/ngpython.hpp>
|
||||
#include <core/python_ngcore.hpp>
|
||||
#include <stlgeom.hpp>
|
||||
#include "../meshing/python_mesh.hpp"
|
||||
|
||||
#ifdef WIN32
|
||||
#define DLL_HEADER __declspec(dllexport)
|
||||
@ -21,6 +22,12 @@ DLL_HEADER void ExportSTL(py::module & m)
|
||||
{
|
||||
py::class_<STLGeometry,shared_ptr<STLGeometry>, NetgenGeometry> (m,"STLGeometry")
|
||||
.def(py::init<>())
|
||||
.def(py::init<>([](const string& filename)
|
||||
{
|
||||
ifstream ist(filename);
|
||||
return shared_ptr<STLGeometry>(STLGeometry::Load(ist));
|
||||
}), py::arg("filename"),
|
||||
py::call_guard<py::gil_scoped_release>())
|
||||
.def(NGSPickle<STLGeometry>())
|
||||
.def("_visualizationData", [](shared_ptr<STLGeometry> stl_geo)
|
||||
{
|
||||
@ -71,29 +78,29 @@ DLL_HEADER void ExportSTL(py::module & m)
|
||||
res["max"] = MoveToNumpy(max);
|
||||
return res;
|
||||
}, py::call_guard<py::gil_scoped_release>())
|
||||
.def("GenerateMesh", [] (shared_ptr<STLGeometry> geo, py::kwargs kwargs)
|
||||
{
|
||||
MeshingParameters mp;
|
||||
{
|
||||
py::gil_scoped_acquire aq;
|
||||
mp = CreateMPfromKwargs(kwargs);
|
||||
}
|
||||
auto mesh = make_shared<Mesh>();
|
||||
SetGlobalMesh(mesh);
|
||||
mesh->SetGeometry(geo);
|
||||
ng_geometry = geo;
|
||||
geo->GenerateMesh(mesh,mp);
|
||||
return mesh;
|
||||
},
|
||||
py::call_guard<py::gil_scoped_release>(),
|
||||
meshingparameter_description.c_str())
|
||||
;
|
||||
m.def("LoadSTLGeometry", FunctionPointer([] (const string & filename)
|
||||
{
|
||||
ifstream ist(filename);
|
||||
return shared_ptr<STLGeometry>(STLGeometry::Load(ist));
|
||||
}),py::call_guard<py::gil_scoped_release>());
|
||||
m.def("GenerateMesh", FunctionPointer([] (shared_ptr<STLGeometry> geo, MeshingParameters ¶m)
|
||||
{
|
||||
auto mesh = make_shared<Mesh>();
|
||||
SetGlobalMesh(mesh);
|
||||
mesh->SetGeometry(geo);
|
||||
ng_geometry = geo;
|
||||
try
|
||||
{
|
||||
geo->GenerateMesh(mesh,param);
|
||||
}
|
||||
catch (NgException ex)
|
||||
{
|
||||
cout << "Caught NgException: " << ex.What() << endl;
|
||||
}
|
||||
return mesh;
|
||||
}),py::call_guard<py::gil_scoped_release>())
|
||||
;
|
||||
m.def("LoadSTLGeometry", [] (const string & filename)
|
||||
{
|
||||
cout << "WARNING: LoadSTLGeometry is deprecated, use the STLGeometry(filename) constructor instead!" << endl;
|
||||
ifstream ist(filename);
|
||||
return shared_ptr<STLGeometry>(STLGeometry::Load(ist));
|
||||
},py::call_guard<py::gil_scoped_release>());
|
||||
}
|
||||
|
||||
PYBIND11_MODULE(libstl, m) {
|
||||
|
@ -7,7 +7,7 @@ configure_file(__init__.py ${CMAKE_CURRENT_BINARY_DIR}/__init__.py @ONLY)
|
||||
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/__init__.py
|
||||
meshing.py csg.py geom2d.py stl.py gui.py NgOCC.py read_gmsh.py
|
||||
meshing.py csg.py geom2d.py stl.py gui.py NgOCC.py occ.py read_gmsh.py
|
||||
DESTINATION ${NG_INSTALL_DIR_PYTHON}/${NG_INSTALL_SUFFIX}
|
||||
COMPONENT netgen
|
||||
)
|
||||
|
@ -1,10 +1,7 @@
|
||||
from netgen.libngpy._NgOCC import *
|
||||
from netgen.libngpy._meshing import MeshingParameters
|
||||
|
||||
def NgOCC_meshing_func (geom, **args):
|
||||
if "mp" in args:
|
||||
return GenerateMesh (geom, args["mp"])
|
||||
else:
|
||||
return GenerateMesh (geom, MeshingParameters (**args))
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
OCCGeometry.GenerateMesh = NgOCC_meshing_func
|
||||
logger.warn("This module is deprecated and just a wrapper for netgen.occ, import netgen.occ instead")
|
||||
|
||||
from .occ import *
|
||||
|
@ -1,34 +1,18 @@
|
||||
from netgen.libngpy._csg import *
|
||||
from netgen.libngpy._meshing import MeshingParameters
|
||||
from netgen.libngpy._meshing import Pnt
|
||||
from netgen.libngpy._meshing import Vec
|
||||
from netgen.libngpy._meshing import Trafo
|
||||
|
||||
from .libngpy._csg import *
|
||||
from .libngpy._meshing import Pnt, Vec, Trafo
|
||||
|
||||
try:
|
||||
import libngpy.csgvis as csgvis
|
||||
from libngpy.csgvis import MouseMove
|
||||
from . import csgvis
|
||||
from .csgvis import MouseMove
|
||||
CSGeometry.VS = csgvis.VS
|
||||
SetBackGroundColor = csgvis.SetBackGroundColor
|
||||
del csgvis
|
||||
|
||||
def VS (obj):
|
||||
return obj.VS()
|
||||
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def csg_meshing_func (geom, **args):
|
||||
if "mp" in args:
|
||||
return GenerateMesh (geom, args["mp"])
|
||||
else:
|
||||
return GenerateMesh (geom, MeshingParameters (**args))
|
||||
# return GenerateMesh (geom, MeshingParameters (**args))
|
||||
|
||||
CSGeometry.GenerateMesh = csg_meshing_func
|
||||
|
||||
|
||||
unit_cube = CSGeometry()
|
||||
p1 = Plane(Pnt(0,0,0),Vec(-1,0,0)).bc("back")
|
||||
p2 = Plane(Pnt(1,1,1),Vec(1,0,0)).bc("front")
|
||||
@ -37,5 +21,4 @@ p4 = Plane(Pnt(1,1,1),Vec(0,1,0)).bc("right")
|
||||
p5 = Plane(Pnt(0,0,0),Vec(0,0,-1)).bc("bottom")
|
||||
p6 = Plane(Pnt(1,1,1),Vec(0,0,1)).bc("top")
|
||||
unit_cube.Add (p1*p2*p3*p4*p5*p6, col=(0,0,1))
|
||||
# unit_cube.Add (OrthoBrick(Pnt(0,0,0), Pnt(1,1,1)))
|
||||
|
||||
|
@ -1,24 +1,11 @@
|
||||
from netgen.libngpy._geom2d import *
|
||||
from netgen.libngpy._meshing import *
|
||||
|
||||
tmp_generate_mesh = SplineGeometry.GenerateMesh
|
||||
|
||||
def geom2d_meshing_func (geom, **args):
|
||||
if "mp" in args:
|
||||
return tmp_generate_mesh (geom, args["mp"])
|
||||
else:
|
||||
return tmp_generate_mesh (geom, MeshingParameters (**args))
|
||||
|
||||
|
||||
SplineGeometry.GenerateMesh = geom2d_meshing_func
|
||||
|
||||
from .libngpy._geom2d import SplineGeometry
|
||||
|
||||
unit_square = SplineGeometry()
|
||||
pnts = [ (0,0), (1,0), (1,1), (0,1) ]
|
||||
lines = [ (0,1,1,"bottom"), (1,2,2,"right"), (2,3,3,"top"), (3,0,4,"left") ]
|
||||
pnums = [unit_square.AppendPoint(*p) for p in pnts]
|
||||
for l1,l2,bc,bcname in lines:
|
||||
unit_square.Append( ["line", pnums[l1], pnums[l2]], bc=bcname)
|
||||
_pnts = [ (0,0), (1,0), (1,1), (0,1) ]
|
||||
_lines = [ (0,1,1,"bottom"), (1,2,2,"right"), (2,3,3,"top"), (3,0,4,"left") ]
|
||||
_pnums = [unit_square.AppendPoint(*p) for p in _pnts]
|
||||
for l1,l2,bc,bcname in _lines:
|
||||
unit_square.Append( ["line", _pnums[l1], _pnums[l2]], bc=bcname)
|
||||
|
||||
|
||||
def MakeRectangle (geo, p1, p2, bc=None, bcs=None, **args):
|
||||
@ -141,8 +128,4 @@ SplineGeometry.AddSegment = lambda *args, **kwargs : SplineGeometry.Append(*args
|
||||
SplineGeometry.AddPoint = lambda *args, **kwargs : SplineGeometry.AppendPoint(*args, **kwargs)
|
||||
SplineGeometry.CreatePML = CreatePML
|
||||
|
||||
__all__ = ['SplineGeometry', 'unit_square']
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1 +1 @@
|
||||
from netgen.libngpy._meshing import *
|
||||
from .libngpy._meshing import *
|
||||
|
1
python/occ.py
Normal file
1
python/occ.py
Normal file
@ -0,0 +1 @@
|
||||
from .libngpy._NgOCC import *
|
@ -1,12 +1 @@
|
||||
from netgen.libngpy._stl import *
|
||||
from netgen.libngpy._meshing import MeshingParameters
|
||||
|
||||
|
||||
def stl_meshing_func (geom, **args):
|
||||
if "mp" in args:
|
||||
return GenerateMesh (geom, args["mp"])
|
||||
else:
|
||||
return GenerateMesh (geom, MeshingParameters (**args))
|
||||
# return GenerateMesh (geom, MeshingParameters (**args))
|
||||
|
||||
STLGeometry.GenerateMesh = stl_meshing_func
|
||||
|
Loading…
Reference in New Issue
Block a user