Skip to content

Commit e439e2f

Browse files
authored
Refactor and update the examples to clarify Entry and Premium capabilities (#674)
* New "file-IO" and "mesh_operations" sections * Move examples in other sections * Create a skin_extraction example * Separate skin_extraction and use_local_data * Make basic-plotting entry * Refactor sections * Reformat descriptions * Reformat description and apply premium for the end of the example * Fix ref to _user_guide_server_context in Note for Premium examples * Fix folder name in run_non_regression_examples.py * Fix link to Server context doc section
1 parent ff13c20 commit e439e2f

File tree

55 files changed

+229
-91
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+229
-91
lines changed

.ci/run_non_regression_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
list_tests = [
1616
os.path.join(actual_path, os.path.pardir, "examples", "00-basic"),
17-
os.path.join(actual_path, os.path.pardir, "examples", "01-static-transient"),
17+
os.path.join(actual_path, os.path.pardir, "examples", "01-transient_analyses"),
1818
os.path.join(actual_path, os.path.pardir, "examples", "02-modal-harmonic"),
1919
os.path.join(actual_path, os.path.pardir, "examples", "05-plotting", "00-basic_plotting.py"),
2020
os.path.join(actual_path, os.path.pardir, "examples", "05-plotting",

examples/00-basic/00-basic_example.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44
55
Basic DPF-Core usage
66
~~~~~~~~~~~~~~~~~~~~
7+
78
This example shows how to open a result file and do some
89
basic postprocessing.
910
1011
If you have Ansys 2021 R1 or higher installed, starting DPF is quite easy
1112
as DPF-Core takes care of launching all the services that
1213
are required for postprocessing Ansys files.
1314
14-
First, import the DPF-Core module as ``dpf`` and import the
15-
included examples file.
16-
17-
1815
"""
1916

17+
# First, import the DPF-Core module as ``dpf`` and import the included examples file.
2018
from ansys.dpf import core as dpf
2119
from ansys.dpf.core import examples
2220

examples/00-basic/01-basic_operators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
This example demonstrates how to work directly with operators and
1616
compares this method to a wrapped approach.
1717
18-
Import the necessary modules:
1918
"""
2019

20+
# Import the necessary modules
2121
from ansys.dpf import core as dpf
2222
from ansys.dpf.core import examples
2323

examples/00-basic/02-basic_field_containers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
Field and field containers overview
66
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
78
In DPF, the field is the main simulation data container. During a numerical
89
simulation, the result data is defined by values associated to entities
910
(scoping). These entities are a subset of a model (support).
@@ -29,9 +30,9 @@
2930
container have each individual field operated on. Fields
3031
containers are outputs from operators.
3132
32-
First, import necessary modules:
33-
3433
"""
34+
35+
# First, import necessary modules
3536
import numpy as np
3637

3738
from ansys.dpf import core as dpf

examples/00-basic/03-create_entities.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
55
Create your own entities using DPF operators
66
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
78
You can create your field, fields container, or meshed region to use DPF operators
89
with your own data. The ability to use scripting to create any DPF entity means
910
that you are not dependent on result files and can connect the DPF environment
1011
with any Python tool.
1112
12-
Import necessary modules:
1313
"""
14+
15+
# Import necessary modules
1416
import numpy as np
1517

1618
from ansys.dpf import core as dpf

examples/00-basic/05-use_local_data.py

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,37 @@
33
44
Bring a field's data locally to improve performance
55
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
67
Reducing the number of calls to the server is key to improving
78
performance. Using the ``as_local_field`` option brings the data
89
from the server to your local machine where you can work on it.
910
When finished, you send the updated data back to the server
1011
in one transaction.
1112
12-
.. note::
13-
This example requires the Premium ServerContext.
14-
For more information, see :ref:`_ref_getting_started_contexts`.
15-
1613
"""
14+
1715
# Import necessary modules
1816
from ansys.dpf import core as dpf
1917
from ansys.dpf.core import examples
2018
from ansys.dpf.core import operators as ops
2119

2220

23-
dpf.set_default_server_context(dpf.AvailableServerContexts.premium)
24-
2521
###############################################################################
2622
# Create a model object to establish a connection with an
2723
# example result file and then extract:
2824
model = dpf.Model(examples.download_multi_stage_cyclic_result())
2925
print(model)
26+
mesh = model.metadata.meshed_region
3027

3128
###############################################################################
3229
# Create the workflow
3330
# ~~~~~~~~~~~~~~~~~~~~
34-
# Maximum principal stress usually occurs on the skin of the
35-
# model. Computing results only on this skin reduces the data size.
36-
37-
# Create a simple workflow computing the principal stress on the skin
38-
# of the model.
39-
40-
skin_op = ops.mesh.external_layer(model.metadata.meshed_region)
41-
skin_mesh = skin_op.outputs.mesh()
42-
43-
###############################################################################
44-
# Plot the mesh skin:
45-
skin_mesh.plot()
4631

4732
###############################################################################
48-
# Compute the stress principal invariants on the skin nodes only:
33+
# Compute the stress principal invariants:
4934
stress_op = ops.result.stress(data_sources=model.metadata.data_sources)
5035
stress_op.inputs.requested_location.connect(dpf.locations.nodal)
51-
stress_op.inputs.mesh_scoping.connect(skin_op.outputs.nodes_mesh_scoping)
36+
stress_op.inputs.mesh_scoping.connect(mesh.nodes.scoping)
5237

5338
principal_op = ops.invariant.principal_invariants_fc(stress_op)
5439
principal_stress_1 = principal_op.outputs.fields_eig_1()[0]
@@ -91,16 +76,16 @@
9176

9277
###############################################################################
9378
# Plot the result field on the skin mesh:
94-
skin_mesh.plot(field_to_keep)
79+
mesh.plot(field_to_keep)
9580

9681
###############################################################################
9782
# Plot initial invariants
9883
# ~~~~~~~~~~~~~~~~~~~~~~~
9984

10085

10186
###############################################################################
102-
# Plot the initial invariants on the skin mesh:
87+
# Plot the initial invariants:
10388

104-
skin_mesh.plot(principal_stress_1)
105-
skin_mesh.plot(principal_stress_2)
106-
skin_mesh.plot(principal_stress_3)
89+
mesh.plot(principal_stress_1)
90+
mesh.plot(principal_stress_2)
91+
mesh.plot(principal_stress_3)

examples/00-basic/07-use_result_helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
55
Use result helpers to load custom data
66
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
78
The :class:`Result <ansys.dpf.core.results.Result>` class, which is an instance
89
created by the :class:`Model <ansys.dpf.core.model.Model>`, gives
910
access to helpers for requesting results on specific mesh and time scopings.
1011
With these helpers, working on a custom spatial and temporal subset of the
1112
model is straightforward.
1213
13-
Import necessary modules:
1414
"""
1515

16+
# Import necessary modules
1617
from ansys.dpf import core as dpf
1718
from ansys.dpf.core import examples
1819

examples/00-basic/08-results_over_time_subset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
55
Scope results over custom time domains
66
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
78
The :class:`Result <ansys.dpf.core.results.Result>` class, which are instances
89
created by the :class:`Model <ansys.dpf.core.model.Model>`, give
910
access to helpers for requesting results on specific mesh and time scopings.
1011
With these helpers, working on a temporal subset of the
1112
model is straightforward. In this example, different ways to choose the temporal subset to
1213
evaluate a result are exposed. This example can be extended to frequency subsets.
1314
14-
Import necessary modules:
1515
"""
1616

17+
# Import necessary modules
1718
from ansys.dpf import core as dpf
1819
from ansys.dpf.core import examples
1920

examples/00-basic/09-results_over_space_subset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
Scope results over custom space domains
66
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
78
The :class:`Result <ansys.dpf.core.results.Result>` class, which are instances
89
created by the :class:`Model <ansys.dpf.core.model.Model>`, give
910
access to helpers for requesting results on specific mesh and time scopings.

examples/00-basic/11-server_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
Communicate in process or via gRPC
66
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
78
Starting with Ansys 2022 R2, PyDPF can communicate either via In Process or via gRPC
89
with DPF C++ core server (``Ans.Dpf.Grpc.exe``). To choose which type of
910
:class:`ansys.dpf.core.server_types.BaseServer` (object defining the type of communication

0 commit comments

Comments
 (0)