.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\01-Detailed-Examples\05-export_data.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_01-Detailed-Examples_05-export_data.py: .. _ref_export_data_example: Export data contained in a DataFrame to a new format ==================================================== **将 DataFrame 中包含的数据导出为新格式** 本脚本以静态模拟为例,说明如何将数据从 DataFrame 导出到另一种格式。 .. GENERATED FROM PYTHON SOURCE LINES 12-15 Perform required imports ------------------------ **执行所需的导入** .. GENERATED FROM PYTHON SOURCE LINES 17-18 本示例使用了一个提供的文件,您可以通过导入 DPF ``examples`` 包获得该文件。 .. GENERATED FROM PYTHON SOURCE LINES 18-22 .. code-block:: Python from ansys.dpf import post from ansys.dpf.post import examples .. GENERATED FROM PYTHON SOURCE LINES 23-26 Get the ``Simulation`` object ----------------------------- **获取允许访问结果的 ``Simulation`` 对象** .. GENERATED FROM PYTHON SOURCE LINES 28-29 必须使用结果文件的路径实例化 ``Simulation`` 对象。例如,Windows 下为 ``"C:/Users/user/my_result.rst"`` 或 Linux 下为 ``"/home/user/my_result.rst"`` 。 .. GENERATED FROM PYTHON SOURCE LINES 29-40 .. code-block:: Python example_path = examples.download_crankshaft() # 自动检测模拟类型,请使用 simulation = post.load_simulation(example_path) # 要启用 auto-completion 功能,请使用等效的命令: simulation = post.StaticMechanicalSimulation(example_path) # 打印 simulation ,了解可用内容的概况 print(simulation) .. 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\crankshaft\crankshaft.rst DPF Model ------------------------------ Static analysis Unit system: MKS: m, kg, N, s, V, A, degC Physics Type: Mechanical Available results: - displacement: Nodal Displacement - velocity: Nodal Velocity - acceleration: Nodal Acceleration - 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: 69762 nodes 39315 elements Unit: m With solid (3D) elements ------------------------------ DPF Time/Freq Support: Number of sets: 3 Cumulative Time (s) LoadStep Substep 1 1.000000 1 1 2 2.000000 1 2 3 3.000000 1 3 .. GENERATED FROM PYTHON SOURCE LINES 41-44 Extract elemental nodal stress ------------------------------ **提取单元节点应力** .. GENERATED FROM PYTHON SOURCE LINES 44-48 .. code-block:: Python stress = simulation.stress_nodal(all_sets=True) print(stress) .. rst-class:: sphx-glr-script-out .. code-block:: none results S (Pa) set_ids 1 2 3 node_ids components 4872 XX 1.8630e+05 -2.6097e+05 -1.4740e+06 YY 8.2844e+06 2.8386e+07 5.9846e+07 ZZ -1.3700e+07 -7.9701e+06 1.7550e+07 XY 5.9991e+05 6.6079e+05 -7.5702e+05 YZ -1.9344e+08 -3.8683e+08 -5.7889e+08 XZ -6.2727e+06 -2.8690e+06 1.0085e+07 ... ... ... ... ... .. GENERATED FROM PYTHON SOURCE LINES 49-52 Export to a numpy.ndarray ------------------------- **导出为 numpy.ndarray** .. GENERATED FROM PYTHON SOURCE LINES 52-62 .. code-block:: Python # 要导出为 numpy.ndarray,DataFrame 必须只包含列标签值单一组合的数据。 # 选择一个荷载步,因为 dataframe 包含多个荷载步的数据 stress_1 = stress.select(set_ids=1) print(stress_1) # 将其导出为 numpy.ndarray stress_1_array = stress_1.array print(stress_1_array) .. rst-class:: sphx-glr-script-out .. code-block:: none results S (Pa) set_ids 1 node_ids components 4872 XX 1.8630e+05 YY 8.2844e+06 ZZ -1.3700e+07 XY 5.9991e+05 YZ -1.9344e+08 XZ -6.2727e+06 ... ... ... [[ 1.86304666e+05 8.28436396e+06 -1.37003496e+07 5.99907420e+05 -1.93439042e+08 -6.27268473e+06] [-4.26076223e+05 4.27353118e+06 3.61489620e+05 1.27870163e+07 -1.64836014e+08 3.78081724e+05] [ 4.36222667e+06 2.02005176e+07 3.49514000e+07 5.31671006e+07 -1.69700130e+08 4.16285682e+06] ... [ 2.43008628e+06 3.45306104e+05 -6.96869804e+07 -1.88974926e+06 1.78308703e+08 3.70653393e+07] [-3.15639127e+06 -4.87652891e+07 -1.52290762e+08 3.59354599e+07 1.97891422e+08 2.65947999e+07] [ 6.32054643e+05 -3.24065639e+07 -1.18464495e+08 4.38019212e+07 2.00763823e+08 2.51322083e+07]] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.381 seconds) .. _sphx_glr_download_examples_01-Detailed-Examples_05-export_data.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 05-export_data.ipynb <05-export_data.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 05-export_data.py <05-export_data.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_