From b523388ed8fbb9bbe706ee3897da6972d067ddfa Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@uliege.be> Date: Sat, 3 Jul 2021 08:14:33 +0200 Subject: [PATCH] julia version --- demos/api/terrain_bspline.jl | 77 ++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 demos/api/terrain_bspline.jl diff --git a/demos/api/terrain_bspline.jl b/demos/api/terrain_bspline.jl new file mode 100644 index 0000000000..cc3110666c --- /dev/null +++ b/demos/api/terrain_bspline.jl @@ -0,0 +1,77 @@ +import gmsh + +gmsh.initialize() + +gmsh.model.add("terrain") + +# create the terrain surface from N x N input data points (here simulated using +# a simple function): +N = 100 +ps = [] + +# create a bspline surface +for i in 0:N + for j in 0:N + push!(ps, gmsh.model.occ.addPoint(float(i) / N, float(j) / N, + 0.05 * sin(10 * float(i + j) / N))) + end +end +s = gmsh.model.occ.addBSplineSurface(ps, N+1) + +# create a box +v = gmsh.model.occ.addBox(0, 0, -0.5, 1, 1, 1) + +# fragment the box with the bspline surface +gmsh.model.occ.fragment([(2, s)], [(3, v)]) +gmsh.model.occ.synchronize() + +# define a parameter to select the mesh type interactively +gmsh.onelab.set("""[ + { + "type":"number", + "name":"Parameters/Full-hex mesh?", + "values":[0], + "choices":[0, 1] + } +]""") + + +function setMeshConstraint() + if gmsh.onelab.getNumber("Parameters/Full-hex mesh?")[1] == 1 + NN = 30 + for c in gmsh.model.getEntities(1) + gmsh.model.mesh.setTransfiniteCurve(c[2], NN) + for s in gmsh.model.getEntities(2) + gmsh.model.mesh.setTransfiniteSurface(s[2]) + gmsh.model.mesh.setRecombine(s[1], s[2]) + gmsh.model.mesh.setSmoothing(s[1], s[2], 100) + end + end + gmsh.model.mesh.setTransfiniteVolume(1) + gmsh.model.mesh.setTransfiniteVolume(2) + else + gmsh.model.mesh.removeConstraints() + gmsh.option.setNumber("Mesh.MeshSizeMin", 0.05) + gmsh.option.setNumber("Mesh.MeshSizeMax", 0.05) + end +end + +setMeshConstraint() + +function checkForEvent() + action = gmsh.onelab.getString("ONELAB/Action") + if length(action) > 0 && action[1] == "check" + gmsh.onelab.setString("ONELAB/Action", [""]) + setMeshConstraint() + end + return true +end + +if !("-nopopup" in ARGS) + gmsh.fltk.initialize() + while gmsh.fltk.isAvailable() == 1 && checkForEvent() + gmsh.fltk.wait() + end +end + +gmsh.finalize() -- GitLab