MATLAB Apps For ANSYS Products: Updated for ANSYS 17.0

In 2013, I wrote a blog showing ANSYS users how to make MATLAB apps for ANSYS Fluent. Just as a quick reminder, a friend of mine, who is also an ANSYS Fluent and Mechanical APDL user has a Windows Matlab code programming a Linux Fluent session. She had just updated her hardware. Everything is moved to Linux. She also needed to integrate a Mechanical APDL session.

She was asking me: “Why, can’t I port my MATLAB®  code running on the platform of my choice and be able to also connect to Mechanical APDL?” She challenged me to to create a less than 20 lines code example. Back in 2013, my example was for ANSYS 16.0. Here is my update for ANSYS 17.0.

Software:

  1. Fluent
  2. Mechanical APDL
  3. Workbench
  4. MATLAB

Hardware:

  1. Network of computers with ANSYS or MathWorks software installed

Instructions:

  1. Download ANSYS aaS Matlab toolbox (supports Matlab R2014b to 2016a) from ANSYS Customer Portal
  2. Open the folder where the mltbx has been downloaded in a Matlab folder view.
    • double click on it and follow instructions to install
  3. Start the ANSYS products in aaS mode
    • Read the downloaded pdf for suggestions
  4. Collect the aaS keys (aas_FluentId.txt, aaSMapdlId.txt and aaS_WbId.txt)  and transfer them to the MATLAB machine
    • These are the “keys” required to connect with ANSYS aaS products.
  5. Now let’s code. What should it do? Well, I will keep it simple: one command per ANSYS product:
    • ask a report from Fluent
    • set a variable in Mechanical APDL
    • retrieve the Workbench Schematic

%initialize aaS
orb=initialize_orb();
load_ansys_aas();

%connect to ANSYS products
iCoFluentUnit=actfluentserver(orb,‘aaS_FluentId.txt’);
iCoMapdlUnit=actmapdlserver(orb,‘aaS_MapdlId.txt’);
actwbserver(‘aaS_WbId.txt’)

%execute a Fluent TUI command
iFluentTuiInterpreter=iCoFluentUnit.getSchemeControllerInstance();
fluentResult=iFluentTuiInterpreter.doMenuCommandToString(‘report summary’)

%execute a Mechanical APDL command
mapdlResult=char(iCoMapdlUnit.executeCommandToString(‘aas_param=22’))

%retrieve the content of the remote Workbench Schematic
execwbcommand(‘systems=GetAllSystems()’)
querywbvariable(‘systems’)

Well, all in all I used only 19 lines of code. My friend added her own code to create her elegant and efficient so-simulation.

Thank you for reading.

6 thoughts on “MATLAB Apps For ANSYS Products: Updated for ANSYS 17.0

  1. Hi Sorin,

    Thank you for the note. But, where is the default location after installation? Thanks.

    • Hi Fa-Gung,

      The AAS_Key_Folder is the folder where you store the ANSYS aaS keys. The ANSYS aaS key (e.g.aaS_FluentId.txt, aaS_MadlId.txt ,…) are generated by the the ANSYS solvers at launch time. You can transfer them from a remote machine, after launch and use them to connect Matlab to a living Fluent or Mechanical APDL session.

      After you launch the ANSYS solver e.g., Mechanical APDL, this file will be generated in the working directory of the solver.

      For additional specifications please refer to the aaS chapter in ANSYS Mechanical APDL documentation.

      Thank you

      Sorin

  2. Hello Sorin,

    Thanks for the information. I followed the steps shown in the pdf document, but the keyfile generated has nothing except for ‘localhost: ‘ written in it. I’m guessing that’s why the command ‘actwbserver(‘aaS_WbId.txt’) fails with a NoSuchFileException or something like that when run in MATLAB.

    What could be going wrong? I’ve tried this with both ANSYS 15.0 and 17.1 without success. Do I need to register ‘RunWB2’ as a server? I had to do it last time with FLUENT using -regserver on command prompt but Wbench doesn’t let me (‘-regserver’ suffix doesn’t match with Workbench’s standard command extension options and returns an error)

    Quite stuck here. Any help from anyone would be appreciated. Thanks.

Comments are closed.