Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add official support for CFX .res files #1620

Merged
merged 10 commits into from
Jun 24, 2024
11 changes: 6 additions & 5 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ apps by DPF and their related formats:
| || .rst, .mode || **1.0** and later | :ref:`ref_basic_example` |
| MAPDL || .rfrq, .rdsp || (*Ansys 2021 R1*) | |
+--------------------+------------------------+----------------------------------+----------------------------------+
| LS DYNA | .d3plot, .binout || **4.0** and later | :ref:`lsdyna_operators` |
| LS DYNA | .d3plot, .binout || **4.0** and later | :ref:`examples_lsdyna` |
| | || (*Ansys 2022 R2*) | |
+--------------------+------------------------+----------------------------------+----------------------------------+
| || *CFF restart files* || | :ref:`ref_fluids_model` |
Expand All @@ -34,12 +34,13 @@ apps by DPF and their related formats:
| || *Project files* | | :ref:`ref_fluids_results` |
| || .flprj | | |
+--------------------+------------------------+----------------------------------+----------------------------------+
| || *CFF files* || | :ref:`ref_fluids_model` |
| || *CFF files* || | :ref:`examples_cfx` |
| || .cas/dat.cff || +----------------------------------+
| | || **7.0** and later | :ref:`ref_fluids_mesh` |
| || .res || **7.0** and later | :ref:`ref_fluids_model` |
| CFX +------------------------+| (*Ansys 2024 R1 pre0*) +----------------------------------+
| || *Project files* | | :ref:`ref_fluids_results` |
| || .flprj | | |
| || *Project files* | | :ref:`ref_fluids_mesh` |
| || .flprj | +----------------------------------+
| || | | :ref:`ref_fluids_results` |
+--------------------+------------------------+----------------------------------+----------------------------------+

Visualisation is ensured by VTK and leverages `PyVista tools
Expand Down
63 changes: 63 additions & 0 deletions examples/15-cfx/00-cfx_res_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
.. _ref_cfx_res_files:

Read CFX `.res` files
---------------------

This example demonstrates how to read Ansys CFX `.res` files.

.. note::
This example requires DPF 7.0 (ansys-dpf-server-2024-1-pre0) or above.
For more information, see :ref:`ref_compatibility`.

"""

###############################################################################
# Exploring an Ansys CFX `.res` file
# ----------------------------------
# The first part of the example demonstrates how you can load an
# Ansys CFX `.res` file in a model.

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

path = examples.download_cfx_mixing_elbow()
model = dpf.Model(path)
print(model)

###############################################################################
# Exploring the mesh
# ~~~~~~~~~~~~~~~~~~
# Explore the mesh through the ``MeshInfo``. The ``MeshInfo`` provides metadata
# information about the mesh. For fluid models, it is useful to know the bodies and
# face zones, as well as the topological relationships between them. First get all
# the available information in the ``MeshInfo``.
mesh_info = model.metadata.mesh_info
print(mesh_info)

###############################################################################
# The ``MeshInfo`` exposes several helpers, such as a dictionary of available bodies:
print(mesh_info.bodies)

###############################################################################
# Or the dictionary of available face zones:
print(mesh_info.face_zones)

###############################################################################
# Exploring the results
# ~~~~~~~~~~~~~~~~~~~~~
# Explore the available results through the ``ResultInfo``.
# The ``ResultInfo`` provides metadata information about the results stored in the files.
# First get all the available information in the ``ResultInfo``.
# As you can see above, the ``ResultInfo`` information is also listed when printing the ``Model``.
result_info = model.metadata.result_info
print(result_info)

###############################################################################
# The ``ResultInfo`` class exposes the list of ``AvailableResults``.
print(result_info.available_results)

###############################################################################
# Extracting data
# ~~~~~~~~~~~~~~~
# Extracting the mesh or results is then the same as for any other file type.
6 changes: 6 additions & 0 deletions examples/15-cfx/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _examples_cfx:

CFX examples
============
These examples show how to post-process CFX result files.

9 changes: 7 additions & 2 deletions src/ansys/dpf/core/data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ def set_result_file_path(self, filepath, key=""):
['/tmp/file.rst']

"""
extension = os.path.splitext(filepath)[1]
# Handle .res files from CFX
if key == "" and extension == ".res":
key = "cas"
self.add_file_path(filepath, key="dat")
# Handle no key given and no file extension
if key == "" and os.path.splitext(filepath)[1] == "":
if key == "" and extension == "":
key = self.guess_result_key(str(filepath))
# Look for another extension for .h5 and .cff files
if key == "" and os.path.splitext(filepath)[1] in [".h5", ".cff"]:
if key == "" and extension in [".h5", ".cff"]:
key = self.guess_second_key(str(filepath))
if key == "":
self._api.data_sources_set_result_file_path_utf8(self, str(filepath))
Expand Down
20 changes: 9 additions & 11 deletions src/ansys/dpf/core/examples/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -1565,9 +1565,9 @@ def download_cfx_heating_coil(

def download_cfx_mixing_elbow(
should_upload: bool = True, server=None, return_local_path=False
) -> dict:
"""Download the flprj, cas and dat files of a CFX analysis of a mixing elbow
and return the download paths into a dictionary extension->path.
) -> str:
"""Download the res file of a CFX analysis of a mixing elbow
and return the download path.
If the server is remote (or doesn't share memory), the file is uploaded or made available
on the server side.

Expand All @@ -1587,28 +1587,26 @@ def download_cfx_mixing_elbow(

Returns
-------
dict[str:str]
Path to the example files.
str:
Path to the example file.

Examples
--------
Download an example result file and return the path of the file

>>> from ansys.dpf.core import examples
>>> paths = examples.download_cfx_mixing_elbow()
>>> paths
{'cas': 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\cfx-mixing_elbow\\InjectMixer.res',
'dat': 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\cfx-mixing_elbow\\InjectMixer.res'} # noqa: E501
>>> path = examples.download_cfx_mixing_elbow()
>>> path
'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\cfx-mixing_elbow\\InjectMixer.res' # noqa: E501

"""
file = _download_file(
return _download_file(
"result_files/cfx-mixing_elbow",
"InjectMixer.res",
should_upload,
server,
return_local_path,
)
return {"cas": file, "dat": file}


def find_simple_bar(should_upload: bool = True, server=None, return_local_path=False) -> str:
Expand Down
10 changes: 8 additions & 2 deletions tests/test_datasources.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def test_setresultpath_data_sources_no_extension(d3plot_beam, binout_glstat, ser
def test_set_resultpath_data_sources_h5(server_type):
from ansys.dpf.core import examples
cas_h5_file = examples.download_fluent_axial_comp(server=server_type)["cas"][0]
print(cas_h5_file)
data_sources = dpf.core.DataSources(server=server_type)
data_sources.set_result_file_path(cas_h5_file)
assert data_sources.result_key == "cas"
Expand All @@ -71,14 +70,21 @@ def test_set_resultpath_data_sources_h5(server_type):
def test_set_resultpath_data_sources_cff(server_type):
from ansys.dpf.core import examples
cas_h5_file = examples.download_cfx_heating_coil(server=server_type)["cas"]
print(cas_h5_file)
data_sources = dpf.core.DataSources(server=server_type)
data_sources.set_result_file_path(cas_h5_file)
assert data_sources.result_key == "cas"
data_sources = dpf.core.DataSources(result_path=cas_h5_file, server=server_type)
assert data_sources.result_key == "cas"


def test_set_resultpath_data_sources_cfx_res(server_type):
from ansys.dpf.core import examples
res_file = examples.download_cfx_mixing_elbow(server=server_type)
data_sources = dpf.core.DataSources(server=server_type)
data_sources.set_result_file_path(res_file)
assert data_sources.result_key == "cas"


def test_addupstream_data_sources(allkindofcomplexity, server_type):
data_sources = dpf.core.DataSources(server=server_type)
data_sources2 = dpf.core.DataSources(server=server_type)
Expand Down
Loading