ansys.fluent.core.fluent_connection#
Provides a module for Fluent connection functionality.
Classes:
|
Object to indicate the error state of the connected Fluent client. |
|
Encapsulates a Fluent connection. |
|
Stores Fluent connection properties, including connection IP, port and password; Fluent Cortex working directory, process ID and hostname; and whether Fluent was launched in a docker container. |
A class used for monitoring a Fluent session. |
Exceptions:
Raised when port is not provided. |
|
Raised when 'wait_process_finished' does not support remote Fluent session. |
|
Raised when invalid |
Functions:
|
Get the Docker container object. |
- class ansys.fluent.core.fluent_connection.ErrorState(name='', details='')#
Bases:
object
Object to indicate the error state of the connected Fluent client.
Examples
>>> import ansys.fluent.core as pyfluent >>> session = pyfluent.launch_fluent() >>> session._fluent_connection._error_state.set("test", "test details") >>> session._fluent_connection._error_state.name 'test' >>> session._fluent_connection._error_state.details 'test details' >>> session._fluent_connection._error_state.clear() >>> session._fluent_connection._error_state.name ''
Methods:
__init__
([name, details])Initializes the error state object.
clear
()Method to clear the current error state, emptying the error name and details properties.
set
(name, details)Method to set the error state name and details to new values.
Attributes:
- __init__(name='', details='')#
Initializes the error state object.
- clear()#
Method to clear the current error state, emptying the error name and details properties.
- property details#
Get details.
- property name#
Get name.
- set(name, details)#
Method to set the error state name and details to new values.
- class ansys.fluent.core.fluent_connection.FluentConnection(ip=None, port=None, password=None, channel=None, cleanup_on_exit=True, remote_instance=None, file_transfer_service=None, slurm_job_id=None, inside_container=None)#
Bases:
object
Encapsulates a Fluent connection.
Methods
check_health()
Check health of Fluent connection.
exit()
Close the Fluent connection and exit Fluent.
Methods:
__init__
([ip, port, password, channel, ...])Initialize a Session.
Check health of Fluent connection.
create_grpc_service
(service, *args)Create a gRPC service.
exit
([timeout, timeout_force, wait])Close the Fluent connection and exit Fluent.
Immediately terminates the Fluent client, losing unsaved progress and data.
Register a callback to run with the finalizer.
wait_process_finished
([wait])Returns
True
if local Fluent processes have finished,False
if they are still running when wait limit (default 60 seconds) is reached.- __init__(ip=None, port=None, password=None, channel=None, cleanup_on_exit=True, remote_instance=None, file_transfer_service=None, slurm_job_id=None, inside_container=None)#
Initialize a Session.
- Parameters:
- ip
str
,optional
IP address to connect to existing Fluent instance. Used only when
channel
isNone
. Defaults to"127.0.0.1"
and can also be set by the environment variablePYFLUENT_FLUENT_IP=<ip>
.- port
int
,optional
Port to connect to existing Fluent instance. Used only when
channel
isNone
. Defaults value can be set by the environment variablePYFLUENT_FLUENT_PORT=<port>
.- password
str
,optional
Password to connect to existing Fluent instance.
- channel
grpc.Channel
,optional
Grpc channel to use to connect to existing Fluent instance. ip and port arguments will be ignored when channel is specified.
- cleanup_on_exitbool,
optional
When True, the connected Fluent session will be shut down when PyFluent is exited or exit() is called on the session instance, by default True.
- remote_instance
ansys.platform.instancemanagement.Instance
The corresponding remote instance when Fluent is launched through PyPIM. This instance will be deleted when calling
Session.exit()
.- file_transfer_service
optional
File transfer service for uploading files to and downloading files from the server.
- slurm_job_id: bool, optional
Job ID of a Fluent session running within a Slurm environment.
- inside_container: bool, optional
Whether the Fluent session that is being connected to is running inside a Docker container.
- ip
- Raises:
PortNotProvided
If port is not provided.
- check_health()#
Check health of Fluent connection.
- create_grpc_service(service, *args)#
Create a gRPC service.
- Parameters:
- service
Any
service class
- args
Any
,optional
additional arguments, by default empty
- service
- Returns:
Any
service object
- exit(timeout=None, timeout_force=True, wait=False)#
Close the Fluent connection and exit Fluent.
- Parameters:
- timeout
float
,optional
Time in seconds before considering that the exit request has timed out. If omitted or specified as None, then the request will not time out and will lock up the interpreter while waiting for a response. Will return earlier if request succeeds earlier.
- timeout_forcebool,
optional
If not specified, defaults to
True
. IfTrue
, attempts to terminate the Fluent process if exit request reached timeout. If no timeout is set, this option is ignored. Executesforce_exit()
orforce_exit_container()
, depending on how Fluent was launched.- wait
float
,int
or bool,optional
Specifies whether to wait for local Fluent processes to finish completely before proceeding. If omitted or specified as
False
, will proceed as usual without waiting for the Fluent processes to finish. Can be set toTrue
which will wait for up to 60 seconds, or set to a float or int value to specify the wait limit. If wait limit is reached, will forcefully terminate the Fluent process. If set to wait, will return as soon as processes completely finish. Does not work for remote Fluent processes.
- timeout
Notes
Can also set the
PYFLUENT_TIMEOUT_FORCE_EXIT
environment variable to specify the number of seconds and alter the defaulttimeout
value. Setting this env var to a non-number value, such asOFF
, will return this function to default behavior. Note that the environment variable will be ignored if timeout is specified when calling this function.Examples
>>> import ansys.fluent.core as pyfluent >>> session = pyfluent.launch_fluent() >>> session.exit()
- force_exit()#
Immediately terminates the Fluent client, losing unsaved progress and data.
Notes
If the Fluent session is responsive, prefer using
exit()
instead.Examples
>>> import ansys.fluent.core as pyfluent >>> session = pyfluent.launch_fluent() >>> session.force_exit()
- register_finalizer_cb(cb)#
Register a callback to run with the finalizer.
- wait_process_finished(wait=60)#
Returns
True
if local Fluent processes have finished,False
if they are still running when wait limit (default 60 seconds) is reached. Immediately cancels and returnsNone
ifwait
is set toFalse
.- Parameters:
- Raises:
UnsupportedRemoteFluentInstance
If current Fluent instance is running remotely.
WaitTypeError
If
wait
is specified improperly.
- class ansys.fluent.core.fluent_connection.FluentConnectionProperties(ip=None, port=None, password=None, cortex_pwd=None, cortex_pid=None, cortex_host=None, fluent_host_pid=None, inside_container=None)#
Bases:
object
Stores Fluent connection properties, including connection IP, port and password; Fluent Cortex working directory, process ID and hostname; and whether Fluent was launched in a docker container.
Examples
These properties are also available through the session object and can be accessed as:
>>> import ansys.fluent.core as pyfluent >>> session = pyfluent.launch_fluent() >>> session.connection_properties.list_names() ['ip', 'port', 'password', 'cortex_pwd', 'cortex_pid', 'cortex_host', 'inside_container'] >>> session.connection_properties.ip '127.0.0.1'
Methods:
__init__
([ip, port, password, cortex_pwd, ...])Returns list with all property names.
Returns dictionary with all property names and values.
Attributes:
- __init__(ip=None, port=None, password=None, cortex_pwd=None, cortex_pid=None, cortex_host=None, fluent_host_pid=None, inside_container=None)#
- cortex_host: str | None = None#
- cortex_pid: int | None = None#
- cortex_pwd: str | None = None#
- fluent_host_pid: int | None = None#
- inside_container: bool | Container | None = None#
- ip: str | None = None#
- list_names()#
Returns list with all property names.
- list_values()#
Returns dictionary with all property names and values.
- password: str | None = None#
- port: int | None = None#
- class ansys.fluent.core.fluent_connection.MonitorThread#
Bases:
Thread
A class used for monitoring a Fluent session.
Daemon thread which will ensure cleanup of session objects, shutdown of non-deamon threads etc.
- Attributes:
- cbs
List
[Callable
] Cleanup/shutdown functions
- cbs
Methods:
__init__
()This constructor should always be called with keyword arguments.
run
()Run monitor thread.
- __init__()#
This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is a list or tuple of arguments for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
- run()#
Run monitor thread.
- exception ansys.fluent.core.fluent_connection.PortNotProvided#
Bases:
ValueError
Raised when port is not provided.
- __init__()#
- exception ansys.fluent.core.fluent_connection.UnsupportedRemoteFluentInstance#
Bases:
ValueError
Raised when ‘wait_process_finished’ does not support remote Fluent session.
- __init__()#
- exception ansys.fluent.core.fluent_connection.WaitTypeError#
Bases:
TypeError
Raised when invalid
wait
type is provided.- __init__()#
- ansys.fluent.core.fluent_connection.get_container(container_id_or_name)#
Get the Docker container object.
- Returns:
Notes
See Docker container for more information.