%% Create run file
%Open the file with write permission
fid = fopen(strcat(basename,’.run’), ‘w’);
%Load the AVL definition of the aircraft
fprintf(fid, ‘LOAD %sn’, strcat(filename,’.avl’));
%Load mass parameters
fprintf(fid, ‘MASS %sn’, strcat(filename,’.mass’));
fprintf(fid, ‘MSETn’);
%Change this parameter to set which run cases to apply
fprintf(fid, ‘%in’,   0);
%Disable Graphics
fprintf(fid, ‘PLOPngnn’);
%Open the OPER menu
fprintf(fid, ‘%sn’,   ‘OPER’);
%Define the run case
fprintf(fid, ‘c1n’,   ‘c1’);
fprintf(fid, ‘v %6.4fn’,velocity);
fprintf(fid, ‘n’);
%Options for trimming
%fprintf(fid, ‘%sn’,   ‘d1 rm 0’);
%fprintf(fid, ‘%sn’,   ‘d2 pm 0’);
%Run the Case
fprintf(fid, ‘%sn’,   ‘x’);
%Save the st data
fprintf(fid, ‘%sn’,   ‘st’);
fprintf(fid, ‘%s%sn’,basename,’.st’);
%Save the sb data
fprintf(fid, ‘%sn’,   ‘sb’);
fprintf(fid, ‘%s%sn’,basename,’.sb’);
%Drop out of OPER menu
fprintf(fid, ‘%sn’,   ”);
%Switch to MODE menu
fprintf(fid, ‘%sn’,   ‘MODE’);
fprintf(fid, ‘%sn’,   ‘n’);
%Save the eigenvalue data
fprintf(fid, ‘%sn’,   ‘w’);
fprintf(fid, ‘%s%sn’, basename,’.eig’);   %File to save to
%Exit MODE Menu
fprintf(fid, ‘n’);
%Quit Program
fprintf(fid, ‘Quitn’);
%Close File
fclose(fid);

Mark Drela’s Athena Vortex Lattice (AVL)  program is a powerful tool for aerodynamic analysis.  Automating AVL runs using Matlab not only saves time, but eliminates human error when plugging through a large range of run cases.  In combination with tools for parsing the results and editing the models this automation may also enable design methods such as genetic algorithms and other iterative approaches.

Included below is a zip file containing the example script detailed here as well as a set of sample AVL files copied from the AVL source directory.  You will need to download AVL yourself and place the executable in the unzipped folder with the other files. Alternately, you may change the path to the avl executable in the last line of the script.  This tutorial was tested against avl 3.27.  Version 3.16 may have issues.

runAVL

Creating the run file

The run file to be created is simply a batch script that will be fed into AVL.  This will cause AVL to act as though the commands in the batch file are being typed in by a user.  The process begins by creating a blank file to put the batch script in.

%% Create run file %Open the file with write permission fid = fopen('.allegro.run', 'w');

Once this is complete, each line of the batch script is “printed” to the file by the fprintf command.  First, the aircraft’s avl and mass file are loaded into AVL.  The MSET command is executed to apply the mass parameters to all the run cases.  Then graphics are disabled to allow the program to run silently in the background.

%Load the AVL definition of the aircraft
fprintf(fid, 'LOAD %s\n', strcat(filename,'.avl'));

%Load mass parameters
fprintf(fid, 'MASS %s\n', strcat(filename,'.mass'));
fprintf(fid, 'MSET\n');
%Change this parameter to set which run cases to apply
fprintf(fid, '%i\n',   0); 

%Disable Graphics
fprintf(fid, 'PLOP\ng\n\n');

Once the setup is complete, the run case is defined and executed.  In this instance the C1 command is used to “set level or banked  horizontal flight constraints”.  The velocity is then set.  Depending on the purpose of the run case you may also use commands such as commented out under “Options for trimming”.  The case is then run using the X command.

%Open the OPER menu
fprintf(fid, '%s\n',   'OPER');   

%Define the run case
fprintf(fid, 'c1\n',   'c1');
fprintf(fid, 'v %6.4f\n',velocity);
fprintf(fid, '\n');

%Options for trimming %fprintf(fid, '%sn', 'd1 rm 0'); %Set surface 1 so rolling moment is 0 %fprintf(fid, '%sn', 'd2 pm 0'); %Set surface 2 so pitching moment is 0

%Run the Case
fprintf(fid, '%s\n',   'x');

Once the run is complete, the desired data in the OPER menu is saved to files for post analysis.  This example shows how to save the stability derivatives (ST) and body-axis derivatives (SB) data.  Other data that can be saved off in a similar fashion as shown below include:

  • ST  stability derivatives
  • SB  body-axis derivatives
  • RE  reference quantities
  • FT  total   forces
  • FN  surface forces
  • FS  strip   forces
  • FE  element forces
  • VM  strip shear,moment
  • HM  hinge moments
%Save the st data
fprintf(fid, '%s\n',   'st');
fprintf(fid, '%s%s\n',basename,'.st');
%Save the sb data
fprintf(fid, '%s\n',   'sb');
fprintf(fid, '%s%s\n',basename,'.sb');
%Drop out of OPER menu
fprintf(fid, '%s\n',   '');

Other data may also be obtained by leaving the OPER menu and entering the MODE menu.  This eigenvalue data can be useful for analyzing an aircraft’s stability.

%Switch to MODE menu
fprintf(fid, '%s\n',   'MODE');
fprintf(fid, '%s\n',   'n');
%Save the eigenvalue data
fprintf(fid, '%s\n',   'w');
fprintf(fid, '%s%s\n', basename,'.eig');   %File to save to

%Exit MODE Menu
fprintf(fid, '\n');

Once all the desired runs have been computed and saved, it is important to use the return key character ‘n’ to return to the top level menu before issuing the Quit command to exit out of AVL and back to the command line. With the script complete the batch script file is closed.

%Quit Program
fprintf(fid, 'Quit\n'); 

%Close File
fclose(fid);

Executing the script

Files whose names conflict with new files to be generated should be moved out of the target directory or deleted before running the script.

[status,result] =dos(strcat('del ','allegro.st'));

Execution of the script from matlab is acheived by simply using the below command.  The dos command tells matlab to execute the string argument on the command line.  The instruction tells the OS feed the allegro.run file in the local directory to the avl executable at the absolute address shown.  The dos function also returns status and result data.  The status variable will get the final return state of the execution, nominally a 0 unless the program crashed.  The result variable will contain all the text that would have been printed to the screen if executed from the command line.

[status,result] = dos('C:avl.exe < .allegro.run');

With this complete the batch script will have successfully executed your run case or will have crashed.  To debug your batch script it is helpful to look through the result variable’s data.  Also helpful is to manually type in a script so that you can see more easily what the program is trying to do.