adding physical groups to occ kernel and refining mesh in Python API
Dear community, I have two question about using python API of Gmsh. Firstly, ho can I add physical groups? I have seen it in tutorials but it is not working for me. I am using occ kernel for making my model and maybe it is my problem. Can anyone please help me for this issue? I am using the following syntax:
import numpy as np
from numpy import genfromtxt
four_c_li=[[[26.54956817626953, 0.75, 1.0], [26.54956817626953, 29.25, 1.0],\
[71.69188690185547, 29.25, 99.0], [71.69188690185547, 0.75, 99.0]]]
sorted_c= np.array([[26.54956818, 0.75 , 1. ],\
[26.54956818, 29.25 , 1. ],\
[71.6918869 , 29.25 , 99. ],\
[71.6918869 , 0.75 , 99. ]])
cleared_ver= genfromtxt('cleared_ver.csv', delimiter=',')
four_c_d=np.expand_dims(sorted_c, axis=0)
cleared_ver_d=np.expand_dims(cleared_ver, axis=0)
cleared_ver_li=cleared_ver_d.tolist()
n_p=1053
import gmsh
gmsh.initialize()
sets = zip(four_c_li, cleared_ver_li)
for i, (a, b) in enumerate(sets):
gmsh.model.occ.addBox(0,sorted_c[0,1],sorted_c[0,2],100,sorted_c[1,1]-sorted_c[0,1],sorted_c[2,2]-sorted_c[0,2])
for [x, y, z] in a:
gmsh.model.occ.addPoint(x, y, z)
for [m, n, o] in b:
gmsh.model.occ.addPoint(m, n, o)
gmsh.model.occ.addLine(9,10,13)
gmsh.model.occ.addLine(10,11,14)
gmsh.model.occ.addLine(11,12,15)
gmsh.model.occ.addLine(12,9,16)
gmsh.model.occ.addCurveLoop([13, 14, 15, 16],7)
gmsh.model.occ.addPlaneSurface([7],7)
gmsh.model.addPhysicalGroup(1, [13, 14, 15, 16])
ps1 = gmsh.model.addPhysicalGroup(2, [7])
gmsh.model.setPhysicalName(2, ps1, "Fault")
gmsh.model.addPhysicalGroup(1, [21,25,26,27,22,17])
ps2= gmsh.model.addPhysicalGroup(2, [9,13])
gmsh.model.setPhysicalName(2, ps2, "front")
gmsh.model.addPhysicalGroup(1, [20,19,18,17])
ps3= gmsh.model.addPhysicalGroup(2, [15])
gmsh.model.setPhysicalName(2, ps3, "in")
gmsh.model.addPhysicalGroup(1, [29, 31, 30,26])
ps4= gmsh.model.addPhysicalGroup(2, [8])
gmsh.model.setPhysicalName(2, ps4, "out")
gmsh.model.addPhysicalGroup(1, [22,27,30,32,23,18])
ps5= gmsh.model.addPhysicalGroup(2, [10,16])
gmsh.model.setPhysicalName(2, ps5, "top")
gmsh.model.addPhysicalGroup(1, [21,25,29,28,24,20])
ps6= gmsh.model.addPhysicalGroup(2, [12,14])
gmsh.model.setPhysicalName(2, ps6, "bot")
gmsh.model.addPhysicalGroup(1, [28,24,19,23,32,31])
ps7= gmsh.model.addPhysicalGroup(2, [11,17])
gmsh.model.setPhysicalName(2, ps7, "back")
gmsh.model.occ.synchronize()
gmsh.model.mesh.setTransfiniteCurve(13, 15, "Progression")
gmsh.model.mesh.setTransfiniteCurve(14, 30, "Progression")
gmsh.model.mesh.setTransfiniteCurve(15, 15, "Progression")
gmsh.model.mesh.setTransfiniteCurve(16, 30, "Progression")
gmsh.model.mesh.setTransfiniteSurface(7, "Left")
gmsh.model.occ.synchronize()
gmsh.model.occ.fragment([(0,i) for i in range(13,n_p)], [(3,1)])
gmsh.model.occ.fragment([(2,7)], [(3,1)])
gmsh.model.occ.synchronize()
gmsh.model.mesh.embed(2, [7], 3, 1)
gmsh.model.mesh.embed(2, [7], 3, 2)
gmsh.model.mesh.field.add("Distance", 1)
gmsh.model.mesh.field.setNumbers(1, "NodesList", range(13,n_p))
gmsh.model.mesh.field.setNumber(1, "NNodesByEdge", 100)
gmsh.model.mesh.field.setNumbers(1, "EdgesList", [13,14,15,16])
gmsh.model.mesh.field.add("Threshold", 2)
gmsh.model.mesh.field.setNumber(2, "IField", 1)
gmsh.model.mesh.field.setNumber(2, "LcMin", 1)
gmsh.model.mesh.field.setNumber(2, "LcMax", 10)
gmsh.model.mesh.field.setNumber(2, "DistMin", 1)
gmsh.model.mesh.field.setNumber(2, "DistMax", 1.1)
gmsh.model.occ.synchronize()
gmsh.model.mesh.generate(3)
gmsh.option.setNumber("Mesh.MshFileVersion", 2.2)
gmsh.write("model" + str(i) + ".msh")
gmsh.fltk.run()
gmsh.clear()
gmsh.finalize()
I have also another question about refining my mesh. I am using both field method and transfinite in my model. But there are some parts of it that I want refine my mesh. Thes parts are shown by a yellow line in the uploaded fig. In fact, I want to reduce the number meshes in the junction of the cutting surface and my embedded points. In other words, I want to have my meshes dominantely around that surface and points rather than the body of my model. I tried to change gmsh.model.mesh.field.setNumber(2, "DistMin", ...)
and gmsh.model.mesh.field.setNumber(2, "DistMax", ...)
but I was successful. I uploaded my python script (as a .py file) and points (as a .csv file).
In advance, I appreciate any help and consideration.