splitCurve not producing the expected result
I mean to use splitCurve
in python, from the built-in kernel.
I use function test_split_rectangle2
below.
The output I get is
Entity dim: 0 , tag: 1 , name: p_lb, coordinates: [ 0. -1. 0.]
Entity dim: 0 , tag: 2 , name: p_lt, coordinates: [0. 2. 0.]
Entity dim: 0 , tag: 3 , name: p_rb, coordinates: [ 1. -1. 0.]
Entity dim: 0 , tag: 4 , name: p_rt, coordinates: [1. 2. 0.]
Entity dim: 0 , tag: 5 , name: psplit1, coordinates: [0. 0.5 0. ]
Entity dim: 1 , tag: 2 , name: l_t, end points: [2 4]
Entity dim: 1 , tag: 3 , name: l_r, end points: [4 3]
Entity dim: 1 , tag: 4 , name: l_b, end points: [3 1]
Entity dim: 1 , tag: 5 , name: , end points: [1 2]
Info : Writing 'rectangle_split.msh'...
Info : Done writing 'rectangle_split.msh'
Before splitCurve
I have 4 lines forming a rectangle, with tags 1-4.
After splitCurve
(which aims at splitting line 1) I still have 4 lines, replacing line 1 with line 5 (same end points).
I guess I might be misinterpreting the way to use splitCurve
, and I didn't find any example.
Any hint is welcome! Thanks
def dump_entity(e):
"""
@brief Dump information on a (geometrical) entity
"""
edim = e[0]
etag = e[1]
gm = gmsh.model
ename = gm.getEntityName(edim, etag)
print('Entity dim:', edim, ', tag:', etag, ', name:', ename, end='')
if (edim == 0):
coords = gm.getValue(0, etag, [])
print(', coordinates:', coords)
elif (edim == 1):
# downadj = getAdjacenciesDownward(edim, etag)
# print(', end points:', downadj)
eadj = gm.getAdjacencies(edim, etag)
print(', end points:', eadj[1])
elif (edim == 2):
# downadj = getAdjacenciesDownward(edim, etag)
# print(', edges:', downadj)
eadj = gm.getAdjacencies(edim, etag)
print(', edges:', eadj[1])
else: # TODO: also define what to do for edim=2
print()
return (edim, etag, ename)
def test_split_rectangle2():
import gmsh
# Initialize Gmsh
gmsh.initialize()
gm = gmsh.model
# Create a new model
gm.add("rectangle_split")
# Rectangle corners
bbox = [[0,1], [-1, 2]]
# Mesh resolution
res = 0.2
# Setup a dict for assigning dynamically named variables
my_locals = {}
# Use the built-in kernel
kernel = gm.geo
# Create points
lr_list = ['l', 'r'] # left/right
bt_list = ['b', 't'] # bottom/top
p_list = []
for ix in range(2):
for iy in range(2):
# Create a point (vertex)
p = kernel.addPoint(bbox[0][ix], bbox[1][iy], 0.0, res)
var_p = f'p_{lr_list[ix]}{bt_list[iy]}'
my_locals[var_p] = p
gm.setEntityName(0, p, f'{var_p}')
# Collect points in the edge
p_list.append(p)
# Create lines
l_l = kernel.addLine(my_locals['p_lb'], my_locals['p_lt'])
l_t = kernel.addLine(my_locals['p_lt'], my_locals['p_rt'])
l_r = kernel.addLine(my_locals['p_rt'], my_locals['p_rb'])
l_b = kernel.addLine(my_locals['p_rb'], my_locals['p_lb'])
l_list = []
for var2 in ['l', 't', 'r', 'b']:
var = f'l_{var2}'
val = locals()[var]
gm.setEntityName(1, val, f'{var}')
l_list.append(val)
# Try splitting a line
# Synchronize the model
kernel.synchronize()
# Add point
coords = gm.getValue(1, l_l, [0.5])
psplit1 = kernel.addPoint(*coords)
gm.setEntityName(0, psplit1, f'psplit1')
kernel.synchronize()
c = kernel.splitCurve(l_l, [psplit1])
kernel.synchronize()
# Print entities
entities = gm.getEntities()
for e in entities:
(edim, etag, ename) = dump_entity(e)
# Save the mesh to a file
gmsh.write("rectangle_split.msh")
# Finalize Gmsh
gmsh.finalize()
return