Skip to content

Commit 993ee2c

Browse files
update
1 parent ac78d86 commit 993ee2c

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

examples/01-mathematical-operations/matrix-operations.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
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+
123
"""
224
.. _ref_matrix-operations:
325
@@ -39,7 +61,9 @@
3961
my_stress = my_model.results.stress(mesh_scoping=my_nodes_scoping).eval()
4062

4163
# 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()
4367
print(my_avg_stress, my_avg_stress[0])
4468

4569
#########################################################
@@ -50,14 +74,16 @@
5074
# :func:'select_component()<ansys.dpf.core.fields_container.FieldsContainer.select_component>'.
5175
# Here, the stress tensor has 6 components per elementary data (symmetrical tensor XX,YY,ZZ,XY,YZ,XZ).
5276

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)
5581

5682
################################################################################
5783
# Mathematical operation on each field
5884
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5985

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
6187
# Power
6288
# Raise each value of the field to power 2
6389
stress_1 = maths.pow_fc(fields_container=stress_1, factor=2.0).eval()
@@ -86,8 +112,7 @@
86112
# There are different methods to re-assemble the components
87113

88114
# 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()
92118
print(assemble_1, assemble_1[0])
93-

0 commit comments

Comments
 (0)