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

FieldData updated to be consistent with core Repo #133

Merged
merged 3 commits into from
Oct 20, 2022
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Module for matplotlib windows management."""
import itertools
import multiprocessing as mp
from typing import List, Optional, Union
from typing import Dict, List, Optional, Union

from ansys.fluent.core.session import Session
from ansys.fluent.core.fluent_connection import _FluentConnection
from ansys.fluent.core.utils.generic import AbstractSingletonMeta, in_notebook

from ansys.fluent.visualization import get_config
Expand Down Expand Up @@ -38,7 +38,7 @@ def __init__(
target=self.plotter, args=(plotter_pipe,), daemon=True
)
self.plot_process.start()
Session._monitor_thread.cbs.append(self.close)
_FluentConnection._monitor_thread.cbs.append(self.close)

def plot(self, data):
self.plot_pipe.send(data)
Expand Down
60 changes: 34 additions & 26 deletions src/ansys/fluent/visualization/post_data_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Dict

from ansys.api.fluent.v0.field_data_pb2 import PayloadTag
from ansys.fluent.core.services.field_data import _FieldDataConstants
import numpy as np

from ansys.fluent.visualization.post_object_defns import GraphicsDefn, PlotDefn
Expand Down Expand Up @@ -49,17 +50,18 @@ def _fetch_mesh_data(self, obj, *args, **kwargs):
obj._pre_display()
field_info = obj._api_helper.field_info()
field_data = obj._api_helper.field_data()
transaction = field_data.new_transaction()
surfaces_info = field_info.get_surfaces_info()
surface_ids = [
id
for surf in map(obj._api_helper.remote_surface_name, obj.surfaces_list())
for id in surfaces_info[surf]["surface_id"]
]

field_data.add_get_surfaces_request(surface_ids, *args, **kwargs)
transaction.add_surfaces_request(surface_ids, *args, **kwargs)
surface_tag = 0
try:
surfaces_data = field_data.get_fields()[surface_tag]
surfaces_data = transaction.get_fields()[surface_tag]
except:
raise RuntimeError("Error while requesting data from server.")
finally:
Expand Down Expand Up @@ -105,34 +107,35 @@ def _fetch_contour_data(self, obj, *args, **kwargs):

field_info = obj._api_helper.field_info()
field_data = obj._api_helper.field_data()
transaction = field_data.new_transaction()
surfaces_info = field_info.get_surfaces_info()
surface_ids = [
id
for surf in map(obj._api_helper.remote_surface_name, obj.surfaces_list())
for id in surfaces_info[surf]["surface_id"]
]
# get scalar field data
field_data.add_get_surfaces_request(surface_ids, *args, **kwargs)
field_data.add_get_scalar_fields_request(
surface_ids,
field,
node_values,
boundary_values,
transaction.add_surfaces_request(surface_ids=surface_ids, *args, **kwargs)
transaction.add_scalar_fields_request(
field_name=field,
surface_ids=surface_ids,
node_value=node_values,
boundary_value=boundary_values,
)

location_tag = (
field_data._payloadTags[PayloadTag.NODE_LOCATION]
_FieldDataConstants.payloadTags[PayloadTag.NODE_LOCATION]
if node_values
else field_data._payloadTags[PayloadTag.ELEMENT_LOCATION]
else _FieldDataConstants.payloadTags[PayloadTag.ELEMENT_LOCATION]
)
boundary_value_tag = (
field_data._payloadTags[PayloadTag.BOUNDARY_VALUES]
_FieldDataConstants.payloadTags[PayloadTag.BOUNDARY_VALUES]
if boundary_values
else 0
)
surface_tag = 0
try:
scalar_field_payload_data = field_data.get_fields()
scalar_field_payload_data = 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]
Expand All @@ -151,6 +154,8 @@ def _fetch_vector_data(self, obj, *args, **kwargs):
field_info = obj._api_helper.field_info()
field_data = obj._api_helper.field_data()

transaction = field_data.new_transaction()

# surface ids
surfaces_info = field_info.get_surfaces_info()
surface_ids = [
Expand All @@ -159,11 +164,13 @@ def _fetch_vector_data(self, obj, *args, **kwargs):
for id in surfaces_info[surf]["surface_id"]
]

field_data.add_get_surfaces_request(surface_ids, *args, **kwargs)
field_data.add_get_vector_fields_request(surface_ids, obj.vectors_of())
transaction.add_surfaces_request(surface_ids=surface_ids, *args, **kwargs)
transaction.add_vector_fields_request(
field_name=obj.vectors_of(), surface_ids=surface_ids
)
vector_field_tag = 0
try:
fields = field_data.get_fields()[vector_field_tag]
fields = transaction.get_fields()[vector_field_tag]
except:
raise RuntimeError("Error while requesting data from server.")
finally:
Expand Down Expand Up @@ -218,6 +225,7 @@ def _fetch_xy_data(self, obj):
surfaces_list = obj.surfaces_list()
field_info = obj._api_helper.field_info()
field_data = obj._api_helper.field_data()
transaction = field_data.new_transaction()
surfaces_info = field_info.get_surfaces_info()
surface_ids = [
id
Expand Down Expand Up @@ -248,31 +256,31 @@ def _fetch_xy_data(self, obj):
]

# get scalar field data
field_data.add_get_surfaces_request(
surface_ids,
transaction.add_surfaces_request(
surface_ids=surface_ids,
provide_faces=False,
provide_vertices=True if node_values else False,
provide_faces_centroid=False if node_values else True,
)
field_data.add_get_scalar_fields_request(
surface_ids,
field,
node_values,
boundary_values,
transaction.add_scalar_fields_request(
field_name=field,
surface_ids=surface_ids,
node_value=node_values,
boundary_value=boundary_values,
)

location_tag = (
field_data._payloadTags[PayloadTag.NODE_LOCATION]
_FieldDataConstants.payloadTags[PayloadTag.NODE_LOCATION]
if node_values
else field_data._payloadTags[PayloadTag.ELEMENT_LOCATION]
else _FieldDataConstants.payloadTags[PayloadTag.ELEMENT_LOCATION]
)
boundary_value_tag = (
field_data._payloadTags[PayloadTag.BOUNDARY_VALUES]
_FieldDataConstants.payloadTags[PayloadTag.BOUNDARY_VALUES]
if boundary_values
else 0
)
surface_tag = 0
xyplot_payload_data = field_data.get_fields()
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.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import threading
from typing import List, Optional, Union

from ansys.fluent.core.session import Session
from ansys.fluent.core.fluent_connection import _FluentConnection
from ansys.fluent.core.utils.generic import AbstractSingletonMeta, in_notebook
import numpy as np
import pyvista as pv
Expand Down Expand Up @@ -599,8 +599,8 @@ def _open_and_plot_console(self, obj: object, window_id: str) -> None:
self._post_object = obj

if not self._plotter_thread:
if Session._monitor_thread:
Session._monitor_thread.cbs.append(self._exit)
if _FluentConnection._monitor_thread:
_FluentConnection._monitor_thread.cbs.append(self._exit)
self._plotter_thread = threading.Thread(target=self._display, args=())
self._plotter_thread.start()

Expand Down