MAPDL 2D Beam Example#

This is an example from the book “Finite element analysis using ansys 11.0” by Paletikrishna Chaitanya, Sambanarajesh Kumar, and Datti Srinivas. PHI Learning Pvt. Ltd., 1 Jan 2010.

Launch MAPDL with interactive plotting

from ansys.mapdl.core import launch_mapdl

mapdl = launch_mapdl()
mapdl.fcomp("rst", 0)  # specify compression level
File compression level set to 0 for RST      file(s).

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)
mapdl beam
[[  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

for node in mapdl.mesh.nnum[:-1]:
    mapdl.e(node, node + 1)

# print the elements from MAPDL
print(mapdl.elist())
LIST ALL SELECTED ELEMENTS.  (LIST NODES)
   *****MAPDL VERIFICATION RUN ONLY*****
     DO NOT USE RESULTS FOR PRODUCTION

    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 interpreting the individual elements

for elem in mapdl.mesh.elem:
    print(elem)
[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

# Allow movement only in the X and Z direction
for const in ["UX", "UY", "ROTX", "ROTZ"]:
    mapdl.d("all", const)

# constrain just nodes 1 and 23 in the Z direction
mapdl.d(1, "UZ")
mapdl.d(23, "UZ")

# apply a -Z force at node 12
mapdl.f(12, "FZ", -22840)
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())
*****  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 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.


   *****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   ROTX ROTY ROTZ
   ANALYSIS TYPE . . . . . . . . . . . . . . . . .STATIC (STEADY-STATE)
   GLOBALLY ASSEMBLED MATRIX . . . . . . . . . . .SYMMETRIC

 *** NOTE ***                            CP =       0.000   TIME= 00:00:00
 Present time 0 is less than or equal to the previous time.  Time will
 default to 1.

 *** 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: 22
  ...Number of nodes:    23
  ...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
   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


 *** NOTE ***                            CP =       0.000   TIME= 00:00:00
 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 0.
 Minimum = 2.504767151E+10 at element 0.

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

        1        22  BEAM188       0.000   0.000000
 Time at end of element matrix formulation CP = 0.

 DISTRIBUTED SPARSE MATRIX DIRECT SOLVER.
  Number of equations =          44,    Maximum wavefront =      0
  Memory available (MB) =    0.0    ,  Memory required (MB) =    0.0

 Distributed sparse solver maximum pivot= 0 at node 0 .
 Distributed sparse solver minimum pivot= 0 at node 0 .
 Distributed sparse solver minimum pivot in absolute value= 0 at node 0
 .

   *** ELEMENT RESULT CALCULATION TIMES
     TYPE    NUMBER   ENAME      TOTAL CP  AVE CP

        1        22  BEAM188       0.000   0.000000

   *** NODAL LOAD CALCULATION TIMES
     TYPE    NUMBER   ENAME      TOTAL CP  AVE CP

        1        22  BEAM188       0.000   0.000000
 *** LOAD STEP     1   SUBSTEP     1  COMPLETED.    CUM ITER =      1
 *** TIME =   1.00000         TIME INC =   1.00000      NEW TRIANG MATRIX

Stop mapdl#

mapdl.exit()

Total running time of the script: (0 minutes 0.688 seconds)