diff --git a/tutorial/julia/README.txt b/tutorial/julia/README.txt index 78d08cd7df36beec262c8641995da66557f3cbd6..81a29d92d621c8bff6213898298ebae57cf208fa 100644 --- a/tutorial/julia/README.txt +++ b/tutorial/julia/README.txt @@ -1,5 +1,5 @@ -This directory contains Julia versions of some of the tutorials, written using -the Gmsh API. +This directory contains the Gmsh Julia tutorials, written using the Gmsh Julia +API. To run the Julia tutorials, you need the Gmsh dynamic library and the Julia module (`gmsh.jl'). These can be either obtained diff --git a/tutorial/julia/t1.jl b/tutorial/julia/t1.jl index d320c2038ebdcce2b40efc1f1e345aaf997223e0..de01e2a8b1c980a8948f8e913acef970ded5db7b 100644 --- a/tutorial/julia/t1.jl +++ b/tutorial/julia/t1.jl @@ -1,85 +1,38 @@ -# This file reimplements gmsh/tutorial/t1.geo in Julia. +# See the corresponding Python tutorial for detailed comments. -# For all the elementary explanations about the general philosphy of entities in -# Gmsh, see the comments in the .geo file. Comments here focus on the specifics -# of the Julia API. - -# The API is entirely defined in the gmsh module import gmsh -# Before using any functions in the Julia API, Gmsh must be initialized. gmsh.initialize() -# By default Gmsh will not print out any messages: in order to output messages -# on the terminal, just set the standard Gmsh option "General.Terminal" (same -# format and meaning as in .geo files): gmsh.option.setNumber("General.Terminal", 1) -# Next we add a new model named "t1" (if gmsh.model.add() is not called a new -# unnamed model will be created on the fly, if necessary): gmsh.model.add("t1") -# The Julia API provides direct access to the internal CAD kernels. The -# built-in CAD kernel was used in t1.geo: the corresponding API functions have -# the "gmsh.model.geo" prefix. To create geometrical points with the built-in -# CAD kernel, one thus uses gmsh.model.geo.addPoint(): -# -# - the first 3 arguments are the point coordinates (x, y, z) -# -# - the next (optional) argument is the target mesh size close to the point -# -# - the last (optional) argument is the point tag lc = 1e-2 gmsh.model.geo.addPoint(0, 0, 0, lc, 1) gmsh.model.geo.addPoint(.1, 0, 0, lc, 2) gmsh.model.geo.addPoint(.1, .3, 0, lc, 3) -gmsh.model.geo.addPoint(0, .3, 0, lc, 4) -# The API to create lines with the built-in kernel follows the same -# conventions: the first 2 arguments are point tags, the last (optional one) -# is the line tag. +p4 = gmsh.model.geo.addPoint(0, .3, 0, lc) + gmsh.model.geo.addLine(1, 2, 1) gmsh.model.geo.addLine(3, 2, 2) -gmsh.model.geo.addLine(3, 4, 3) -gmsh.model.geo.addLine(4, 1, 4) +gmsh.model.geo.addLine(3, p4, 3) +gmsh.model.geo.addLine(4, 1, p4) -# The philosophy to construct curve loops and surfaces is similar: the first -# argument is now a vector of integers. gmsh.model.geo.addCurveLoop([4, 1, -2, 3], 1) gmsh.model.geo.addPlaneSurface([1], 1) -# Physical groups are defined by providing the dimension of the group (0 for -# physical points, 1 for physical curves, 2 for physical surfaces and 3 for -# phsyical volumes) followed by a vector of entity tags. The last (optional) -# argument is the tag of the new group to create. gmsh.model.addPhysicalGroup(0, [1, 2], 1) gmsh.model.addPhysicalGroup(1, [1, 2], 2) gmsh.model.addPhysicalGroup(2, [1], 6) -# Physical names are also defined by providing the dimension and tag of the -# entity. gmsh.model.setPhysicalName(2, 6, "My surface") -# Before it can be meshed, the internal CAD representation must be synchronized -# with the Gmsh model, which will create the relevant Gmsh data structures. This -# is achieved by the gmsh.model.geo.synchronize() API call for the built-in CAD -# kernel. Synchronizations can be called at any time, but they involve a non -# trivial amount of processing; so while you could synchronize the internal CAD -# data after every CAD command, it is usually better to minimize the number of -# synchronization points. gmsh.model.geo.synchronize() -# We can then generate a 2D mesh... gmsh.model.mesh.generate(2) -# ... and save it to disk gmsh.write("t1.msh") -# Remember that by default, if physical groups are defined, Gmsh will export in -# the output mesh file only those elements that belong to at least one physical -# group. To force Gmsh to save all elements, you can use -# -# gmsh.option.setNumber("Mesh.SaveAll", 1) - -# This should be called at the end: gmsh.finalize() diff --git a/tutorial/julia/t16.jl b/tutorial/julia/t16.jl index d523eaf1e848f42656da139032644f735bc58c38..6e72adde9198b8d70ad0b24200fffce5a0c21050 100644 --- a/tutorial/julia/t16.jl +++ b/tutorial/julia/t16.jl @@ -1,4 +1,4 @@ -# This file reimplements gmsh/tutorial/t16.geo in Julia. +# See the corresponding Python tutorial for detailed comments. import gmsh diff --git a/tutorial/julia/t2.jl b/tutorial/julia/t2.jl index 0f9bbe8a3c4313fc0db649a8c3c45014306f1fc8..cd24b8c2ed020b8e3e0415bb64ff218bd71ae298 100644 --- a/tutorial/julia/t2.jl +++ b/tutorial/julia/t2.jl @@ -1,21 +1,16 @@ -# 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. +# See the corresponding Python tutorial for detailed comments. 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) @@ -31,21 +26,12 @@ 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) @@ -85,18 +71,11 @@ 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) diff --git a/tutorial/julia/t3.jl b/tutorial/julia/t3.jl index 7d7884fa21bf1bf3c66551deb5ff2000013cc426..72b830f155b7cf9c2d4954a1e01728a95919a5d4 100644 --- a/tutorial/julia/t3.jl +++ b/tutorial/julia/t3.jl @@ -1,4 +1,4 @@ -# This files reimplements gmsh/tutorial/t3.geo in Julia. +# See the corresponding Python tutorial for detailed comments. import gmsh @@ -10,7 +10,6 @@ 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) @@ -26,19 +25,12 @@ 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) diff --git a/tutorial/julia/t4.jl b/tutorial/julia/t4.jl index b19cffc898c579b6c633ccceb8964a1291f1db66..0c86cf9b5a33b0d1b445d5da7e40e34278eb9ee0 100644 --- a/tutorial/julia/t4.jl +++ b/tutorial/julia/t4.jl @@ -1,4 +1,4 @@ -# This file reimplements gmsh/tutorial/t4.geo in Julia. +# See the corresponding Python tutorial for detailed comments. import gmsh @@ -49,7 +49,7 @@ 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) @@ -79,7 +79,6 @@ 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 diff --git a/tutorial/julia/t5.jl b/tutorial/julia/t5.jl index 8fd96b2fa2a462e310ec69429364b6a287907521..3e368152b1c3d6e5f93071b6521112f33cf610d6 100644 --- a/tutorial/julia/t5.jl +++ b/tutorial/julia/t5.jl @@ -1,4 +1,4 @@ -# This file reimplements gmsh/tutorial/t5.geo in Julia. +# See the corresponding Python tutorial for detailed comments. import gmsh