pyMAPDL 基本热力学分析#

本例演示了如何使用 MAPDL 在 pyMAPDL 中创建板块、施加热边界条件、求解并绘制曲线。

首先,将 MAPDL 作为服务启动,并禁用除错误信息之外的所有功能。

from ansys.mapdl.core import launch_mapdl

mapdl = launch_mapdl()

Geometry and Material Properties#

创建一个简单的横梁,指定材料属性并对其进行网格划分。

mapdl.prep7()
mapdl.mp("kxx", 1, 45)
mapdl.et(1, 90)
mapdl.block(-0.3, 0.3, -0.46, 1.34, -0.2, -0.2 + 0.02)
mapdl.vsweep(1)
mapdl.eplot()
3d plate thermal

Boundary Conditions#

设置热边界条件

mapdl.asel("S", vmin=3)
mapdl.nsla()
mapdl.d("all", "temp", 5)
mapdl.asel("S", vmin=4)
mapdl.nsla()
mapdl.d("all", "temp", 100)
out = mapdl.allsel()

Solve#

求解热力学静态分析并打印结果

mapdl.vsweep(1)
mapdl.run("/SOLU")
print(mapdl.solve())
out = mapdl.finish()
*** NOTE ***                            CP =      12.875   TIME= 22:17:08
 The automatic domain decomposition logic has selected the MESH domain
 decomposition method with 2 processes per solution.

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

 *** NOTE ***                            CP =      12.875   TIME= 22:17:08
 There is no title defined for this analysis.

 *** MAPDL - ENGINEERING ANALYSIS SYSTEM  RELEASE 2023 R1          23.1     ***
 Ansys Mechanical Enterprise
 20120530  VERSION=WINDOWS x64   22:17:08  JAN 21, 2024 CP=     12.875





                       S O L U T I O N   O P T I O N S

   PROBLEM DIMENSIONALITY. . . . . . . . . . . . .3-D
   DEGREES OF FREEDOM. . . . . . TEMP
   ANALYSIS TYPE . . . . . . . . . . . . . . . . .STATIC (STEADY-STATE)
   GLOBALLY ASSEMBLED MATRIX . . . . . . . . . . .SYMMETRIC

 *** NOTE ***                            CP =      12.875   TIME= 22:17:08
 Present time 0 is less than or equal to the previous time.  Time will
 default to 1.

 *** NOTE ***                            CP =      12.875   TIME= 22:17:08
 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: 450
  ...Number of nodes:    2720
  ...Decompose to 2 CPU domains
  ...Element load balance ratio =     1.004


                      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


 Range of element maximum matrix coefficients in global coordinates
 Maximum = 13.6474747 at element 449.
 Minimum = 13.6474747 at element 106.

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

        1       450  SOLID90       0.000   0.000000
 Time at end of element matrix formulation CP = 12.921875.

 DISTRIBUTED SPARSE MATRIX DIRECT SOLVER.
  Number of equations =        2606,    Maximum wavefront =     76

  Process memory allocated for solver              =     3.199 MB
  Process memory required for in-core solution     =     3.076 MB
  Process memory required for out-of-core solution =     1.989 MB

  Total memory allocated for solver                =     5.953 MB
  Total memory required for in-core solution       =     5.726 MB
  Total memory required for out-of-core solution   =     3.755 MB

 *** NOTE ***                            CP =      12.984   TIME= 22:17:08
 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= 33.3096879 at node 1906 TEMP.
 Distributed sparse solver minimum pivot= 0.695228045 at node 1569 TEMP.
 Distributed sparse solver minimum pivot in absolute value= 0.695228045
 at node 1569 TEMP.

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

        1       450  SOLID90       0.000   0.000000

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

        1       450  SOLID90       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.625 MB WRITTEN ON ASSEMBLED MATRIX FILE: file0.full
        0.562 MB WRITTEN ON RESULTS FILE: file0.rth

Post-Processing using MAPDL#

通过 MAPDL 直接获取结果,查看梁的热力学结果。

mapdl.post1()
mapdl.set(1, 1)
mapdl.post_processing.plot_nodal_temperature()
3d plate thermal

或者,也可以使用 pyansys 读取结果文件的结果对象

result = mapdl.result
nnum, temp = result.nodal_temperature(0)
# 这等同于 pyansys.read_binary(mapdl._result_file)
print(nnum, temp)
[   1    2    3 ... 2718 2719 2720] [11.41342066 17.70960818 24.03472642 ... 96.77753462 96.76893653
 96.73371864]

Stop mapdl#

mapdl.exit()

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