python export

This commit is contained in:
Joachim Schoeberl 2014-08-31 12:12:31 +00:00
parent a5650c992d
commit 7804ece54b
10 changed files with 118 additions and 121 deletions

View File

@ -2922,15 +2922,15 @@ namespace netgen
} }
void Mesh :: LoadLocalMeshSize (const char * meshsizefilename) void Mesh :: LoadLocalMeshSize (const string & meshsizefilename)
{ {
// Philippose - 10/03/2009 // Philippose - 10/03/2009
// Improve error checking when loading and reading // Improve error checking when loading and reading
// the local mesh size file // the local mesh size file
if (!meshsizefilename) return; if (meshsizefilename.empty()) return;
ifstream msf(meshsizefilename); ifstream msf(meshsizefilename.c_str());
// Philippose - 09/03/2009 // Philippose - 09/03/2009
// Adding print message information in case the specified // Adding print message information in case the specified

View File

@ -389,7 +389,7 @@ namespace netgen
/// ///
DLL_HEADER void RestrictLocalH (resthtype rht, int nr, double loch); DLL_HEADER void RestrictLocalH (resthtype rht, int nr, double loch);
/// ///
DLL_HEADER void LoadLocalMeshSize (const char * meshsizefilename); DLL_HEADER void LoadLocalMeshSize (const string & meshsizefilename);
/// ///
DLL_HEADER void SetGlobalH (double h); DLL_HEADER void SetGlobalH (double h);
/// ///

View File

@ -11,7 +11,7 @@ namespace netgen
mesh.CalcSurfacesOfNode(); mesh.CalcSurfacesOfNode();
const char * optstr = mp.optimize2d; const char * optstr = mp.optimize2d.c_str();
int optsteps = mp.optsteps2d; int optsteps = mp.optsteps2d;
for (int i = 1; i <= optsteps; i++) for (int i = 1; i <= optsteps; i++)

View File

@ -2513,41 +2513,41 @@ namespace netgen
MeshingParameters :: MeshingParameters () MeshingParameters :: MeshingParameters ()
{ {
optimize3d = "cmdmustm"; // optimize3d = "cmdmustm";
//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;
safety = 5; // safety = 5;
relinnersafety = 3; // relinnersafety = 3;
uselocalh = 1; // uselocalh = 1;
grading = 0.3; // grading = 0.3;
delaunay = 1; // delaunay = 1;
maxh = 1e10; // maxh = 1e10;
minh = 0; // minh = 0;
meshsizefilename = NULL; // meshsizefilename = NULL;
startinsurface = 0; // startinsurface = 0;
checkoverlap = 1; // checkoverlap = 1;
checkoverlappingboundary = 1; // checkoverlappingboundary = 1;
checkchartboundary = 1; // checkchartboundary = 1;
curvaturesafety = 2; // curvaturesafety = 2;
segmentsperedge = 1; // segmentsperedge = 1;
parthread = 0; // parthread = 0;
elsizeweight = 0.2; // elsizeweight = 0.2;
giveuptol2d = 200; // giveuptol2d = 200;
giveuptol = 10; // giveuptol = 10;
maxoutersteps = 10; // maxoutersteps = 10;
starshapeclass = 5; // starshapeclass = 5;
baseelnp = 0; // baseelnp = 0;
sloppy = 1; // sloppy = 1;
badellimit = 175; // badellimit = 175;
check_impossible = 0; // check_impossible = 0;
secondorder = 0; // secondorder = 0;
} }
void MeshingParameters :: Print (ostream & ost) const void MeshingParameters :: Print (ostream & ost) const
@ -2565,12 +2565,9 @@ namespace netgen
<< " uselocalh = " << uselocalh << endl << " uselocalh = " << uselocalh << endl
<< " grading = " << grading << endl << " grading = " << grading << endl
<< " delaunay = " << delaunay << endl << " delaunay = " << delaunay << endl
<< " maxh = " << maxh << endl; << " maxh = " << maxh << endl
if(meshsizefilename) << " meshsizefilename = " << meshsizefilename << endl
ost << " meshsizefilename = " << meshsizefilename << endl; << " startinsurface = " << startinsurface << endl
else
ost << " meshsizefilename = NULL" << endl;
ost << " startinsurface = " << startinsurface << endl
<< " checkoverlap = " << checkoverlap << endl << " checkoverlap = " << checkoverlap << endl
<< " checkchartboundary = " << checkchartboundary << endl << " checkchartboundary = " << checkchartboundary << endl
<< " curvaturesafety = " << curvaturesafety << endl << " curvaturesafety = " << curvaturesafety << endl
@ -2591,6 +2588,7 @@ namespace netgen
<< " inverttrigs = " << inverttrigs << endl; << " inverttrigs = " << inverttrigs << endl;
} }
/*
void MeshingParameters :: CopyFrom(const MeshingParameters & other) void MeshingParameters :: CopyFrom(const MeshingParameters & other)
{ {
//strcpy(optimize3d,other.optimize3d); //strcpy(optimize3d,other.optimize3d);
@ -2610,6 +2608,7 @@ namespace netgen
maxh = other.maxh; maxh = other.maxh;
//strcpy(const_cast<char*>(meshsizefilename), other.meshsizefilename); //strcpy(const_cast<char*>(meshsizefilename), other.meshsizefilename);
//const_cast<char*>(meshsizefilename) = other.meshsizefilename; //??? //const_cast<char*>(meshsizefilename) = other.meshsizefilename; //???
meshsizefilename = other.meshsizefilename;
startinsurface = other.startinsurface; startinsurface = other.startinsurface;
checkoverlap = other.checkoverlap; checkoverlap = other.checkoverlap;
checkoverlappingboundary = other.checkoverlappingboundary; checkoverlappingboundary = other.checkoverlappingboundary;
@ -2631,7 +2630,7 @@ namespace netgen
inverttets = other.inverttets; inverttets = other.inverttets;
inverttrigs = other.inverttrigs; inverttrigs = other.inverttrigs;
} }
*/
DebugParameters :: DebugParameters () DebugParameters :: DebugParameters ()
{ {

View File

@ -999,6 +999,13 @@ namespace netgen
class DLL_HEADER MeshingParameters class DLL_HEADER MeshingParameters
{ {
public: public:
/** /**
3d optimization strategy: 3d optimization strategy:
// m .. move nodes // m .. move nodes
@ -1011,7 +1018,7 @@ namespace netgen
// h .. Histogramm, no pause // h .. Histogramm, no pause
// H .. Histogramm, pause // H .. Histogramm, pause
*/ */
string optimize3d; string optimize3d = "cmdmustm";
/// number of 3d optimization steps /// number of 3d optimization steps
int optsteps3d = 3; int optsteps3d = 3;
/** /**
@ -1023,71 +1030,71 @@ namespace netgen
// P .. plot, pause // P .. plot, pause
// c .. combine // c .. combine
**/ **/
const char * optimize2d; string optimize2d = "smsmsmSmSmSm";
/// number of 2d optimization steps /// number of 2d optimization steps
int optsteps2d; int optsteps2d = 3;
/// power of error (to approximate max err optimization) /// power of error (to approximate max err optimization)
double opterrpow; double opterrpow = 2;
/// do block filling ? /// do block filling ?
int blockfill; int blockfill = 1;
/// block filling up to distance /// block filling up to distance
double filldist; double filldist = 0.1;
/// radius of local environment (times h) /// radius of local environment (times h)
double safety; double safety = 5;
/// radius of active environment (times h) /// radius of active environment (times h)
double relinnersafety; double relinnersafety = 3;
/// use local h ? /// use local h ?
int uselocalh; int uselocalh = 1;
/// grading for local h /// grading for local h
double grading; double grading = 0.3;
/// use delaunay meshing /// use delaunay meshing
int delaunay; int delaunay = 1;
/// maximal mesh size /// maximal mesh size
double maxh; double maxh = 1e10;
/// minimal mesh size /// minimal mesh size
double minh; double minh = 0.0;
/// file for meshsize /// file for meshsize
const char * meshsizefilename; string meshsizefilename = "";
/// start surfacemeshing from everywhere in surface /// start surfacemeshing from everywhere in surface
int startinsurface; int startinsurface = 0;
/// check overlapping surfaces (debug) /// check overlapping surfaces (debug)
int checkoverlap; int checkoverlap = 1;
/// check overlapping surface mesh before volume meshing /// check overlapping surface mesh before volume meshing
int checkoverlappingboundary; int checkoverlappingboundary = 1;
/// check chart boundary (sometimes too restrictive) /// check chart boundary (sometimes too restrictive)
int checkchartboundary; int checkchartboundary = 1;
/// safty factor for curvatures (elemetns per radius) /// safty factor for curvatures (elemetns per radius)
double curvaturesafety; double curvaturesafety = 2;
/// minimal number of segments per edge /// minimal number of segments per edge
double segmentsperedge; double segmentsperedge = 1;
/// use parallel threads /// use parallel threads
int parthread; int parthread = 0;
/// weight of element size w.r.t element shape /// weight of element size w.r.t element shape
double elsizeweight; double elsizeweight = 0.2;
/// init with default values /// init with default values
/// from mp3: /// from mp3:
/// give up quality class, 2d meshing /// give up quality class, 2d meshing
int giveuptol2d; int giveuptol2d = 200;
/// give up quality class, 3d meshing /// give up quality class, 3d meshing
int giveuptol; int giveuptol = 10;
/// maximal outer steps /// maximal outer steps
int maxoutersteps; int maxoutersteps = 10;
/// class starting star-shape filling /// class starting star-shape filling
int starshapeclass; int starshapeclass = 5;
/// if non-zero, baseelement must have baseelnp points /// if non-zero, baseelement must have baseelnp points
int baseelnp; int baseelnp = 0;
/// quality tolerances are handled less careful /// quality tolerances are handled less careful
int sloppy; int sloppy = 1;
/// limit for max element angle (150-180) /// limit for max element angle (150-180)
double badellimit; double badellimit = 175;
bool check_impossible; bool check_impossible = 0;
/// ///
int secondorder; int secondorder = 0;
/// high order element curvature /// high order element curvature
int elementorder; int elementorder;
/// quad-dominated surface meshing /// quad-dominated surface meshing
@ -1101,9 +1108,12 @@ namespace netgen
/// ///
MeshingParameters (); MeshingParameters ();
/// ///
MeshingParameters (const MeshingParameters & mp2) = default;
///
void Print (ostream & ost) const; void Print (ostream & ost) const;
///
void CopyFrom(const MeshingParameters & other); // void CopyFrom(const MeshingParameters & other);
void (*render_function)() = NULL; void (*render_function)() = NULL;
void Render() void Render()

View File

@ -100,6 +100,7 @@ void ExportNetgenMeshing()
; ;
bp::class_<Element>("Element3D") bp::class_<Element>("Element3D")
.add_property("index", &Element::GetIndex, &Element::SetIndex)
.add_property("vertices", .add_property("vertices",
FunctionPointer ([](const Element & self) -> bp::list FunctionPointer ([](const Element & self) -> bp::list
{ {

View File

@ -756,7 +756,7 @@ void STLSurfaceOptimization (STLGeometry & geom,
PrintMessage(5,"optimize string = ", meshparam.optimize2d, " elsizew = ", meshparam.elsizeweight); PrintMessage(5,"optimize string = ", meshparam.optimize2d, " elsizew = ", meshparam.elsizeweight);
for (int i = 1; i <= meshparam.optsteps2d; i++) for (int i = 1; i <= meshparam.optsteps2d; i++)
for (size_t j = 1; j <= strlen(meshparam.optimize2d); j++) for (size_t j = 1; j <= meshparam.optimize2d.length(); j++)
{ {
if (multithread.terminate) if (multithread.terminate)
break; break;

View File

@ -1130,8 +1130,7 @@ namespace netgen
mparam.minh = atof (Tcl_GetVar (interp, "::options.minmeshsize", 0)); mparam.minh = atof (Tcl_GetVar (interp, "::options.minmeshsize", 0));
mparam.meshsizefilename = Tcl_GetVar (interp, "::options.meshsizefilename", 0); mparam.meshsizefilename = Tcl_GetVar (interp, "::options.meshsizefilename", 0);
if (!strlen (mparam.meshsizefilename)) // if (!strlen (mparam.meshsizefilename)) mparam.meshsizefilename = NULL;
mparam.meshsizefilename = NULL;
mparam.curvaturesafety = atof (Tcl_GetVar (interp, "::options.curvaturesafety", 0)); mparam.curvaturesafety = atof (Tcl_GetVar (interp, "::options.curvaturesafety", 0));
mparam.segmentsperedge = atof (Tcl_GetVar (interp, "::options.segmentsperedge", 0)); mparam.segmentsperedge = atof (Tcl_GetVar (interp, "::options.segmentsperedge", 0));

26
python/exportNeutral.py Normal file
View File

@ -0,0 +1,26 @@
import sys
def Export (mesh, filename):
""" export Netgen mesh to neutral format """
print ("export mesh in neutral format to file = ", filename)
f = open (filename, 'w')
points = mesh.Points()
print (len(points), file=f)
for p in points:
print (p.p[0], p.p[1], p.p[2], file=f)
volels = mesh.Elements3D();
print (len(volels), file=f)
for el in volels:
print (el.index, end=" ", file=f)
for j in el.vertices:
print (j.nr, end=" ", file=f)
print(file=f)

View File

@ -5,55 +5,17 @@ from libmesh.meshing import *
from libcsg.csg import * from libcsg.csg import *
geo = CSGeometry("cube.geo") geo = CSGeometry("shaft.geo")
geo.ntlo
param = MeshingParameters() param = MeshingParameters()
# param.maxh = 100 param.maxh = 10
print (param) print (param)
m1 = GenerateMesh (geo, param) m1 = GenerateMesh (geo, param)
for el in m1.Elements3D(): import exportNeutral
vi = el.vertices exportNeutral.Export (m1, "shaft.mesh")
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")
# els = mesh.Elements3D()
#cnt = 0
# for el in mesh.Elements3D():
# print ("el ", cnt, " has vertices " , el.vertices)
# cnt = cnt+1