diff --git a/README.md b/README.md index a53d50bf194..0a57ee115cf 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ To open a result file and explore what's inside, do: ```py >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples ->>> model = dpf.Model(examples.simple_bar) +>>> model = dpf.Model(examples.find_simple_bar()) >>> print(model) DPF Model diff --git a/ansys/dpf/core/core.py b/ansys/dpf/core/core.py index dafdb01c132..8a3aad2adbb 100644 --- a/ansys/dpf/core/core.py +++ b/ansys/dpf/core/core.py @@ -96,7 +96,7 @@ def upload_file_in_tmp_folder(file_path, new_file_name=None, server=None): >>> from ansys.dpf.core import examples >>> server = dpf.start_local_server(config=dpf.AvailableServerConfigs.GrpcServer, ... as_global=False) - >>> file_path = dpf.upload_file_in_tmp_folder(examples.static_rst, server=server) + >>> file_path = dpf.upload_file_in_tmp_folder(examples.find_static_rst(), server=server) Notes ----- @@ -161,8 +161,8 @@ def download_file(server_file_path, to_client_file_path, server=None): >>> from ansys.dpf.core import examples >>> server = dpf.start_local_server(config=dpf.AvailableServerConfigs.GrpcServer, ... as_global=False) - >>> file_path = dpf.upload_file_in_tmp_folder(examples.static_rst, server=server) - >>> dpf.download_file(file_path, examples.static_rst, server=server) + >>> file_path = dpf.upload_file_in_tmp_folder(examples.find_static_rst(), server=server) + >>> dpf.download_file(file_path, examples.find_static_rst(), server=server) ... diff --git a/ansys/dpf/core/dpf_operator.py b/ansys/dpf/core/dpf_operator.py index 682f755ea4d..71d044fe67d 100644 --- a/ansys/dpf/core/dpf_operator.py +++ b/ansys/dpf/core/dpf_operator.py @@ -80,7 +80,7 @@ class Operator: >>> from ansys.dpf.core import Model >>> from ansys.dpf.core import examples - >>> model = Model(examples.static_rst) + >>> model = Model(examples.find_static_rst()) >>> disp_oper = model.results.displacement() """ @@ -142,7 +142,7 @@ def _add_sub_res_operators(self, sub_results): -------- >>> from ansys.dpf.core import Model >>> from ansys.dpf.core import examples - >>> model = Model(examples.static_rst) + >>> model = Model(examples.find_static_rst()) >>> disp_oper = model.results.displacement() >>> disp_oper = model.results.displacement() >>> disp_x = model.results.displacement().X() @@ -200,7 +200,7 @@ def connect(self, pin, inpt, pin_out=0): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> data_src = dpf.DataSources(examples.multishells_rst) + >>> data_src = dpf.DataSources(examples.find_multishells_rst()) >>> disp_op = dpf.operators.result.displacement() >>> disp_op.inputs.data_sources(data_src) >>> max_fc_op = dpf.operators.min_max.min_max_fc() @@ -430,7 +430,7 @@ def inputs(self): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> data_src = dpf.DataSources(examples.multishells_rst) + >>> data_src = dpf.DataSources(examples.find_multishells_rst()) >>> disp_op = dpf.operators.result.displacement() >>> disp_op.inputs.data_sources(data_src) @@ -453,7 +453,7 @@ def outputs(self): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> data_src = dpf.DataSources(examples.multishells_rst) + >>> data_src = dpf.DataSources(examples.find_multishells_rst()) >>> disp_op = dpf.operators.result.displacement() >>> disp_op.inputs.data_sources(data_src) >>> disp_fc = disp_op.outputs.fields_container() @@ -532,7 +532,7 @@ def eval(self, pin=None): >>> from ansys.dpf import core as dpf >>> import ansys.dpf.core.operators.math as math >>> from ansys.dpf.core import examples - >>> data_src = dpf.DataSources(examples.multishells_rst) + >>> data_src = dpf.DataSources(examples.find_multishells_rst()) >>> disp_op = dpf.operators.result.displacement() >>> disp_op.inputs.data_sources(data_src) >>> normfc = math.norm_fc(disp_op).eval() diff --git a/ansys/dpf/core/elements.py b/ansys/dpf/core/elements.py index f8191e182e9..539061554e1 100644 --- a/ansys/dpf/core/elements.py +++ b/ansys/dpf/core/elements.py @@ -38,7 +38,7 @@ class Element: >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> elements = model.metadata.meshed_region.elements >>> element = elements[0] @@ -69,7 +69,7 @@ def node_ids(self): -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> elements = model.metadata.meshed_region.elements >>> element = elements[0] >>> element.node_ids @@ -117,7 +117,7 @@ def nodes(self): -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> elements = model.metadata.meshed_region.elements >>> element = elements[0] >>> first_node = element.nodes[0] @@ -161,7 +161,7 @@ def type(self) -> int: -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> elements = model.metadata.meshed_region.elements >>> element = elements[0] >>> element.type @@ -191,7 +191,7 @@ def shape(self) -> str: -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> elements = model.metadata.meshed_region.elements >>> element = elements[0] >>> element.shape @@ -240,7 +240,7 @@ class Elements: -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> elements = model.metadata.meshed_region.elements >>> elements.n_elements 8 @@ -480,7 +480,7 @@ def scoping(self) -> scoping.Scoping: -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> elements = model.metadata.meshed_region.elements >>> my_scoping = elements.scoping @@ -501,7 +501,7 @@ def element_types_field(self): -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> elements = model.metadata.meshed_region.elements >>> field = elements.element_types_field >>> print(field.data) @@ -539,7 +539,7 @@ def materials_field(self): >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> elements = model.metadata.meshed_region.elements >>> print(elements.materials_field.data) [1 1 1 1 1 1 1 1] @@ -574,7 +574,7 @@ def connectivities_field(self): -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> elements = model.metadata.meshed_region.elements >>> field = elements.connectivities_field >>> field.get_entity_data(1) @@ -621,7 +621,7 @@ def mapping_id_to_index(self) -> dict: -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.simple_bar) + >>> model = dpf.Model(examples.find_simple_bar()) >>> meshed_region = model.metadata.meshed_region >>> map = meshed_region.nodes.mapping_id_to_index @@ -654,7 +654,7 @@ def map_scoping(self, external_scope): >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> elements = model.metadata.meshed_region.elements >>> vol = model.results.elemental_volume() >>> field = vol.outputs.fields_container()[0] @@ -1286,7 +1286,7 @@ def descriptor(element_type): -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> elements = model.metadata.meshed_region.elements >>> element = elements[0] >>> type_of_element = element.type diff --git a/ansys/dpf/core/examples/downloads.py b/ansys/dpf/core/examples/downloads.py index 02355cb9de1..b61f13b5580 100644 --- a/ansys/dpf/core/examples/downloads.py +++ b/ansys/dpf/core/examples/downloads.py @@ -5,6 +5,8 @@ import os import urllib.request import warnings +from ansys.dpf.core.examples.examples import find_files + EXAMPLE_REPO = "https://github.com/pyansys/example-data/raw/master/result_files/" @@ -67,22 +69,33 @@ def _retrieve_file(url, filename, directory): path_utilities.downloaded_example_path())) -def _download_file(directory, filename): +def _download_file(directory, filename, should_upload: bool, server): url = _get_file_url(directory, filename) local_path = _retrieve_file(url, filename, directory) - return local_path + return find_files(local_path, should_upload, server) ############################################################################### # front-facing functions -def download_transient_result() -> str: - """Download an example transient result file and return the download path. +def download_transient_result(should_upload: bool = True, server=None) -> str: + """Download an example transient result file and return the download path + available server side. + If the server is remote (or doesn't share the memory), the file is uploaded or made available + 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. + Returns ------- str @@ -93,20 +106,31 @@ def download_transient_result() -> str: Download an example result file and return the path of the file >>> from ansys.dpf.core import examples - >>> path = examples.transient_result + >>> path = examples.download_transient_result() >>> path 'C:/Users/user/AppData/local/temp/transient.rst' """ - return _download_file("transient", "transient.rst") + return _download_file("transient", "transient.rst", should_upload, server) -def download_all_kinds_of_complexity() -> str: - """Download an example static result and return the download path. +def download_all_kinds_of_complexity(should_upload: bool = True, server=None) -> str: + """Download an example static result and return the download path + available server side. + If the server is remote (or doesn't share the memory), the file is uploaded or made available + 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. + Returns ------- str @@ -117,21 +141,31 @@ def download_all_kinds_of_complexity() -> str: Download an example result file and return the path of the file >>> from ansys.dpf.core import examples - >>> path = examples.download_all_kinds_of_complexity + >>> path = examples.download_all_kinds_of_complexity() >>> path 'C:/Users/user/AppData/local/temp/allKindOfComplexity.rst' """ - return _download_file("testing", "allKindOfComplexity.rst") + return _download_file("testing", "allKindOfComplexity.rst", should_upload, server) -def download_all_kinds_of_complexity_modal() -> str: +def download_all_kinds_of_complexity_modal(should_upload: bool = True, server=None) -> str: """Download an example result file from a static modal analysis and - return the download path. + return the download path available server side. + If the server is remote (or doesn't share the memory), the file is uploaded or made available + 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. + Returns ------- str @@ -147,16 +181,26 @@ def download_all_kinds_of_complexity_modal() -> str: 'C:/Users/user/AppData/local/temp/modal_allKindOfComplexity.rst' """ - return _download_file("testing", "modal_allKindOfComplexity.rst") + return _download_file("testing", "modal_allKindOfComplexity.rst", should_upload, server) -def download_pontoon() -> str: +def download_pontoon(should_upload: bool = True, server=None) -> str: """Download an example result file from a static modal analsys and - return the download path. + return the download path available server side. + If the server is remote (or doesn't share the memory), the file is uploaded or made available + 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. + Returns ------- str @@ -172,16 +216,26 @@ def download_pontoon() -> str: 'C:/Users/user/AppData/local/temp/pontoon.rst' """ - return _download_file("docs", "pontoon.rst") + return _download_file("docs", "pontoon.rst", should_upload, server) -def download_multi_harmonic_result() -> str: +def download_multi_harmonic_result(should_upload: bool = True, server=None) -> str: """Download an example multi-harmonic result file and return the - download path. + download path available server side. + If the server is remote (or doesn't share the memory), the file is uploaded or made available + 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. + Returns ------- str @@ -196,16 +250,26 @@ def download_multi_harmonic_result() -> str: >>> path 'C:/Users/user/AppData/local/temp/file_harmonic_5rpms.rst' """ - return _download_file("harmonic", "file_harmonic_5rpms.rst") + return _download_file("harmonic", "file_harmonic_5rpms.rst", should_upload, server) -def download_multi_stage_cyclic_result() -> str: +def download_multi_stage_cyclic_result(should_upload: bool = True, server=None) -> str: """Download an example multi stage result file and return the - download path. + download path available server side. + If the server is remote (or doesn't share the memory), the file is uploaded or made available + 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. + Returns ------- str @@ -221,16 +285,26 @@ def download_multi_stage_cyclic_result() -> str: 'C:/Users/user/AppData/local/temp/multistage.rst' """ - return _download_file("multistage", "multistage.rst") + return _download_file("multistage", "multistage.rst", should_upload, server) -def download_sub_file() -> str: +def download_sub_file(should_upload: bool = True, server=None) -> str: """Download an example .sub result file containing matrices and return the - download path. + download path available server side. + If the server is remote (or doesn't share the memory), the file is uploaded or made available + 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. + Returns ------- str @@ -246,16 +320,26 @@ def download_sub_file() -> str: 'C:\\Users\\user\\AppData\\Local\\ansys-dpf-core\\ansys-dpf-core\\examples\\sub\\cp56.sub' """ - return _download_file("sub", "cp56.sub") + return _download_file("sub", "cp56.sub", should_upload, server) -def download_msup_files_to_dict() -> dict: +def download_msup_files_to_dict(should_upload: bool = True, server=None) -> dict: """Download all the files necessary for a msup expansion and return the - download paths into a dictionary extension->path. + download paths available server side into a dictionary extension->path. + If the server is remote (or doesn't share the memory), the files are uploaded or made available + 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. + Returns ------- dict[str:str] @@ -274,19 +358,29 @@ def download_msup_files_to_dict() -> dict: """ return { - "rfrq": _download_file("msup", "file.rfrq"), - "mode": _download_file("msup", "file.mode"), - "rst": _download_file("msup", "file.rst"), + "rfrq": _download_file("msup", "file.rfrq", should_upload, server), + "mode": _download_file("msup", "file.mode", should_upload, server), + "rst": _download_file("msup", "file.rst", should_upload, server), } -def download_distributed_files() -> dict: +def download_distributed_files(should_upload: bool = True, server=None) -> dict: """Download distributed rst files and return the download paths into a dictionary domain id->path. + If the server is remote (or doesn't share the memory), the files are uploaded or made available + 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. + Returns ------- dict[int:str] @@ -304,18 +398,28 @@ def download_distributed_files() -> dict: """ return { - 0: _download_file("distributed", "file0.rst"), - 1: _download_file("distributed", "file1.rst"), + 0: _download_file("distributed", "file0.rst", should_upload, server), + 1: _download_file("distributed", "file1.rst", should_upload, server), } -def download_fluent_files() -> dict: +def download_fluent_files(should_upload: bool = True, server=None) -> dict: """Download the cas and dat file of a fluent analysis and return the download paths into a dictionary extension->path. + If the server is remote (or doesn't share the memory), the files are uploaded or made available + 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. + Returns ------- dict[str:str] @@ -333,18 +437,28 @@ def download_fluent_files() -> dict: """ return { - "cas": _download_file("fluent", "FFF.cas.h5"), - "dat": _download_file("fluent", "FFF.dat.h5"), + "cas": _download_file("fluent", "FFF.cas.h5", should_upload, server), + "dat": _download_file("fluent", "FFF.dat.h5", should_upload, server), } -def download_extrapolation_3d_result() -> dict: +def download_extrapolation_3d_result(should_upload: bool = True, server=None) -> dict: """Download example static results of reference and integrated points for extrapolation of 3d-element and return return the dictionary of 2 download paths. + If the server is remote (or doesn't share the memory), the files are uploaded or made available + 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. + Returns ------- dict @@ -356,29 +470,39 @@ def download_extrapolation_3d_result() -> dict: Download 2 example result files and return the dictionary containing 2 files >>> from ansys.dpf.core import examples - >>> dict = examples.download_extrapolation_ref_result - >>> dict + >>> path_dict = examples.download_extrapolation_ref_result() + >>> path_dict { 'file_ref': 'C:/Users/user/AppData/local/temp/file_ref.rst', 'file_integrated': 'C:/Users/user/AppData/local/temp/file.rst' } """ - dict = { - "file_ref": _download_file("extrapolate", "file_ref.rst"), - "file_integrated": _download_file("extrapolate", "file.rst"), + path_dict = { + "file_ref": _download_file("extrapolate", "file_ref.rst", should_upload, server), + "file_integrated": _download_file("extrapolate", "file.rst", should_upload, server), } - return dict + return path_dict -def download_extrapolation_2d_result() -> dict: +def download_extrapolation_2d_result(should_upload: bool = True, server=None) -> dict: """Download example static results of reference and integrated points for extrapolation of 2d-element and return the dictionary of 2 download paths. + If the server is remote (or doesn't share the memory), the files are uploaded or made available + 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. + Returns ------- dict @@ -390,29 +514,40 @@ def download_extrapolation_2d_result() -> dict: Download 2 example result files and return the dictionary containing 2 files >>> from ansys.dpf.core import examples - >>> dict = examples.download_extrapolation_ref_result - >>> dict + >>> path_dict = examples.download_extrapolation_ref_result() + >>> path_dict { 'file_ref': 'C:/Users/user/AppData/local/temp/extrapolate_2d_ref.rst', 'file_integrated': 'C:/Users/user/AppData/local/temp/extrapolate_2d.rst' } """ - dict = { - "file_ref": _download_file("extrapolate", "extrapolate_2d_ref.rst"), - "file_integrated": _download_file("extrapolate", "extrapolate_2d.rst"), + path_dict = { + "file_ref": _download_file("extrapolate", "extrapolate_2d_ref.rst", should_upload, server), + "file_integrated": _download_file("extrapolate", "extrapolate_2d.rst", + should_upload, server), } - return dict + return path_dict -def download_hemisphere() -> str: +def download_hemisphere(should_upload: bool = True, server=None) -> str: """Download an example result file from a static analysis and - return the download path. + return the download path available server side. + If the server is remote (or doesn't share the memory), the file is uploaded or made available + 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. + Returns ------- str @@ -428,18 +563,31 @@ def download_hemisphere() -> str: 'C:/Users/user/AppData/local/temp/hemisphere.rst' """ - return _download_file("hemisphere", "hemisphere.rst") + return _download_file("hemisphere", "hemisphere.rst", should_upload, server) -def download_example_asme_result() -> str: +def download_example_asme_result(should_upload: bool = True, server=None) -> str: """Download an example result file from a static analysis and - return the download path. + return the download path available server side. + If the server is remote (or doesn't share the memory), the file is uploaded or made available + 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. + Returns ------- str Path to the example file. + Examples -------- Download an example result file and return the path of the file @@ -448,15 +596,26 @@ def download_example_asme_result() -> str: >>> path 'C:/Users/user/AppData/local/temp/asme_example.rst' """ - return _download_file("postprocessing", "asme_example.rst") + return _download_file("postprocessing", "asme_example.rst", should_upload, server) + -def download_crankshaft() -> str: +def download_crankshaft(should_upload: bool = True, server=None) -> str: """Download the result file of an example of a crankshaft - under load and return the download path. + under load and return the download path available server side. + If the server is remote (or doesn't share the memory), the file is uploaded or made available + 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. + Returns ------- str @@ -467,20 +626,31 @@ def download_crankshaft() -> str: Download an example result file and return the path of the file >>> from ansys.dpf.core import examples - >>> path = examples.crankshaft + >>> path = examples.download_crankshaft() >>> path 'C:/Users/user/AppData/local/temp/crankshaft.rst' """ - return _download_file("crankshaft", "crankshaft.rst") + return _download_file("crankshaft", "crankshaft.rst", should_upload, server) -def download_piston_rod() -> str: + +def download_piston_rod(should_upload: bool = True, server=None) -> str: """Download the result file of an example of a piston rod - under load and return the download path. + under load and return the download path available server side. + If the server is remote (or doesn't share the memory), the file is uploaded or made available + 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. + Returns ------- str @@ -491,9 +661,9 @@ def download_piston_rod() -> str: Download an example result file and return the path of the file >>> from ansys.dpf.core import examples - >>> path = examples.piston_rod + >>> path = examples.download_piston_rod() >>> path 'C:/Users/user/AppData/local/temp/piston_rod.rst' """ - return _download_file("piston_rod", "piston_rod.rst") \ No newline at end of file + return _download_file("piston_rod", "piston_rod.rst", should_upload, server) diff --git a/ansys/dpf/core/examples/examples.py b/ansys/dpf/core/examples/examples.py index 87f67d73b71..6989077a8aa 100644 --- a/ansys/dpf/core/examples/examples.py +++ b/ansys/dpf/core/examples/examples.py @@ -9,6 +9,9 @@ import os import inspect +from ansys.dpf.core import server as server_module +from ansys.dpf.core.core import upload_file_in_tmp_folder + if os.environ.get("DPF_DOCKER", "").lower() == "true": # must pass a path that can be accessed by a docker image with # this directory mounted at the repository level for CI @@ -26,4 +29,320 @@ transient_therm = os.path.join(_module_path, "rth", "rth_transient.rth") msup_transient = os.path.join(_module_path, "msup_transient_plate1.rst") simple_cyclic = os.path.join(_module_path, "file_cyclic.rst") -distributed_msup_folder = os.path.join(_module_path, 'msup_distributed') \ No newline at end of file +distributed_msup_folder = os.path.join(_module_path, 'msup_distributed') + + +def find_files(local_path, should_upload=True, server=None): + """Make the result file available server side, if the server is remote the file is uploaded + server side. Returns the path on the file. + + Parameters + ---------- + local_path : str + File path to make available server side. + 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. + + Returns + ------- + str + Path to the example file. + """ + if should_upload: + server = server_module.get_or_create_server(server) + if not server.local_server: + return upload_file_in_tmp_folder(local_path, server=server) + return local_path + + +def find_simple_bar(should_upload: bool = True, server=None) -> str: + """Make the result file available server side, if the server is remote the file is uploaded + server side. Returns the path on the file. + + 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. + + Returns + ------- + str + Path to the example file. + + Examples + -------- + + >>> from ansys.dpf.core import examples + >>> path = examples.find_simple_bar() + >>> path + 'C:/Users/user/AppData/local/temp/ASimpleBar.rst' + + """ + return find_files(simple_bar, should_upload, server) + + +def find_static_rst(should_upload: bool = True, server=None) -> str: + """Make the result file available server side, if the server is remote the file is uploaded + server side. Returns the path on the file. + + 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. + + Returns + ------- + str + Path to the example file. + + Examples + -------- + + >>> from ansys.dpf.core import examples + >>> path = examples.find_static_rst() + >>> path + 'C:/Users/user/AppData/local/temp/static.rst' + + """ + return find_files(static_rst, should_upload, server) + + +def find_complex_rst(should_upload: bool = True, server=None) -> str: + """Make the result file available server side, if the server is remote the file is uploaded + server side. Returns the path on the file. + + 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. + + Returns + ------- + str + Path to the example file. + + Examples + -------- + + >>> from ansys.dpf.core import examples + >>> path = examples.find_complex_rst() + >>> path + 'C:/Users/user/AppData/local/temp/complex.rst' + + """ + return find_files(complex_rst, should_upload, server) + + +def find_multishells_rst(should_upload: bool = True, server=None) -> str: + """Make the result file available server side, if the server is remote the file is uploaded + server side. Returns the path on the file. + + 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. + + Returns + ------- + str + Path to the example file. + + Examples + -------- + + >>> from ansys.dpf.core import examples + >>> path = examples.find_multishells_rst() + >>> path + 'C:/Users/user/AppData/local/temp/model_with_ns.rst' + + """ + return find_files(multishells_rst, should_upload, server) + + +def find_electric_therm(should_upload: bool = True, server=None) -> str: + """Make the result file available server side, if the server is remote the file is uploaded + server side. Returns the path on the file. + + 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. + + Returns + ------- + str + Path to the example file. + + Examples + -------- + + >>> from ansys.dpf.core import examples + >>> path = examples.find_electric_therm() + >>> path + 'C:/Users/user/AppData/local/temp/rth_electric.rth' + + """ + return find_files(electric_therm, should_upload, server) + + +def find_steady_therm(should_upload: bool = True, server=None) -> str: + """Make the result file available server side, if the server is remote the file is uploaded + server side. Returns the path on the file. + + 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. + + Returns + ------- + str + Path to the example file. + + Examples + -------- + + >>> from ansys.dpf.core import examples + >>> path = examples.find_steady_therm() + >>> path + 'C:/Users/user/AppData/local/temp/rth_steady.rst' + + """ + return find_files(steady_therm, should_upload, server) + + +def find_transient_therm(should_upload: bool = True, server=None) -> str: + """Make the result file available server side, if the server is remote the file is uploaded + server side. Returns the path on the file. + + 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. + + Returns + ------- + str + Path to the example file. + + Examples + -------- + + >>> from ansys.dpf.core import examples + >>> path = examples.find_transient_therm() + >>> path + 'C:/Users/user/AppData/local/temp/rth_transient.rst' + + """ + return find_files(transient_therm, should_upload, server) + + +def find_msup_transient(should_upload: bool = True, server=None) -> str: + """Make the result file available server side, if the server is remote the file is uploaded + server side. Returns the path on the file. + + 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. + + Returns + ------- + str + Path to the example file. + + Examples + -------- + + >>> from ansys.dpf.core import examples + >>> path = examples.find_msup_transient() + >>> path + 'C:/Users/user/AppData/local/temp/msup_transient_plate1.rst' + + """ + return find_files(msup_transient, should_upload, server) + + +def find_simple_cyclic(should_upload: bool = True, server=None) -> str: + """Make the result file available server side, if the server is remote the file is uploaded + server side. Returns the path on the file. + + 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. + + Returns + ------- + str + Path to the example file. + + Examples + -------- + + >>> from ansys.dpf.core import examples + >>> path = examples.find_simple_cyclic() + >>> path + 'C:/Users/user/AppData/local/temp/file_cyclic.rst' + + """ + return find_files(simple_cyclic, should_upload, server) + + +def find_distributed_msup_folder(should_upload: bool = True, server=None) -> str: + """Make the result file available server side, if the server is remote the file is uploaded + server side. Returns the path on the file. + + 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. + + Returns + ------- + str + Path to the example file. + + Examples + -------- + + >>> from ansys.dpf.core import examples + >>> path = examples.find_distributed_msup_folder() + >>> path + 'C:/Users/user/AppData/local/temp/msup_distributed' + + """ + return find_files(distributed_msup_folder, should_upload, server) diff --git a/ansys/dpf/core/field_base.py b/ansys/dpf/core/field_base.py index d40beb7c945..313bffbeb3a 100644 --- a/ansys/dpf/core/field_base.py +++ b/ansys/dpf/core/field_base.py @@ -600,7 +600,7 @@ def get_entity_data_by_id(self, id): -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> stress_op = model.results.stress() >>> fields_container = stress_op.outputs.fields_container() >>> with fields_container[0].as_local_field() as f: diff --git a/ansys/dpf/core/help.py b/ansys/dpf/core/help.py index f59be83be6b..0f0a7c8ace7 100644 --- a/ansys/dpf/core/help.py +++ b/ansys/dpf/core/help.py @@ -38,14 +38,14 @@ def sum(var_inp): # >>> from ansys.dpf import core as dpf # >>> from ansys.dpf.core import examples - # >>> model = dpf.Model(examples.static_rst) + # >>> model = dpf.Model(examples.find_static_rst()) # >>> e_vol = model.results.volume() # >>> total_volume = e_vol.sum() # Sum element volume using dpf.core.sum. # >>> from ansys.dpf.core import examples - # >>> model = dpf.Model(examples.static_rst) + # >>> model = dpf.Model(examples.find_static_rst()) # >>> e_vol = model.results.volume() # >>> total_volume = dpf.help.sum(e_vol) diff --git a/ansys/dpf/core/inputs.py b/ansys/dpf/core/inputs.py index 01d745c3341..a3a0147f32e 100644 --- a/ansys/dpf/core/inputs.py +++ b/ansys/dpf/core/inputs.py @@ -21,7 +21,7 @@ class Input: -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> data_src = dpf.DataSources(examples.msup_transient) + >>> data_src = dpf.DataSources(examples.find_msup_transient()) >>> disp_op = dpf.operators.result.displacement() >>> isinstance(disp_op.inputs.data_sources, dpf.inputs.Input) True @@ -289,7 +289,7 @@ class Inputs(_Inputs): -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> data_src = dpf.DataSources(examples.msup_transient) + >>> data_src = dpf.DataSources(examples.find_msup_transient()) >>> disp_op = dpf.operators.result.displacement() >>> isinstance(disp_op.inputs, dpf.inputs._Inputs) True diff --git a/ansys/dpf/core/meshed_region.py b/ansys/dpf/core/meshed_region.py index 83b27e5e4a7..2a689acbd3d 100644 --- a/ansys/dpf/core/meshed_region.py +++ b/ansys/dpf/core/meshed_region.py @@ -57,7 +57,7 @@ class MeshedRegion: >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> meshed_region = model.metadata.meshed_region Create a meshed region from scratch (line with 3 beam elements). @@ -156,7 +156,7 @@ def elements(self): -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> meshed_region = model.metadata.meshed_region >>> elements = meshed_region.elements >>> print(elements) @@ -179,7 +179,7 @@ def nodes(self): -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> meshed_region = model.metadata.meshed_region >>> nodes = meshed_region.nodes >>> nodes.n_nodes @@ -498,7 +498,7 @@ def grid(self): -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> meshed_region = model.metadata.meshed_region >>> grid = meshed_region.grid @@ -547,7 +547,7 @@ def plot( >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> disp = model.results.displacement() >>> field = disp.outputs.fields_container()[0] >>> model.metadata.meshed_region.plot(field) @@ -601,7 +601,7 @@ def deep_copy(self, server=None): -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> meshed_region = model.metadata.meshed_region >>> other_server = dpf.start_local_server(as_global=False) >>> deep_copy = meshed_region.deep_copy(server=other_server) @@ -645,7 +645,7 @@ def field_of_properties(self, property_name): -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> meshed_region = model.metadata.meshed_region >>> connectivity = meshed_region.field_of_properties( ... dpf.common.elemental_properties.connectivity) diff --git a/ansys/dpf/core/meshes_container.py b/ansys/dpf/core/meshes_container.py index dab66ceae41..a2f05a48e49 100644 --- a/ansys/dpf/core/meshes_container.py +++ b/ansys/dpf/core/meshes_container.py @@ -59,12 +59,12 @@ def plot(self, fields_container=None, deform_by=None, scale_factor=1.0, **kwargs -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.multishells_rst) + >>> model = dpf.Model(examples.find_multishells_rst()) >>> mesh = model.metadata.meshed_region >>> split_mesh_op = dpf.operators.mesh.split_mesh(mesh=mesh, property="mat") >>> meshes_cont = split_mesh_op.eval() >>> disp_op = dpf.operators.result.displacement( - ... data_sources = dpf.DataSources(examples.multishells_rst), + ... data_sources = dpf.DataSources(examples.find_multishells_rst()), ... mesh = meshes_cont ... ) >>> disp_fc = disp_op.outputs.fields_container() diff --git a/ansys/dpf/core/model.py b/ansys/dpf/core/model.py index 3c3d190fe9d..3f0588cc76f 100644 --- a/ansys/dpf/core/model.py +++ b/ansys/dpf/core/model.py @@ -129,7 +129,7 @@ def results(self): -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.electric_therm) + >>> model = dpf.Model(examples.find_electric_therm()) >>> v = model.results.electric_potential >>> dissip = model.results.thermal_dissipation_energy @@ -139,7 +139,7 @@ def results(self): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.simple_bar) + >>> model = dpf.Model(examples.find_simple_bar()) >>> results = model.results # printable object Access the displacement at all times. diff --git a/ansys/dpf/core/nodes.py b/ansys/dpf/core/nodes.py index ac621d6f655..cec9638253f 100644 --- a/ansys/dpf/core/nodes.py +++ b/ansys/dpf/core/nodes.py @@ -32,7 +32,7 @@ class Node: -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> nodes = model.metadata.meshed_region.nodes >>> # Initialize a node from a nodes collection @@ -70,7 +70,7 @@ def coordinates(self): -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> node = model.metadata.meshed_region.nodes[0] >>> node.coordinates [0.015, 0.045, 0.015] @@ -109,7 +109,7 @@ class Nodes: -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> meshed_region = model.metadata.meshed_region >>> nodes = model.metadata.meshed_region.nodes >>> nodes.n_nodes @@ -191,7 +191,7 @@ def scoping(self): >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> meshed_region = model.metadata.meshed_region >>> nodes = model.metadata.meshed_region.nodes >>> nodes.scoping.ids[2] @@ -219,7 +219,7 @@ def coordinates_field(self): -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> meshed_region = model.metadata.meshed_region >>> nodes = model.metadata.meshed_region.nodes >>> coordinates = nodes.coordinates_field @@ -261,7 +261,7 @@ def nodal_connectivity_field(self): -------- >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> meshed_region = model.metadata.meshed_region >>> nodes = model.metadata.meshed_region.nodes >>> field = nodes.nodal_connectivity_field @@ -309,7 +309,7 @@ def map_scoping(self, external_scope): >>> import ansys.dpf.core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.static_rst) + >>> model = dpf.Model(examples.find_static_rst()) >>> nodes = model.metadata.meshed_region.nodes >>> disp = model.results.displacement() >>> field = disp.outputs.fields_container()[0] diff --git a/ansys/dpf/core/outputs.py b/ansys/dpf/core/outputs.py index d248241bb8b..7846fdac6ec 100644 --- a/ansys/dpf/core/outputs.py +++ b/ansys/dpf/core/outputs.py @@ -20,7 +20,7 @@ class Output: -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> data_src = dpf.DataSources(examples.msup_transient) + >>> data_src = dpf.DataSources(examples.find_msup_transient()) >>> disp_op = dpf.operators.result.displacement() >>> disp_op.inputs.data_sources(data_src) >>> isinstance(disp_op.outputs.fields_container, dpf.inputs.Output) @@ -141,7 +141,7 @@ class Outputs(_Outputs): -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> data_src = dpf.DataSources(examples.msup_transient) + >>> data_src = dpf.DataSources(examples.find_msup_transient()) >>> disp_op = dpf.operators.result.displacement() >>> disp_op.inputs.data_sources(data_src) >>> isinstance(disp_op.outputs, dpf.inputs._Outputs) diff --git a/ansys/dpf/core/plotter.py b/ansys/dpf/core/plotter.py index 89887b7315e..652ef8013e2 100755 --- a/ansys/dpf/core/plotter.py +++ b/ansys/dpf/core/plotter.py @@ -384,7 +384,7 @@ def add_mesh(self, meshed_region, deform_by=None, scale_factor=1.0, **kwargs): -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.multishells_rst) + >>> model = dpf.Model(examples.find_multishells_rst()) >>> mesh = model.metadata.meshed_region >>> from ansys.dpf.core.plotter import DpfPlotter >>> pl = DpfPlotter() @@ -432,7 +432,7 @@ def add_field(self, field, meshed_region=None, show_max=False, show_min=False, -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.multishells_rst) + >>> model = dpf.Model(examples.find_multishells_rst()) >>> mesh = model.metadata.meshed_region >>> field = model.results.displacement().outputs.fields_container()[0] >>> from ansys.dpf.core.plotter import DpfPlotter @@ -463,7 +463,7 @@ def show_figure(self, **kwargs): -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.multishells_rst) + >>> model = dpf.Model(examples.find_multishells_rst()) >>> mesh = model.metadata.meshed_region >>> field = model.results.displacement().outputs.fields_container()[0] >>> from ansys.dpf.core.plotter import DpfPlotter @@ -498,7 +498,7 @@ def plot_chart(fields_container, off_screen=False, screenshot=None): -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.transient_therm) + >>> model = dpf.Model(examples.find_transient_therm()) >>> t = model.results.temperature.on_all_time_freqs() >>> fc = t.outputs.fields_container() >>> plotter = dpf.plotter.plot_chart(fc) @@ -566,7 +566,7 @@ def plot_chart(fields_container, off_screen=False, screenshot=None): -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.simple_bar) + >>> model = dpf.Model(examples.find_simple_bar()) >>> disp = model.results.displacement() >>> scoping = dpf.Scoping() >>> scoping.ids = range(1, len(model.metadata.time_freq_support.time_frequencies) + 1) diff --git a/ansys/dpf/core/results.py b/ansys/dpf/core/results.py index 9434f38ae3e..274ad6f7c16 100644 --- a/ansys/dpf/core/results.py +++ b/ansys/dpf/core/results.py @@ -34,7 +34,7 @@ class Results: >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.msup_transient) + >>> model = dpf.Model(examples.find_msup_transient()) >>> disp = model.results.displacement.on_last_time_freq.on_named_selection("_CONSTRAINEDNODES") >>> last_time_disp = disp.eval() @@ -49,7 +49,7 @@ class Results: >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.msup_transient) + >>> model = dpf.Model(examples.find_msup_transient()) >>> stress = model.results.stress.on_last_time_freq.on_named_selection('_CONSTRAINEDNODES') >>> last_time_stress = stress.eval() @@ -61,7 +61,7 @@ class Results: -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.electric_therm) + >>> model = dpf.Model(examples.find_electric_therm()) >>> v = model.results.electric_potential >>> dissip = model.results.thermal_dissipation_energy @@ -71,7 +71,7 @@ class Results: >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.simple_bar) + >>> model = dpf.Model(examples.find_simple_bar()) >>> results = model.results # printable object Access the displacement at all times. @@ -167,7 +167,7 @@ class Result: >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.msup_transient) + >>> model = dpf.Model(examples.find_msup_transient()) >>> disp = model.results.displacement.on_last_time_freq.on_named_selection('_CONSTRAINEDNODES') >>> last_time_disp = disp.eval() @@ -182,7 +182,7 @@ class Result: Create a strain result from the model on all time sets and recover the operator to connect it to other operators. - >>> model = dpf.Model(examples.msup_transient) + >>> model = dpf.Model(examples.find_msup_transient()) >>> strain = model.results.elastic_strain.on_all_time_freqs() >>> eqv = dpf.operators.invariant.von_mises_eqv_fc(strain) >>> strain_eqv = eqv.outputs.fields_container() @@ -260,7 +260,7 @@ def eval(self): -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.msup_transient) + >>> model = dpf.Model(examples.find_msup_transient()) >>> disp = model.results.displacement >>> fc = disp.on_all_time_freqs.eval() @@ -284,7 +284,7 @@ def on_all_time_freqs(self): -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.msup_transient) + >>> model = dpf.Model(examples.find_msup_transient()) >>> disp = model.results.displacement >>> disp.on_all_time_freqs.eval().get_label_scoping("time").ids @@ -308,7 +308,7 @@ def on_first_time_freq(self): -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.msup_transient) + >>> model = dpf.Model(examples.find_msup_transient()) >>> disp = model.results.displacement >>> disp.on_first_time_freq.eval().get_label_scoping("time").ids @@ -330,7 +330,7 @@ def on_last_time_freq(self): -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.msup_transient) + >>> model = dpf.Model(examples.find_msup_transient()) >>> disp = model.results.displacement >>> disp.on_last_time_freq.eval().get_label_scoping("time").ids @@ -360,7 +360,7 @@ def on_time_scoping(self, time_scoping): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.msup_transient) + >>> model = dpf.Model(examples.find_msup_transient()) >>> stress = model.results.stress >>> fc = stress.on_time_scoping([1,2,3,19]).eval() >>> len(fc) @@ -397,7 +397,7 @@ def on_named_selection(self, named_selection): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.msup_transient) + >>> model = dpf.Model(examples.find_msup_transient()) >>> stress = model.results.stress >>> fc = stress.on_first_time_freq.on_named_selection('_CONSTRAINEDNODES').eval() >>> len(fc[0].scoping) @@ -501,7 +501,7 @@ def on_mesh_scoping(self, mesh_scoping): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.complex_rst) + >>> model = dpf.Model(examples.find_complex_rst()) >>> disp = model.results.displacement >>> fc = disp.on_mesh_scoping([1,2,3]).eval() >>> len(fc[0].scoping) @@ -547,7 +547,7 @@ def on_location(self, location): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.complex_rst) + >>> model = dpf.Model(examples.find_complex_rst()) >>> stress = model.results.stress >>> fc = stress.eval() >>> fc[0].location @@ -600,7 +600,7 @@ def displacement(self): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.msup_transient) + >>> model = dpf.Model(examples.find_msup_transient()) >>> disp = model.results.displacement >>> disp = disp.on_last_time_freq.on_named_selection("_CONSTRAINEDNODES") >>> last_time_disp = disp.eval() @@ -625,7 +625,7 @@ def elastic_strain(self): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.msup_transient) + >>> model = dpf.Model(examples.find_msup_transient()) >>> strain = model.results.elastic_strain >>> strain = strain.on_last_time_freq.on_named_selection("_CONSTRAINEDNODES") >>> last_time_disp = strain.eval() @@ -650,7 +650,7 @@ def stress(self): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.msup_transient) + >>> model = dpf.Model(examples.find_msup_transient()) >>> stress = model.results.stress >>> stress = stress.on_last_time_freq.on_named_selection("_CONSTRAINEDNODES") >>> last_time_disp = stress.eval() @@ -676,7 +676,7 @@ def structural_temperature(self): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.complex_rst) + >>> model = dpf.Model(examples.find_complex_rst()) >>> structural_temperature = model.results.structural_temperature >>> structural_temperature = structural_temperature.on_last_time_freq() >>> last_time_disp = structural_temperature.eval() @@ -702,7 +702,7 @@ def temperature(self): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.steady_therm) + >>> model = dpf.Model(examples.find_steady_therm()) >>> temperature = model.results.temperature.on_last_time_freq() >>> last_time_disp = temperature.eval() """ @@ -727,7 +727,7 @@ def electric_potential(self): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.electric_therm) + >>> model = dpf.Model(examples.find_electric_therm()) >>> electric_potential = model.results.electric_potential.on_first_time_freq() >>> last_time_disp = electric_potential.eval() """ diff --git a/ansys/dpf/core/server.py b/ansys/dpf/core/server.py index 63ba76d5281..4c04bc539fb 100644 --- a/ansys/dpf/core/server.py +++ b/ansys/dpf/core/server.py @@ -226,7 +226,7 @@ def start_local_server( else: server = server_type( ansys_path, as_global=as_global, - load_operators=load_operators, docker_name=docker_name, timeout=timeout) + load_operators=load_operators, timeout=timeout) break except errors.InvalidPortError: # allow socket in use errors port += 1 diff --git a/ansys/dpf/core/server_types.py b/ansys/dpf/core/server_types.py index a2784b8459a..451beb3156f 100644 --- a/ansys/dpf/core/server_types.py +++ b/ansys/dpf/core/server_types.py @@ -74,7 +74,7 @@ def check_valid_ip(ip): raise ValueError(f'Invalid IP address "{ip}"') -def _verify_ansys_path_is_valid(ansys_path, executable, path_in_install = None): +def _verify_ansys_path_is_valid(ansys_path, executable, path_in_install=None): if path_in_install is None: path_in_install = load_api._get_path_in_install() if os.path.isdir(f"{ansys_path}/{path_in_install}"): @@ -457,6 +457,11 @@ def meet_version(self, required_version): def local_server(self) -> bool: pass + @local_server.setter + @abc.abstractmethod + def local_server(self, val): + pass + def __str__(self): return f"DPF Server: {self.info}" @@ -662,6 +667,10 @@ def port(self): def local_server(self): return self._local_server + @local_server.setter + def local_server(self, val): + self._local_server = val + class InProcessServer(CServer): """Server using the InProcess communication protocol""" @@ -670,7 +679,6 @@ def __init__(self, ansys_path=None, as_global=True, load_operators=True, - docker_name=None, timeout=None): # Load DPFClientAPI super().__init__(ansys_path=ansys_path, load_operators=load_operators) @@ -720,6 +728,11 @@ def client(self): def local_server(self): return True + @local_server.setter + def local_server(self, val): + if not val: + raise NotImplementedError("an in process server can only be local.") + class LegacyGrpcServer(BaseServer): """Provides an instance of the DPF server using InProcess gRPC. @@ -897,6 +910,10 @@ def info(self): def local_server(self): return self._local_server + @local_server.setter + def local_server(self, val): + self._local_server = val + def shutdown(self): if self._own_process and self.live: b_shell = False diff --git a/ansys/dpf/core/streams_container.py b/ansys/dpf/core/streams_container.py index 47e9ec910b3..8d2cf1f7fb2 100644 --- a/ansys/dpf/core/streams_container.py +++ b/ansys/dpf/core/streams_container.py @@ -33,7 +33,7 @@ class StreamsContainer: -------- >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples - >>> model = dpf.Model(examples.multishells_rst) + >>> model = dpf.Model(examples.find_multishells_rst()) >>> streams_provider = model.metadata.streams_provider >>> sc = streams_provider.outputs.streams_container() """ diff --git a/ansys/dpf/core/workflow.py b/ansys/dpf/core/workflow.py index c9aef2fef92..ffbb899f442 100644 --- a/ansys/dpf/core/workflow.py +++ b/ansys/dpf/core/workflow.py @@ -58,7 +58,7 @@ class Workflow: >>> from ansys.dpf.core import examples - >>> data_src = dpf.DataSources(examples.multishells_rst) + >>> data_src = dpf.DataSources(examples.find_multishells_rst()) >>> workflow.connect("data_sources", data_src) >>> min = workflow.get_output("min", dpf.types.field) # doctest: +SKIP >>> max = workflow.get_output("max", dpf.types.field) # doctest: +SKIP @@ -138,7 +138,7 @@ def connect(self, pin_name, inpt, pin_out=0): >>> from ansys.dpf.core import examples - >>> data_src = dpf.DataSources(examples.multishells_rst) + >>> data_src = dpf.DataSources(examples.find_multishells_rst()) >>> workflow.connect("data_sources", data_src) >>> min = workflow.get_output("min", dpf.types.field) # doctest: +SKIP >>> max = workflow.get_output("max", dpf.types.field) # doctest: +SKIP @@ -326,7 +326,7 @@ def set_input_name(self, name, *args): >>> workflow.set_input_name("data_sources", disp_op.inputs.data_sources) >>> from ansys.dpf.core import examples - >>> data_src = dpf.DataSources(examples.multishells_rst) + >>> data_src = dpf.DataSources(examples.find_multishells_rst()) >>> workflow.connect("data_sources", data_src) """ @@ -358,7 +358,7 @@ def set_output_name(self, name, *args): >>> from ansys.dpf import core as dpf >>> from ansys.dpf.core import examples >>> workflow = dpf.Workflow() - >>> model = dpf.Model(examples.simple_bar) + >>> model = dpf.Model(examples.find_simple_bar()) >>> disp_op = model.results.displacement() >>> max_fc_op = dpf.operators.min_max.min_max_fc(disp_op) >>> workflow.set_output_name("contour", disp_op.outputs.fields_container) diff --git a/docs/source/_static/simple_example.rst b/docs/source/_static/simple_example.rst index 0856880be2a..f9d5538b453 100644 --- a/docs/source/_static/simple_example.rst +++ b/docs/source/_static/simple_example.rst @@ -5,7 +5,7 @@ extract results: from ansys.dpf.core import Model from ansys.dpf.core import examples - model = Model(examples.simple_bar) + model = Model(examples.find_simple_bar()) print(model) diff --git a/docs/source/getting_started/install.rst b/docs/source/getting_started/install.rst index 63230b8bef1..eef32ffbfa9 100644 --- a/docs/source/getting_started/install.rst +++ b/docs/source/getting_started/install.rst @@ -42,7 +42,7 @@ For a quick tryou, use: from ansys.dpf.core import Model from ansys.dpf.core import examples - model = Model(examples.simple_bar) + model = Model(examples.find_simple_bar()) print(model) diff --git a/docs/source/index.rst b/docs/source/index.rst index 29a9db74c73..b0adb6c07e7 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -39,7 +39,7 @@ and extract results: >>> from ansys.dpf.core import Model >>> from ansys.dpf.core import examples - >>> model = Model(examples.simple_bar) + >>> model = Model(examples.find_simple_bar()) >>> print(model) diff --git a/docs/source/user_guide/fields_container.rst b/docs/source/user_guide/fields_container.rst index 1aca1de66ee..2c95bf52466 100644 --- a/docs/source/user_guide/fields_container.rst +++ b/docs/source/user_guide/fields_container.rst @@ -23,7 +23,7 @@ This example uses the ``elastic_strain`` operator to access a fields container: from ansys.dpf import core as dpf from ansys.dpf.core import examples - model = dpf.Model(examples.msup_transient) + model = dpf.Model(examples.find_msup_transient()) epel = model.results.elastic_strain.on_all_time_freqs fields = epel.eval() print(fields) @@ -152,7 +152,7 @@ time complex IDs are available in the fields container: .. code-block:: - model = dpf.Model(examples.msup_transient) + model = dpf.Model(examples.find_msup_transient()) epel = model.results.elastic_strain.on_all_time_freqs fields = epel.eval() print(fields.time_freq_support) diff --git a/docs/source/user_guide/model.rst b/docs/source/user_guide/model.rst index 4ea420e30cb..d046abdab6d 100644 --- a/docs/source/user_guide/model.rst +++ b/docs/source/user_guide/model.rst @@ -17,7 +17,7 @@ or a path relative to the DPF server. from ansys.dpf import core as dpf from ansys.dpf.core import examples - path = examples.simple_bar + path = examples.find_simple_bar() model = dpf.Model(path) To understand what is available in the result file, you can print the model diff --git a/docs/source/user_guide/operators.rst b/docs/source/user_guide/operators.rst index bce9dceac23..9f07f3678da 100644 --- a/docs/source/user_guide/operators.rst +++ b/docs/source/user_guide/operators.rst @@ -36,7 +36,7 @@ of a result: from ansys.dpf.core import Model from ansys.dpf.core import examples from ansys.dpf.core import operators as ops - model = Model(examples.simple_bar) + model = Model(examples.find_simple_bar()) displacement = model.results.displacement() norm = ops.math.norm(displacement) min_max = ops.min_max.min_max(norm) @@ -109,7 +109,7 @@ available results for your result files: from ansys.dpf.core import Model from ansys.dpf.core import examples from ansys.dpf.core import operators as ops - model = Model(examples.simple_bar) + model = Model(examples.find_simple_bar()) displacement = model.results.displacement() @@ -132,7 +132,7 @@ Because several other examples use the ``Model`` class, this example uses the from ansys.dpf import core as dpf from ansys.dpf.core import examples - data_src = dpf.DataSources(examples.multishells_rst) + data_src = dpf.DataSources(examples.find_multishells_rst()) print(data_src) @@ -227,7 +227,7 @@ displacement data on the client side to compute the maximum: from ansys.dpf.core import Model from ansys.dpf.core import examples from ansys.dpf.core import operators as ops - model = Model(examples.simple_bar) + model = Model(examples.find_simple_bar()) displacement = model.results.displacement() fc = displacement.outputs.fields_container() @@ -253,7 +253,7 @@ On an industrial model, however, you should use code like this: from ansys.dpf.core import Model from ansys.dpf.core import examples from ansys.dpf.core import operators as ops - model = Model(examples.simple_bar) + model = Model(examples.find_simple_bar()) displacement = model.results.displacement() min_max = ops.min_max.min_max(displacement) max_field = min_max.outputs.field_max() @@ -333,7 +333,7 @@ This example shows how to read a displacement or a stress for any file: from ansys.dpf import core as dpf from ansys.dpf.core import examples from ansys.dpf.core import operators as ops - data_src = dpf.DataSources(examples.multishells_rst) + data_src = dpf.DataSources(examples.find_multishells_rst()) disp = ops.result.displacement(data_sources = data_src) stress = ops.result.stress(data_sources = data_src) @@ -420,7 +420,7 @@ displays available import and export operators. from ansys.dpf import core as dpf from ansys.dpf.core import examples from ansys.dpf.core import operators as ops - model = dpf.Model(examples.multishells_rst) + model = dpf.Model(examples.find_multishells_rst()) disp = model.results.displacement() vtk = ops.serialization.vtk_export(file_path='c:/temp/file.vtk', mesh=model.metadata.meshed_region, fields1=disp) @@ -437,7 +437,7 @@ Python client is not on the same machine as the server: from ansys.dpf.core import operators as ops server_dir = dpf.make_tmp_dir_server() print(server_dir) - up_loaded_file = dpf.upload_file_in_tmp_folder(examples.multishells_rst) + up_loaded_file = dpf.upload_file_in_tmp_folder(examples.find_multishells_rst()) model = dpf.Model(up_loaded_file) disp = model.results.displacement() vtk = ops.serialization.vtk_export(file_path=server_dir+"\\file.vtk", diff --git a/docs/source/user_guide/stepbystep.rst b/docs/source/user_guide/stepbystep.rst index 16383a09aca..5d395897c0f 100644 --- a/docs/source/user_guide/stepbystep.rst +++ b/docs/source/user_guide/stepbystep.rst @@ -192,7 +192,7 @@ This example shows how to define an operator from a model: from ansys.dpf.core import Model from ansys.dpf.core import examples - model = Model(examples.static_rst) + model = Model(examples.find_static_rst()) disp_oper = model.results.displacement() Define workflows @@ -228,7 +228,7 @@ of displacement by chaining the ``U`` and ``min_max_fc`` operators: .. code-block:: python from ansys.dpf.core import examples - data_src = dpf.DataSources(examples.multishells_rst) + data_src = dpf.DataSources(examples.find_multishells_rst()) workflow.connect("data_sources", data_src) min = workflow.get_output("min", dpf.types.field) max = workflow.get_output("max", dpf.types.field) diff --git a/examples/00-basic/00-basic_example.py b/examples/00-basic/00-basic_example.py index a2b53bd4edc..a760321c401 100644 --- a/examples/00-basic/00-basic_example.py +++ b/examples/00-basic/00-basic_example.py @@ -37,7 +37,7 @@ # want to connect to an existing server (either local or remote), use # :func:`dpf.connect_to_server`. -model = dpf.Model(examples.simple_bar) +model = dpf.Model(examples.find_simple_bar()) print(model) ############################################################################### diff --git a/examples/00-basic/01-basic_operators.py b/examples/00-basic/01-basic_operators.py index 4d49754d38e..ae61f1b7cc0 100644 --- a/examples/00-basic/01-basic_operators.py +++ b/examples/00-basic/01-basic_operators.py @@ -23,7 +23,7 @@ ############################################################################### # Create a model object to establish a connection with an # example result file: -model = dpf.Model(examples.static_rst) +model = dpf.Model(examples.find_static_rst()) print(model) ############################################################################### @@ -102,8 +102,8 @@ ############################################################################### # Instead of using a ``model`` class instance, use a # ``DdataSources`` object directly. The ``DataSources`` constructor input is a path. -ds = dpf.DataSources(examples.static_rst) -print(examples.static_rst) +ds = dpf.DataSources(examples.find_static_rst()) +print(examples.find_static_rst()) ############################################################################### # Instantiate the operators and connect them: diff --git a/examples/00-basic/02-basic_field_containers.py b/examples/00-basic/02-basic_field_containers.py index c6c01686645..403b653c55e 100644 --- a/examples/00-basic/02-basic_field_containers.py +++ b/examples/00-basic/02-basic_field_containers.py @@ -39,7 +39,7 @@ ############################################################################### # Create a model object to establish a connection with an # example result file and then extract: -model = dpf.Model(examples.static_rst) +model = dpf.Model(examples.find_static_rst()) print(model) ############################################################################### diff --git a/examples/00-basic/04-basic-load-file.py b/examples/00-basic/04-basic-load-file.py index bdfa0fb3da9..5564afae78f 100644 --- a/examples/00-basic/04-basic-load-file.py +++ b/examples/00-basic/04-basic-load-file.py @@ -17,7 +17,7 @@ from ansys.dpf import core as dpf from ansys.dpf.core import examples -model = dpf.Model(examples.simple_bar) +model = dpf.Model(examples.find_simple_bar()) mesh = model.metadata.meshed_region ############################################################################### diff --git a/examples/00-basic/11-server_types.py b/examples/00-basic/11-server_types.py index 8e49f4cc839..d12eae02df8 100644 --- a/examples/00-basic/11-server_types.py +++ b/examples/00-basic/11-server_types.py @@ -20,6 +20,12 @@ - :class:`ansys.dpf.core.server_types.LegacyGrpcServer` using gRPC communication through the Python module ``ansys.grpc.dpf``. +To change the default type of server's configuration used by DPF change: + +- the global variable ``SERVER_CONFIGURATION`` at the beginning of the python script. +- the environment variable ``DPF_SERVER_TYPE`` before running the python executable, see + :class:`ansys.dpf.core.server_factory.ServerConfig` for more information. + """ from ansys.dpf import core as dpf diff --git a/examples/00-basic/12-get_material_properties.py b/examples/00-basic/12-get_material_properties.py index 73f8303f4f5..e6763be3b91 100644 --- a/examples/00-basic/12-get_material_properties.py +++ b/examples/00-basic/12-get_material_properties.py @@ -15,7 +15,7 @@ ############################################################################### # Create a model object to establish a connection with an example result file. -model = dpf.Model(examples.simple_bar) +model = dpf.Model(examples.find_simple_bar()) ############################################################################### # Get the :class:`meshed_region ` diff --git a/examples/01-static-transient/01-transient_easy_time_scoping.py b/examples/01-static-transient/01-transient_easy_time_scoping.py index 531332ab3d1..a34451987a1 100644 --- a/examples/01-static-transient/01-transient_easy_time_scoping.py +++ b/examples/01-static-transient/01-transient_easy_time_scoping.py @@ -16,7 +16,7 @@ # Create the model and display the state of the result. This transient result # file contains several individual results, each at a different times. -transient = examples.msup_transient +transient = examples.find_msup_transient() model = dpf.Model(transient) print(model) diff --git a/examples/02-modal-harmonic/01-modal_cyclic.py b/examples/02-modal-harmonic/01-modal_cyclic.py index 83e276efa81..76e349994a5 100644 --- a/examples/02-modal-harmonic/01-modal_cyclic.py +++ b/examples/02-modal-harmonic/01-modal_cyclic.py @@ -12,7 +12,7 @@ ############################################################################### # Create the model and display the state of the result. -model = dpf.Model(examples.simple_cyclic) +model = dpf.Model(examples.find_simple_cyclic()) print(model) ############################################################################### diff --git a/examples/03-advanced/02-volume_averaged_stress.py b/examples/03-advanced/02-volume_averaged_stress.py index 532fe8477af..6cceee51942 100644 --- a/examples/03-advanced/02-volume_averaged_stress.py +++ b/examples/03-advanced/02-volume_averaged_stress.py @@ -18,7 +18,7 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # The model provides easy access to the mesh and time frequency support. -model = dpf.Model(examples.complex_rst) +model = dpf.Model(examples.find_complex_rst()) mesh = model.metadata.meshed_region # Volume size to check diff --git a/examples/03-advanced/03-exchange_data_between_servers.py b/examples/03-advanced/03-exchange_data_between_servers.py index 0cb9ce4335c..4cecf2df173 100644 --- a/examples/03-advanced/03-exchange_data_between_servers.py +++ b/examples/03-advanced/03-exchange_data_between_servers.py @@ -35,8 +35,7 @@ # The result file is sent to the temporary directory of the first server. # This file upload is useless in this case because the two servers are local # machines. -file = examples.complex_rst -file_path_in_tmp = dpf.upload_file_in_tmp_folder(file) +file_path_in_tmp = examples.find_complex_rst(server=server1) ############################################################################### # Create a workflow on the first server diff --git a/examples/05-plotting/00-basic_plotting.py b/examples/05-plotting/00-basic_plotting.py index 51ce43cc068..235093f423c 100644 --- a/examples/05-plotting/00-basic_plotting.py +++ b/examples/05-plotting/00-basic_plotting.py @@ -13,7 +13,7 @@ # Plot the bare mesh of a model -model = dpf.Model(examples.multishells_rst) +model = dpf.Model(examples.find_multishells_rst()) model.plot(color="w", show_edges=True, title='Model', text='Model plot') # # Additional PyVista kwargs are supported, such as: model.plot(off_screen=True, notebook=False, screenshot='model_plot.png', @@ -54,7 +54,7 @@ # A fields_container can be given as input, with results on each part of our split mesh. disp_op = dpf.Operator("U") disp_op.connect(7, meshes_cont) -ds = dpf.DataSources(examples.multishells_rst) +ds = dpf.DataSources(examples.find_multishells_rst()) disp_op.connect(4, ds) disp_fc = disp_op.outputs.fields_container() meshes_cont.plot(disp_fc, title='Meshes Container disp_fc', text='Meshes Container disp_fc plot') diff --git a/examples/05-plotting/01-compare_results.py b/examples/05-plotting/01-compare_results.py index bf5e690568b..639ea1d6e61 100644 --- a/examples/05-plotting/01-compare_results.py +++ b/examples/05-plotting/01-compare_results.py @@ -19,7 +19,7 @@ # results over the same mesh and compare them. # Here we create a Model and request its mesh -model = dpf.Model(examples.msup_transient) +model = dpf.Model(examples.find_msup_transient()) mesh_set2 = model.metadata.meshed_region # Then we need to request the displacement for two different time steps diff --git a/examples/05-plotting/02-solution_combination.py b/examples/05-plotting/02-solution_combination.py index ac6095112df..19de699f975 100644 --- a/examples/05-plotting/02-solution_combination.py +++ b/examples/05-plotting/02-solution_combination.py @@ -28,7 +28,7 @@ # - Size of the mesh # - Number of results # -model = dpf.Model(examples.msup_transient) +model = dpf.Model(examples.find_msup_transient()) print(model) ############################################################################### diff --git a/examples/05-plotting/03-labels.py b/examples/05-plotting/03-labels.py index b92a9a9ba8b..e140e58483f 100644 --- a/examples/05-plotting/03-labels.py +++ b/examples/05-plotting/03-labels.py @@ -27,7 +27,7 @@ # - Size of the mesh # - Number of results # -model = dpf.Model(examples.msup_transient) +model = dpf.Model(examples.find_msup_transient()) print(model) ############################################################################### diff --git a/examples/05-plotting/04-plot_on_path.py b/examples/05-plotting/04-plot_on_path.py index af510f1b682..5b793b0e460 100644 --- a/examples/05-plotting/04-plot_on_path.py +++ b/examples/05-plotting/04-plot_on_path.py @@ -20,7 +20,7 @@ # result over a defined path of coordinates. # Create the model and request its mesh and displacement data. -model = dpf.Model(examples.static_rst) +model = dpf.Model(examples.find_static_rst()) mesh = model.metadata.meshed_region stress_fc = model.results.stress().eqv().eval() diff --git a/examples/05-plotting/05-plot_on_warped_mesh.py b/examples/05-plotting/05-plot_on_warped_mesh.py index d51ccd6b8c6..7374701dc61 100644 --- a/examples/05-plotting/05-plot_on_warped_mesh.py +++ b/examples/05-plotting/05-plot_on_warped_mesh.py @@ -12,7 +12,7 @@ from ansys.dpf.core import examples # Get and show the initial model -model = dpf.Model(examples.multishells_rst) +model = dpf.Model(examples.find_multishells_rst()) print(model) model.plot(title='Model', text='Model.plot()') diff --git a/examples/05-plotting/06-animate_results.py b/examples/05-plotting/06-animate_results.py index 7faf9e279a0..feae81c8025 100644 --- a/examples/05-plotting/06-animate_results.py +++ b/examples/05-plotting/06-animate_results.py @@ -12,7 +12,7 @@ # Load the model -model = dpf.Model(examples.msup_transient) +model = dpf.Model(examples.find_msup_transient()) print(model) # Use Scoping instances to adjust the region and the steps involved. diff --git a/examples/06-distributed-post/02-distributed-msup_expansion.py b/examples/06-distributed-post/02-distributed-msup_expansion.py index a8c10d4c97a..23e6996ecea 100644 --- a/examples/06-distributed-post/02-distributed-msup_expansion.py +++ b/examples/06-distributed-post/02-distributed-msup_expansion.py @@ -108,7 +108,7 @@ ############################################################################### # Specify the file path. -base_path = examples.distributed_msup_folder +base_path = examples.find_distributed_msup_folder() files = [base_path + r'/file0.mode', base_path + r'/file1.mode'] files_aux = [base_path + r'/file0.rst', base_path + r'/file1.rst'] diff --git a/examples/06-distributed-post/03-distributed-msup_expansion_steps.py b/examples/06-distributed-post/03-distributed-msup_expansion_steps.py index c66d3b11205..1bdde7c7204 100644 --- a/examples/06-distributed-post/03-distributed-msup_expansion_steps.py +++ b/examples/06-distributed-post/03-distributed-msup_expansion_steps.py @@ -113,7 +113,7 @@ ############################################################################### # Specify the file path. -base_path = examples.distributed_msup_folder +base_path = examples.find_distributed_msup_folder() files = [os.path.join(base_path, "file0.mode"), os.path.join(base_path, "file1.mode")] files_aux = [os.path.join(base_path, "file0.rst"), os.path.join(base_path, "file1.rst")] diff --git a/examples/07-python-operators/00-wrapping_numpy_capabilities.py b/examples/07-python-operators/00-wrapping_numpy_capabilities.py index 3f272f8b79e..04b79a6d482 100644 --- a/examples/07-python-operators/00-wrapping_numpy_capabilities.py +++ b/examples/07-python-operators/00-wrapping_numpy_capabilities.py @@ -94,7 +94,7 @@ # Use the operator # ---------------- -ds = dpf.DataSources(dpf.upload_file_in_tmp_folder(examples.static_rst)) +ds = dpf.DataSources(dpf.upload_file_in_tmp_folder(examples.find_static_rst())) displacement = dpf.operators.result.displacement(data_sources=ds) norm = dpf.operators.math.norm(displacement) new_operator.inputs.connect(norm) diff --git a/examples/07-python-operators/01-package_python_operators.py b/examples/07-python-operators/01-package_python_operators.py index 5d145e37953..c5ad5802070 100644 --- a/examples/07-python-operators/01-package_python_operators.py +++ b/examples/07-python-operators/01-package_python_operators.py @@ -112,7 +112,7 @@ # Use the operator # ---------------- -ds = dpf.DataSources(dpf.upload_file_in_tmp_folder(examples.static_rst)) +ds = dpf.DataSources(dpf.upload_file_in_tmp_folder(examples.find_static_rst())) displacement = dpf.operators.result.displacement(data_sources=ds) norm = dpf.operators.math.norm(displacement) new_operator.inputs.connect(norm) diff --git a/examples/07-python-operators/02-python_operators_with_dependencies.py b/examples/07-python-operators/02-python_operators_with_dependencies.py index 09a2f62df8f..05d6750d257 100644 --- a/examples/07-python-operators/02-python_operators_with_dependencies.py +++ b/examples/07-python-operators/02-python_operators_with_dependencies.py @@ -212,7 +212,7 @@ import os -model = dpf.Model(dpf.upload_file_in_tmp_folder(examples.static_rst)) +model = dpf.Model(dpf.upload_file_in_tmp_folder(examples.find_static_rst())) mesh = model.metadata.meshed_region skin_mesh = dpf.operators.mesh.tri_mesh_skin(mesh=mesh) diff --git a/tests/conftest.py b/tests/conftest.py index 0b81c03328c..07684d78e9d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -66,7 +66,7 @@ def resolve_test_file(basename, additional_path="", is_in_examples=None): """ if local_test_repo is False: if is_in_examples: - return getattr(examples, is_in_examples) + return examples.find_files(getattr(examples, is_in_examples)) else: # otherwise, assume file is local test_path = os.path.join( @@ -237,7 +237,7 @@ def wrapper(*args, **kwargs): if SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_4_0: @pytest.fixture( - scope="session", + scope="package", params=[ ServerConfig(protocol=CommunicationProtocols.gRPC, legacy=True), ServerConfig(protocol=CommunicationProtocols.gRPC, legacy=False), @@ -250,7 +250,7 @@ def server_type(request): return server @pytest.fixture( - scope="session", + scope="package", params=[ ServerConfig(protocol=CommunicationProtocols.gRPC, legacy=True), ServerConfig(protocol=CommunicationProtocols.gRPC, legacy=False), @@ -265,7 +265,7 @@ def server_type_remote_process(request): return server @pytest.fixture( - scope="session", + scope="package", params=[ ServerConfig(protocol=CommunicationProtocols.gRPC, legacy=True), ServerConfig(protocol=CommunicationProtocols.gRPC, legacy=False), @@ -276,7 +276,7 @@ def remote_config_server_type(request): return request.param @pytest.fixture( - scope="session", + scope="package", params=[ServerConfig(protocol=CommunicationProtocols.gRPC, legacy=True)], ids=[ "ansys-grpc-dpf", @@ -287,12 +287,12 @@ def server_type_legacy_grpc(request): else: - @pytest.fixture(scope="session") + @pytest.fixture(scope="package") def server_type(): return core._global_server() @pytest.fixture( - scope="session", + scope="package", params=[ServerConfig(protocol=CommunicationProtocols.gRPC, legacy=True)], ids=[ "ansys-grpc-dpf", @@ -302,7 +302,7 @@ def server_type_remote_process(request): return core._global_server() @pytest.fixture( - scope="session", + scope="package", params=[ServerConfig(protocol=CommunicationProtocols.gRPC, legacy=True)], ids=[ "ansys-grpc-dpf", @@ -311,13 +311,13 @@ def server_type_remote_process(request): def remote_config_server_type(request): return request.param - @pytest.fixture(scope="session") + @pytest.fixture(scope="package") def server_type_legacy_grpc(request): return core._global_server() @pytest.fixture( - scope="session", + scope="package", params=[ServerConfig(protocol=CommunicationProtocols.gRPC, legacy=False)], ids=[ "gRPC CLayer", @@ -325,16 +325,11 @@ def server_type_legacy_grpc(request): ) def server_clayer_remote_process(request): server = core.start_local_server(config=request.param, as_global=False) - if request.param == ServerConfig( - protocol=CommunicationProtocols.gRPC, legacy=False - ): - client = core.settings.get_runtime_client_config(server) - client.cache_enabled = True return server @pytest.fixture( - scope="session", + scope="function", params=[ ServerConfig(protocol=CommunicationProtocols.gRPC, legacy=False), ServerConfig(protocol=None, legacy=False), @@ -343,10 +338,6 @@ def server_clayer_remote_process(request): ) def server_clayer(request): server = core.start_local_server(config=request.param, as_global=False) - if request.param == ServerConfig( - protocol=CommunicationProtocols.gRPC, legacy=False - ): - core.settings.get_runtime_client_config(server).cache_enabled = False return server diff --git a/tests/test_animator.py b/tests/test_animator.py index 1d6bb0a85df..081de7af497 100644 --- a/tests/test_animator.py +++ b/tests/test_animator.py @@ -26,7 +26,7 @@ def remove_gif(): @pytest.fixture() def displacement_fields(): - model = dpf.Model(examples.msup_transient) + model = dpf.Model(examples.find_msup_transient()) mesh_scoping = dpf.mesh_scoping_factory.nodal_scoping( model.metadata.meshed_region.nodes.scoping) # time_scoping = dpf.time_freq_scoping_factory.scoping_on_all_time_freqs(model) @@ -101,7 +101,7 @@ def test_animator_animate_fields_container_deform_by_false(displacement_fields): def test_animator_animate_fields_container_eqv(): - model = dpf.Model(examples.msup_transient) + model = dpf.Model(examples.find_msup_transient()) time_scoping = dpf.time_freq_scoping_factory.scoping_by_sets( list(range(5, 20))) stress_result = model.results.stress.on_time_scoping(time_scoping) @@ -111,7 +111,7 @@ def test_animator_animate_fields_container_eqv(): def test_animator_animate_fields_container_eqv_partial_scoping(): - model = dpf.Model(examples.msup_transient) + model = dpf.Model(examples.find_msup_transient()) time_scoping = dpf.time_freq_scoping_factory.scoping_by_sets( list(range(5, 20))) stress_result = model.results.stress.on_time_scoping(time_scoping) @@ -145,14 +145,14 @@ def test_animator_animate_fields_container_scale_factor_raise(displacement_field def test_animator_animate_fields_container_deform_by_result(): - model = dpf.Model(examples.msup_transient) + model = dpf.Model(examples.find_msup_transient()) displacement_result = model.results.displacement.on_all_time_freqs displacement_fields = displacement_result.eval() displacement_fields.animate(deform_by=displacement_result) def test_animator_animate_fields_container_deform_by_result_raise(): - model = dpf.Model(examples.msup_transient) + model = dpf.Model(examples.find_msup_transient()) displacement_result = model.results.displacement displacement_fields = displacement_result.on_all_time_freqs.eval() with pytest.raises(ValueError) as e: @@ -161,7 +161,7 @@ def test_animator_animate_fields_container_deform_by_result_raise(): def test_animator_animate_fields_container_deform_by_operator(): - model = dpf.Model(examples.msup_transient) + model = dpf.Model(examples.find_msup_transient()) displacement_op = model.results.displacement.on_all_time_freqs() displacement_fields = displacement_op.eval() displacement_fields.animate(deform_by=displacement_op) diff --git a/tests/test_datasources.py b/tests/test_datasources.py index 214a6ccf322..d3b4a44c88d 100644 --- a/tests/test_datasources.py +++ b/tests/test_datasources.py @@ -2,6 +2,7 @@ from ansys import dpf import conftest +import weakref skip_always = pytest.mark.skipif(True, reason="Investigate why this is failing") @@ -76,10 +77,10 @@ def test_several_result_path_data_sources(server_type): @pytest.mark.skipif(not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_3_0, reason='Copying data is supported starting server version 3.0') -def test_delete_auto_data_sources(allkindofcomplexity, server_type): +def test_delete_auto_data_sources(server_type): data_sources = dpf.core.DataSources(server=server_type) - data_sources2 = dpf.core.DataSources(data_sources=data_sources, server=server_type) + ref = weakref.ref(data_sources) data_sources = None import gc gc.collect() - data_sources2.set_result_file_path(allkindofcomplexity) + assert ref() is None diff --git a/tests/test_examples.py b/tests/test_examples.py index 16cecfa9ee7..4f60be2d9dc 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -3,6 +3,7 @@ import pytest +from ansys.dpf import core as dpf from ansys.dpf.core import Model from ansys.dpf.core import examples @@ -32,18 +33,20 @@ def test_download_piston_rod(): assert isinstance(Model(path), Model) +list_examples = [ + "simple_bar", + "static_rst", + "complex_rst", + "multishells_rst", + "electric_therm", + "steady_therm", + "transient_therm", + "msup_transient", +] + + @pytest.mark.parametrize( - "example", - [ - "simple_bar", - "static_rst", - "complex_rst", - "multishells_rst", - "electric_therm", - "steady_therm", - "transient_therm", - "msup_transient", - ], + "example", list_examples, ) def test_examples(example): # get example by string, so we can parameterize it without breaking @@ -52,6 +55,23 @@ def test_examples(example): assert isinstance(Model(path), Model) +@pytest.mark.parametrize( + "example", list_examples, +) +def test_find_examples(example, server_type_remote_process): + # get example by string, so we can parameterize it without breaking + # collection + assert server_type_remote_process.local_server is True + server_type_remote_process.local_server = False + func = getattr(globals()["examples"], "find_" + example) + path = func(server=server_type_remote_process) + assert isinstance(Model(path).metadata.result_info, dpf.ResultInfo) + assert path != getattr(globals()["examples"], example) + server_type_remote_process.local_server = True + path = func(server=server_type_remote_process) + assert path == getattr(globals()["examples"], example) + + def test_delete_downloaded_files(): path = examples.download_multi_stage_cyclic_result() assert os.path.exists(path) diff --git a/tests/test_model.py b/tests/test_model.py index 52931e4afcf..79112db301c 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -20,9 +20,9 @@ @pytest.fixture() def static_model(): try: - path = dpf.core.upload_file_in_tmp_folder(examples.static_rst) + path = dpf.core.upload_file_in_tmp_folder(examples.find_static_rst()) except ServerTypeError: - path = examples.static_rst + path = examples.find_static_rst() return dpf.core.Model(path) @@ -116,7 +116,7 @@ def test_iterate_results_model(allkindofcomplexity): def test_result_not_overrided(plate_msup): - model1 = dpf.core.Model(examples.electric_therm) + model1 = dpf.core.Model(examples.find_electric_therm()) size = len(model1.results) model2 = dpf.core.Model(plate_msup) assert len(model1.results) == size diff --git a/tests/test_server.py b/tests/test_server.py index 33c0cbc9276..0353547c41b 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -132,7 +132,7 @@ def test_shutting_down_when_deleted_legacy(): "from ansys.dpf import core as dpf;" "from ansys.dpf.core import examples;" "dpf.SERVER_CONFIGURATION = dpf.server_factory.AvailableServerConfigs.LegacyGrpcServer;" - "model = dpf.Model(examples.static_rst);" + "model = dpf.Model(examples.find_static_rst());" ]) new_num_dpf_exe = 0 for proc in psutil.process_iter(): @@ -153,7 +153,7 @@ def test_shutting_down_when_deleted(): "from ansys.dpf import core as dpf;" "from ansys.dpf.core import examples;" "dpf.SERVER_CONFIGURATION = dpf.server_factory.AvailableServerConfigs.GrpcServer;" - "model = dpf.Model(examples.static_rst);" + "model = dpf.Model(examples.find_static_rst());" ]) new_num_dpf_exe = 0 for proc in psutil.process_iter(): diff --git a/tests/test_workflow.py b/tests/test_workflow.py index a6064f2be04..c1ceaf031ff 100644 --- a/tests/test_workflow.py +++ b/tests/test_workflow.py @@ -621,7 +621,6 @@ def test_throws_error(allkindofcomplexity): @pytest.mark.xfail(raises=dpf.core.errors.ServerTypeError) @conftest.raises_for_servers_version_under('3.0') def test_flush_workflows_session(allkindofcomplexity): - dpf.core.start_local_server() model = dpf.core.Model(allkindofcomplexity) wf = dpf.core.Workflow() op = model.results.stress() @@ -655,7 +654,6 @@ def test_flush_workflows_session(allkindofcomplexity): @pytest.mark.skipif(platform.system() == "Linux" and platform.python_version().startswith("3.8"), reason="Random SEGFAULT in the GitHub pipeline for 3.8 on Ubuntu") def test_create_on_other_server_workflow(local_server): - dpf.core.start_local_server() disp_op = op.result.displacement() max_fc_op = op.min_max.min_max_fc(disp_op) workflow = dpf.core.Workflow() @@ -673,7 +671,6 @@ def test_create_on_other_server_workflow(local_server): @pytest.mark.skipif(platform.system() == "Linux" and platform.python_version().startswith("3.8"), reason="Random SEGFAULT in the GitHub pipeline for 3.8 on Ubuntu") def test_create_on_other_server2_workflow(local_server): - dpf.core.start_local_server() disp_op = op.result.displacement() max_fc_op = op.min_max.min_max_fc(disp_op) workflow = dpf.core.Workflow() @@ -691,7 +688,6 @@ def test_create_on_other_server2_workflow(local_server): @pytest.mark.skipif(platform.system() == "Linux" and platform.python_version().startswith("3.8"), reason="Random SEGFAULT in the GitHub pipeline for 3.8 on Ubuntu") def test_create_on_other_server_with_ip_workflow(local_server): - dpf.core.start_local_server() disp_op = op.result.displacement() max_fc_op = op.min_max.min_max_fc(disp_op) workflow = dpf.core.Workflow() @@ -711,7 +707,6 @@ def test_create_on_other_server_with_ip_workflow(local_server): @pytest.mark.skipif(platform.system() == "Linux" and platform.python_version().startswith("3.8"), reason="Random SEGFAULT in the GitHub pipeline for 3.8 on Ubuntu") def test_create_on_other_server_with_address_workflow(local_server): - dpf.core.start_local_server() disp_op = op.result.displacement() max_fc_op = op.min_max.min_max_fc(disp_op) workflow = dpf.core.Workflow() @@ -728,7 +723,6 @@ def test_create_on_other_server_with_address_workflow(local_server): @pytest.mark.xfail(raises=dpf.core.errors.ServerTypeError) @conftest.raises_for_servers_version_under('3.0') def test_create_on_other_server_with_address2_workflow(local_server): - dpf.core.start_local_server() disp_op = op.result.displacement() max_fc_op = op.min_max.min_max_fc(disp_op) workflow = dpf.core.Workflow() @@ -748,7 +742,6 @@ def test_create_on_other_server_with_address2_workflow(local_server): @conftest.raises_for_servers_version_under('3.0') def test_create_on_other_server_and_connect_workflow( allkindofcomplexity, local_server): - dpf.core.start_local_server() disp_op = op.result.displacement() max_fc_op = op.min_max.min_max_fc(disp_op) workflow = dpf.core.Workflow()