Tecplot Tutorial

  

This blog on Tecplot Macro Tutorials was written from a webinar entitled Ask the Expert About Tecplot 360 hosted by Scott Fowler, Tecplot 360 Product Manager. We received numerous questions about Tecplot macros and this blog pulls our macro resources together in one place.

What is a Tecplot macro? A Tecplot macro is a set of instructions, called macro commands, that perform actions in Tecplot 360. Macro commands can be used to accomplish virtually any task that can be done via the Tecplot 360 interface, offering an easy way to automate Tecplot 360 processes.

Tecplot Macro Tutorials

Tips and Tricks for using Tecplot for CONVERGE - watch the full Webinar. It includes a walk-through of the user interface, loading data, keyboard shortcuts. Has anyone any idea that why the value of 'shock' variable in Tecplot can be greater than 1 or less than -1? I tried to capture a shock interface in a 2D convergent-divergent nozzle. Although the position is deriable, but the lengend given in Tecplot has a value which can be as high as 30 and as low as -30. According to the definition. Get started with Tecplot 360 while learning best practices for plotting and analyzing your data. This 30-minute Webinar walks you through everything from loa. Licensed users have been emailed an invitation to create a new account. You do not need an account to get Free Trial Software or to Request a Quote. The ParaView Tutorial is an introductory and comprehensive tutorial. It teaches using ParaView through examples that start at basic usage and continue through more advanced topics such as temporal analysis, animation, parallel processing, and scripting.

Macro Resources

  • Tecplot 360 Scripting Guide
    (also available in the Tecplot 360 User Interface)

We recommend that you download the macros, datasets and layout files used in the descriptions below. If you do not already have Tecplot 360 running, you can download a Free Trial.

Using a Macro to Produce Transient Plots

This macro reads and edits different time steps and produces transient plots. This macro first finds out how many time steps are in your dataset, then it loops over those time steps. At each time step the current time step is set and an image is exported. That’s It!

export_over_time.mcr
$!EXTENDEDCOMMAND COMMANDPROCESSORID='extend time mcr' COMMAND='QUERY.NUMTIMESTEPS NUMTIMESTEPS'
$!LOOP |NUMTIMESTEPS|
$!EXTENDEDCOMMAND COMMANDPROCESSORID='extend time mcr' COMMAND='SET.CURTIMESTEP |LOOP|'
$!EXPORTSETUP EXPORTFORMAT = PNG
$!EXPORTSETUP EXPORTFNAME = 'FILE_|LOOP|.png'
$!EXPORT
$!ENDLOOP

Extend Time Macro Addon

The Extend Time Macro add-on simplifies the macro interface by allowing you to use a simple loop to query the number of solution times in the dataset and advance the time step. This differs from the native Tecplot macro language as it does not require that you know the solution time of your data.

This add-on uses a different algorithm than Tecplot 360 EX for sorting the solution times. Because Tecplot 360 combines time steps that are sufficiently close together, the number of time steps reported by this add-on may differ from the number of time steps reported by Tecplot 360.

You can load this addon by adding the following line to your tecplot.add File. See chapters 31 – 3.5 and 31 – 1.2 in the Tecplot 360 User’s Manual.

$!LoadAddOn 'tecutilscript_extendtime.mcr'

Converting Binary Files to ASCII

A question asked during the webinar was “How do I convert TEC files to binary?” The .tec file extension has been adopted by the greater Tecplot community. These files are usually ASCII, but in this case, the TEC file was a binary file. So, the question becomes “How do I convert from binary to ASCII?” Well, that’s easy!

Let’s backtrack for a moment and review the canonical Tecplot file extensions:

  • PLT (.plt) – Tecplot binary format.
  • DAT (.dat) – Tecplot ASCII format.
  • SZL (.szplt) – Tecplot Subzone Load-on-demand binary format. This format allows you to load large volume metric grids with very little RAM.

» Read the “Comparison of Tecplot Data File Formats” blog on Tecplot file types.

We don’t have a standalone utility to convert binary files to ASCII, but you can do it using the macro binary_to_ascii.mcr (also included in the ZIP file mentioned above). In the macro, you simply use the ReadDataSet command and then a WriteDataSet command.

binary_to_ascii.mcr
#!MC 1410
$!ReadDataSet 'VortexShedding.plt' '
ReadDataOption = New
ResetStyle = No
VarLoadMode = ByName
AssignStrandIDs = Yes
$!WriteDataSet 'VortexShedding.dat'
IncludeText = No
IncludeGeom = No
IncludeCustomLabels = No
IncludeDataShareLinkage = Yes
Binary = No
UsePointFormat = No
Precision = 9
TecplotVersionToWrite = TecplotCurrent

From the command line you would call tec360.exe and pass this macro. Note that the file names in the macro need to be hard coded.>tec360 -b -p binary_to_ascii.mcr
Here a plug for the power of Python!
Using PyTecplot to convert files, in this case binary to ASCII, is so much simpler as you can see in these few lines of code. This Python script (binary_to_ascii.py)is in the ZIP file mentioned above.

import tecplot as tp
tp.data.load_tecplot(‘mybinaryfile.plt’)​
tp.data.save_tecplot_ascii(‘myasciifile.dat’)​

Converting ASCII Files to Binary

Another user wanted to convert ASCII files to binary.

Focus

You can use a utility called Preplot. Preplot is included with Tecplot 360 and it’s located in the bin directory in the Tecplot 360 installation. You just pass it an ASCII file (.dat) and tell it the output file name. Preplot will do the conversion for you.

