Skip to content

Add math tutorials to the main tutorials branch #1910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: doc/new-tutorials-section
Choose a base branch
from

Conversation

luisaFelixSalles
Copy link
Contributor

@luisaFelixSalles luisaFelixSalles commented Nov 19, 2024

Adds the tutorials of the math section

List of tutorials:

  • Basic maths

Preview on how it renders:

Mathematics section main page

image

Basic maths

_D__ANSYSdev_pydpf-core_doc_build_html_user_guide_tutorials_mathematics_basic_maths html (1)

@luisaFelixSalles luisaFelixSalles self-assigned this Nov 19, 2024
@luisaFelixSalles luisaFelixSalles changed the base branch from master to doc/new-tutorials-section November 19, 2024 14:06
@PProfizi
Copy link
Contributor

@luisaFelixSalles can we scroll down in the out section here?
image
If not then some prints are missing

@PProfizi
Copy link
Contributor

It seems there mismatches between code and output
image

How come?

@luisaFelixSalles luisaFelixSalles mentioned this pull request Nov 19, 2024
36 tasks
Copy link

codecov bot commented Nov 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.44%. Comparing base (627c2de) to head (643c312).

Additional details and impacted files
@@                      Coverage Diff                      @@
##           doc/new-tutorials-section    #1910      +/-   ##
=============================================================
- Coverage                      88.50%   88.44%   -0.07%     
=============================================================
  Files                             89       89              
  Lines                          10251    10251              
=============================================================
- Hits                            9073     9066       -7     
- Misses                          1178     1185       +7     

@luisaFelixSalles
Copy link
Contributor Author

luisaFelixSalles commented Nov 19, 2024

@luisaFelixSalles can we scroll down in the out section here? image If not then some prints are missing

Yes we can, I think is just not in the screenshot

@PProfizi PProfizi added the tutorials Related to PyDPF-Core tutorials label Nov 19, 2024
@luisaFelixSalles luisaFelixSalles force-pushed the tutorials/math/firsts-math-tutorials branch from ce9b1fc to cd37263 Compare November 20, 2024 12:41
@luisaFelixSalles luisaFelixSalles force-pushed the tutorials/math/firsts-math-tutorials branch from 4a1bf3b to 0b7935b Compare December 17, 2024 10:59
@luisaFelixSalles luisaFelixSalles force-pushed the doc/new-tutorials-section branch from 576cd9f to 627c2de Compare December 19, 2024 16:42
@luisaFelixSalles luisaFelixSalles force-pushed the tutorials/math/firsts-math-tutorials branch from 4606b6a to 939a805 Compare December 20, 2024 11:09
- The entities ids and location. Thus, the |Field| scoping

- If not specified, the location is *'nodal'* by default.
- Each entity (here, the nodes) must have a |Scoping| id. The ids allows DPF to apply an operator on the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Each entity (here, the nodes) must have a |Scoping| id. The ids allows DPF to apply an operator on the
- Each node must have a |Scoping| id. The ids allows DPF to apply an operator on the

@rafacanton rafacanton self-requested a review March 27, 2025 15:02

.. tab-item:: Fields

Create the Fields by defining:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Create the Fields by defining:
Create the fields based on:

Comment on lines +58 to +63
- The entities ids and location. Thus, the |Field| scoping

- If not specified, the location is *'nodal'* by default.
- Each entity (here, the nodes) must have a |Scoping| id. The ids allows DPF to apply an operator on the
corresponding entities. For more detailed explanation about the influence of the |Scoping| on the operations,
see the :ref:`ref_basic_maths_scoping_handling` section on this tutorial.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- The entities ids and location. Thus, the |Field| scoping
- If not specified, the location is *'nodal'* by default.
- Each entity (here, the nodes) must have a |Scoping| id. The ids allows DPF to apply an operator on the
corresponding entities. For more detailed explanation about the influence of the |Scoping| on the operations,
see the :ref:`ref_basic_maths_scoping_handling` section on this tutorial.
- A list of IDs and a location, which together define the scoping of the field:
The location defines the type of entity the IDs refer to. It defaults to *nodal*, in which case the scoping is
understood as a list of node IDs, and the field is a nodal field.
For a more detailed explanation about the influence of the |Scoping| on the operations,
see the :ref:`ref_basic_maths_scoping_handling` section of this tutorial.

.. |norm| replace:: :class:`norm<ansys.dpf.core.operators.math.norm.norm>`
.. |norm_fc| replace:: :class:`norm_fc<ansys.dpf.core.operators.math.norm_fc.norm_fc>`

This tutorial explains how to do some basic mathematical operations with PyDPF-Core.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This tutorial explains how to do some basic mathematical operations with PyDPF-Core.
This tutorial explains how to perform some basic mathematical operations with PyDPF-Core.

DPF uses |Field| and |FieldsContainer| objects to handle data. The |Field| is a homogeneous array and
a |FieldsContainer| is a labeled collection of |Field|.

