diff --git a/doc/source/index.rst b/doc/source/index.rst index 67d1d944680..bef595d83d0 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -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` | @@ -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 diff --git a/examples/15-cfx/00-cfx_res_files.py b/examples/15-cfx/00-cfx_res_files.py new file mode 100644 index 00000000000..81fbef80139 --- /dev/null +++ b/examples/15-cfx/00-cfx_res_files.py @@ -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. diff --git a/examples/15-cfx/README.txt b/examples/15-cfx/README.txt new file mode 100644 index 00000000000..686644159a2 --- /dev/null +++ b/examples/15-cfx/README.txt @@ -0,0 +1,6 @@ +.. _examples_cfx: + +CFX examples +============ +These examples show how to post-process CFX result files. + diff --git a/src/ansys/dpf/core/data_sources.py b/src/ansys/dpf/core/data_sources.py index 4f03dbcc75d..b5d64e2114c 100644 --- a/src/ansys/dpf/core/data_sources.py +++ b/src/ansys/dpf/core/data_sources.py @@ -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)) diff --git a/src/ansys/dpf/core/examples/downloads.py b/src/ansys/dpf/core/examples/downloads.py index f6c91c2d409..da6f247756c 100644 --- a/src/ansys/dpf/core/examples/downloads.py +++ b/src/ansys/dpf/core/examples/downloads.py @@ -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. @@ -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: diff --git a/tests/test_datasources.py b/tests/test_datasources.py index 726735a7532..6f4246967c5 100644 --- a/tests/test_datasources.py +++ b/tests/test_datasources.py @@ -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" @@ -71,7 +70,6 @@ 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" @@ -79,6 +77,14 @@ def test_set_resultpath_data_sources_cff(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)