.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\00-Different-analysis-types\01-static-simulation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_00-Different-analysis-types_01-static-simulation.py: .. _ref_static_example: Static Simulation ================= 在该脚本中,将对静态模拟进行处理,以提取应力、位移等结果。此外,还可通过对特定节点或单元进行扫描来选择结果的子部分。 .. GENERATED FROM PYTHON SOURCE LINES 11-14 Perform required imports ------------------------ 执行所需的导入. .. GENERATED FROM PYTHON SOURCE LINES 14-20 .. code-block:: Python # 本示例使用了一个提供的文件,您可以通过导入 DPF ``examples`` 包获得该文件。 from ansys.dpf import post from ansys.dpf.post import examples .. GENERATED FROM PYTHON SOURCE LINES 21-25 Get ``Simulation`` object ------------------------- 获取允许访问结果的 ``Simulation`` 对象。必须使用结果文件的路径实例化 ``Simulation`` 对象。 例如,Windows 下为 ``"C:/Users/user/my_result.rst"`` 或 Linux 下为 ``"/home/user/my_result.rst"`` 。 .. GENERATED FROM PYTHON SOURCE LINES 25-43 .. code-block:: Python example_path = examples.find_static_rst() example_path # 若要自动检测模拟类型,请使用: simulation = post.load_simulation(example_path) # 要启用 auto-completion 功能,请使用等效的命令: simulation = post.StaticMechanicalSimulation(example_path) # 打印 simulation ,了解可用内容的概况 print(simulation) # 获取模拟结果中的位移数据 displacement = simulation.displacement() print(displacement) .. rst-class:: sphx-glr-script-out .. code-block:: none Static Mechanical Simulation. Data Sources ------------------------------ C:\Users\ff\AppData\Roaming\Python\Python310\site-packages\ansys\dpf\core\examples\result_files\static.rst DPF Model ------------------------------ Static analysis Unit system: MKS: m, kg, N, s, V, A, degC Physics Type: Mechanical Available results: - displacement: Nodal Displacement - reaction_force: Nodal Force - stress: ElementalNodal Stress - elemental_volume: Elemental Volume - stiffness_matrix_energy: Elemental Energy-stiffness matrix - artificial_hourglass_energy: Elemental Hourglass Energy - thermal_dissipation_energy: Elemental thermal dissipation energy - kinetic_energy: Elemental Kinetic Energy - co_energy: Elemental co-energy - incremental_energy: Elemental incremental energy - elastic_strain: ElementalNodal Strain - structural_temperature: ElementalNodal Temperature ------------------------------ DPF Meshed Region: 81 nodes 8 elements Unit: m With solid (3D) elements ------------------------------ DPF Time/Freq Support: Number of sets: 1 Cumulative Time (s) LoadStep Substep 1 1.000000 1 1 results U (m) set_ids 1 node_ids components 1 X -3.3190e-22 Y -6.9357e-09 Z -3.2862e-22 26 X 2.2303e-09 Y -7.1421e-09 Z -2.9208e-22 ... ... ... .. GENERATED FROM PYTHON SOURCE LINES 44-46 Select sub parts of displacement --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 46-67 .. code-block:: Python # 获取 X 位移 x_displacement = displacement.select(components="X") print(x_displacement) print(type(x_displacement)) # # 等同于: x_displacement = simulation.displacement(components=["X"]) print(x_displacement) # 绘制 X 位移图 x_displacement.plot() # 提取特定节点上的位移 nodes_displacement = displacement.select(node_ids=[1, 10, 100]) nodes_displacement.plot() # 等同于: nodes_displacement = simulation.displacement(node_ids=[1, 10, 100]) print(nodes_displacement) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/00-Different-analysis-types/images/sphx_glr_01-static-simulation_001.png :alt: 01 static simulation :srcset: /examples/00-Different-analysis-types/images/sphx_glr_01-static-simulation_001.png :class: sphx-glr-multi-img * .. image-sg:: /examples/00-Different-analysis-types/images/sphx_glr_01-static-simulation_002.png :alt: 01 static simulation :srcset: /examples/00-Different-analysis-types/images/sphx_glr_01-static-simulation_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none results U (m) set_ids 1 node_ids components 1 X -3.3190e-22 26 2.2303e-09 14 0.0000e+00 12 0.0000e+00 2 -3.0117e-22 27 2.0908e-09 ... ... ... results U_X (m) set_ids 1 node_ids 1 -3.3190e-22 26 2.2303e-09 14 0.0000e+00 12 0.0000e+00 2 -3.0117e-22 27 2.0908e-09 ... ... results U (m) set_ids 1 node_ids components 1 X -3.3190e-22 Y -6.9357e-09 Z -3.2862e-22 10 X 0.0000e+00 Y 0.0000e+00 Z 0.0000e+00 .. GENERATED FROM PYTHON SOURCE LINES 68-71 Compute total displacement (norm) --------------------------------- 计算选定节点上的位移范数 .. GENERATED FROM PYTHON SOURCE LINES 71-83 .. code-block:: Python nodes_displacement = simulation.displacement( node_ids=simulation.mesh.node_ids[10:], norm=True ) print(nodes_displacement) nodes_displacement.plot() # 这段代码首先调用 simulation 对象的 displacement 方法,获取模拟中特定节点的位移信息。这些节点的 ID 是从 simulation.mesh.node_ids[10:] 获取的,这意味着它获取的是除了前10个节点之外的所有节点的 ID。 # 参数 norm=True 表示获取的是位移的范数(即位移的大小)。然后,代码打印了获取到的位移信息。 # 最后,使用 plot 方法绘制了位移信息的图形。具体的绘图结果取决于 nodes_displacement 对象的类型和 plot 方法的实现。 # 如果你需要更具体的信息,如 nodes_displacement 的具体类型或 plot 方法的具体行为,你可能需要查阅相关的文档或源代码。 .. image-sg:: /examples/00-Different-analysis-types/images/sphx_glr_01-static-simulation_003.png :alt: 01 static simulation :srcset: /examples/00-Different-analysis-types/images/sphx_glr_01-static-simulation_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none results U_N (m) set_ids 1 node_ids 11 0.0000e+00 12 0.0000e+00 13 0.0000e+00 14 0.0000e+00 15 0.0000e+00 16 0.0000e+00 ... ... .. GENERATED FROM PYTHON SOURCE LINES 84-87 Extract tensor stress, apply averaging, compute equivalent ---------------------------------------------------------- 从 rst 文件中提取原始单元节点应力: .. GENERATED FROM PYTHON SOURCE LINES 87-107 .. code-block:: Python elem_nodal_stress = simulation.stress() print(elem_nodal_stress) # 从结果文件中计算节点应力 nodal_stress = simulation.stress_nodal() print(nodal_stress) # 从结果文件计算单元应力 elemental_stress = simulation.stress_elemental() print(elemental_stress) # 提取特定单元的单元应力 elemental_stress = elemental_stress.select(element_ids=[5, 6, 7]) elemental_stress.plot() # 从结果文件中计算节点等效应力 eqv_stress = simulation.stress_eqv_von_mises_nodal() print(eqv_stress) eqv_stress.plot() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/00-Different-analysis-types/images/sphx_glr_01-static-simulation_004.png :alt: 01 static simulation :srcset: /examples/00-Different-analysis-types/images/sphx_glr_01-static-simulation_004.png :class: sphx-glr-multi-img * .. image-sg:: /examples/00-Different-analysis-types/images/sphx_glr_01-static-simulation_005.png :alt: 01 static simulation :srcset: /examples/00-Different-analysis-types/images/sphx_glr_01-static-simulation_005.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none results S (Pa) ... set_ids 1 ... node 0 1 2 3 4 5 ... element_ids components ... 5 XX -3.7836e+03 1.1793e+04 -3.2947e+04 -2.2019e+04 7.3721e+03 1.8301e+04 ... YY -1.2110e+05 -9.9179e+04 -1.0033e+05 -7.4344e+04 -9.9179e+04 -8.0542e+04 ... ZZ -3.7836e+03 7.3721e+03 -3.2461e+04 -2.2019e+04 1.1793e+04 1.8301e+04 ... XY 5.3318e+02 -9.7301e+03 2.6037e+04 -1.2541e+03 5.5354e+02 -1.1500e+04 ... YZ -5.3318e+02 -5.5354e+02 1.1343e+03 1.2541e+03 9.7301e+03 1.1500e+04 ... XZ -1.4540e+02 5.9879e+02 -2.4309e+02 -2.1037e-10 5.9879e+02 2.5527e+02 ... ... ... ... ... ... ... ... ... ... results S (Pa) set_ids 1 node_ids components 1 XX -4.8113e+03 YY -1.1280e+05 ZZ -4.8113e+03 XY 0.0000e+00 YZ 0.0000e+00 XZ 0.0000e+00 ... ... ... results S (Pa) set_ids 1 element_ids components 5 XX -1.2071e+04 YY -1.0000e+05 ZZ -1.2071e+04 XY 3.8006e+03 YZ -3.8006e+03 XZ 4.1885e+01 ... ... ... results S_VM (Pa) set_ids 1 node_ids 1 1.0799e+05 26 1.0460e+05 14 8.1283e+04 12 5.2324e+04 2 1.0460e+05 27 1.0006e+05 ... ... .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.540 seconds) .. _sphx_glr_download_examples_00-Different-analysis-types_01-static-simulation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01-static-simulation.ipynb <01-static-simulation.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01-static-simulation.py <01-static-simulation.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_