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)

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.

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

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

Create Triangle Mesh

If you are faced with the problem that you have a hole in a surface EnSight has no powerful tool to fill it. Think about the radiator grille of a car. If one has the request to create a clip plane within the grille geometry to calculate the flow for example, the plane tool wont help in most cases as it’s rectangular and radiator grills are often not rectangular.

This tool can create a triangle meshes within a closed spline. If you campare the result with the meshing of a point part it has two big advantages:

1. The mesh elements are connected

2. Point parts along splines are meshed with one row of triangles. Here we have multiple rows. This enables calculation and coloring on the new mesh.

The spline geometry should be circular or elliptic and as flat as possible. Convex or concave geometries might cause problems. If the geometry is elliptic the first spline point should be at a pointed area (Think about the two ends of an egg). The scipt can use an existing spline or you can create a new one. If you select the option new spline, the GUI becomes interactive. Just click along the surface with the left mouse button and check how the spline points get created. There’s a control field of the current number of splines in the script GUI. If you want to get rid of one or more spline points, just use the delete button within the GUI. The spline can be open. The code will create a final spline point to close it. This will be done on existing splines and on new splines. Furthermore you can map an existing fluid variable to the new surface.

When the create button was pressed EnSight will create a new case and geometry file in the current working directory. These files are loaded as an additional case

 

 

 

 

 

 

 

The attached script is a stand alone tool. You can run it via File > Command > Play. Just contact me if you want to add it to your user tools.

triangle_mesh_2013_04_07

Dynamic Range Plotter

Suppose that you have a transient domain, where you have some information at a high temporal frequency, but your time domain is relatively large. If you make a default plotter, the temporal range is too large to see the high frequency information. But, if you zoom in the time range, you are “fixed” to a particular time. Suppose you’d like to see both the higher frequency information, but also the whole time domain?

Python to the rescue again. Using Python, we can dynamically adjust the time range of the graph at each timestep… and thus create a plotter with a relatively small time “window”, but that window moves with the current timestep, so that you can see the whole time domain.

Here is a short example of what such a “dyanmic range plotter” would look like:

dynamic_range_plotter

Here is a short tutorial on using this python tool:

http://www.ceisoftware.com/wp-content/uploads/screencasts/dynamic_range_plotter/dynamic_range_plotter.html

And here is the tool itself:

dynamic range plotter python

Particle Distribution Analysis

As a follow on to the Probability Density/Distribution Function for the continuous phase domain (link here), I have created a close cousin of this routine which works on Discrete Particles to determine a Particle Distribution of the Discrete Phase.

This routine was written with the intended use for Spray Distribution in an In-Cylinder model, and built according to the typical variables and techniques used for this modeling scheme. It is common to determine and understand what the distribution of the particular spray is within the domain over time (mass distribution vs. radius).  This routine asks the user for a variable to base the Distribution on (in this case droplet radius). The routine breaks this value down into N number of “bins” (in this case 20). For each bin, the routine calculates the total mass of the spray in that bin, and reports back out a distribution. The routine then walks the transient domain to collect this information over time, and generate extracted information vs. time.

In order to base the total in each bin on Mass, the user must prescribe three items : a) the droplet radius, b) the droplet density, and c) the number of droplet per parcel. In this instance, the actual Discrete/Particle data in EnSight represents one parcel of spray (all with the same physical properties).  Therefore, the mass is represented as (number_drop_parcel)*(particle_density)*(4/3*pi*r^3).

The GUI input for this routine is similar to the previous PDF macro for the continuous phase, with the addition of variable prescription needed for the mass calculation.

Based on this range, it then divides the volume into N number of IsoVolumes (number of bins) based on this variable range. The routine then determines the mass of the spray which is contained within each of these variable constrained ranges. The result is placed into a query register and automatically plotted on the screen.

The Tool presents the user with the simple Window to select the variable, and number of bins (or bars) for the distribution function, along with the three items needed to calculate the mass of the spray (radius, density, parcel count)

 

After executing, you will then get a graph of distribution of the variable within the parent part(s) selected.

The values on the graph should always sum to the total mass of spray in the domain.

Note: As users increase the number of bars( or bins) for the graph, the shape of the curve will increase in resolution, although values on the Y-axis of the graph will adjust.

This Tool can be downloaded from the link below. Please unzip the file and place both the Python Script and Icon PNG file into your UserDefinedTools area and restart EnSight. You should see a “PDF Particle Graph” icon available in your UDT area, and you can double click to execute.

 

 Video Tutorial:

Please view this video tutorial for a detailed walk through of using this tool for Spray Analysis.

Screencast Tutorial

Download:
Please use the following link to download the UserDefinedTool:

Click here to download Particle Distribution Tool