From 1d9937c24b21251b6fd0f3bfd94603302eb97385 Mon Sep 17 00:00:00 2001 From: Luisa Felix Salles Date: Thu, 26 Sep 2024 09:19:44 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Paul Profizi <100710998+PProfizi@users.noreply.github.com> --- .../matrix-operations.py | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/examples/01-mathematical-operations/matrix-operations.py b/examples/01-mathematical-operations/matrix-operations.py index 3aa5ba9852..9ed1d32a76 100644 --- a/examples/01-mathematical-operations/matrix-operations.py +++ b/examples/01-mathematical-operations/matrix-operations.py @@ -17,8 +17,7 @@ import ansys.dpf.core.operators.math as maths ############################################################################### -# Open an example and print the ``Model`` object. Here a result file from a crankshaft -# under load simulation is used. +Open an example and print the ``Model`` object # The :class:`Model ` class helps to organize access # methods for the result by keeping track of the operators and data sources # used by the result file. @@ -34,23 +33,22 @@ my_mesh = my_model.metadata.meshed_region print(my_model) ############################################################################### -# Get the stress tensor and define it's scoping. Here, only three nodes will be take into account to facilitate the -# results visualisation +# Get the stress tensor and define its scoping. Only three nodes will be taken into account to facilitate the +# visualization. my_nodes_scoping = dpf.Scoping(ids=[38, 37, 36], location=dpf.locations.elemental) my_stress = my_model.results.stress(mesh_scoping=my_nodes_scoping).eval() -# Here we need to average the result from 'elemental_nodal' to an 'elemental' location to -# facilitate the visualisation of the plot +# We need to average the result from 'elemental_nodal' to an 'elemental' location to plot it. my_avg_stress = dpf.operators.averaging.to_elemental_fc(fields_container=my_stress, mesh=my_mesh).eval() -# print(my_avg_stress, my_avg_stress[0]) +print(my_avg_stress, my_avg_stress[0]) ######################################################### # Separating tensor by component # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# If operations need to be done separetly in each tensor component, the +# If operations need to be done separately in each tensor component, use # :func:'select_component()'. -# Here, the stress tensor has 6 components by elementary data (symmetrical tensor XX,YY,ZZ,XY,YZ,XZ). +# Here, the stress tensor has 6 components per elementary data (symmetrical tensor XX,YY,ZZ,XY,YZ,XZ). for i in range(0, 6): # Separating the results in different fields containers for each stress tensor component globals()[f'stress_{i + 1}'] = my_avg_stress.select_component(i) @@ -64,20 +62,20 @@ # Compute the power operation for each elementary data stress_1 = maths.pow_fc(fields_container=stress_1, factor=2.0).eval() -# Add constant -# Each component of each field is added by 2 +# Add a constant +# Add 2 to each value in the field stress_2 = maths.add_constant_fc(fields_container=stress_2, ponderation=2.0).eval() # Multiply by a constant -# Each component of each field is multiplied by 3 +# Multiply each value in the field by 3 stress_3 = maths.scale_fc(fields_container=stress_3, ponderation=3.0).eval() # Add fields containers -# Each component of each field is added by the correspondent component of the others fields +# Each value of each field is added by the correspondent component of the others fields stress_4 = maths.add_fc(fields_container1=stress_4, fields_container2=stress_5).eval() stress_5 = maths.add_fc(fields_container1=stress_5, fields_container2=stress_6).eval() -#Invert +# Invert # Compute the invert of each element of each field (1./X) stress_6 = maths.invert_fc(fields_container=stress_6).eval() @@ -87,7 +85,7 @@ # There are different methods to re-assemble the components -# 1) With the class :class:'assemble_scalars_to_matrices_fc ' +# 1) With the operator :class:'assemble_scalars_to_matrices_fc ' assemble_1 = dpf.operators.utility.assemble_scalars_to_matrices_fc(xx=stress_1, yy=stress_2, zz=stress_3, xy=stress_4, yz=stress_5, xz=stress_6, symmetrical=True).eval()