Skip to content

Commit 6cc7ab0

Browse files
authored
Add official support for CFX .res files (#1620)
* Mark res as supported in doc landing page Signed-off-by: paul.profizi <[email protected]> * Add a CFX examples section Signed-off-by: paul.profizi <[email protected]> * Fix download_cfx_mixing_elbow in downloads.py Signed-off-by: paul.profizi <[email protected]> * Add an example for CFX .res files Signed-off-by: paul.profizi <[email protected]> * Proposal: automatically set .res CFX files as cas and dat Signed-off-by: paul.profizi <[email protected]> * Skip the DataSources Signed-off-by: paul.profizi <[email protected]> * Update 00-cfx_res_files.py Signed-off-by: paul.profizi <[email protected]> * Add test Signed-off-by: paul.profizi <[email protected]> --------- Signed-off-by: paul.profizi <[email protected]>
1 parent 120a3b9 commit 6cc7ab0

File tree

6 files changed

+99
-20
lines changed

6 files changed

+99
-20
lines changed

doc/source/index.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ apps by DPF and their related formats:
2424
| || .rst, .mode || **1.0** and later | :ref:`ref_basic_example` |
2525
| MAPDL || .rfrq, .rdsp || (*Ansys 2021 R1*) | |
2626
+--------------------+------------------------+----------------------------------+----------------------------------+
27-
| LS DYNA | .d3plot, .binout || **4.0** and later | :ref:`lsdyna_operators` |
27+
| LS DYNA | .d3plot, .binout || **4.0** and later | :ref:`examples_lsdyna` |
2828
| | || (*Ansys 2022 R2*) | |
2929
+--------------------+------------------------+----------------------------------+----------------------------------+
3030
| || *CFF restart files* || | :ref:`ref_fluids_model` |
@@ -34,12 +34,13 @@ apps by DPF and their related formats:
3434
| || *Project files* | | :ref:`ref_fluids_results` |
3535
| || .flprj | | |
3636
+--------------------+------------------------+----------------------------------+----------------------------------+
37-
| || *CFF files* || | :ref:`ref_fluids_model` |
37+
| || *CFF files* || | :ref:`examples_cfx` |
3838
| || .cas/dat.cff || +----------------------------------+
39-
| | || **7.0** and later | :ref:`ref_fluids_mesh` |
39+
| || .res || **7.0** and later | :ref:`ref_fluids_model` |
4040
| CFX +------------------------+| (*Ansys 2024 R1 pre0*) +----------------------------------+
41-
| || *Project files* | | :ref:`ref_fluids_results` |
42-
| || .flprj | | |
41+
| || *Project files* | | :ref:`ref_fluids_mesh` |
42+
| || .flprj | +----------------------------------+
43+
| || | | :ref:`ref_fluids_results` |
4344
+--------------------+------------------------+----------------------------------+----------------------------------+
4445

4546
Visualisation is ensured by VTK and leverages `PyVista tools

examples/15-cfx/00-cfx_res_files.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
.. _ref_cfx_res_files:
3+
4+
Read CFX `.res` files
5+
---------------------
6+
7+
This example demonstrates how to read Ansys CFX `.res` files.
8+
9+
.. note::
10+
This example requires DPF 7.0 (ansys-dpf-server-2024-1-pre0) or above.
11+
For more information, see :ref:`ref_compatibility`.
12+
13+
"""
14+
15+
###############################################################################
16+
# Exploring an Ansys CFX `.res` file
17+
# ----------------------------------
18+
# The first part of the example demonstrates how you can load an
19+
# Ansys CFX `.res` file in a model.
20+
21+
import ansys.dpf.core as dpf
22+
from ansys.dpf.core import examples
23+
24+
path = examples.download_cfx_mixing_elbow()
25+
model = dpf.Model(path)
26+
print(model)
27+
28+
###############################################################################
29+
# Exploring the mesh
30+
# ~~~~~~~~~~~~~~~~~~
31+
# Explore the mesh through the ``MeshInfo``. The ``MeshInfo`` provides metadata
32+
# information about the mesh. For fluid models, it is useful to know the bodies and
33+
# face zones, as well as the topological relationships between them. First get all
34+
# the available information in the ``MeshInfo``.
35+
mesh_info = model.metadata.mesh_info
36+
print(mesh_info)
37+
38+
###############################################################################
39+
# The ``MeshInfo`` exposes several helpers, such as a dictionary of available bodies:
40+
print(mesh_info.bodies)
41+
42+
###############################################################################
43+
# Or the dictionary of available face zones:
44+
print(mesh_info.face_zones)
45+
46+
###############################################################################
47+
# Exploring the results
48+
# ~~~~~~~~~~~~~~~~~~~~~
49+
# Explore the available results through the ``ResultInfo``.
50+
# The ``ResultInfo`` provides metadata information about the results stored in the files.
51+
# First get all the available information in the ``ResultInfo``.
52+
# As you can see above, the ``ResultInfo`` information is also listed when printing the ``Model``.
53+
result_info = model.metadata.result_info
54+
print(result_info)
55+
56+
###############################################################################
57+
# The ``ResultInfo`` class exposes the list of ``AvailableResults``.
58+
print(result_info.available_results)
59+
60+
###############################################################################
61+
# Extracting data
62+
# ~~~~~~~~~~~~~~~
63+
# Extracting the mesh or results is then the same as for any other file type.

examples/15-cfx/README.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. _examples_cfx:
2+
3+
CFX examples
4+
============
5+
These examples show how to post-process CFX result files.
6+

src/ansys/dpf/core/data_sources.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ def set_result_file_path(self, filepath, key=""):
119119
['/tmp/file.rst']
120120
121121
"""
122+
extension = os.path.splitext(filepath)[1]
123+
# Handle .res files from CFX
124+
if key == "" and extension == ".res":
125+
key = "cas"
126+
self.add_file_path(filepath, key="dat")
122127
# Handle no key given and no file extension
123-
if key == "" and os.path.splitext(filepath)[1] == "":
128+
if key == "" and extension == "":
124129
key = self.guess_result_key(str(filepath))
125130
# Look for another extension for .h5 and .cff files
126-
if key == "" and os.path.splitext(filepath)[1] in [".h5", ".cff"]:
131+
if key == "" and extension in [".h5", ".cff"]:
127132
key = self.guess_second_key(str(filepath))
128133
if key == "":
129134
self._api.data_sources_set_result_file_path_utf8(self, str(filepath))

src/ansys/dpf/core/examples/downloads.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,9 +1565,9 @@ def download_cfx_heating_coil(
15651565

15661566
def download_cfx_mixing_elbow(
15671567
should_upload: bool = True, server=None, return_local_path=False
1568-
) -> dict:
1569-
"""Download the flprj, cas and dat files of a CFX analysis of a mixing elbow
1570-
and return the download paths into a dictionary extension->path.
1568+
) -> str:
1569+
"""Download the res file of a CFX analysis of a mixing elbow
1570+
and return the download path.
15711571
If the server is remote (or doesn't share memory), the file is uploaded or made available
15721572
on the server side.
15731573
@@ -1587,28 +1587,26 @@ def download_cfx_mixing_elbow(
15871587
15881588
Returns
15891589
-------
1590-
dict[str:str]
1591-
Path to the example files.
1590+
str:
1591+
Path to the example file.
15921592
15931593
Examples
15941594
--------
15951595
Download an example result file and return the path of the file
15961596
15971597
>>> from ansys.dpf.core import examples
1598-
>>> paths = examples.download_cfx_mixing_elbow()
1599-
>>> paths
1600-
{'cas': 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\cfx-mixing_elbow\\InjectMixer.res',
1601-
'dat': 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\cfx-mixing_elbow\\InjectMixer.res'} # noqa: E501
1598+
>>> path = examples.download_cfx_mixing_elbow()
1599+
>>> path
1600+
'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\cfx-mixing_elbow\\InjectMixer.res' # noqa: E501
16021601
16031602
"""
1604-
file = _download_file(
1603+
return _download_file(
16051604
"result_files/cfx-mixing_elbow",
16061605
"InjectMixer.res",
16071606
should_upload,
16081607
server,
16091608
return_local_path,
16101609
)
1611-
return {"cas": file, "dat": file}
16121610

16131611

16141612
def find_simple_bar(should_upload: bool = True, server=None, return_local_path=False) -> str:

tests/test_datasources.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def test_setresultpath_data_sources_no_extension(d3plot_beam, binout_glstat, ser
6060
def test_set_resultpath_data_sources_h5(server_type):
6161
from ansys.dpf.core import examples
6262
cas_h5_file = examples.download_fluent_axial_comp(server=server_type)["cas"][0]
63-
print(cas_h5_file)
6463
data_sources = dpf.core.DataSources(server=server_type)
6564
data_sources.set_result_file_path(cas_h5_file)
6665
assert data_sources.result_key == "cas"
@@ -71,14 +70,21 @@ def test_set_resultpath_data_sources_h5(server_type):
7170
def test_set_resultpath_data_sources_cff(server_type):
7271
from ansys.dpf.core import examples
7372
cas_h5_file = examples.download_cfx_heating_coil(server=server_type)["cas"]
74-
print(cas_h5_file)
7573
data_sources = dpf.core.DataSources(server=server_type)
7674
data_sources.set_result_file_path(cas_h5_file)
7775
assert data_sources.result_key == "cas"
7876
data_sources = dpf.core.DataSources(result_path=cas_h5_file, server=server_type)
7977
assert data_sources.result_key == "cas"
8078

8179

80+
def test_set_resultpath_data_sources_cfx_res(server_type):
81+
from ansys.dpf.core import examples
82+
res_file = examples.download_cfx_mixing_elbow(server=server_type)
83+
data_sources = dpf.core.DataSources(server=server_type)
84+
data_sources.set_result_file_path(res_file)
85+
assert data_sources.result_key == "cas"
86+
87+
8288
def test_addupstream_data_sources(allkindofcomplexity, server_type):
8389
data_sources = dpf.core.DataSources(server=server_type)
8490
data_sources2 = dpf.core.DataSources(server=server_type)

0 commit comments

Comments
 (0)