Element Metrics and Histogram Tool

elemetric_histogramAs part of the core capability of EnSight to not only visualize, but analyze the domain and solution results, we have implemented the Element Metrics routines from Sandia Verdict Library (http://cubit.sandia.gov/public/documents/Verde_UG-2.5B.pdf). There are approximately 30 different element metrics that this routine will calculate for you, depending upon the grid types used. Again, we have implemented this function as a general purpose calculator function, as well wrap this fundamental capability with a Python-based macro to add further ease of use and end-user functionality. This macro is called “EleMetric_Histogram”, and performs the following on the selected parts in EnSight:

1. Determines the element types selected, and only calculates EleMetric quantities which apply.
2. Creates separate scalar variables for each Metric computed. Users can color by any of these variables, or further query where maximum or minimum values occur.
3. Determines a Histogram Distribution through the domain, and reports this to a text file (EleMetric_Histogram.txt) in the directory where your case is. This file is simple ascii, and can be inspected with any text editor.
4. An EnSight Query is generated for each Metric Histogram, so that you can visually graph the distribution of that Metric for the domain.

elemetrics_guiDouble clicking on this utility will launch the following short GUI for some basic user controls:
The first option allows the user to utilize the current selected parts only, or to calculate the variables for ALL parts in the model.
The histogram options provide the ability to control the number of bins for the histogram function, as well as where to write this information (text file and/or EnSight query registers).
The typical output to the text file should provide a nice overview of the variables computed, as well as quantification of the variable distribution in the domain.

The “EleMetric_Histogram.txt” file list all of the variables computed. If the minimum and maximum are the same, we simply report that. Else, the distribution is given as well:

txt_file_grab

In EnSight, the user now has access to the variable information computed, and can clip the domain (perhaps a crinkly clip would be best), and color the domain by the metric of interest:

image_quality1_lrg

 

The following link can be used to download the user defined tool for “EleMetric_Histogram”

Download here for elemetric_histogram

Current version is 3.0, dated 11-Feb-2014

Kevin Colburn, CEI

 

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

Texture mapping tool

This code enables a very simple and handy way of texture mapping. The code can handle pre-selected (multiple) parts or the user can select a single part within the script GUI. Additionally the mapping direction and the texture image must be chosen. Now click “Create” and the code will automatically grab the dimension of all selected parts and map the texture over the whole part surface. The GUI remains open so the user can rotate the plane tool for adjusting the texture.

http://pythonexchange.com/?attachment_id=816

Continue reading

Quick save a plot as an image

This simple script provides a fast way to save a singular plot as an image, with no other objects from the graphics window visible.

It provides a few options that need to be edited in the file (notably the image save path) and a few other options that are specified in a pop-up window. I think usage is fairly straight forward. If this script is used often, one will probably want to remove the pop-up window and set the options to the desired defaults inside the script. The script should work regardless of whatever else is visible in the graphics window, and should restore the view to it’s original state after running. Multiple viewports are supported, but the script may fail if the maximum allowed 16 viewports exit.

The saved images will be named after the Plot name. In a duplicate filename exists the new name will be modified (existing images will not be overwritten).

Added a toggle in the GUI to allow toggling the background color automatically using EnSight.

Download the script image_plot2.py (updated April 23, 2014)

Gradient textures for coloring with two variables

EnSight has the ability to color a single part by 2 different variables by using a bitmap texture. Each axis of the texture is assigned to one variable. A sample image is included with EnSight (dual_gradient.png in the cube data directory) which has one axis as color and the other axis as transparency. Sometimes the user may want to use different colors for each axis instead of transparency, but this requires having the texture to use.

This script uses EnVe to create a custom image for this purpose, by letting the user define the colors of the 4 corners of a 256×256 square, and interpolating the color values between them. It is a barebones script with little documentation, but is also short and simple to use. In this post is also an archive with a few images created with the script.

Images: gradient_textures.zip

Script: make_image_4_color_square.py

Below is a screenshot of the textures dialog, with the settings changed to the optimal settings for using gradient textures (in most cases).

Texture Mode: Decal or Replace

Repeat Mode: Clamp or Clamp to Texture

Interpolation: Nearest

Compute Texture Coordinates by: Variables

S Variable and T Variable: select 2 scalar variables. Ideally the range of these variables are between 0 and 1. Read the How To manual for more information.

Note that if your variable values var1 + var2 <= 1 (for example mass, volume, or mole fraction) then you will only use the bottom-left triangle half of the square.