Skip to content

Commit

Permalink
Add gmsh example
Browse files Browse the repository at this point in the history
  • Loading branch information
j-fu committed Nov 23, 2023
1 parent 915a910 commit 056a793
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ ExampleJuggler.verbose!(true)

function mkdocs()
cleanexamples()
generated_examples = @docscripts(joinpath(@__DIR__, "..", "examples"), ["examples1d.jl", "examples2d.jl", "examples3d.jl"],
generated_examples = @docscripts(joinpath(@__DIR__, "..", "examples"),
["examples1d.jl", "examples2d.jl", "examples3d.jl", "gmsh.jl"],
Plotter=CairoMakie)
makedocs(; sitename = "ExtendableGrids.jl",
modules = [ExtendableGrids, Base.get_extension(ExtendableGrids, :ExtendableGridsGmshExt)],
Expand Down
57 changes: 57 additions & 0 deletions examples/gmsh.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Gmsh examples
# ===============

using ExtendableGrids
using Gmsh: gmsh

function gmsh2d()
gmsh.initialize()
gmsh.option.setNumber("General.Terminal", 1)
gmsh.model.add("t1")

lc = 1e-2
gmsh.model.geo.addPoint(0, 0, 0, lc, 1)
gmsh.model.geo.addPoint(0.1, 0, 0, lc, 2)
gmsh.model.geo.addPoint(0.1, 0.3, 0, lc, 3)

p4 = gmsh.model.geo.addPoint(0, 0.3, 0, lc)

gmsh.model.geo.addLine(1, 2, 1)
gmsh.model.geo.addLine(3, 2, 2)
gmsh.model.geo.addLine(3, p4, 3)
gmsh.model.geo.addLine(4, 1, p4)

gmsh.model.geo.addCurveLoop([4, 1, -2, 3], 1)
gmsh.model.geo.addPlaneSurface([1], 1)

gmsh.model.geo.synchronize()

gmsh.model.addPhysicalGroup(0, [1, 2], 1)
gmsh.model.addPhysicalGroup(1, [1, 2], 2)
gmsh.model.addPhysicalGroup(2, [1], 6)

gmsh.model.setPhysicalName(2, 6, "My surface")

gmsh.model.mesh.generate(2)
grid = ExtendableGrids.simplexgrid_from_gmsh(gmsh.model)
gmsh.finalize()
grid
end
# ![](gmsh2d.svg)

# ## CI callbacks
# Unit tests
using Test
function runtests()
grid = gmsh2d()
@test num_nodes(grid) > 0 && num_cells(grid) > 0 && num_bfaces(grid) > 0
end

# Plot generation
using GridVisualize
function generateplots(picdir; Plotter = nothing)
if isdefined(Plotter, :Makie)
size = (300, 300)
Plotter.save(joinpath(picdir, "gmsh2d.svg"), gridplot(gmsh2d(); Plotter, size))
end
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ end
end

@testset "Examples" begin
@testscripts(joinpath(@__DIR__, "..", "examples"), ["examples1d.jl", "examples2d.jl", "examples3d.jl"])
@testscripts(joinpath(@__DIR__, "..", "examples"), ["examples1d.jl", "examples2d.jl", "examples3d.jl", "gmsh.jl"])
end

function voronoitest()
Expand Down

0 comments on commit 056a793

Please sign in to comment.