python exports

This commit is contained in:
Joachim Schoeberl 2014-08-31 09:14:18 +00:00
parent e2cf4ea591
commit a5650c992d
6 changed files with 105 additions and 26 deletions

View File

@ -272,6 +272,9 @@ namespace netgen
Element2d & operator[] (SurfaceElementIndex ei)
{ return surfelements[ei]; }
const T_SURFELEMENTS & SurfaceElements() const { return surfelements; }
T_SURFELEMENTS & SurfaceElements() { return surfelements; }
DLL_HEADER void RebuildSurfaceElementLists ();
DLL_HEADER void GetSurfaceElementsOfFace (int facenr, Array<SurfaceElementIndex> & sei) const;

View File

@ -639,7 +639,8 @@ namespace netgen
MeshOptimize3d optmesh(mp);
// teterrpow = mp.opterrpow;
for (size_t j = 1; j <= strlen(mp.optimize3d); j++)
// for (size_t j = 1; j <= strlen(mp.optimize3d); j++)
for (size_t j = 1; j <= mp.optimize3d.length(); j++)
{
if (multithread.terminate)
break;

View File

@ -2517,7 +2517,7 @@ namespace netgen
//optimize3d = "cmdmstm";
optsteps3d = 3;
optimize2d = "smsmsmSmSmSm";
optsteps2d = 3;
// optsteps2d = 3;
opterrpow = 2;
blockfill = 1;
filldist = 0.1;

View File

@ -1011,9 +1011,9 @@ namespace netgen
// h .. Histogramm, no pause
// H .. Histogramm, pause
*/
const char * optimize3d;
string optimize3d;
/// number of 3d optimization steps
int optsteps3d;
int optsteps3d = 3;
/**
2d optimization strategy:
// s .. swap, opt 6 lines/node
@ -1091,13 +1091,13 @@ namespace netgen
/// high order element curvature
int elementorder;
/// quad-dominated surface meshing
int quad;
int quad = 0;
///
int inverttets;
int inverttets = 0;
///
int inverttrigs;
int inverttrigs = 0;
///
int autozrefine;
int autozrefine = 0;
///
MeshingParameters ();
///
@ -1113,7 +1113,11 @@ namespace netgen
}
};
inline ostream & operator<< (ostream & ost, const MeshingParameters & mp)
{
mp.Print (ost);
return ost;
}
class DebugParameters
{

View File

@ -1,4 +1,5 @@
#include <boost/python.hpp>
#include <boost/python/slice.hpp>
#include <mystdlib.h>
#include "meshing.hpp"
@ -37,20 +38,25 @@ inline string ToString (const T& t)
template <typename T>
template <typename T, int BASE = 0, typename TIND = int>
void ExportArray ()
{
string name = string("Array_") + typeid(T).name();
bp::class_<Array<T>,boost::noncopyable>(name.c_str())
.def ("__len__", &Array<T>::Size)
bp::class_<Array<T,BASE,TIND>,boost::noncopyable>(name.c_str())
.def ("__len__", &Array<T,BASE,TIND>::Size)
.def ("__getitem__",
FunctionPointer ([](Array<T> & self, int i) -> T&
FunctionPointer ([](Array<T,BASE,TIND> & self, TIND i) -> T&
{
if (i < 0 || i >= self.Size())
if (i < BASE || i >= BASE+self.Size())
bp::exec("raise IndexError()\n");
return self[i];
}),
bp::return_value_policy<bp::reference_existing_object>())
.def ("__iter__",
bp::range (FunctionPointer([](Array<T,BASE,TIND> & self) { return &self[BASE]; }),
FunctionPointer([](Array<T,BASE,TIND> & self) { return &self[BASE+self.Size()]; })))
;
}
@ -71,12 +77,28 @@ void ExportNetgenMeshing()
bp::scope local_scope(module);
bp::class_<PointIndex>("PointId")
bp::class_<PointIndex>("PointId", bp::init<int>())
.def("__repr__", &ToString<PointIndex>)
.def("__str__", &ToString<PointIndex>)
.add_property("nr", &PointIndex::operator int)
;
bp::class_<Point<3>> ("Point")
.def(bp::init<double,double,double>())
;
bp::class_<MeshPoint,bp::bases<Point<3>>>("MeshPoint")
.def(bp::init<Point<3>>())
.add_property("p", FunctionPointer([](const MeshPoint & self)
{
bp::list l;
l.append ( (self)[0] );
l.append ( (self)[1] );
l.append ( (self)[2] );
return l;
}))
;
bp::class_<Element>("Element3D")
.add_property("vertices",
FunctionPointer ([](const Element & self) -> bp::list
@ -89,6 +111,8 @@ void ExportNetgenMeshing()
;
ExportArray<Element>();
ExportArray<Element2d>();
ExportArray<MeshPoint,PointIndex::BASE,PointIndex>();
;
@ -100,16 +124,35 @@ void ExportNetgenMeshing()
.def("Elements3D",
static_cast<Array<Element>&(Mesh::*)()> (& &Mesh::VolumeElements),
bp::return_value_policy<bp::reference_existing_object>())
/*
.def("Elements2D", &Mesh::SurfaceElements,
.def("Elements2D",
static_cast<Array<Element2d>&(Mesh::*)()> (& &Mesh::SurfaceElements),
bp::return_value_policy<bp::reference_existing_object>())
*/
.def("Points",
static_cast<Mesh::T_POINTS&(Mesh::*)()> (& &Mesh::Points),
bp::return_value_policy<bp::reference_existing_object>())
.def("__getitem__", FunctionPointer ([](const Mesh & self, PointIndex pi)
{
return self[pi];
}))
.def ("Add", FunctionPointer ([](Mesh & self, MeshPoint p)
{
return self.AddPoint (Point3d(p));
}))
;
bp::class_<MeshingParameters> ("MeshingParameters")
typedef MeshingParameters MP;
bp::class_<MP> ("MeshingParameters")
.def("__str__", &ToString<MP>)
.add_property("maxh",
FunctionPointer ([](const MP & mp ) { return mp.maxh; }),
FunctionPointer ([](MP & mp, double maxh) { return mp.maxh = maxh; }))
;
}

View File

@ -5,18 +5,46 @@ from libmesh.meshing import *
from libcsg.csg import *
geo = CSGeometry("shaft.geo")
geo = CSGeometry("cube.geo")
geo.ntlo
param = MeshingParameters()
# param.maxh = 100
print (param)
m1 = GenerateMesh (geo, param)
els = [ i for i in m1.Elements3D() ]
for i in els:
print (i.vertices)
m1.Save("pymesh.vol")
for el in m1.Elements3D():
vi = el.vertices
for j in vi:
print (j.nr, m1[j].p)
print ()
print ("num points = ", len (m1.Points()))
for p in m1.Points():
print (p.p)
m2 = Mesh()
for p in m1.Points():
l = p.p
print (l)
m2.Add ( MeshPoint (Point(l[0],l[1],l[2])) )
print ("Mesh2 is ", m2)
# els = [ i for i in m1.Elements3D() ]
# for i in els:
# print (i.vertices)
# m1.Save("pymesh.vol")
# mesh = Mesh()
# mesh.Load ("shaft.vol.gz")