From 1a300154efdce50bfe1e1a23d6ad892bc87c7be9 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 19 Jun 2024 15:05:13 +0200 Subject: [PATCH 1/8] Mark res as supported in doc landing page Signed-off-by: paul.profizi --- doc/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/index.rst b/doc/source/index.rst index 67d1d94468..eed61408cc 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -36,7 +36,7 @@ apps by DPF and their related formats: +--------------------+------------------------+----------------------------------+----------------------------------+ | || *CFF files* || | :ref:`ref_fluids_model` | | || .cas/dat.cff || +----------------------------------+ -| | || **7.0** and later | :ref:`ref_fluids_mesh` | +| || .res || **7.0** and later | :ref:`ref_fluids_mesh` | | CFX +------------------------+| (*Ansys 2024 R1 pre0*) +----------------------------------+ | || *Project files* | | :ref:`ref_fluids_results` | | || .flprj | | | From 57d23dc2126a35e4add518279aad3b6fb26082f6 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 19 Jun 2024 15:38:12 +0200 Subject: [PATCH 2/8] Add a CFX examples section Signed-off-by: paul.profizi --- doc/source/index.rst | 11 ++++++----- examples/15-cfx/README.txt | 6 ++++++ 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 examples/15-cfx/README.txt diff --git a/doc/source/index.rst b/doc/source/index.rst index eed61408cc..bef595d83d 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 || +----------------------------------+ -| || .res || **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/README.txt b/examples/15-cfx/README.txt new file mode 100644 index 0000000000..686644159a --- /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. + From b73e9a871b3b835233c66cc4d2bab0fb048eb733 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 19 Jun 2024 16:11:00 +0200 Subject: [PATCH 3/8] Fix download_cfx_mixing_elbow in downloads.py Signed-off-by: paul.profizi --- src/ansys/dpf/core/examples/downloads.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/ansys/dpf/core/examples/downloads.py b/src/ansys/dpf/core/examples/downloads.py index f6c91c2d40..da6f247756 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: From e0df1301ba19b34a3ffb8e0bbc032672e5e3bd55 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 19 Jun 2024 16:15:57 +0200 Subject: [PATCH 4/8] Add an example for CFX .res files Signed-off-by: paul.profizi --- examples/15-cfx/00-cfx_res_files.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 examples/15-cfx/00-cfx_res_files.py 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 0000000000..83cfdf15f0 --- /dev/null +++ b/examples/15-cfx/00-cfx_res_files.py @@ -0,0 +1,29 @@ +""" +.. _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() +ds = dpf.DataSources() +ds.set_result_file_path(path, key="cas") +ds.add_file_path(path, key="dat") +model = dpf.Model(data_sources=ds) +print(model) From 3e829f865a4c734a3ba15ab273c5492ba302850c Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 19 Jun 2024 16:22:08 +0200 Subject: [PATCH 5/8] Proposal: automatically set .res CFX files as cas and dat Signed-off-by: paul.profizi --- examples/15-cfx/00-cfx_res_files.py | 4 +--- src/ansys/dpf/core/data_sources.py | 9 +++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/15-cfx/00-cfx_res_files.py b/examples/15-cfx/00-cfx_res_files.py index 83cfdf15f0..90b547dfdd 100644 --- a/examples/15-cfx/00-cfx_res_files.py +++ b/examples/15-cfx/00-cfx_res_files.py @@ -22,8 +22,6 @@ from ansys.dpf.core import examples path = examples.download_cfx_mixing_elbow() -ds = dpf.DataSources() -ds.set_result_file_path(path, key="cas") -ds.add_file_path(path, key="dat") +ds = dpf.DataSources(path) model = dpf.Model(data_sources=ds) print(model) diff --git a/src/ansys/dpf/core/data_sources.py b/src/ansys/dpf/core/data_sources.py index 4f03dbcc75..b5d64e2114 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)) From 1f5fa2cc70d7f8488a608c3da40332d2649d4ee5 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Wed, 19 Jun 2024 16:23:06 +0200 Subject: [PATCH 6/8] Skip the DataSources Signed-off-by: paul.profizi --- examples/15-cfx/00-cfx_res_files.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/15-cfx/00-cfx_res_files.py b/examples/15-cfx/00-cfx_res_files.py index 90b547dfdd..4b7f0f55fe 100644 --- a/examples/15-cfx/00-cfx_res_files.py +++ b/examples/15-cfx/00-cfx_res_files.py @@ -22,6 +22,5 @@ from ansys.dpf.core import examples path = examples.download_cfx_mixing_elbow() -ds = dpf.DataSources(path) -model = dpf.Model(data_sources=ds) +model = dpf.Model(path) print(model) From ddc40ca5f166ef6ceed6f85cd14529b406f52a18 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Thu, 20 Jun 2024 10:57:27 +0200 Subject: [PATCH 7/8] Update 00-cfx_res_files.py Signed-off-by: paul.profizi --- examples/15-cfx/00-cfx_res_files.py | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/examples/15-cfx/00-cfx_res_files.py b/examples/15-cfx/00-cfx_res_files.py index 4b7f0f55fe..81fbef8013 100644 --- a/examples/15-cfx/00-cfx_res_files.py +++ b/examples/15-cfx/00-cfx_res_files.py @@ -24,3 +24,40 @@ 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. From fdbaa7f9a22ad2427e0b6e0702a313b441eb3ce5 Mon Sep 17 00:00:00 2001 From: "paul.profizi" Date: Thu, 20 Jun 2024 18:03:25 +0200 Subject: [PATCH 8/8] Add test Signed-off-by: paul.profizi --- tests/test_datasources.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_datasources.py b/tests/test_datasources.py index 726735a753..6f4246967c 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)