Tech Tips_Ansys_Matlab

Supercharge your system simulations with the ANSYS MATLAB Toolbox

kaan-80x80One of the most exciting features in the latest release is something that’s not getting much publicity: running MAPDL (or ANSYS Classic) as a headless server. Okay, I can see why people may not be too excited by that but it allows you to run Mechanical APDL with whatever user interface you want, for example – MATLAB. With the MATLAB toolbox you can to run ANSYS, the number one FEA solver in the world, like any other module in MATLAB. This opens up all kinds of possibilities for co-simulation with ANSYS and MATLAB, taking your integrative and system simulations to the next level.

This is not just a more sophisticated way to send batch files to Ansys MAPDL, you can send commands and receive output from a running Ansys FEA solver:

>> mapdl.executeCommandToString('asel,s,mat,,6')

ans =

SELECT       FOR ITEM=MAT  COMPONENT=\n  IN RANGE         6 TO          6 STEP          1\n\n

You can interrogate parameters:

>> str = mapdl.executeCommandToString('*get,max_x,node,,mxloc,x')

str =

*GET MAX_X FROM NODE ITEM=MXLO X VALUE= 500.000000

>> exp = 'VALUE= ([^\s]+)'

exp =

VALUE= ([^\s]+)

>> m = regexp(char(str),exp,'tokens')

m =

{1x1 cell}

>> str2double(char(m{:}))

ans =

500

You can execute commands using Matlab control logic:

 >> loads

loads = 

1x2 struct array with fields:

 cmsel
 val

>> for elem = loads
mapdl.executeCommandToString(strcat('d,', elem.cmsel,',uy,',num2str(elem.val)))

ans =

SPECIFIED CONSTRAINT UY FOR PICKED NODES\n REAL= 300.000000 IMAG= 0.00000000

ans =

SPECIFIED CONSTRAINT UY FOR PICKED NODES\n REAL= 0.00000000 IMAG= 0.00000000

Writing data files is still handled by batch files but MATLAB easily reads and works with comma separated data files:

>> type('to_outf.inp')

*cfopen,outputs,csv
*vwrite,
("plwk_top, plwk_bot")
*vwrite,plwkData(1,1), plwkData(1,2)
(E16.8, "," E16.8)
*cfclos

>> mapdl.executeCommand('/inp,to_outf,inp')

>> tab = readtable('outputs.csv')

tab =

plwk_top plwk_bot
________ ________

0.013099 0.010709
0.025962 0.021216

And of course there are all the plotting and visualization functionality that you are used to:

bar3(table2array(tab))

MatlabFigure

You can similarly interface with Workbench and Fluent with this toolbox.

We are pleased to make this ANSYS Matlab Toolbox available early for our customers (please log in):

Download ANSYS Matlab Toolbox

If you are not a customer, we can offer this as premium content: