Size maps using .pos file
Hello,
I am trying to use a post-processing view to create a size map. I have created a very simple structure (following tutorial #7 (closed)). I have defined a rectangle with a very coarse mesh so that I only have 4 nodes and 2 elements.
import os
# Initialize gmsh
gmsh.initialize()
# Create a simple rectangular geometry:
lc = 1e0
gmsh.model.geo.addPoint(0, 0, 0, lc, 1)
gmsh.model.geo.addPoint(.1, 0, 0, lc, 2)
gmsh.model.geo.addPoint(.1, .3, 0, lc, 3)
gmsh.model.geo.addPoint(0, .3, 0, lc, 4)
gmsh.model.geo.addLine(1, 2, 1)
gmsh.model.geo.addLine(3, 2, 2)
gmsh.model.geo.addLine(3, 4, 3)
gmsh.model.geo.addLine(4, 1, 4)
gmsh.model.geo.addCurveLoop([4, 1, -2, 3], 1)
gmsh.model.geo.addPlaneSurface([1], 1)
gmsh.model.geo.synchronize()
# Save mesh
gmsh.model.mesh.generate(2)
gmsh.write("rectangle.msh2")
I have then defined the mesh size in a .pos for points:
View "background mesh" { SP(0, 0, 0){0.00001}; SP(0.1, 0, 0){0.015}; SP(0.1, 0.3, 0){0.015}; SP(0, 0.3, 0){0.015}; };
and over triangles: View "background mesh" { ST(0.1, 0, 0, 0, 0.3, 0, 0, 0, 0){0.15, 0.15, 0.0001}; ST(0.1, 0, 0, 0.1, 0.3, 0, 0, 0.3, 0){0.15, 0.15, 0.15}; };
And using tutorial 7 have used the .pos as a size map
script_dir = os.path.dirname(__file__)
path_pos = script_dir + "/../pos_files/sm.pos"
gmsh.merge(path_pos)
# Add the post-processing view as a new size field:
bg_field = gmsh.model.mesh.field.add("PostView")
gmsh.model.mesh.field.setNumber(bg_field, "ViewIndex", 0)
# Apply the view as the current background mesh size field:
gmsh.model.mesh.field.setAsBackgroundMesh(bg_field)
# In order to compute the mesh sizes from the background mesh only, and
# disregard any other size constraints, one can set:
gmsh.option.setNumber("Mesh.MeshSizeExtendFromBoundary", 0)
gmsh.option.setNumber("Mesh.MeshSizeFromPoints", 0)
gmsh.option.setNumber("Mesh.MeshSizeFromCurvature", 0)
gmsh.fltk.run()
# Save new mesh.
gmsh.model.mesh.generate(2)
gmsh.write("rectangle_sm.msh2")
In both cases, I am attempting to get a very fine mesh at the 0,0,0 corner. In the case where things are defined over triangles, I get what I expect. A fine mesh on the bottom left corner that is much coarser at the other corners. However, when defining things over points, the mesh has (roughly) the same characteristic length throughout the rectangle. What is the difference between using the .pos to define the characteristic length over triangles vs. over points?
My end goal is to create a size map where I would be able to define the characteristic length at every global node. Which approach should I use?
Any help or documentation you could point me to would be greatly appreciated.
Thanks in advance.