-
Notifications
You must be signed in to change notification settings - Fork 25
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
base: doc/new-tutorials-section
Are you sure you want to change the base?
Add math tutorials to the main tutorials branch #1910
Conversation
@luisaFelixSalles can we scroll down in the out section here? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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 |
Yes we can, I think is just not in the screenshot |
ce9b1fc
to
cd37263
Compare
4a1bf3b
to
0b7935b
Compare
576cd9f
to
627c2de
Compare
4606b6a
to
939a805
Compare
- 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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 |
Co-authored-by: Jorge Martínez <[email protected]>
|
||
.. tab-item:: Fields | ||
|
||
Create the Fields by defining: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create the Fields by defining: | |
Create the fields based on: |
- 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create the Fields by intanciating the |Field| object. | |
Create the fields with the |Field| class constructor. |
|
||
.. jupyter-execute:: | ||
|
||
# Instantiate the Fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Instantiate the Fields | |
# Create the fields |
num_entities = 2 | ||
field1 = field2 = field3 = field4 = dpf.Field(nentities=num_entities) | ||
|
||
# Define the scoping ids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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| |
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
Their usage is similar, for each operation you must instantiate the operator and use ``.eval()`` method to compute | ||
and retrieve the results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mathematical operations with Fields | |
Mathematical operations with fields |
|
||
Here, we use: | ||
|
||
- The |add| operator for component wise addition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This operator computes the sum between the data vectors for the corresponding entity id. | |
This operator computes the sum of two fields. |
# 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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
Adds the tutorials of the math section
List of tutorials:
Preview on how it renders:
Mathematics section main page
Basic maths