All Things Ansys 066: Simulation Automation & Optimization management with Ansys optiSLang


Published on: June 29th, 2020
With: Eric Miller & Josh Stout

In this episode your host and Co-Founder of PADT, Eric Miller is joined by PADT’s systems application & support engineer Josh Stout to look at the optimization tool optiSLang. This tool helps automate simulation and optimization activities across various solution areas, such as autonomy, electrification, digital twins, and more, as well as how it enables users to capitalize on the benefits of enterprise simulation management.

If you would like to learn more, you can view the product brochure here:

If you have any questions, comments, or would like to suggest a topic for the next episode, shoot us an email at we would love to hear from you!


This is also a perfect example of how a customer can hand over an entire project that they need done, but don’t have the resources to do in-house. PADT’s team created the test specification, designed the hardware, conducted the tests, and delivered actionable information to the customer.

If you have a project you do not have the resources to complete in-house, consider having our engineers take a look at it to see how we can help.

Serial and Parallel ANSYS Mechanical APDL Simulations

ANSYS-APDL-Macro-PeDALThere are times when you want to study the effects of varying parameters.  If you have an existing MAPDL script that is parameterized, the following procedure will allow you to easily run many variations in an organized manner. 

Let’s assume a parameterized MAPDL macro called build_solve that does something you want to simulate many times and has 2 variables called power and scale which are set with argument 1 and 2 respectively.  Running this macro with the classic interface, with power=30 and scale=2.5 would look like this:


Next, create a MAPDL macro to launch all of the simulations.  This script could be named control.mac.  The first thing to do here is to create arrays of your parameters and assign values to them.  This example will vary power and scale.  Here are the arrays of values that will be passed to build_solve:





Most of the control.mac commands will be put inside of nested *do loops.  There will be a *do loop for each of parameters being varied.



Next, use *cfopen to set up the arguments to be passed to build_solve.  Each time through the *do loops will create a new run1.mac







One of the key features of this approach is to run anywhere and build directories below the working directory.  Use the /inquire command to store the current directory name.


Use *cfopen to create a string that will be used for the directory name.  By using the variables as part of the string, the directories will have unique names.  A time or date stamp could also be included in this string.  This macro is executed immediately to create the string dirnam for use in the commands subsequently.







Eventually, the resulting directory structure will look something like the image below.  Each directory will contain a separate simulation with the arguments of power and scale set respectively.


The last *cfopen creates a windows batch file which will (when executed)

  1. Create the new directory

  2. Copy all of the macro files from the working directory into the new directory (including run1.mac)

  3. Change into the new directory using CD

  4. Launch ansys in batch mode, in this case using a gpu and 12 cpus, using the run1.mac input and outputting to f.out

  5. Change back to the working directory (ready to do it all again)

The code for the windows batch file is:





COPY *.mac "%C\%S"


CD "%C\%S"


"C:\Program Files\ANSYS Inc\v150\ansys\bin\winx64\ansys150" -b -acc nvidia -np 12 -i run1.mac -o f.out


CD "%C"


The last step is to run the windows batch file.  /sys is used to make this system call.  If the simulation is not well parallelized and you have enough licenses available, run the simulations in low priority mode immediately.  This will launch all of your simulations in parallel:

  • /sys,start /b /low rfile.bat

If the model is well parallelized (in other words, it will use your system’s gpu/cpus/RAM efficiently) or you only have 1 license available, launch the batch files in high priority mode and use the /wait option which will insure that windows waits for the job to finish before launching the next simulation.

  • /sys,start /b /high /wait rfile.bat

You can download and view the examples control.mac and build_solve.mac from this zip file: