« Back to Video Tutorials

External Flow – Automation and Macros


External Flow – Automation and Macros

Hello and welcome the fourth video in our Tecplot 360 Getting Started: External Flow series.

In the previous video (Comparing a CFD Simulation with Experimental Data), we extracted slices to create a Cp plot. In this video, we will automate slice extraction and show you how to:

  • Record and run a macro
  • Add macros to the Quick Macro Panel
  • Edit a macro.

Plotting Results Using Macros

First, I’ll show you the results from using a macro so you will know what to expect.

Notice the Quick Macro Panel in the lower right side of the Tecplot 360 user interface. We will show you how to add macros to the quick macro panel later in the video. If you are following along in Tecplot 360, choose Scripting>Quick Macros from the main menu.

At this point we assume that the slices have already been placed from previous video in the series and we need only to toggle them on (see the first 5 minutes of Comparing a CFD Simulation with Experimental Data). Because this macro can be used for any wing, the slices have already been placed wherever you wish to have them extracted.

To play the macro, Choose Scripting>Play Macro, navigate to your Tecplot 360 installation folder and examples>OneraM6wing>macros folder, and then select the CpPlot_Demo.mcr file. Enter 12 for the Pressure Coefficient. The variable number for Pressure Coefficient is 12 for this data set. This macro will extract each slice, calculate X/L, then plot each extracted slice on the same XY plot.

Creating a Macro Step-by-Step

Now, let’s see how we did this.

  1. First open a new layout by choosing File>New Layout.
  2. Second, load the data by choosing File>Load Data and choose OneraM6_SU2_RANS (PLT file).
  3. Third, start recording a macro by choosing Scripting>Record Macro. Name the macro CpPlot_Test.
  4. Next, go through the same steps as we did in video 3 (about the first 5 minutes of that video). However, do not load in the experimental data. When you finish the steps of video 3, click Stop Recording to finish your macro.

Editing a Macro

Now we will edit this macro to get the multiple slice extraction macro we showed at the beginning of this video. Let’s open the macro in a text editor (outside of Tecplot 360).

Note that each action you performed in Tecplot 360 was recorded in the macro. Also note that Tecplot is a one-based system.

Let’s now step through the macro.

  1. First, we normalized the span, then extracted our slice.
  2. We created our X/L variable and calculated X/L.
  3. Next, we created a new frame, then tiled our frames.
  4. We changed the plot to XY line, which allowed us to add our extracted slice zone to our XY plot.
  5. Lastly, we formatted our plot.

We’ll now go through some steps to turn this recorded macro into the macro shown at the beginning of this video.

Using and Setting Macro Variables

The macro language has its own way to use and set variables.

You can define your own variable or use intrinsic variables. Intrinsic variables are Tecplot-defined variables like numzones, which is the number of zones. This and other Tecplot-defined variables are defined in the Tecplot 360 Scripting Guide.

You can also calculate variables. These require parentheses. We’ll go through this in more detail a little later in the video.

You can also include variables in commands. In this example, we’re setting the active field maps equal to foo, which equals 5 in this case.

Variables can also be used in command strings. We are creating a variable called green, which is equal to bar multiplied by 5.

Setting variables
$!VarSet |FOO| = 5

Intrinsic variables
$!VarSet |BAR| = |NUMZONES|

Variable calculations
$!VarSet |TOTALFOOBAR| = (|FOO| + |BAR|)

Using variables in commands
$!ACTIVEFIELDMAPS = [|FOO|]

Include variables in command string
$!ALTERDATA
EQUATION = ‘{Green}= |BAR|*5’

Setting Up Macro Loops

Loops in Tecplot 360 macros work a little differently than other languages. This is how you set up a loop in a macro. You can define variables that return the number of times through the loop and the current iteration.

Set up the total number of times through the loop. |LOOP| returns the current iteration.
$!VARSET |NUMBEROFLOOPS| = 10
$!LOOP |NUMBEROFLOOPS|
     #Do things in the loop
     $!VARSET |CURRENTVALUE| = |LOOP|
$!ENDLOOP

Here is an example of the recorded macro that created a single line map. We assigned it variables and a name and used a loop to create multiple plot lines for each extracted slice zone.

Recorded Macro
$!CREATELINEMAP
$!LINEMAP [1] NAME = 'Map 0'
$!LINEMAP [1] ASSIGN{XAXISVAR = 20}
$!LINEMAP [1] ASSIGN{YAXISVAR = 12}
$!LINEMAP [1] ASSIGN{ZONE = 5}

We created a new variable called newzonecount, which serves as the number of iterations for the loop. In the loop, line maps are created for each zone that has been extracted. Note that we can use strings as variable names.

Edited Macro
$!VarSet |CURZONE| = (|INITZONE| + 1)
$!VARSET |NEWZONECOUNT| = (|FINALZONES| - |INITZONES|)
$!LOOP |NEWZONECOUNT|
     $!CREATELINEMAP
     $!LINEMAP [|LOOP|] NAME = '&ZN&'
     $!LINEMAP [|LOOP|] ASSIGN{YAXISVAR = |YVARNUM|}
     $!LINEMAP [|LOOP|] ASSIGN{XAXISVAR = “x”} #Uses string
     $!LINEMAP [|LOOP|] ASSIGN{ZONE = |CURZONE|}
     $!VarSet |CURZONE| += 1
$!ENDLOOP

Adding Macros to the Quick Macro Panel

The Quick Macro Panel is a great way to store frequently used macros. To add a macro to the Quick Macro Panel, open the tecplot.mcr file located in the home directory and write the following code anywhere in the file. Just ensure to get the correct path to the macros so Tecplot 360 can call it. Once you’ve added the macro function to the tecplot.mcr file, all you need to do in Tecplot 360 is go to the Quick Macro Panel and double click on the macro you wish to run.

$!MacroFunction NAME = “Some Name”
ShowInMacroPanel = TRUE
$!INCLUDEMACRO “PATH/TO/MACRO/FILE.mcr”    
$!EndMacroFunction

Extending Tecplot Macros with Add-ons

As you may recall from the beginning of this video, there was a prompt for the pressure coefficient variable number. This was done using this command which asks for the user’s input.

User Input
$!PROMPTFORTEXTSTRING |BAR|
INSTRUCTIONS = “Give Instructions Here”

Tecplot 360 can be extended by using add-ons. Add-ons can supply their own macro language for scripting. The extended command example below is running a query on how many zones are active. That number is then stored in a variable called BAZ. More information on writing macros can be found in the Tecplot 360 Scripting Guide.

Extended commands give useful information
$!EXTENDEDCOMMAND COMMANDPROCESSORID=‘extendmcr’
COMMAND=‘QUERY.ACTIVEZONES BAZ’

Recorded Macros vs. Edited Macros

Now, let’s compare the recorded with the edited macro. On the left, we have our recorded macro, and on our right, we have our edited macro. Add the Quick Macro code explained above to the edited macro to add this macro to the Quick Macro Panel. Copy and paste this into the tecplot.mcr file and change the path name.

  1. First, we prompt for the variable number for the pressure coefficient
  2. Second, we extract our slices.
  3. Third, we create our X/L variable to normalize the cord for each slice.
  4. Fourth, we create a loop to extract each X/L.
  5. Then create a new frame and tile the frames nicely.
  6. Add the line maps to the XY plot for each extracted slice zone.
  7. Finally, edit the XY plot.

Recorded Cp Macro


#!MC 1410

