Extracting Global Element ID (instead of Hex number)

Is there any way to efficiently extract global element id of elements?

Getting hex number associated with an element is straightforward, but getting the global element id of a group of elements is not trivial. Adding them to group will only add them as hex numbers instead of global element id. So now, in order to get global element id of elements, I’d add to select each element one at a time and list its information.

Global element id of elements are useful because they relate to actual FEM analysis.

Thanks.

You can use the get_global_element_id functions for this. Open your Journal Editor and click the Python button on the toolbar. Paste the following:

cubit.cmd(‘reset’)
cubit.cmd(‘bri x 1’)
cubit.cmd(‘vol 1 int 2’)
cubit.cmd(‘mesh vol 1’)
cubit.cmd(‘block 1 vol all’)

Add this code to use the get_global_element_id function. I used a variable ‘element_type’ to specify hex elements.

element_type = ‘hex’
element_id_list = cubit.parse_cubit_list(element_type, ‘all’)
for element_id in element_id_list:
global_element_id = cubit.get_global_element_id(element_type, element_id)
print “Element ID: {0}, Global ID: {1}”.format(element_id, global_element_id)

(The indentation doesn’t work right in the forum post. You will need to indent the two lines after the for statement.)

Or, you can use the get_hex_global_element_id function:

hex_id_list = cubit.parse_cubit_list(‘hex’, ‘all’)
for hex_id in hex_id_list:
global_hex_id = cubit.get_hex_global_element_id(hex_id)
print “Hex ID: {0}, Global ID: {1}”.format(hex_id, global_hex_id)

(The indentation doesn’t work right in the forum post. You will need to indent the two lines after the for statement.)

Other functions can be found under Mesh Element Queries here:

csimsoft.com/help/appendix/pyth … erface.htm

I tried the reply and it work. But now I’m trying to get the global id for a selected list or group of hex?

I want to:

  1. Create a list of hex id (here I was hoping I can choose whichever hex I want to put into this list); for example, all the hex at the boundary etc.
  2. Use this list and then the post python script to loop through this hex_id_list and print out the corresponding Global_Element_ID.

Thanks

You could use the extended parsing expression "in face in surface in volume " to specify which hexes you include. For example, run this journal file:

reset
bri x 1
mesh vol 1
block 1 hex in face in surface in volume 1
graphics clip on direction 1 0 -2
draw block 1

You should see only the hexes around the boundary of the cube. When adding hexes to Block 1, using the expression “hex in face in surface in volume 1” will only add the hexes that have a face in the surfaces of volume 1.

In the previous example where we got the global element ids, you could get the list of hexes on the border using:

hex_id_list = cubit.parse_cubit_list(‘hex’, ‘in face in surface in volume 1’)

Hi,

Thanks for the tip; it worked. Is there an option to instead of exporting/showing onto the Trelis command window, the result (element ID) exported to a external text file?

Thanks,

I would use Python to export the ID list to a file, something like this:

hex_id_list = cubit.parse_cubit_list(‘hex’, ‘in face in surface in volume 1’)
f = open(‘exportHexIDList.txt’, ‘w’)
f.write(repr(hex_id_list))
f.close()

Or formatted somehow:

hex_id_list = cubit.parse_cubit_list(‘hex’, ‘in face in surface in volume 1’)
f = open(‘exportHexIDList.txt’, ‘w’)
for hex_id in hex_id_list:
f.write(“Hex ID: {0}\n”.format(hex_id))
f.close()

This file can be run from the Journal Editor.
ExportHexIDList.py (402 Bytes)

Hi,

So I tried using that script but I get the following errors like the text I want to open and write on Permission is denied. See below:
Traceback (most recent call last):
File “”, line 2, in
IOError: [Errno 13] Permission denied: ‘exportHexIDList.txt’
Trelis>
Traceback (most recent call last):
File “”, line 3, in
NameError: name ‘f’ is not defined
Trelis>
Traceback (most recent call last):
File “”, line 4, in
NameError: name ‘f’ is not defined

May you help me resolve this?

Thanks