Using Python to find free vertices inside, outside, on vol

Use Python to determine if a free vertex is inside, outside, or on a volume. (See … erface.htm for more information about using Python in Trelis)

The example creates a brick and three vertices, one inside, one outside, and one on the volume.

cubit.cmd(“bri x 10”)
cubit.cmd(“create vert 0 0 0”)
cubit.cmd(“create vert 5 0 0”)
cubit.cmd(“create vert 6 0 0”)

my_vol = cubit.volume(1)
vert1 = cubit.vertex(9)
vert2 = cubit.vertex(10)
vert3 = cubit.vertex(11)

We only expect one body to be in this, but note that it is a tuple

vol_bodies = my_vol.bodies()
my_body = vol_bodies[0]

print my_body.point_containment(vert1.coordinates())
print my_body.point_containment(vert2.coordinates())
print my_body.point_containment(vert3.coordinates())

A value of 0 means outside, 1 means inside, 2 means on the volume.

Continuing on this example, below is a script that will find all the nodes that fall inside an interior, unmeshed volume within a larger, encompassing external volume and group the nodes as a Node Set. Similarly, the script will group all elements that fall inside or intersect with the internal volume into a Block.

cubit.cmd(“bri x 10”)
cubit.cmd(“bri x 5”)
cubit.cmd(“volume 1 scheme Tetmesh”)
cubit.cmd(“volume 1 size auto factor 5”)
cubit.cmd(“mesh vol 1”) # Note that only the volume 1 is meshed, not volume 2

Get element inside the internal volume (3 here)

my_vol = cubit.volume(3)
vol_bodies = my_vol.bodies()
int_body = vol_bodies[0]
nodes_in_body =
elements_in_body =
vol1_elements = cubit.parse_cubit_list(“tet”, “in volume 1”)

Loop over all tets in the volume

for tet_id in vol1_elements:
interior_tet = False
tet_nodes = cubit.parse_cubit_list(“node”, "in tet "+str(tet_id))

Loop over the four nodes of the tet

for node_id in tet_nodes:
node_coord = cubit.get_nodal_coordinates(node_id)
result = int_body.point_containment(node_coord)
# 1: inside; 2: on the boudary
if result == 1 or result == 2:
interior_tet = True
if node_id not in nodes_in_body:
if interior_tet:

print “Nodes in Internal Body: {}”.format(nodes_in_body)
print “Elements in Internal Body: {}”.format(elements_in_body)
cubit.cmd("nodeset 1 add node " + " ".join(str(e) for e in nodes_in_body))
cubit.cmd("block 1 add tet " + " ".join(str(e) for e in elements_in_body))