Skip to content
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

refactor: Update field data output. #3329

Merged
merged 34 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
795a2cd
refactor: Update field data output.
prmukherj Sep 28, 2024
32cae33
Update tests.
prmukherj Sep 28, 2024
96bc644
Fix import.
prmukherj Sep 28, 2024
ed81c51
Update.
prmukherj Oct 3, 2024
030c2ca
Refactor and update test.
prmukherj Oct 7, 2024
1938b6c
Update docs.
prmukherj Oct 7, 2024
38349f5
Merge branch 'main' into maint/update_field_data_output
prmukherj Oct 7, 2024
5cd602f
Update test.
prmukherj Oct 7, 2024
5c27391
Update faces_connectivity.
prmukherj Oct 8, 2024
d4508f9
Merge branch 'main' into maint/update_field_data_output
prmukherj Oct 8, 2024
b62c233
Update File Session.
prmukherj Oct 8, 2024
4f00715
Merge branch 'maint/update_field_data_output' of https://github.com/a…
prmukherj Oct 8, 2024
8af365f
Update file_session.
prmukherj Oct 8, 2024
06a581d
Added deprecated field data interface.
prmukherj Oct 10, 2024
9511f22
Add test.
prmukherj Oct 10, 2024
26ff551
Update 'get_surface_data' interface.
prmukherj Oct 10, 2024
0c0414d
Refactor.
prmukherj Oct 10, 2024
a909d03
Update docs.
prmukherj Oct 10, 2024
1262c9b
Merge branch 'main' into maint/update_field_data_output
prmukherj Oct 14, 2024
db2d144
Merge branch 'main' of https://github.com/ansys/pyfluent into maint/u…
prmukherj Oct 14, 2024
d6cfee0
Merge branch 'maint/update_field_data_output' of https://github.com/a…
prmukherj Oct 14, 2024
d02bf97
Delete old test.
prmukherj Oct 14, 2024
2d4d102
Merge branch 'main' into maint/update_field_data_output
prmukherj Oct 15, 2024
ce28cd8
Merge branch 'main' into maint/update_field_data_output
prmukherj Oct 16, 2024
536f25c
Update 'get_surface_data' interface.
prmukherj Oct 16, 2024
eb0c1b7
Revert reduction changes.
prmukherj Oct 16, 2024
86de8de
Merge branch 'main' into maint/update_field_data_output
prmukherj Oct 16, 2024
00d3966
Update pathlines output.
prmukherj Oct 17, 2024
7ea1f82
Merge branch 'main' into maint/update_field_data_output
prmukherj Oct 17, 2024
7938bf8
Merge branch 'maint/update_field_data_output' of https://github.com/a…
prmukherj Oct 17, 2024
a927f65
Update docs.
prmukherj Oct 17, 2024
0085b41
Update the deprecated class.
prmukherj Oct 17, 2024
310d327
Revert pathlines change.
prmukherj Oct 17, 2024
5728aa7
Update get surface data.
prmukherj Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 45 additions & 56 deletions doc/source/user_guide/fields/field_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,54 +43,47 @@ Here are the methods for requesting each type of field:

Get surface data
~~~~~~~~~~~~~~~~
You can request surface vertices for a given ``surface_name`` by calling
the ``get_surface_data`` method and specifying ``Vertices`` for ``data_type``.
You can request surface vertices for a given surface name by calling
the ``get_surface_data`` method and specifying ``Vertices`` for ``data_types``.

.. code-block:: python

>>> from ansys.fluent.core.services.field_data import SurfaceDataType

>>> vertices_data = field_data.get_surface_data(surface_name="cold-inlet", data_type=SurfaceDataType.Vertices)
>>> vertices_data.size
241
>>> vertices_data.surface_id
3
>>> vertices_data[5].x
-0.2
>>> vertices_data[5].y
-0.10167995
>>> vertices_data[5].z
0.0036200774
>>> vertices_data = field_data.get_surface_data(surfaces=["cold-inlet"], data_types=[SurfaceDataType.Vertices])
>>> vertices_data[SurfaceDataType.Vertices]["cold-inlet"].shape
(241, 3)
>>> vertices_data[SurfaceDataType.Vertices]["cold-inlet"][5]
array([-0.2 , -0.10167995, 0.00362008], dtype=float32)

You can call the same method to get the corresponding surface face normals and centroids.
For ``data_type``, specifying ``FacesNormal`` and ``FacesCentroid`` respectively.
For ``data_types``, specifying ``FacesNormal`` and ``FacesCentroid`` respectively.