Here, we use |Field| and |FieldsContainer| created from scratch to facilitate the understanding on how the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Here, we use |Field| and |FieldsContainer| created from scratch to facilitate the understanding on how the
Here, we use |Field| and |FieldsContainer| created from scratch to facilitate understanding of how the

a |FieldsContainer| is a labeled collection of |Field|.

Here, we use |Field| and |FieldsContainer| created from scratch to facilitate the understanding on how the
mathematical operators works. For more information on creating a |Field| from scratch check
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mathematical operators works. For more information on creating a |Field| from scratch check
mathematical operators work. For more information on creating a |Field| from scratch check


Create the Fields by defining:

- The number of entities
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- The number of entities
- A number of entities

# Import the math operators module
from ansys.dpf.core.operators import math as maths

Create the Fields by intanciating the |Field| object.
Copy link
Contributor

@PProfizi PProfizi May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Create the Fields by intanciating the |Field| object.
Create the fields with the |Field| class constructor.


.. jupyter-execute::

# Instantiate the Fields
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Instantiate the Fields
# Create the fields

num_entities = 2
field1 = field2 = field3 = field4 = dpf.Field(nentities=num_entities)

# Define the scoping ids
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Define the scoping ids
# Set the scoping IDs

# Define the scoping ids
field1.scoping.ids = field2.scoping.ids = field3.scoping.ids = field4.scoping.ids = range(num_entities)

# Set the data to each Field
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Set the data to each Field
# Set the data for each field

field3.data = [6.0, 5.0, 4.0, 3.0, 2.0, 1.0]
field4.data = [4.0, 1.0, 8.0, 5.0, 7.0, 9.0]

# Print the Fields
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Print the Fields
# Print the fields


.. tab-item:: FieldsContainers

Create the FieldsContainers using the |fields_container_factory|. Here, we use the |over_time_freq_fields_container|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Create the FieldsContainers using the |fields_container_factory|. Here, we use the |over_time_freq_fields_container|
Create the field containers using the |fields_container_factory|. Here, we use the |over_time_freq_fields_container|

Comment on lines +102 to +106
# Create the FieldsContainers
fc1 = dpf.fields_container_factory.over_time_freq_fields_container(fields=[field1, field2])
fc2 = dpf.fields_container_factory.over_time_freq_fields_container(fields=[field3, field4])

# Print the FieldsContainers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Create the FieldsContainers
fc1 = dpf.fields_container_factory.over_time_freq_fields_container(fields=[field1, field2])
fc2 = dpf.fields_container_factory.over_time_freq_fields_container(fields=[field3, field4])
# Print the FieldsContainers
# Create the field containers
fc1 = dpf.fields_container_factory.over_time_freq_fields_container(fields=[field1, field2])
fc2 = dpf.fields_container_factory.over_time_freq_fields_container(fields=[field3, field4])
# Print the field containers

print("FieldsContainer2","\n", fc2, "\n")


To make the mathematics operations, we use the operators available in the |math operators| module.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To make the mathematics operations, we use the operators available in the |math operators| module.
To perform mathematical operations, we use operators available in the |math operators| module.

Comment on lines +112 to +113
Their usage is similar, for each operation you must instantiate the operator and use ``.eval()`` method to compute
and retrieve the results.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Their usage is similar, for each operation you must instantiate the operator and use ``.eval()`` method to compute
and retrieve the results.
First create an instance of the operator of interest, then use the ``.eval()`` method to compute
and retrieve the first output available.

Their usage is similar, for each operation you must instantiate the operator and use ``.eval()`` method to compute
and retrieve the results.

Mathematical operations with Fields
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Mathematical operations with Fields
Mathematical operations with fields


Here, we use:

- The |add| operator for component wise addition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- The |add| operator for component wise addition
- The |add| operator for component-wise addition


**'add' operator**

This operator computes the sum between the data vectors for the corresponding entity id.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This operator computes the sum between the data vectors for the corresponding entity id.
This operator computes the sum of two fields.

Comment on lines +133 to +139
# Add the Fields
add_field = maths.add(fieldA=field1, fieldB=field2).eval()
# id 0: [1.+7. 2.+3. 3.+5.]
# id 1: [4.+8. 5.+1. 6.+2.]

# Print the results
print("Addition fields",add_field , "\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Add the Fields
add_field = maths.add(fieldA=field1, fieldB=field2).eval()
# id 0: [1.+7. 2.+3. 3.+5.]
# id 1: [4.+8. 5.+1. 6.+2.]
# Print the results
print("Addition fields",add_field , "\n")
# Add the fields
add_field = maths.add(fieldA=field1, fieldB=field2).eval()
# id 0: [1.+7. 2.+3. 3.+5.]
# id 1: [4.+8. 5.+1. 6.+2.]
# Print the results
print("Addition field ", add_field , "\n")


**'accumulate' operator**

This operator sums all the elementary data of a field to produce one elementary data for each vector component.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This operator sums all the elementary data of a field to produce one elementary data for each vector component.
This operator computes the total sum of elementary data of a field, for each component of the field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tutorials Related to PyDPF-Core tutorials
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants