Skip to content

Commit bbcd6ec

Browse files
add represent_data_on_dpf.rst tutorial
1 parent 22de654 commit bbcd6ec

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,103 @@
11
.. _ref_tutorials_represent_data_on_dpf:
22

3+
========================
4+
Manual input data on DPF
5+
========================
6+
7+
.. |Field| replace:: :class:`Field<ansys.dpf.core.field.Field>`
8+
.. |FieldsContainer| replace:: :class:`FieldsContainer<ansys.dpf.core.fields_container.FieldsContainer>`
9+
.. |append| replace:: :func:`append()<ansys.dpf.core.field.Field.append>`
10+
.. |data| replace:: :attr:`Field.data<ansys.dpf.core.field_base._FieldBase.data>`
11+
.. |scoping| replace:: :attr:`Field.scoping<ansys.dpf.core.field_base._FieldBase.scoping>`
12+
13+
This tutorial shows how to represent your manual input data in a DPF data storage structures.
14+
15+
When handling data DPF uses |FieldsContainer| and |Field| to store and return it. The |Field| is a DPF array
16+
and a collection of |Field| is called |FieldsContainer|. For more information on how the data is structure
17+
in a |Field| and how the DPF data storage structures works check the :ref:`ref_tutorials_data_structures`
18+
tutorial section.
19+
20+
Here we will create some 3d vector |Field|, where the data comes from lists.
21+
22+
Defining the fields
23+
-------------------
24+
25+
To manually import data on DPF you have to create the structure to store it.
26+
27+
Here we create a |Field| from scratch by instantiating this object. When using this approach the |Field| has
28+
vector nature by default. Check the :ref:`ref_tutorials_data_structures` tutorial section for more information
29+
on others approaches.
30+
31+
We will need two 3d vector |Field|:
32+
33+
.. jupyter-execute::
34+
35+
# Import the ``ansys.dpf.core`` module
36+
from ansys.dpf import core as dpf
37+
38+
# Create the fields
39+
# a. Define the number of entities
40+
num_entities_1 = 2
41+
42+
# b. Instanciate the field
43+
field_1 = dpf.Field(nentities=num_entities_1)
44+
field_2 = dpf.Field(nentities=num_entities_1)
45+
field_3 = dpf.Field(nentities=num_entities_1)
46+
field_4 = dpf.Field(nentities=num_entities_1)
47+
48+
# c. Define the scoping ids
49+
50+
field_3.scoping.ids = range(num_entities_1)
51+
field_4.scoping.ids = range(num_entities_1)
52+
53+
# d. Create a FieldsContainer
54+
fc_1 = dpf.fields_container_factory.over_time_freq_fields_container(fields=[field_1, field_2])
55+
56+
# Check the Fields and the FieldsContainer
57+
print("Field 1: ", "\n" ,field_1, "\n")
58+
print("Field 2: ", "\n" ,field_2, "\n")
59+
print("Field 3: ", "\n" ,field_3, "\n")
60+
print("Field 4: ", "\n" ,field_4, "\n")
61+
print("FieldsContainer: ", "\n" ,fc_1, "\n")
62+
63+
Add data to the fields
64+
----------------------
65+
66+
Here we define the data and then add it to the fields.
67+
68+
You can add data to a |Field| by using the |append| method, if you have not set the |scoping| property
69+
with the scoping ids, or the |data| property, if you have set the |scoping| property
70+
with the scoping ids.
71+
72+
.. jupyter-execute::
73+
74+
# Define and add the data to the fields
75+
# a. Using the append method
76+
77+
# Define the Fields data
78+
data_11 = [1.0, 2.0, 3.0]
79+
data_12 = [4.0, 5.0, 6.0]
80+
data_21 = [7.0, 3.0, 5.0]
81+
data_22 = [8.0, 1.0, 2.0]
82+
83+
# Add the data to the field
84+
field_1.append(data=data_11, scopingid=0)
85+
field_1.append(data=data_12, scopingid=1)
86+
field_2.append(data=data_21, scopingid=0)
87+
field_2.append(data=data_22, scopingid=1)
88+
89+
# b. Using the data property
90+
91+
# Define the Fields data
92+
data_3b = [6.0, 5.0, 4.0, 3.0, 2.0, 1.0]
93+
data_4b = [4.0, 1.0, 8.0, 5.0, 7.0, 9.0]
94+
95+
# Add the data to the field
96+
field_3.data = data_3b
97+
field_4.data = data_4b
98+
99+
# Check the Fields
100+
print("Field 1: ", "\n", field_1, "\n")
101+
print("Field 2: ", "\n", field_2, "\n")
102+
print("Field 3: ", "\n" ,field_3, "\n")
103+
print("Field 4: ", "\n" ,field_4, "\n")

0 commit comments

Comments
 (0)