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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ repos:
additional_dependencies: ["tomli"]

- repo: https://github.com/PyCQA/docformatter
rev: v1.6.0.rc1
rev: v1.5.1
hooks:
- id: docformatter
args: ["--config", "pyproject.toml"]
Expand Down
5 changes: 4 additions & 1 deletion codegen/allapigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
args = parser.parse_args()

if args.ansys_version:
awp_root = os.environ["AWP_ROOT" + "".join(str(FluentVersion(args.ansys_version)).split("."))[:-1]]
awp_root = os.environ[
"AWP_ROOT"
+ "".join(str(FluentVersion(args.ansys_version)).split("."))[:-1]
]
os.environ["PYFLUENT_FLUENT_ROOT"] = str(Path(awp_root) / "fluent")
if args.fluent_path:
os.environ["PYFLUENT_FLUENT_ROOT"] = args.fluent_path
Expand Down
4 changes: 3 additions & 1 deletion codegen/tuigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def _copy_tui_help_xml_file(version: str):
subprocess.run(f"docker container rm {container_name}", shell=is_linux)

else:
ansys_version = get_ansys_version() # picking up the file from the latest install location
ansys_version = (
get_ansys_version()
) # picking up the file from the latest install location
awp_root = os.environ["AWP_ROOT" + "".join(str(ansys_version).split("."))[:-1]]
xml_source = (
Path(awp_root)
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ markers = [


[tool.black]
force-exclude = ["src/ansys/fluent/core/meshing/tui", "src/ansys/fluent/core/solver/tui", "src/ansys/fluent/core/solver/settings", "src/ansys/fluent/core/datamodel"]
extend-exclude = "/(src/ansys/fluent/core/meshing/tui*|src/ansys/fluent/core/solver/tui*|src/ansys/fluent/core/solver/settings*|src/ansys/fluent/core/datamodel*)/"


[tool.isort]
Expand Down Expand Up @@ -63,6 +63,9 @@ exclude = [
"src/ansys/fluent/core/solver/settings_231/",
"src/ansys/fluent/core/datamodel_231/"
]
pre-summary-space = true
wrap-descriptions = 88
wrap-summaries = 88


[tool.coverage.run]
Expand Down
7 changes: 5 additions & 2 deletions src/ansys/fluent/core/filereader/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ def __call__(self, name: str = ""):
try:
return self._variables[name]
except KeyError:
raise ValueError(allowed_name_error_message(
"config-vars", name, list(self._variables.keys())))
raise ValueError(
allowed_name_error_message(
"config-vars", name, list(self._variables.keys())
)
)

def __getattr__(self, name: str):
for orig, sub in (
Expand Down
13 changes: 8 additions & 5 deletions src/ansys/fluent/core/filereader/lispy.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def readchar(in_port):

def read(in_port):
"""Read a Scheme expression from an input port."""

def read_ahead(token):
if "(" == token:
list_ = None
Expand All @@ -109,10 +110,10 @@ def read_ahead(token):
token = in_port.next_token()
if token == ")":
return (
(tuple(list_) if to_tuple else list_) if list_ else (
tuple(cons) if cons else (
[]
)))
(tuple(list_) if to_tuple else list_)
if list_
else (tuple(cons) if cons else ([]))
)
if token == ".":
if list_:
cons = [list_.pop()]
Expand Down Expand Up @@ -173,16 +174,18 @@ def atom(token):

def to_string(x):
"""Convert a Python object back into a Lisp-readable string."""

def sequence(sep):
return "(" + sep.join(map(to_string, x)) + ")"

if x is True:
return "#t"
elif x is False:
return "#f"
elif isa(x, Symbol):
return x
elif isa(x, str):
return x.replace("\'", '\"')
return x.replace("'", '"')
elif isinstance(x, list):
return sequence(" ")
elif isinstance(x, tuple):
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/fluent/core/fluent_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(
cleanup_on_exit: bool = True,
start_transcript: bool = True,
remote_instance: bool = None,
launcher_args: Dict[str, Any] = None
launcher_args: Dict[str, Any] = None,
):
"""Instantiate a Session.

Expand Down
10 changes: 2 additions & 8 deletions src/ansys/fluent/core/launcher/fluent_container.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import os
from pathlib import Path
import socket
import subprocess
import tempfile
import time
from typing import List

from ansys.fluent.core.session import parse_server_info_file


def _get_free_port() -> int:
sock = socket.socket()
sock.bind(("", 0))
return sock.getsockname()[1]
from ansys.fluent.core.utils.network import get_free_port


def start_fluent_container(mounted_from: str, mounted_to: str, args: List[str]) -> int:
Expand All @@ -38,7 +32,7 @@ def start_fluent_container(mounted_from: str, mounted_to: str, args: List[str])
os.close(fd)
timeout = 100
license_server = os.environ["ANSYSLMD_LICENSE_FILE"]
port = _get_free_port()
port = get_free_port()
password = ""
container_sifile = mounted_to + "/" + Path(sifile).name
image_tag = os.getenv("FLUENT_IMAGE_TAG", "v23.1.0")
Expand Down
52 changes: 26 additions & 26 deletions src/ansys/fluent/core/launcher/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ def _missing_(cls, version):
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]} ")
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)
Expand Down Expand Up @@ -200,7 +202,6 @@ def launch_remote_fluent(
dimensionality: str = None,
launcher_args: Dict[str, Any] = None,
):

"""Launch Fluent remotely using the PIM (Product Instance Management) API.

When calling this method, you must ensure that you are in an
Expand Down Expand Up @@ -257,14 +258,12 @@ def launch_remote_fluent(
remote_instance=instance,
start_timeout=start_timeout,
start_transcript=start_transcript,
launcher_args=launcher_args
launcher_args=launcher_args,
)
)


def _get_session_info(
argvals, mode: Union[LaunchModes, str, None] = None
):
def _get_session_info(argvals, mode: Union[LaunchModes, str, None] = None):
"""Updates the session information."""
if mode is None:
mode = LaunchModes.SOLVER
Expand Down Expand Up @@ -397,17 +396,13 @@ def _generate_launch_string(
def scm_to_py(topy):
if not isinstance(topy, (str, list)):
raise TypeError("Journal name should be of str or list type.")
launch_string = ""
if isinstance(topy, str):
topy = [topy]
fluent_jou_arg = "".join([f'-i "{journal}" ' for journal in topy])
py_jou = "_".join([Path(journal).stem for journal in topy])
launch_string += f' {fluent_jou_arg} -command="(api-start-python-journal \\\"\\\"{py_jou}.py\\\"\\\")"' # noqa: E501
return launch_string
return f" {fluent_jou_arg} -topy"


class LaunchFluentError(Exception):

def __init__(self, launch_string):
details = "\n" + "Fluent Launch string: " + launch_string
super().__init__(details)
Expand Down Expand Up @@ -440,7 +435,6 @@ def launch_fluent(
topy: Union[str, list] = None,
**kwargs,
) -> _BaseSession:

"""Launch Fluent locally in server mode or connect to a running Fluent
server instance.

Expand Down Expand Up @@ -544,17 +538,19 @@ def launch_fluent(
"""
if kwargs:
if "meshing_mode" in kwargs:
raise RuntimeError("'meshing_mode' argument is no longer used."
" Please use launch_fluent(mode='meshing') to launch in meshing mode.")
raise RuntimeError(
"'meshing_mode' argument is no longer used."
" Please use launch_fluent(mode='meshing') to launch in meshing mode."
)
else:
raise TypeError(f"launch_fluent() got an unexpected keyword argument {next(iter(kwargs))}")
raise TypeError(
f"launch_fluent() got an unexpected keyword argument {next(iter(kwargs))}"
)

del kwargs
argvals = locals()

new_session, meshing_mode, argvals, mode = _get_session_info(
argvals, mode
)
new_session, meshing_mode, argvals, mode = _get_session_info(argvals, mode)
_raise_exception_g_gu_in_windows_os(additional_arguments)
if _start_instance(start_instance):
server_info_filepath = _get_server_info_filepath()
Expand Down Expand Up @@ -583,7 +579,7 @@ def launch_fluent(
server_info_filepath=server_info_filepath,
cleanup_on_exit=cleanup_on_exit,
start_transcript=start_transcript,
launcher_args=argvals
launcher_args=argvals,
)
if case_filepath:
if meshing_mode:
Expand All @@ -597,9 +593,13 @@ def launch_fluent(
session.file.read_journal(journal_filepath)
if case_data_filepath:
if not meshing_mode:
session.file.read(file_type="case-data", file_name=case_data_filepath)
session.file.read(
file_type="case-data", file_name=case_data_filepath
)
else:
raise RuntimeError("Case and data file cannot be read in meshing mode.")
raise RuntimeError(
"Case and data file cannot be read in meshing mode."
)

return session
except Exception as ex:
Expand All @@ -621,7 +621,7 @@ def launch_fluent(
cleanup_on_exit=cleanup_on_exit,
meshing_mode=meshing_mode,
dimensionality=version,
launcher_args=argvals
launcher_args=argvals,
)
import ansys.fluent.core as pyfluent

Expand All @@ -642,7 +642,7 @@ def launch_fluent(
password=password,
cleanup_on_exit=cleanup_on_exit,
start_transcript=start_transcript,
launcher_args=argvals
launcher_args=argvals,
)
)
else:
Expand All @@ -655,7 +655,7 @@ def launch_fluent(
password=password,
cleanup_on_exit=cleanup_on_exit,
start_transcript=start_transcript,
launcher_args=argvals
launcher_args=argvals,
)
new_session = _get_running_session_mode(fluent_connection, mode)
return new_session(fluent_connection=fluent_connection)
44 changes: 31 additions & 13 deletions src/ansys/fluent/core/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,22 @@ def _init(_self, obj):
_self.obj = obj

self.command_cls = type(
'command', (), {
'__init__': _init,
'__call__': lambda _self, *args, **kwargs: method(_self.obj, *args, **kwargs),
"command",
(),
{
"__init__": _init,
"__call__": lambda _self, *args, **kwargs: method(
_self.obj, *args, **kwargs
),
"argument_attribute": lambda _self, argument_name, attr_name: self.arguments_attrs[
argument_name][attr_name](_self.obj),
argument_name
][
attr_name
](
_self.obj
),
"arguments": lambda _self: list(self.arguments_attrs.keys()),
}
},
)

def __set_name__(self, obj, name):
Expand All @@ -68,9 +77,13 @@ def __get__(self, obj, obj_type=None):
def CommandArgs(command_object, argument_name):
def wrapper(attribute):
if argument_name in command_object.arguments_attrs:
command_object.arguments_attrs[argument_name].update({attribute.__name__: attribute})
command_object.arguments_attrs[argument_name].update(
{attribute.__name__: attribute}
)
else:
command_object.arguments_attrs[argument_name] = {attribute.__name__: attribute}
command_object.arguments_attrs[argument_name] = {
attribute.__name__: attribute
}
return attribute

return wrapper
Expand Down Expand Up @@ -236,7 +249,10 @@ def update(clss):
name,
cls(self, api_helper),
)
if cls.__class__.__name__ == "PyLocalNamedObjectMeta" or cls.__class__.__name__ == "PyLocalNamedObjectMetaAbstract" :
if (
cls.__class__.__name__ == "PyLocalNamedObjectMeta"
or cls.__class__.__name__ == "PyLocalNamedObjectMetaAbstract"
):
setattr(
self,
cls.PLURAL,
Expand Down Expand Up @@ -286,7 +302,6 @@ def wrapper(self, show_attributes=False):

def update_state(clss):
for name, cls in clss.__dict__.items():

availability = (
getattr(self, "_availability")(name)
if hasattr(self, "_availability")
Expand Down Expand Up @@ -368,7 +383,10 @@ def update(clss):
name,
cls(self, api_helper),
)
elif cls.__class__.__name__ == "PyLocalNamedObjectMeta" or cls.__class__.__name__ == "PyLocalNamedObjectMetaAbstract" :
elif (
cls.__class__.__name__ == "PyLocalNamedObjectMeta"
or cls.__class__.__name__ == "PyLocalNamedObjectMetaAbstract"
):
setattr(
self,
cls.PLURAL,
Expand Down Expand Up @@ -445,13 +463,13 @@ def allowed_values(self):
return list(self)

@Command
def Create(self, name = None):
def Create(self, name=None):
if not name:
name = self._get_unique_chid_name()

new_object = self.__getitem__(name)
new_object = self.__getitem__(name)
return new_object._name

@CommandArgs(Create, "name")
def type(self):
return "string"
return "string"
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def allowed_values(self):
self._api_helper.field_info().get_surfaces_info().keys()
) + list(self._get_top_most_parent()._local_surfaces_provider())


class MeshDefn(GraphicsDefn):
"""Mesh graphics definition."""

Expand Down
Loading