Note
Go to the end to download the full example code
MAPDL 3D Beam#
这是一个简单的示例,加载包含梁的档案文件,然后使用简化的 modal_analysis
方法运行模态分析。
首先,将 MAPDL 作为一项服务启动。
from ansys.mapdl.reader import examples
from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl()
# 加载存储为示例档案文件的梁并对其进行网格划分
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")
# 边界条件
mapdl.allsel()
# 假设钢材性能
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)
# 边界条件
# 固定梁的一端
mapdl.nsel("S", "LOC", "Z")
mapdl.d("all", "all")
mapdl.allsel()
# 绘制边界条件
mapdl.nplot(plot_bc=True)
C:\Users\ff\AppData\Local\Programs\Python\Python310\lib\site-packages\ansys\tools\path\path.py:818: DeprecationWarning: This method is going to be deprecated in future versions. Please use 'get_mapdl_path'.
warnings.warn(
mapdl.mxpand(elcalc="YES")
mapdl.modal_analysis(nmode=6)
*** NOTE *** CP = 0.266 TIME= 13:01:27
The automatic domain decomposition logic has selected the MESH domain
decomposition method with 2 processes per solution.
***** MAPDL SOLVE COMMAND *****
*** NOTE *** CP = 0.266 TIME= 13:01:27
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 - ENGINEERING ANALYSIS SYSTEM RELEASE 2023 R1 23.1 ***
Ansys Mechanical Enterprise
20120530 VERSION=WINDOWS x64 13:01:27 JAN 25, 2024 CP= 0.266
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.266 TIME= 13:01:27
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 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
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.22795E-11 -0.37570E-11
0.22795E-11 84500. -0.37570E-11
-0.37570E-11 -0.37570E-11 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.000 0.000000
Time at end of element matrix formulation CP = 0.265625.
BLOCK LANCZOS CALCULATION OF UP TO 6 EIGENVECTORS.
NUMBER OF EQUATIONS = 900
MAXIMUM WAVEFRONT = 167
MAXIMUM MODES STORED = 6
MINIMUM EIGENVALUE = 0.00000E+00
MAXIMUM EIGENVALUE = 0.10000E+31
Process memory allocated for solver = 1.844 MB
Process memory required for in-core solution = 1.759 MB
Process memory required for out-of-core solution = 1.402 MB
Total memory allocated for solver = 3.467 MB
Total memory required for in-core solution = 3.306 MB
Total memory required for out-of-core solution = 2.662 MB
*** NOTE *** CP = 0.281 TIME= 13:01:27
The Distributed 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.
Total memory available for LANCZOS = 27.406200 GB
Process memory required for in-core LANCZOS Workspace = 2.801674 MB
Process memory required for out-of-core LANCZOS Workspace = 551.132813 KB
Total memory required for in-core LANCZOS Workspace = 5.015030 MB
Total memory required for out-of-core LANCZOS Workspace = 1.062424 MB
Lanczos Memory Mode : INCORE
*** MAPDL - ENGINEERING ANALYSIS SYSTEM RELEASE 2023 R1 23.1 ***
Ansys Mechanical Enterprise
20120530 VERSION=WINDOWS x64 13:01:27 JAN 25, 2024 CP= 0.281
*** FREQUENCIES FROM BLOCK LANCZOS ITERATION ***
MODE FREQUENCY (HERTZ)
1 32.13951614479
2 32.13951614484
3 145.4783895431
4 173.4557943042
5 173.4557943042
6 254.8511237205
*** MAPDL BINARY FILE STATISTICS
BUFFER SIZE USED= 16384
0.500 MB WRITTEN ON ASSEMBLED MATRIX FILE: file0.full
0.062 MB WRITTEN ON MODAL MATRIX FILE: file0.mode
0.312 MB WRITTEN ON RESULTS FILE: file0.rst
使用 pyansys 结果对象查看结果
result = mapdl.result
print(result)
PyMAPDL Result
Units : User Defined
Version : 23.1
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
获取节点位移值
50 [-0.00113171 0.00211654 0.00133242]
51 [-0.00137177 0.00258624 0.00143286]
52 [-0.00162765 0.00308601 0.00151924]
53 [-0.00189697 0.0036112 0.00159201]
54 [-0.00217744 0.00415741 0.00165203]
55 [-0.0024669 0.0047204 0.00170006]
56 [-0.0027634 0.00529632 0.00173723]
57 [-0.00306508 0.00588155 0.00176452]
58 [-0.0033704 0.00647304 0.00178334]
59 [-0.00367793 0.00706797 0.0017949 ]
绘制模态结果
result.plot_nodal_displacement(0, show_edges=True)
为模态结果制作动画
result.animate_nodal_solution(0, show_edges=True, loop=False, displacement_factor=10, movie_filename='demo.gif')
[(6.295554957734411, 6.295554957734411, 8.29555495773441),
(0.5, 0.5, 2.5),
(0.0, 0.0, 1.0)]
Stop mapdl#
mapdl.exit()
Total running time of the script: (0 minutes 21.073 seconds)