> preplot myasciifile.dat mybinaryfile.plt

» Watch the video tutorial, Preplot and SZL Convert Tools.
» Read the Tecplot 360 User’s Manual.
» Reference the Data Format Guide.

A note about ASCII data, whenever Tecplot 360 loads an ASCII file we actually convert it to binary as it’s being loaded. Because of this, it is in your best interest, if you need to load that file over and over, to do the conversion only once. You will save yourself a lot of time!

Placing Streamlines and Streaklines Using Macros

During the webinar, one user was trying to create an arc of streamlines (which we call streamtraces in Tecplot 360). This is not possible using the onscreen “Rake” tool! The Rake tool only places straight lines of streamlines.

Tecplot Tutorial

If you want to define an arc of streamlines, the best way to do it would be with PyTecplot (but that will be the topic of a future blog). I explain here how to do it with a Tecplot macro.

Here is the Tecplot macro for placing the streamtrace object associated with the frame. In the code below, I’m adding a streamtrace, defining it as a volume line, setting the direction to “both” (default is forward), and placing it at X= 0.5, Y=0.5, Z=0.5. You can create an arc by having multiple of these add commands at different locations.

$!STREAMTRACE ADD ​
NUMPTS = 1 ​
STREAMTYPE = VolumeLine​
STREAMDIRECTION = Both​
STARTPOS { X = 0.5 Y = 0.5 Z = 0.5 }​

Loading a Saved Frame Style Without the Position

How do I share data across frames without having to reload the data? In this example, I want to tile frames and then save the style from the upper left plot and load it into the lower right frame. You can do this, but not directly in the Tecplot 360 user interface. We will use a macro to do this (It can also be done with PyTecplot).

Copy Frame Style Steps

  1. First, create a new frame (click the Frame icon and draw a new frame). Then change the plot type to 2D Cartesian. (Now I could easily click on the upper left frame and save the frame style (Frame>Save Frame Style). Then, I could click in the new frame and load the frame style, but that will also copy the frame size and position which will overlay the original position. I want to retain the position. So, I don’t want to do it this way.)
  2. Drag and drop the copy_frame_style.mcr macro (from the ZIP file above) onto the Tecplot 360 user interface. Two new entries will appear in the Quick Macro Panel: “Copy frame Style” and “Paste frame Style.” Be sure the stylesheet directory in the macro is valid (C:TEMPtemp_style.sty”).
  3. Click on the frame you want to copy, click the Quick Macro “Copy frame Style” and click Play (or simply double-click on the macro name).
  4. Select the new frame and double click on the “Paste frame Style” macro.
  5. Voila! You now have a new frame with the same style. This is one of the macros I use most often.

Tecplot Tutorials

Copy Frame Style Video Tutorial

Tecplot Tutorial

The magic is in the macro’s last command “INCLUDEFRAMESIZEANDPOSITION=NO,” which loads the frame style but ignores the position.

Making Macros Persistent in Tecplot 360

If you want these macro functions always available, you can put them in the tecplot.mcr file (located in Tecplot 360 installation directory).

If you are sharing the Tecplot 360 installation, for example in a Linux environment, you can put the “.tecplot.mcr” file in your Linux home directory so as not to impact other users on your network.

Tecplot Animation Tutorial

Learn more about macros in the Tecplot 360 User’s Manual (search for “tecplot.mcr”).

Creating a new variable or referencing a variable by name requires surrounding it in curly braces.

Tecplot Tutorial

Variables on the right side of equations may be referenced by two other methods: First, by the variable index. Second is to use variable assignment letter codes. In this example, we’re using ‘u’ and ‘v’ which represent the variables assigned to the U and V vector components in Plot -> Vector -> Variables dialog. A complete list of variable assignment letter codes is available in Section 20 – 1.1, “Equation Syntax” in the User’s Manual.

Common mathematical functions such as SIN, COS, SQRT, and other common mathematical operands are available in the equation syntax. Notably, squared or second power is indicated by a double star. A full list of functions is located in Section 20 – 1.1, “Equation Syntax” in the User’s Manual.

For our velocity magnitude calculation, all three of these equations will achieve the same result.

Editing Specific Zones

Tecplot Focus Tutorial

If you only want to edit or create a variable for one zone, select the zone you wish to use in the “Zones to Alter” field.

Tecplot Xy Plot Tutorial

For this example, only the second zone will be edited and Vmag will be calculated using only its velocity components.

If you wanted to compare two zones, find two zones of identical grid structure and enter the following syntax:

This will create a new variable called “delta_Vmag” which takes the difference of the tenth and first zone. The result will be applied only to the first zone due to the selection in “Zones to Alter”.

To see a full example of the bracket syntax, watch “Comparing Grids in Tecplot 360”.

Using IF statements

Let’s say you only want to edit a specific portion of your dataset. You can specify these conditions with an IF statement. Let’s take the Vmag variable we have already created and make it 0 outside of a specific region:

This equation reiterates our Vmag calculation and then adds our IF statement. This IF condition makes all of the Vmag values outside our bounding box, equal to zero. Our bounding box chosen in this situation is X from -5 to 5, and Y from -5 to 5.

Tecplot Focus Tutorial

If you would like to learn additional capabilities and examples of the Specify equations dialog, check out previous tutorial videos: “Data Alter using If Conditions” or “Comparing a CFD solution with Experimental Data” from the external flow series.