Commit 8dcd4241 by Christophe Geuzaine

ovectorpair

parent 492b492c
Pipeline #1621 passed with stage
in 17 minutes 4 seconds
......@@ -328,6 +328,13 @@ def ovectorpair(name, value=None, python_value=None, julia_value=None):
a.python_arg = "byref(" + api_name + "), byref(" + api_name_n + ")"
a.python_return = "_ovectorpair(" + api_name + ", " + api_name_n + ".value)"
a.julia_ctype = "Ptr{Ptr{Cint}}, Ptr{Csize_t}"
a.julia_pre = (api_name + "= Vector{Ptr{Cint}}(1)\n " +
api_name_n + "= Vector{Csize_t}(1)")
a.julia_arg = api_name + ", " + api_name_n
a.julia_post = ("tmp_" + api_name + " = unsafe_wrap(Array, " + api_name + "[1], " +
api_name_n + "[1], true)\n " +
name + " = [ (tmp_" + api_name + "[i], tmp_" + api_name + "[i+1]) " +
"for i in 1:2:length(tmp_" + api_name + ") ]")
return a
def ovectorvectorint(name, value=None, python_value=None, julia_value=None):
......
......@@ -8,19 +8,19 @@
# Running `python gen.py' will generate
#
# - gmsh.h: the Gmsh C++ API header
# - gmsh.py: the Gmsh Python API module
# - gmsh.jl: the Gmsh Julia API module
# - gmshc.h: the Gmsh C API header
# - gmsh.h_cwrap: the Gmsh C++ API redefined in terms of the C API
# - gmshc.cpp: the C to C++ wrapper code used by the Gmsh C API
# - gmsh.h_cwrap: the Gmsh C++ API redefined in terms of the C API
# - gmsh.py: the Gmsh Python API module
# - gmsh.jl: the Gmsh Julia API module
# - api.texi: the texinfo API documentation
#
# By design, the Gmsh API is purely functional, and only uses elementary types
# of the target language.
# from the target language.
#
# See `demos/api' for examples on how to use the Gmsh API. In particular, this
# directory contains C++ and Python versions of several of the `.geo' tutorials
# from `tutorials'.
# See `demos/api' for examples on how to use the Gmsh API. In particular,
# `demos/api' contains C++, C, Python and Julia versions of several of the
# `.geo' tutorials from `tutorials'.
from GenApi import *
......
This directory contains examples on how to use the Gmsh API.
The files t1.{cpp,py}, t2.{cpp,py}, ... are reimplementations in C++ and Python
of the corresponding .geo tutorials. The other files show how to use various
other Gmsh API functions.
The files t1.*, t2.*, ... are reimplementations in C++ (.cpp), C (.c), Python
(.py) and Julia (.jl) of the corresponding .geo tutorials. The other files show
how to use various other Gmsh API functions.
To run the examples, you need the Gmsh dynamic library and the associated header
files (for C++ and C) or modules (for Python and Julia). This library and the
associated files can be either obtained from the binary Software Development Kit
(SDK), or can be rebuilt using the Gmsh source code.
(SDK), or can be rebuilt from the Gmsh source code.
Using the Gmsh binary Software Development Kit (SDK)
----------------------------------------------------
......@@ -19,7 +19,7 @@ operating system.
To run the Python examples, add the "lib" directory from the SDK to PYTHONPATH,
e.g., if you are currently in the root directory of the SDK:
export PYTHONPATH=${PYTHONPATH}:lib
export PYTHONPATH=${PYTHONPATH}:${PWD}/lib
then run e.g.
......@@ -28,7 +28,7 @@ then run e.g.
To run the Julia examples, add the "lib" directory from the SDK to
JULIA_LOAD_PATH, e.g.
export JULIA_LOAD_PATH=${JULIA_LOAD_PATH}:lib
export JULIA_LOAD_PATH=${JULIA_LOAD_PATH}:${PWD}/lib
then run e.g.
......@@ -58,7 +58,7 @@ code:
To run the Python examples, add the "api" directory to PYTHONPATH, e.g.
export PYTHONPATH=api
export PYTHONPATH=${PYTHONPATH}:${PWD}/api
then run
......@@ -66,7 +66,7 @@ then run
To run the Julia examples, add the "api" directory to JULIA_LOAD_PATH, e.g.
export JULIA_LOAD_PATH=${JULIA_LOAD_PATH}:lib
export JULIA_LOAD_PATH=${JULIA_LOAD_PATH}:${PWD}/lib
then run e.g.
......
# This file reimplements gmsh/tutorial/t2.geo in Julia. Comments focus on the new
# API functions used, compared to the ones introduced in t1.jl.
import gmsh
# nice shortcuts
model = gmsh.model
factory = model.geo
# If ARGS is passed, Gmsh will parse the commandline in the same way as the
# standalone Gmsh app.
gmsh.initialize(ARGS)
gmsh.option.setNumber("General.Terminal", 1)
model.add("t2")
# Copied from t1.jl...
lc = 1e-2
factory.addPoint(0, 0, 0, lc, 1)
factory.addPoint(.1, 0, 0, lc, 2)
factory.addPoint(.1, .3, 0, lc, 3)
factory.addPoint(0, .3, 0, lc, 4)
factory.addLine(1, 2, 1)
factory.addLine(3, 2, 2)
factory.addLine(3, 4, 3)
factory.addLine(4, 1, 4)
factory.addCurveLoop([4, 1, -2, 3], 1)
factory.addPlaneSurface([1], 1)
model.addPhysicalGroup(0, [1, 2], 1)
model.addPhysicalGroup(1, [1, 2], 2)
model.addPhysicalGroup(2, [1], 6)
model.setPhysicalName(2, 6, "My surface")
# ...end of copy
factory.addPoint(0, .4, 0, lc, 5)
factory.addLine(4, 5, 5)
# Geometrical transformations take a vector of pairs of integers as first
# argument, which contains the list of entities, represented by (dimension, tag)
# pairs. Here we thus translate point 3 (dimension=0, tag=3), by dx=-0.05, dy=0,
# dz=0.
factory.translate([(0, 3)], -0.05, 0, 0)
# The "Duplicata" functionality in .geo files is handled by
# factory.Copy(), which takes a vector of (dim, tag) pairs as input, and
# returns another vector of (dim, tag) pairs.
ov = factory.copy([(0, 3)])
factory.translate(ov, 0, 0.1, 0)
factory.addLine(3, ov[1][2], 7)
factory.addLine(ov[1][2], 5, 8)
factory.addCurveLoop([5,-8,-7,3], 10)
factory.addPlaneSurface([10], 11)
ov = factory.copy([(2, 1), (2, 11)])
factory.translate(ov, 0.12, 0, 0)
println("New surfaces ", ov[1][2], " and ", ov[2][2])
factory.addPoint(0., 0.3, 0.13, lc, 100)
factory.addPoint(0.08, 0.3, 0.1, lc, 101)
factory.addPoint(0.08, 0.4, 0.1, lc, 102)
factory.addPoint(0., 0.4, 0.13, lc, 103)
factory.addLine(4, 100, 110)
factory.addLine(3, 101, 111)
factory.addLine(6, 102, 112)
factory.addLine(5, 103, 113)
factory.addLine(103, 100, 114)
factory.addLine(100, 101, 115)
factory.addLine(101, 102, 116)
factory.addLine(102, 103, 117)
factory.addCurveLoop([115, -111, 3, 110], 118)
factory.addPlaneSurface([118], 119)
factory.addCurveLoop([111, 116, -112, -7], 120)
factory.addPlaneSurface([120], 121)
factory.addCurveLoop([112, 117, -113, -8], 122)
factory.addPlaneSurface([122], 123)
factory.addCurveLoop([114, -110, 5, 113], 124)
factory.addPlaneSurface([124], 125)
factory.addCurveLoop([115, 116, 117, 114], 126)
factory.addPlaneSurface([126], 127)
# The API to create surface loops ("shells") and volumes is similar to the
# one used to create curve loops and surfaces.
factory.addSurfaceLoop([127, 119, 121, 123, 125, 11], 128)
factory.addVolume([128], 129)
# Extrusion works as expected, by providing a vector of (dim, tag) pairs as
# input, the translation vector, and a vector of (dim, tag) pairs as output.
ov2 = factory.extrude([ov[1]], 0, 0, 0.12)
# Mesh sizes associated to geometrical points can be set by passing a vector of
# (dim, tag) pairs for the corresponding points.
factory.mesh.setSize([(0,103), (0,105), (0,109), (0,102), (0,28),
(0, 24), (0,6), (0,5)], lc * 3)
model.addPhysicalGroup(3, [129,130], 1)
model.setPhysicalName(3, 1, "The volume")
factory.synchronize()
model.mesh.generate(3)
gmsh.write("t2.msh")
gmsh.finalize()
# This files reimplements gmsh/tutorial/t3.geo in Julia.
import gmsh
model = gmsh.model
factory = model.geo
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1)
model.add("t3")
# Copied from t1.jl...
lc = 1e-2
factory.addPoint(0, 0, 0, lc, 1)
factory.addPoint(.1, 0, 0, lc, 2)
factory.addPoint(.1, .3, 0, lc, 3)
factory.addPoint(0, .3, 0, lc, 4)
factory.addLine(1, 2, 1)
factory.addLine(3, 2, 2)
factory.addLine(3, 4, 3)
factory.addLine(4, 1, 4)
factory.addCurveLoop([4, 1, -2, 3], 1)
factory.addPlaneSurface([1], 1)
model.addPhysicalGroup(0, [1, 2], 1)
model.addPhysicalGroup(1, [1, 2], 2)
model.addPhysicalGroup(2, [1], 6)
model.setPhysicalName(2, 6, "My surface")
# ...end of copy
h = 0.1
angle = 90.
# Extruding the mesh in addition to the geometry works as in .geo files: the
# number of elements for each layer and the (end) height of each layer are
# specified in two vectors.
ov = factory.extrude([(2,1)], 0, 0, h, [8,2], [0.5,1])
#/ Rotational and twisted extrusions are available as well with the built-in CAD
# kernel. The last (optional) argument for the Extrude/Revolve/Twist commands
# specified whether the extruded mesh should be recombined or not.
ov = factory.revolve([(2,28)], -0.1,0,0.1, 0,1,0, -pi/2, [7])
ov = factory.twist([(2,50)], 0,0.15,0.25, -2*h,0,0, 1,0,0, angle*pi/180.,
[10], [], true)
model.addPhysicalGroup(3, [1, 2, ov[2][2]], 101)
factory.synchronize()
model.mesh.generate(3)
gmsh.write("t3.msh")
gmsh.finalize()
# This file reimplements gmsh/tutorial/t4.geo in Julia.
import gmsh
model = gmsh.model
factory = model.geo
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1)
model.add("t4")
cm = 1e-02
e1 = 4.5 * cm; e2 = 6 * cm / 2; e3 = 5 * cm / 2
h1 = 5 * cm; h2 = 10 * cm; h3 = 5 * cm; h4 = 2 * cm; h5 = 4.5 * cm
R1 = 1 * cm; R2 = 1.5 * cm; r = 1 * cm
Lc1 = 0.01
Lc2 = 0.003
function hypot(a, b)
return sqrt(a * a + b * b)
end
ccos = (-h5*R1 + e2 * hypot(h5, hypot(e2, R1))) / (h5*h5 + e2*e2)
ssin = sqrt(1 - ccos*ccos)
factory.addPoint(-e1-e2, 0 , 0, Lc1, 1)
factory.addPoint(-e1-e2, h1 , 0, Lc1, 2)
factory.addPoint(-e3-r , h1 , 0, Lc2, 3)
factory.addPoint(-e3-r , h1+r , 0, Lc2, 4)
factory.addPoint(-e3 , h1+r , 0, Lc2, 5)
factory.addPoint(-e3 , h1+h2, 0, Lc1, 6)
factory.addPoint( e3 , h1+h2, 0, Lc1, 7)
factory.addPoint( e3 , h1+r , 0, Lc2, 8)
factory.addPoint( e3+r , h1+r , 0, Lc2, 9)
factory.addPoint( e3+r , h1 , 0, Lc2, 10)
factory.addPoint( e1+e2, h1 , 0, Lc1, 11)
factory.addPoint( e1+e2, 0 , 0, Lc1, 12)
factory.addPoint( e2 , 0 , 0, Lc1, 13)
factory.addPoint( R1 / ssin, h5+R1*ccos, 0, Lc2, 14)
factory.addPoint( 0 , h5 , 0, Lc2, 15)
factory.addPoint(-R1 / ssin, h5+R1*ccos, 0, Lc2, 16)
factory.addPoint(-e2 , 0.0 , 0, Lc1, 17)
factory.addPoint(-R2 , h1+h3 , 0, Lc2, 18)
factory.addPoint(-R2 , h1+h3+h4, 0, Lc2, 19)
factory.addPoint( 0 , h1+h3+h4, 0, Lc2, 20)
factory.addPoint( R2 , h1+h3+h4, 0, Lc2, 21)
factory.addPoint( R2 , h1+h3 , 0, Lc2, 22)
factory.addPoint( 0 , h1+h3 , 0, Lc2, 23)
factory.addPoint( 0, h1+h3+h4+R2, 0, Lc2, 24)
factory.addPoint( 0, h1+h3-R2, 0, Lc2, 25)
factory.addLine(1 , 17, 1)
factory.addLine(17, 16, 2)
factory.addCircleArc(14,15,16, 3)
factory.addLine(14,13, 4)
factory.addLine(13,12, 5)
factory.addLine(12,11, 6)
factory.addLine(11,10, 7)
factory.addCircleArc(8,9,10, 8)
factory.addLine(8,7, 9)
factory.addLine(7,6, 10)
factory.addLine(6,5, 11)
factory.addCircleArc(3,4,5, 12)
factory.addLine(3,2, 13)
factory.addLine(2,1, 14)
factory.addLine(18,19, 15)
factory.addCircleArc(21,20,24, 16)
factory.addCircleArc(24,20,19, 17)
factory.addCircleArc(18,23,25, 18)
factory.addCircleArc(25,23,22, 19)
factory.addLine(21,22, 20)
factory.addCurveLoop([17,-15,18,19,-20,16], 21)
factory.addPlaneSurface([21], 22)
factory.addCurveLoop([11,-12,13,14,1,2,-3,4,5,6,7,-8,9,10], 23)
# A surface with one hole is specified using 2 curve loops:
factory.addPlaneSurface([23,21], 24)
# FIXME: this will be implemented through the gmshView API
# View "comments" {
# T2(10, -10, 0){ StrCat("Created on ", Today, " with Gmsh") };
# T3(0, 0.11, 0, TextAttributes("Align", "Center", "Font", "Helvetica")){ "Hole" };
# T3(0, 0.09, 0, TextAttributes("Align", "Center")){ "file://image.png@0.01x0" };
# T3(-0.01, 0.09, 0, 0){ "file://image.png@0.01x0,0,0,1,0,1,0" };
# T3(0, 0.12, 0, TextAttributes("Align", "Center")){ "file://image.png@0.01x0#" };
# T2(350, -7, 0){ "file://image.png@20x0" };
# };
factory.synchronize()
model.mesh.generate(2)
gmsh.write("t4.msh")
gmsh.finalize()
# This file reimplements gmsh/tutorial/t5.geo in Julia.
import gmsh
model = gmsh.model
factory = model.geo
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1)
model.add("t5")
lcar1 = .1
lcar2 = .0005
lcar3 = .055
factory.addPoint(0.5,0.5,0.5, lcar2, 1)
factory.addPoint(0.5,0.5,0, lcar1, 2)
factory.addPoint(0,0.5,0.5, lcar1, 3)
factory.addPoint(0,0,0.5, lcar1, 4)
factory.addPoint(0.5,0,0.5, lcar1, 5)
factory.addPoint(0.5,0,0, lcar1, 6)
factory.addPoint(0,0.5,0, lcar1, 7)
factory.addPoint(0,1,0, lcar1, 8)
factory.addPoint(1,1,0, lcar1, 9)
factory.addPoint(0,0,1, lcar1, 10)
factory.addPoint(0,1,1, lcar1, 11)
factory.addPoint(1,1,1, lcar1, 12)
factory.addPoint(1,0,1, lcar1, 13)
factory.addPoint(1,0,0, lcar1, 14)
factory.addLine(8,9, 1); factory.addLine(9,12, 2)
factory.addLine(12,11, 3); factory.addLine(11,8, 4)
factory.addLine(9,14, 5); factory.addLine(14,13, 6)
factory.addLine(13,12, 7); factory.addLine(11,10, 8)
factory.addLine(10,13, 9); factory.addLine(10,4, 10)
factory.addLine(4,5, 11); factory.addLine(5,6, 12)
factory.addLine(6,2, 13); factory.addLine(2,1, 14)
factory.addLine(1,3, 15); factory.addLine(3,7, 16)
factory.addLine(7,2, 17); factory.addLine(3,4, 18)
factory.addLine(5,1, 19); factory.addLine(7,8, 20)
factory.addLine(6,14, 21);
factory.addCurveLoop([-11,-19,-15,-18], 22)
factory.addPlaneSurface([22], 23)
factory.addCurveLoop([16,17,14,15], 24)
factory.addPlaneSurface([24], 25)
factory.addCurveLoop([-17,20,1,5,-21,13], 26)
factory.addPlaneSurface([26], 27)
factory.addCurveLoop([-4,-1,-2,-3], 28)
factory.addPlaneSurface([28], 29)
factory.addCurveLoop([-7,2,-5,-6], 30)
factory.addPlaneSurface([30], 31)
factory.addCurveLoop([6,-9,10,11,12,21], 32)
factory.addPlaneSurface([32], 33)
factory.addCurveLoop([7,3,8,9], 34)
factory.addPlaneSurface([34], 35)
factory.addCurveLoop([-10,18,-16,-20,4,-8], 36)
factory.addPlaneSurface([36], 37)
factory.addCurveLoop([-14,-13,-12,19], 38)
factory.addPlaneSurface([38], 39)
shells = []
# When the tag is not specified, a new one is automatically provided
sl = factory.addSurfaceLoop([35,31,29,37,33,23,39,25,27])
append!(shells, sl)
function cheeseHole(x, y, z, r, lc, shells)
p1 = factory.addPoint(x, y, z, lc)
p2 = factory.addPoint(x+r,y, z, lc)
p3 = factory.addPoint(x, y+r,z, lc)
p4 = factory.addPoint(x, y, z+r, lc)
p5 = factory.addPoint(x-r,y, z, lc)
p6 = factory.addPoint(x, y-r,z, lc)
p7 = factory.addPoint(x, y, z-r, lc)
c1 = factory.addCircleArc(p2,p1,p7)
c2 = factory.addCircleArc(p7,p1,p5)
c3 = factory.addCircleArc(p5,p1,p4)
c4 = factory.addCircleArc(p4,p1,p2)
c5 = factory.addCircleArc(p2,p1,p3)
c6 = factory.addCircleArc(p3,p1,p5)
c7 = factory.addCircleArc(p5,p1,p6)
c8 = factory.addCircleArc(p6,p1,p2)
c9 = factory.addCircleArc(p7,p1,p3)
c10 = factory.addCircleArc(p3,p1,p4)
c11 = factory.addCircleArc(p4,p1,p6)
c12 = factory.addCircleArc(p6,p1,p7)
l1 = factory.addCurveLoop([c5,c10,c4])
l2 = factory.addCurveLoop([c9,-c5,c1])
l3 = factory.addCurveLoop([c12,-c8,-c1])
l4 = factory.addCurveLoop([c8,-c4,c11])
l5 = factory.addCurveLoop([-c10,c6,c3])
l6 = factory.addCurveLoop([-c11,-c3,c7])
l7 = factory.addCurveLoop([-c2,-c7,-c12])
l8 = factory.addCurveLoop([-c6,-c9,c2])
s1 = factory.addSurfaceFilling([l1])
s2 = factory.addSurfaceFilling([l2])
s3 = factory.addSurfaceFilling([l3])
s4 = factory.addSurfaceFilling([l4])
s5 = factory.addSurfaceFilling([l5])
s6 = factory.addSurfaceFilling([l6])
s7 = factory.addSurfaceFilling([l7])
s8 = factory.addSurfaceFilling([l8])
sl = factory.addSurfaceLoop([s1, s2, s3, s4, s5, s6, s7, s8])
v = factory.addVolume([sl])
append!(shells, sl)
return v
end
x = 0; y = 0.75; z = 0; r = 0.09
for t in 1:5
x += 0.166
z += 0.166
v = cheeseHole(x, y, z, r, lcar3, shells)
model.addPhysicalGroup(3, [v], t)
end
factory.addVolume(shells, 186);
model.addPhysicalGroup(3, [186], 10);
factory.synchronize()
gmsh.fltk.run()
model.mesh.generate(3)
gmsh.write("t5.msh")
gmsh.finalize()
......@@ -40,7 +40,7 @@ factory.addLine(6,2, 13); factory.addLine(2,1, 14)
factory.addLine(1,3, 15); factory.addLine(3,7, 16)
factory.addLine(7,2, 17); factory.addLine(3,4, 18)
factory.addLine(5,1, 19); factory.addLine(7,8, 20)
factory.addLine(6,14, 21);
factory.addLine(6,14, 21)
factory.addCurveLoop([-11,-19,-15,-18], 22)
factory.addPlaneSurface([22], 23)
......@@ -114,14 +114,14 @@ def cheeseHole(x, y, z, r, lc, shells):
x = 0; y = 0.75; z = 0; r = 0.09
for t in range(1, 6):
x += 0.166 ;
z += 0.166 ;
v = cheeseHole(x, y, z, r, lcar3, shells);
model.addPhysicalGroup(3, [v], t);
x += 0.166
z += 0.166
v = cheeseHole(x, y, z, r, lcar3, shells)
model.addPhysicalGroup(3, [v], t)
factory.addVolume(shells, 186);
factory.addVolume(shells, 186)
model.addPhysicalGroup(3, [186], 10);
model.addPhysicalGroup(3, [186], 10)
factory.synchronize()
model.mesh.generate(3)
gmsh.write("t5.msh")
......
......@@ -78,9 +78,9 @@ post-processor. Its design goal is to provide a fast, light and user-friendly
meshing tool with parametric input and advanced visualization capabilities.
Gmsh is built around four modules: geometry, mesh, solver and
post-processing. The specification of any input to these modules is done either
interactively using the graphical user interface, in ASCII text files using
Gmsh's own scripting language (<code>.geo</code> files), or using the C++,
Python or C API.
interactively using the graphical user interface, in ASCII text files using
Gmsh's own scripting language (<code>.geo</code> files), or using the C++, C,
Python or Julia API.
</p>
<p>
......@@ -92,8 +92,8 @@ questions</a>. The source code contains many examples written using both the
<a href="https://gitlab.onelab.info/gmsh/gmsh/tree/master/tutorial">built-in</a>
<a href="https://gitlab.onelab.info/gmsh/gmsh/tree/master/demos/boolean">scripting</a>
language and the
<a href="https://gitlab.onelab.info/gmsh/gmsh/tree/master/demos/api">C++, Python
or C API</a>.
<a href="https://gitlab.onelab.info/gmsh/gmsh/tree/master/demos/api">C++, C,
Python or Julia API</a>.
</p>
<h2><a name="Download"></a>Download</h2>
......@@ -130,7 +130,7 @@ Public License (GPL)</a>:
<a href="https://gitlab.onelab.info/gmsh/gmsh/tree/master/demos/boolean">other
examples</a> are also available.
<!-- See the <a href="https://gitlab.onelab.info/gmsh/gmsh/tree/master/demos/api">C++,
C and Python</a> examples on how to use the Gmsh API to develop your
C, Python and Julia</a> examples on how to use the Gmsh API to develop your
own applications using the SDK. -->
</em>
</p>
......@@ -155,7 +155,7 @@ Public License (GPL)</a>:
</ul>
<p>
<em>See the <a href="https://gitlab.onelab.info/gmsh/gmsh/tree/master/demos/api">C++,
C and Python</a> examples on how to use the Gmsh API to develop your
C, Python and Julia</a> examples on how to use the Gmsh API to develop your
own applications using the SDK.</em>
</p>
<li>All versions: <a href="bin/">binaries</a>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment