Introduction to Ansys APDL Programming — Easy Hand-on Bar Example of Learning APDL

Johnny Chen
3 min readJun 9, 2022

The first Finite Element (FE) commercial software I learn is Ansys Workbench, and it is quite intuitive to me to get hand on it for the beautiful user interface, very powerful CAD software-SpaceClaim. Mesh setting and imposing boundary condition are also not that hard for me at the time, but when I first approach to APDL (ANSYS Parametric Design Language), it surprise me in a way that how Ansys code work in behind and makes me want to explore more about where Ansys started it.

Beautiful sunset at McGraw Tower, Cornell University

The quick outline of the hand-on APDL, MAPDL, involves following tasks:

  • Create geometry in the preprocessor (/PREP7 )
  • Define material properties and element attributes (For mechanical analysis: Poisson’s ratio, density, elastic modulus. For element attribute such as element types)
  • Mesh the model (Global and local mesh are allowed)
  • Impose Dirichlet Boundary Conditions and Neuman Boundary Conditions (that is, boundary conditions and loads)
  • Solve for displacement (/SOLVE)
  • Post-processing to obtain nodal solution and result plots (/POST1)

After knowing the outline of the APDL, we can now start to devise the problem that we are going to tackle. For this tutorial, I am going to start with a bar question: with one fixed-ended boundary conditions and another has an applied load.

Applied a load on green side of the bar, and clamp another side of the bar (orange)
! Clear the previous result 
FINISH
/CLEAR
/PREP7
! Element type and material properties
ET, 1, 187 ! ElementType, 1, ElementTypeNumber
MP, EX, 1, 10E6 ! Material Properties: Young's Modulus
MP, NUXY, 1, .3 ! Material Properties: Poisson's ratio
! Geometry and element type
BLOCK, 0, 10, 0, 100, 0, 10
! Volumne mesh
VMESH, ALL
! APPLY BOUNDARY CONDITION: Clamp one end (coordinate origin)
NSEL, S, LOC, Y, 0
D, ALL, ALL, 0
! APPLIED LOAD: Load on another end
NSEL, S, LOC, Y, 100 ! Select Y direction 100 side
NSEL, ALL, FY, 100 ! Select all points on the plane
ALLSEL
FINISH ! Solution
/SOLU
/STATUS, SOLU
SOLVE
FINISH
! Post-processing
/POST1
PLNSOL, U, SUM, 0, 1 ! Solve for displacement
Solution derived from the above code

One command that I found very useful if we import geometry (.IGES) file from SOLIDWORK or import Mesh file (.CDB) file from WORKBENCH, the node dimension might change. Therefore, it’s important for us to know the distance between the node, by using the command NDIST(P) we are able to manually select the nodes that we node and obtain the distance between them.

By using DIST(P) command, we are able to manually select the nodes and obtain the distance

Some useful tutorial links:

  1. https://www.youtube.com/c/FemExpert
  2. https://www.youtube.com/watch?v=qx69C-UyxsE&list=PLtt6-ZgUFmMKFfbOBhmCwG30KIVyvhDop
  3. https://courses.ansys.com/index.php/courses/intro-to-ansys-mechanical-apdl-scripting/

Thank you for your reading, I hope this helps a bit to your Ansys APDL study!

--

--