Question and Answer session from Powered by Python” webinar

Q: Can we get the recorded session?

A: Yes, this will be posted on YouTube afterwards.
A: Here’s the link to the YouTube video: https://www.youtube.com/watch?v=2TCPPO8z5VA

Q: Will the script used here be made available to attendees?

A: Yes, some of them will require permission for release. A link to the scripts will be included with the YouTube presentation of the webinar.

Q: Sharing the python scripts used today would be a great help in building that comfort level in using python

A: Yes! Will do.
A: The scripts and related files have been uploaded to Zenodo: http://doi.org/10.5281/zenodo.4671051 – be sure to read the README.md!

Q:: Installing Modules by hand is not needed if I run an Anaconda install?

A: The Coreform Cubit GUI is using its own installed python. If you want to use the features from the GUI, you must change the version of python in Coreform Cubit and not the system python. If you are importing cubit into a python session, you can use the system version if the python versions match.

Q: Can I use a Python-IDE alternative to the cubit python interface?

A: Yes. If you import cubit into python you can use it in any IDE you wish. The Cubit GUI only has the one interface.

Q: How do the coordinate axes appear alongside the volumes?

A: Click in the graphics window to give it focus. Then hit the ‘s’ key. This is the scale function to give an idea of the model size.

Q: Is there any way to get the ID of the new entity created by the command in python(e.g. a volume, surface, curve)? Asking because that ID could be used by the following commands to apply modifications without the need of filtering and parsing all of them.

A:: There are a few creation functions that pass back a python object. They are limited to geometry primitives. You can get the Id with the object.

Q: Forgot to mention, last ID in not enough sometimes because multiple entities are created. return the output of cubit command through the python API as a string would be enough.

A: You can get the ID of the last generated object with get_last_id(entity_type_string) If I am issuing a command that will create many objects, I will get the number of objects that existed prior to the command and the number of objects after the command. IDs are sequentially generated. So, I can use the last generated id and the number of generated objects to find the ids of the generated set.

A: Here’s an example of what Karl is talking about - this is what I do in my Cubit-Python scripts

def get_last_ids():
	body_id = cubit.get_last_id("body")
	volume_id = cubit.get_last_id("volume")
	surface_id = cubit.get_last_id("surface")
	curve_id = cubit.get_last_id("curve")
	vertex_id = cubit.get_last_id("vertex")
	return body_id, volume_id, surface_id, curve_id, vertex_id

def get_entity_list_from_range(entity_type, range_min, range_max):
	entity_list = cubit.parse_cubit_list(entity_type, "{} to {}".format(range_min, range_max))
	return entity_list

### Get the last ID's of the previously existing entities
body_id_old, volume_id_old, surface_id_old, curve_id_old, vertex_id_old = get_last_ids()
####### Do geometry operations here… ####### 
### Get the last ID's after geometric operations
body_id_new, volume_id_new, surface_id_new, curve_id_new, vertex_id_new = get_last_ids()
### Extract the actual ID's that exist within the range of entity IDs
new_bodies = get_entity_list_from_range(“body”, body_id_old+1, body_id_new+1)

Q: Is that possible to define as python interpreter for Cubit, the Anaconda distribution (taking advantage of ecosystem of packages already installed)?

A: From the GUI no. By importing cubit into python, yes if the versions match.

Q: Is there a way to create an entity like surface/cube using python but the cmd package? Something along the lines of cubit.brick(x=10,y=5,z=1)

A: Yes, most of the geometry primitives can be created this way. For example,

    b = cubit.brick(depth=2, height=4, width=1)
    print( b.id() )

However, most commands are only available with the cubit.cmd() function.
A: Additionally, we highly recommend that any commands that create, modify, or remove entities (geometry, mesh, sets, groups, etc) that users use the cubit.cmd() function for maximum stability.

Q: Is it possible to perform automatic adaptive re-meshing (adaptive to the computed stress field distribution, for example) using Python scripting? Is there such an example, if so?

A: We do not have an example. I would extract the stress field and create an exodus sizing function from that. Use the exodus sizing function to remesh the model.

Q: Do the random cubit.cmd(…) command return the number of created entities? or just some python API functions? Asking because I use a lot cubit.cmd() functionality.

A: No, the cubit.cmd() function doesn’t return anything but the status of the command execution.

Q: Would be really nice return the console output as a string. That string will contain all the info I need. Do you have a wish list website where I can drop this request? (I am not the only one that would love having this functionality)

A: we welcome any feature requests at forum.coreform.com!

Q: Did you have Cubit installed on the Ubuntu WSL?

A: Last time I checked; graphics windows were not working in WSL. We have not tested against Ubuntu WSL.
A: Yes! I installed Coreform Cubit on my Ubuntu WSL. I’ve done this for both WSL 1 and WSL 2. While you can get graphics, it is a bit hacky with the current WSL versions and I don’t recommend using graphics on the WSL instance until WSL has better graphics support (which I think is coming).

Q: Does Cubit work with Ansys or Abaqus as the FEA solver?

A: We have an Abaqus exporter that is well supported. We also have an Ansys exporter. I would say the that the Abaqus exporter is more complete than the Ansys exporter. There will be some features in both analysis packages that we do not fully support.

Q: Will we ever see python cubit on PyPi :slight_smile:

A: Probably not. Cubit depends on some proprietary libraries such as ACIS. There would likely be some difficulties distributing Cubit because of the licensing agreements.

Q: Can I get an example code mesh that use python to mesh a model (solid, shell, …) thanks!

A: The easiest way to start with that is to use the Cubit command language. Each of the following commands could be wrapped with cubit.cmd() to execute them in python.

The following commands will build a block with a hole through it, mesh it with a hexahedral mesh and create solid elements and shell elements for export.

Brick x 10
Cylinder radius 2 z 12
Subtract vol 2 from 1
Mesh volume 1
Block 1 volume 1 # create a group of solid elements.
Block 1 element type HEX8
Block 2 surface all # create a group of surface elements.
Block 2 element type SHELL4
Export abaqus ‘hexes.inp’ block 1
Export lsdyna ‘shells.k’ block 2
1 Like