diff --git a/demos/api/basic.cpp b/demos/api/open.cpp similarity index 100% rename from demos/api/basic.cpp rename to demos/api/open.cpp diff --git a/demos/api/basic.py b/demos/api/open.py similarity index 100% rename from demos/api/basic.py rename to demos/api/open.py diff --git a/demos/api/basic2.cpp b/demos/api/open2.cpp similarity index 100% rename from demos/api/basic2.cpp rename to demos/api/open2.cpp diff --git a/demos/api/basic2.py b/demos/api/open2.py similarity index 100% rename from demos/api/basic2.py rename to demos/api/open2.py diff --git a/demos/api/t1.cpp b/demos/api/t1.cpp index 00a6d3d6189e1dc24b0b1b3f8645ed2b1030cadb..0447938fe40554e7b94206bf19d1381252a3054d 100644 --- a/demos/api/t1.cpp +++ b/demos/api/t1.cpp @@ -8,10 +8,9 @@ int main(int argc, char **argv) { - // Before using any functions in the C++ API, Gmsh must be initialized. If - // argc/argv are passed, Gmsh will parse the commandline in the same way as - // the standalone Gmsh code. - gmshInitialize(argc, argv); + // Before using any functions in the C++ API, Gmsh must be initialized. All + // the function in the API return 0 on successful completion. + gmshInitialize(); // By default Gmsh will not print out any messages: in order to output // messages on the terminal, just set the standard Gmsh option diff --git a/demos/api/t1.py b/demos/api/t1.py index 16b69c570190f5f0c1182422ac596c08a96805ed..b7caa2b00ad7da8041727717ac6f8d3da3fadba4 100644 --- a/demos/api/t1.py +++ b/demos/api/t1.py @@ -5,12 +5,11 @@ # comments in the .geo file. Comments here will focus on the specifics of the # Python API. -# The Gmsh API is entirely defined in the gmsh module +# The API is entirely defined in the gmsh module from gmsh import * -# Before using any functions in the Python API, Gmsh must be initialized. If -# argc/argv are passed, Gmsh will parse the commandline in the same way as the -# standalone Gmsh code. +# Before using any functions in the Python API, Gmsh must be initialized. All +# the function in the API return 0 on successful completion. gmshInitialize() # By default Gmsh will not print out any messages: in order to output messages diff --git a/demos/api/t2.cpp b/demos/api/t2.cpp index 7d78d5c5f259cc1471f99958e0a029316c32ed44..be48cd38cc82bbcaddf9d388ae4ce3561c6c520e 100644 --- a/demos/api/t2.cpp +++ b/demos/api/t2.cpp @@ -5,6 +5,8 @@ int main(int argc, char **argv) { + // If argc/argv are passed, Gmsh will parse the commandline in the same way as + // the standalone Gmsh code. gmshInitialize(argc, argv); gmshOptionSetNumber("General.Terminal", 1); diff --git a/demos/api/t4.py b/demos/api/t4.py index 5f04725cc9c9794e7ddb459b286345b7913a2bc1..c3ee26869efb2059091575367121920c6a91147c 100644 --- a/demos/api/t4.py +++ b/demos/api/t4.py @@ -3,9 +3,6 @@ from gmsh import * import math -def hypot(a, b): - return math.sqrt(a * a + b * b) - gmshInitialize() gmshOptionSetNumber("General.Terminal", 1) @@ -18,6 +15,9 @@ R1 = 1 * cm; R2 = 1.5 * cm; r = 1 * cm Lc1 = 0.01 Lc2 = 0.003 +def hypot(a, b): + return math.sqrt(a * a + b * b) + ccos = (-h5*R1 + e2 * hypot(h5, hypot(e2, R1))) / (h5*h5 + e2*e2) ssin = math.sqrt(1 - ccos*ccos) diff --git a/demos/api/t5.cpp b/demos/api/t5.cpp index e031dc4e563865d961bd778baa77f2423146093c..f0c57325b4a5d62e2db5ea596dabeabbeef71dfe 100644 --- a/demos/api/t5.cpp +++ b/demos/api/t5.cpp @@ -6,7 +6,8 @@ void cheeseHole(double x, double y, double z, double r, double lc, std::vector<int> &shells, std::vector<int> &volumes) { - // When the tag (first argument) is negative, the + // When the tag (first argument) is negative, the next available tag for the + // corresponding entity is returned as the 5th argument (e.g. p1) int p1; gmshModelGeoAddPoint(-1, x, y, z, p1, lc); int p2; gmshModelGeoAddPoint(-1, x+r,y, z, p2, lc); int p3; gmshModelGeoAddPoint(-1, x, y+r,z, p3, lc); diff --git a/demos/api/t5.py b/demos/api/t5.py new file mode 100644 index 0000000000000000000000000000000000000000..8a97f9765b967c4ea5b8c797ba37e014e4c5ecf2 --- /dev/null +++ b/demos/api/t5.py @@ -0,0 +1,130 @@ +# This file reimplements gmsh/tutorial/t5.geo in Python. + +from gmsh import * +import math + +def hypot(a, b): + return math.sqrt(a * a + b * b) + +gmshInitialize() +gmshOptionSetNumber("General.Terminal", 1) + +gmshModelCreate("t5") + +lcar1 = .1 +lcar2 = .0005 +lcar3 = .055 + +gmshModelGeoAddPoint(1, 0.5,0.5,0.5, lcar2) +gmshModelGeoAddPoint(2, 0.5,0.5,0, lcar1) +gmshModelGeoAddPoint(3, 0,0.5,0.5, lcar1) +gmshModelGeoAddPoint(4, 0,0,0.5, lcar1) +gmshModelGeoAddPoint(5, 0.5,0,0.5, lcar1) +gmshModelGeoAddPoint(6, 0.5,0,0, lcar1) +gmshModelGeoAddPoint(7, 0,0.5,0, lcar1) +gmshModelGeoAddPoint(8, 0,1,0, lcar1) +gmshModelGeoAddPoint(9, 1,1,0, lcar1) +gmshModelGeoAddPoint(10, 0,0,1, lcar1) +gmshModelGeoAddPoint(11, 0,1,1, lcar1) +gmshModelGeoAddPoint(12, 1,1,1, lcar1) +gmshModelGeoAddPoint(13, 1,0,1, lcar1) +gmshModelGeoAddPoint(14, 1,0,0, lcar1) + +gmshModelGeoAddLine(1, 8,9); gmshModelGeoAddLine(2, 9,12) +gmshModelGeoAddLine(3, 12,11); gmshModelGeoAddLine(4, 11,8) +gmshModelGeoAddLine(5, 9,14); gmshModelGeoAddLine(6, 14,13) +gmshModelGeoAddLine(7, 13,12); gmshModelGeoAddLine(8, 11,10) +gmshModelGeoAddLine(9, 10,13); gmshModelGeoAddLine(10, 10,4) +gmshModelGeoAddLine(11, 4,5); gmshModelGeoAddLine(12, 5,6) +gmshModelGeoAddLine(13, 6,2); gmshModelGeoAddLine(14, 2,1) +gmshModelGeoAddLine(15, 1,3); gmshModelGeoAddLine(16, 3,7) +gmshModelGeoAddLine(17, 7,2); gmshModelGeoAddLine(18, 3,4) +gmshModelGeoAddLine(19, 5,1); gmshModelGeoAddLine(20, 7,8) +gmshModelGeoAddLine(21, 6,14); + +gmshModelGeoAddLineLoop(22, [-11,-19,-15,-18]) +gmshModelGeoAddPlaneSurface(23, [22]) +gmshModelGeoAddLineLoop(24, [16,17,14,15]) +gmshModelGeoAddPlaneSurface(25, [24]) +gmshModelGeoAddLineLoop(26, [-17,20,1,5,-21,13]) +gmshModelGeoAddPlaneSurface(27, [26]) +gmshModelGeoAddLineLoop(28, [-4,-1,-2,-3]) +gmshModelGeoAddPlaneSurface(29, [28]) +gmshModelGeoAddLineLoop(30, [-7,2,-5,-6]) +gmshModelGeoAddPlaneSurface(31, [30]) +gmshModelGeoAddLineLoop(32, [6,-9,10,11,12,21]) +gmshModelGeoAddPlaneSurface(33, [32]) +gmshModelGeoAddLineLoop(34, [7,3,8,9]) +gmshModelGeoAddPlaneSurface(35, [34]) +gmshModelGeoAddLineLoop(36, [-10,18,-16,-20,4,-8]) +gmshModelGeoAddPlaneSurface(37, [36]) +gmshModelGeoAddLineLoop(38, [-14,-13,-12,19]) +gmshModelGeoAddPlaneSurface(39, [38]) + +shells = IntVector(); volumes = IntVector() + +sl = gmshModelGeoAddSurfaceLoop(-1, [35,31,29,37,33,23,39,25,27]) +shells.push_back(sl[1]) + +def cheeseHole(x, y, z, r, lc, shells, volumes): + # When the tag (first argument) is negative, the next available tag for the + # corresponding entity is appended to the value returned by the function + p1 = gmshModelGeoAddPoint(-1, x, y, z, lc)[1] + p2 = gmshModelGeoAddPoint(-1, x+r,y, z, lc)[1] + p3 = gmshModelGeoAddPoint(-1, x, y+r,z, lc)[1] + p4 = gmshModelGeoAddPoint(-1, x, y, z+r, lc)[1] + p5 = gmshModelGeoAddPoint(-1, x-r,y, z, lc)[1] + p6 = gmshModelGeoAddPoint(-1, x, y-r,z, lc)[1] + p7 = gmshModelGeoAddPoint(-1, x, y, z-r, lc)[1] + + c1 = gmshModelGeoAddCircleArc(-1, p2,p1,p7)[1] + c2 = gmshModelGeoAddCircleArc(-1, p7,p1,p5)[1] + c3 = gmshModelGeoAddCircleArc(-1, p5,p1,p4)[1] + c4 = gmshModelGeoAddCircleArc(-1, p4,p1,p2)[1] + c5 = gmshModelGeoAddCircleArc(-1, p2,p1,p3)[1] + c6 = gmshModelGeoAddCircleArc(-1, p3,p1,p5)[1] + c7 = gmshModelGeoAddCircleArc(-1, p5,p1,p6)[1] + c8 = gmshModelGeoAddCircleArc(-1, p6,p1,p2)[1] + c9 = gmshModelGeoAddCircleArc(-1, p7,p1,p3)[1] + c10 = gmshModelGeoAddCircleArc(-1, p3,p1,p4)[1] + c11 = gmshModelGeoAddCircleArc(-1, p4,p1,p6)[1] + c12 = gmshModelGeoAddCircleArc(-1, p6,p1,p7)[1] + + l1 = gmshModelGeoAddLineLoop(-1, [c5,c10,c4])[1] + l2 = gmshModelGeoAddLineLoop(-1, [c9,-c5,c1])[1] + l3 = gmshModelGeoAddLineLoop(-1, [c12,-c8,-c1])[1] + l4 = gmshModelGeoAddLineLoop(-1, [c8,-c4,c11])[1] + l5 = gmshModelGeoAddLineLoop(-1, [-c10,c6,c3])[1] + l6 = gmshModelGeoAddLineLoop(-1, [-c11,-c3,c7])[1] + l7 = gmshModelGeoAddLineLoop(-1, [-c2,-c7,-c12])[1] + l8 = gmshModelGeoAddLineLoop(-1, [-c6,-c9,c2])[1] + + s1 = gmshModelGeoAddSurfaceFilling(-1, [l1])[1] + s2 = gmshModelGeoAddSurfaceFilling(-1, [l2])[1] + s3 = gmshModelGeoAddSurfaceFilling(-1, [l3])[1] + s4 = gmshModelGeoAddSurfaceFilling(-1, [l4])[1] + s5 = gmshModelGeoAddSurfaceFilling(-1, [l5])[1] + s6 = gmshModelGeoAddSurfaceFilling(-1, [l6])[1] + s7 = gmshModelGeoAddSurfaceFilling(-1, [l7])[1] + s8 = gmshModelGeoAddSurfaceFilling(-1, [l8])[1] + + sl = gmshModelGeoAddSurfaceLoop(-1, [s1, s2, s3, s4, s5, s6, s7, s8])[1] + v = gmshModelGeoAddVolume(-1, [sl])[1] + shells.append(sl) + volumes.append(v) + +x = 0; y = 0.75; z = 0; r = 0.09 +for t in range(1,5): + x += 0.166 ; + z += 0.166 ; + cheeseHole(x, y, z, r, lcar3, shells, volumes); + gmshModelAddPhysicalGroup(3, t, [volumes.back()]); + +gmshModelGeoAddVolume(186, shells); + +gmshModelAddPhysicalGroup(3, 10, [186]); +gmshModelGeoSynchronize() +gmshModelMesh(3) +gmshExport("t5.msh") + +gmshFinalize()