|
3 | 3 |
|
4 | 4 | Bring a field's data locally to improve performance |
5 | 5 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 6 | +
|
6 | 7 | Reducing the number of calls to the server is key to improving |
7 | 8 | performance. Using the ``as_local_field`` option brings the data |
8 | 9 | from the server to your local machine where you can work on it. |
9 | 10 | When finished, you send the updated data back to the server |
10 | 11 | in one transaction. |
11 | 12 |
|
12 | | -.. note:: |
13 | | - This example requires the Premium ServerContext. |
14 | | - For more information, see :ref:`_ref_getting_started_contexts`. |
15 | | -
|
16 | 13 | """ |
| 14 | + |
17 | 15 | # Import necessary modules |
18 | 16 | from ansys.dpf import core as dpf |
19 | 17 | from ansys.dpf.core import examples |
20 | 18 | from ansys.dpf.core import operators as ops |
21 | 19 |
|
22 | 20 |
|
23 | | -dpf.set_default_server_context(dpf.AvailableServerContexts.premium) |
24 | | - |
25 | 21 | ############################################################################### |
26 | 22 | # Create a model object to establish a connection with an |
27 | 23 | # example result file and then extract: |
28 | 24 | model = dpf.Model(examples.download_multi_stage_cyclic_result()) |
29 | 25 | print(model) |
| 26 | +mesh = model.metadata.meshed_region |
30 | 27 |
|
31 | 28 | ############################################################################### |
32 | 29 | # Create the workflow |
33 | 30 | # ~~~~~~~~~~~~~~~~~~~~ |
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() |
46 | 31 |
|
47 | 32 | ############################################################################### |
48 | | -# Compute the stress principal invariants on the skin nodes only: |
| 33 | +# Compute the stress principal invariants: |
49 | 34 | stress_op = ops.result.stress(data_sources=model.metadata.data_sources) |
50 | 35 | 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) |
52 | 37 |
|
53 | 38 | principal_op = ops.invariant.principal_invariants_fc(stress_op) |
54 | 39 | principal_stress_1 = principal_op.outputs.fields_eig_1()[0] |
|
91 | 76 |
|
92 | 77 | ############################################################################### |
93 | 78 | # Plot the result field on the skin mesh: |
94 | | -skin_mesh.plot(field_to_keep) |
| 79 | +mesh.plot(field_to_keep) |
95 | 80 |
|
96 | 81 | ############################################################################### |
97 | 82 | # Plot initial invariants |
98 | 83 | # ~~~~~~~~~~~~~~~~~~~~~~~ |
99 | 84 |
|
100 | 85 |
|
101 | 86 | ############################################################################### |
102 | | -# Plot the initial invariants on the skin mesh: |
| 87 | +# Plot the initial invariants: |
103 | 88 |
|
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) |
0 commit comments