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

Custom Higher Level Exceptions #2176

Merged
merged 33 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cea7510
Custom Higher Level Exceptions
hpohekar Oct 26, 2023
0463f8f
Remove dunder method overload
hpohekar Oct 26, 2023
b004450
Remove exceptions from __init__
hpohekar Oct 26, 2023
1624245
Move excpetions to top
hpohekar Oct 26, 2023
4cdcbaf
Doc fix
hpohekar Oct 26, 2023
4dc90e1
Add docstring
hpohekar Oct 26, 2023
7a02740
Update tests
hpohekar Oct 27, 2023
7dce610
Add more exceptions
hpohekar Oct 27, 2023
24a79a7
Add new tests
hpohekar Oct 27, 2023
375ae52
Add new test execution
hpohekar Oct 27, 2023
9fbf1f4
field data
hpohekar Oct 30, 2023
1270196
test fix
hpohekar Oct 30, 2023
3aa13cf
Merge branch 'main' into feat/higher_level_exceptions_latest
hpohekar Oct 31, 2023
2814c87
test fix 2
hpohekar Oct 31, 2023
8c12921
redesign 1
hpohekar Nov 1, 2023
4801529
redesign 2
hpohekar Nov 3, 2023
a184334
redesign 3
hpohekar Nov 3, 2023
5ec5f67
doc fix
hpohekar Nov 7, 2023
0089447
update 1
hpohekar Nov 7, 2023
165bcfc
update 2
hpohekar Nov 7, 2023
b6d1d4e
update 3
hpohekar Nov 7, 2023
2eec993
update 4
hpohekar Nov 7, 2023
63e5b53
update 5
hpohekar Nov 7, 2023
d8abec7
update 6
hpohekar Nov 7, 2023
4c2284e
test fix
hpohekar Nov 8, 2023
e6db321
test fix error_message
hpohekar Nov 8, 2023
30cf3b8
correct a typo
hpohekar Nov 13, 2023
ed94366
Updated error messages
hpohekar Nov 13, 2023
ea2d604
Incorporate TaskObject change
hpohekar Nov 13, 2023
9b36a05
Incorporate TaskObject change 2
hpohekar Nov 13, 2023
e664ff9
Incorporate TaskObject change 3
hpohekar Nov 13, 2023
a98366f
Incorporate TaskObject change 4
hpohekar Nov 13, 2023
731d714
Update test
hpohekar Nov 13, 2023
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
32 changes: 32 additions & 0 deletions src/ansys/fluent/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,46 @@
logging.configure_env_var()

from ansys.fluent.core._version import __version__ # noqa: F401
from ansys.fluent.core.file_session import ( # noqa: F401
InvalidFieldName,
InvalidFieldNamePrefix,
SurfaceNamesIDsNotProvided,
)
hpohekar marked this conversation as resolved.
Show resolved Hide resolved
from ansys.fluent.core.filereader.data_file import InvalidFilePath # noqa: F401
from ansys.fluent.core.fluent_connection import ( # noqa: F401
PortNotProvided,
RemoteNotSupported,
WaitTypeError,
)
from ansys.fluent.core.launcher.fluent_container import ( # noqa: F401
FluentImageNameTagNotSpecified,
LicenseServerNotSpecified,
ServerInfoFileError,
)
from ansys.fluent.core.launcher.launcher import ( # noqa: F401
AnsysVersionNotFound,
DockerContainerLaunchNotSupported,
FluentMode,
FluentVersion,
InvalidPassword,
IpPortNotProvided,
UnexpectedKeywordArgument,
connect_to_fluent,
launch_fluent,
)
from ansys.fluent.core.launcher.watchdog import WatchdogLaunchFailed # noqa: F401
from ansys.fluent.core.post_objects.post_helper import ( # noqa: F401
IncompleteISOSurfaceDefinition,
SurfaceCreationError,
)
from ansys.fluent.core.services.batch_ops import BatchOps # noqa: F401
from ansys.fluent.core.services.datamodel_se import ( # noqa: F401
InvalidNamedObject,
SubscribeEventError,
UnsubscribeEventError,
)
from ansys.fluent.core.session import BaseSession as Fluent # noqa: F401
from ansys.fluent.core.solver.flobject import InactiveObjectError # noqa: F401
from ansys.fluent.core.utils import fldoc
from ansys.fluent.core.utils.search import search # noqa: F401
from ansys.fluent.core.utils.setup_for_fluent import setup_for_fluent # noqa: F401
Expand Down
11 changes: 11 additions & 0 deletions src/ansys/fluent/core/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Custom common higher level exceptions."""


class DisallowedValuesError(ValueError):
def __init__(self, error):
super().__init__(error)
hpohekar marked this conversation as resolved.
Show resolved Hide resolved


class InvalidArgument(ValueError):
def __init__(self, error):
super().__init__(error)
77 changes: 49 additions & 28 deletions src/ansys/fluent/core/file_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,17 @@ def add_scalar_fields_request(

Raises
------
RuntimeError
SurfaceNamesIDsNotProvided
If surface names or surface ids are not provided.
RuntimeError
InvalidFieldNamePrefix
If field name does not have prefix ``phase-`` for multi-phase cases.
"""
if surface_ids is None:
surface_ids = []
if surface_ids and surface_names:
raise RuntimeError("Please provide either surface names or surface ids.")
raise SurfaceNamesIDsNotProvided(
"Please provide either surface names or surface ids."
)

