diff --git a/examples/cube/mesh/cube.jl b/examples/cube/mesh/box.jl similarity index 59% rename from examples/cube/mesh/cube.jl rename to examples/cube/mesh/box.jl index 5b7159e07..ab97ff2cc 100644 --- a/examples/cube/mesh/cube.jl +++ b/examples/cube/mesh/box.jl @@ -1,41 +1,47 @@ using Gmsh: gmsh #= - make_cube_mesh(;hex_mesh = true, verbose = 10, periodic =[false,false,false], filename="") + make_box_mesh(;hex_mesh = true, verbose = 10, periodic =[false,false,false], filename="") -Generate a mesh of a cube for testing periodicity +Generate a mesh of a box for testing periodicity Arguments: - hex_mesh - Whether the generated mesh should be hexahedral - verbose - Verbosity setting for gmsh + - length - length of the box for each direction, [lx, ly, lz] + - res - element size at each direction [rez_x, rez_y, rez_z] - periodic - which faces to be periodic, [x periodic, y periodic, z periodic] - filename - filename to save the generated mesh, if empty the mesh is not saved + - gui - Opens gui if true =# -function make_cube_mesh(; +function make_box_mesh(; hex_mesh=true, verbose=10, + length=[1., 1., 1.], + res=[2/3, 2/3, 2/3], periodic=[false, false, false], - filename="" + filename="", + gui=false ) gmsh.initialize() gmsh.option.setNumber("General.Verbosity", verbose) # Add model - if "cube" in gmsh.model.list() - gmsh.model.setCurrent("cube") + if "box" in gmsh.model.list() + gmsh.model.setCurrent("box") gmsh.model.remove() end - gmsh.model.add("cube") + gmsh.model.add("box") + - length = 1.0 kernel = gmsh.model.occ - @show cube = kernel.add_box(0.0, 0.0, 0.0, length, length, length) - @show _, cube_boundary = kernel.getSurfaceLoops(cube) + @show box = kernel.add_box(0.0, 0.0, 0.0, length[1], length[2], length[3]) + @show _, box_boundary = kernel.getSurfaceLoops(box) kernel.synchronize() - gmsh.option.setNumber("Mesh.MeshSizeMin", length / 1.5) - gmsh.option.setNumber("Mesh.MeshSizeMax", length / 1.5) + gmsh.option.setNumber("Mesh.MeshSizeMin", minimum(res)) # TODO: This doesn't set the resolution for each direction + gmsh.option.setNumber("Mesh.MeshSizeMax", maximum(res)) # Makes the surfaces of the hex transfinite if hex_mesh @@ -51,7 +57,7 @@ function make_cube_mesh(; 2, [2], [1], - [1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] + [1, 0, 0, length[1], 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] ) end if periodic[2] @@ -59,7 +65,7 @@ function make_cube_mesh(; 2, [4], [3], - [1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1] + [1, 0, 0, 0, 0, 1, 0, length[2], 0, 0, 1, 0, 0, 0, 0, 1] ) end if periodic[3] @@ -67,11 +73,11 @@ function make_cube_mesh(; 2, [6], [5], - [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1] + [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, length[3], 0, 0, 0, 1] ) end - gmsh.model.add_physical_group(3, [cube], -1, "Volume") + gmsh.model.add_physical_group(3, [box], -1, "Volume") gmsh.model.add_physical_group(2, [1], 1, "Xmin") gmsh.model.add_physical_group(2, [2], 2, "Xmax") gmsh.model.add_physical_group(2, [3], 3, "Ymin") @@ -81,12 +87,14 @@ function make_cube_mesh(; gmsh.model.mesh.generate(3) - gmsh.fltk.run() + if gui + gmsh.fltk.run() + end - if isempty(filename) + if !isempty(filename) gmsh.option.setNumber("Mesh.MshFileVersion", 2.2) gmsh.option.setNumber("Mesh.Binary", 0) - gmsh.write(joinpath(@__DIR__, "cube.msh")) + gmsh.write(joinpath(@__DIR__, filename)) end return gmsh.finalize() end