Skip to content

Commit 9f9d2aa

Browse files
authored
Add basic example files to module (#20)
* add additional examples * update model test * add plot contour testing * patch component count * move cache * fix temp file creation and deletion * add ignored word due to entrie(s) * add docker directory mapping for downloads cache * add docstring for example downloads * fix paths in examples * add typehint * patch single component plotting
1 parent 1f4cfa6 commit 9f9d2aa

22 files changed

+173
-35
lines changed

.ci/azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jobs:
128128
set -ex
129129
echo $(PAT) | docker login -u $(GH_USERNAME) --password-stdin docker.pkg.github.com
130130
docker pull $(DPF_IMAGE)
131-
docker run --restart always --name dpf -v `pwd`:/dpf -p $(DPF_PORT):50054 $(DPF_IMAGE) > log.txt &
131+
docker run --restart always --name dpf -v `pwd`:/dpf -v /tmp:/dpf/_cache -p $(DPF_PORT):50054 $(DPF_IMAGE) > log.txt &
132132
grep -q 'server started on ip' <(timeout 60 tail -f log.txt)
133133
python -c "from ansys.dpf import core; core.connect_to_server(port=$(DPF_PORT)); print('Python Connected')"
134134
displayName: Pull, launch, and validate DPF service

.github/workflows/ci-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- name: Pull, launch, and validate DPF service
4545
run: |
4646
echo $PAT | docker login -u $GH_USERNAME --password-stdin docker.pkg.github.com
47-
docker run --restart always --name dpf -v `pwd`:/dpf -p $DPF_PORT:50054 $DPF_IMAGE > log.txt &
47+
docker run --restart always --name dpf -v `pwd`:/dpf -v /tmp:/dpf/_cache -p $DPF_PORT:50054 $DPF_IMAGE > log.txt &
4848
grep -q 'server started on ip' <(timeout 60 tail -f log.txt)
4949
python -c "import os; from ansys.dpf import core; core.connect_to_server(port=os.environ['DPF_PORT']); print('Python Connected')"
5050
env:

ansys/dpf/core/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@
4040
if os.environ.get('DPF_DOCKER', False): # pragma: no cover
4141
# Running DPF within docker (likely for CI)
4242
# path must be relative to DPF directory
43-
_module_path = os.path.dirname(inspect.getfile(inspect.currentframe()))
44-
EXAMPLES_PATH = os.path.join(_module_path, 'examples', '_cache')
45-
if not os.path.isdir(EXAMPLES_PATH):
46-
os.makedirs(EXAMPLES_PATH)
47-
43+
#
44+
# assumes the following docker mount:
45+
# -v /tmp:/dpf/_cache
46+
EXAMPLES_PATH = '/tmp'
4847
else:
4948
try:
5049
import appdirs

ansys/dpf/core/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Version for ansys-dpf-core"""
22
# major, minor, patch
3-
version_info = 0, 1, 2
3+
version_info = 0, 2, 0
44

55
# Nice string for the version
66
__version__ = '.'.join(map(str, version_info))

ansys/dpf/core/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def __getitem__(self, index):
210210
if not self_len:
211211
raise IndexError('This collection contains no items')
212212
if index >= self_len:
213-
raise IndexError(f'This collection contains only {self_len} entries')
213+
raise IndexError(f'This collection contains only {self_len} entrie(s)')
214214

215215
return self._get_entries(index)
216216

File renamed without changes.

ansys/dpf/core/examples/downloads.py

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _retrieve_file(url, filename, directory):
2323
local_path = os.path.join(EXAMPLES_PATH, directory, os.path.basename(filename))
2424
local_path_no_zip = local_path.replace('.zip', '')
2525
if os.path.isfile(local_path_no_zip) or os.path.isdir(local_path_no_zip):
26-
return local_path_no_zip, None
26+
return local_path_no_zip
2727

2828
# grab the correct url retriever
2929
urlretrieve = urllib.request.urlretrieve
@@ -44,13 +44,84 @@ def _download_file(directory, filename):
4444
if os.environ.get('DPF_DOCKER', False): # pragma: no cover
4545
# override path if running on docker as path must be relative
4646
# to docker mount
47-
local_path = os.path.join('/dpf/ansys/dpf/core/examples/_cache/', directory,
48-
filename)
47+
#
48+
# Assumes the following mapping in docker
49+
# DWN_CSH=/tmp/dpf_cache
50+
# -v $DWN_CSH:/dpf/_cache
51+
local_path = os.path.join('/dpf/_cache', directory, filename)
4952
return local_path
5053

5154
###############################################################################
5255
# front-facing downloads
5356

54-
def download_transient_result():
55-
"""Download an example transient result and return the download path"""
57+
def download_transient_result() -> str:
58+
"""Download an example transient result file and return the download path.
59+
60+
Examples files are downloaded to a persistent cache to avoid
61+
re-downloading the same file twice.
62+
63+
Returns
64+
-------
65+
str
66+
Path to the example file.
67+
68+
Examples
69+
--------
70+
Download an example result file and return the path of the file
71+
72+
>>> from ansys.dpf.core import examples
73+
>>> path = examples.transient_result
74+
>>> path
75+
'C:/Users/user/AppData/local/temp/transient.rst'
76+
77+
"""
5678
return _download_file('transient', 'transient.rst')
79+
80+
81+
def download_all_kinds_of_complexity() -> str:
82+
"""Download an example static result and return the download path.
83+
84+
Examples files are downloaded to a persistent cache to avoid
85+
re-downloading the same file twice.
86+
87+
Returns
88+
-------
89+
str
90+
Path to the example file.
91+
92+
Examples
93+
--------
94+
Download an example result file and return the path of the file
95+
96+
>>> from ansys.dpf.core import examples
97+
>>> path = examples.download_all_kinds_of_complexity
98+
>>> path
99+
'C:/Users/user/AppData/local/temp/allKindOfComplexity.rst'
100+
101+
"""
102+
return _download_file('testing', 'allKindOfComplexity.rst')
103+
104+
105+
def download_all_kinds_of_complexity_modal() -> str:
106+
"""Download an example result file from a static modal analsys and
107+
return the download path.
108+
109+
Examples files are downloaded to a persistent cache to avoid
110+
re-downloading the same file twice.
111+
112+
Returns
113+
-------
114+
str
115+
Path to the example file.
116+
117+
Examples
118+
--------
119+
Download an example result file and return the path of the file
120+
121+
>>> from ansys.dpf.core import examples
122+
>>> path = examples.download_all_kinds_of_complexity_modal
123+
>>> path
124+
'C:/Users/user/AppData/local/temp/modal_allKindOfComplexity.rst'
125+
126+
"""
127+
return _download_file('testing', 'modal_allKindOfComplexity.rst')

ansys/dpf/core/examples/examples.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@
1111
# this files can be imported with from `ansys.dpf.core import examples`:
1212
simple_bar = os.path.join(_module_path, 'ASimpleBar.rst')
1313
static_rst = os.path.join(_module_path, 'static.rst')
14+
complex_rst = os.path.join(_module_path, 'complex.rst')
15+
multishells_rst = os.path.join(_module_path, 'model_with_ns.rst')
16+
electric_therm = os.path.join(_module_path, 'rth', 'rth_electric.rth')
17+
steady_therm = os.path.join(_module_path, 'rth', 'rth_steady.rth')
18+
transient_therm = os.path.join(_module_path, 'rth', 'rth_transient.rth')
19+
msup_transient = os.path.join(_module_path, 'msup_transient_plate1.rst')
3.06 MB
Binary file not shown.

0 commit comments

Comments
 (0)