if surface_names:
for surface_name in surface_names:
Expand All @@ -126,7 +128,7 @@ def add_scalar_fields_request(

if len(self._file_session._data_file.get_phases()) > 1:
if not field_name.startswith("phase-"):
raise RuntimeError(
raise InvalidFieldNamePrefix(
hpohekar marked this conversation as resolved.
Show resolved Hide resolved
"For multi-phase cases field name should have a prefix of phase name."
)
self._scalar_field_transactions.append(
Expand Down Expand Up @@ -162,15 +164,17 @@ def add_vector_fields_request(

Raises
------
RuntimeError
SurfaceNamesIDsNotProvided
If surface names or surface ids are not provided.
RuntimeError
InvalidFieldNamePrefix
If field name does not have prefix ``phase-`` for multi-phase cases.
"""
if surface_ids is None:
surface_ids = []
if surface_ids and surface_names:
raise RuntimeError("Please provide either surface names or surface ids.")
raise SurfaceNamesIDsNotProvided(
"Please provide either surface names or surface ids."
)

if surface_names:
for surface_name in surface_names:
Expand All @@ -180,7 +184,7 @@ def add_vector_fields_request(

if len(self._file_session._data_file.get_phases()) > 1:
if not field_name.startswith("phase-"):
raise RuntimeError(
raise InvalidFieldNamePrefix(
"For multi-phase cases field name should have a prefix of phase name."
)
self._vector_field_transactions.append(
Expand Down Expand Up @@ -227,7 +231,7 @@ def get_fields(self):

Raises
------
RuntimeError
InvalidFieldName
If any field other than ``"velocity"`` is provided.
"""
mesh = self._file_session._case_file.get_mesh()
Expand Down Expand Up @@ -258,7 +262,7 @@ def get_fields(self):

for transaction in self._vector_field_transactions:
if "velocity" not in transaction.field_name:
raise RuntimeError("Only 'velocity' is allowed field.")
raise InvalidFieldName("Only 'velocity' is allowed field.")
hpohekar marked this conversation as resolved.
Show resolved Hide resolved
if vector_field_tag not in field_data:
field_data[vector_field_tag] = {}
field_data_surface = field_data[vector_field_tag]
Expand Down Expand Up @@ -323,11 +327,13 @@ def get_surface_data(

Raises
------
RuntimeError
SurfaceNamesIDsNotProvided
If surface names or surface ids are not provided.
"""
if surface_ids and surface_name:
raise RuntimeError("Please provide either surface name or surface ids.")
raise SurfaceNamesIDsNotProvided(
"Please provide either surface name or surface ids."
)

if data_type == SurfaceDataType.Vertices:
if surface_name:
Expand Down Expand Up @@ -407,23 +413,23 @@ def get_scalar_field_data(

Raises
------
RuntimeError
SurfaceNamesIDsNotProvided
If surface names or surface ids are not provided.
RuntimeError
If field name does not have prefix ``phase-`` for multi-phase cases.
RuntimeError
InvalidFieldNamePrefix
If field name does not have prefix ``phase-`` for multi-phase cases.
"""
if surface_ids and surface_name:
raise RuntimeError("Please provide either surface name or surface ids.")
raise SurfaceNamesIDsNotProvided(
"Please provide either surface name or surface ids."
hpohekar marked this conversation as resolved.
Show resolved Hide resolved
)

if surface_name:
surface_ids = self._field_info.get_surfaces_info()[surface_name][
"surface_id"
]
if len(self._file_session._data_file.get_phases()) > 1:
if not field_name.startswith("phase-"):
raise RuntimeError(
raise InvalidFieldNamePrefix(
"For multi-phase cases field name should have a prefix of phase name."
)
return ScalarFieldData(
Expand All @@ -444,7 +450,7 @@ def get_scalar_field_data(
else:
if len(self._file_session._data_file.get_phases()) > 1:
if not field_name.startswith("phase-"):
raise RuntimeError(
raise InvalidFieldNamePrefix(
"For multi-phase cases field name should have a prefix of phase name."
)
return {
Expand Down Expand Up @@ -495,31 +501,31 @@ def get_vector_field_data(

Raises
------
RuntimeError
SurfaceNamesIDsNotProvided
If surface names or surface ids are not provided.
RuntimeError
InvalidFieldName
If any field other than ``"velocity"`` is provided.
RuntimeError
If field name does not have prefix ``phase-`` for multi-phase cases.
RuntimeError
InvalidFieldNamePrefix
If field name does not have prefix ``phase-`` for multi-phase cases.
"""
if surface_ids and surface_name:
raise RuntimeError("Please provide either surface name or surface ids.")
raise SurfaceNamesIDsNotProvided(
"Please provide either surface name or surface ids."
)

if (
field_name.lower() != "velocity"
and field_name.split(":")[1].lower() != "velocity"
):
raise RuntimeError("Only 'velocity' is allowed field.")
raise InvalidFieldName("Only 'velocity' is allowed field.")

if surface_name:
surface_ids = self._field_info.get_surfaces_info()[surface_name][
"surface_id"
]
if len(self._file_session._data_file.get_phases()) > 1:
if not field_name.startswith("phase-"):
raise RuntimeError(
raise InvalidFieldNamePrefix(
"For multi-phase cases field name should have a prefix of phase name."
)
vector_data = self._file_session._data_file.get_face_vector_field_data(
Expand All @@ -534,7 +540,7 @@ def get_vector_field_data(
else:
if len(self._file_session._data_file.get_phases()) > 1:
if not field_name.startswith("phase-"):
raise RuntimeError(
raise InvalidFieldNamePrefix(
"For multi-phase cases field name should have a prefix of phase name."
)
return {
Expand Down Expand Up @@ -724,3 +730,18 @@ def read_case(self, case_file_name):
def read_data(self, data_file_name):
"""Read Data file."""
self._data_file = DataFile(data_file_name, case_file_handle=self._case_file)


class SurfaceNamesIDsNotProvided(ValueError):
def __init__(self, error):
super().__init__(error)


class InvalidFieldNamePrefix(ValueError):
def __init__(self, error):
super().__init__(error)


class InvalidFieldName(ValueError):
def __init__(self, error):
super().__init__(error)
30 changes: 25 additions & 5 deletions src/ansys/fluent/core/fluent_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ def __init__(
inside_container: bool, optional
Whether the Fluent session that is being connected to
is running inside a docker container.

Raises
------
PortNotProvided
If port is not provided.
"""
self.error_state = ErrorState()
self._data_valid = False
Expand All @@ -250,7 +255,7 @@ def __init__(
port = os.getenv("PYFLUENT_FLUENT_PORT")
self._channel_str = f"{ip}:{port}"
if not port:
raise ValueError(
raise PortNotProvided(
"The port to connect to Fluent session is not provided."
hpohekar marked this conversation as resolved.
Show resolved Hide resolved
)
# Same maximum message length is used in the server
Expand Down Expand Up @@ -495,13 +500,13 @@ def wait_process_finished(self, wait: Union[float, int, bool] = 60):

Raises
------
ValueError
RemoteNotSupported
If current Fluent instance is running remotely.
TypeError
WaitTypeError
If ``wait`` is specified improperly.
"""
if self._remote_instance:
raise ValueError(
raise RemoteNotSupported(
"Fluent remote instance not supported by FluentConnection.wait_process_finished()."
)
if isinstance(wait, bool):
Expand All @@ -513,7 +518,7 @@ def wait_process_finished(self, wait: Union[float, int, bool] = 60):
if isinstance(wait, (float, int)):
logger.info(f"Waiting {wait} seconds for Fluent processes to finish...")
else:
raise TypeError("Invalid 'limit' type.")
raise WaitTypeError("Invalid 'limit' type.")
if self.connection_properties.inside_container:
_response = timeout_loop(
get_container,
Expand Down Expand Up @@ -659,3 +664,18 @@ def _exit(
remote_instance.delete()

exit_event.set()


class PortNotProvided(ValueError):
def __init__(self, error):
super().__init__(error)


class RemoteNotSupported(ValueError):
def __init__(self, error):
super().__init__(error)


class WaitTypeError(TypeError):
def __init__(self, error):
super().__init__(error)
Loading