Skip to content

Commit adaa900

Browse files
committed
Local surface provider.
1 parent f19a840 commit adaa900

File tree

5 files changed

+87
-18
lines changed

5 files changed

+87
-18
lines changed

ansys/fluent/post/matplotlib/matplot_objects.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Plots:
1313

1414
_sessions_state = {}
1515

16-
def __init__(self, session):
16+
def __init__(self, session, local_surfaces_provider=None):
1717
"""Instantiate Plots, container of plot objects."""
1818
session_state = Plots._sessions_state.get(session.id if session else 1)
1919
if not session_state:
@@ -23,6 +23,13 @@ def __init__(self, session):
2323
self._init_module(self, sys.modules[__name__])
2424
else:
2525
self.__dict__ = session_state
26+
self._local_surfaces_provider = (
27+
lambda: local_surfaces_provider
28+
if local_surfaces_provider
29+
else self.Surfaces
30+
if hasattr(self, "Surfaces")
31+
else []
32+
)
2633

2734
def _init_module(self, obj, mod):
2835
for name, cls in mod.__dict__.items():
@@ -50,4 +57,6 @@ def plot(self, window_id: Optional[str] = None):
5057
Window id. If not specified unique id is used.
5158
5259
"""
60+
self._pre_display()
5361
matplot_windows_manager.plot(self, window_id)
62+
self._post_display()

ansys/fluent/post/matplotlib/matplot_windows_manager.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ def __init__(
2727
):
2828
self._closed = False
2929
self.plot_pipe, plotter_pipe = mp.Pipe()
30-
self.plotter = ProcessPlotter(
31-
window_id, curves, title, xlabel, ylabel
32-
)
30+
self.plotter = ProcessPlotter(window_id, curves, title, xlabel, ylabel)
3331
self.plot_process = mp.Process(
3432
target=self.plotter, args=(plotter_pipe,), daemon=True
3533
)

ansys/fluent/post/post_object_defns.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,41 @@
1010
)
1111

1212

13-
class GraphicsDefn(metaclass=PyLocalNamedObjectMetaAbstract):
13+
class BasePostObjectDefn:
14+
"""Base class for post objects."""
15+
16+
def _pre_display(self):
17+
local_surfaces_provider = (
18+
self._get_top_most_parent()._local_surfaces_provider()
19+
)
20+
for surf_name in self.surfaces_list():
21+
if surf_name in list(local_surfaces_provider):
22+
surf_obj = local_surfaces_provider[surf_name]
23+
if surf_obj.surface.type() == "iso-surface":
24+
surf_api = surf_obj._data_extractor.surface_api()
25+
surf_api.iso_surface(
26+
surf_obj.surface.iso_surface.field(),
27+
surf_name,
28+
(),
29+
(),
30+
surf_obj.surface.iso_surface.iso_value(),
31+
(),
32+
)
33+
34+
def _post_display(self):
35+
local_surfaces_provider = (
36+
self._get_top_most_parent()._local_surfaces_provider()
37+
)
38+
for surf_name in self.surfaces_list():
39+
if surf_name in list(local_surfaces_provider):
40+
surf_obj = local_surfaces_provider[surf_name]
41+
surf_api = surf_obj._data_extractor.surface_api()
42+
surf_api.delete_surface(surf_name)
43+
44+
45+
class GraphicsDefn(
46+
BasePostObjectDefn, metaclass=PyLocalNamedObjectMetaAbstract
47+
):
1448
"""Abstract base class for graphics objects."""
1549

1650
@abstractmethod
@@ -26,7 +60,7 @@ def display(self, plotter_id: Optional[str] = None):
2660
pass
2761

2862

29-
class PlotDefn(metaclass=PyLocalNamedObjectMetaAbstract):
63+
class PlotDefn(BasePostObjectDefn, metaclass=PyLocalNamedObjectMetaAbstract):
3064
"""Abstract base class for plot objects."""
3165

3266
@abstractmethod
@@ -106,7 +140,7 @@ def allowed_values(self):
106140
"""Surface list allowed values."""
107141
return list(
108142
self._data_extractor.field_info().get_surfaces_info().keys()
109-
)
143+
) + list(self._get_top_most_parent()._local_surfaces_provider())
110144

111145

112146
class MeshDefn(GraphicsDefn):
@@ -124,7 +158,7 @@ def allowed_values(self):
124158
"""Surface list allowed values."""
125159
return list(
126160
(self._data_extractor.field_info().get_surfaces_info().keys())
127-
)
161+
) + list(self._get_top_most_parent()._local_surfaces_provider())
128162

129163
class show_edges(metaclass=PyLocalPropertyMeta):
130164
"""Show edges for mesh."""
@@ -142,17 +176,17 @@ class show_edges(metaclass=PyLocalPropertyMeta):
142176

143177
value: bool = True
144178

145-
class surface_type(metaclass=PyLocalObjectMeta):
179+
class surface(metaclass=PyLocalObjectMeta):
146180
"""Specify surface type."""
147181

148182
def _availability(self, name):
149183
if name == "plane_surface":
150-
return self.surface_type() == "plane-surface"
184+
return self.type() == "plane-surface"
151185
if name == "iso_surface":
152-
return self.surface_type() == "iso-surface"
186+
return self.type() == "iso-surface"
153187
return True
154188

155-
class surface_type(metaclass=PyLocalPropertyMeta):
189+
class type(metaclass=PyLocalPropertyMeta):
156190
"""Surface type."""
157191

158192
value: str = "iso-surface"
@@ -251,7 +285,7 @@ def allowed_values(self):
251285
"""Surfaces list allowed values."""
252286
return list(
253287
self._data_extractor.field_info().get_surfaces_info().keys()
254-
)
288+
) + list(self._get_top_most_parent()._local_surfaces_provider())
255289

256290
class filled(metaclass=PyLocalPropertyMeta):
257291
"""Show filled contour."""
@@ -278,7 +312,7 @@ class show_edges(metaclass=PyLocalPropertyMeta):
278312

279313
value: bool = False
280314

281-
class range (metaclass=PyLocalObjectMeta):
315+
class range(metaclass=PyLocalObjectMeta):
282316
"""Specify range options."""
283317

284318
def _availability(self, name):
@@ -407,7 +441,7 @@ def allowed_values(self):
407441
"""Surface list allowed values."""
408442
return list(
409443
self._data_extractor.field_info().get_surfaces_info().keys()
410-
)
444+
) + list(self._get_top_most_parent()._local_surfaces_provider())
411445

412446
class scale(metaclass=PyLocalPropertyMeta):
413447
"""Vector scale."""

ansys/fluent/post/pyvista/pyvista_objects.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Graphics:
2121

2222
_sessions_state = {}
2323

24-
def __init__(self, session):
24+
def __init__(self, session, local_surfaces_provider=None):
2525
"""Instantiate Graphics, containter of graphics objects."""
2626
session_state = Graphics._sessions_state.get(
2727
session.id if session else 1
@@ -35,6 +35,13 @@ def __init__(self, session):
3535
self._init_module(self, sys.modules[__name__])
3636
else:
3737
self.__dict__ = session_state
38+
self._local_surfaces_provider = (
39+
lambda: local_surfaces_provider
40+
if local_surfaces_provider
41+
else self.Surfaces
42+
if hasattr(self, "Surfaces")
43+
else []
44+
)
3845

3946
def _init_module(self, obj, mod):
4047
for name, cls in mod.__dict__.items():
@@ -61,7 +68,9 @@ def display(self, window_id: Optional[str] = None):
6168
window_id : str, optional
6269
Window id. If not specified unique id is used.
6370
"""
71+
self._pre_display()
6472
pyvista_windows_manager.plot(self, window_id)
73+
self._post_display()
6574

