Quick Tip: Concatenating Text Files Using ANSYS Mechanical APDL

So you have text output from some ANSYS analysis and you wish you could just do this:

cat lift.txt  cop.txt drag.txt >> results.txt

and you are writing an ANSYS macro and want it to run on all platforms.  The following macro will use APDL commands to join the files together. 



















Bonus: If you want to strip some lines off of the top or read less than all the lines, you can pass additional arguments to *sread:






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: build_solve-control-macros.zip

Checking Hyper-Elastic Material Models

non-linear-thumbWhen using hyper-elastic materials, analyst often have little material data to assist them. Fortunate engineers will have a tensile stress-strain curve; a lucky few will also have a simple shear stress-strain curve as well. Where do you start?

To gain confidence in the procedure which is typically used, a set of FEA models were run in a closed loop. The loop consists of assuming some material parameters, running FEA models based upon those parameters, and then using the FEA results to recover the material parameters using ANSYS’s built in hyper-elastic curve fitting.

To isolate the material model from boundary conditions effects, simple FEA models that are 3D but have 1D stress states are used. The figures below show tensile and shear models that can be used to verify material models.

For this article, a 2 Parameter Mooney-Rivlin material model with values consistent with typical Imperial units was selected. The figure below shows the data entry including a value of zero for d which indicates that the material is fully incompressible.

The tensile test FEA model was run with this 2 parameter MR model. The engineering stress-strain results were extracted from the results using /post26 APDL. The results are graphed and listed in the figure below. We use APDL because there are some calculations involved with getting engineering results. For example, the engineering stress was calculated by dividing the reaction force at node n1 by the original area like this:

QUOT,3,2, , , , , ,-1/area_,1,

cs3This test data was then used in ANSYS’s curve fitting routine. The results of the curve fitting are shown below. The parameters from the curve fitting results are < 0.01% different than the assumed inputs. This is a reassuring result. Note that this is one instance in ANSYS that you are required to use engineering data (for hyper-elastic curve fitting only).

In recent versions of ANSYS, a hyper-elastic response function was introduced. This allows the user to enter the test data and use it without curve fitting. The figure below shows how uniaxial tension test data is entered and the response function activated to use it.

As expected, the response function matched the /post26 output exactly. This method offers a clear advantage in that the user doesn’t need to assume a material model.

The next step in this verification process was to run some simple shear FEA models to compare the curve fitting results. The plot below shows the engineering shear stress-strain curve using the 2 parameter MR model from above.

The data was curve fitted as shown in the figure below. This time both the uniaxial tension and simple shear data are entered. The resulting 2 parameter model differs (<2%) from the entered model.

These new values were used in the FEA models. As shown in the figures below, the change in material parameters (<2%) did not significantly change the tensile or shear stress-strain results (<1%). This raises some interesting questions regarding the 2 parameter MR model that will be explored at a later date.