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
31 changes: 21 additions & 10 deletions src/ansys/fluent/visualization/post_data_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ def _fetch_mesh_data(self, obj, *args, **kwargs):

field_data.add_get_surfaces_request(surface_ids, *args, **kwargs)
surface_tag = 0
surfaces_data = field_data.get_fields()[surface_tag]
obj._post_display()
try:
surfaces_data = field_data.get_fields()[surface_tag]
except:
raise RuntimeError("Error while requesting data from server.")
finally:
obj._post_display()
return surfaces_data

def _fetch_surface_data(self, obj, *args, **kwargs):
Expand Down Expand Up @@ -127,12 +131,15 @@ def _fetch_contour_data(self, obj, *args, **kwargs):
else 0
)
surface_tag = 0

scalar_field_payload_data = field_data.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]
obj._post_display()
try:
scalar_field_payload_data = field_data.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:
raise RuntimeError("Error while requesting data from server.")
finally:
obj._post_display()
return self._merge(surface_data, scalar_field_data)

def _fetch_vector_data(self, obj, *args, **kwargs):
Expand All @@ -155,8 +162,12 @@ def _fetch_vector_data(self, obj, *args, **kwargs):
field_data.add_get_surfaces_request(surface_ids, *args, **kwargs)
field_data.add_get_vector_fields_request(surface_ids, obj.vectors_of())
vector_field_tag = 0
fields = field_data.get_fields()[vector_field_tag]
obj._post_display()
try:
fields = field_data.get_fields()[vector_field_tag]
except:
raise RuntimeError("Error while requesting data from server.")
finally:
obj._post_display()
return fields

def _merge(self, a, b):
Expand Down
7 changes: 7 additions & 0 deletions src/ansys/fluent/visualization/post_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ def get_vector_fields(self):
scheme_eval_str = "(map car (apply append (map client-inquire-cell-vector-functions (inquire-domain-for-cell-functions))))" # noqa: E501
return self._scheme_str_to_py_list(scheme_eval_str)

def get_field_unit(self, field):
quantity = self._field_unit_quantity(field)
if quantity == "*null*":
return ""
scheme_eval_str = f"(units/get-pretty-wb-units-from-dimension (units/inquire-dimension '{quantity}))" # noqa: E501
return self._scheme_str_to_py_list(scheme_eval_str)[0]

def _get_phases(self):
scheme_eval_str = "(map domain-name (get-phase-domains))"
return self._scheme_str_to_py_list(scheme_eval_str)
Expand Down
6 changes: 5 additions & 1 deletion src/ansys/fluent/visualization/post_object_defns.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Module providing visualization objects definition."""
from abc import abstractmethod
from typing import List, NamedTuple, Optional
import warnings

from ansys.fluent.core.meta import (
Attribute,
Expand Down Expand Up @@ -293,7 +294,7 @@ def value(self):
"""Iso value property setter."""
if getattr(self, "_value", None) is None:
range = self.range
self._value = range[0] if range else None
self._value = (range[0] + range[1]) / 2.0 if range else None
return self._value

@value.setter
Expand Down Expand Up @@ -351,6 +352,9 @@ def value(self):
filled = self._get_parent_by_type(ContourDefn).filled()
auto_range_off = self._get_parent_by_type(ContourDefn).range.auto_range_off
if not filled or (auto_range_off and auto_range_off.clip_to_range()):
warnings.warn(
"For unfilled and clipped contours node values are diaplyed."
)
self._value = True
return self._value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ def _display_vector(self, obj, plotter: Union[BackgroundPlotter, pv.Plotter]):
def _display_contour(self, obj, plotter: Union[BackgroundPlotter, pv.Plotter]):
# contour properties
field = obj.field()
field_unit = obj._api_helper.get_field_unit(field)
field = f"{field}\n[{field_unit}]" if field_unit else field
range_option = obj.range.option()
filled = obj.filled()
contour_lines = obj.contour_lines()
Expand Down Expand Up @@ -209,9 +211,9 @@ def _display_contour(self, obj, plotter: Union[BackgroundPlotter, pv.Plotter]):
faces=surface_data["faces"],
)
if node_values:
mesh.point_data[field] = surface_data[field]
mesh.point_data[field] = surface_data[obj.field()]
else:
mesh.cell_data[field] = surface_data[field]
mesh.cell_data[field] = surface_data[obj.field()]
if range_option == "auto-range-off":
auto_range_off = obj.range.auto_range_off
if auto_range_off.clip_to_range():
Expand Down Expand Up @@ -262,7 +264,7 @@ def _display_contour(self, obj, plotter: Union[BackgroundPlotter, pv.Plotter]):
field_info = obj._api_helper.field_info()
plotter.add_mesh(
mesh,
clim=field_info.get_range(field, False),
clim=field_info.get_range(obj.field(), False),
scalars=field,
show_edges=obj.show_edges(),
scalar_bar_args=scalar_bar_args,
Expand Down Expand Up @@ -297,14 +299,14 @@ def _display_surface(self, obj, plotter: Union[BackgroundPlotter, pv.Plotter]):
contour = post_session.Contours[dummy_object]
contour.field = obj.definition.iso_surface.field()
contour.surfaces_list = [obj._name]
contour.show_edges = True
contour.show_edges = obj.show_edges()
contour.range.auto_range_on.global_range = True
self._display_contour(contour, plotter)
del post_session.Contours[dummy_object]
else:
mesh = post_session.Meshes[dummy_object]
mesh.surfaces_list = [obj._name]
mesh.show_edges = True
mesh.show_edges = obj.show_edges()
self._display_mesh(mesh, plotter)
del post_session.Meshes[dummy_object]
surface_api.delete_surface_on_server()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def test_surface_object():
# Iso surface value should automatically update upon change in field.
iso_surf.field = "temperature"
range = field_info.get_range(iso_surf.field(), True)
assert range[0] == pytest.approx(iso_surf.iso_value())
assert (range[0] + range[1]) / 2.0 == pytest.approx(iso_surf.iso_value())

# Setting out of range should throw exception
with pytest.raises(ValueError) as value_error:
Expand All @@ -416,7 +416,7 @@ def test_surface_object():
# Iso surface value should automatically update upon change in field.
iso_surf.field = "pressure"
range = field_info.get_range(iso_surf.field(), True)
assert range[0] == pytest.approx(iso_surf.iso_value())
assert (range[0] + range[1]) / 2.0 == pytest.approx(iso_surf.iso_value())

# New surface should be in allowed values for graphics.
cont1 = pyvista_graphics.Contours["surf-1"]
Expand Down