Assigning blocks from coordiante range

Hello, I was wondering if there is an easy way to create blocks from a mesh using coordiantes so that I can assign multiple materials to the mesh. For example I have the following simple surface:

which I created using the following code:

lx = 10000.0
lz = 600.0
I1 = 500.0
W1 = 100.0

nPml = 3
elementSize = 25 # Mean element size in meters

cubit.cmd(‘reset’)

cubit.cmd(‘create surface rectangle width ‘+str(lx+nPmlelementSize)+’ height '+str(lz+nPmlelementSize)+’ yplane’) # Create a lx*lz rectangle
cubit.cmd('volume 1 move x ‘+str(lx/2.0)+’ z '+str(-lz/2.0)) # To get correct coordinates

cubit.cmd('surface 1 size '+str(elementsize))
cubit.cmd(‘mesh surface all’)

is there a simple way I can make blocks based on coordinates? I would like to assign divide this into 200 meter layers?

Also it is very important that I am able to do this using coordiantes, going forward I will need to be able to assign more complex materials based on coordinates (I am trying to build an earth model the materials for which is defined in a 3d array, ultimately I want to be able to assign materials based on coordinates so that I can simply take the closest material and assign it to the corresponding part of the mesh).

I really appreciate the assistance,

–Eric

Hi Eric,

Welcome to the forum. I typically create separate surfaces/volumes for different material groups. It help me keep things straight. If you choose to go that route, make sure you do an imprint and merge on the surfaces.

That said, you can also create blocks by adding quadrilateral faces specified by location. Create the block first and then add the faces.

create block 1
block 1 face with x_coord > 0 and x_coord < 1000

This will add all the faces with x-coordinate values between 0 and 1000 into block 1.

You should be able to see how to get that into python. Let me know if you need more help.

Karl

P.S. I’ve been proselytizing the use of f-strings in python 3. I find that the form

cubit.cmd( f’volume 1 move x {lx/2.0} z {-lz/2.0}’ )

is less typing and easier to read and maintain.

1 Like