From 01197e7739aade8b9694e133d2a609eea313c5e2 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Wed, 1 Oct 2014 13:52:58 +0000 Subject: [PATCH] py - tutorials --- py_tutorials/csg_first_example.py | 24 ++++++++++++ py_tutorials/cube.geo | 16 ++++++++ py_tutorials/exportNeutral.py | 26 +++++++++++++ py_tutorials/mesh.py | 17 ++++++++ py_tutorials/shaft.geo | 65 +++++++++++++++++++++++++++++++ 5 files changed, 148 insertions(+) create mode 100644 py_tutorials/csg_first_example.py create mode 100644 py_tutorials/cube.geo create mode 100644 py_tutorials/exportNeutral.py create mode 100644 py_tutorials/mesh.py create mode 100644 py_tutorials/shaft.geo diff --git a/py_tutorials/csg_first_example.py b/py_tutorials/csg_first_example.py new file mode 100644 index 00000000..fd74a70d --- /dev/null +++ b/py_tutorials/csg_first_example.py @@ -0,0 +1,24 @@ +import sys +sys.path.append("/opt/netgen/lib") + +from libcsg.csg import * +from libmesh.meshing import * + + +sp1 = Sphere (Point3d(1,0,0), 1) +sp2 = Sphere (Point3d(2,0,0), 1) + +both = Or(sp1, sp2) +all = And (both, OrthoBrick ( Point3d(0,0,0), Point3d (3,0.5,1))) + + +geom = CSGeometry() +geom.Add (all) + + + +param = MeshingParameters() +param.maxh = 0.2 +mesh = GenerateMesh (geom, param) + +mesh.Save ("test.vol") diff --git a/py_tutorials/cube.geo b/py_tutorials/cube.geo new file mode 100644 index 00000000..bcacf4d3 --- /dev/null +++ b/py_tutorials/cube.geo @@ -0,0 +1,16 @@ +# +## A cube +# +algebraic3d + +# cube consisting of 6 planes: + +solid cube = plane (0, 0, 0; 0, 0, -1) + and plane (0, 0, 0; 0, -1, 0) + and plane (0, 0, 0; -1, 0, 0) + and plane (1, 1, 1; 0, 0, 1) + and plane (1, 1, 1; 0, 1, 0) + and plane (1, 1, 1; 1, 0, 0); + +tlo cube; + diff --git a/py_tutorials/exportNeutral.py b/py_tutorials/exportNeutral.py new file mode 100644 index 00000000..ad58ea41 --- /dev/null +++ b/py_tutorials/exportNeutral.py @@ -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) + + + + diff --git a/py_tutorials/mesh.py b/py_tutorials/mesh.py new file mode 100644 index 00000000..54ff2e97 --- /dev/null +++ b/py_tutorials/mesh.py @@ -0,0 +1,17 @@ +from netgen.meshing import * +from netgen.csg import * + +geo = CSGeometry("shaft.geo") + +param = MeshingParameters() +param.maxh = 10 +print (param) + +m1 = GenerateMesh (geo, param) + + +import exportNeutral +exportNeutral.Export (m1, "shaft.mesh") + + + diff --git a/py_tutorials/shaft.geo b/py_tutorials/shaft.geo new file mode 100644 index 00000000..8bb4ce32 --- /dev/null +++ b/py_tutorials/shaft.geo @@ -0,0 +1,65 @@ +# +## Crankshaft +# +algebraic3d +solid p1 = plane (0, 0, 0; -1, 0, 0) + and plane (10, 0, 0; 1, 0, 0) + and + ( plane (35, 0, 28; 0, -1, 3) + and plane (35, 0, -28; 0, -1, -3) + and plane (35, 0, 0; 0, 1, 0) + and plane (35, -30, 0; 0, -1, 0) + or cylinder (-10, 0, 0; 20, 0, 0; 30) + or cylinder (-10, -30, 0; 20, -30, 0; 20) + ); +solid p2 = plane (35, 0, 0; -1, 0, 0) + and plane (45, 0, 0; 1, 0, 0) + and + ( plane (35, 0, 28; 0, -1, 3) + and plane (35, 0, -28; 0, -1, -3) + and plane (35, 0, 0; 0, 1, 0) + and plane (35, -30, 0; 0, -1, 0) + or cylinder (30, 0, 0; 50, 0, 0; 30) + or cylinder (30, -30, 0; 50, -30, 0; 20) + ); +solid p3 = plane (80, 0, 0; -1, 0, 0) + and plane (90, 0, 0; 1, 0, 0) + and + ( plane (0, 0, 28; 0, 1, 3) + and plane (0, 0, -28; 0, 1, -3) + and plane (0, 0, 0; 0, -1, 0) + and plane (0, 30, 0; 0, 1, 0) + or cylinder (70, 0, 0; 100, 0, 0; 30) + or cylinder (70, 30, 0; 100, 30, 0; 20) + ); +solid p4 = plane (115, 0, 0; -1, 0, 0) + and plane (125, 0, 0; 1, 0, 0) + and + ( plane (35, 0, 28; 0, 1, 3) + and plane (35, 0, -28; 0, 1, -3) + and plane (35, 0, 0; 0, -1, 0) + and plane (35, 30, 0; 0, 1, 0) + or cylinder (110, 0, 0; 130, 0, 0; 30) + or cylinder (110, 30, 0;130, 30, 0; 20) + ); +solid sh1 = cylinder (-50, 0, 0; 10, 0, 0; 15) + and plane (-40, 0, 0; -1, 0, 0) + and plane (5, 0, 0; 1, 0, 0); +solid sh2 = cylinder (30, 0, 0; 90, 0, 0; 15) + and plane (40, 0, 0; -1, 0, 0) + and plane (85, 0, 0; 1, 0, 0); +solid sh3 = cylinder (110, 0, 0; 170, 0, 0; 15) + and plane (120, 0, 0; -1, 0, 0) + and plane (165, 0, 0; 1, 0, 0); + +solid pl1 = cylinder (0, -30, 0; 50, -30, 0; 10) + and plane (5, 0, 0; -1, 0, 0) + and plane (40, 0, 0; 1, 0, 0); +solid pl2 = cylinder (80, 30, 0; 130, 30, 0; 10) + and plane (85, 0, 0; -1, 0, 0) + and plane (120, 0, 0; 1, 0, 0); +# +# +solid main = p1 or p2 or p3 or p4 or sh1 or sh2 or sh3 or pl1 or pl2; + +tlo main;