meshing from python in 2d

This commit is contained in:
Joachim Schoeberl 2015-08-08 12:58:41 +02:00
parent 4e258c7b2e
commit 714385724c
7 changed files with 62 additions and 23 deletions

View File

@ -356,9 +356,6 @@ DLL_HEADER void ExportCSG()
{ {
// testout = new ofstream ("test.out"); // testout = new ofstream ("test.out");
shared_ptr<Mesh> dummy; shared_ptr<Mesh> dummy;
cout << "Genrate Mesh" << endl;
// cout << "Genrate Mesh, params = " << param << endl;
// cout << "geom, bbox = " << geo.BoundingBox() << endl;
geo.FindIdenticSurfaces(1e-8 * geo.MaxSize()); geo.FindIdenticSurfaces(1e-8 * geo.MaxSize());
geo.GenerateMesh (dummy, param, 0, 6); geo.GenerateMesh (dummy, param, 0, 6);
ng_geometry.reset (&geo, NOOP_Deleter); ng_geometry.reset (&geo, NOOP_Deleter);

View File

@ -9,12 +9,29 @@
using namespace netgen; using namespace netgen;
namespace bp = boost::python; namespace bp = boost::python;
namespace netgen
{
extern std::shared_ptr<NetgenGeometry> ng_geometry;
}
DLL_HEADER void ExportGeom2d() DLL_HEADER void ExportGeom2d()
{ {
ModuleScope module("geom2d"); ModuleScope module("geom2d");
bp::class_<SplineGeometry2d, boost::noncopyable>("SplineGeometry") bp::class_<SplineGeometry2d, shared_ptr<SplineGeometry2d>, boost::noncopyable>("SplineGeometry")
.def("__init__", bp::make_constructor
(FunctionPointer
([](const string & filename)
{
cout << "load geometry";
ifstream ist(filename);
auto geom = make_shared<SplineGeometry2d>();
geom->Load (filename.c_str());
ng_geometry = geom;
return geom;
})))
.def("Load",&SplineGeometry2d::Load) .def("Load",&SplineGeometry2d::Load)
.def("AppendPoint", FunctionPointer([](SplineGeometry2d &self, double px, double py) .def("AppendPoint", FunctionPointer([](SplineGeometry2d &self, double px, double py)
{ {
@ -201,10 +218,11 @@ DLL_HEADER void ExportGeom2d()
//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", FunctionPointer([](SplineGeometry2d &self, MeshingParameters & mparam) .def("GenerateMesh", FunctionPointer([](shared_ptr<SplineGeometry2d> self, MeshingParameters & mparam)
{ {
shared_ptr<Mesh> mesh; shared_ptr<Mesh> mesh = make_shared<Mesh> ();
self.GenerateMesh(mesh, mparam, 0, 0); ng_geometry = self;
self->GenerateMesh(mesh, mparam, 0, 0);
return mesh; return mesh;
})) }))

View File

@ -15,7 +15,8 @@ extern void Ng_PrintDest(const char * s);
//the dots for progression of program //the dots for progression of program
void PrintDot(char ch) void PrintDot(char ch)
{ {
if (printdots) // if (printdots)
if (printmessage_importance >= 4)
{ {
char st[2]; char st[2];
st[0] = ch; st[0] = ch;

View File

@ -1,4 +1,4 @@
install(FILES __init__.py meshing.py csg.py install(FILES __init__.py meshing.py csg.py geom2d.py
DESTINATION ${PYTHON_PACKAGES_INSTALL_DIR}/netgen DESTINATION ${PYTHON_PACKAGES_INSTALL_DIR}/netgen
COMPONENT netgen COMPONENT netgen
) )

View File

@ -1,3 +1,4 @@
python_PYTHON = __init__.py meshing.py csg.py python_PYTHON = __init__.py meshing.py csg.py geom2d.py

View File

@ -21,8 +21,8 @@ def VS (obj):
def csg_meshing_func (geom, maxh): def csg_meshing_func (geom, **args):
return GenerateMesh (geom, MeshingParameters (maxh=maxh)) return GenerateMesh (geom, MeshingParameters (**args))
CSGeometry.GenerateMesh = csg_meshing_func CSGeometry.GenerateMesh = csg_meshing_func

View File

@ -1,11 +1,33 @@
from nglib.meshing import * from netgen import __platform
from nglib.geom2d import * if __platform.startswith('linux') or __platform.startswith('darwin'):
# Linux or Mac OS X
geom = SplineGeometry() from libgeom2d.geom2d import *
geom.Load("square.in2d") # import libcsgvis.csgvis as csgvis
# from libcsgvis.csgvis import MouseMove
param = MeshingParameters() from libmesh.meshing import *
param.maxh = 0.05 if __platform.startswith('win'):
# Windows
m1 = geom.GenerateMesh (param) from nglib.geom2d import *
# import nglib.csgvis as csgvis
# from nglib.csgvis import MouseMove
from nglib.meshing import *
unit_square = SplineGeometry()
pi1 = unit_square.AppendPoint(0,0)
pi2 = unit_square.AppendPoint(1,0)
pi3 = unit_square.AppendPoint(1,1)
pi4 = unit_square.AppendPoint(0,1)
unit_square.Append(["line",pi1,pi2], bc=1)
unit_square.Append(["line",pi2,pi3], bc=2)
unit_square.Append(["line",pi3,pi4], bc=3)
unit_square.Append(["line",pi4,pi1], bc=4)
all = ['SplineGeometry', 'unit_square']