diff --git a/src/ansys/dpf/core/examples/downloads.py b/src/ansys/dpf/core/examples/downloads.py index 11ade049fbe..8ebcc761666 100644 --- a/src/ansys/dpf/core/examples/downloads.py +++ b/src/ansys/dpf/core/examples/downloads.py @@ -7,7 +7,7 @@ import warnings from ansys.dpf.core.examples.examples import find_files -EXAMPLE_REPO = "https://github.com/ansys/example-data/raw/master/result_files/" +EXAMPLE_REPO = "https://github.com/ansys/example-data/raw/master/" def delete_downloads(): @@ -121,7 +121,9 @@ def download_transient_result( 'C:/Users/user/AppData/local/temp/transient.rst' """ - return _download_file("transient", "transient.rst", should_upload, server, return_local_path) + return _download_file( + "result_files/transient", "transient.rst", should_upload, server, return_local_path + ) def download_all_kinds_of_complexity( @@ -162,7 +164,7 @@ def download_all_kinds_of_complexity( """ return _download_file( - "testing", "allKindOfComplexity.rst", should_upload, server, return_local_path + "result_files/testing", "allKindOfComplexity.rst", should_upload, server, return_local_path ) @@ -204,7 +206,7 @@ def download_all_kinds_of_complexity_modal( """ return _download_file( - "testing", + "result_files/testing", "modal_allKindOfComplexity.rst", should_upload, server, @@ -247,7 +249,9 @@ def download_pontoon(should_upload: bool = True, server=None, return_local_path= 'C:/Users/user/AppData/local/temp/pontoon.rst' """ - return _download_file("docs", "pontoon.rst", should_upload, server, return_local_path) + return _download_file( + "result_files/docs", "pontoon.rst", should_upload, server, return_local_path + ) def download_multi_harmonic_result( @@ -287,7 +291,7 @@ def download_multi_harmonic_result( 'C:/Users/user/AppData/local/temp/file_harmonic_5rpms.rst' """ return _download_file( - "harmonic", "file_harmonic_5rpms.rst", should_upload, server, return_local_path + "result_files/harmonic", "file_harmonic_5rpms.rst", should_upload, server, return_local_path ) @@ -328,7 +332,9 @@ def download_multi_stage_cyclic_result( 'C:/Users/user/AppData/local/temp/multistage.rst' """ - return _download_file("multistage", "multistage.rst", should_upload, server, return_local_path) + return _download_file( + "result_files/multistage", "multistage.rst", should_upload, server, return_local_path + ) def download_sub_file(should_upload: bool = True, server=None, return_local_path=False) -> str: @@ -366,7 +372,7 @@ def download_sub_file(should_upload: bool = True, server=None, return_local_path 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\sub\\cp56.sub' """ - return _download_file("sub", "cp56.sub", should_upload, server, return_local_path) + return _download_file("result_files/sub", "cp56.sub", should_upload, server, return_local_path) def download_msup_files_to_dict( @@ -409,9 +415,15 @@ def download_msup_files_to_dict( """ return { - "rfrq": _download_file("msup", "file.rfrq", should_upload, server, return_local_path), - "mode": _download_file("msup", "file.mode", should_upload, server, return_local_path), - "rst": _download_file("msup", "file.rst", should_upload, server, return_local_path), + "rfrq": _download_file( + "result_files/msup", "file.rfrq", should_upload, server, return_local_path + ), + "mode": _download_file( + "result_files/msup", "file.mode", should_upload, server, return_local_path + ), + "rst": _download_file( + "result_files/msup", "file.rst", should_upload, server, return_local_path + ), } @@ -454,14 +466,20 @@ def download_distributed_files( """ return { - 0: _download_file("distributed", "file0.rst", should_upload, server, return_local_path), - 1: _download_file("distributed", "file1.rst", should_upload, server, return_local_path), + 0: _download_file( + "result_files/distributed", "file0.rst", should_upload, server, return_local_path + ), + 1: _download_file( + "result_files/distributed", "file1.rst", should_upload, server, return_local_path + ), } -def download_fluent_files(should_upload: bool = True, server=None, return_local_path=False) -> dict: - """Download the cas and dat file of a fluent analysis and return the - download paths into a dictionary extension->path. +def download_fluent_multi_species( + should_upload: bool = True, server=None, return_local_path=False +) -> dict: + """Download the cas and dat file of a fluent analysis with multiple species + and return the download paths into a dictionary extension->path. If the server is remote (or doesn't share memory), the file is uploaded or made available on the server side. @@ -489,15 +507,27 @@ def download_fluent_files(should_upload: bool = True, server=None, return_local_ Download an example result file and return the path of the file >>> from ansys.dpf.core import examples - >>> paths = examples.download_fluent_files() + >>> paths = examples.download_fluent_multi_species() >>> paths - {'cas': 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent\\FFF.cas.h5', - 'dat': 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent\\FFF.dat.h5'} # noqa: E501 + {'cas': 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-multi_species\\FFF.cas.h5', + 'dat': 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-multi_species\\FFF.dat.h5'} # noqa: E501 """ return { - "cas": _download_file("fluent", "FFF.cas.h5", should_upload, server, return_local_path), - "dat": _download_file("fluent", "FFF.dat.h5", should_upload, server, return_local_path), + "cas": _download_file( + "result_files/fluent-multi_species", + "FFF.cas.h5", + should_upload, + server, + return_local_path, + ), + "dat": _download_file( + "result_files/fluent-multi_species", + "FFF.dat.h5", + should_upload, + server, + return_local_path, + ), } @@ -544,10 +574,10 @@ def download_extrapolation_3d_result( """ path_dict = { "file_ref": _download_file( - "extrapolate", "file_ref.rst", should_upload, server, return_local_path + "result_files/extrapolate", "file_ref.rst", should_upload, server, return_local_path ), "file_integrated": _download_file( - "extrapolate", "file.rst", should_upload, server, return_local_path + "result_files/extrapolate", "file.rst", should_upload, server, return_local_path ), } @@ -597,14 +627,14 @@ def download_extrapolation_2d_result( """ path_dict = { "file_ref": _download_file( - "extrapolate", + "result_files/extrapolate", "extrapolate_2d_ref.rst", should_upload, server, return_local_path, ), "file_integrated": _download_file( - "extrapolate", + "result_files/extrapolate", "extrapolate_2d.rst", should_upload, server, @@ -650,7 +680,9 @@ def download_hemisphere(should_upload: bool = True, server=None, return_local_pa 'C:/Users/user/AppData/local/temp/hemisphere.rst' """ - return _download_file("hemisphere", "hemisphere.rst", should_upload, server, return_local_path) + return _download_file( + "result_files/hemisphere", "hemisphere.rst", should_upload, server, return_local_path + ) def download_example_asme_result( @@ -689,7 +721,7 @@ def download_example_asme_result( 'C:/Users/user/AppData/local/temp/asme_example.rst' """ return _download_file( - "postprocessing", "asme_example.rst", should_upload, server, return_local_path + "result_files/postprocessing", "asme_example.rst", should_upload, server, return_local_path ) @@ -728,7 +760,9 @@ def download_crankshaft(should_upload: bool = True, server=None, return_local_pa 'C:/Users/user/AppData/local/temp/crankshaft.rst' """ - return _download_file("crankshaft", "crankshaft.rst", should_upload, server, return_local_path) + return _download_file( + "result_files/crankshaft", "crankshaft.rst", should_upload, server, return_local_path + ) def download_piston_rod(should_upload: bool = True, server=None, return_local_path=False) -> str: @@ -766,7 +800,9 @@ def download_piston_rod(should_upload: bool = True, server=None, return_local_pa 'C:/Users/user/AppData/local/temp/piston_rod.rst' """ - return _download_file("piston_rod", "piston_rod.rst", should_upload, server, return_local_path) + return _download_file( + "result_files/piston_rod", "piston_rod.rst", should_upload, server, return_local_path + ) def download_d3plot_beam(should_upload: bool = True, server=None, return_local_path=False) -> list: @@ -808,10 +844,18 @@ def download_d3plot_beam(should_upload: bool = True, server=None, return_local_p """ return [ - _download_file("d3plot_beam", "d3plot", should_upload, server, return_local_path), - _download_file("d3plot_beam", "d3plot01", should_upload, server, return_local_path), - _download_file("d3plot_beam", "d3plot02", should_upload, server, return_local_path), - _download_file("d3plot_beam", "file.actunits", should_upload, server, return_local_path), + _download_file( + "result_files/d3plot_beam", "d3plot", should_upload, server, return_local_path + ), + _download_file( + "result_files/d3plot_beam", "d3plot01", should_upload, server, return_local_path + ), + _download_file( + "result_files/d3plot_beam", "d3plot02", should_upload, server, return_local_path + ), + _download_file( + "result_files/d3plot_beam", "file.actunits", should_upload, server, return_local_path + ), ] @@ -850,7 +894,9 @@ def download_binout_matsum(should_upload: bool = True, server=None, return_local 'C:/Users/user/AppData/local/temp/binout_matsum' """ - return _download_file("binout", "binout_matsum", should_upload, server, return_local_path) + return _download_file( + "result_files/binout", "binout_matsum", should_upload, server, return_local_path + ) def download_binout_glstat(should_upload: bool = True, server=None, return_local_path=False) -> str: @@ -888,7 +934,9 @@ def download_binout_glstat(should_upload: bool = True, server=None, return_local 'C:/Users/user/AppData/local/temp/binout_glstat' """ - return _download_file("binout", "binout_glstat", should_upload, server, return_local_path) + return _download_file( + "result_files/binout", "binout_glstat", should_upload, server, return_local_path + ) def download_cycles_to_failure( @@ -929,7 +977,7 @@ def download_cycles_to_failure( """ return _download_file( - "cyclic", "cyclic_to_failure.rst", should_upload, server, return_local_path + "result_files/cyclic", "cyclic_to_failure.rst", should_upload, server, return_local_path ) @@ -966,7 +1014,9 @@ def download_modal_frame(should_upload: bool = True, server=None, return_local_p >>> path = examples.download_modal_frame() """ - return _download_file("modal", "frame.rst", should_upload, server, return_local_path) + return _download_file( + "result_files/modal", "frame.rst", should_upload, server, return_local_path + ) def download_harmonic_clamped_pipe( @@ -1004,7 +1054,9 @@ def download_harmonic_clamped_pipe( >>> path = examples.download_modal_frame() """ - return _download_file("harmonic", "clamped_pipe.rst", should_upload, server, return_local_path) + return _download_file( + "result_files/harmonic", "clamped_pipe.rst", should_upload, server, return_local_path + ) def download_modal_cyclic(should_upload: bool = True, server=None, return_local_path=False) -> str: @@ -1040,4 +1092,302 @@ def download_modal_cyclic(should_upload: bool = True, server=None, return_local_ >>> path = examples.download_modal_cyclic() """ - return _download_file("cyclic", "modal_cyclic.rst", should_upload, server, return_local_path) + return _download_file( + "result_files/cyclic", "modal_cyclic.rst", should_upload, server, return_local_path + ) + + +def download_fluent_axial_comp( + should_upload: bool = True, server=None, return_local_path=False +) -> dict: + """Download the flprj, cas and dat files of a fluent analysis of an axial compressor sector + and return the download paths into a dictionary extension->path. + If the server is remote (or doesn't share memory), the file is uploaded or made available + on the server side. + + Examples files are downloaded to a persistent cache to avoid + re-downloading the same file twice. + + Parameters + ---------- + should_upload : bool, optional (default True) + Whether the file should be uploaded server side when the server is remote. + server : server.DPFServer, optional + Server with channel connected to the remote or local instance. When + ``None``, attempts to use the global server. + return_local_path: bool, optional + If ``True``, the local path is returned as is, without uploading, nor searching + for mounted volumes. + + Returns + ------- + dict[str:str] + Path to the example files. + + Examples + -------- + Download an example result file and return the path of the file + + >>> from ansys.dpf.core import examples + >>> paths = examples.download_fluent_axial_comp() + >>> paths + {'flprj': 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-axial_comp\\axial_comp_reduced.flprj', + 'cas': [ + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-axial_comp\\axial_comp-1-01438.cas.h5', + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-axial_comp\\axial_comp-1-01439.cas.h5', + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-axial_comp\\axial_comp-1-01440.cas.h5', + ], + 'dat': [ + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-axial_comp\\axial_comp-1-01438.dat.h5', + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-axial_comp\\axial_comp-1-01439.dat.h5', + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-axial_comp\\axial_comp-1-01440.dat.h5', + ]} # noqa: E501 + + """ + return { + "flprj": _download_file( + "result_files/fluent-axial_comp", + "axial_comp_reduced.flprj", + should_upload, + server, + return_local_path, + ), + "cas": [ + _download_file( + "result_files/fluent-axial_comp", + "axial_comp-1-01438.cas.h5", + should_upload, + server, + return_local_path, + ), + _download_file( + "result_files/fluent-axial_comp", + "axial_comp-1-01439.cas.h5", + should_upload, + server, + return_local_path, + ), + _download_file( + "result_files/fluent-axial_comp", + "axial_comp-1-01440.cas.h5", + should_upload, + server, + return_local_path, + ), + ], + "dat": [ + _download_file( + "result_files/fluent-axial_comp", + "axial_comp-1-01438.dat.h5", + should_upload, + server, + return_local_path, + ), + _download_file( + "result_files/fluent-axial_comp", + "axial_comp-1-01439.dat.h5", + should_upload, + server, + return_local_path, + ), + _download_file( + "result_files/fluent-axial_comp", + "axial_comp-1-01440.dat.h5", + should_upload, + server, + return_local_path, + ), + ], + } + + +def download_fluent_mixing_elbow_steady_state( + should_upload: bool = True, server=None, return_local_path=False +) -> dict: + """Download the flprj, cas and dat files of a steady-state fluent analysis of a mixing elbow + and return the download paths into a dictionary extension->path. + If the server is remote (or doesn't share memory), the file is uploaded or made available + on the server side. + + Examples files are downloaded to a persistent cache to avoid + re-downloading the same file twice. + + Parameters + ---------- + should_upload : bool, optional (default True) + Whether the file should be uploaded server side when the server is remote. + server : server.DPFServer, optional + Server with channel connected to the remote or local instance. When + ``None``, attempts to use the global server. + return_local_path: bool, optional + If ``True``, the local path is returned as is, without uploading, nor searching + for mounted volumes. + + Returns + ------- + dict[str:str] + Path to the example files. + + Examples + -------- + Download an example result file and return the path of the file + + >>> from ansys.dpf.core import examples + >>> paths = examples.download_fluent_mixing_elbow_steady_state() + >>> paths + {'flprj': 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-mixing_elbow_steady-state\\elbow.flprj', + 'cas': [ + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-mixing_elbow_steady-state\\elbow-2.cas.h5', + ], + 'dat': [ + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-mixing_elbow_steady-state\\elbow-2-00005.dat.h5', + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-mixing_elbow_steady-state\\elbow-2-00010.dat.h5', + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-mixing_elbow_steady-state\\elbow-2-00015.dat.h5', + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-mixing_elbow_steady-state\\elbow-2-00020.dat.h5', + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-mixing_elbow_steady-state\\elbow-2-00025.dat.h5', + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-mixing_elbow_steady-state\\elbow-2-00030.dat.h5', + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-mixing_elbow_steady-state\\elbow-2-00035.dat.h5', + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-mixing_elbow_steady-state\\elbow-2-00040.dat.h5', + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-mixing_elbow_steady-state\\elbow-2-00045.dat.h5', + 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\fluent-mixing_elbow_steady-state\\elbow-2-00050.dat.h5', + ]} # noqa: E501 + + """ + return { + "flprj": _download_file( + "result_files/fluent-mixing_elbow_steady-state", + "elbow.flprj", + should_upload, + server, + return_local_path, + ), + "cas": [ + _download_file( + "result_files/fluent-mixing_elbow_steady-state", + "elbow-2.cas.h5", + should_upload, + server, + return_local_path, + ), + ], + "dat": [ + _download_file( + "result_files/fluent-mixing_elbow_steady-state", + "elbow-2-00005.dat.h5", + should_upload, + server, + return_local_path, + ), + _download_file( + "result_files/fluent-mixing_elbow_steady-state", + "elbow-2-00010.dat.h5", + should_upload, + server, + return_local_path, + ), + _download_file( + "result_files/fluent-mixing_elbow_steady-state", + "elbow-2-00015.dat.h5", + should_upload, + server, + return_local_path, + ), + _download_file( + "result_files/fluent-mixing_elbow_steady-state", + "elbow-2-00020.dat.h5", + should_upload, + server, + return_local_path, + ), + _download_file( + "result_files/fluent-mixing_elbow_steady-state", + "elbow-2-00025.dat.h5", + should_upload, + server, + return_local_path, + ), + _download_file( + "result_files/fluent-mixing_elbow_steady-state", + "elbow-2-00030.dat.h5", + should_upload, + server, + return_local_path, + ), + _download_file( + "result_files/fluent-mixing_elbow_steady-state", + "elbow-2-00035.dat.h5", + should_upload, + server, + return_local_path, + ), + _download_file( + "result_files/fluent-mixing_elbow_steady-state", + "elbow-2-00040.dat.h5", + should_upload, + server, + return_local_path, + ), + _download_file( + "result_files/fluent-mixing_elbow_steady-state", + "elbow-2-00045.dat.h5", + should_upload, + server, + return_local_path, + ), + _download_file( + "result_files/fluent-mixing_elbow_steady-state", + "elbow-2-00050.dat.h5", + should_upload, + server, + return_local_path, + ), + ], + } + + +def download_cfx_heating_coil( + should_upload: bool = True, server=None, return_local_path=False +) -> dict: + """Download the flprj, cas and dat files of a CFX analysis of a heating coil + and return the download paths into a dictionary extension->path. + If the server is remote (or doesn't share memory), the file is uploaded or made available + on the server side. + + Examples files are downloaded to a persistent cache to avoid + re-downloading the same file twice. + + Parameters + ---------- + should_upload : bool, optional (default True) + Whether the file should be uploaded server side when the server is remote. + server : server.DPFServer, optional + Server with channel connected to the remote or local instance. When + ``None``, attempts to use the global server. + return_local_path: bool, optional + If ``True``, the local path is returned as is, without uploading, nor searching + for mounted volumes. + + Returns + ------- + dict[str:str] + Path to the example files. + + Examples + -------- + Download an example result file and return the path of the file + + >>> from ansys.dpf.core import examples + >>> paths = examples.download_cfx_heating_coil() + >>> paths + {'cas': 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\cfx-heating_coil\\HeatingCoil.res', + 'dat': 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\cfx-heating_coil\\HeatingCoil.res'} # noqa: E501 + + """ + file = _download_file( + "result_files/cfx-heating_coil", + "HeatingCoil.res", + should_upload, + server, + return_local_path, + ) + return {"cas": file, "dat": file} diff --git a/tests/conftest.py b/tests/conftest.py index 830894b0573..b20f31a90f2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -158,7 +158,7 @@ def model_with_ns(): def cff_data_sources(): """Create a data sources with a cas and a dat file of fluent""" ds = core.DataSources() - files = examples.download_fluent_files() + files = examples.download_fluent_multi_species_files() ds.set_result_file_path(files["cas"], "cas") ds.add_file_path(files["dat"], "dat") return ds diff --git a/tests/test_examples.py b/tests/test_examples.py index 2eed8000b2c..f627b6d948c 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -54,6 +54,36 @@ def test_download_modal_cyclic(): assert isinstance(Model(path), Model) +def test_download_fluent_multi_species(): + path = examples.download_fluent_multi_species() + assert isinstance(Model(path), Model) + + +def test_download_fluent_axial_comp(): + path = examples.download_fluent_axial_comp() + assert isinstance(Model(path), Model) + + +def test_download_fluent_mixing_elbow_steady_state(): + path = examples.download_fluent_mixing_elbow_steady_state() + assert isinstance(Model(path), Model) + + +# def test_download_fluent_mixing_elbow_transient(): +# path = examples.download_fluent_mixing_elbow_transient() +# assert isinstance(Model(path), Model) + + +def test_download_cfx_heating_coil(): + path = examples.download_cfx_heating_coil() + assert isinstance(Model(path), Model) + + +# def test_download_cfx_mixing_elbow(): +# path = examples.download_cfx_mixing_elbow() +# assert isinstance(Model(path), Model) + + list_examples = [ "simple_bar", "static_rst",