Skip to content

Commit 9d42dcd

Browse files
authored
DataSources.set_result_file_path recognizes .cas/dat.cff and .cas/dat.h5 files automatically (#1589)
* Add optional mesh arguments to fields Add a key guess for .cff and .h5 files Signed-off-by: paul.profizi <[email protected]> * Restrict to officially supported .cas.h5, .dat.h5, .cas.cff, and .dat.cff Signed-off-by: paul.profizi <[email protected]> --------- Signed-off-by: paul.profizi <[email protected]>
1 parent 97588b6 commit 9d42dcd

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/ansys/dpf/core/data_sources.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ def set_result_file_path(self, filepath, key=""):
120120
# Handle no key given and no file extension
121121
if key == "" and os.path.splitext(filepath)[1] == "":
122122
key = self.guess_result_key(str(filepath))
123+
# Look for another extension for .h5 and .cff files
124+
if key == "" and os.path.splitext(filepath)[1] in [".h5", ".cff"]:
125+
key = self.guess_second_key(str(filepath))
123126
if key == "":
124127
self._api.data_sources_set_result_file_path_utf8(self, str(filepath))
125128
else:
@@ -136,6 +139,19 @@ def guess_result_key(filepath: str) -> str:
136139
return result_key
137140
return ""
138141

142+
@staticmethod
143+
def guess_second_key(filepath: str) -> str:
144+
"""For files with an h5 or cff extension, look for another extension."""
145+
accepted = ["cas", "dat"]
146+
without_ext = os.path.splitext(filepath)[0]
147+
new_split = os.path.splitext(without_ext)
148+
new_key = ""
149+
if len(new_split) > 1:
150+
key = new_split[1][1:]
151+
if key in accepted:
152+
new_key = key
153+
return new_key
154+
139155
def set_domain_result_file_path(
140156
self, path: Union[str, os.PathLike], domain_id: int, key: Union[str, None] = None
141157
):

tests/test_datasources.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,28 @@ def test_setresultpath_data_sources_no_extension(d3plot_beam, binout_glstat, ser
5757
assert data_sources.result_key == "binout"
5858

5959

60+
def test_set_resultpath_data_sources_h5(server_type):
61+
from ansys.dpf.core import examples
62+
cas_h5_file = examples.download_fluent_axial_comp(server=server_type)["cas"][0]
63+
print(cas_h5_file)
64+
data_sources = dpf.core.DataSources(server=server_type)
65+
data_sources.set_result_file_path(cas_h5_file)
66+
assert data_sources.result_key == "cas"
67+
data_sources = dpf.core.DataSources(result_path=cas_h5_file, server=server_type)
68+
assert data_sources.result_key == "cas"
69+
70+
71+
def test_set_resultpath_data_sources_cff(server_type):
72+
from ansys.dpf.core import examples
73+
cas_h5_file = examples.download_cfx_heating_coil(server=server_type)["cas"]
74+
print(cas_h5_file)
75+
data_sources = dpf.core.DataSources(server=server_type)
76+
data_sources.set_result_file_path(cas_h5_file)
77+
assert data_sources.result_key == "cas"
78+
data_sources = dpf.core.DataSources(result_path=cas_h5_file, server=server_type)
79+
assert data_sources.result_key == "cas"
80+
81+
6082
def test_addupstream_data_sources(allkindofcomplexity, server_type):
6183
data_sources = dpf.core.DataSources(server=server_type)
6284
data_sources2 = dpf.core.DataSources(server=server_type)

0 commit comments

Comments
 (0)