mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-26 13:50:33 +05:00
python exports
This commit is contained in:
parent
e2cf4ea591
commit
a5650c992d
@ -272,6 +272,9 @@ namespace netgen
|
|||||||
Element2d & operator[] (SurfaceElementIndex ei)
|
Element2d & operator[] (SurfaceElementIndex ei)
|
||||||
{ return surfelements[ei]; }
|
{ return surfelements[ei]; }
|
||||||
|
|
||||||
|
const T_SURFELEMENTS & SurfaceElements() const { return surfelements; }
|
||||||
|
T_SURFELEMENTS & SurfaceElements() { return surfelements; }
|
||||||
|
|
||||||
|
|
||||||
DLL_HEADER void RebuildSurfaceElementLists ();
|
DLL_HEADER void RebuildSurfaceElementLists ();
|
||||||
DLL_HEADER void GetSurfaceElementsOfFace (int facenr, Array<SurfaceElementIndex> & sei) const;
|
DLL_HEADER void GetSurfaceElementsOfFace (int facenr, Array<SurfaceElementIndex> & sei) const;
|
||||||
|
@ -639,7 +639,8 @@ namespace netgen
|
|||||||
MeshOptimize3d optmesh(mp);
|
MeshOptimize3d optmesh(mp);
|
||||||
|
|
||||||
// teterrpow = mp.opterrpow;
|
// 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)
|
if (multithread.terminate)
|
||||||
break;
|
break;
|
||||||
|
@ -2517,7 +2517,7 @@ namespace netgen
|
|||||||
//optimize3d = "cmdmstm";
|
//optimize3d = "cmdmstm";
|
||||||
optsteps3d = 3;
|
optsteps3d = 3;
|
||||||
optimize2d = "smsmsmSmSmSm";
|
optimize2d = "smsmsmSmSmSm";
|
||||||
optsteps2d = 3;
|
// optsteps2d = 3;
|
||||||
opterrpow = 2;
|
opterrpow = 2;
|
||||||
blockfill = 1;
|
blockfill = 1;
|
||||||
filldist = 0.1;
|
filldist = 0.1;
|
||||||
|
@ -1011,9 +1011,9 @@ namespace netgen
|
|||||||
// h .. Histogramm, no pause
|
// h .. Histogramm, no pause
|
||||||
// H .. Histogramm, pause
|
// H .. Histogramm, pause
|
||||||
*/
|
*/
|
||||||
const char * optimize3d;
|
string optimize3d;
|
||||||
/// number of 3d optimization steps
|
/// number of 3d optimization steps
|
||||||
int optsteps3d;
|
int optsteps3d = 3;
|
||||||
/**
|
/**
|
||||||
2d optimization strategy:
|
2d optimization strategy:
|
||||||
// s .. swap, opt 6 lines/node
|
// s .. swap, opt 6 lines/node
|
||||||
@ -1091,13 +1091,13 @@ namespace netgen
|
|||||||
/// high order element curvature
|
/// high order element curvature
|
||||||
int elementorder;
|
int elementorder;
|
||||||
/// quad-dominated surface meshing
|
/// 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 ();
|
MeshingParameters ();
|
||||||
///
|
///
|
||||||
@ -1113,7 +1113,11 @@ namespace netgen
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline ostream & operator<< (ostream & ost, const MeshingParameters & mp)
|
||||||
|
{
|
||||||
|
mp.Print (ost);
|
||||||
|
return ost;
|
||||||
|
}
|
||||||
|
|
||||||
class DebugParameters
|
class DebugParameters
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <boost/python.hpp>
|
#include <boost/python.hpp>
|
||||||
|
#include <boost/python/slice.hpp>
|
||||||
|
|
||||||
#include <mystdlib.h>
|
#include <mystdlib.h>
|
||||||
#include "meshing.hpp"
|
#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 ()
|
void ExportArray ()
|
||||||
{
|
{
|
||||||
string name = string("Array_") + typeid(T).name();
|
string name = string("Array_") + typeid(T).name();
|
||||||
bp::class_<Array<T>,boost::noncopyable>(name.c_str())
|
bp::class_<Array<T,BASE,TIND>,boost::noncopyable>(name.c_str())
|
||||||
.def ("__len__", &Array<T>::Size)
|
.def ("__len__", &Array<T,BASE,TIND>::Size)
|
||||||
.def ("__getitem__",
|
.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");
|
bp::exec("raise IndexError()\n");
|
||||||
return self[i];
|
return self[i];
|
||||||
}),
|
}),
|
||||||
bp::return_value_policy<bp::reference_existing_object>())
|
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::scope local_scope(module);
|
||||||
|
|
||||||
bp::class_<PointIndex>("PointId")
|
bp::class_<PointIndex>("PointId", bp::init<int>())
|
||||||
.def("__repr__", &ToString<PointIndex>)
|
.def("__repr__", &ToString<PointIndex>)
|
||||||
.def("__str__", &ToString<PointIndex>)
|
.def("__str__", &ToString<PointIndex>)
|
||||||
.add_property("nr", &PointIndex::operator int)
|
.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")
|
bp::class_<Element>("Element3D")
|
||||||
.add_property("vertices",
|
.add_property("vertices",
|
||||||
FunctionPointer ([](const Element & self) -> bp::list
|
FunctionPointer ([](const Element & self) -> bp::list
|
||||||
@ -89,6 +111,8 @@ void ExportNetgenMeshing()
|
|||||||
;
|
;
|
||||||
|
|
||||||
ExportArray<Element>();
|
ExportArray<Element>();
|
||||||
|
ExportArray<Element2d>();
|
||||||
|
ExportArray<MeshPoint,PointIndex::BASE,PointIndex>();
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
@ -101,15 +125,34 @@ void ExportNetgenMeshing()
|
|||||||
static_cast<Array<Element>&(Mesh::*)()> (& &Mesh::VolumeElements),
|
static_cast<Array<Element>&(Mesh::*)()> (& &Mesh::VolumeElements),
|
||||||
bp::return_value_policy<bp::reference_existing_object>())
|
bp::return_value_policy<bp::reference_existing_object>())
|
||||||
|
|
||||||
/*
|
.def("Elements2D",
|
||||||
.def("Elements2D", &Mesh::SurfaceElements,
|
static_cast<Array<Element2d>&(Mesh::*)()> (& &Mesh::SurfaceElements),
|
||||||
bp::return_value_policy<bp::reference_existing_object>())
|
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; }))
|
||||||
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,18 +5,46 @@ from libmesh.meshing import *
|
|||||||
from libcsg.csg import *
|
from libcsg.csg import *
|
||||||
|
|
||||||
|
|
||||||
geo = CSGeometry("shaft.geo")
|
geo = CSGeometry("cube.geo")
|
||||||
geo.ntlo
|
geo.ntlo
|
||||||
|
|
||||||
|
|
||||||
param = MeshingParameters()
|
param = MeshingParameters()
|
||||||
|
# param.maxh = 100
|
||||||
|
print (param)
|
||||||
|
|
||||||
m1 = GenerateMesh (geo, 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 = Mesh()
|
||||||
# mesh.Load ("shaft.vol.gz")
|
# mesh.Load ("shaft.vol.gz")
|
||||||
|
Loading…
Reference in New Issue
Block a user