Exodus sizing function from python netcdf4

Hello,

I am new to Cubit (and Exodus) and I would like to be able to add a mesh sizing function to a Cubit generated exodus file. I was previously using the background mesh strategy in Gmsh, but have decided to move on.

Using the netCDF4 Python module, I am able to convert the file to a format I can use in my simulator. I would now like to add a sizing function back into the original exodus file.

According to this documentation, this needs to be a time-based (element or nodal) variable:
https://coreform.com/cubit_help/mesh_generation/adaptivity_and_sizing_functions/exodus2_field_function.htm

Are there any available examples for doing this? If I do a nodal array, does it just need to be the same dimension as the coordinates of the whole structure? If I do an element array, does it need to be the size of the block, or the total size of all the elements?

Regards,

Juan

This is what I have been able to come up with so far, but I have no insight if this format will be close to correct.
timedata.py (488 Bytes)

Welcome @js34654!

You can find comprehensive Exodus documentation on Sandia’s open-source repository for their SEACAS project, which owns the Exodus format. (SEACAS stands for: "Sandia Engineering Analysis Code Access System)

If you have access to Linux or Mac, you can build the SEACAS project, which will give you access to a few useful utilities utilities to convert Exodus to & from ASCII text (exotxt / txtexo), and to/from Matlab *.mat files ( exo2mat / mat2exo ). There are also extensive APIs for C, Fortran, and Python ( exodus.py ). You may find these tools useful for understanding & creating your Exodus file.

Of course, you could also use the meshio Python module to convert into Exodus from a format that’s more familiar to you.

I’ve attached two files to this email to help get you started with Exodus:

And here’s a script that will operate on those files to do sizing. Note that Cubit computes mesh size range by scaling the variable range to the min_size - max_size in the sizing command - small values result in smaller elements. This may seem counter-intuitive if you’ve used a stress variable as your sizing function as high positive values result in larger elements, while small numbers (large negative values if they exist) will correspond to the smallest elements. So I would recommend creating a custom scalar variable where you compute the sizing function.

reset
import step "/path/to/ASTM_E8-Round-1.step" heal
webcut volume all  with loop curve 1  
webcut volume all with loop curve 1  
webcut volume all with loop curve 4  
webcut volume all with loop curve 7  
webcut volume all  with loop curve 3  

imprint all
merge all

## Use Element Variable (Von Mises Stress) as sizing Function
#import sizing function "/path/to/params_out.e" block 1 variable "von_mises" time 1

## Use Nodal Variable (Z-Displacement) as sizing Function
import sizing function "/path/to/params_out.e" block 1 variable "disp_z" time 1

volume all sizing function type exodus min_size 1 max_size 10
mesh volume all

Sizing by Von Mises Stress


Sizing by Z-Displacement


Thanks for the files and links to the site. I am hoping the ncdump of params_out.e has all of the info I need. It looks like I just need to follow this format:

double vals_nod_var1(time_step, num_nodes) ;
double vals_nod_var2(time_step, num_nodes) ;
double vals_nod_var3(time_step, num_nodes) ;
char name_nod_var(num_nod_var, len_name) ;

and put the names in the name_node_var array and the values into the vals_nod_var*. And expand:

time_whole = 0, 1 ;

I was able to write a script to update a sizing variable, mytestvar, to the values of coordx.
test.py (558 Bytes)

@gvernon Thanks again for your help reverse engineering the format.

I am memorializing the numbering of the element sides here:
https://gsjaardema.github.io/seacas-docs/html/element_types.html#tet

if I need to do any sideset conversions for new elements.

@gvernon are the sizing function values the distance between nodes (edge length), or some other calculation?

Yes, it should be approximately the edge length. Recall, however, that the values are mapped to the range of (min_size, max_size) in the command.

Thanks for your response. So the appropriate strategy would be for me to put the desired node sizes in the time dependent variable, and not specify min_size and max_size on the sizing function statement? Is setting a growth factor in conjunction with the sizing function available?

Essentially, the time-dependent variable will store the relative sizes of the elements. Let’s say you have a 4-element 1-D mesh with the values of the sizing variable:

s = [42, 50, 88, 130]

and using the command

volume all sizing function type exodus min_size 1 max_size 10

Then the resulting element sizes would be:

element_size = [1, 1.8, 5.7, 10]

However, this may not be attainable if the geometry doesn’t permit this sizing (e.g. if the entire length of the curve is only 3 units). But this is my understanding of what the sizing function is trying to do.

So when I reload my .cub5 with my initial mesh, and try to remesh from the command line, it doesn’t seem to work. When I try it from the gui, it asks me about deleting the existing mesh and proceeding. Do I need to somehow delete the initial mesh before trying the sizing function?