How to run scripts in APDL
Scrips in APDL are usually executed by the use of one of two methods. The first method is to write (or copy & paste) your code directly into the command window available in APDL.
The other method is to read in an input file (txt file) containing your script. To do this, go to File → Read Input From, select the correct file form the menu and click OK.
When locating the correct file, you will often notice that APDL by default opens the wrong directory (e.g. C:USERS when you actually want ../Marine Konstruksjoner/Exercise 7). To fix this, we need to open APDL with our chosen working directory. We may do so by first opening the ANSYS Mechanical APDL Product Launcher and then choose the correct working directory before clicking Run.
Introduction to APDL commands
Although many APDL commands are similar to what we are familiar with from other programming languages, very few have the exact same syntax. This means that to fully understand your code, and to further improve it, you will have to read the APDL commands documentation.
The easiest way to locate the correct documentation is to open Mechanical APDL and click Help → Help Topics. Since we will focus on the scripting part of APDL, the Command reference documentation is the most relevant to us.
As a first example, we would like to obtain the stresses in the node located in the point (L/2, X/2) and write them into our file answers.txt, given the plate below.
The following script includes some simple comments for most commands, but to truly understand the code, we highly recommend you to search them up in the Command Reference as well.
The following result file will then be created.
Meshsize XX YY XY Von Mise 0.100E-01 0.481E+08 0.500E+06 -0.686E+05 0.479E+08
Loops and statements in APDL?
When doing FEM-analyses, we are often looking to locate e.g. how large our load is before buckling or how small the mesh size has to be before the results converges. If we were to do these tasks manually, it would take forever, and it is for that reason APDL has included loops and statements.
As an example, let's do the analysis presented in the previous section, but for mesh size = 0.20 to mesh size = 0.01 with a step size of 0.01.