Exporting variable values on a grid

This was made for a specific customer request. It exports variable values that lay on a specified grid of points over an X-Y plane. It saves these values for all time steps. Download: probe_values_XY_export.zip

flow2d_probes

The default settings work with the flow2d data and save to a .csv file.

This was also my first venture with PyQt. These lines of code pop up a confirm file overwrite window if the target save file already exists:

q = PyQt4.QtGui.QMessageBox()
q.setWindowTitle(“File already exists”)
q.setText(“The file “+filename+” already exists.\nDo you want to overwrite the existing file?”)
q.setIcon(PyQt4.QtGui.QMessageBox.Warning)
q.addButton(“Cancel”,PyQt4.QtGui.QMessageBox.RejectRole)
q.addButton(“Overwrite”,PyQt4.QtGui.QMessageBox.YesRole)
ret = q.exec_()

I didn’t make my own class to do it, but QMessageBox is already a class so I don’t see why my own class would be better for a simple case like this. The setWindowTitle method doesn’t seem to work for me though (the window has no title). Making it a function would have been cleaner but this was just a quick script.

Prepare cube tool for a skybox

Here is a very short script that prepares the cube tool to make a skybox. Just change the numbers in the first 2 lines and go. Then create the skybox manually.

skbox_size=1000
skbox_center=[0,0,0]
ensight.tools.box(“ON”)
ensight.view_transf.function(“box”)
ensight.view_transf.box_length(skbox_size,skbox_size,skbox_size)
ensight.view_transf.box_origin(-skbox_size/2+skbox_center[0],-skbox_size/2+skbox_center[1],-skbox_size/2+skbox_center[2])
ensight.view.highlight_parts(“OFF”)
ensight.tools.box(“OFF”)

Moving car animation

This script assists in creating an animation with frame mode. It makes the car appear to move and wheel spin at a rate that matches the car’s speed. It can do constant speed as well as constant acceleration and deceleration.

First create 3 frames (ground and background, front wheels, rear wheels) and assign them to the parts. Then adjust the settings at the beginning of the script. The car will stay stationary while the ground moves in the opposite direction to give the appearance of motion.

Download: drive_car.py

Transient animation update palette range

Problem statement: EnSight has an option for setting the variable palette range to what is visible in a given viewport or to selected parts. However there is no option to update to these ranges automatically when time changes.

Value proposition: These are two scripts for updating the palette range automatically. One script adds a time callback, but this is only called when changing solution time in the GUI. It is not called for transient flipbooks, keyframes, or when saving a solution time animation. So the other script uses EnVe to save a solution time animation. Neither script works with flipbook or keyframe.

Script 1: Time callback update palette range

This works by remembering the selected parts when the script is run and using their min/max range. If the variable used to color the first part (of the selected parts) is changed then the new variable will update instead of the old one. You can add multiple independent callbacks by running the script again (each run creates a new instance of the class). The user should not need to edit the script, just select parts and run. There is some output in the python tab.

Download: time_callback_update_palette_range.zip

Script 2: Transient update palette

A very basic script that creates a single transient movie. All the settings are near the beginning of the script. Only a few lines of code update the palette range, and these could easily be changed to perform different actions every time step. So this is also a template for saving any transient animation with changes each time step.

Download: transient_update_palette.zip

Calculate percent volume/area/length

For users who want to calculate the % or fraction of a part which has variable values within a certain range. This is fairly easy to do manually in EnSight but requires some knowledge and can give false answers if parent parts have mixed dimensions. This routine automates the steps:

  1. create an isovolume
  2. calculate the volume, area, or length of the isovolume and parent part(s)
  3. divide the isovolume by parent to get fraction (x100 for %)

In addition to automating, the script also checks for the existence of mixed element dimensions in the selected parts. If there is more than one dimensionality (1D, 2D, 3D) of elements then the script aborts. If only one type exists then the script chooses the correct calculator function for that dimension and names the constant variables accordingly.

The options are set by 3 variables at the beginning of the script. Just variable, isovolume by high/low/band, and the iso values. Multiple values can be specified to create multiple isos.

This is really just the bare beginnings and there is certainly a lot more that can be done. GUI, error reporting, creating annotations, more options, command language, extension class.

After you have run this script you will have a Vol_percent_1 variable which represents the isovolume fraction % of total.  Now select the isovolume part and double click on the Tools icon at the top, and go into the Analyze folder and run the Part Constant Query tool. Choose the Vol_percent_1 constant variable.  Now you have a nice plot from sweeping the max isovolume from min to max.

Vol_vs_var

 

Download script: percent_area.zip

Logo annotation helper

Problem statement: Most EnSight graphics and annotations will resize automatically with the graphics window or output image size, however, the logo annotation does not. Also, the location of the logo is fixed by the bottom-left corner, which means it won’t stay fixed in the upper-right corner when the resolution changes.

Value proposition: This tools makes it easy to set the logo size, aspect ratio, and location in ways useful for image and animation output.

The current state of this python is a script with a simple GUI. It is unfinished but in a usable state and lacking documentation. The GUI options are a bit long and confusing at first.

Download the script: logo_helper.zip