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 3d beam
mapdl.mxpand(elcalc="YES")
mapdl.modal_analysis(nmode=6)
*****  MAPDL SOLVE    COMMAND  *****

 *** NOTE ***                            CP =       0.000   TIME= 00:00:00
 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.


   *****MAPDL VERIFICATION RUN ONLY*****
     DO NOT USE RESULTS FOR PRODUCTION

                       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 =       0.000   TIME= 00:00:00
 The conditions for direct assembly have been met.  No .emat or .erot
 files will be produced.



     D I S T R I B U T E D   D O M A I N   D E C O M P O S E R

  ...Number of elements: 40
  ...Number of nodes:    321
  ...Decompose to 0 CPU domains
  ...Element load balance ratio =     0.000


                      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.54570E-11  -0.14552E-10
       -0.54570E-11    84500.      -0.29104E-10
       -0.14552E-10  -0.29104E-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 0.
 Minimum = 9.116809117E+10 at element 0.

   *** ELEMENT MATRIX FORMULATION TIMES
     TYPE    NUMBER   ENAME      TOTAL CP  AVE CP

        1        40  SOLID186      0.000   0.000000
 Time at end of element matrix formulation CP = 0.

  BLOCK LANCZOS CALCULATION OF UP TO     6 EIGENVECTORS.
  NUMBER OF EQUATIONS              =          900
  MAXIMUM WAVEFRONT                =            0
  MAXIMUM MODES STORED             =            6
  MINIMUM EIGENVALUE               =  0.00000E+00
  MAXIMUM EIGENVALUE               =  0.10000E+31

  Memory available (MB) =    0.0    ,  Memory required (MB) =    0.0

   *****MAPDL VERIFICATION RUN ONLY*****
     DO NOT USE RESULTS FOR PRODUCTION

 *** FREQUENCIES FROM BLOCK LANCZOS ITERATION ***

  MODE    FREQUENCY (HERTZ)


    1     32.13951614478
    2     32.13951614482
    3     145.4783895431
    4     173.4557943042
    5     173.4557943042
    6     254.8511237205

View the results using the pyansys result object

result = mapdl.result
print(result)
PyMAPDL Result
Units       : User Defined
Version     : 24.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

nnum, disp = result.nodal_displacement(0)

# print the nodes 50 - 59
for i in range(49, 59):
    print(nnum[i], disp[i])
50 [-0.0014446   0.00192484  0.00138213]
51 [-0.00175672  0.00234895  0.00148631]
52 [-0.00208918  0.00280034  0.00157592]
53 [-0.00243886  0.0032748   0.0016514 ]
54 [-0.00280283  0.00376836  0.00171367]
55 [-0.00317827  0.00427718  0.00176348]
56 [-0.00356262  0.00479779  0.00180204]
57 [-0.00395349  0.00532693  0.00183035]
58 [-0.00434885  0.00586184  0.00184988]
59 [-0.00474683  0.00639997  0.00186187]

Plot a modal result

result.plot_nodal_displacement(0, show_edges=True)
mapdl 3d beam

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 1.423 seconds)