DPF model#

DPF 模型是打开结果文件的起点。通过 Model 对象,您可以连接各种运算符并显示结果和数据。

要创建 Model 对象的实例,请导入 pydpf-core 软件包并加载结果文件。所提供的路径必须是绝对路径或相对于 DPF 服务器的路径。

from ansys.dpf import core as dpf
from ansys.dpf.core import examples

path = examples.find_simple_bar()
model = dpf.Model(path)

要了解结果文件中的内容,可以打印模型(或任何其他实例):

print(model)
DPF Model
------------------------------
Static analysis
Unit system: Metric (m, kg, N, s, V, A)
Physics Type: Mechanical
Available results:
     -  displacement: Nodal Displacement
     -  element_nodal_forces: ElementalNodal Element nodal Forces
     -  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
     -  structural_temperature: ElementalNodal Temperature
------------------------------
DPF  Meshed Region:
  3751 nodes
  3000 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

有关综合模型示例,请参阅 Basic DPF-Core usage

有关 Model 对象的描述,请参阅 ref_model

Model metadata#

要访问有关分析的所有信息,可以使用模型元数据:

  • Type of analysis/分析类型

  • Time or frequency descriptions/时间或频率描述

  • Mesh/网格

  • Available results/可用结果

本例说明了如何获取分析类型:

model.metadata.result_info.analysis_type
'static'

本例展示了如何获取网格信息:

model.metadata.meshed_region.nodes.n_nodes
model.metadata.meshed_region.elements.n_elements
print(model.metadata.meshed_region.elements.element_by_id(1))
3751
3000
DPF Element 1
    Index:         1400
    Nodes:            8
    Type:       element_types.Hex8
    Shape:        Solid

此示例显示如何获取 time sets:

time_freq_support =  model.metadata.time_freq_support
print(time_freq_support.time_frequencies.data)
[1.]

有关 Metadata 对象的描述,请参阅 ref_model

Model results#

Model 对象包含 results 属性,您可以用它创建操作符来访问某些结果。

本例显示了如何查看可用结果:

print(model.results)
Static analysis
Unit system: Metric (m, kg, N, s, V, A)
Physics Type: Mechanical
Available results:
     -  displacement: Nodal Displacement
     -  element_nodal_forces: ElementalNodal Element nodal Forces
     -  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
     -  structural_temperature: ElementalNodal Temperature
Model.results

Available results of the model.

Organizes the results from DPF into accessible methods. All the available results are dynamically created depending on the model’s class:ansys.dpf.core.result_info.

Returns:

results – Available results of the model if possible, else returns common results.

Return type:

Results, CommonResults

all types of results

Result provider helper wrapping all types of provider available for a given result file.

Examples

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_electric_therm())
>>> v = model.results.electric_potential
>>> dissip = model.results.thermal_dissipation_energy
Type:

Result

Examples

Extract the result object from a model.

>>> from ansys.dpf import core as dpf
>>> from ansys.dpf.core import examples
>>> model = dpf.Model(examples.find_simple_bar())
>>> results = model.results # printable object

Access the displacement at all times.

>>> from ansys.dpf.core import Model
>>> from ansys.dpf.core import examples
>>> transient = examples.download_transient_result()
>>> model = Model(transient)
>>> displacements = model.results.displacement.on_all_time_freqs.eval()

使用 results 属性,可以直接选择时间、频率或空间子集来获取给定结果。

本例展示了如何在网格范围内获得所有时间频率的位移结果:

disp_result = model.results.displacement
disp_at_all_times_on_node_1 =  disp_result.on_all_time_freqs.on_mesh_scoping([1])

有关使用 Result 对象的示例,请参阅 Choose a time scoping for a transient analysis

有关 Model 对象的描述,请参阅 ref_results

API reference#

更多信息,请参阅 ref_modelref_results