Note
Go to the end to download the full example code
车床刀具结构分析#
介绍 PyMAPDL 的基本功能。
Objective#
本示例的目的是通过车刀有限元模型来突出 PyMAPDL 的一些常用功能。 车床铣刀有多种磨损和失效途径,支持其设计的分析通常是瞬态热结构分析。 不过,为了简单起见,本仿真示例使用了非均匀载荷。
Contents#
变量和启动: 定义必要的变量并启动 MAPDL。
几何、网格和 MAPDL 参数: 导入几何体并检查 MAPDL 参数。使用 Python 变量定义线性弹性材料模型。绘制网格并应用对称边界条件。
坐标系和载荷: 为外加载荷创建局部坐标系,并通过绘图进行验证。
压力负荷: 使用 numpy 数组将压力负荷定义为应用区域长度的正弦函数。将压力数组作为表数组导入 MAPDL。验证应用载荷并求解。
绘图: 显示结果绘图、选择绘图以及使用绘图图例。
后处理: 列出结果的两种方法:使用 PyMAPDL 和 Pythonic 版本的 APDL。演示扩展方法和将列表写入文件。
高级绘图: 使用
pyvista.UnstructuredGrid
进行额外的后处理。
Step 1: Variables and launch#
定义变量并启动 MAPDL。
G:\Github\PyMAPDL-zh_CN\examples\00-mapdl-examples
常用的 MAPDL 命令行选项在 ansys.mapdl.core.launcher.launch_mapdl()
中以 Pythonic 参数名公开。
例如, -dir
变成了 run_location
。您可以使用 run_location
指定 MAPDL 的运行位置。例如
mapdl = launch_mapdl(run_location=path)
否则,MAPDL 的工作目录将存储在 mapdl.directory
中。在这个目录中,MAPDL 将创建我们稍后要展示的一些图像。
没有 Pythonic 版本的选项可以通过 additional_switches
参数访问。
这里使用 -smp
只是为了尽量减少求解器文件的数量。
mapdl = launch_mapdl(additional_switches="-smp")
Step 2: Geometry, mesh, and MAPDL parameters#
导入几何体并检查 MAPDL 参数。
定义材料和网格,然后创建边界条件。
# 首先,重置 MAPDL 数据库。
mapdl.clear()
导入几何体文件并列出所有 MAPDL 参数。
lathe_cutter_geo = download_example_data("LatheCutter.anf", "geometry")
mapdl.input(lathe_cutter_geo)
mapdl.finish()
print(mapdl.parameters)
MAPDL Parameters
----------------
PRESS_LENGTH : 0.055
UNIT_SYSTEM : "bin"
在载荷定义中使用单位长度的压力面积。
pressure_length = mapdl.parameters["PRESS_LENGTH"]
print(mapdl.parameters)
MAPDL Parameters
----------------
PRESS_LENGTH : 0.055
UNIT_SYSTEM : "bin"
更改单位和标题。
mapdl.units("Bin")
mapdl.title("Lathe Cutter")
TITLE=
Lathe Cutter
设置材料属性
MATERIAL 1 NUXY = 0.2700000
MAPDL 单元类型 SOLID285
用于演示目的。请考虑在实际应用中使用适当的单元类型或网格密度。
mapdl.et(1, 285)
mapdl.smrtsize(4)
mapdl.aesize(14, 0.0025)
mapdl.vmesh(1)
mapdl.da(11, "symm")
mapdl.da(16, "symm")
mapdl.da(9, "symm")
mapdl.da(10, "symm")
CONSTRAINT AT AREA 10
LOAD LABEL = SYMM
Step 3: Coordinate system and load#
创建一个局部坐标系(CS),将施加的压力作为局部坐标轴 X 的函数。
局部坐标系 ID = 11
mapdl.cskp(11, 0, 2, 1, 13)
mapdl.csys(1)
mapdl.view(1, -1, 1, 1)
mapdl.psymb("CS", 1)
mapdl.vplot(
color_areas=True,
show_lines=True,
cpos=[-1, 1, 1],
smooth_shading=True,
)
VTK 图形不显示 MAPDL 图形符号。
不过,要使用 MAPDL 绘图功能,可以将关键字选项 vtk
设为 False
。
mapdl.lplot(vtk=False)
Step 4: Pressure load#
创建压力载荷,将其作为表数组载入 MAPDL,验证载荷并求解。
length_x
和 press
是一个向量。要将它们组合成定义 MAPDL 表数组所需的正确形式,可以使用 numpy.stack 。
SELECT ALL ENTITIES OF TYPE= ALL AND BELOW
您可以打开 MAPDL GUI 检查模型。
mapdl.open_gui()
设置求解。
mapdl.finish()
mapdl.slashsolu()
mapdl.nlgeom("On")
mapdl.psf("PRES", "NORM", 3, 0, 1)
mapdl.view(1, -1, 1, 1)
mapdl.eplot(vtk=False)
求解模型。
mapdl.solve()
mapdl.finish()
if mapdl.solution.converged:
print("The solution has converged.")
The solution has converged.
Step 5: Plotting#
mapdl.post1()
mapdl.set("last")
mapdl.allsel()
mapdl.post_processing.plot_nodal_principal_stress("1", smooth_shading=False)
Plotting - Part of Model#
mapdl.csys(1)
mapdl.nsel("S", "LOC", "Z", -0.5, -0.141)
mapdl.esln()
mapdl.nsle()
mapdl.post_processing.plot_nodal_principal_stress(
"1", edge_color="white", show_edges=True
)
Plotting - Legend Options#
mapdl.allsel()
sbar_kwargs = {
"color": "black",
"title": "1st Principal Stress (psi)",
"vertical": False,
"n_labels": 6,
}
mapdl.post_processing.plot_nodal_principal_stress(
"1",
cpos="xy",
background="white",
edge_color="black",
show_edges=True,
scalar_bar_args=sbar_kwargs,
n_colors=9,
)
让我们从 PyVista 文档 中试用一些标量条选项。 例如,在米色背景上设置黑色文字。
定义为 Python 字典的标量条关键字是使用 {key:value} 的另一种方法。 您也可以使用 “单击并拖动” 方法重新定位标量栏。 试着按住鼠标左键,同时移动鼠标。
sbar_kwargs = dict(
title_font_size=20,
label_font_size=16,
shadow=True,
n_labels=9,
italic=True,
bold=True,
fmt="%.1f",
font_family="arial",
title="1st Principal Stress (psi)",
color="black",
)
mapdl.post_processing.plot_nodal_principal_stress(
"1",
cpos="xy",
edge_color="black",
background="beige",
show_edges=True,
scalar_bar_args=sbar_kwargs,
n_colors=256,
cmap="jet",
)
# cmap 名称 *_r 通常会反转值。试试 cmap='jet_r'
Step 6: Postprocessing#
Results List#
得到所有的节点主应力。
mapdl.post_processing.nodal_principal_stress("1")
array([1090.04777804, 1365.33943166, 208.07761269, ..., 1492.86229405,
1006.32609565, 1670.09466751])
获取节点子集的主节点应力。
mapdl.nsel("S", vmin=1200, vmax=1210)
mapdl.esln()
mapdl.nsle()
print("The node numbers are:")
print(mapdl.mesh.nnum) # get node numbers
print("The principal nodal stresses are:")
mapdl.post_processing.nodal_principal_stress("1")
The node numbers are:
[ 148 149 344 356 369 370 377 382 391 393 394 395 550 781
787 788 806 809 811 824 826 849 851 862 863 897 899 903
905 907 915 917 938 939 970 974 975 976 977 1014 1017 1029
1030 1036 1037 1038 1040 1043 1045 1051 1054 1058 1059 1060 1083 1086
1087 1093 1095 1118 1120 1130 1132 1133 1134 1135 1136 1140 1141 1152
1163 1166 1167 1168 1170 1171 1175 1176 1185 1186 1188 1199 1200 1201
1202 1203 1204 1205 1206 1207 1208 1209 1210 1218 1221 1230 1232 1233
1234 1236 1238 1239 1240 1241 1249 1250 1260]
The principal nodal stresses are:
array([ 983.11562743, 776.8619691 , 939.25461086, 711.79983737,
1933.23861924, 1522.16251827, 1208.25661227, 1790.61011693,
2379.77191706, 2175.02307907, 2255.24996179, 2547.41653478,
983.51123077, -18.55881452, 522.57364849, 527.73117202,
1973.28616001, 994.47570955, 860.77648934, 1075.69876281,
1328.00741645, 1356.41971592, 1238.12773083, 131.66671856,
409.1232715 , 381.84092426, 804.10532601, 1227.18941002,
735.47529127, 497.54965151, 1369.56712097, 1307.03870153,
1558.11564265, 1412.56876688, 1569.39440477, 1633.12444675,
1468.46245321, 1214.47919325, 62.00544036, 1532.13765645,
1296.48163611, 355.81519376, 767.53487071, 766.91072533,
669.15110572, 426.18751245, 1217.21340733, 1257.85720022,
722.34200894, 2053.60084616, 1645.10090105, 1454.30324337,
1458.25284216, 1268.09487241, 1016.515403 , 1414.84285523,
1469.18347838, 1435.00349844, 1506.43325605, 1265.85952153,
1027.33898052, 45.029466 , 1515.24730671, 1395.69359686,
1598.33751236, 1551.59115101, 1779.55456504, 778.07926617,
508.55505568, -20.56775721, 1489.76157669, 1495.67703201,
1193.07141023, 1497.03068241, 1394.87448696, -412.57360365,
1347.46626227, 946.82662632, 1694.14321373, 1666.02297287,
1552.15182477, 1986.87642392, 930.83189147, 1296.82184049,
1364.41543762, 1490.94505526, 1477.08706795, 1556.74812377,
2016.1425884 , 548.91061902, 407.9263888 , 248.44679386,
1047.46771587, 980.64639583, 1238.13720783, 1159.89018697,
1470.96684779, 1189.98931085, 1388.90096699, 1111.41428121,
1843.35441404, 1463.5682048 , 1404.83607763, 1632.79014038,
1823.49471082, 1789.31240338, 1564.3351745 ])
Results as lists, arrays, and DataFrames#
使用 mapdl.prnsol()
检查
print(mapdl.prnsol("S", "PRIN"))
PRINT S NODAL SOLUTION PER NODE
*** MAPDL - ENGINEERING ANALYSIS SYSTEM RELEASE 2023 R1 23.1 ***
Ansys Mechanical Enterprise
20120530 VERSION=WINDOWS x64 00:34:57 JAN 25, 2024 CP= 2.203
Lathe Cutter
***** POST1 NODAL STRESS LISTING *****
LOAD STEP= 1 SUBSTEP= 1
TIME= 1.0000 LOAD CASE= 0
NODE S1 S2 S3 SINT SEQV
148 983.12 28.745 -1453.7 2436.8 2126.8
149 776.86 -23.055 -1626.4 2403.3 2119.7
344 939.25 132.95 -1201.4 2140.7 1872.6
356 711.80 -19.620 -1464.9 2176.7 1918.6
369 1933.2 54.619 -2021.5 3954.7 3426.3
370 1522.2 -26.416 -2026.9 3549.1 3081.9
377 1208.3 -162.18 -2042.7 3250.9 2826.9
382 1790.6 -45.272 -2033.4 3824.0 3312.6
391 2379.8 74.614 -1580.3 3960.1 3444.9
393 2175.0 198.87 -1762.1 3937.2 3409.7
394 2255.2 62.975 -1770.4 4025.6 3490.9
395 2547.4 192.68 -1646.3 4193.7 3641.0
550 983.51 -153.56 -1735.1 2718.6 2364.8
781 -18.559 -752.26 -1492.5 1473.9 1276.5
787 522.57 -406.00 -1084.4 1607.0 1397.3
788 527.73 -468.74 -1194.2 1722.0 1497.4
806 1973.3 80.313 -1509.4 3482.7 3019.9
809 994.48 -505.82 -2204.7 3199.2 2772.4
811 860.78 -744.62 -2612.8 3473.5 3011.0
824 1075.7 -307.82 -1432.0 2507.7 2175.6
826 1328.0 -286.44 -1442.4 2770.4 2410.2
849 1356.4 -566.29 -2595.6 3952.0 3422.9
851 1238.1 -444.54 -2336.8 3574.9 3097.7
862 131.67 -709.14 -1960.8 2092.5 1823.8
863 409.12 -664.83 -1629.3 2038.4 1766.1
897 381.84 -775.22 -2342.9 2724.7 2368.6
899 804.11 -417.06 -1901.6 2705.8 2346.9
903 1227.2 -40.357 -1557.1 2784.3 2414.5
905 735.48 -110.29 -1099.0 1834.4 1590.3
907 497.55 -325.81 -1697.2 2194.8 1920.4
915 1369.6 -119.24 -1779.1 3148.7 2728.2
917 1307.0 -107.63 -1853.6 3160.7 2742.2
938 1558.1 -41.100 -753.80 2311.9 2050.7
939 1412.6 38.397 -619.99 2032.6 1796.3
970 1569.4 -198.98 -1769.7 3339.1 2893.5
974 1633.1 6.5463 -1842.0 3475.1 3011.6
975 1468.5 -157.41 -1752.3 3220.8 2789.3
976 1214.5 -273.66 -2093.9 3308.4 2869.9
977 62.005 -501.48 -982.02 1044.0 905.11
*** MAPDL - ENGINEERING ANALYSIS SYSTEM RELEASE 2023 R1 23.1 ***
Ansys Mechanical Enterprise
20120530 VERSION=WINDOWS x64 00:34:57 JAN 25, 2024 CP= 2.203
Lathe Cutter
***** POST1 NODAL STRESS LISTING *****
LOAD STEP= 1 SUBSTEP= 1
TIME= 1.0000 LOAD CASE= 0
NODE S1 S2 S3 SINT SEQV
1014 1532.1 -33.966 -1617.5 3149.6 2727.6
1017 1296.5 67.996 -1205.2 2501.7 2166.6
1029 355.82 -511.48 -2043.5 2399.3 2104.3
1030 767.53 -310.12 -1866.5 2634.1 2293.7
1036 766.91 -348.11 -1650.5 2417.4 2095.7
1037 669.15 -446.11 -1601.8 2271.0 1966.8
1038 426.19 -553.34 -1821.0 2247.2 1951.4
1040 1217.2 73.728 -1363.8 2581.0 2240.0
1043 1257.9 -82.369 -1481.7 2739.5 2372.7
1045 722.34 -423.37 -1095.9 1818.3 1592.3
1051 2053.6 199.65 -1569.9 3623.5 3138.3
1054 1645.1 10.144 -1486.9 3132.0 2713.3
1058 1454.3 -420.04 -2251.9 3706.2 3209.8
1059 1458.3 -388.03 -2246.7 3705.0 3208.6
1060 1268.1 -162.73 -1927.3 3195.4 2772.4
1083 1016.5 -112.83 -1026.4 2043.0 1772.5
1086 1414.8 59.833 -648.73 2063.6 1816.1
1087 1469.2 -47.132 -873.82 2343.0 2058.2
1093 1435.0 49.489 -586.82 2021.8 1790.6
1095 1506.4 34.900 -749.17 2255.6 1983.4
1118 1265.9 -175.96 -1827.1 3092.9 2680.6
1120 1027.3 -1.3298 -1662.7 2690.1 2351.0
1130 45.029 -883.49 -2215.6 2260.6 1968.1
1132 1515.2 14.494 -961.41 2476.7 2160.8
1133 1395.7 -61.523 -878.43 2274.1 1995.3
1134 1598.3 63.476 -955.91 2554.2 2227.0
1135 1551.6 57.955 -841.34 2392.9 2093.5
1136 1779.6 -29.393 -1469.3 3248.9 2819.6
1140 778.08 -228.85 -1385.8 2163.9 1875.5
1141 508.56 -510.85 -1698.5 2207.0 1913.2
1152 -20.568 -872.14 -1728.6 1708.1 1479.2
1163 1489.8 -13.848 -859.05 2348.8 2060.6
1166 1495.7 -498.14 -2548.2 4043.8 3502.2
1167 1193.1 -645.41 -2515.2 3708.3 3211.5
1168 1497.0 -16.009 -832.14 2329.2 2047.0
1170 1394.9 -222.25 -1043.3 2438.2 2148.7
1171 -412.57 -907.52 -1261.3 848.77 738.44
1175 1347.5 -237.18 -1980.0 3327.5 2882.7
1176 946.83 -27.284 -1592.2 2539.0 2218.6
*** MAPDL - ENGINEERING ANALYSIS SYSTEM RELEASE 2023 R1 23.1 ***
Ansys Mechanical Enterprise
20120530 VERSION=WINDOWS x64 00:34:57 JAN 25, 2024 CP= 2.203
Lathe Cutter
***** POST1 NODAL STRESS LISTING *****
LOAD STEP= 1 SUBSTEP= 1
TIME= 1.0000 LOAD CASE= 0
NODE S1 S2 S3 SINT SEQV
1185 1694.1 -208.48 -1618.3 3312.5 2879.2
1186 1666.0 -36.965 -1722.6 3388.6 2934.6
1188 1552.2 -48.725 -1121.8 2674.0 2330.7
1199 1986.9 23.931 -1734.4 3721.2 3224.3
1200 930.83 -42.693 -1606.5 2537.3 2217.1
1201 1296.8 -439.93 -2338.8 3635.6 3149.5
1202 1364.4 -300.58 -2007.0 3371.4 2919.8
1203 1490.9 31.361 -701.12 2192.1 1932.9
1204 1477.1 -41.115 -942.66 2419.7 2118.1
1205 1556.7 -62.024 -1829.3 3386.0 2933.3
1206 2016.1 77.611 -1576.5 3592.6 3114.6
1207 548.91 -529.01 -1718.3 2267.2 1964.3
1208 407.93 -496.07 -1184.4 1592.3 1383.2
1209 248.45 -661.85 -1735.4 1983.9 1720.0
1210 1047.5 -193.78 -1398.6 2446.1 2118.5
1218 980.65 3.7924 -1530.5 2511.1 2192.5
1221 1238.1 -294.98 -1960.3 3198.4 2770.7
1230 1159.9 -511.73 -2239.0 3398.9 2943.6
1232 1471.0 -237.69 -2019.9 3490.9 3023.4
1233 1190.0 -78.456 -1769.8 2959.8 2572.0
1234 1388.9 -126.56 -1028.0 2416.9 2115.5
1236 1111.4 -75.296 -1831.9 2943.3 2564.9
1238 1843.4 -5.8117 -1616.0 3459.4 2998.3
1239 1463.6 -117.23 -1063.8 2527.4 2211.6
1240 1404.8 -157.46 -1167.9 2572.7 2245.1
1241 1632.8 -58.702 -1537.3 3170.1 2747.4
1249 1823.5 -99.741 -1655.3 3478.8 3018.3
1250 1789.3 -31.130 -1537.0 3326.3 2884.9
1260 1564.3 -210.45 -1731.8 3296.1 2857.3
MINIMUM VALUES
NODE 1171 1171 811 1171 1171
VALUE -412.57 -907.52 -2612.8 848.77 738.44
MAXIMUM VALUES
NODE 395 1051 1093 395 395
VALUE 2547.4 199.65 -586.82 4193.7 3641.0
使用此命令可以将其转换为 list 类型。
mapdl_s_1_list = mapdl.prnsol("S", "PRIN").to_list()
print(mapdl_s_1_list)
[[148.0, 983.12, 28.745, -1453.7, 2436.8, 2126.8], [149.0, 776.86, -23.055, -1626.4, 2403.3, 2119.7], [344.0, 939.25, 132.95, -1201.4, 2140.7, 1872.6], [356.0, 711.8, -19.62, -1464.9, 2176.7, 1918.6], [369.0, 1933.2, 54.619, -2021.5, 3954.7, 3426.3], [370.0, 1522.2, -26.416, -2026.9, 3549.1, 3081.9], [377.0, 1208.3, -162.18, -2042.7, 3250.9, 2826.9], [382.0, 1790.6, -45.272, -2033.4, 3824.0, 3312.6], [391.0, 2379.8, 74.614, -1580.3, 3960.1, 3444.9], [393.0, 2175.0, 198.87, -1762.1, 3937.2, 3409.7], [394.0, 2255.2, 62.975, -1770.4, 4025.6, 3490.9], [395.0, 2547.4, 192.68, -1646.3, 4193.7, 3641.0], [550.0, 983.51, -153.56, -1735.1, 2718.6, 2364.8], [781.0, -18.559, -752.26, -1492.5, 1473.9, 1276.5], [787.0, 522.57, -406.0, -1084.4, 1607.0, 1397.3], [788.0, 527.73, -468.74, -1194.2, 1722.0, 1497.4], [806.0, 1973.3, 80.313, -1509.4, 3482.7, 3019.9], [809.0, 994.48, -505.82, -2204.7, 3199.2, 2772.4], [811.0, 860.78, -744.62, -2612.8, 3473.5, 3011.0], [824.0, 1075.7, -307.82, -1432.0, 2507.7, 2175.6], [826.0, 1328.0, -286.44, -1442.4, 2770.4, 2410.2], [849.0, 1356.4, -566.29, -2595.6, 3952.0, 3422.9], [851.0, 1238.1, -444.54, -2336.8, 3574.9, 3097.7], [862.0, 131.67, -709.14, -1960.8, 2092.5, 1823.8], [863.0, 409.12, -664.83, -1629.3, 2038.4, 1766.1], [897.0, 381.84, -775.22, -2342.9, 2724.7, 2368.6], [899.0, 804.11, -417.06, -1901.6, 2705.8, 2346.9], [903.0, 1227.2, -40.357, -1557.1, 2784.3, 2414.5], [905.0, 735.48, -110.29, -1099.0, 1834.4, 1590.3], [907.0, 497.55, -325.81, -1697.2, 2194.8, 1920.4], [915.0, 1369.6, -119.24, -1779.1, 3148.7, 2728.2], [917.0, 1307.0, -107.63, -1853.6, 3160.7, 2742.2], [938.0, 1558.1, -41.1, -753.8, 2311.9, 2050.7], [939.0, 1412.6, 38.397, -619.99, 2032.6, 1796.3], [970.0, 1569.4, -198.98, -1769.7, 3339.1, 2893.5], [974.0, 1633.1, 6.5463, -1842.0, 3475.1, 3011.6], [975.0, 1468.5, -157.41, -1752.3, 3220.8, 2789.3], [976.0, 1214.5, -273.66, -2093.9, 3308.4, 2869.9], [977.0, 62.005, -501.48, -982.02, 1044.0, 905.11], [1014.0, 1532.1, -33.966, -1617.5, 3149.6, 2727.6], [1017.0, 1296.5, 67.996, -1205.2, 2501.7, 2166.6], [1029.0, 355.82, -511.48, -2043.5, 2399.3, 2104.3], [1030.0, 767.53, -310.12, -1866.5, 2634.1, 2293.7], [1036.0, 766.91, -348.11, -1650.5, 2417.4, 2095.7], [1037.0, 669.15, -446.11, -1601.8, 2271.0, 1966.8], [1038.0, 426.19, -553.34, -1821.0, 2247.2, 1951.4], [1040.0, 1217.2, 73.728, -1363.8, 2581.0, 2240.0], [1043.0, 1257.9, -82.369, -1481.7, 2739.5, 2372.7], [1045.0, 722.34, -423.37, -1095.9, 1818.3, 1592.3], [1051.0, 2053.6, 199.65, -1569.9, 3623.5, 3138.3], [1054.0, 1645.1, 10.144, -1486.9, 3132.0, 2713.3], [1058.0, 1454.3, -420.04, -2251.9, 3706.2, 3209.8], [1059.0, 1458.3, -388.03, -2246.7, 3705.0, 3208.6], [1060.0, 1268.1, -162.73, -1927.3, 3195.4, 2772.4], [1083.0, 1016.5, -112.83, -1026.4, 2043.0, 1772.5], [1086.0, 1414.8, 59.833, -648.73, 2063.6, 1816.1], [1087.0, 1469.2, -47.132, -873.82, 2343.0, 2058.2], [1093.0, 1435.0, 49.489, -586.82, 2021.8, 1790.6], [1095.0, 1506.4, 34.9, -749.17, 2255.6, 1983.4], [1118.0, 1265.9, -175.96, -1827.1, 3092.9, 2680.6], [1120.0, 1027.3, -1.3298, -1662.7, 2690.1, 2351.0], [1130.0, 45.029, -883.49, -2215.6, 2260.6, 1968.1], [1132.0, 1515.2, 14.494, -961.41, 2476.7, 2160.8], [1133.0, 1395.7, -61.523, -878.43, 2274.1, 1995.3], [1134.0, 1598.3, 63.476, -955.91, 2554.2, 2227.0], [1135.0, 1551.6, 57.955, -841.34, 2392.9, 2093.5], [1136.0, 1779.6, -29.393, -1469.3, 3248.9, 2819.6], [1140.0, 778.08, -228.85, -1385.8, 2163.9, 1875.5], [1141.0, 508.56, -510.85, -1698.5, 2207.0, 1913.2], [1152.0, -20.568, -872.14, -1728.6, 1708.1, 1479.2], [1163.0, 1489.8, -13.848, -859.05, 2348.8, 2060.6], [1166.0, 1495.7, -498.14, -2548.2, 4043.8, 3502.2], [1167.0, 1193.1, -645.41, -2515.2, 3708.3, 3211.5], [1168.0, 1497.0, -16.009, -832.14, 2329.2, 2047.0], [1170.0, 1394.9, -222.25, -1043.3, 2438.2, 2148.7], [1171.0, -412.57, -907.52, -1261.3, 848.77, 738.44], [1175.0, 1347.5, -237.18, -1980.0, 3327.5, 2882.7], [1176.0, 946.83, -27.284, -1592.2, 2539.0, 2218.6], [1185.0, 1694.1, -208.48, -1618.3, 3312.5, 2879.2], [1186.0, 1666.0, -36.965, -1722.6, 3388.6, 2934.6], [1188.0, 1552.2, -48.725, -1121.8, 2674.0, 2330.7], [1199.0, 1986.9, 23.931, -1734.4, 3721.2, 3224.3], [1200.0, 930.83, -42.693, -1606.5, 2537.3, 2217.1], [1201.0, 1296.8, -439.93, -2338.8, 3635.6, 3149.5], [1202.0, 1364.4, -300.58, -2007.0, 3371.4, 2919.8], [1203.0, 1490.9, 31.361, -701.12, 2192.1, 1932.9], [1204.0, 1477.1, -41.115, -942.66, 2419.7, 2118.1], [1205.0, 1556.7, -62.024, -1829.3, 3386.0, 2933.3], [1206.0, 2016.1, 77.611, -1576.5, 3592.6, 3114.6], [1207.0, 548.91, -529.01, -1718.3, 2267.2, 1964.3], [1208.0, 407.93, -496.07, -1184.4, 1592.3, 1383.2], [1209.0, 248.45, -661.85, -1735.4, 1983.9, 1720.0], [1210.0, 1047.5, -193.78, -1398.6, 2446.1, 2118.5], [1218.0, 980.65, 3.7924, -1530.5, 2511.1, 2192.5], [1221.0, 1238.1, -294.98, -1960.3, 3198.4, 2770.7], [1230.0, 1159.9, -511.73, -2239.0, 3398.9, 2943.6], [1232.0, 1471.0, -237.69, -2019.9, 3490.9, 3023.4], [1233.0, 1190.0, -78.456, -1769.8, 2959.8, 2572.0], [1234.0, 1388.9, -126.56, -1028.0, 2416.9, 2115.5], [1236.0, 1111.4, -75.296, -1831.9, 2943.3, 2564.9], [1238.0, 1843.4, -5.8117, -1616.0, 3459.4, 2998.3], [1239.0, 1463.6, -117.23, -1063.8, 2527.4, 2211.6], [1240.0, 1404.8, -157.46, -1167.9, 2572.7, 2245.1], [1241.0, 1632.8, -58.702, -1537.3, 3170.1, 2747.4], [1249.0, 1823.5, -99.741, -1655.3, 3478.8, 3018.3], [1250.0, 1789.3, -31.13, -1537.0, 3326.3, 2884.9], [1260.0, 1564.3, -210.45, -1731.8, 3296.1, 2857.3]]
使用此命令可以将其转换为 array 类型:
mapdl_s_1_array = mapdl.prnsol("S", "PRIN").to_array()
print(mapdl_s_1_array)
[[ 1.4800e+02 9.8312e+02 2.8745e+01 -1.4537e+03 2.4368e+03 2.1268e+03]
[ 1.4900e+02 7.7686e+02 -2.3055e+01 -1.6264e+03 2.4033e+03 2.1197e+03]
[ 3.4400e+02 9.3925e+02 1.3295e+02 -1.2014e+03 2.1407e+03 1.8726e+03]
[ 3.5600e+02 7.1180e+02 -1.9620e+01 -1.4649e+03 2.1767e+03 1.9186e+03]
[ 3.6900e+02 1.9332e+03 5.4619e+01 -2.0215e+03 3.9547e+03 3.4263e+03]
[ 3.7000e+02 1.5222e+03 -2.6416e+01 -2.0269e+03 3.5491e+03 3.0819e+03]
[ 3.7700e+02 1.2083e+03 -1.6218e+02 -2.0427e+03 3.2509e+03 2.8269e+03]
[ 3.8200e+02 1.7906e+03 -4.5272e+01 -2.0334e+03 3.8240e+03 3.3126e+03]
[ 3.9100e+02 2.3798e+03 7.4614e+01 -1.5803e+03 3.9601e+03 3.4449e+03]
[ 3.9300e+02 2.1750e+03 1.9887e+02 -1.7621e+03 3.9372e+03 3.4097e+03]
[ 3.9400e+02 2.2552e+03 6.2975e+01 -1.7704e+03 4.0256e+03 3.4909e+03]
[ 3.9500e+02 2.5474e+03 1.9268e+02 -1.6463e+03 4.1937e+03 3.6410e+03]
[ 5.5000e+02 9.8351e+02 -1.5356e+02 -1.7351e+03 2.7186e+03 2.3648e+03]
[ 7.8100e+02 -1.8559e+01 -7.5226e+02 -1.4925e+03 1.4739e+03 1.2765e+03]
[ 7.8700e+02 5.2257e+02 -4.0600e+02 -1.0844e+03 1.6070e+03 1.3973e+03]
[ 7.8800e+02 5.2773e+02 -4.6874e+02 -1.1942e+03 1.7220e+03 1.4974e+03]
[ 8.0600e+02 1.9733e+03 8.0313e+01 -1.5094e+03 3.4827e+03 3.0199e+03]
[ 8.0900e+02 9.9448e+02 -5.0582e+02 -2.2047e+03 3.1992e+03 2.7724e+03]
[ 8.1100e+02 8.6078e+02 -7.4462e+02 -2.6128e+03 3.4735e+03 3.0110e+03]
[ 8.2400e+02 1.0757e+03 -3.0782e+02 -1.4320e+03 2.5077e+03 2.1756e+03]
[ 8.2600e+02 1.3280e+03 -2.8644e+02 -1.4424e+03 2.7704e+03 2.4102e+03]
[ 8.4900e+02 1.3564e+03 -5.6629e+02 -2.5956e+03 3.9520e+03 3.4229e+03]
[ 8.5100e+02 1.2381e+03 -4.4454e+02 -2.3368e+03 3.5749e+03 3.0977e+03]
[ 8.6200e+02 1.3167e+02 -7.0914e+02 -1.9608e+03 2.0925e+03 1.8238e+03]
[ 8.6300e+02 4.0912e+02 -6.6483e+02 -1.6293e+03 2.0384e+03 1.7661e+03]
[ 8.9700e+02 3.8184e+02 -7.7522e+02 -2.3429e+03 2.7247e+03 2.3686e+03]
[ 8.9900e+02 8.0411e+02 -4.1706e+02 -1.9016e+03 2.7058e+03 2.3469e+03]
[ 9.0300e+02 1.2272e+03 -4.0357e+01 -1.5571e+03 2.7843e+03 2.4145e+03]
[ 9.0500e+02 7.3548e+02 -1.1029e+02 -1.0990e+03 1.8344e+03 1.5903e+03]
[ 9.0700e+02 4.9755e+02 -3.2581e+02 -1.6972e+03 2.1948e+03 1.9204e+03]
[ 9.1500e+02 1.3696e+03 -1.1924e+02 -1.7791e+03 3.1487e+03 2.7282e+03]
[ 9.1700e+02 1.3070e+03 -1.0763e+02 -1.8536e+03 3.1607e+03 2.7422e+03]
[ 9.3800e+02 1.5581e+03 -4.1100e+01 -7.5380e+02 2.3119e+03 2.0507e+03]
[ 9.3900e+02 1.4126e+03 3.8397e+01 -6.1999e+02 2.0326e+03 1.7963e+03]
[ 9.7000e+02 1.5694e+03 -1.9898e+02 -1.7697e+03 3.3391e+03 2.8935e+03]
[ 9.7400e+02 1.6331e+03 6.5463e+00 -1.8420e+03 3.4751e+03 3.0116e+03]
[ 9.7500e+02 1.4685e+03 -1.5741e+02 -1.7523e+03 3.2208e+03 2.7893e+03]
[ 9.7600e+02 1.2145e+03 -2.7366e+02 -2.0939e+03 3.3084e+03 2.8699e+03]
[ 9.7700e+02 6.2005e+01 -5.0148e+02 -9.8202e+02 1.0440e+03 9.0511e+02]
[ 1.0140e+03 1.5321e+03 -3.3966e+01 -1.6175e+03 3.1496e+03 2.7276e+03]
[ 1.0170e+03 1.2965e+03 6.7996e+01 -1.2052e+03 2.5017e+03 2.1666e+03]
[ 1.0290e+03 3.5582e+02 -5.1148e+02 -2.0435e+03 2.3993e+03 2.1043e+03]
[ 1.0300e+03 7.6753e+02 -3.1012e+02 -1.8665e+03 2.6341e+03 2.2937e+03]
[ 1.0360e+03 7.6691e+02 -3.4811e+02 -1.6505e+03 2.4174e+03 2.0957e+03]
[ 1.0370e+03 6.6915e+02 -4.4611e+02 -1.6018e+03 2.2710e+03 1.9668e+03]
[ 1.0380e+03 4.2619e+02 -5.5334e+02 -1.8210e+03 2.2472e+03 1.9514e+03]
[ 1.0400e+03 1.2172e+03 7.3728e+01 -1.3638e+03 2.5810e+03 2.2400e+03]
[ 1.0430e+03 1.2579e+03 -8.2369e+01 -1.4817e+03 2.7395e+03 2.3727e+03]
[ 1.0450e+03 7.2234e+02 -4.2337e+02 -1.0959e+03 1.8183e+03 1.5923e+03]
[ 1.0510e+03 2.0536e+03 1.9965e+02 -1.5699e+03 3.6235e+03 3.1383e+03]
[ 1.0540e+03 1.6451e+03 1.0144e+01 -1.4869e+03 3.1320e+03 2.7133e+03]
[ 1.0580e+03 1.4543e+03 -4.2004e+02 -2.2519e+03 3.7062e+03 3.2098e+03]
[ 1.0590e+03 1.4583e+03 -3.8803e+02 -2.2467e+03 3.7050e+03 3.2086e+03]
[ 1.0600e+03 1.2681e+03 -1.6273e+02 -1.9273e+03 3.1954e+03 2.7724e+03]
[ 1.0830e+03 1.0165e+03 -1.1283e+02 -1.0264e+03 2.0430e+03 1.7725e+03]
[ 1.0860e+03 1.4148e+03 5.9833e+01 -6.4873e+02 2.0636e+03 1.8161e+03]
[ 1.0870e+03 1.4692e+03 -4.7132e+01 -8.7382e+02 2.3430e+03 2.0582e+03]
[ 1.0930e+03 1.4350e+03 4.9489e+01 -5.8682e+02 2.0218e+03 1.7906e+03]
[ 1.0950e+03 1.5064e+03 3.4900e+01 -7.4917e+02 2.2556e+03 1.9834e+03]
[ 1.1180e+03 1.2659e+03 -1.7596e+02 -1.8271e+03 3.0929e+03 2.6806e+03]
[ 1.1200e+03 1.0273e+03 -1.3298e+00 -1.6627e+03 2.6901e+03 2.3510e+03]
[ 1.1300e+03 4.5029e+01 -8.8349e+02 -2.2156e+03 2.2606e+03 1.9681e+03]
[ 1.1320e+03 1.5152e+03 1.4494e+01 -9.6141e+02 2.4767e+03 2.1608e+03]
[ 1.1330e+03 1.3957e+03 -6.1523e+01 -8.7843e+02 2.2741e+03 1.9953e+03]
[ 1.1340e+03 1.5983e+03 6.3476e+01 -9.5591e+02 2.5542e+03 2.2270e+03]
[ 1.1350e+03 1.5516e+03 5.7955e+01 -8.4134e+02 2.3929e+03 2.0935e+03]
[ 1.1360e+03 1.7796e+03 -2.9393e+01 -1.4693e+03 3.2489e+03 2.8196e+03]
[ 1.1400e+03 7.7808e+02 -2.2885e+02 -1.3858e+03 2.1639e+03 1.8755e+03]
[ 1.1410e+03 5.0856e+02 -5.1085e+02 -1.6985e+03 2.2070e+03 1.9132e+03]
[ 1.1520e+03 -2.0568e+01 -8.7214e+02 -1.7286e+03 1.7081e+03 1.4792e+03]
[ 1.1630e+03 1.4898e+03 -1.3848e+01 -8.5905e+02 2.3488e+03 2.0606e+03]
[ 1.1660e+03 1.4957e+03 -4.9814e+02 -2.5482e+03 4.0438e+03 3.5022e+03]
[ 1.1670e+03 1.1931e+03 -6.4541e+02 -2.5152e+03 3.7083e+03 3.2115e+03]
[ 1.1680e+03 1.4970e+03 -1.6009e+01 -8.3214e+02 2.3292e+03 2.0470e+03]
[ 1.1700e+03 1.3949e+03 -2.2225e+02 -1.0433e+03 2.4382e+03 2.1487e+03]
[ 1.1710e+03 -4.1257e+02 -9.0752e+02 -1.2613e+03 8.4877e+02 7.3844e+02]
[ 1.1750e+03 1.3475e+03 -2.3718e+02 -1.9800e+03 3.3275e+03 2.8827e+03]
[ 1.1760e+03 9.4683e+02 -2.7284e+01 -1.5922e+03 2.5390e+03 2.2186e+03]
[ 1.1850e+03 1.6941e+03 -2.0848e+02 -1.6183e+03 3.3125e+03 2.8792e+03]
[ 1.1860e+03 1.6660e+03 -3.6965e+01 -1.7226e+03 3.3886e+03 2.9346e+03]
[ 1.1880e+03 1.5522e+03 -4.8725e+01 -1.1218e+03 2.6740e+03 2.3307e+03]
[ 1.1990e+03 1.9869e+03 2.3931e+01 -1.7344e+03 3.7212e+03 3.2243e+03]
[ 1.2000e+03 9.3083e+02 -4.2693e+01 -1.6065e+03 2.5373e+03 2.2171e+03]
[ 1.2010e+03 1.2968e+03 -4.3993e+02 -2.3388e+03 3.6356e+03 3.1495e+03]
[ 1.2020e+03 1.3644e+03 -3.0058e+02 -2.0070e+03 3.3714e+03 2.9198e+03]
[ 1.2030e+03 1.4909e+03 3.1361e+01 -7.0112e+02 2.1921e+03 1.9329e+03]
[ 1.2040e+03 1.4771e+03 -4.1115e+01 -9.4266e+02 2.4197e+03 2.1181e+03]
[ 1.2050e+03 1.5567e+03 -6.2024e+01 -1.8293e+03 3.3860e+03 2.9333e+03]
[ 1.2060e+03 2.0161e+03 7.7611e+01 -1.5765e+03 3.5926e+03 3.1146e+03]
[ 1.2070e+03 5.4891e+02 -5.2901e+02 -1.7183e+03 2.2672e+03 1.9643e+03]
[ 1.2080e+03 4.0793e+02 -4.9607e+02 -1.1844e+03 1.5923e+03 1.3832e+03]
[ 1.2090e+03 2.4845e+02 -6.6185e+02 -1.7354e+03 1.9839e+03 1.7200e+03]
[ 1.2100e+03 1.0475e+03 -1.9378e+02 -1.3986e+03 2.4461e+03 2.1185e+03]
[ 1.2180e+03 9.8065e+02 3.7924e+00 -1.5305e+03 2.5111e+03 2.1925e+03]
[ 1.2210e+03 1.2381e+03 -2.9498e+02 -1.9603e+03 3.1984e+03 2.7707e+03]
[ 1.2300e+03 1.1599e+03 -5.1173e+02 -2.2390e+03 3.3989e+03 2.9436e+03]
[ 1.2320e+03 1.4710e+03 -2.3769e+02 -2.0199e+03 3.4909e+03 3.0234e+03]
[ 1.2330e+03 1.1900e+03 -7.8456e+01 -1.7698e+03 2.9598e+03 2.5720e+03]
[ 1.2340e+03 1.3889e+03 -1.2656e+02 -1.0280e+03 2.4169e+03 2.1155e+03]
[ 1.2360e+03 1.1114e+03 -7.5296e+01 -1.8319e+03 2.9433e+03 2.5649e+03]
[ 1.2380e+03 1.8434e+03 -5.8117e+00 -1.6160e+03 3.4594e+03 2.9983e+03]
[ 1.2390e+03 1.4636e+03 -1.1723e+02 -1.0638e+03 2.5274e+03 2.2116e+03]
[ 1.2400e+03 1.4048e+03 -1.5746e+02 -1.1679e+03 2.5727e+03 2.2451e+03]
[ 1.2410e+03 1.6328e+03 -5.8702e+01 -1.5373e+03 3.1701e+03 2.7474e+03]
[ 1.2490e+03 1.8235e+03 -9.9741e+01 -1.6553e+03 3.4788e+03 3.0183e+03]
[ 1.2500e+03 1.7893e+03 -3.1130e+01 -1.5370e+03 3.3263e+03 2.8849e+03]
[ 1.2600e+03 1.5643e+03 -2.1045e+02 -1.7318e+03 3.2961e+03 2.8573e+03]]
或转换为为 DataFrame:
mapdl_s_1_df = mapdl.prnsol("S", "PRIN").to_dataframe()
mapdl_s_1_df.head()
使用该命令可以以 DataFrame 的形式获取数据,DataFrame 是一种 Pandas 数据类型 。由于已导入 Pandas 模块,因此可以使用其函数。例如,可以将主应力写入文件。
# mapdl_s_1_df.to_csv(path + '\prin-stresses.csv')
# mapdl_s_1_df.to_json(path + '\prin-stresses.json')
mapdl_s_1_df.to_html(path + "\prin-stresses.html")
Step 7: Advanced plotting#
mapdl.allsel()
principal_1 = mapdl.post_processing.nodal_principal_stress("1")
将结果加载到 VTK grid 中。
grid = mapdl.mesh.grid
grid["p1"] = principal_1
sbar_kwargs = {
"color": "black",
"title": "1st Principal Stress (psi)",
"vertical": False,
"n_labels": 6,
}
沿 XY 平面生成单个水平切片。
Note
PyVista 的 eye_dome_lighting
方法用于增强切片的绘图效果。更多信息,请参阅 Eye Dome Lighting 。
single_slice = grid.slice(normal=[0, 0, 1], origin=[0, 0, 0])
single_slice.plot(
scalars="p1",
background="white",
lighting=False,
eye_dome_lighting=True,
show_edges=False,
cmap="jet",
n_colors=9,
scalar_bar_args=sbar_kwargs,
)
生成带有三个切平面的绘图。
slices = grid.slice_orthogonal()
slices.plot(
scalars="p1",
background="white",
lighting=False,
eye_dome_lighting=True,
show_edges=False,
cmap="jet",
n_colors=9,
scalar_bar_args=sbar_kwargs,
)
在同一平面内生成具有多个切面的网格。
slices = grid.slice_along_axis(12, "x")
slices.plot(
scalars="p1",
background="white",
show_edges=False,
lighting=False,
eye_dome_lighting=True,
cmap="jet",
n_colors=9,
scalar_bar_args=sbar_kwargs,
)
Finally, exit MAPDL.
mapdl.exit()
Total running time of the script: (0 minutes 7.289 seconds)