Creating curved clips from splines

These are two related tools which create 2D curved “clips” from user-created splines. The tools do not create actual EnSight clip parts. Instead the final result is either an offset part (a type of elevated surface) or a second case with a single part and no variables. The “clip” geometry and mesh depend only on the splines, not on any parts.

Tool 1 – Curved clip from a single spline

splines

This will create a clip which is the shape of a spine extruded in a single direction.

Instructions

  1. Makes one or more splines
  2. Run the tool (if there is more than one spline the tool will ask you to select one)
  3. Set the extrusion distance and direction

The tool should run and a new part should be visible.

Options to set in the file before starting EnSight

grid_size – The clip mesh will be quad4 elements that are approximately square. The grid_size variable sets the desired length of one side of each element.
min_spline_points – In cases where the grid_size is too large relative to the length of the spline the number of elements could be very small. If the number of points along the spline is below the minimum specified here then the grid_size will be reduced to meet the minimum requirement.

Tool 2 – Curved clip from two splines

splines2

This will create a clip which is the shape of a spine extruded along the direction of a second spline.

Instructions

  1. Make two or more splines
  2. Run the tool
  3. Select the two splines to use (the order of the splines matters) and other options in the window

The tool should run and a new part should be visible. If there are critical errors a window should pop up with an error message. If the direction of the extrusion is in the wrong direction, invert the second spline and run the tool again.

Options to set in the file before starting EnSight

There are two methods the tool can use for creating clips.
1. The default is to write a new case file, load it in as a second case, and use CaseMap to color it by a variable. This method is much faster and more robust but it does require loading a second case. For that reason a second method is included.
2. Create a point part with triangle mesh, then use the point part to create an offset part. There are two sub-methods for how to create the point part. See below.

temp_file_type – chooses which method above to use.
‘case’ is for writing a new case file.
‘point’ is for creating a point part by writing a point part file.
‘none’ will create a point part without using a file.
grid_size – The grid_size variable sets the desired distance between neighboring nodes.
max_rectangles – (for ‘case’ only) If the given grid_size and spline lengths would result in more than max_rectangles then the grid_size will be increased.
max_triangles – (for ‘point’ and ‘none’ only) The tool can become prohibitively slow if there are too many triangles. The number depends on your hardware and OS but 10k triangles should take a few seconds, 100k triangles a few minutes. The time increase is faster than linear (i.e. n^2) so be careful how high you go. If the given grid_size and spline lengths would result in more than max_triangles then the grid_size will be increased.

Other

Creating point parts should be faster in 10.1.4a and later. Some text output is sent to the python tab.

spline_clip.zip (updated 2015-4-23)

Fluent Particle Data with Multiple Injections

Currently (up to at least Fluent 15), when you attempt to export multiple injections from Fluent to the EnSight format, each injection is written as its own set of Measured Data files **SEPARATELY**, with separate .encas files written.

The result is that if you were to attempt to load any of the separate .encas files into EnSight, you would only see particles from a single injection. You could perhaps load in the multiple .encas files as multiple cases, but this would perhaps multiply the amount of memory used, result in lots of extra parts, and is not a suggested method (although it might work for you).

Fluent are aware of this issue, and have been requested to correctly export multiple injections to a single set of Measured Data files. Their schedule for that improvement is currently unknown.

However, in the meantime, there is a potential work around for this. With a short python script, one can merge the various injections into a single set of measured data files, so that you can visualize all of the injections in a single case. In addition to merging the injections, the routine also creates one additional variable called “inj_id” for the injection ID. Thus, you can still analyze, interrogate, visualize separate injections within EnSight, even though it is contained within a single Measured Data Part.

The ptyhon routine does require a very minor edit, based on your particular dataset, variable export, and timesteps.

A short video tutorial on using this python utility (including the basic editing for your dataset) is provided below.

Tutorial Video on Handling Multiple Injection Particle Data from Fluent

Click here to Download the Python Utility

Smoke rendering for FDS

From the official site for FDS:

Fire Dynamics Simulator (FDS) is a large-eddy simulation (LES) code for low-speed flows, with an emphasis on smoke and heat transport from fires.

Smokeview (SMV) is a visualization program used to display the output of FDS and CFASTsimulations.

FDS+Evac is the evacuation simulation module for FDS.

These tools are open source and freely available.

FDS smoke 2

One use of FDS is simulation of visibility through smoke. The most realistic way to visualize smoke is volume rendering, which the default post processor Smokeview can do.

EnSight volume rendering color and transparency are customizable by the user, so they cannot be relied upon to accurately represent the visibility through smoke. The attached document and python script present a method which sets the volume rendering opacity in EnSight to accurately represent visibility. With minor modification the script also applies to any data that has a light extinction coefficient or optical density variable.

Analysis and python script.

A session file containing this dataset can be downloaded here.

Releasing Streamlines from Centroids of Elements

imgoutA request came in the other day to release streamlines from the centroids of all of the 2D elements of the selected parts. Now, EnSight, the default seed locations are from the nodes of the parts, not the centroids. However, this user would like to release from the centroids of the parts selected.

Python to rescue. We can utilize the Calculator Capability in EnSight to compute the X,Y,Z coordinates of the selected parts, and use the “NodeToElem” to convert those three scalar variable field values to be at the centroids of each element. With Elemental Values at the centroids of the parts, we use the FlatFile export with the “CELLID” parameter and ascii format to write out the elements of selected part(s) and their elemental variables to a text file. We can then just reformat this text file into a qualified “Particle Emitter File”. Voila. Within the standard streamline creation of EnSight, we can use a “Particle Emitter File” as the seed locations for the Streamlines, and therefore generate streamlines from the centroids of all elements in the selected part(s).

See below a short little Python Code to do this operation, as well as an image of what such a release would look like.

Python Utility to create Particle Emitter File from Centroids of Parts Selected

Converting Plot3D variables to dimensional variables

PLOT3D variables in EnSight are non-dimensional.  They are non-dimensionalized in a somewhat arcane calculation.  The density is scaled by the freestream density, the momentum is scaled by the product of the  freestream density and the speed of sound, and the Energy is scaled by the product of the freestream density and the speed of sound squared.

For those who don’t want to go through this calculation of dimensioned variables manually and want access to the engineering variables in consistent, user-selected units at a user-selected altitude from a PLOT3D calculation, this script calculates the extended plot3d variables in either SI or English units. This script uses the non-dimensional Plot3D Energy, Density, and Momentum variables in its calculation. This script is assumes Earth atmospheric data. So, it is not valid for calculations on Mars, nor is it valid for calculations in water.

If ‘Energy’, ‘Density’ and ‘Momentum’ all exist then the script will prompt the user for unit type (SI or English) and the altitude and then use a lookup table to find the corresponding variables in consistent units.  The code will then calculate a Density_true, Momentum_true, and Energy_true variables (which have consistent units for the user input)  and use those to calculate the extended CFD variables.

Click below to download the zipped EnSight Python Script

extended_cfd_with_units4.py

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 4.0, dated 23-Oct-2014, updated by Marina Galvagni.

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