Skip to content

Commit 75a7c50

Browse files
committed
Revert "Remove parametric and visualization code"
This reverts commit cd7a60b.
1 parent cd7a60b commit 75a7c50

File tree

12 files changed

+3148
-0
lines changed

12 files changed

+3148
-0
lines changed

src/ansys/fluent/parametric/__init__.py

Lines changed: 734 additions & 0 deletions
Large diffs are not rendered by default.

src/ansys/fluent/post/__init__.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""Python post processing integrations for the Fluent solver."""
2+
import platform
3+
import struct
4+
import sys
5+
6+
import pkg_resources
7+
8+
required_libraries = {
9+
"vtk": "9.1.0",
10+
"pyvista": "0.33.2",
11+
"pyvistaqt": "0.7.0",
12+
"pyside6": "6.2.3",
13+
"matplotlib": "3.5.1",
14+
}
15+
16+
17+
def _get_vtk_install_cmd(reinstall=False):
18+
is64 = struct.calcsize("P") * 8 == 64
19+
if sys.version_info.minor == 10 and is64:
20+
if platform.system().lower() == "linux":
21+
return f" Please {'reinstall' if reinstall else 'install'} vtk with `pip install {'-I' if reinstall else ''} https://github.com/pyvista/pyvista-wheels/raw/main/vtk-9.1.0.dev0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl`" # noqa: E501
22+
23+
elif platform.system().lower() == "windows":
24+
return f" Please {'reinstall' if reinstall else 'install'} vtk with `pip install {'-I' if reinstall else ''} https://github.com/pyvista/pyvista-wheels/raw/main/vtk-9.1.0.dev0-cp310-cp310-win_amd64.whl`" # noqa: E501
25+
else:
26+
return (
27+
f" Please {'reinstall' if reinstall else 'install'} "
28+
f"vtk with `pip install vtk=={required_libraries[lib]}`."
29+
)
30+
31+
32+
def _update_vtk_version():
33+
is64 = struct.calcsize("P") * 8 == 64
34+
if sys.version_info.minor in (9, 10) and is64:
35+
required_libraries.update({"vtk": "9.1.0.dev0"})
36+
37+
38+
_update_vtk_version()
39+
installed = {pkg.key for pkg in pkg_resources.working_set}
40+
installed_libraries = [
41+
lib for lib, version in required_libraries.items() if lib in installed
42+
]
43+
missing_libraries = required_libraries.keys() - installed
44+
import_errors = []
45+
if missing_libraries:
46+
import_errors.append(
47+
(f"Required libraries {missing_libraries} " "are missing to use this feature.")
48+
)
49+
for lib in missing_libraries:
50+
import_errors.append(
51+
(
52+
f" Please install {lib} with "
53+
f"`pip install {lib}=={required_libraries[lib]}`."
54+
if lib != "vtk"
55+
else _get_vtk_install_cmd()
56+
)
57+
)
58+
if installed_libraries:
59+
versions_mismatched_message = False
60+
for lib in installed_libraries:
61+
required_version = required_libraries[lib]
62+
installed_version = pkg_resources.get_distribution(lib).version
63+
if pkg_resources.parse_version(installed_version) < pkg_resources.parse_version(
64+
required_version
65+
):
66+
if not versions_mismatched_message:
67+
import_errors.append(
68+
(
69+
f"Required libraries version is incompatible "
70+
"to use this feature."
71+
)
72+
)
73+
versions_mismatched_message = True
74+
import_errors.append(
75+
(
76+
f" Please re-install {lib} with "
77+
f"`pip install -I {lib}=={required_libraries[lib]}`."
78+
if lib != "vtk"
79+
else _get_vtk_install_cmd(True)
80+
)
81+
)
82+
83+
if import_errors:
84+
raise ImportError("\n".join(import_errors))
85+
from ansys.fluent.post._config import get_config, set_config # noqa: F401

src/ansys/fluent/post/_config.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Global configuration state for post."""
2+
3+
_global_config = {"blocking": False, "set_view_on_display": None}
4+
5+
6+
def get_config() -> dict:
7+
"""Retrieve post configuration.
8+
9+
Returns
10+
-------
11+
config : dict
12+
Keys are parameter names that can be passed to :func:`set_config`.
13+
"""
14+
return _global_config.copy()
15+
16+
17+
def set_config(blocking: bool = False, set_view_on_display: str = None):
18+
"""Set post configuration.
19+
20+
Parameters
21+
----------
22+
blocking : bool, default=False
23+
If True, then graphics/plot display will block the current thread.
24+
set_view_on_display : str, default=None
25+
If specified, then graphics will always be displayed in the specified view.
26+
Valid values are xy, xz, yx, yz, zx, zy and isometric.
27+
"""
28+
29+
_global_config["blocking"] = blocking
30+
_global_config["set_view_on_display"] = set_view_on_display
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""A package that provides interfacing Fluent with Matplotlib."""
2+
3+
from ansys.fluent.post.matplotlib.matplot_objects import Plots # noqa: F401
4+
from ansys.fluent.post.matplotlib.matplot_windows_manager import ( # noqa: F401
5+
matplot_windows_manager,
6+
)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""Module providing post objects for Matplotlib."""
2+
import inspect
3+
import sys
4+
from typing import Optional
5+
6+
from ansys.fluent.core.meta import PyLocalContainer
7+
from ansys.fluent.post.matplotlib.matplot_windows_manager import matplot_windows_manager
8+
from ansys.fluent.post.post_object_defns import XYPlotDefn
9+
10+
11+
class Plots:
12+
"""Plot objects provider."""
13+
14+
_sessions_state = {}
15+
16+
def __init__(self, session, local_surfaces_provider=None):
17+
"""Instantiate Plots, container of plot objects.
18+
19+
Parameters
20+
----------
21+
session :
22+
Session object.
23+
local_surfaces_provider : object, optional
24+
Object providing local surfaces.
25+
"""
26+
session_state = Plots._sessions_state.get(session.id if session else 1)
27+
if not session_state:
28+
session_state = self.__dict__
29+
Plots._sessions_state[session.id if session else 1] = session_state
30+
self.session = session
31+
self._init_module(self, sys.modules[__name__])
32+
else:
33+
self.__dict__ = session_state
34+
self._local_surfaces_provider = lambda: local_surfaces_provider or getattr(
35+
self, "Surfaces", []
36+
)
37+
38+
def _init_module(self, obj, mod):
39+
for name, cls in mod.__dict__.items():
40+
41+
if cls.__class__.__name__ in (
42+
"PyLocalNamedObjectMetaAbstract",
43+
) and not inspect.isabstract(cls):
44+
setattr(
45+
obj,
46+
cls.PLURAL,
47+
PyLocalContainer(self, cls),
48+
)
49+
50+
51+
class XYPlot(XYPlotDefn):
52+
"""XY Plot."""
53+
54+
def plot(self, window_id: Optional[str] = None):
55+
"""Draw XYPlot.
56+
57+
Parameters
58+
----------
59+
window_id : str, optional
60+
Window id. If not specified unique id is used.
61+
"""
62+
self._pre_display()
63+
matplot_windows_manager.plot(self, window_id)
64+
self._post_display()

0 commit comments

Comments
 (0)