$!ALTERDATA
EQUATION = '{y/b} = {y}/1.19'
$!THREEDAXIS YDETAIL{VARNUM = 19}
$!CREATESLICEZONES
$!ALTERDATA
EQUATION = '{X/L} = 0'
$!ACTIVEFIELDMAPS -= [1-2] $!ALTERDATA [3] EQUATION = '{X/L} = ({x}-MINX)/(MAXX-MINX)'
$!ACTIVEFIELDMAPS += [1-2] $!CREATENEWFRAME
XYPOS
{
X = 1.3727
Y = 5.2767
}
WIDTH = 7.3183
HEIGHT = 3.0719
$!EXTENDEDCOMMAND
COMMANDPROCESSORID = 'Multi Frame Manager'
COMMAND = 'TILEFRAMESHORIZ'
$!PLOTTYPE = XYLINE
$!DELETELINEMAPS
$!CREATELINEMAP
$!LINEMAP [1] NAME = 'Map 0'
$!LINEMAP [1] ASSIGN{XAXISVAR = 20}
$!LINEMAP [1] ASSIGN{YAXISVAR = 12}
$!LINEMAP [1] ASSIGN{ZONE = 3}
$!ACTIVELINEMAPS += [1] $!VIEW FIT
$!XYLINEAXIS YDETAIL 1 {ISREVERSED = YES}
$!GLOBALLINEPLOT LEGEND{SHOW = YES}
$!RemoveVar |MFBD|

Edited Cp Macro


#!MC 1410

$!PROMPTFORTEXTSTRING |CPVARNUM|
INSTRUCTIONS = "Enter variable number for Pressure Coefficient"

$!ALTERDATA
EQUATION = '{X/L} = 0'

$!VarSet |INITZONES| = |NUMZONES|

## Extract existing slices
$!CREATESLICEZONES

$!VarSet |FINALZONES| = |NUMZONES|
$!VarSet |NUMSLICEZONE| = (|FINALZONES| - |NUMZONES|)

# Get current active zones and set it to ORIGACTIVEZONES variable.
$!EXTENDEDCOMMAND
COMMANDPROCESSORID='extendmcr'
COMMAND='QUERY.ACTIVEZONES ORIGACTIVEZONES'

# Loop over all the new zones. Need to activate the zones
# one at a time to use MINX and MAXX intrinsic variables
# which return the min and max X value for active zones

$!VARSET |FIRSTSLICEZONE| = (|INITZONES| + 1)
$!VARSET |SLICEZONE| = |FIRSTSLICEZONE|
$!LOOP |NEWZONECOUNT|
$!ACTIVEFIELDMAPS = [|SLICEZONE|] $!ALTERDATA [|SLICEZONE|] EQUATION = '{X/L} = ({x} - MINX)/(MAXX-MINX)'
$!VarSet |SLICEZONE| += 1
$!ENDLOOP

# Return to the originally active zones
$!ACTIVEFIELDMAPS = [|ORIGACTIVEZONES|]

$!CREATENEWFRAME
$!EXTENDEDCOMMAND
COMMANDPROCESSORID = 'Multi Frame Manager'
COMMAND = 'TILEFRAMESHORIZ'

$!PLOTTYPE = XYLINE
$!DELETELINEMAPS

$!VarSet |CURZONE| = |FIRSTSLICEZONE|

# Loop over all the new zones and create new
# line maps for each of the new zones

$!VARSET |NEWZONECOUNT| = (1 + |NUMZONES| - |FIRSTSLICEZONE|)
$!LOOP |NEWZONECOUNT|
$!CREATELINEMAP
$!LINEMAP [|LOOP|] NAME = '&ZN&'
# |CPVARNUM| gathered in the prompt at beginning
$!LINEMAP [|LOOP|] ASSIGN{YAXISVAR = |CPVARNUM|}
# New feature allows variable names as strings to be used in place of numbers
$!LINEMAP [|LOOP|] ASSIGN{XAXISVAR = "X/L"}
$!LINEMAP [|LOOP|] ASSIGN{ZONE = |CURZONE|}
$!VarSet |CURZONE| += 1
$!ENDLOOP

$!GLOBALLINEPLOT LEGEND{SHOW = YES}
$!VIEW NICEFIT
$!REDRAWALL
$!RemoveVar |MFBD|

Now you know a little bit about macros. We encourage you to look over the scripting guide and expand this macro. You will soon be customizing and exploring your results in a matter of clicks!

Thanks for watching!

 

Related Videos