Note
Click here to download the full example code
MAPDL 2D Beam Example#
This is an example from FINITE ELEMENT ANALYSIS USING ANSYS 11.0
Launch MAPDL with interactive plotting
from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl()
Define an I-beam
mapdl.prep7()
mapdl.et(1, "BEAM188")
mapdl.keyopt(1, 4, 1) # transverse shear stress output
# material properties
mapdl.mp("EX", 1, 2e7) # N/cm2
mapdl.mp("PRXY", 1, 0.27) # Poisson's ratio
# beam properties in centimeters
sec_num = 1
mapdl.sectype(sec_num, "BEAM", "I", "ISection", 3)
mapdl.secoffset("CENT")
beam_info = mapdl.secdata(15, 15, 29, 2, 2, 1) # dimensions are in centimeters
Create nodes within MAPDL
mapdl.n(1, 0, 0, 0)
mapdl.n(12, 110, 0, 0)
mapdl.n(23, 220, 0, 0)
mapdl.fill(1, 12, 10)
mapdl.fill(12, 23, 10)
# list the node coordinates
print(mapdl.mesh.nodes)
# list the node numbers
print(mapdl.mesh.nnum)
# plot the nodes using VTK
mapdl.nplot(vtk=True, nnum=True, cpos="xy", show_bounds=True, point_size=10)

Out:
[[ 0. 0. 0.]
[ 10. 0. 0.]
[ 20. 0. 0.]
[ 30. 0. 0.]
[ 40. 0. 0.]
[ 50. 0. 0.]
[ 60. 0. 0.]
[ 70. 0. 0.]
[ 80. 0. 0.]
[ 90. 0. 0.]
[100. 0. 0.]
[110. 0. 0.]
[120. 0. 0.]
[130. 0. 0.]
[140. 0. 0.]
[150. 0. 0.]
[160. 0. 0.]
[170. 0. 0.]
[180. 0. 0.]
[190. 0. 0.]
[200. 0. 0.]
[210. 0. 0.]
[220. 0. 0.]]
[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23]
create elements between the nodes we can just manually create elements since we know that the elements are sequential
Out:
LIST ALL SELECTED ELEMENTS. (LIST NODES)
*** ANSYS - ENGINEERING ANALYSIS SYSTEM RELEASE 2021 R2 21.2BETA ***
Ansys Mechanical Enterprise
00000000 VERSION=LINUX x64 10:27:36 JUN 01, 2022 CP= 88.669
** WARNING: PRE-RELEASE VERSION OF ANSYS 21.2BETA
ANSYS,INC TESTING IS NOT COMPLETE - CHECK RESULTS CAREFULLY **
ELEM MAT TYP REL ESY SEC NODES
1 1 1 1 0 1 1 2 0
2 1 1 1 0 1 2 3 0
3 1 1 1 0 1 3 4 0
4 1 1 1 0 1 4 5 0
5 1 1 1 0 1 5 6 0
6 1 1 1 0 1 6 7 0
7 1 1 1 0 1 7 8 0
8 1 1 1 0 1 8 9 0
9 1 1 1 0 1 9 10 0
10 1 1 1 0 1 10 11 0
11 1 1 1 0 1 11 12 0
12 1 1 1 0 1 12 13 0
13 1 1 1 0 1 13 14 0
14 1 1 1 0 1 14 15 0
15 1 1 1 0 1 15 16 0
16 1 1 1 0 1 16 17 0
17 1 1 1 0 1 17 18 0
18 1 1 1 0 1 18 19 0
19 1 1 1 0 1 19 20 0
20 1 1 1 0 1 20 21 0
21 1 1 1 0 1 21 22 0
22 1 1 1 0 1 22 23 0
Access them as a list of arrays
See the documentation on mapdl.mesh.elem
for interperting the
individual elements
Out:
[1 1 1 1 0 0 0 0 1 0 1 2 0]
[1 1 1 1 0 0 0 0 2 0 2 3 0]
[1 1 1 1 0 0 0 0 3 0 3 4 0]
[1 1 1 1 0 0 0 0 4 0 4 5 0]
[1 1 1 1 0 0 0 0 5 0 5 6 0]
[1 1 1 1 0 0 0 0 6 0 6 7 0]
[1 1 1 1 0 0 0 0 7 0 7 8 0]
[1 1 1 1 0 0 0 0 8 0 8 9 0]
[ 1 1 1 1 0 0 0 0 9 0 9 10 0]
[ 1 1 1 1 0 0 0 0 10 0 10 11 0]
[ 1 1 1 1 0 0 0 0 11 0 11 12 0]
[ 1 1 1 1 0 0 0 0 12 0 12 13 0]
[ 1 1 1 1 0 0 0 0 13 0 13 14 0]
[ 1 1 1 1 0 0 0 0 14 0 14 15 0]
[ 1 1 1 1 0 0 0 0 15 0 15 16 0]
[ 1 1 1 1 0 0 0 0 16 0 16 17 0]
[ 1 1 1 1 0 0 0 0 17 0 17 18 0]
[ 1 1 1 1 0 0 0 0 18 0 18 19 0]
[ 1 1 1 1 0 0 0 0 19 0 19 20 0]
[ 1 1 1 1 0 0 0 0 20 0 20 21 0]
[ 1 1 1 1 0 0 0 0 21 0 21 22 0]
[ 1 1 1 1 0 0 0 0 22 0 22 23 0]
Define the boundary conditions
Out:
SPECIFIED NODAL LOAD FZ FOR SELECTED NODES 12 TO 12 BY 1
REAL= -22840.0000 IMAG= 0.00000000
run the static analysis
mapdl.run("/solu")
mapdl.antype("static")
print(mapdl.solve())
Out:
***** ANSYS SOLVE COMMAND *****
*** NOTE *** CP = 88.675 TIME= 10:27:36
There is no title defined for this analysis.
*** SELECTION OF ELEMENT TECHNOLOGIES FOR APPLICABLE ELEMENTS ***
---GIVE SUGGESTIONS ONLY---
ELEMENT TYPE 1 IS BEAM188 . KEYOPT(1)=1 IS SUGGESTED FOR NON-CIRCULAR CROSS
SECTIONS AND KEYOPT(3)=2 IS ALWAYS SUGGESTED.
ELEMENT TYPE 1 IS BEAM188 . KEYOPT(15) IS ALREADY SET AS SUGGESTED.
*** ANSYS - ENGINEERING ANALYSIS SYSTEM RELEASE 2021 R2 21.2BETA ***
Ansys Mechanical Enterprise
00000000 VERSION=LINUX x64 10:27:36 JUN 01, 2022 CP= 88.676
** WARNING: PRE-RELEASE VERSION OF ANSYS 21.2BETA
ANSYS,INC TESTING IS NOT COMPLETE - CHECK RESULTS CAREFULLY **
S O L U T I O N O P T I O N S
PROBLEM DIMENSIONALITY. . . . . . . . . . . . .3-D
DEGREES OF FREEDOM. . . . . . UX UY UZ ROTX ROTY ROTZ
ANALYSIS TYPE . . . . . . . . . . . . . . . . .STATIC (STEADY-STATE)
GLOBALLY ASSEMBLED MATRIX . . . . . . . . . . .SYMMETRIC
*** NOTE *** CP = 88.676 TIME= 10:27:36
Present time 0 is less than or equal to the previous time. Time will
default to 1.
*** NOTE *** CP = 88.676 TIME= 10:27:36
The conditions for direct assembly have been met. No .emat or .erot
files will be produced.
L O A D S T E P O P T I O N S
LOAD STEP NUMBER. . . . . . . . . . . . . . . . 1
TIME AT END OF THE LOAD STEP. . . . . . . . . . 1.0000
NUMBER OF SUBSTEPS. . . . . . . . . . . . . . . 1
STEP CHANGE BOUNDARY CONDITIONS . . . . . . . . NO
PRINT OUTPUT CONTROLS . . . . . . . . . . . . .NO PRINTOUT
DATABASE OUTPUT CONTROLS. . . . . . . . . . . .ALL DATA WRITTEN
FOR THE LAST SUBSTEP
SOLUTION MONITORING INFO IS WRITTEN TO FILE= file.mntr
*** NOTE *** CP = 88.682 TIME= 10:27:36
Predictor is ON by default for structural elements with rotational
degrees of freedom. Use the PRED,OFF command to turn the predictor
OFF if it adversely affects the convergence.
Range of element maximum matrix coefficients in global coordinates
Maximum = 2.504767151E+10 at element 22.
Minimum = 2.504767151E+10 at element 22.
*** ELEMENT MATRIX FORMULATION TIMES
TYPE NUMBER ENAME TOTAL CP AVE CP
1 22 BEAM188 0.009 0.000400
Time at end of element matrix formulation CP = 88.6870422.
SPARSE MATRIX DIRECT SOLVER.
Number of equations = 44, Maximum wavefront = 12
Memory allocated for solver = 0.065 MB
Memory required for in-core solution = 0.062 MB
Memory required for out-of-core solution = 0.062 MB
*** NOTE *** CP = 88.691 TIME= 10:27:36
The Sparse Matrix Solver is currently running in the in-core memory
mode. This memory mode uses the most amount of memory in order to
avoid using the hard drive as much as possible, which most often
results in the fastest solution time. This mode is recommended if
enough physical memory is present to accommodate all of the solver
data.
Sparse solver maximum pivot= 5.009534302E+10 at node 8 ROTY.
Sparse solver minimum pivot= 2691965.06 at node 12 UZ.
Sparse solver minimum pivot in absolute value= 2691965.06 at node 12
UZ.
*** ELEMENT RESULT CALCULATION TIMES
TYPE NUMBER ENAME TOTAL CP AVE CP
1 22 BEAM188 0.028 0.001254
*** NODAL LOAD CALCULATION TIMES
TYPE NUMBER ENAME TOTAL CP AVE CP
1 22 BEAM188 0.001 0.000056
*** LOAD STEP 1 SUBSTEP 1 COMPLETED. CUM ITER = 1
*** TIME = 1.00000 TIME INC = 1.00000 NEW TRIANG MATRIX
*** ANSYS BINARY FILE STATISTICS
BUFFER SIZE USED= 16384
0.062 MB WRITTEN ON ASSEMBLED MATRIX FILE: file.full
0.625 MB WRITTEN ON RESULTS FILE: file.rst
stop mapdl
mapdl.exit()
Total running time of the script: ( 0 minutes 0.516 seconds)