|
| 1 | +# Copyright (C) 2020 - 2024 ANSYS, Inc. and/or its affiliates. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +# |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
1 | 23 | """ |
2 | 24 | .. _ref_matrix-operations: |
3 | 25 |
|
|
39 | 61 | my_stress = my_model.results.stress(mesh_scoping=my_nodes_scoping).eval() |
40 | 62 |
|
41 | 63 | # We need to average the result from 'elemental_nodal' to an 'elemental' location to plot it. |
42 | | -my_avg_stress = dpf.operators.averaging.to_elemental_fc(fields_container=my_stress, mesh=my_mesh).eval() |
| 64 | +my_avg_stress = dpf.operators.averaging.to_elemental_fc( |
| 65 | + fields_container=my_stress, mesh=my_mesh |
| 66 | +).eval() |
43 | 67 | print(my_avg_stress, my_avg_stress[0]) |
44 | 68 |
|
45 | 69 | ######################################################### |
|
50 | 74 | # :func:'select_component()<ansys.dpf.core.fields_container.FieldsContainer.select_component>'. |
51 | 75 | # Here, the stress tensor has 6 components per elementary data (symmetrical tensor XX,YY,ZZ,XY,YZ,XZ). |
52 | 76 |
|
53 | | -for i in range(0, 6): # Separating the results in different fields containers for each stress tensor component |
54 | | - globals()[f'stress_{i + 1}'] = my_avg_stress.select_component(i) |
| 77 | +for i in range( |
| 78 | + 0, 6 |
| 79 | +): # Separating the results in different fields containers for each stress tensor component |
| 80 | + globals()[f"stress_{i + 1}"] = my_avg_stress.select_component(i) |
55 | 81 |
|
56 | 82 | ################################################################################ |
57 | 83 | # Mathematical operation on each field |
58 | 84 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
59 | 85 |
|
60 | | -# Here we will do some basic mathematical operations on each stress field |
| 86 | +# Here we will do some basic mathematical operations on each stress field |
61 | 87 | # Power |
62 | 88 | # Raise each value of the field to power 2 |
63 | 89 | stress_1 = maths.pow_fc(fields_container=stress_1, factor=2.0).eval() |
|
86 | 112 | # There are different methods to re-assemble the components |
87 | 113 |
|
88 | 114 | # 1) With the operator :class:'assemble_scalars_to_matrices_fc <ansys.dpf.core.operators.utility.assemble_scalars_to_matrices_fc.assemble_scalars_to_matrices_fc>' |
89 | | -assemble_1 = dpf.operators.utility.assemble_scalars_to_matrices_fc(xx=stress_1, yy=stress_2, zz=stress_3, |
90 | | - xy=stress_4, yz=stress_5, xz=stress_6, |
91 | | - symmetrical=True).eval() |
| 115 | +assemble_1 = dpf.operators.utility.assemble_scalars_to_matrices_fc( |
| 116 | + xx=stress_1, yy=stress_2, zz=stress_3, xy=stress_4, yz=stress_5, xz=stress_6, symmetrical=True |
| 117 | +).eval() |
92 | 118 | print(assemble_1, assemble_1[0]) |
93 | | - |
|
0 commit comments