.. code-block:: python

>>> faces_normal_data = field_data.get_surface_data(
>>> data_type=SurfaceDataType.FacesNormal, surface_name="cold-inlet"
>>> faces_normal_and_centroid_data = field_data.get_surface_data(
>>> data_types=[SurfaceDataType.FacesNormal, SurfaceDataType.FacesCentroid], surfaces=["cold-inlet"]
>>> )

>>> faces_centroid_data = field_data.get_surface_data(
>>> data_type=SurfaceDataType.FacesCentroid, surface_name="cold-inlet"
>>> )
>>> faces_normal_and_centroid_data[SurfaceDataType.FacesNormal]["cold-inlet"].shape
(152, 3)
>>> faces_normal_and_centroid_data[SurfaceDataType.FacesCentroid]["cold-inlet"][15]
array([-0.2 , -0.11418786, 0.03345207], dtype=float32)

You can request face connectivity data for a given ``surface_name`` by calling
the ``get_surface_data`` method and specifying ``FacesConnectivity`` for ``data_type``.
You can request face connectivity data for given ``surfaces`` by calling
the ``get_surface_data`` method and specifying ``FacesConnectivity`` for ``data_types``.

.. code-block:: python

>>> faces_connectivity_data = field_data.get_surface_data(
>>> data_type=SurfaceDataType.FacesConnectivity, surface_name="cold-inlet"
>>> data_types=[SurfaceDataType.FacesConnectivity], surfaces=["cold-inlet"]
>>> )
>>> faces_connectivity_data[5].node_count
4
>>> faces_connectivity_data[5].node_indices
[12, 13, 17, 16]
>>> faces_connectivity_data[SurfaceDataType.FacesConnectivity]["cold-inlet"][5]
array([12, 13, 17, 16])


If a surface name is provided as input, the response contains face vertices, connectivity data, and normal or centroid data.
If surface IDs are provided as input, the response is a dictionary containing a map of surface IDs to face
If a single surface is provided as input, the response contains face vertices, connectivity data, and normal or centroid data.
If multiple surfaces are provided as input, the response is a dictionary containing a map of surface IDs to face
vertices, connectivity data, and normal or centroid data.

Get scalar field data
Expand All @@ -99,50 +92,46 @@ You can call the ``get_scalar_field_data`` method to get scalar field data, such

.. code-block:: python

>>> abs_press_data = field_data.get_scalar_field_data(field_name="absolute-pressure", surface_name="cold-inlet")
>>> abs_press_data.size
241
>>> abs_press_data[120].scalar_data
>>> abs_press_data = field_data.get_scalar_field_data(field_name="absolute-pressure", surfaces=["cold-inlet"])
>>> abs_press_data["cold-inlet"].shape
(241,)
>>> abs_press_data["cold-inlet"][120]
101325.0

If a surface name is provided as input, scalar field data is returned.
If surface IDs are provided as input, a dictionary containing a map of surface IDs to scalar field data is returned.
If a single surface is provided as input, scalar field data is returned.
If multiple surfaces are provided as input, a dictionary containing a map of surface IDs to scalar field data is returned.

Get vector field data
~~~~~~~~~~~~~~~~~~~~~
You can call the ``get_vector_field_data`` method to get vector field data.

.. code-block:: python

>>> velocity_vector_data = field_data.get_vector_field_data(field_name="velocity", surface_name="cold-inlet")
>>> velocity_vector_data.size
152
>>> velocity_vector_data.scale
1.0
>>> velocity_vector_data = field_data.get_vector_field_data(field_name="velocity", surfaces=["cold-inlet"])
>>> velocity_vector_data["cold-inlet"].shape
(152, 3)

If a surface name is provided as input, vector field data is returned.
If surface IDs are provided as input, a dictionary containing a map of surface IDs to vector field data is returned.
If a single surface is provided as input, vector field data is returned.
If multiple surfaces are provided as input, a dictionary containing a map of surface IDs to vector field data is returned.

Get pathlines field data
~~~~~~~~~~~~~~~~~~~~~~~~
You can call the ``get_pathlines_field_data`` method to get pathlines field data.

.. code-block:: python

>>> path_lines_data = field_data.get_pathlines_field_data(field_name="velocity", surface_name="cold-inlet")
>>> path_lines_data["vertices"].size
76152
>>> path_lines_data["lines"].size
>>> path_lines_data = field_data.get_pathlines_field_data(field_name="velocity", surfaces=["cold-inlet"])
>>> path_lines_data["cold-inlet"]["vertices"].shape
prmukherj marked this conversation as resolved.
Show resolved Hide resolved
(76152, 3)
>>> len(path_lines_data["cold-inlet"]["lines"])
76000
>>> path_lines_data["velocity"].size
76152
>>> path_lines_data["lines"][100].node_count
2
>>> path_lines_data["lines"][100].node_indices
>>> path_lines_data["cold-inlet"]["velocity"].shape
(76152, )
>>> path_lines_data["cold-inlet"]["lines"][100]
array([100, 101])

Dictionary containing a map of surface IDs to the path-line data is returned.
or example, pathlines connectivity, vertices, and field.
For example, pathlines connectivity, vertices, and field.


.. note::
Expand Down Expand Up @@ -172,16 +161,16 @@ Following code demonstrate adding multiple requests to a single transaction.
.. code-block::

>>> transaction.add_surfaces_request(
>>> surface_ids=[1], provide_vertices=True, provide_faces=False, provide_faces_centroid=True
>>> surfaces=[1], data_types = [SurfaceDataType.Vertices, SurfaceDataType.FacesCentroid],
>>> )
>>> transaction.add_surfaces_request(
>>> surface_ids=[2], provide_vertices=True, provide_faces=True
>>> surfaces=[2], data_types = [SurfaceDataType.Vertices, SurfaceDataType.FacesConnectivity],
>>> )
>>> transaction.add_scalar_fields_request(
>>> surface_ids=[1,2], field_name="temperature", node_value=True, boundary_value=True
>>> surfaces=[1,2], field_name="pressure", node_value=True, boundary_value=True
>>> )
>>> transaction.add_vector_fields_request(surface_ids=[1,2], field_name="velocity")
>>> transaction.add_pathlines_fields_request(surface_ids=[1,2], field_name="temperature")
>>> transaction.add_vector_fields_request(surfaces=[1,2], field_name="velocity")
>>> transaction.add_pathlines_fields_request(surfaces=[1,2], field_name="temperature")


You can call the ``get_fields`` method to get the data for all these requests. This call also
Expand Down
186 changes: 55 additions & 131 deletions src/ansys/fluent/core/file_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
from ansys.fluent.core import PyFluentDeprecationWarning
from ansys.fluent.core.filereader.case_file import CaseFile
from ansys.fluent.core.filereader.data_file import DataFile
from ansys.fluent.core.services.field_data import (
FacesConnectivity,
ScalarFieldData,
SurfaceDataType,
VectorFieldData,
Vertices,
)
from ansys.fluent.core.services.field_data import SurfaceDataType
from ansys.fluent.core.utils.deprecate import deprecate_argument, deprecate_arguments


Expand Down Expand Up @@ -411,48 +405,32 @@ def get_surface_data(
)

if SurfaceDataType.Vertices in data_types:
if len(surfaces) == 1 and isinstance(surfaces[0], str):
surface_ids = self._field_info.get_surfaces_info()[surfaces[0]][
"surface_id"
]
return Vertices(
surface_ids[0],
self._file_session._case_file.get_mesh().get_vertices(
surface_ids[0]
),
)
else:
return {
surface_id: Vertices(
surface_id,
self._file_session._case_file.get_mesh().get_vertices(
surface_id
),
)
for surface_id in surface_ids
}
return {
surface: self._file_session._case_file.get_mesh()
.get_vertices(surface_ids[count])
.reshape(-1, 3)
for count, surface in enumerate(surfaces)
}

if SurfaceDataType.FacesConnectivity in data_types:
if len(surfaces) == 1 and isinstance(surfaces[0], str):
surface_ids = self._field_info.get_surfaces_info()[surfaces[0]][
"surface_id"
]
return FacesConnectivity(
surface_ids[0],
return {
surface: self._get_faces_connectivity_data(
self._file_session._case_file.get_mesh().get_connectivity(
surface_ids[0]
),
)
else:
return {
surface_id: FacesConnectivity(
surface_id,
self._file_session._case_file.get_mesh().get_connectivity(
surface_id
),
surface_ids[count]
)
for surface_id in surface_ids
}
)
for count, surface in enumerate(surfaces)
}

@staticmethod
def _get_faces_connectivity_data(data):
faces_data = []
i = 0
while i < len(data):
end = i + 1 + data[i]
faces_data.append(data[i + 1 : end])
i = end
return faces_data

@deprecate_argument(
old_arg="surface_name",
Expand Down Expand Up @@ -504,53 +482,24 @@ def get_scalar_field_data(
field_info=self._field_info,
surfaces=surfaces,
)
if len(surfaces) == 1 and isinstance(surfaces[0], str):
surface_ids = self._field_info.get_surfaces_info()[surfaces[0]][
"surface_id"
]
if len(self._file_session._data_file.get_phases()) > 1:
if not field_name.startswith("phase-"):
raise InvalidMultiPhaseFieldName()
return ScalarFieldData(
surface_ids[0],
self._file_session._data_file.get_face_scalar_field_data(
field_name.split(":")[0],
field_name.split(":")[1],
surface_ids[0],
),
)
else:
return ScalarFieldData(
surface_ids[0],
self._file_session._data_file.get_face_scalar_field_data(
"phase-1", field_name, surface_ids[0]
),
if len(self._file_session._data_file.get_phases()) > 1:
if not field_name.startswith("phase-"):
raise InvalidMultiPhaseFieldName()
return {
surface: self._file_session._data_file.get_face_scalar_field_data(
field_name.split(":")[0],
field_name.split(":")[1],
surface_ids[count],
)
for count, surface in enumerate(surfaces)
}
else:
if len(self._file_session._data_file.get_phases()) > 1:
if not field_name.startswith("phase-"):
raise InvalidMultiPhaseFieldName()
return {
surface_id: ScalarFieldData(
surface_id,
self._file_session._data_file.get_face_scalar_field_data(
field_name.split(":")[0],
field_name.split(":")[1],
surface_id,
),
)
for surface_id in surface_ids
}
else:
return {
surface_id: ScalarFieldData(
surface_id,
self._file_session._data_file.get_face_scalar_field_data(
"phase-1", field_name, surface_id
),
)
for surface_id in surface_ids
}
return {
surface: self._file_session._data_file.get_face_scalar_field_data(
"phase-1", field_name, surface_ids[count]
)
for count, surface in enumerate(surfaces)
}

@deprecate_argument(
old_arg="surface_name",
Expand Down Expand Up @@ -602,47 +551,22 @@ def get_vector_field_data(
):
raise InvalidFieldName()

if len(surfaces) == 1 and isinstance(surfaces[0], str):
surface_ids = self._field_info.get_surfaces_info()[surfaces[0]][
"surface_id"
]
if len(self._file_session._data_file.get_phases()) > 1:
if not field_name.startswith("phase-"):
raise InvalidMultiPhaseFieldName()
vector_data = self._file_session._data_file.get_face_vector_field_data(
field_name.split(":")[0], surface_ids[0]
)
else:
vector_data = self._file_session._data_file.get_face_vector_field_data(
"phase-1", surface_ids[0]
)

return VectorFieldData(surface_ids[0], vector_data, scale=1.0)
if len(self._file_session._data_file.get_phases()) > 1:
if not field_name.startswith("phase-"):
raise InvalidMultiPhaseFieldName()
return {
surface: self._file_session._data_file.get_face_vector_field_data(
field_name.split(":")[0], surface_ids[count]
).reshape(-1, 3)
for count, surface in enumerate(surfaces)
}
else:
if len(self._file_session._data_file.get_phases()) > 1:
if not field_name.startswith("phase-"):
raise InvalidMultiPhaseFieldName()
return {
surface_id: VectorFieldData(
surface_id,
self._file_session._data_file.get_face_vector_field_data(
field_name.split(":")[0], surface_id
),
scale=1.0,
)
for surface_id in surface_ids
}
else:
return {
surface_id: VectorFieldData(
surface_id,
self._file_session._data_file.get_face_vector_field_data(
"phase-1", surface_id
),
scale=1.0,
)
for surface_id in surface_ids
}
return {
surface: self._file_session._data_file.get_face_vector_field_data(
"phase-1", surface_ids[count]
).reshape(-1, 3)
for count, surface in enumerate(surfaces)
}

@deprecate_argument(
old_arg="surface_name",
Expand Down Expand Up @@ -871,4 +795,4 @@ def _get_surface_ids(
surface_ids.extend(field_info.get_surfaces_info()[surf]["surface_id"])
else:
surface_ids.append(surf)
return list(set(surface_ids))
return surface_ids
Loading
Loading