Skip to content

Commit

Permalink
Improve function name
Browse files Browse the repository at this point in the history
Also support windows remote servers
Don't rely on dpf mat ids in tests
  • Loading branch information
janvonrickenbach committed Jan 8, 2024
1 parent 390d496 commit 3121622
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/ansys/dpf/composites/example_helper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
ContinuousFiberCompositesFiles,
ShortFiberCompositesFiles,
)
from ..server_helpers import upload_file_to_unique_folder
from ..server_helpers import upload_file_to_unique_tmp_folder

EXAMPLE_REPO = "https://github.com/ansys/example-data/raw/master/pydpf-composites/"

Expand Down Expand Up @@ -146,7 +146,7 @@ def _download_and_upload_file(
urllib.request.urlretrieve(file_url, local_path)
if server.local_server:
return local_path
return upload_file_to_unique_folder(local_path, server=server)
return upload_file_to_unique_tmp_folder(local_path, server=server)


def get_short_fiber_example_files(
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/dpf/composites/server_helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ._load_plugin import load_composites_plugin
from ._upload_files_to_server import (
upload_continuous_fiber_composite_files_to_server,
upload_file_to_unique_folder,
upload_file_to_unique_tmp_folder,
upload_short_fiber_composite_files_to_server,
)
from ._versions import version_equal_or_later, version_older_than
Expand All @@ -17,7 +17,7 @@
"load_composites_plugin",
"connect_to_or_start_server",
"upload_short_fiber_composite_files_to_server",
"upload_file_to_unique_folder",
"upload_file_to_unique_tmp_folder",
"upload_continuous_fiber_composite_files_to_server",
"version_older_than",
"version_equal_or_later",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
)


def upload_file_to_unique_folder(path_on_client: _PATH, server: BaseServer) -> str:
"""Upload file to a unique folder on the server.
def upload_file_to_unique_tmp_folder(path_on_client: _PATH, server: BaseServer) -> str:
"""Upload file to a unique temporary folder on the server.
Parameters
----------
Expand All @@ -27,8 +27,11 @@ def upload_file_to_unique_folder(path_on_client: _PATH, server: BaseServer) -> s
dpf.make_tmp_dir_server()
) # Returns the dpf tmp folder (only one per server)
path_on_client = pathlib.Path(path_on_client)
tmp_dir_unique = tmp_dir / str(uuid.uuid4())
path_on_server = (tmp_dir_unique / path_on_client.name).as_posix()
if server.os == "posix":
path_on_server = str(tmp_dir) + "/" + str(uuid.uuid4()) + "/" + path_on_client.name
else:
path_on_server = str(tmp_dir) + "\\" + str(uuid.uuid4()) + "\\" + path_on_client.name

uploaded_path = cast(str, dpf.upload_file(path_on_client, path_on_server, server=server))
if uploaded_path == "":
raise RuntimeError(
Expand All @@ -54,7 +57,7 @@ def upload_short_fiber_composite_files_to_server(
return data_files

def upload(filename: _PATH) -> str:
return upload_file_to_unique_folder(filename, server=server)
return upload_file_to_unique_tmp_folder(filename, server=server)

return ShortFiberCompositesFiles(
rst=[upload(filename) for filename in data_files.rst],
Expand Down Expand Up @@ -82,7 +85,7 @@ def upload_continuous_fiber_composite_files_to_server(
return data_files

def upload(filename: _PATH) -> _PATH:
return upload_file_to_unique_folder(filename, server=server)
return upload_file_to_unique_tmp_folder(filename, server=server)

all_composite_files = {}
for key, composite_files_by_scope in data_files.composite.items():
Expand Down
10 changes: 6 additions & 4 deletions tests/basic_workflow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ansys.dpf.core as dpf
import pytest

from ansys.dpf.composites.server_helpers import upload_file_to_unique_folder
from ansys.dpf.composites.server_helpers import upload_file_to_unique_tmp_folder

from .utils import get_basic_combined_failure_criterion

Expand All @@ -22,10 +22,12 @@ def test_basic_workflow(dpf_server, distributed_rst):
material_path = os.path.join(TEST_DATA_ROOT_DIR, "material.engd")

if not dpf_server.local_server:
rst_paths = [upload_file_to_unique_folder(path, server=dpf_server) for path in rst_paths]
rst_paths = [
upload_file_to_unique_tmp_folder(path, server=dpf_server) for path in rst_paths
]

h5_path = upload_file_to_unique_folder(h5_path, server=dpf_server)
material_path = upload_file_to_unique_folder(material_path, server=dpf_server)
h5_path = upload_file_to_unique_tmp_folder(h5_path, server=dpf_server)
material_path = upload_file_to_unique_tmp_folder(material_path, server=dpf_server)

eng_data_path = material_path
composite_definitions_path = h5_path
Expand Down
6 changes: 3 additions & 3 deletions tests/element_info_output_all_element_types_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
get_selected_indices,
get_selected_indices_by_dpf_material_ids,
)
from ansys.dpf.composites.server_helpers import upload_file_to_unique_folder
from ansys.dpf.composites.server_helpers import upload_file_to_unique_tmp_folder


@dataclass(frozen=True)
Expand Down Expand Up @@ -113,7 +113,7 @@ def get_expected_output(
def check_output(rst_file, expected_output):
rst_path = TEST_DATA_ROOT_DIR / "all_element_types" / rst_file
if not dpf_server.local_server:
rst_path = upload_file_to_unique_folder(rst_path, server=dpf_server)
rst_path = upload_file_to_unique_tmp_folder(rst_path, server=dpf_server)

rst_data_source = dpf.DataSources(rst_path)

Expand Down Expand Up @@ -190,7 +190,7 @@ def get_layup_info_for_rst(rst_file):
rst_path = TEST_DATA_ROOT_DIR / "all_element_types" / rst_file

if not dpf_server.local_server:
rst_path = upload_file_to_unique_folder(rst_path, server=dpf_server)
rst_path = upload_file_to_unique_tmp_folder(rst_path, server=dpf_server)

rst_data_source = dpf.DataSources(rst_path)

Expand Down
11 changes: 8 additions & 3 deletions tests/element_info_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,20 @@ def test_section_definitions_from_multiple_sources(dpf_server):
files, server=dpf_server, default_unit_system=unit_systems.solver_nmm
)

ud_mat_id = composite_model.material_names["Epoxy Carbon UD (230 GPa) Wet"]
woven_mat_id = composite_model.material_names["Epoxy Carbon Woven (230 GPa) Prepreg"]
element_1 = composite_model.get_element_info(1)
assert element_1.is_layered
assert all(element_1.dpf_material_ids == np.array([2, 2, 1, 1, 2, 2]))
assert all(
element_1.dpf_material_ids
== np.array([ud_mat_id, ud_mat_id, woven_mat_id, woven_mat_id, ud_mat_id, ud_mat_id])
)
element_2 = composite_model.get_element_info(2)
assert element_2.is_layered
assert all(element_2.dpf_material_ids == np.array([1, 2, 1]))
assert all(element_2.dpf_material_ids == np.array([woven_mat_id, ud_mat_id, woven_mat_id]))
element_3 = composite_model.get_element_info(3)
assert element_3.is_layered
assert all(element_3.dpf_material_ids == np.array([2]))
assert all(element_3.dpf_material_ids == np.array([ud_mat_id]))

combined_failure_criterion = CombinedFailureCriterion(
"max stress", failure_criteria=[MaxStressCriterion()]
Expand Down

0 comments on commit 3121622

Please sign in to comment.