From 53b1d3dea81aa25448c506bbb39b520c89c7d680 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Wed, 15 Nov 2017 21:36:59 +0100
Subject: [PATCH] new python demos

---
 demos/api/basic2.py | 33 +++++++++++++++++++++++++++++++++
 demos/api/t2.py     |  2 +-
 2 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 demos/api/basic2.py

diff --git a/demos/api/basic2.py b/demos/api/basic2.py
new file mode 100644
index 0000000000..5bec30b80c
--- /dev/null
+++ b/demos/api/basic2.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+
+from gmsh import *
+import sys
+
+if len(sys.argv) < 2:
+    print "Usage: basic.py file.geo [options]"
+    exit(0)
+
+gmshInitialize()
+gmshOptionSetNumber("General.Terminal", 1)
+gmshOpen(sys.argv[1])
+gmshModelMesh(3)
+
+# get all elementary entities in the model
+entities = PairVector()
+gmshModelGetEntities(entities)
+
+for e in entities:
+    # get the mesh vertices for each elementary entity
+    vertexTags = IntVector()
+    vertexCoords = DoubleVector()
+    gmshModelGetMeshVertices(e[0], e[1], vertexTags, vertexCoords)
+    # get the mesh elements for each elementary entity
+    elemTypes = IntVector()
+    elemTags = IntVectorVector(); elemVertexTags = IntVectorVector()
+    gmshModelGetMeshElements(e[0], e[1], elemTypes, elemTags, elemVertexTags)
+    # report some statistics
+    numElem = sum(len(i) for i in elemTags)
+    print str(vertexTags.size()) + " mesh vertices " + str(numElem),\
+          "mesh elements on entity " + str(e)
+
+gmshFinalize()
diff --git a/demos/api/t2.py b/demos/api/t2.py
index 8c3c357086..1907f5cd53 100644
--- a/demos/api/t2.py
+++ b/demos/api/t2.py
@@ -59,7 +59,7 @@ gmshModelGeoAddPlaneSurface(11, [10])
 gmshModelGeoCopy([(2, 1), (2, 11)], ov)
 gmshModelGeoTranslate(ov, 0.12, 0, 0)
 
-print "New surfaces '%d' and '%d'\n", ov[0][1], ov[1][1]
+print "New surfaces " + str(ov[0][1]) + " and " + str(ov[1][1])
 
 gmshModelGeoAddPoint(100, 0., 0.3, 0.13, lc)
 gmshModelGeoAddPoint(101, 0.08, 0.3, 0.1, lc)
-- 
GitLab