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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ jobs:
PYFLUENT_START_INSTANCE: 0
FLUENT_IMAGE_TAG: ${{ env.DOC_DEPLOYMENT_IMAGE_TAG }}

- name: Zip HTML Documentation before upload
run: |
sudo apt install zip -y
zip -r doc.zip doc/_build/html

- name: Upload HTML Documentation
uses: actions/upload-artifact@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions codegen/allapigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import settingsgen
import tuigen

from ansys.fluent.core.launcher.launcher import FLUENT_VERSION, set_ansys_version
from ansys.fluent.core.launcher.launcher import get_ansys_version, set_ansys_version

if __name__ == "__main__":
parser = argparse.ArgumentParser(
Expand All @@ -15,7 +15,7 @@
parser.add_argument(
"--ansys-version",
dest="ansys_version",
help=f"Specify the ansys package version to use, default is {FLUENT_VERSION[0]}",
help=f"Specify the ansys package version to use, default is {get_ansys_version()}",
)
parser.add_argument(
"--fluent-path",
Expand Down
1 change: 1 addition & 0 deletions src/ansys/fluent/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ansys.fluent.core.launcher.launcher import ( # noqa: F401
FluentVersion,
LaunchModes,
get_ansys_version,
launch_fluent,
set_ansys_version,
set_fluent_path,
Expand Down
65 changes: 39 additions & 26 deletions src/ansys/fluent/core/launcher/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,31 @@

_THIS_DIR = os.path.dirname(__file__)
_OPTIONS_FILE = os.path.join(_THIS_DIR, "fluent_launcher_options.json")
FLUENT_VERSION = ["22.2"]
PIM_FLUENT_PRODUCT_VERSION = [FLUENT_VERSION[0].replace(".", "")]
FLUENT_EXE_PATH = []
FLUENT_VERSION = "22.2.0"
_FLUENT_EXE_PATH = ""


class FluentVersion(Enum):
"""Contains the standard Ansys Fluent release."""

version_22R2 = "22.2"
version_23R1 = "23.1"
version_23R2 = "23.2"
version_22R2 = "22.2.0"
version_23R1 = "23.1.0"
version_23R2 = "23.2.0"

@staticmethod
def get_version(version: str) -> "FluentVersion":
"""Get the available versions based on the version in string format."""
for v in FluentVersion:
if version == v.value:
return v
else:
raise RuntimeError(f"The passed version '{version}' does not exist.")
@classmethod
def _missing_(cls, version):
if isinstance(version, (float, str)):
version = str(version) + ".0"
for v in FluentVersion:
if version == v.value:
return FluentVersion(version)
else:
raise RuntimeError(f"The passed version '{version[:-2]}' does not exist."
f" Available version strings are: "
f"{[ver.value for ver in FluentVersion]} ")

def __str__(self):
return str(self.value)


def set_fluent_path(fluent_exe_path: Union[str, Path]) -> None:
Expand All @@ -55,7 +60,8 @@ def set_fluent_path(fluent_exe_path: Union[str, Path]) -> None:
This supersedes the Fluent path set in the environment variable.
"""
if Path(fluent_exe_path).exists():
FLUENT_EXE_PATH.append(str(fluent_exe_path))
global _FLUENT_EXE_PATH
_FLUENT_EXE_PATH = (str(fluent_exe_path))
else:
raise RuntimeError(
f"The passed path '{fluent_exe_path}' does not contain a valid Fluent executable file."
Expand All @@ -69,11 +75,13 @@ def set_ansys_version(version: Union[str, float, FluentVersion]) -> None:
and the environment variables are updated properly. This supersedes
the Fluent path set in the environment variable.
"""
if type(version) in [float, str]:
version = FluentVersion.get_version(str(version))
if version in FluentVersion or str(version) in FluentVersion.value:
FLUENT_VERSION[0] = version.value
PIM_FLUENT_PRODUCT_VERSION[0] = FLUENT_VERSION[0].replace(".", "")
global FLUENT_VERSION
FLUENT_VERSION = str(FluentVersion(version))


def get_ansys_version() -> str:
"""Return the Fluent version."""
return FLUENT_VERSION


class LaunchModes(Enum):
Expand Down Expand Up @@ -110,7 +118,7 @@ def get_fluent_path() -> Path:
path = os.environ["PYFLUENT_FLUENT_ROOT"]
return Path(path)
else:
path = os.environ["AWP_ROOT" + "".join(FLUENT_VERSION[0].split("."))]
path = os.environ["AWP_ROOT" + "".join(FLUENT_VERSION.split("."))[:-1]]
return Path(path) / "fluent"


Expand All @@ -128,8 +136,8 @@ def get_exe_path():
set_ansys_version(product_version)
return get_exe_path()

if FLUENT_EXE_PATH:
return str(FLUENT_EXE_PATH[0])
if _FLUENT_EXE_PATH:
return str(_FLUENT_EXE_PATH)

return get_exe_path()

Expand Down Expand Up @@ -287,7 +295,7 @@ def _get_session_info(
if mode is None:
mode = LaunchModes.SOLVER

if type(mode) == str:
if isinstance(mode, str):
mode = LaunchModes.get_mode(mode)
new_session = mode.value[1]
meshing_mode = mode.value[2]
Expand Down Expand Up @@ -440,6 +448,7 @@ def launch_fluent(
py: bool = None,
cwd: str = None,
topy: Union[str, list] = None,
**kwargs,
) -> _BaseSession:

"""Launch Fluent locally in server mode or connect to a running Fluent
Expand All @@ -448,7 +457,7 @@ def launch_fluent(
Parameters
----------
product_version : str, optional
Version of Fluent to use in the numeric format (such as ``"23.1"``
Version of Fluent to use in the numeric format (such as ``"23.1.0"``
for 2023 R1). The default is ``None``, in which case the active version
or latest installed version is used.
version : str, optional
Expand Down Expand Up @@ -536,6 +545,10 @@ def launch_fluent(
machines and core counts are queried from the scheduler environment and
passed to Fluent.
"""
if "meshing_mode" in kwargs.keys():
raise RuntimeError("'meshing_mode' argument is no longer used."
" Please use launch_fluent(mode='meshing') to launch in meshing mode.")

argvals = locals()

new_session, meshing_mode, argvals, mode = _get_session_info(
Expand Down Expand Up @@ -594,7 +607,7 @@ def launch_fluent(
session_cls=new_session,
start_timeout=start_timeout,
start_transcript=start_transcript,
product_version=PIM_FLUENT_PRODUCT_VERSION[0],
product_version="".join(FLUENT_VERSION.split("."))[:-1],
cleanup_on_exit=cleanup_on_exit,
meshing_mode=meshing_mode,
dimensionality=version,
Expand Down
10 changes: 10 additions & 0 deletions src/ansys/fluent/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any):
self.fluent_connection.exit()

def __getattr__(self, attr):
if attr == "root":
raise RuntimeError(
"Please use the new structure where the settings objects can be accessed directly."
" For example: 'solver.setup' or 'solver.solution'"
)
if attr == "solver":
raise RuntimeError(
"'Solver' is the parent object."
" Please use the new structure, where: session.solver => solver."
)
return getattr(self.fluent_connection, attr)

def __dir__(self):
Expand Down
12 changes: 6 additions & 6 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

import ansys.fluent.core as pyfluent
from ansys.fluent.core.launcher import launcher
from ansys.fluent.core.launcher.launcher import FLUENT_VERSION
from ansys.fluent.core.launcher.launcher import get_ansys_version


def test_manual_fluent_version_setting():
"""Test case for setting up the Ansys / Fluent version via program"""

initial_version_info = FLUENT_VERSION[0]
initial_version_info = get_ansys_version()

pyfluent.set_ansys_version("23.1")
assert FLUENT_VERSION[0] == "23.1"
pyfluent.set_ansys_version("23.1.0")
assert get_ansys_version() == "23.1.0"

pyfluent.set_ansys_version(22.2)
assert FLUENT_VERSION[0] == "22.2"
assert get_ansys_version() == "22.2.0"

pyfluent.set_ansys_version(version=pyfluent.FluentVersion.version_23R1)
assert FLUENT_VERSION[0] == "23.1"
assert get_ansys_version() == "23.1.0"

# version does not exist
with pytest.raises(RuntimeError):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_launcher_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_launch_remote_instance(monkeypatch, new_solver_session):
assert mock_is_configured.called
assert mock_connect.called
mock_client.create_instance.assert_called_with(
"fluent-3ddp", product_version=launcher.PIM_FLUENT_PRODUCT_VERSION[0]
"fluent-3ddp", product_version="".join(launcher.get_ansys_version().split("."))[:-1]
)
assert mock_instance.wait_for_ready.called
mock_instance.build_grpc_channel.assert_called_with()
Expand Down