Selecting all curves that make up a single boundary using Python

Hi all,

Here’s the toy problem I’m working with:

I’m able to set up the geometry and construct the mesh using the attached Python script. However, one of the things which I’m trying to make more general is how the composite curve of the “blob” cutout is defined. Currently I have this set up to be

cubit.cmd(f"composite create curve all except 1 to 4")

since curves 1 to 4 in this case represent the outer boundaries of the square.

I’m trying to generalize this so that we can say something along the lines of:

cubit.cmd(f"composite create curve all except <OUTER BOUNDARY OF THE SQUARE>")

or

cubit.cmd(f"composite create curve all <BOUNDARY OF THE BLOB>")

Is there a nice way how one can iterate through the connected boundaries of a given surface to extract this information?

Here’s the full code in case you want to give it a go:

import cubit
import numpy as np

cubit.cmd("reset")

# Create an irregularly shaped blob with a lot of samples
n_pts = 2 ** 10 - 1
theta = np.linspace(0, 2 * np.pi, n_pts, endpoint=False)
r = 0.025 * np.sin(np.linspace(0, 16 * np.pi, n_pts, endpoint=False)) + 0.25

x = np.cos(theta) * r
y = np.sin(theta) * r

blob = np.vstack([x, y]).T

# Add a unit square
cubit.cmd("create surface rectangle width 1 height 1 zplane")

# Used for tracking the vert IDs in the blob
vertex_list = np.zeros(n_pts, dtype=int)

# Add the verts for the blob
for i, pt in enumerate(blob):
    cubit.cmd(f"create vertex {pt[0]} {pt[1]} 0.0")
    vertex_list[i] = cubit.get_last_id("vertex")

# Create the blob
verts = ""
for v in vertex_list:
    verts += str(v) + ", "
cubit.cmd(f"create surface vertex {verts[:-2]}")

# Boolean surfaces
cubit.cmd("subtract surface 2 from surface 1")

# Create composite curve of the blob
cubit.cmd("composite create curve all except 1 to 4")

# Create the mesh
cubit.cmd("surface all scheme pave")
cubit.cmd("surface all size 0.01")
cubit.cmd("surface all sizing function constant")
cubit.cmd("mesh surface all")

Thanks a lot for your help :slight_smile:

All the best,
Pat

Hi Pat,

There are a couple of ways that I can think of doing this. If all the curves in the blob are smaller than the bounding curves, you could use a with length attribute.

cubit.cmd("composite create curve with length < .002")

Another way would require finding the id of at least one curve in the blob and using the include continuous qualifier

# After the boolean get the curve created
last_curve = cubit.get_last_id("curve")

cubit.cmd(f"composite create curve {last_curve} include continuous")

I would also recommend surrounding the script in a

cubit.cmd("undo off")
.
.
cubit.cmd("undo on")

pair to speed up your processing.

Hope this helps,
Karl

Hi Karl,

That’s awesome, the include continuous qualifier is exactly what I was looking for.

Thanks so much for your help and have a great rest of your day!

All the best,
Pat