Run ANSYS with MATLAB for parametric analysis

I switched from ABAQUS to ANSYS for my current research, though I am more familiar with ABAQUS.  I currently have all the APDL for my model and want to do  parametric analysis which requires about 7 to 8 hours for the calculation of one model with 2 cores. To improve the efficiency of running macro files in ANSYS, I decide to use MATLAB to run ANSYS.

I never used this function before and I am also a beginner in ANSYS. I searched on Google and found there are different ways to realize this function. I asked a friend for help and she sent me three files, but I still cannot understand how to do. So I focused on her method and searched again. The descriptions are not so friendly for beginners, at least for me. How I hope there was a tutorial explaining how to run ANSYS with MATLAB for parametric study. After tried and tried again, finally I could run the model one by one automatically. I decided to record the method in this article and hope I can help someone else.

First file: run_ansys.bat

SET ANS_CONSEC=YES
SET ANSYS_LOCK=OFF
SET KMP_STACKSIZE=1024k
"C:\Program Files\ANSYS Inc\v181\ansys\bin\winx64\ANSYS181.exe" -b -i ansysinputreader.txt -o out.txt

The codes in the last line means ANSYS will read the ansysinputreader.txt file and store output to out.txt file. It should be noted that the default value for KMP_STACKSIZE is 512k, which may not be able to run your analysis. So you can set the value for your case. When I set it to 2048k (2 cores) in my laptop, it showed no responding in task manager. Thus, this value cannot be too large to be the same case as mine. 

Second file: ansysinputreader.txt

/INPUT,test,'txt','C:\ANSYS\paper1\',,0

This file tell ANSYS which file to be run and also the location of the file. One thing I should record is that I tried many times and the output file showed it could not find test.txt file. Latter I found it worked if I just use  test,'txt' , while all the sources I could find online use 'test','txt'. I think this difference may be caused by different versions of ANSYS. 

After you have the two files and then you can run the following codes in MATLAB. I put all the files in the same folder to avoid any error resulting from location of files.

Run in MATLAB:

cd 'C:\ANSYS\paper1'
!run_ansys.bat

After you successfully run the APDL codes in test.txt file, you will have out.txt file in your folder (defined in the first file) and the following codes will be in this file. You can also find errors, if any,  in this file.

         *****  ANSYS COMMAND LINE ARGUMENTS  *****
 BATCH MODE REQUESTED (-b)    = LIST
 INPUT FILE COPY MODE (-c)    = COPY

RELEASE= Release 18.1         BUILD= 18.1      UP20170403   VERSION=WINDOWS x64 
CURRENT JOBNAME=file  12:50:41  DEC 19, 2019 CP=      0.281

    1  /INPUT,test,'txt','C:\ANSYS\paper1\',,0 

RUN SETUP PROCEDURE FROM FILE= C:\Program Files\ANSYS Inc\v181\ANSYS\apdl\start.ans

/INPUT FILE= C:\Program Files\ANSYS Inc\v181\ANSYS\apdl\start.ans  LINE=       0

/INPUT FILE= C:\ANSYS\paper1\test.txt  LINE=       0

*** ANSYS - ENGINEERING ANALYSIS SYSTEM  RELEASE Release 18.1     18.1     ***
ANSYS Mechanical Enterprise                       
00000000  VERSION=WINDOWS x64   12:50:41  DEC 19, 2019 CP=      0.375

Parametric analysis

I want to do parametric analysis with ANSYS and thus I should use MATLAB to run different models one by one. I used a for loop in MATLAB to write the second file test.txt everytime and then run bat file. The simplified codes of for loop is demonstrated below. I used disp(wind_speed)to remind me which model has been run.

matrix = [60,70,80];
for wind_speed = matrix
    fileID = fopen(filename, 'w+');
    fprintf(fileID, '/CLEAR \n');
    fprintf(fileID, '/PREP7 \n');
    fclose(fileID);
    !run_ansys.bat 
    cd 'C:\ANSYS\paper1'
    disp(wind_speed)
end

 

5 comments On Run ANSYS with MATLAB for parametric analysis

  • Sir,
    After getting output.txt…. I want to extract stress values at different nodes stored in that output file… Can you help me out to solve it

  • There are no codes available in this topic sir…..

  • hello, first of all. Thanks for this kind of material is rare.
    And how did you run in parametric way? Could you shared more material about ? Thanks a lot.

Leave a Reply to Sateesh Cancel Reply

Your email address will not be published.

Site Footer

Recording Life, Sharing Knowledge, Be Happy~