There 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)
Create the new directory
Copy all of the macro files from the working directory into the new directory (including run1.mac)
Change into the new directory using CD
Launch ansys in batch mode, in this case using a gpu and 12 cpus, using the run1.mac input and outputting to f.out
Change back to the working directory (ready to do it all again)
The code for the windows batch file is:
COPY *.mac "%C\%S"
"C:\Program Files\ANSYS Inc\v150\ansys\bin\winx64\ansys150" -b -acc nvidia -np 12 -i run1.mac -o f.out
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: build_solve-control-macros.zip