MAPDL 2D Beam#

本例来自 Paletikrishna Chaitanya、Sambanarajesh Kumar 和 Datti Srinivas 合著的 “Finite element analysis using ansys 11.0” 一书。PHI Learning Pvt. Ltd., 1 Jan 2010.

启动具有交互式绘图功能的 MAPDL

from ansys.mapdl.core import launch_mapdl

mapdl = launch_mapdl()
mapdl.fcomp("rst", 0)  # 指定压缩级别
File compression level set to 0 for RST      file(s).

定义工字钢

mapdl.prep7()
mapdl.et(1, "BEAM188")
mapdl.keyopt(1, 4, 1)  # 横向剪应力输出

# 材料特性
mapdl.mp("EX", 1, 2e7)  # N/cm2
mapdl.mp("PRXY", 1, 0.27)  #  Poisson's ratio

# 以厘米为单位的梁特性
sec_num = 1
mapdl.sectype(sec_num, "BEAM", "I", "ISection", 3)
mapdl.secoffset("CENT")
beam_info = mapdl.secdata(15, 15, 29, 2, 2, 1)  # 尺寸单位为厘米

在 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)

# 列出节点坐标
print(f'节点坐标为: {mapdl.mesh.nodes}')

# 列出节点编号
print(f'节点编号为: {mapdl.mesh.nnum}')

# 使用 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]

在节点之间创建单元 我们可以手动创建单元,因为我们知道单元是连续的

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

# 打印来自 MAPDL 的单元
print(mapdl.elist())
LIST ALL SELECTED ELEMENTS.  (LIST NODES)

 *** MAPDL - ENGINEERING ANALYSIS SYSTEM  RELEASE 2023 R1          23.1     ***
 Ansys Mechanical Enterprise
 20120530  VERSION=WINDOWS x64   13:01:43  JAN 25, 2024 CP=      0.844





    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

以数组的形式访问它们 请参阅有关 mapdl.mesh.elem 的文档,了解如何解释各个单元

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]

定义边界条件

# 只允许在 X 和 Z 方向移动
for const in ["UX", "UY", "ROTX", "ROTZ"]:
    mapdl.d("all", const)

# 只限制 Z 方向上的节点 1 和 23
mapdl.d(1, "UZ")
mapdl.d(23, "UZ")

# 在节点 12 上施加 -Z 方向的力
mapdl.f(12, "FZ", -22840)
SPECIFIED NODAL LOAD FZ   FOR SELECTED NODES        12 TO       12 BY        1
  REAL= -22840.0000       IMAG=  0.00000000

运行静态分析

mapdl.run("/solu")
mapdl.antype("static")
print(mapdl.solve())
*** NOTE ***                            CP =       0.859   TIME= 13:01:44
 The automatic domain decomposition logic has selected the MESH domain
 decomposition method with 2 processes per solution.

 *****  MAPDL SOLVE    COMMAND  *****

 *** NOTE ***                            CP =       0.859   TIME= 13:01:44
 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 - ENGINEERING ANALYSIS SYSTEM  RELEASE 2023 R1          23.1     ***
 Ansys Mechanical Enterprise
 20120530  VERSION=WINDOWS x64   13:01:44  JAN 25, 2024 CP=      0.859





                       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.859   TIME= 13:01:44
 Present time 0 is less than or equal to the previous time.  Time will
 default to 1.

 *** NOTE ***                            CP =       0.859   TIME= 13:01:44
 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 2 CPU domains
  ...Element load balance ratio =     1.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


 SOLUTION MONITORING INFO IS WRITTEN TO FILE= file.mntr

 *** NOTE ***                            CP =       0.859   TIME= 13:01:44
 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.000   0.000000
 Time at end of element matrix formulation CP = 0.859375.

 DISTRIBUTED SPARSE MATRIX DIRECT SOLVER.
  Number of equations =          44,    Maximum wavefront =     18

  Process memory allocated for solver              =     0.160 MB
  Process memory required for in-core solution     =     0.153 MB
  Process memory required for out-of-core solution =     0.153 MB

  Total memory allocated for solver                =     0.325 MB
  Total memory required for in-core solution       =     0.310 MB
  Total memory required for out-of-core solution   =     0.310 MB

 *** NOTE ***                            CP =       0.859   TIME= 13:01:44
 The Distributed 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.
 Distributed sparse solver maximum pivot= 5.009534302E+10 at node 16
 ROTY.
 Distributed sparse solver minimum pivot= 861490.522 at node 12 UZ.
 Distributed sparse solver minimum pivot in absolute value= 861490.522
 at node 12 UZ.

   *** 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


 *** MAPDL BINARY FILE STATISTICS
  BUFFER SIZE USED= 16384
        0.062 MB WRITTEN ON ASSEMBLED MATRIX FILE: file0.full
        0.625 MB WRITTEN ON RESULTS FILE: file0.rst

Stop mapdl#

mapdl.exit()

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