Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion doc/source/api/visualization/graphics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ contour, vector, and surface. The contour is then deleted.
contour1 = graphics_session.Contours["contour-1"]
vector1 = graphics_session.Vectors["vector-1"]
surface1 = graphics_session.Surfaces["surface-1"]
pathlines1 = graphics_session.Pathlines["pathlines-1"]

#Delete object
del graphics_session.Contours["contour-1"]
Expand All @@ -30,4 +31,5 @@ contour, vector, and surface. The contour is then deleted.
mesh
surface
contour
vector
vector
pathlines
6 changes: 6 additions & 0 deletions doc/source/api/visualization/pathlines.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _ref_pathlines:

Pathlines
=========

.. autopostdoc:: ansys.fluent.visualization.pyvista.pyvista_objects.Pathlines
4 changes: 3 additions & 1 deletion doc/styles/Vocab/ANSYS/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ postprocess
Pythonic
PyVista
Util
XY
XY
pathlines
Pathlines
11 changes: 11 additions & 0 deletions examples/00-postprocessing/post_processing_exhaust_manifold.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,21 @@
# Create a vector on a predefined surface.

velocity_vector = graphics.Vectors["velocity-vector"]
velocity_vector.field = "pressure"
velocity_vector.surfaces_list = ["solid_up:1:830"]
velocity_vector.scale = 2
velocity_vector.display("window-8")

###############################################################################
# Create Pathlines
# ~~~~~~~~~~~~~~~~
# Create a pathlines on a predefined surface.

pathlines = graphics.Pathlines["pathlines"]
pathlines.field = "velocity-magnitude"
pathlines.surfaces_list = ["inlet", "inlet1", "inlet2"]
# pathlines.display("window-9")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@akulshre-qa @ypatel-qa Now pathlines is also supported. Currently commented.


