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.

 

Vector length legend for vector arrows

This script requires some effort from the user and if used incorrectly it could lead to wrong or misleading information.

One of the EnSight created part types is a “Vector Arrow” part. The length of these arrows can be in proportional to the magnitude of the vector used to create them (the arrows can also be set to have uniform length). So the length of the arrows has definite meaning, but there is no ‘legend’ like the color palette legend which indicates what the length of a vector arrow means.

This script can create such a legend semi-automatically, but the legend is only accurate in certain situations. Since the arrows and the legend are in a 3D space, the direction the arrows are viewed from will affect how large the arrows appear. So I recommend using this legend only in certain situations such as:

  1. When all the arrows lay in a 2D plane, and they are viewed orthogonally with perspective view turned off (orthographic view mode)
  2. When the viewer can rotate the view, and therefore gauge the 3D scene and have an intuitive feeling about the distortion in size due to the viewer’s perspective

Example: The arrow length shows velocity while color indicates temperature.

The script performs a few simple steps:

  1. Create a single node using a point part
  2. Create a vector variable of unit magnitude on the node using MakeScalNode and MakeVect
  3. Create a vector arrow part on this node using this vector variable

The script will prompt you for the location and direction of the arrow. If desired, the location of the arrow can be changed by editing the point part. After the script runs the user should do two things:

  1. Adjust the arrow length by changing the scale factor of the Vector Arrow Legend part
  2. Create a text annotation indicating the meaning of the length of the reference arrow

One must be careful when scaling the legend arrow so that it represents the correct value. One could follow these steps:

  1. Adjust the scale factor of your vector arrow part(s) (not the legend part) to get the desired vector lengths. Call the scale factor “A”.
  2. Choose a vector value that you want the legend to represent, call this value “B”
  3. A * B = C, C is the scale factor you should use for the Vector Arrow Legend part (since the original vector magnitude is one). Now the legend arrow should be the same length in 3D space as an arrow that has vector value B.
  4. The text annotation should use the value B

Download the script. vector_legend.py

If you like the idea of a vector arrow length legend and would like to see it added as a standard feature of EnSight you can vote for it and other features at ideas.ceisoftware.com. Link to the arrow legend request

Assign Unique Node IDs

EnSight allows nodes and elements on different parts to have the same node ID numbers. For example it is perfectly fine to have a node #1 on every part even though those nodes are not the same node. In most cases EnSight provides a way to distinguish between these nodes, for example if you query a node ID, EnSight will query the node on the part(s) that you have selected.

However, there are a few somewhat uncommon situations when one does need unique node ID numbers. Two example are when using a Periodic Matchfile (for periodic boundaries), and when positioning the plane tool using 3 nodes.

This script will assign a unique node ID to every node in the geometry.

  • Run the script and select a .geo file
  • Requires the .geo file to be ascii (not binary)
  • Starts with node ID 1 and goes up from there
  • Ignores the current node IDs, accepts any type (none, assign, given)
  • Creates a new file with the old .geo name, and renames the original to “…_original.geo”

Possible enhancements (does not do this now):

  • Automatically convert all the .geo files in a transient simulation
  • Read and write binary .geo files
  • Change element IDs

Download the script. assign_unique_node_id.py

Create a plane part

This is a simple tool but it may come in handy. Sometimes you just want to create some simple geometry, and probably the most common geometry to make is a plane. EnSight has the capability to create points and mesh them in various ways. This capability is called point parts, but it is cumbersome to specify each point manually.

This tool uses the location of the plane tool to create a point part and mesh the points to create a surface. The resulting part is a plane at the exact size and location of the plane tool. The new part can be colored and textured as desired, but it will have no variable information.

Example: This tool used to create a road for the guard rail demo model.

Just plug and chug with this tool. Don’t try to modify a created plane, just delete it and make a new one. Use the tool repeatedly to create multiple planes.

Download tool and icon. (updated 2012-09-28)

create_plane_part.zip

Transform a vector or tensor

This tool transforms an existing vector or tensor variable into another reference frame which is specified by the user. Another way to describe it is that the tool rotates the variable. This was requested by a customer because they were interested in the components of vectors and tensors in arbitrary reference frames.

Note that the tool (as-is) does not rotate the variable along with the reference frame (the way EnSight frame mode will rotate objects attached to the frame). The variable is left unchanged, but it’s components are transformed to be in the basis of the new reference frame. For a vector, this is equivalent to taking the dot product of the vector with each of the 3 axes of the new coordinate system. This is also equivalent to rotating the vector in the opposite direction, which is how the vector will look if you visualize it in EnSight. If you would like the tool to rotate the vector WITH the reference frame then you can simply add “.transpose()” to the end of line 216, which transposes the rotation matrix and reverses the direction of rotation.

The new reference frame is determined using 3 points which are specified by the user. Point 1 is the origin of the new frame (the absolute location of this origin is irrelevant as no translations are performed). Point 2 is in the direction of X’, meaning the X’ axis is in the direction of a line from point 1 to point 2. Point 3 is the direction of Y’ (normal to the X’ axis). The image below shows a 2D representation. Points 1 and 2 determine the X’ axis, and point 3 determines the X’-Y’ plane, but Y’ does not necessarily pass through point 3.

These three points can be specified in two ways:

  1. If 3 or more query probes exist, the first 3 probes will be taken as the 3 points.
  2. If 2 or fewer probes exist, then a window will appear for the user to specify the XYZ locations of all 3 points.

The next step is to choose a variable to transform, and which parts to calculate the new variables on. All existing vectors and tensors will appear in the list of variables to select.

The script then runs. The user should see these results:

  • A new axis triad will be displayed (centered at (0,0,0)). The triad consists of three “3D arrow” annotations and they can be edited if desired.
  • Intermediate scalar variables will be created and placed in the group “p_scalars”. 3 scalars will be created for vectors, 18 for tensors. The scalars are needed for the calculation, and removing them (deactivating them) will also remove the final variable.
  • A new vector or tensor will be created with “_p” tagged to the end of the variable name. “p” here stands for “prime” meaning the primed coordinate system. When this variable is created the script is finished (there is no pop-up window indicating the script has completed running).

This tool was designed to meet the specifications of a single customer. Many aspects of how the script operates could be easily changed to make it more suitable for other users. For example, there could be a different way to define the rotation, or the tool could be made to rotate more than one variable at a time.

Limitations and warnings

  • By running the tool repeatedly, any number of vectors can be transformed but rotating a tensor will deactivate the previous tensor.
  • The accuracy of the transformation has not been extensively tested. If errors exist in the calculation they could occur for vectors only, or tensors only, or for both types.
  • EnSight 10 only. It could be adapted to EnSight 9 with little effort, if requested.

Download the tool and icon: (updated 2012-09-18)

transform_variable.zip

Data Translator for measured PIV data

Particle Image Velocimetry (PIV) is one way of experimentally measuring the velocity of a fluid. EnSight is highly suited for analysis of PIV results but there must be some way to load the data. One PIV data format is DaVis .vec or .ve7 which is an ascii file that is basically a comma-separated (.csv) file with one header line. The original data is a collection of points with defined XY position and velocity in X and Y directions. Using python I translated the .vec file to EnSight case gold format. I created a 2D part with a mesh instead of just a collection of data points so that more analysis could be performed.

Download the script Updated 2017-05-25

Previous version (2015-07-08)

Online documentation for this script.

The following images are from relative velocity measured for a rotating pump. Since the data is on a mesh, most CFD post processing techniques can be used.

(Above) Streamlines calculated with and colored by velocity.

(Above) Colored by vorticity, which was calculated in EnSight from the measured velocity.

Many other visualization techniques could also be used such as isosurfaces and elevated surfaces. Other uses might be to compare measured data vs. CFD side by side, or by directly calculating the difference. If using CFD data be careful to compare equivalent data. For example, the measured data has no information about the z component of the velocity. So if your simulation is 3D you must create a 2D velocity vector for comparison to experiment.

This translator is still fairly rough and the documentation is limited, so please contact me if you want to use it. Running the script will open a window to select a .vec file.

Update 4/2012: The script has been modified to work with DaVis 7 format. Also fixed one bug. My test data set is still very small, so if you experience a problem with the translator please send the data to me.

Update 8/2012: The script now has an option to create a transient case from multiple PIV files. It also now treats the data points as element centers instead of nodes of the mesh. Has better GUI for making selections, and reports on the success or failure of the translation.

Update 7/2015: Now handles DaVis 8 format. Also handles “,” (commas) when they are used for decimal points.

Update 5/2017: Can specify which axes to write out to instead of always writing to the X and Y axes. Now handles both spaces and tabs in DaVis 7 and 8 formats.

Color by element type

This one is for EnSight 10 only, folks. E10 has a new calculator function called EleMetric which has many features for mesh quality assessment. One function creates a scalar variable for each element which represents the type of element it is. Using this function one can color each element by element type. This tool is essentially a wrapper for EleMetric that adds some nice extras.

Download: color_by_element_type.zip (updated 2014-2-20)

Advantages of using this tool vs. manually coloring by EleMetric include:

  1. Automate simple steps: calculating the variable, naming the variable, coloring the parts, hiding the default legend, setting per-element variable coloring to discrete (palette option).
  2. Automatically sets the palette to the correct number of levels. One level for each element type.
  3. Gives consistent coloring of element types between sessions and using different datasets. For example triangles will always be colored light blue. Colors were chosen to contrast.
  4. Creation of a ‘legend’ consisting of text annotations that tell which element types each color refers to.
  5. Provides a note about the consequences of creating the variable on created parts vs. only on model parts. Also makes it easier to calculate only on model parts.


EnSight versions: 10.0+
OS: all

Show a multi-colored overlay mesh

This simple script will create the effect of a “hidden line’ display but with more coloring options than are normally available. The script does not do anything that cannot be done through the EnSight GUI but it does make it easier. Also, only fairly advanced users of EnSight would be aware that it is even possible. To use this script just set the view and part colors how you want them, then run the script as a UDT.

colored_mesh.zip (updated 2014-2-21)

Basically the script does these steps:
Part selection: Applies to selected and visible parts only. If no parts are selected it is applied to all visible parts. Only 2D parts and 3D parts in border representation are affected.
1. Creates copies of the original parts and colors these parts gray.
2. Creates a black ‘outline’ part by taking an extract of 2D parts (in border rep) and 3D parts (in feature angle rep). (Skips this step by default. Set “CREATE_EDGES = True” on line 24.)
3. Turns element shading of original parts off and sets line thickness to 2.

The effect is that the ‘hidden line’ display is show with the colors of the original parts, on top of gray shaded parts.

The script attempts to have a minimal effect on the original parts. To return to the original view just do steps:
1. Delete or hide the created copy and extract parts
2. Turn on part shading of the original parts

Asian Font Assistant

This tool displays samples of all the available fonts for a given language. It currently supports Japanese, Korean, and Chinese (simplified and traditional). Leave a comment if you would like support for additional languages.

Download the user defined tool with icon (updated 2011-8-22)

EnSight supports international languages in annotations, but this may not be immediately apparent to most users. This is partly because the default font does not support extended characters. Also, the font names are not recognizable to native speakers because the names have been romanized. This tool addresses both of those problems. It identifies all of the system fonts for a given language, then creates a text annotation for each font. The annotation contains both a sample of the language and the name of the font. So users can quickly see all of the fonts, select the ones they want, and be able to find it in the list of fonts.

Screenshot for simplified Chinese on an English system.

Usage

In order for EnSight to support extended characters, the operating system must be configured to use a correct encoding. In Windows 7 this setting is found in Control Panel -> Region and Language -> Advanced (tab) -> Language for non-Unicode programs. Ideally this should be set to the language you want to use, however some languages are compatible with others. If you use a non-extended characters set like English then you will not be able to view any languages that have extended characters.

You should see a GUI window with a language selector. If you encoding is the same as your desired language then select the language and click OK. If you have a different encoding then uncheck the box before clicking OK. Unchecking the box will bring up a second window where you can choose the encoding independently of the font language. For example, use this if you want to view Japanese text on a Chinese system. To do this select Japanese as the language, uncheck the box, then select Chinese encoding.

After you have made your selection, the script will start creating annotations. It will attempt to size and position the annotations appropriate to the number of fonts there are. However, some of the annotations may overlap and there may be some empty space. The script exits after all fonts have been handled. The annotations can be deleted manually, or by re-running the tool and selecting ‘delete all annotations’ as the language.

Screenshot for Japanese on a Japanese system.

EnSight versions: 9.2, 10.0
OS: Windows only

Find new parts

This function finds the new parts which are created when EnSight performs some part creation action. I discovered this gem inside skybox.py, which probably means Randy wrote it.

Download the script

 

Usage:

existing_parts = find_parts()
something_that_creates_parts()
new_parts = find_parts(existing_parts)
# you now have a list of all the parts created by something_that_creates_parts()

Code:

def find_parts(prev=None):
    l = ensight.query_parts(parts="all",client=1)
    out = []
    for i in l:
        out.append(i[0])
    if (prev):
        for i in prev:
            try:
                out.remove(i)
            except:
                pass
    return out

EnSight version: 9.1 and later
OS: all