Note
Click here to download the full example code
MAPDL 3D Beam Example#
This is a simple example that loads an archive file containing a beam
and then runs a modal analysis using the simplified modal_analysis
method.
First, start by launching MAPDL as a service.
from ansys.mapdl.reader import examples
from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl()
# load a beam stored as an example archive file and mesh it
mapdl.cdread("db", examples.hexarchivefile)
mapdl.esel("s", "ELEM", vmin=5, vmax=20)
mapdl.cm("ELEM_COMP", "ELEM")
mapdl.nsel("s", "NODE", vmin=5, vmax=20)
mapdl.cm("NODE_COMP", "NODE")
# boundary conditions
mapdl.allsel()
# dummy steel properties
mapdl.prep7()
mapdl.mp("EX", 1, 200e9) # Elastic moduli in Pa (kg/(m*s**2))
mapdl.mp("DENS", 1, 7800) # Density in kg/m3
mapdl.mp("NUXY", 1, 0.3) # Poissons Ratio
mapdl.emodif("ALL", "MAT", 1)
# fix one end of the beam
mapdl.nsel("S", "LOC", "Z")
mapdl.d("all", "all")
mapdl.allsel()
# plot the boundary conditions
mapdl.nplot(plot_bc=True)

mapdl.mxpand(elcalc="YES")
mapdl.modal_analysis(nmode=6)
Out:
***** ANSYS SOLVE COMMAND *****
*** NOTE *** CP = 88.199 TIME= 10:27:34
There is no title defined for this analysis.
*** SELECTION OF ELEMENT TECHNOLOGIES FOR APPLICABLE ELEMENTS ***
---GIVE SUGGESTIONS ONLY---
ELEMENT TYPE 1 IS SOLID186. KEYOPT(2) IS ALREADY SET AS SUGGESTED.
*** ANSYS - ENGINEERING ANALYSIS SYSTEM RELEASE 2021 R2 21.2BETA ***
Ansys Mechanical Enterprise
00000000 VERSION=LINUX x64 10:27:34 JUN 01, 2022 CP= 88.200
** 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
ANALYSIS TYPE . . . . . . . . . . . . . . . . .MODAL
EXTRACTION METHOD. . . . . . . . . . . . . .BLOCK LANCZOS
NUMBER OF MODES TO EXTRACT. . . . . . . . . . . 6
GLOBALLY ASSEMBLED MATRIX . . . . . . . . . . .SYMMETRIC
NUMBER OF MODES TO EXPAND . . . . . . . . . . .ALL
ELEMENT RESULTS CALCULATION . . . . . . . . . .ON
*** NOTE *** CP = 88.200 TIME= 10:27:34
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
THERMAL STRAINS INCLUDED IN THE LOAD VECTOR . . YES
PRINT OUTPUT CONTROLS . . . . . . . . . . . . .NO PRINTOUT
DATABASE OUTPUT CONTROLS. . . . . . . . . . . .ALL DATA WRITTEN
*********** PRECISE MASS SUMMARY ***********
TOTAL RIGID BODY MASS MATRIX ABOUT ORIGIN
Translational mass | Coupled translational/rotational mass
39000. 0.0000 0.0000 | 0.0000 97500. -19500.
0.0000 39000. 0.0000 | -97500. 0.0000 19500.
0.0000 0.0000 39000. | 19500. -19500. 0.0000
------------------------------------------ | ------------------------------------------
| Rotational mass (inertia)
| 0.33800E+06 -9750.0 -48750.
| -9750.0 0.33800E+06 -48750.
| -48750. -48750. 26000.
TOTAL MASS = 39000.
The mass principal axes coincide with the global Cartesian axes
CENTER OF MASS (X,Y,Z)= 0.50000 0.50000 2.5000
TOTAL INERTIA ABOUT CENTER OF MASS
84500. -0.92371E-11 -0.79876E-10
-0.92371E-11 84500. -0.32069E-10
-0.79876E-10 -0.32069E-10 6500.0
The inertia principal axes coincide with the global Cartesian axes
*** MASS SUMMARY BY ELEMENT TYPE ***
TYPE MASS
1 39000.0
Range of element maximum matrix coefficients in global coordinates
Maximum = 9.116809117E+10 at element 32.
Minimum = 9.116809117E+10 at element 4.
*** ELEMENT MATRIX FORMULATION TIMES
TYPE NUMBER ENAME TOTAL CP AVE CP
1 40 SOLID186 0.010 0.000252
Time at end of element matrix formulation CP = 88.2154617.
BLOCK LANCZOS CALCULATION OF UP TO 6 EIGENVECTORS.
NUMBER OF EQUATIONS = 900
MAXIMUM WAVEFRONT = 174
MAXIMUM MODES STORED = 6
MINIMUM EIGENVALUE = 0.00000E+00
MAXIMUM EIGENVALUE = 0.10000E+31
Memory allocated for solver = 2.263 MB
Memory required for in-core solution = 2.159 MB
Memory required for out-of-core solution = 1.369 MB
*** NOTE *** CP = 88.270 TIME= 10:27:34
The Sparse Matrix Solver used by the Block Lanczos eigensolver 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.
*** ANSYS - ENGINEERING ANALYSIS SYSTEM RELEASE 2021 R2 21.2BETA ***
Ansys Mechanical Enterprise
00000000 VERSION=LINUX x64 10:27:34 JUN 01, 2022 CP= 88.321
** WARNING: PRE-RELEASE VERSION OF ANSYS 21.2BETA
ANSYS,INC TESTING IS NOT COMPLETE - CHECK RESULTS CAREFULLY **
*** FREQUENCIES FROM BLOCK LANCZOS ITERATION ***
MODE FREQUENCY (HERTZ)
1 32.13951614478
2 32.13951614483
3 145.4783895431
4 173.4557943042
5 173.4557943042
6 254.8511237205
*** ANSYS BINARY FILE STATISTICS
BUFFER SIZE USED= 16384
0.750 MB WRITTEN ON ASSEMBLED MATRIX FILE: file.full
0.062 MB WRITTEN ON MODAL MATRIX FILE: file.mode
0.312 MB WRITTEN ON RESULTS FILE: file.rst
View the results using the pyansys result object
result = mapdl.result
print(result)
Out:
PyMAPDL Result
Units : User Defined
Version : 21.2
Cyclic : False
Result Sets : 6
Nodes : 321
Elements : 40
Available Results:
EMS : Miscellaneous summable items (normally includes face pressures)
ENF : Nodal forces
ENS : Nodal stresses
ENG : Element energies and volume
EEL : Nodal elastic strains
ETH : Nodal thermal strains (includes swelling strains)
EUL : Element euler angles
EPT : Nodal temperatures
NSL : Nodal displacements
RF : Nodal reaction forces
Access nodal displacement values
Out:
50 [-0.00118414 0.00208919 0.00134271]
51 [-0.00143623 0.00255233 0.00144392]
52 [-0.00170491 0.00304514 0.00153097]
53 [-0.00198766 0.00356303 0.0016043 ]
54 [-0.00228208 0.00410167 0.00166479]
55 [-0.00258591 0.00465688 0.00171318]
56 [-0.00289709 0.00522485 0.00175064]
57 [-0.00321369 0.00580202 0.00177814]
58 [-0.00353406 0.00638538 0.00179711]
59 [-0.00385671 0.00697215 0.00180876]
Plot a modal result
result.plot_nodal_displacement(0, show_edges=True)

Animate a modal result result.animate_nodal_solution(0, show_edges=True, loop=False, displacement_factor=10, movie_filename=’demo.gif’)
stop mapdl
mapdl.exit()
Total running time of the script: ( 0 minutes 0.900 seconds)