.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\01-Detailed-Examples\03-explore-result-data-harmonic.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_03-explore-result-data-harmonic.py: .. _ref_data_data_frame_example: Explore the data of a result with the DataFrame - Harmonic Simulation ===================================================================== **使用 DataFrame 查看结果数据 - 谐波分析** 本脚本以谐波模拟为例,说明如何与每个结果返回的 post 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_harmonic_clamped_pipe() # 自动检测模拟类型,请使用 simulation = post.load_simulation(example_path) # 要启用 auto-completion 功能,请使用等效的命令: simulation = post.HarmonicMechanicalSimulation(example_path) # 打印 simulation ,了解可用内容的概况 print(simulation) .. rst-class:: sphx-glr-script-out .. code-block:: none Harmonic Mechanical Simulation. Data Sources ------------------------------ C:\Users\ff\AppData\Roaming\Python\Python310\site-packages\ansys\dpf\core\examples\result_files\harmonic\clamped_pipe.rst DPF Model ------------------------------ Msup analysis Unit system: NMM: mm, ton, N, s, mA, 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 ------------------------------ DPF Meshed Region: 9943 nodes 5732 elements Unit: mm With solid (3D) elements, shell (2D) elements, shell (3D) elements ------------------------------ DPF Time/Freq Support: Number of sets: 5 With complex values Cumulative Frequency (Hz) LoadStep Substep RPM 1 2000.000000 1 1 0.000000 2 4000.000000 1 2 0.000000 3 6000.000000 1 3 0.000000 4 8000.000000 1 4 0.000000 5 10000.000000 1 5 0.000000 .. GENERATED FROM PYTHON SOURCE LINES 41-44 Extract displacement over all sets as an example ------------------------------------------------ **以提取所有 sets 的位移结果为例** .. GENERATED FROM PYTHON SOURCE LINES 44-49 .. code-block:: Python displacement = simulation.displacement(all_sets=True) print(displacement) print(type(displacement)) # .. rst-class:: sphx-glr-script-out .. code-block:: none results U ... set_ids 1 2 3 ... complex 0 1 0 1 0 1 ... node_ids components ... 3548 X 9.3929e+01 0.0000e+00 -5.2330e+01 0.0000e+00 -1.1203e+01 0.0000e+00 ... Y -4.3312e+02 0.0000e+00 1.8810e+02 0.0000e+00 6.8681e+01 0.0000e+00 ... Z 9.6172e-01 0.0000e+00 -1.3049e+01 0.0000e+00 2.3508e+01 0.0000e+00 ... 3656 X 1.0516e+02 0.0000e+00 -5.8461e+01 0.0000e+00 -1.4575e+01 0.0000e+00 ... Y -4.6059e+02 0.0000e+00 2.0315e+02 0.0000e+00 7.4665e+01 0.0000e+00 ... Z 9.4728e-01 0.0000e+00 -1.3728e+01 0.0000e+00 2.5207e+01 0.0000e+00 ... ... ... ... ... ... ... ... ... ... .. GENERATED FROM PYTHON SOURCE LINES 50-51 循环遍历所有列和行,了解 DataFrame 并获取每个索引的值。 .. GENERATED FROM PYTHON SOURCE LINES 51-60 .. code-block:: Python # columns for column in displacement.columns: print(f'Column with label "{column.name}" and available values {column.values}.') # rows for row in displacement.index: print(f'Row with label "{row.name}" and available values {row.values}.') .. rst-class:: sphx-glr-script-out .. code-block:: none Column with label "results" and available values ['U']. Column with label "set_ids" and available values [1, 2, 3, 4, 5]. Column with label "complex" and available values [0, 1]. Row with label "node_ids" and available values [3548 3656 4099 ... 3260 9942 9943]. Row with label "components" and available values ['X', 'Y', 'Z']. .. GENERATED FROM PYTHON SOURCE LINES 61-62 这里的 “complex” 列标签代表复数,0 表示实数部分,1 表示虚数部分。 --ff .. GENERATED FROM PYTHON SOURCE LINES 65-68 Make selections in this DataFrame --------------------------------- **在此 DataFrame 中进行选择** .. GENERATED FROM PYTHON SOURCE LINES 70-71 上面显示的所有标签和数值都可用于选择 DataFrame 的子部分。 .. GENERATED FROM PYTHON SOURCE LINES 71-84 .. code-block:: Python all_real_values = displacement.select(complex=0) print(all_real_values) # 这段代码首先调用 displacement 对象的 select 方法,选择复数部分为 0(即实数部分)的位移信息。然后,代码打印了选择的位移信息。 all_imaginary_values = displacement.select(complex=1) print(all_imaginary_values) # 这段代码首先调用 displacement 对象的 select 方法,选择复数部分为 1(即虚数部分)的位移信息。然后,代码打印了选择的位移信息。 sets_values = displacement.select(set_ids=[1, 2]) print(sets_values) node_values = displacement.select(node_ids=[3548]) print(node_values) .. rst-class:: sphx-glr-script-out .. code-block:: none results U set_ids 1 2 3 4 5 complex 0 node_ids components 3548 X 9.3929e+01 -5.2330e+01 -1.1203e+01 -1.1510e+01 -1.4457e+01 Y -4.3312e+02 1.8810e+02 6.8681e+01 2.2900e+01 -6.6765e+00 Z 9.6172e-01 -1.3049e+01 2.3508e+01 1.4745e+00 -5.9568e+00 3656 X 1.0516e+02 -5.8461e+01 -1.4575e+01 -1.3822e+01 -1.7782e+01 Y -4.6059e+02 2.0315e+02 7.4665e+01 2.7874e+01 1.5223e+00 Z 9.4728e-01 -1.3728e+01 2.5207e+01 1.4487e+00 -7.3947e+00 ... ... ... ... ... ... ... results U set_ids 1 2 3 4 5 complex 1 node_ids components 3548 X 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 Y 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 Z 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 3656 X 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 Y 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 Z 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 ... ... ... ... ... ... ... results U set_ids 1 2 complex 0 1 0 1 node_ids components 3548 X 9.3929e+01 0.0000e+00 -5.2330e+01 0.0000e+00 Y -4.3312e+02 0.0000e+00 1.8810e+02 0.0000e+00 Z 9.6172e-01 0.0000e+00 -1.3049e+01 0.0000e+00 3656 X 1.0516e+02 0.0000e+00 -5.8461e+01 0.0000e+00 Y -4.6059e+02 0.0000e+00 2.0315e+02 0.0000e+00 Z 9.4728e-01 0.0000e+00 -1.3728e+01 0.0000e+00 ... ... ... ... ... ... results U ... set_ids 1 2 3 ... complex 0 1 0 1 0 1 ... node_ids components ... 3548 X 9.3929e+01 0.0000e+00 -5.2330e+01 0.0000e+00 -1.1203e+01 0.0000e+00 ... Y -4.3312e+02 0.0000e+00 1.8810e+02 0.0000e+00 6.8681e+01 0.0000e+00 ... Z 9.6172e-01 0.0000e+00 -1.3049e+01 0.0000e+00 2.3508e+01 0.0000e+00 ... .. GENERATED FROM PYTHON SOURCE LINES 85-88 Make selections by index in this DataFrame ------------------------------------------ **在此 DataFrame 中按索引进行选择** .. GENERATED FROM PYTHON SOURCE LINES 90-92 要按索引选择每个标签的值,可以使用 iselect 方法。(注意这个方法索引值是从 0 开始的。 --ff) 从索引到 ID 的顺序与上述索引值方法返回的顺序一致。 .. GENERATED FROM PYTHON SOURCE LINES 92-99 .. code-block:: Python sets_values = displacement.iselect(set_ids=0) print(sets_values) node_values = displacement.iselect(node_ids=[0]) print(node_values) .. rst-class:: sphx-glr-script-out .. code-block:: none results U set_ids 1 complex 0 1 node_ids components 3548 X 9.3929e+01 0.0000e+00 Y -4.3312e+02 0.0000e+00 Z 9.6172e-01 0.0000e+00 3656 X 1.0516e+02 0.0000e+00 Y -4.6059e+02 0.0000e+00 Z 9.4728e-01 0.0000e+00 ... ... ... ... results U ... set_ids 1 2 3 ... complex 0 1 0 1 0 1 ... node_ids components ... 3548 X 9.3929e+01 0.0000e+00 -5.2330e+01 0.0000e+00 -1.1203e+01 0.0000e+00 ... Y -4.3312e+02 0.0000e+00 1.8810e+02 0.0000e+00 6.8681e+01 0.0000e+00 ... Z 9.6172e-01 0.0000e+00 -1.3049e+01 0.0000e+00 2.3508e+01 0.0000e+00 ... .. GENERATED FROM PYTHON SOURCE LINES 100-103 Make multi selections in this DataFrame --------------------------------------- 在此 DataFrame 中进行多重选择 .. GENERATED FROM PYTHON SOURCE LINES 103-111 .. code-block:: Python real_values_for_one_set_onde_node = displacement.select( node_ids=[3548], set_ids=1, complex=0 ) print(real_values_for_one_set_onde_node) .. rst-class:: sphx-glr-script-out .. code-block:: none results U set_ids 1 complex 0 node_ids components 3548 X 9.3929e+01 Y -4.3312e+02 Z 9.6172e-01 .. GENERATED FROM PYTHON SOURCE LINES 112-115 Make selections to plot the DataFrame ------------------------------------- 选择并绘制 DataFrame .. GENERATED FROM PYTHON SOURCE LINES 115-118 .. code-block:: Python displacement.plot(set_ids=1, complex=0) .. image-sg:: /examples/01-Detailed-Examples/images/sphx_glr_03-explore-result-data-harmonic_001.png :alt: 03 explore result data harmonic :srcset: /examples/01-Detailed-Examples/images/sphx_glr_03-explore-result-data-harmonic_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.330 seconds) .. _sphx_glr_download_examples_01-Detailed-Examples_03-explore-result-data-harmonic.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 03-explore-result-data-harmonic.ipynb <03-explore-result-data-harmonic.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 03-explore-result-data-harmonic.py <03-explore-result-data-harmonic.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_