Skip to content

Commit 4ecf526

Browse files
authored
DPF in build docs CICD (#1449)
* Implementation in unit tests * Missing run * Fixing TTY error * Removing it flag * Update .github/workflows/ci.yml * Update .github/workflows/ci.yml * Detaching. * Adding the requirements to tests * Asserting conneciton is live, and specifing port. * Adding comment * Updating requirements * Implementing DPF in docs CICD. * Removing duplicated function in MAPDL and MAPDL_GRPC * fixing result type return * Adding simple example * Undoin the post1 env. * Using temp directory for the example. * Removing file deletion * Adding default ext value * standarization * Removing duplicate method. * Going to post1 to get RST file. * Updating unit tests * Avoid coverage issues * Atempting to fix upload rst file to docker * Using private image * Adding dpf to doc mapping * Adding references to dpf objects * Improving text
1 parent d1b0bb1 commit 4ecf526

File tree

5 files changed

+171
-4
lines changed

5 files changed

+171
-4
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ concurrency:
3333
group: ${{ github.workflow }}-${{ github.ref }}
3434
cancel-in-progress: true
3535

36+
permissions:
37+
packages: read
38+
39+
3640
jobs:
3741

3842
stylecheck:
@@ -159,7 +163,7 @@ jobs:
159163
xvfb-run python -c "from ansys.mapdl import core as pymapdl; print(pymapdl.Report())"
160164
161165
- name: Login in Github Container registry
162-
uses: docker/login-action@v2
166+
uses: docker/login-action@v2.1.0
163167
with:
164168
registry: ghcr.io
165169
username: ${{ secrets.GH_USERNAME }}
@@ -205,6 +209,11 @@ jobs:
205209
run: |
206210
pip install -r requirements/requirements_docs.txt
207211
212+
- name: DPF Server Activation
213+
run: |
214+
docker pull ghcr.io/pyansys/dpf-core:22.2dev
215+
docker run -d --name dpfserver -v `pwd`:/dpf -p ${{ env.DPF_PORT }}:50052 ghcr.io/pyansys/dpf-core:22.2dev && echo "DPF Server active on port ${{ env.DPF_PORT }}."
216+
208217
- name: Build Documentation
209218
run: |
210219
xvfb-run make -C doc html SPHINXOPTS="-j auto -W --keep-going"
@@ -332,7 +341,7 @@ jobs:
332341
xvfb-run python -c "from ansys.mapdl import core as pymapdl; print(pymapdl.Report())"
333342
334343
- name: Login in Github Container registry
335-
uses: docker/login-action@v2
344+
uses: docker/login-action@v2.1.0
336345
with:
337346
registry: ghcr.io
338347
username: ${{ secrets.GH_USERNAME }}
@@ -350,7 +359,8 @@ jobs:
350359
351360
- name: DPF Server Activation
352361
run: |
353-
docker run -d -v `pwd`:/dpf -p ${{ env.DPF_PORT }}:50054 ghcr.io/pyansys/dpf-core/dpf:v2021.1
362+
docker pull ghcr.io/pyansys/dpf-core:22.2dev
363+
docker run -d --name dpfserver -v `pwd`:/dpf -p ${{ env.DPF_PORT }}:50052 ghcr.io/pyansys/dpf-core:22.2dev && echo "DPF Server active on port ${{ env.DPF_PORT }}."
354364
355365
- name: Unit Testing
356366
run: |

doc/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"pyvista": ("https://docs.pyvista.org/", None),
7575
"grpc": ("https://grpc.github.io/grpc/python/", None),
7676
"pypim": ("https://pypim.docs.pyansys.com/", None),
77+
"dpf-core": ("https://dpf.docs.pyansys.com/", None),
7778
}
7879

7980
suppress_warnings = ["label.*"]
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
"""
2+
.. _ref_dpf_basic_example:
3+
4+
Basic DPF-Core Usage with PyMAPDL
5+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
7+
This example is adapted from
8+
`Basic DPF-Core Usage Example <https://dpf.docs.pyansys.com/examples/00-basic/00-basic_example.html>`_
9+
and it shows how to open a result file in `DPF <https://dpf.docs.pyansys.com/>`_ and do some
10+
basic postprocessing.
11+
12+
If you have Ansys 2021 R1 installed, starting DPF is quite easy
13+
as DPF-Core takes care of launching all the services that
14+
are required for postprocessing Ansys files.
15+
16+
First, import the DPF-Core module as ``dpf_core`` and import the
17+
included examples file.
18+
19+
20+
"""
21+
import tempfile
22+
23+
from ansys.dpf import core as dpf
24+
25+
from ansys.mapdl.core import launch_mapdl
26+
from ansys.mapdl.core.examples import vmfiles
27+
28+
###############################################################################
29+
# ## Model creation
30+
# Running a verification manual example in MAPDL
31+
#
32+
mapdl = launch_mapdl()
33+
34+
vm5 = vmfiles["vm5"]
35+
output = mapdl.input(vm5)
36+
37+
print(output)
38+
39+
# If you are working locally, you don't need to perform the following steps
40+
temp_directory = tempfile.gettempdir()
41+
# Downloading RST file to the current folder
42+
rst_path = mapdl.download_result(temp_directory)
43+
44+
###############################################################################
45+
# Next, open the generated RST file and print out the
46+
# :class:`Model <ansys.dpf.core.model.Model>` object.
47+
# The :class:`Model <ansys.dpf.core.model.Model>` class helps to
48+
# organize access methods for the result by
49+
# keeping track of the operators and data sources used by the result
50+
# file.
51+
#
52+
# Printing the model displays:
53+
#
54+
# - Analysis type
55+
# - Available results
56+
# - Size of the mesh
57+
# - Number of results
58+
#
59+
# Also, note that the first time you create a DPF object, Python
60+
# automatically attempts to start the server in the background. If you
61+
# want to connect to an existing server (either local or remote), use
62+
# :func:`dpf.connect_to_server <ansys.dpf.core.server.connect_to_server>`.
63+
# In this case, DPF will attempt to connect to a local server at the port 50052
64+
# unless another port is specified.
65+
66+
dpf.connect_to_server()
67+
68+
69+
###############################################################################
70+
# If you are working with a remote server, you might need to upload the ``RST``
71+
# file before working with it.
72+
server_file_path = dpf.upload_file_in_tmp_folder(rst_path)
73+
74+
75+
###############################################################################
76+
# Then you can create the :class:`DPF Model <ansys.dpf.core.model.Model>`.
77+
#
78+
79+
model = dpf.Model(server_file_path)
80+
print(model)
81+
82+
###############################################################################
83+
# Model Metadata
84+
# ~~~~~~~~~~~~~~
85+
# Specific metadata can be extracted from the model by referencing the
86+
# model's :attr:`metadata <ansys.dpf.core.model.Model.metadata>`
87+
# property. For example, to print only the
88+
# :attr:`result_info <ansys.dpf.core.model.Metadata.result_info>`:
89+
90+
metadata = model.metadata
91+
print(metadata.result_info)
92+
93+
###############################################################################
94+
# To print the :class:`mesh region<ansys.dpf.core.meshed_region.MeshedRegion>`:
95+
96+
print(metadata.meshed_region)
97+
98+
###############################################################################
99+
# To print the time or frequency of the results use
100+
# :class:`time_freq_support <ansys.dpf.core.time_freq_support.TimeFreqSupport>`:
101+
102+
print(metadata.time_freq_support)
103+
104+
###############################################################################
105+
# Extracting Displacement Results
106+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107+
# All results of the model can be accessed through the :class:`Results <ansys.dpf.core.results.Results>`
108+
# property, which returns the :class:`ansys.dpf.core.results.Results`
109+
# class. This class contains the DPF result operators available to a
110+
# specific result file, which are listed when printing the object with
111+
# ``print(results)``.
112+
#
113+
# Here, the :class:`displacement <ansys.dpf.core.operators.result.displacement.displacement>`
114+
# operator is connected with
115+
# :class:`DataSources <ansys.dpf.core.data_sources.DataSources>`, which
116+
# takes place automatically when running
117+
# :class:`results.displacement() <ansys.dpf.core.operators.result.displacement.displacement>`.
118+
# By default, the :class:`displacement <ansys.dpf.core.operators.result.displacement.displacement>`
119+
# operator is connected to the first result set,
120+
# which for this static result is the only result.
121+
122+
results = model.results
123+
displacements = results.displacement()
124+
fields = displacements.outputs.fields_container()
125+
126+
# Finally, extract the data of the displacement field:
127+
disp = fields[0].data
128+
disp
129+
130+
###############################################################################
131+
# Plot displacements
132+
# ~~~~~~~~~~~~~~~~~~
133+
#
134+
# You can plot the previous displacement field using:
135+
136+
model.metadata.meshed_region.plot(fields, cpos="xy")
137+
138+
###############################################################################
139+
# Or using
140+
#
141+
142+
fields[0].plot(cpos="xy")
143+
144+
###############################################################################
145+
# This way is particularly useful if you have used :class:`ansys.dpf.core.scoping.Scoping`
146+
# on the mesh or results.
147+
148+
149+
###############################################################################
150+
# Clean up
151+
# ~~~~~~~~
152+
#
153+
# Stop MAPDL session.
154+
#
155+
mapdl.exit()

requirements/requirements_docs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Sphinx==5.3.0
2+
ansys-dpf-core==0.6.0
23
ansys-mapdl-reader==0.52.3
34
ansys-sphinx-theme==0.6.1
45
grpcio==1.43.0

requirements/requirements_tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
ansys-dpf-core==0.6.0
12
autopep8==1.7.0
23
matplotlib==3.6.1
34
scipy==1.9.3
@@ -8,4 +9,3 @@ pyvista==0.36.1
89
pyansys-tools-report==0.3.2
910
vtk==9.0.3
1011
pytest-rerunfailures==10.2
11-
ansys-dpf-core==0.6.0

0 commit comments

Comments
 (0)