###############################################################################
# Create plot object
# ~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ packages = [
[tool.poetry.dependencies]
python = ">=3.7,<4.0"
importlib-metadata = {version = "^4.0", python = "<3.8"}
ansys-fluent-core = "~=0.12.dev0"
ansys-fluent-core = "~=0.12.dev5"
vtk = {version = ">=9.0.3", python = "<=3.9"}
ipyvtklink = ">=0.2.2"
pyvista = ">=0.33.2"
Expand Down
1 change: 0 additions & 1 deletion src/ansys/fluent/visualization/matplotlib/plotter_defns.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def plot(self, data: dict) -> None:
"""
if not data:
return

for curve in data:
min_y_value = np.amin(data[curve]["yvalues"])
max_y_value = np.amax(data[curve]["yvalues"])
Expand Down
115 changes: 101 additions & 14 deletions src/ansys/fluent/visualization/post_data_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import itertools
from typing import Dict

from ansys.api.fluent.v0.field_data_pb2 import PayloadTag
from ansys.fluent.core.services.field_data import _FieldDataConstants
from ansys.api.fluent.v0.field_data_pb2 import DataLocation, PayloadTag
from ansys.fluent.core.services.field_data import (
_FieldDataConstants,
merge_pathlines_data,
)
import numpy as np

from ansys.fluent.visualization.post_object_defns import GraphicsDefn, PlotDefn
Expand Down Expand Up @@ -43,6 +46,8 @@ def fetch_data(self, *args, **kwargs):
return self._fetch_contour_data(self._post_object, *args, **kwargs)
elif self._post_object.__class__.__name__ == "Vector":
return self._fetch_vector_data(self._post_object, *args, **kwargs)
elif self._post_object.__class__.__name__ == "Pathlines":
return self._fetch_pathlines_data(self._post_object, *args, **kwargs)

def _fetch_mesh_data(self, obj, *args, **kwargs):
if not obj.surfaces_list():
Expand All @@ -59,9 +64,10 @@ def _fetch_mesh_data(self, obj, *args, **kwargs):
]

transaction.add_surfaces_request(surface_ids, *args, **kwargs)
surface_tag = 0
try:
surfaces_data = transaction.get_fields()[surface_tag]
fields = transaction.get_fields()
# 0 is old tag
surfaces_data = fields.get(0) or fields[(("type", "surface-data"),)]
except:
raise RuntimeError("Error while requesting data from server.")
finally:
Expand Down Expand Up @@ -133,24 +139,72 @@ def _fetch_contour_data(self, obj, *args, **kwargs):
if boundary_values
else 0
)
surface_tag = 0

try:
scalar_field_payload_data = transaction.get_fields()
fields = transaction.get_fields()
data_tag = location_tag | boundary_value_tag
scalar_field_data = scalar_field_payload_data[data_tag]
surface_data = scalar_field_payload_data[surface_tag]
except:
scalar_field_data = (
fields.get(data_tag)
or fields[
(
("type", "scalar-field"),
(
"dataLocation",
DataLocation.Nodes
if node_values
else DataLocation.Elements,
),
("boundaryValues", boundary_values),
)
]
)
surface_data = fields.get(0) or fields[(("type", "surface-data"),)]
except Exception:
raise RuntimeError("Error while requesting data from server.")
finally:
obj._post_display()
return self._merge(surface_data, scalar_field_data)

def _fetch_pathlines_data(self, obj, *args, **kwargs):
if not obj.surfaces_list() or not obj.field():
raise RuntimeError("Ptahline definition is incomplete.")

obj._pre_display()
field = obj.field()
surfaces_list = obj.surfaces_list()

field_info = obj._api_helper.field_info()
field_data = obj._api_helper.field_data()
surfaces_info = field_info.get_surfaces_info()
transaction = field_data.new_transaction()
surface_ids = [
id
for surf in map(obj._api_helper.remote_surface_name, obj.surfaces_list())
for id in surfaces_info[surf]["surface_id"]
]
transaction.add_pathlines_fields_request(
surface_ids=surface_ids, field_name=field
)

try:
fields = transaction.get_fields()
pathlines_data = fields[(("type", "pathlines-field"), ("field", field))]
data = merge_pathlines_data(pathlines_data, field)
except Exception as e:
raise RuntimeError("Error while requesting data from server." + str(e))
finally:
obj._post_display()
return data

def _fetch_vector_data(self, obj, *args, **kwargs):

if not obj.surfaces_list():
raise RuntimeError("Vector definition is incomplete.")

obj._pre_display()
field = obj.field()
if not field:
field = obj.field = "velocity-magnitude"
field_info = obj._api_helper.field_info()
field_data = obj._api_helper.field_data()

Expand All @@ -165,19 +219,42 @@ def _fetch_vector_data(self, obj, *args, **kwargs):
]

transaction.add_surfaces_request(surface_ids=surface_ids, *args, **kwargs)
transaction.add_scalar_fields_request(
surface_ids=surface_ids,
field_name=field,
node_value=False,
boundary_value=False,
)
transaction.add_vector_fields_request(
field_name=obj.vectors_of(), surface_ids=surface_ids
surface_ids=surface_ids, field_name=obj.vectors_of()
)
vector_field_tag = 0
try:
fields = transaction.get_fields()[vector_field_tag]
fields = transaction.get_fields()
vector_field = fields.get(0) or fields[(("type", "vector-field"),)]
scalar_field = (
fields.get(_FieldDataConstants.payloadTags[PayloadTag.ELEMENT_LOCATION])
or fields[
(
("type", "scalar-field"),
(
"dataLocation",
DataLocation.Elements,
),
("boundaryValues", False),
)
]
)
surface_data = fields.get(0) or fields[(("type", "surface-data"),)]
except:
raise RuntimeError("Error while requesting data from server.")
finally:
obj._post_display()
return fields
data = self._merge(surface_data, vector_field)
return self._merge(data, scalar_field)

def _merge(self, a, b):
if a is b:
return a
if b is not None:
for k, v in a.items():
if b.get(k):
Expand Down Expand Up @@ -283,7 +360,17 @@ def _fetch_xy_data(self, obj):
xyplot_payload_data = transaction.get_fields()
data_tag = location_tag | boundary_value_tag
if data_tag not in xyplot_payload_data:
raise RuntimeError("Plot surface is not valid.")
data_tag = (
("type", "scalar-field"),
(
"dataLocation",
DataLocation.Nodes if node_values else DataLocation.Elements,
),
("boundaryValues", boundary_values),
)
surface_tag = (("type", "surface-data"),)
if data_tag not in xyplot_payload_data:
raise RuntimeError("Plot surface is not valid.")
xyplot_data = xyplot_payload_data[data_tag]
surface_data = xyplot_payload_data[surface_tag]

Expand Down
38 changes: 38 additions & 0 deletions src/ansys/fluent/visualization/post_object_defns.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,34 @@ class show_edges(metaclass=PyLocalPropertyMeta):
value: bool = False


class PathlinesDefn(GraphicsDefn):
"""Pathlines definition."""

PLURAL = "Pathlines"

class field(metaclass=PyLocalPropertyMeta):
"""Pathlines field."""

value: str

@Attribute
def allowed_values(self):
"""Field allowed values."""
return list(self._api_helper.field_info().get_fields_info())

class surfaces_list(metaclass=PyLocalPropertyMeta):
"""List of surfaces for pathlines."""

value: List[str]

@Attribute
def allowed_values(self):
"""Surface list allowed values."""
return list(
(self._api_helper.field_info().get_surfaces_info().keys())
) + list(self._get_top_most_parent()._local_surfaces_provider())


class SurfaceDefn(GraphicsDefn):
"""Surface graphics definition."""

Expand Down Expand Up @@ -488,6 +516,16 @@ def allowed_values(self):
"""Vectors of allowed values."""
return list(self._api_helper.get_vector_fields())

class field(metaclass=PyLocalPropertyMeta):
"""Vector color field."""

value: str

@Attribute
def allowed_values(self):
"""Field allowed values."""
return list(self._api_helper.field_info().get_fields_info())

class surfaces_list(metaclass=PyLocalPropertyMeta):
"""List of surfaces for vector graphics."""

Expand Down
27 changes: 27 additions & 0 deletions src/ansys/fluent/visualization/pyvista/pyvista_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ansys.fluent.visualization.post_object_defns import (
ContourDefn,
MeshDefn,
PathlinesDefn,
SurfaceDefn,
VectorDefn,
)
Expand Down Expand Up @@ -142,6 +143,32 @@ def display(self, window_id: Optional[str] = None):
pyvista_windows_manager.plot(self, window_id)


class Pathlines(PathlinesDefn):
"""Pathlines definition for PyVista.

.. code-block:: python

from ansys.fluent.visualization.pyvista import Graphics

graphics_session = Graphics(session)
pathlines1 = graphics_session.Pathlines["pathlines-1"]
pathlines1.field = "velocity-magnitude"
pathlines1.surfaces_list = ['inlet']
pathlines1.display("window-0")
"""

def display(self, window_id: Optional[str] = None):
"""Display mesh graphics.

Parameters
----------
window_id : str, optional
Window ID. If an ID is not specified, a unique ID is used.
The default is ``None``.
"""
pyvista_windows_manager.plot(self, window_id)


class Surface(SurfaceDefn):
"""Provides for displaying surface graphics.

Expand Down
Loading