APDL is a scripting language that is used to drive the MAPDL program, and it supports all the actions that MAPDL can perform.
As with any scripting language, there are some rules related to syntax and usage that are important to understand.
In this video, we will Introduce the basics of APDL language
Discuss the hierarchy of the APDL command groupings
Define and use scalar parameters
And we will write a simple APDL script and execute it in batch mode.
Let’s get started!
An APDL script consists of a series of commands that supply data or instructions to the MAPDL program.
Each command begins with the command name followed by alphanumeric arguments that are comma-separated.
In most commands, the arguments have some defaults that the program assumes.
While passing commands with defaults, it suffices to leave it blank, but the commas should be supplied to indicate the position where defaults are used.
For instance, here’s the ET command, which is used to define an element type.
This is the syntax for this command, the second argument ITYPE is a local element-type number, and it is an integer data type.
By default, it is set to the maximum local element type number plus 1.
So, if you wish to use the default value you may provide the command as ET,,SOLID186 (which is an element name).
Also, note that there are other arguments for this command beyond Ename.
When we don’t specify their values in the command, defaults are assumed where applicable.
If there are no defaults for those arguments, then the program will issue an error message as feedback.
MAPDL interprets up to the first four unique characters of a command name, so a command EALIVE is interpreted in the same way as EALI.
There are two ways of adding comments to an APDL script.
One way is to add an exclamation mark in front of the line – anything followed by this line is ignored and not executed by the program.
Another way to add comments is to use the command /COM,
and any text followed by this command are not executed but they are echoed in the output file or the output window,
which is useful if you wanted to provide some feedback of your APDL script back to the user.
All commands are case insensitive; however, in this course we will follow a standard that’s consistent with the help documentation.
Re-visiting the command ET, this is how it is indicated in the documentation.
The command names are indicated in bold upper case.
Arguments that require numeric input, such as ITYPE, are indicated in upper case.
Arguments that require alphanumeric input are indicated in upper-lower case italics.
We’ll follow the same styling convention for the rest of the course.
The hierarchy of MAPDL program is into two levels, 1) a Begin level, and 2) the processors.
Begin is the primary level at which the program starts with, and each processor is a collection of related functions.
For instance, these are the four commonly used processors:
/PREP7 includes APDL commands such as geometry and mesh generation, defining element and material properties, and applying loads & boundary conditions that fall under the pre-processing stage of model development.
/SOLU includes program controls to apply load & boundary conditions and to solve the model.
Notice that loads and boundary conditions can be applied in /PREP7 or /SOLU, but the actual act of solving takes place here.
/POST1 includes commands that perform general post-processing of results from the database.
This usually involves generating contour plots or listing of results for the entire model at a specific instance of time or frequency.
/POST26 is the time-history post-processor, used to review results at specific nodes or elements throughout the time or frequency domain.
One can enter a processor by issuing the session command and return to the Begin level by issuing FINISH command.
Typically, commands that belong to one processor are not recognized in another processor.
For instance, SPHERE is a command in PREP7 used for creating a sphere of a given radius at a user-specified location.
If this command is issued in, say, the solution processor SOLU, the program issues an error that the command is not recognized.
Note that there are some commands that are recognized in more than one processor and there are several commands that are recognized in all processors.
Before using a command, it's important to know its syntax, the processor in which it is recognized as a valid command, the default values of the arguments, and the licenses required.
There are over 2000+ commands supported by MAPDL and its not practical to keep track of such intricate details of all of them.
Due to this reason, we highly recommend referring to the Command Reference in Help while writing APDL scripts.
The help manual provides all the supported commands indexed both via Command Groupings and also alphabetically.
This is what the help manual for a command looks like:
one can check its syntax and all the available arguments,
the processor level at which it is recognized,
the licenses that support the command,
the acceptable inputs for arguments and their defaults, and
other notes that are relevant to its usage.
That concludes the discussion on the basics of the APDL language; now, let’s learn about defining and using scalar parameters.
One of the hallmarks of APDL scripting is the ability to define and use parameters in performing finite element analysis.
Parameters are APDL variables that can be used in mathematical operations and used as input arguments in APDL commands.
APDL supports two types of parameters, 1) scalar and 2) array parameters. Both the variables can either be numeric or character parameters.
In this video, we’ll limit our discussion to scalar parameters.
While defining parameters, their names must begin with a letter, but they may contain letters, numbers, or an underscore character.
Other symbolic characters are not allowed, and the length of the parameter name cannot exceed 32 characters.
There are two ways for defining parameters: using *SET commands such as this to create a parameter A whose value is 1.
Alternatively, one can issue the line A=1 to perform the same action.
One can also update the parameters, meaning, say we have A=1 and B=2, then issuing A=B will re-set the value of A to be 2.
However, setting A=1, B=A and then setting A=2 does not affect the value of B.
If we wish to delete a variable, we could either use *SET or use the equality operator and set the value of the parameter to an empty argument.
Using parameters, one can also define parametric expressions using different arithmetic operations.
There are also several mathematical functions supported by MAPDL that can be used to create parametric expressions.
Using this knowledge, now let’s develop a simple APDL script and execute it in batch mode via the MAPDL Product Launcher.
The demo problem we’ll tackle today is to calculate the moment of inertia of a rectangular plate with a circular hole at the center, about its axis.
In this demo, we will define the height, width and thickness of the plate, the radius of the hole and the mass density of the material as the parameters.
Using this information, one can compute the moment of inertia of this geometry using this relation, where the first terms represent the moment of inertia of the plate without a hole, and we subtract the moment of inertia of a cylinder to account for the hole.
Before we begin writing the script, it’s good practice to develop a flowchart and then write the script for each portion.
For this example, here’s the flow chart:
We start the program; we then define the height, width, and thickness of the plate, then use this information to calculate the volume of the plate.
We then define the radius of the hole and calculate the volume of the cylindrical hole.
Next, we define the mass density of the material.
Now we can compute the moment of inertia of the plate without the hole and the moment of inertia of cylinder, and therefore calculate the moment of inertia of the plate with a hole.
Then we can exit the program which is the end of our flow chart.
Now that we have the process lined up, let’s use the appropriate commands for each step.
We’ll start with the commands FINISH and /CLEAR; it’s good practice to do this especially if we’re working on an existing MAPDL session to leave any processor we were previously working on and to clear all the database variables to start a fresh session.
Note that using these two commands will not prompt you to save any work you currently have in your MAPDL session, so it’s important to save any existing work beforehand.
Next, we can define the dimensions of the plate using the equality operators.
It’s good practice to document this operation using a comment, so when we or someone else reviews the script, they know what to expect.
In this example, let’s define a square plate of length 5 and thickness 1 unit.
Now, we can calculate the volume of the plate, and let’s make a note of this as a comment, then use the multiplicative operator between the three parameters.
Similarly, define the radius of the hole - don’t forget to comment the action - and calculate the volume of the cylinder.
We’ll use the exponentiation operator to define R squared in this relation.
One last parameter to define before we proceed is the mass density of the material; we’ll set it to 2500 in this example.
Now, let’s proceed to calculating the moment of inertia of the plate without a hole and the cylinder and finally calculate that of a plate with the hole.
That finishes the objective of this script, so we can exit the program using /EXIT command.
Note that in this script we have not indicated the units for any of the parameters.
This is because MAPDL is agnostic to units, and it interprets all numeric parameters simply as dimensionless numbers.
So, users must exercise caution when defining all parameters in a consistent unit system.
Now let's save this script as a text file with an extension .inp in a local directory.
To execute this script, let’s open the MAPDL product launcher from the start menu.
In the product launcher, change the simulation environment to ANSYS Batch from the drop-down menu.
This changes the options available in the File Management tab.
Over here, define a working directory to a location on your local drive, define a jobname - in this case we’ll use MyFirstScript_ - browse and locate the .inp file we saved earlier as the input file, and define a output file - we’ll use the default name in this example.
Now hit run to execute the program.
As you can see, the MAPDL program does not show up, but if you monitor the working directory, you’ll notice that several files are being generated which implies that the MAPDL program is executing our script.
Once it finishes running the script, the output file is created where all the output is stored.
Let’s inspect it using a text editor.
As we scroll down, we can see all the commands, and the output is provided.
All the input parameters and their assigned values are shown, and the values of calculated volumes and moments of inertia are also stored as parameters.
It’s worth noting that all the operations performed in this script are at the Begin level, as we have not entered any processors.
So, in summary, we have created a script that takes the dimensions of the plate and the hole and the mass density of the material as input parameters and calculates the moment of inertia of the plate with a hole as an output parameter.
Now we may change the input parameters and update the moment of inertia by re-running this script, which is useful in automating design iterations.
To conclude the video, let's revise a few points:
APDL is a scripting language that is used to drive the MAPDL program.
It’s used for pre- and post-processing and for defining solver controls.
In addition, we can also define and use different parameters to perform arithmetic and mathematical calculations.
One can save a script to a text file and either run it interactively via the MAPDL GUI or via batch run with no user intervention.
This concludes the video, thank you for watching.