Skip to content
Snippets Groups Projects
Commit fb03e12a authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

remove comments from julia tutorials and point to python tutorials

parent 4b4fd0b3
No related branches found
No related tags found
No related merge requests found
This directory contains Julia versions of some of the tutorials, written using This directory contains the Gmsh Julia tutorials, written using the Gmsh Julia
the Gmsh API. API.
To run the Julia tutorials, you need the Gmsh dynamic library and the Julia To run the Julia tutorials, you need the Gmsh dynamic library and the Julia
module (`gmsh.jl'). These can be either obtained module (`gmsh.jl'). These can be either obtained
......
# 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 import gmsh
# Before using any functions in the Julia API, Gmsh must be initialized.
gmsh.initialize() 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) 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") 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 lc = 1e-2
gmsh.model.geo.addPoint(0, 0, 0, lc, 1) gmsh.model.geo.addPoint(0, 0, 0, lc, 1)
gmsh.model.geo.addPoint(.1, 0, 0, lc, 2) gmsh.model.geo.addPoint(.1, 0, 0, lc, 2)
gmsh.model.geo.addPoint(.1, .3, 0, lc, 3) 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 p4 = gmsh.model.geo.addPoint(0, .3, 0, lc)
# conventions: the first 2 arguments are point tags, the last (optional one)
# is the line tag.
gmsh.model.geo.addLine(1, 2, 1) gmsh.model.geo.addLine(1, 2, 1)
gmsh.model.geo.addLine(3, 2, 2) gmsh.model.geo.addLine(3, 2, 2)
gmsh.model.geo.addLine(3, 4, 3) gmsh.model.geo.addLine(3, p4, 3)
gmsh.model.geo.addLine(4, 1, 4) 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.addCurveLoop([4, 1, -2, 3], 1)
gmsh.model.geo.addPlaneSurface([1], 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(0, [1, 2], 1)
gmsh.model.addPhysicalGroup(1, [1, 2], 2) gmsh.model.addPhysicalGroup(1, [1, 2], 2)
gmsh.model.addPhysicalGroup(2, [1], 6) 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") 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() gmsh.model.geo.synchronize()
# We can then generate a 2D mesh...
gmsh.model.mesh.generate(2) gmsh.model.mesh.generate(2)
# ... and save it to disk
gmsh.write("t1.msh") 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() gmsh.finalize()
# This file reimplements gmsh/tutorial/t16.geo in Julia. # See the corresponding Python tutorial for detailed comments.
import gmsh import gmsh
......
# This file reimplements gmsh/tutorial/t2.geo in Julia. Comments focus on the new # See the corresponding Python tutorial for detailed comments.
# API functions used, compared to the ones introduced in t1.jl.
import gmsh import gmsh
# nice shortcuts
model = gmsh.model model = gmsh.model
factory = model.geo 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.initialize(ARGS)
gmsh.option.setNumber("General.Terminal", 1) gmsh.option.setNumber("General.Terminal", 1)
model.add("t2") model.add("t2")
# Copied from t1.jl...
lc = 1e-2 lc = 1e-2
factory.addPoint(0, 0, 0, lc, 1) factory.addPoint(0, 0, 0, lc, 1)
factory.addPoint(.1, 0, 0, lc, 2) factory.addPoint(.1, 0, 0, lc, 2)
...@@ -31,21 +26,12 @@ model.addPhysicalGroup(0, [1, 2], 1) ...@@ -31,21 +26,12 @@ model.addPhysicalGroup(0, [1, 2], 1)
model.addPhysicalGroup(1, [1, 2], 2) model.addPhysicalGroup(1, [1, 2], 2)
model.addPhysicalGroup(2, [1], 6) model.addPhysicalGroup(2, [1], 6)
model.setPhysicalName(2, 6, "My surface") model.setPhysicalName(2, 6, "My surface")
# ...end of copy
factory.addPoint(0, .4, 0, lc, 5) factory.addPoint(0, .4, 0, lc, 5)
factory.addLine(4, 5, 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) 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)]) ov = factory.copy([(0, 3)])
factory.translate(ov, 0, 0.1, 0) factory.translate(ov, 0, 0.1, 0)
...@@ -85,18 +71,11 @@ factory.addPlaneSurface([124], 125) ...@@ -85,18 +71,11 @@ factory.addPlaneSurface([124], 125)
factory.addCurveLoop([115, 116, 117, 114], 126) factory.addCurveLoop([115, 116, 117, 114], 126)
factory.addPlaneSurface([126], 127) 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.addSurfaceLoop([127, 119, 121, 123, 125, 11], 128)
factory.addVolume([128], 129) 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) 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), factory.mesh.setSize([(0,103), (0,105), (0,109), (0,102), (0,28),
(0, 24), (0,6), (0,5)], lc * 3) (0, 24), (0,6), (0,5)], lc * 3)
......
# This files reimplements gmsh/tutorial/t3.geo in Julia. # See the corresponding Python tutorial for detailed comments.
import gmsh import gmsh
...@@ -10,7 +10,6 @@ gmsh.option.setNumber("General.Terminal", 1) ...@@ -10,7 +10,6 @@ gmsh.option.setNumber("General.Terminal", 1)
model.add("t3") model.add("t3")
# Copied from t1.jl...
lc = 1e-2 lc = 1e-2
factory.addPoint(0, 0, 0, lc, 1) factory.addPoint(0, 0, 0, lc, 1)
factory.addPoint(.1, 0, 0, lc, 2) factory.addPoint(.1, 0, 0, lc, 2)
...@@ -26,19 +25,12 @@ model.addPhysicalGroup(0, [1, 2], 1) ...@@ -26,19 +25,12 @@ model.addPhysicalGroup(0, [1, 2], 1)
model.addPhysicalGroup(1, [1, 2], 2) model.addPhysicalGroup(1, [1, 2], 2)
model.addPhysicalGroup(2, [1], 6) model.addPhysicalGroup(2, [1], 6)
model.setPhysicalName(2, 6, "My surface") model.setPhysicalName(2, 6, "My surface")
# ...end of copy
h = 0.1 h = 0.1
angle = 90. 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]) 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.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., ov = factory.twist([(2,50)], 0,0.15,0.25, -2*h,0,0, 1,0,0, angle*pi/180.,
[10], [], true) [10], [], true)
......
# This file reimplements gmsh/tutorial/t4.geo in Julia. # See the corresponding Python tutorial for detailed comments.
import gmsh import gmsh
...@@ -79,7 +79,6 @@ factory.addCurveLoop([17,-15,18,19,-20,16], 21) ...@@ -79,7 +79,6 @@ factory.addCurveLoop([17,-15,18,19,-20,16], 21)
factory.addPlaneSurface([21], 22) factory.addPlaneSurface([21], 22)
factory.addCurveLoop([11,-12,13,14,1,2,-3,4,5,6,7,-8,9,10], 23) 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) factory.addPlaneSurface([23,21], 24)
# FIXME: this will be implemented through the gmshView API # FIXME: this will be implemented through the gmshView API
......
# This file reimplements gmsh/tutorial/t5.geo in Julia. # See the corresponding Python tutorial for detailed comments.
import gmsh import gmsh
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment