Exporting Data for Boundary Condition Input

An Engineer’s tasks is never a single input/output process. In most all problem solving situations, the engineer needs to use the tools available to “navigate the road” from problem statement to an end solution/conclusion. The exports from one tool are typically the input the next… from CAD to Grid Generation, from Grid Generation to Solver, etc. With EnSight’s flexible output capability, along with a little python knowledge, users can take the output from EnSight and construct the input/boundary condition deck for the next solver.

In this particular example, EnSight was used to analyze the results from a Discrete Element Model to visualize and analyze the forces on the surface of the DEM model. However, the next step in the engineer’s process is to take these forces and use them as a boundary condition for the particular stress solver, to resolve the deformations, stresses, and load paths as a result of these particles. Well, EnSight + Python can help here too.

Within EnSight, we read in the DEM solution, and interrogated the forces on the surface of the DEM model. We used EnSight’s capability to read in multiple models to read in a second case containing just the grid for the stress analysis. We used EnSight’s CaseMap function to map the forces from the DEM model onto the stress analysis grid.  From here, we exported the stress analysis grid (and its new force values) out of EnSight to the EnSight Case Gold format. Here is where python comes in to help us out. We need to reformat this data into a form that the stress analysis package can interpret as boundary condition information. The following python code takes the EnSight Case Gold format geometry file, along with the exported Force Vector information and generated a new input deck containing the boundary condition information for the stress analysis solver. I’ve tried to keep the code simple enough so that you can edit and customize this for your particular data, solver, and situation.

Convert Export to Boundary Condition. (remember you can run this python outside of EnSight by typing : cpython22 conv_bcs.py

EnSight Version 9.2.2; 10.0

Python float to C-standard string

import os
#
#    This routine converts a float value to a % 12.5e  string with two places for the exponent.
#      Microsoft has decided to defy the C Standards and write out three values in the
#        exponent [-]m.ddddde+xxx  rather than only two per the C STANDARD [-]m.ddddde+xx
#
def float_to_exponent_string(float_val):
    # converts a float to a 12-character string with three-character exponent (windows)
    #   or a two-character exponent on all other platforms.
    # First, get positives and negatives printed out with 13 characters
    #  (positives get padded with a space on left)
    if (os.name == 'nt'):
        out_str = " %12.5e" % float(float_val)
        # first digit of three-digit exponent should be a zero; remove it
        # else round to exponent of 99
        for i in range(len(out_str)):
            if out_str[i] == 'e':
                first_ex = i+2
                break
        #print "\npreconvert: '",out_str,"'"
        #print "out_str[",first_ex,"]: '",out_str[first_ex],"'"
        #print "out_str[0:",first_ex,"]: '",out_str[0:first_ex],"'"
        #print "out_str[",first_ex+1,":13]: '",out_str[first_ex+1:first_ex+3],"'"
        if (out_str[first_ex] != '0'):
            out_str = out_str[0:first_ex] + '99'
        else:
            out_str = out_str[0:first_ex] + out_str[first_ex+1:first_ex+3]
    else:
        out_str = " %12.5e" % float(float_val)
#
    if out_str[1] == '-' or (out_str[0]==' ' and out_str[1]==' '):
        out_str = out_str[1:]

    #print "length out_str = ",len(out_str)
    #print "postconvert: '",out_str,"'"

    return(out_str)

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

Rainbow streamlines

This tool creates a rake of streamlines from the line tool. Each streamline in the rake has a different, solid color in a sequence like a rainbow. This helps the eye track the individual streamlines among a group, which should make viewing some types of flow more clear. One example is flow around a vortex core, as seen in the example image below.

Download the tool and icon (2011-8-18)

Example image using the shuttle model showing the three coloring methods using the default setting of 12 streamlines and 6 colors. 

Usage notes

This tool does not actually emit the streamlines from the line tool. It uses the line too position to create individual streamlines from the cursor tool. Therefore the streamlines can only be moved one at a time. For best results first use the line tool to emit streamlines the usual way, then when the desired location and number of streamlines is determined use this tool.

The options in the GUI are,

  • Fluid part(s): selects the parent part(s) for the streamlines (all volume parts, individual 3D parts)
  • Vector variable: select the variable to use to create the streamlines (lists all vectors)
  • Number of traces: (integer value)
  • Method: Which rule to use to color the streamlines (smooth, cycle, group)
  • Number of colors: Total number of different colors to use

 Screenshot of the GUI options.

The example image above shows the 3 color schemes.

  • Smooth will make one unique color for each streamline no matter how many streamlines there are. This is good for small number of streamlines.
  • Cycle will use n# of colors, one for each streamline in sequence. After cycling through all the colors it will start back at the first color. This is useful for large numbers of streamlines or for emphasizing small-scale flow features. 
  • Group is similar to smooth, except that there are only a limited number of colors used so adjacent streamlines have the same color.

Limitations:

  • Cannot be used for 2D flow (since the GUI selection tool only allows selection of 3D parent parts)
  • Does not calculate pathlines or other particle trace types

 

EnSight version: 9.2, 10.0
OS: all

Various data translators

I have early versions of translators for several data types. I will not post the scripts here but contact me if you are interested. They all use python and enout to translate to EnSight case gold.

  • Ansoft HFSS/Maxwell – a very limited version for testing and learning about the data format
  • COMSOL – Reads ascii ‘spanwise’ format which is exported from COMSOL. It does not read the native file format. Created to demonstrate to a prospect in Europe who did not end up purchasing.
  • DEM – Reads a few types of ascii Digital Elevation Model formats. Can use these to create 2D geometry (for flat maps) and 3D geometry which shows the curvature of the earth. Can be used to make some nice images. The simple 2D structured nature of the data was good for learning how to do data translation.
  • FEKO – electromagnetics software. Reads geometry from the native input file and variable data from an optional .out file. Works for nearfield and farfield parts but not all possible geometry types. Good enough for making demonstrations.
  • Moldflow – early version which reads geometry from an ascii .inp input file and variables from separate ascii .nod and .ele ascii files. Done for a customer request, work in progress.
  • Nastran rms format – working version in use by a customer. See separate post. I don’t know what this format is used for. I am guessing it is for vibration analysis.
  • Wavefront OBJ – Handles colors differently than EnSight’s OBJ reader. Each element in an OBJ can have a different color while EnSight will give them only one color per part. This translator creates an element variable for each color assigns a value to each element. The script also edits the palette to display these colors correctly after the data is loaded. See image below. This was for fun.
  • XYZ – Used in chemistry, biology, and molecular dynamics. This is a very simple format which is probably not used often.  The translator creates a node for each atom and assigns a variable which represents the radius of the atom. See the image of a DNA strand below. Part of a quick exploration into the potential for EnSight in molecular dynamics and related fields.
  • PIV (Particle Image Velocimetry) – For measuring velocity. One standard data format is DaVis .vec, which is essentially a .csv files with a header line. My translator creates a 2D part from XY position and velocity information in the file. The result is a 2D part with a velocity vector that can be used to color by variable or create streamlines, etc. Great for comparing CFD to experiment. Added 2011-12-30

This model was originally a Wavefront OBJ model with color information in the .mtl file.

 

 

Part of a DNA double helix. Each sphere represents an atom. The color represents atom type and the size of the sphere is an approximation of the atomic radius.

Data translator: Nastran RMS to EnSight Case Gold

The script reads a Nastran .bdf input file and .rms variable files and converts them to a single EnSight case. The .rms files contain displacement and acceleration data (R, T, R0, and T0).

Download the script (2011-6-1)

Current state is usable but requires manual editing: the user must edit the file names and paths in the python script. It has not been polished and has only been tested on a small number of datasets. A fair amount of performance optimization has been done and the script has been used to translate models of over 1 million nodes in reasonable time.

This script was created for an aerospace customer in China. A version of the script is in use by the customer.

 

Recipe

Load .bdf input file using EnSight’s Nastran input reader; export geometry to case format; read variable data from ascii .rms file(s); export variables to case format using the enout API; modify the case file to merge the geometry and variables into a single case.

 

EnSight versions: 9.2
OS: all

Creating mirror images of parts

This tool creates the effect of mirroring parts about any plane orthogonal to one of the XYZ axes. It also optionally creates a plane at the plane of symmetry using point parts.

Download tool and icon (2013-3-6)

 

There are two intended uses of the tool:

1. Create a ‘display room’ effect where there is a partial reflection of the model, as seen in the image of the Ford Taurus below.

2. For symmetric models where the plane(s) of symmetry are not the X, Y, Z=0 planes.

 

How to use

First select all the parts that you want to create a mirror image for, then run the tool. A screenshot of the options is below.

Direction to reflect in: (+X, +Y, +Z, -X, -Y, -Z)

How to set mirror location: (Extents of selected parts, Extents of entire model, Specify a value)

X, Y, or Z value: (float) Location of the plane of symmetry if ‘Specify a value’ is chosen

Create symmetry plane: Whether to create a plane part at the plane of symmetry.

 

Other notes

The partial reflection effect is created with a partially-transparent plane at the plane of symmetry. The strength of the reflection can be adjusted by changing the opacity of the plane. The plane is 4x larger than the model extents. It can be changed on line 55 of the code.

The tool attempts to group all the newly-created copy parts into a group. In EnSight 9 this can fail and produce an error message if there are different types of parts. The rest of the tool still works in this case.

The tool attempts to account for the current symmetry state of the model. So it will correctly reflect the shuttle model for example. It may not work in all cases however. The tool can be used multiple times to reflect a reflection. In this case you may need to manually edit the symmetry of the parts to get the effect you want.

This tool was not created for a specific customer need and has not been heavily tested.

 

Recipe

Copy selected parts; activate mirror symmetry, original instance off; use frame mode to move the copy parts to the appropriate position; create a plane using point parts at the plane of symmetry (optional)

 

EnSight versions: 9.2, 10.0
OS: Windows, Linux, Mac

Experimental Data into EnSight

In the simulation world, it is quite common to have some type of experimental data which you’d like to compare against your simulation data. Now, if the data is just a table of “location versus value”, you can use EnSight’s built in “Import Query” function to read this 2 column of data into EnSight and graph alongside your simulation. But, what about more complex experimental data? What about a net of data with multiple variables? Perhaps data at a bunch of X,Y,Z locations; each with some amount of variables?   Perhaps some PIV data?…. EnSight can handle that too!

I’ve written a little snippet of code to take an excel comma separated file containing X,Y,Z,Var1,Var2 data, and read that right into EnSight. You can change or adjust the code for more variables, vectors, or even time varying.

You can download the python code and icon file for a UserDefinedTool.

Python code CSV to Point Data

Example Dataset

# ############################################
# Python Script to convert from a comma separated 5 column file (X,Y,Z,Var1,Var2) to
# EnSight Case format
# Assume temperature as Var1
# and strain_rate as Var2
#
# Kevin Colburn
# CEI
# June, 2010
#
# ############################################

Curved Clip Plane … How To

In analyzing internal flow through ducts, pipes, or passages, it is quite often useful to take a sectional cut through based on the centerline of the duct.

The section definition (shown at left by the red line) is used to look at values on the typical path of interest, or within a passage.

This document briefly demonstrates both the manual method to create a clip driven by this curve, as well as describe a GUI driven tool which is meant to automate the process.

 

The basic mechanisms used here is to first use a point part to describe the curved clip. The point part is then converted to a 1D line, and then extruded into the fluid domain. Once extruded, an EnSight function (DistToPartElem) is used to create a scalar field within the domain corresponding to the distance from the fluid domain to this extruded part. An isosurface of 0.0 DistToPartElem is then created, resulting in a new derived part corresponding to this curved clip.

 

The GUI driven python script automates this process, along with a few constraints/assumptions for ease of use. The GUI allows the user to specify the point part either from a file or created from the current available point parts. The GUI then prompts for direction and distance to extrude the part, and then proceeds through the same process used during the manual generation. Either method returns the same part. The resulting curved clip (shown the right) can then be used, colored, or interrogated just like any other created part.

A video tutorial, along with the python script and example dataset can be found on our website tutorial section.

A video tutorial of this exercise can be viewed from this location:

http://www.ensight.com/screencasts/Curved_Clip_Planes/Curved_Clip_Planes.html

The example dataset (including python script) can be obtained from : http://www.ensight.com/screencasts/Curved_Clip_Planes/Example_Manifold.zip

 Background

An example manifold was used for this short tutorial. To work through the method manually, the following steps are used:

  1. Create a point part which will describe the path of the clip. This point part can be created by either reading in from an external file, or via interactive mouse clicks. The amount of points used will determine the level of curvature used to describe the curved clip (more points will result in a smoother curve).
  2. Once the point part has been created, use the Feature Detail Editor to change the point representation from “input dataset” to “mesh the points to create a line mesh”.
  3. With this new 1D line selected, go to the extrude function. Extrude this 1D line via the vector and distance desired into the domain. This distance could be further than the model, but should be large enough to extrude through the whole model.
  4. With the extruded part selected, use the predefined function “Normal” to create a normal vector field for this extruded part. This will allow EnSight to calculate a signed distance from the fluid field to this extruded part.
  5. With this newly created extruded part, and the main fluid part(s) selected, use the predefined function called “DistToPartElem”. Follow the instructions given for its creation. You should enter the part id for the extruded part as the “source”, and the Normal Vector variable as the signed vector. The result of this will be a scalar field in the fluid part(s) which corresponds to the minimum distance from all parts in the fluid part(s) to the extruded part.
  6. With the fluid part(s) selected, create an isosurface of this “DistToPartElem” variable, with a value of 0.0. The resulting isosurface describes the clip through the domain at zero distance to the previous extruded part. You could use another value besides zero, and you will obtain a surface at some distance away from the extruded part.

The above method fairly generic, but also laborious if done over and over, or some time has elapsed since you last did it, and you have forgotten. Therefore, a GUI driven python routine was developed to help automate the process and allow the user to use this process periodically. The python routine should provide an easier tool to use.

The Python script is contained within the Example dataset download. You can place both the .py file and the .png file into your UserDefinedTool area, and thus access this capability directly from the UserDefinedTool. You will have an icon:

When double clicked, the user will be prompted with two separate GUI windows. Window #1 asks where the point part should come from (read in from a file, or already generated):

Once the user answers, the following GUI is opened. This GUI will differ slightly if the user has chosen to read the part in from a file (the “Select Point Part Defining Section” will read “Point part file” and file browser available.

The parent part selection will be through which the DistToPartElem calculation and isosurface will be created. The direction vector and distance input describes the direction and distance to extrude the 1d line.

The process of “DistToPartElem” is an n^2 function, and as such is a somewhat lengthy process. In this small example model, this portion of the routine takes 15-20 seconds to complete, which is 5-10x longer than the remaining steps in the process.

You will note that there were two “intermediate” parts created during the process. The point part and extruded part were used within the calculation, but not explicitly useful at the end of the process. The process relies on a ‘extruded’ 1D part. You cannot therefore easily describe this curved clip with two curves, or curves in more than 2 directions.

The resulting curved clip can be quite useful:

 

Note: Spring 2011, I modified the routine to allow a rotational extrusion rather than Cartesian one. This will allow turbo type customers to generate their curved clip planes in a cylindrical sense.