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

Droplet Claculation Tool

In addition to the Droplet Histogram Tool I was asked for a routine that calculates the penetration depth and the injection cone angle of droplets. The attached tool does these two things. When launched a small GUI pops up which asks the user for the measured particle data, the time step for calculation and the percentage of droplets within the calculated cone angle. The default value here is 80%. With this value the routine tends to stop at a cone angle which comes close to the groplet injection geometry.

 

This routine is written as a user defined tool. If you have an existing directory for your own tools just put it together with the image into that directory. Otherwise it can be used as a standalone tool as well if line 360 is activated. Please contact me if you have any problems (david@ceisoftware.com).

 

download

 

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

Droplet Histogram Tool

I was asked by two customers at the same time if we have a histogram function for droplets or measured parts. In EnSight we can create histograms by looping an isovolume over a 3D part and query the attributes of that isovolume in every loop step. As droplets don’t have a volume this approach will fail.

For droplets we can use EnSight’s capability of exporting geometries. This new routine does that and gets all information from the exported files. The geometry will be exported to the temp file of the operating system. After finishing the script removes all temporary data.

One thing that is typical for droplets is the fact that they usually appear in transient files. Thus this code enables the user to select the time steps to export. By default histogram results for all time steps will be exported. Furthermore the user has to select the desired variable for the histogram. Also the number of value steps has to be selected. This number will define the refinement of the results.

As we usually handle transient files, this routine does not create a x-y plot. This would be unhandy fo several time steps. The results will be written to a text file in two columns. By default this file will be in the working directory and is called histogram_data_pairs.txt.

This routine is written as a user defined tool. If you have an existing directory for your own tools just put it together with the image into that directory. Otherwise it can be used as a standalone tool as well if line 270 is activated. Please contact me if you have any problems (david@ceisoftware.com).

download

Custom Image Save Shortcut

A customer recently asked if a more custom save image could be created. He always wants to use the “Default Print Colors”, and always wants to save out a certain image type and size. His main concern was always having to toggle on the “default print colors”, (as they are turned off after the image is saved), and the 6 mouse clicks/operations to save an image (File (1), Export(2), Image (3), specify filename (4), Default Print colors (5), and Ok (6)).

One option is to use the right Click (Right Click to Viewport — > default print colors), the Right Click again to Save image to file, then specify file name, and Ok. These are perfectly okay when saving a few images, but having to save 20 or 30 images, and you would want to look for a shortcut way to do this.

With EnSight’s scripting, and two lines of python, this can be made into a nice short macro, which would do the above steps in a single keystroke.

Here is the python macro (you can directly assign this to any of your favorite keyboard short cuts):

# Example Python to Create new Output image
import datetime
Basename = "EnSight_Image_"

# Use datetime to generate a filename with unique name
now = datetime.datetime.now()
unique_part = now.strftime("%Y-%m-%d_%H-%M-%S")
new_filename = str(Basename) + str(unique_part)

# Save the image
ensight.file.image_format("png")
ensight.anim_recorders.render_offscreen("ON")
ensight.file.image_numpasses(4)
ensight.file.image_stereo("current")
ensight.file.image_screen_tiling(1,1)
ensight.file.image_file(new_filename)
ensight.file.image_convert("ON")
ensight.file.image_window_size("HD1080p")
ensight.file.save_image()
ensight.file.image_convert("OFF")

 

Here, the three lines of python obtain the current time, and append that to the name “EnSight_Image_” in order to create a unique filename to be saved. The remaining lines in the file are direct EnSight journal commands converted to Python. Note here the use of the “image_convert” lines which do the operation of the default print colors.

So, with only three lines of python, you now can take the journal commands from a file save and make them into a quick shortcut to save an image out.

Right click data access

An annoying problem I saw quite often in doing support or training classes was to access the EnSight installation data sets. Usually the way to open one of the models is:

File -> Open -> Navigate to $CEI_HOME$/ensightxx/data -> select parts to load

Really exhausting if you have to do this 20 times in a single training class day. Using the ‘Open recent data file’ menu point was no really solution for me as EnSight will always ask you if you want to replace your current data. Too many clicks for me. I have written a routine which creates a background right click menu enhancement. Please find the linked routine. If you run that routine it will search for the hard drive location

$HOMEDRIVE$/$HOMEPATH$/.ensightXX/extensions/user_defined/examples.

The routine will create every directory level if the path could not be not found. However it won’t overwrite existing directories so you can run it if you already have defined some functions at that directory. As soon as the routine has created the new file called training_rightclick_background.py it will exit EnSight. Restart it to use the new right click enhancement.

The enhacement includes a quick tool access and hide function, which can be useful for quadric tools. Furthermore we can delete all currently loaded cases and we can find an option ‘Open Data’. Here the user can access all models which are automatically installed with EnSight. If the user selects oen model or clicks on ‘Delete data’, EnSight will immediately replce all current cases without asking. So this is a very quick way to open the file you need for demonstrating any EnSight functions.

 

 

 

 

 

 

 

 

 

download

 

 

Command File translator to EnSight 10

Hi folks,

as the grouping syntax has changed in EnSight 10 I’m sure many users will be faced with the problem that their old command files might fail if they do an upgrade to the latest EnSight version. We have some users with large scripts that include grouping operations so I started to think about a solution for this issue. Attached is the latest version which is still not completely finished but it seems to work fine on most command files I have used for testing. Please feel free to run the routine on your own command files and let me know if it crashes or if EnSight 10 fails on playing the translated files.

The only way I saw to get all necessary part and group info was to replay the original command files. So the original data files must be located at the directory which is included in the command file. The script will create a temporary .enc file and a .py file so the user must have writing permissions to his working directory. To start the script, please navigate to the saving path of your command files and run it with EnSight 9. The script will automatically search all .enc and .cmd files in that directory. If the routine failes on any of the found files for a reason it will create a short output message instead of translating the original command file. The translated files will be written to a new directory in the working directory witch will be named as currentyear_currentmonth_currentday_ensight10_command_files.

David

 

Download the latest update (June 2012) here.

2012_06_01_translate_9x_grouping_command_files

Tool and Script to Plot Probe Values on a Graph

An interesting request came in today: Can I plot the values from my interactive query probe in a graph?

Good question. Currently, you can see the values reported next to the query probe in the viewport, and you can click on “display values” to get a window pop up with the values in tabular form. But, you can’t populate a Query for a Plotter and get a graph of the values.

Python to the rescue again. Through python, you have direct access to a list of those Interactive Probe Queries and their values. With that information, we can utilize Python to populate those values into a Query Register and make a Plotter (or graph) of them.

This small Python macro will create 4 queries actually: one for X coordinate vs Variable; one for Y coordinate vs. Variable, one for Z Coordinate vs. Variable; and one of Distance (from first probe) vs. Variable. The default plot is chosen as “Distance Vs. Variable”. However, the user can easily drag any of the other 3 queries into the plotter (or make their own plotter) in EnSight. Here is what it looks like when I have 6 probe values:

You can see that you have 4 queries generated, and 1 plotter.

Download the following python and setup as a macro perhaps (assign it to a memorable keystroke sequence) and be able to quickly and easily plot the values from your multiple interactive probes…. Voila.

Python Code for Plotting Probes

Another option is a python tool that will do this.

 

query_probe_example

 

 

 

 

 

Multiple Variable Constraints (Venn Diagram)

EnSight’s capability to utilize multiple variables at once is very powerful. Coloring by multiple variables at once on the same part can be very powerful visual aspect to understanding the relationship of various variables at once. One variant of this is to allow the user to specify multiple variables as set of constraints so that the user can visualize a portion of the domain which has been restricted by multiple variables. For example, I would like see the portion of the domain which has Temperature between 290 and 310, and Density between 0.9 and 1.05, and a Velocity from 10 to 15…. and so forth. Basically, the user would like to build a Venn Diagram of the common constraints from multiple variables at once.

Well, enter in Python + EnSight again. Here, we utilize EnSight’s ability to create an IsoVolume (a region constrained by a range of a single variable), along with the ability in Python to loop through this constrain N times, as well as present the user with a new little GUI to specify the constraints. In this short example, I have coded up to 6 constraining variables at once. Each variable gets constrained as an IsoVolume, with the subsequent constraint using the previous IsoVolume as its parent. Voila.

Capitalizing on some of the benefits of EnSight’s dependancy tree structure, you can adjust any of the constraint variables or ranges after the fact, and the whole Venn Diagram Region is automatically updated. Each IsoVolume is now also labeled with the initial variable and range used to create it, so the user can go back through and understand the different constraints.

Here is what the tool in place looks like:

You can download the Python Tool and install it into your UserDefinedTool area:

Download Python Multiple Constraint Tool

Please provide comments back for issue you find, additional capability you’d like, or adjusts which would make this more useful for your implementation.

 

Pipe centerline routine

As many of you know I’ve been working on the pipe centerline routine in the past. Today it’s running well on most geometries so it’s time to share it.

If you already know older versions, you will see that some changes have been made. One thing is that the the routine can be used as a User Defined tool now. If you want to use it that way, please delete the expression run(0), currently in line 693. Copy the routine and the thumbnail to ~/.ensight92/extensions/user_defined/Tools and restart EnSight. Now you should see the thumbnail and the tool description in the UDT dialog. Starting the routine will launch the GUI where you can make your settings.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The GUI changes dynamically, depending on the selectid parts and the settings. For running the script, please select the wall part (this should be the pipe with the desired center spline), an inlet and an outlet. The order of inlet and outlet part is not important. If the pie has no parallel sections you can allow EnSight to generate infinite clips. If there are parallel sections do not allow that. EnSight will then generate a finite pipe clip with the plane tool. The diameter of the plane tool is the twice of the inlet part diameter by default. Modify this setting if the pipe diameter varies.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

The step delta controls the moving steps of the plane tool. This value is calculated automatically, depending on the selected wall part. This value should fit for most situations. Only modify it if the spline result is not satisfying. The script should generate a coaxial spline for the pipe geometry. If you are not satisfied with the result please play with the settings or contact me.

 

 

 

 

 

 

 

 

The script can be downloaded here:

pipe_centerline_tool_PyQt_2011_09_29

The thumbnail: