Skip to content

Commit b830987

Browse files
authored
Finalize user guide with plotting (#28)
1 parent 4746ede commit b830987

File tree

19 files changed

+452
-52
lines changed

19 files changed

+452
-52
lines changed

.github/workflows/ci-build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ jobs:
3333
3434
- name: Install ansys.dpf.core
3535
run: |
36-
pip install ansys.grpc.dpf --extra-index-url https://[email protected]/pyansys/_packaging/pyansys/pypi/simple/
3736
pip install -r requirements_build.txt
3837
pip install -e .
3938
cd tests
@@ -53,7 +52,7 @@ jobs:
5352

5453
- name: Build Documentation
5554
run: |
56-
sudo apt install pandoc -qy
55+
sudo apt-get install pandoc -qy
5756
pip install -r requirements_docs.txt
5857
make -C docs html
5958
touch docs/build/html/.nojekyll

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
/__pycache__
2-
/.pytest_cache
3-
/.spyproject
1+
# cache and pyc
2+
__pycache__
3+
.pytest_cache
4+
.spyproject
45

56
#tests
67
__pycache__

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, 2, 0
3+
version_info = 0, 2, 1
44

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

ansys/dpf/core/dpf_operator.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,23 @@ def connect(self, pin, inpt, pin_out=0):
103103
104104
pin_out : int, optional
105105
In case of the input is an Operator, this is the output
106-
pin of the input Operator. Defaults to 0
106+
pin of the input Operator. Defaults to 0.
107+
108+
Examples
109+
--------
110+
Compute the minimum of displacement by chaining the ``'U'``
111+
and ``'min_max_fc'`` operators.
112+
113+
>>> from ansys.dpf.core import examples
114+
>>> data_src = dpf.DataSources(examples.multishells_rst)
115+
>>> print(data_src)
116+
>>> disp_op = dpf.Operator('U')
117+
>>> disp_op.inputs.data_sources(data_src)
118+
>>> max_fc_op = dpf.Operator('min_max_fc')
119+
>>> max_fc_op.inputs.connect(disp_op.outputs)
120+
>>> max_field = max_fc_op.outputs.field_max()
121+
>>> max_field.data
122+
array([[0.59428386, 0.00201751, 0.0006032 ]])
107123
"""
108124
request = operator_pb2.UpdateRequest()
109125
request.op.CopyFrom(self._message)

ansys/dpf/core/errors.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
"""
1313

1414

15+
class LocationError(ValueError):
16+
"""Raised when using an invalid location"""
17+
18+
def __init__(self, msg='Invalid location'):
19+
ValueError.__init__(self, msg)
20+
21+
1522
class ComplexPlottingError(ValueError):
1623
"""Raised when attempting to plot a field with complex data"""
1724

ansys/dpf/core/examples/downloads.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def _download_file(directory, filename):
5252
return local_path
5353

5454
###############################################################################
55-
# front-facing downloads
55+
# front-facing functions
5656

5757
def download_transient_result() -> str:
5858
"""Download an example transient result file and return the download path.
@@ -103,7 +103,7 @@ def download_all_kinds_of_complexity() -> str:
103103

104104

105105
def download_all_kinds_of_complexity_modal() -> str:
106-
"""Download an example result file from a static modal analsys and
106+
"""Download an example result file from a static modal analysis and
107107
return the download path.
108108
109109
Examples files are downloaded to a persistent cache to avoid
@@ -125,3 +125,28 @@ def download_all_kinds_of_complexity_modal() -> str:
125125
126126
"""
127127
return _download_file('testing', 'modal_allKindOfComplexity.rst')
128+
129+
130+
def download_pontoon() -> str:
131+
"""Download an example result file from a static modal analsys and
132+
return the download path.
133+
134+
Examples files are downloaded to a persistent cache to avoid
135+
re-downloading the same file twice.
136+
137+
Returns
138+
-------
139+
str
140+
Path to the example file.
141+
142+
Examples
143+
--------
144+
Download an example result file and return the path of the file
145+
146+
>>> from ansys.dpf.core import examples
147+
>>> path = examples.download_all_kinds_of_complexity_modal
148+
>>> path
149+
'C:/Users/user/AppData/local/temp/modal_allKindOfComplexity.rst'
150+
151+
"""
152+
return _download_file('docs', 'pontoon.rst')

ansys/dpf/core/field.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ansys.dpf.core.common import natures, types, locations, ShellLayers
99
from ansys.dpf.core import operators_helper, scoping, meshed_region, time_freq_support
1010
from ansys.dpf.core.plotter import Plotter
11+
from ansys.dpf.core import errors
1112

1213

1314
class Field:
@@ -92,9 +93,6 @@ def __init__(self, nentities=0, nature=natures.vector,
9293

9394
self._field_definition = self._load_field_definition()
9495

95-
# add dynamic methods
96-
self._update_dynamic_methods()
97-
9896
@property
9997
def size(self):
10098
"""Number of elements times the number of components"""
@@ -123,12 +121,6 @@ def elementary_data_shape(self):
123121
else:
124122
return self.component_count
125123

126-
def _update_dynamic_methods(self):
127-
"""Add or remove dynamic methods to this instance based on the
128-
field type"""
129-
if self.location in [locations.elemental_nodal, locations.elemental]:
130-
self.to_nodal = self.__to_nodal
131-
132124
@property
133125
def location(self):
134126
"""Return the field location.
@@ -161,8 +153,20 @@ def shell_layers(self):
161153
if self._field_definition:
162154
return self._field_definition.shell_layers
163155

164-
def __to_nodal(self):
165-
"""create a to_nodal operator and evaluates it"""
156+
def to_nodal(self):
157+
"""Convert this field to one with a Nodal location.
158+
159+
Only valid when this field's location is ElementalNodal or
160+
Elemental.
161+
162+
Returns
163+
-------
164+
Field
165+
Field with ``location=='Nodal'``.
166+
"""
167+
if self.location == 'Nodal':
168+
raise errors.LocationError('Location is already "Nodal"')
169+
166170
op = dpf.core.Operator("to_nodal")
167171
op.inputs.connect(self)
168172
return op.outputs.field()

ansys/dpf/core/plotter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ def plot_contour(self, field_or_fields_container, notebook=None,
195195
overall_data[ind] = field.data[mask]
196196

197197
# create the plotter and add the meshes
198+
background = kwargs.pop('background', None)
198199
plotter = pv.Plotter(notebook=notebook, off_screen=off_screen)
199200

200201
# add meshes
@@ -203,6 +204,9 @@ def plot_contour(self, field_or_fields_container, notebook=None,
203204
kwargs.setdefault('stitle', name)
204205
plotter.add_mesh(mesh.grid, scalars=overall_data, **kwargs)
205206

207+
if background is not None:
208+
plotter.set_background(background)
209+
206210
# show result
207211
if show_axes:
208212
plotter.add_axes()

docs/source/api/field.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _ref_api_field:
2+
13
***********
24
Field Class
35
***********

docs/source/api/fieldscontainer.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.. _ref_api_fields_container:
2+
3+
14
*********************
25
FieldsContainer Class
36
*********************

0 commit comments

Comments
 (0)