6675

6776
class Surface(SurfaceDefn):
@@ -76,7 +85,9 @@ def display(self, window_id: Optional[str] = None):
7685
window_id : str, optional
7786
Window id. If not specified unique id is used.
7887
"""
88+
self._pre_display()
7989
pyvista_windows_manager.plot(self, window_id)
90+
self._post_display()
8091

8192

8293
class Contour(ContourDefn):
@@ -91,7 +102,9 @@ def display(self, window_id: Optional[str] = None):
91102
window_id : str, optional
92103
Window id. If not specified unique id is used.
93104
"""
105+
self._pre_display()
94106
pyvista_windows_manager.plot(self, window_id)
107+
self._post_display()
95108

96109

97110
class Vector(VectorDefn):
@@ -106,4 +119,6 @@ def display(self, window_id: Optional[str] = None):
106119
window_id : str, optional
107120
Window id. If not specified unique id is used.
108121
"""
122+
self._pre_display()
109123
pyvista_windows_manager.plot(self, window_id)
124+
self._post_display()

tests/test_post.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ def test_surface_object():
231231
surf1 = pyvista_graphics.Surfaces["surf-1"]
232232
field_info = surf1._data_extractor.field_info()
233233

234-
surf1.surface_type.surface_type = "iso-surface"
235-
iso_surf = surf1.surface_type.iso_surface
234+
surf1.surface.type = "iso-surface"
235+
iso_surf = surf1.surface.iso_surface
236236

237237
assert iso_surf.field.allowed_values == [
238238
v["solver_name"] for k, v in field_info.get_fields_info().items()
@@ -258,6 +258,19 @@ def test_surface_object():
258258
range = field_info.get_range(iso_surf.field(), True)
259259
assert range[0] == pytest.approx(iso_surf.iso_value())
260260

261+
cont1 = pyvista_graphics.Contours["surf-1"]
262+
assert "surf-1" in cont1.surfaces_list.allowed_values
263+
264+
matplotlib_plots = Plots(session=None)
265+
p1 = matplotlib_plots.XYPlots["p-1"]
266+
assert "surf-1" not in p1.surfaces_list.allowed_values
267+
268+
local_surfaces_provider = Graphics(session=None).Surfaces
269+
matplotlib_plots = Plots(
270+
session=None, local_surfaces_provider=local_surfaces_provider
271+
)
272+
assert "surf-1" in p1.surfaces_list.allowed_values
273+
261274

262275
def test_create_plot_objects():
263276
matplotlib_plots1 = Plots(session=None)

0 commit comments

Comments
 (0)