Skip to content
Snippets Groups Projects
Commit 0ece73dd authored by Max Orok's avatar Max Orok
Browse files

Change comment style to match the existing tutorials

parent 5f2b1d9b
No related branches found
No related tags found
No related merge requests found
...@@ -61,7 +61,6 @@ model.mesh.generate(2) ...@@ -61,7 +61,6 @@ model.mesh.generate(2)
# Force a full-quad mesh with either option # Force a full-quad mesh with either option
# gmsh.option.setNumber("Mesh.SubdivisionAlgorithm", 1) # gmsh.option.setNumber("Mesh.SubdivisionAlgorithm", 1)
# gmsh.option.setNumber("Mesh.RecombinationAlgorithm", 2) # or 3 # gmsh.option.setNumber("Mesh.RecombinationAlgorithm", 2) # or 3
# model.mesh.generate(2) # model.mesh.generate(2)
gmsh.fltk.run() gmsh.fltk.run()
......
# This file reimplements gmsh/tutorial/t15.geo in Python. # This file reimplements gmsh/tutorial/t15.geo in Python.
# Note that t15.geo begins by calling "Include(t1.geo)" to paste the contents
# of t1.geo into t15.geo. Since the Python API has no equivalent command, we
# mark the lines adapted from t1.py.
#
# For educational purposes this code makes use of frequent geometry model
# synchronization calls.
# #
# If performance is a priority, you may want to group related embed calls to # Embedded points, lines and surfaces
# avoid calling the expensive synchronize operation too many times.
import gmsh import gmsh
model = gmsh.model model = gmsh.model
factory = model.geo factory = model.geo
# adapted t1.py section {{{
gmsh.initialize() gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1) gmsh.option.setNumber("General.Terminal", 1)
# Copied from t1.py...
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)
factory.addPoint(.1, .3, 0, lc, 3) factory.addPoint(.1, .3, 0, lc, 3)
factory.addPoint(0, .3, 0, lc, 4) factory.addPoint(0, .3, 0, lc, 4)
factory.addLine(1, 2, 1) factory.addLine(1, 2, 1)
factory.addLine(3, 2, 2) factory.addLine(3, 2, 2)
factory.addLine(3, 4, 3) factory.addLine(3, 4, 3)
factory.addLine(4, 1, 4) factory.addLine(4, 1, 4)
factory.addCurveLoop([4, 1, -2, 3], 1) factory.addCurveLoop([4, 1, -2, 3], 1)
factory.addPlaneSurface([1], 1) factory.addPlaneSurface([1], 1)
model.addPhysicalGroup(0, [1, 2], 1) 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
# }}}
# -- begin t15.py proper --
# We change the mesh size to generate a coarser mesh # We change the mesh size to generate a coarser mesh
lc = lc * 4 lc = lc * 4
...@@ -53,7 +37,6 @@ factory.addPoint(0.02, 0.02, 0., lc, 5) ...@@ -53,7 +37,6 @@ factory.addPoint(0.02, 0.02, 0., lc, 5)
# We have to synchronize before embedding entites. # We have to synchronize before embedding entites.
# Otherwise, we get an error like "Point 5 does not exist" # Otherwise, we get an error like "Point 5 does not exist"
#
factory.synchronize() factory.synchronize()
# embed the point (dim 0) in the surface (dim 2) # embed the point (dim 0) in the surface (dim 2)
...@@ -81,7 +64,7 @@ l = factory.addLine(7, p+1) ...@@ -81,7 +64,7 @@ l = factory.addLine(7, p+1)
factory.synchronize() factory.synchronize()
model.mesh.embed(1, [l], 3, 1) model.mesh.embed(1, [l], 3, 1)
# finally, we can only embed a surface in a volume # finally, we can embed a surface in a volume
factory.addPoint(0.02, 0.12, 0.05, lc, p+2) factory.addPoint(0.02, 0.12, 0.05, lc, p+2)
factory.addPoint(0.04, 0.12, 0.05, lc, p+3) factory.addPoint(0.04, 0.12, 0.05, lc, p+3)
factory.addPoint(0.04, 0.18, 0.05, lc, p+4) factory.addPoint(0.04, 0.18, 0.05, lc, p+4)
...@@ -99,7 +82,8 @@ factory.synchronize() ...@@ -99,7 +82,8 @@ factory.synchronize()
model.mesh.embed(2, [s], 3, 1) model.mesh.embed(2, [s], 3, 1)
# create and show the mesh # create and show the mesh
# model.mesh.generate(3) model.mesh.generate(3)
# gmsh.fltk.run() gmsh.write("t15.msh")
gmsh.fltk.run()
gmsh.finalize() gmsh.finalize()
# This file reimplements gmsh/tutorial/t7.geo in Python. # This file reimplements gmsh/tutorial/t7.geo in Python.
# It extends t1.py to use a background mesh. #
# Background mesh
import gmsh import gmsh
model = gmsh.model model = gmsh.model
factory = model.geo factory = model.geo
# adapted t1.py section {{{
gmsh.initialize() gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1) gmsh.option.setNumber("General.Terminal", 1)
# Copied from t1.py...
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)
factory.addPoint(.1, .3, 0, lc, 3) factory.addPoint(.1, .3, 0, lc, 3)
factory.addPoint(0, .3, 0, lc, 4) factory.addPoint(0, .3, 0, lc, 4)
factory.addLine(1, 2, 1) factory.addLine(1, 2, 1)
factory.addLine(3, 2, 2) factory.addLine(3, 2, 2)
factory.addLine(3, 4, 3) factory.addLine(3, 4, 3)
factory.addLine(4, 1, 4) factory.addLine(4, 1, 4)
factory.addCurveLoop([4, 1, -2, 3], 1) factory.addCurveLoop([4, 1, -2, 3], 1)
factory.addPlaneSurface([1], 1) factory.addPlaneSurface([1], 1)
model.addPhysicalGroup(0, [1, 2], 1) 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
model.geo.synchronize() factory.synchronize()
# }}}
# -- begin t7.py --
# add the background mesh file as a view # add the background mesh file as a view
gmsh.merge("bgmesh.pos") gmsh.merge("bgmesh.pos")
...@@ -42,6 +36,7 @@ gmsh.merge("bgmesh.pos") ...@@ -42,6 +36,7 @@ gmsh.merge("bgmesh.pos")
# pass the just-added view number to specify the background mesh # pass the just-added view number to specify the background mesh
gmsh.model.mesh.field.setAsBackgroundMesh(0) gmsh.model.mesh.field.setAsBackgroundMesh(0)
gmsh.model.mesh.generate(2) gmsh.model.mesh.generate(2)
gmsh.write("t7.msh")
# show the mesh file # show the mesh file
# gmsh.fltk.run() # gmsh.fltk.run()
......
# This file reimplements gmsh/tutorial/t8.geo in Python. # This file reimplements gmsh/tutorial/t8.geo in Python.
# It demonstrates post-processing, animations and using options. #
# Post-processing, scripting, animations, options
import gmsh import gmsh
model = gmsh.model model = gmsh.model
factory = model.geo factory = model.geo
# adapted t1.py section {{{
gmsh.initialize() gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1) gmsh.option.setNumber("General.Terminal", 1)
# Copied from t1.py...
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)
factory.addPoint(.1, .3, 0, lc, 3) factory.addPoint(.1, .3, 0, lc, 3)
factory.addPoint(0, .3, 0, lc, 4) factory.addPoint(0, .3, 0, lc, 4)
factory.addLine(1, 2, 1) factory.addLine(1, 2, 1)
factory.addLine(3, 2, 2) factory.addLine(3, 2, 2)
factory.addLine(3, 4, 3) factory.addLine(3, 4, 3)
factory.addLine(4, 1, 4) factory.addLine(4, 1, 4)
factory.addCurveLoop([4, 1, -2, 3], 1) factory.addCurveLoop([4, 1, -2, 3], 1)
factory.addPlaneSurface([1], 1) factory.addPlaneSurface([1], 1)
model.addPhysicalGroup(0, [1, 2], 1) 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
model.geo.synchronize() factory.synchronize()
# }}}
# -- begin t8.py --
# add post-processing views to work on # add post-processing views to work on
gmsh.merge("view1.pos") gmsh.merge("view1.pos")
...@@ -164,10 +158,11 @@ for num in range(1, 4): ...@@ -164,10 +158,11 @@ for num in range(1, 4):
# write out the graphics scene to an image file # write out the graphics scene to an image file
# Gmsh will try to detect the file extension # Gmsh will try to detect the file extension
if num == 3:
gmsh.write("t2-{:.2g}.gif".format(num2)) # if num == 3:
gmsh.write("t2-{:.2g}.ppm".format(num2)) # gmsh.write("t2-{:.2g}.gif".format(num2))
gmsh.write("t2-{:.2g}.jpg".format(num2)) # gmsh.write("t2-{:.2g}.ppm".format(num2))
# gmsh.write("t2-{:.2g}.jpg".format(num2))
if num == 3: if num == 3:
pass pass
......
...@@ -32,7 +32,7 @@ plugin.run("CutPlane") ...@@ -32,7 +32,7 @@ plugin.run("CutPlane")
# Third is Annotate # Third is Annotate
plugin.setString("Annotate", "Text", "A nice title") plugin.setString("Annotate", "Text", "A nice title")
# By convention, window coordinates larger than 99999 represent the center` # By convention, window coordinates larger than 99999 represent the center
plugin.setNumber("Annotate", "X", 1.e5) plugin.setNumber("Annotate", "X", 1.e5)
plugin.setNumber("Annotate", "Y", 50) plugin.setNumber("Annotate", "Y", 50)
plugin.setString("Annotate", "Font", "Times-BoldItalic") plugin.setString("Annotate", "Font", "Times-BoldItalic")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment