session#

Base implementation and active-session context manager for Fluent sessions.

BaseSession is an internal base class; use the concrete session classes exposed by ansys.fluent.core.execution.session. The module-level using() context manager makes a session active for top-level settings objects and is re-exported as ansys.fluent.core.using for compatibility.

Classes:

BaseSession(fluent_connection, scheme_eval)

Encapsulates a Fluent session.

Functions:

using(session)

Make a Fluent session active within a with block.

class ansys.fluent.core.execution.session.session.BaseSession(fluent_connection, scheme_eval, file_transfer_service=None, start_transcript=True, launcher_args=None, event_type=None, get_zones_info=None)#

Bases: object

Encapsulates a Fluent session.

This class exposes methods for interacting with a Fluent session.

Attributes:
scheme: SchemeInterpreter

Instance of SchemeInterpreter to execute Fluent’s scheme code on.

Methods

_create_from_server_info_file(

server_info_file_name, cleanup_on_exit, start_transcript ) Create a Session instance from server-info file

exit()

Close the Fluent connection and exit Fluent.

Methods:

__init__(fluent_connection, scheme_eval[, ...])

BaseSession.

__new__(cls, *args, **kwargs)

chdir(path)

Change Fluent working directory.

download(file_name[, local_directory])

Download a file from the server.

enable_beta_features()

Enable access to Fluent beta-features

execute_tui(command)

Executes a tui command.

exit(**kwargs)

Exit session.

file_exists_on_remote(file_name)

Check if remote file exists.

force_exit()

Forces the Fluent session to exit, losing unsaved progress and data.

from_connection([ip, port, ...])

Connect to an existing Fluent server instance.

from_container(*[, dry_run])

Launch a Fluent session in container mode.

from_install(*[, dry_run])

Launch a Fluent session in standalone mode.

from_pim(**kwargs)

Launch a Fluent session in PIM mode.

get_fluent_version()

Gets and returns the fluent version.

is_active()

Whether the current session is active.

is_server_healthy()

Whether the current session is healthy (i.e. the server is 'SERVING').

start_journal(file_name)

Executes tui command to start journal.

stop_journal()

Executes tui command to stop journal.

upload(file_name[, remote_file_name])

Upload a file to the server.

wait_process_finished([wait])

Returns True if local Fluent processes have finished, False if they are still running when wait limit (default 100 seconds) is reached.

Attributes:

application_runtime

Provides access to the Fluent application runtime.

health_check

Provides access to Health Check service.

id

Return the session ID.

rp_vars

Provides access and modification of rpvars.

scheme_eval

Provides access to Fluent field information.

__init__(fluent_connection, scheme_eval, file_transfer_service=None, start_transcript=True, launcher_args=None, event_type=None, get_zones_info=None)#

BaseSession.

Parameters:
fluent_connectionFluentConnection

Encapsulates a FluentConnection.

scheme_eval: SchemeInterpreter

Instance of SchemeInterpreter to execute Fluent’s scheme code on.

file_transfer_serviceOptional

Service for uploading and downloading files.

start_transcriptbool, optional

Whether to start the Fluent transcript in the client. The default is True, in which case the Fluent transcript can be subsequently started and stopped using method calls on the Session object.

event_typeEnum, optional

Event enumeration specific to the session type.

static __new__(cls, *args, **kwargs)#
property application_runtime#

Provides access to the Fluent application runtime.

See the application runtime API for details.

chdir(path)#

Change Fluent working directory.

Parameters:
pathos.PathLike[str | bytes] | str | bytes

Path of the directory to change.

download(file_name, local_directory=None)#

Download a file from the server.

Parameters:
file_namestr

Name of the file to download from the server.

local_directorystr, optional

Local destination directory. The default is the current working directory.

enable_beta_features()#

Enable access to Fluent beta-features

execute_tui(command)#

Executes a tui command.

exit(**kwargs)#

Exit session.

This public method is a convenience wrapper that delegates directly to _exit().

file_exists_on_remote(file_name)#

Check if remote file exists.

Parameters:
file_name: str

File name.

Returns:
Whether file exists.
force_exit()#

Forces the Fluent session to exit, losing unsaved progress and data.

classmethod from_connection(ip=None, port=None, server_info_file_name=None, password=None, allow_remote_host=False, certificates_folder=None, insecure_mode=False)#

Connect to an existing Fluent server instance.

Parameters:
ipstr, optional

IP address for connecting to an existing Fluent instance. The IP address defaults to "127.0.0.1". You can also use the environment variable PYFLUENT_FLUENT_IP=<ip> to set this parameter. The explicit value of ip takes precedence over PYFLUENT_FLUENT_IP=<ip>.

portint, optional

Port to listen on for an existing Fluent instance. You can use the environment variable PYFLUENT_FLUENT_PORT=<port> to set a default value. The explicit value of port takes precedence over PYFLUENT_FLUENT_PORT=<port>.

server_info_file_name: str

Path to server-info file written out by Fluent server. The default is None. PyFluent uses the connection information in the file to connect to a running Fluent session.

passwordstr, optional

Password to connect to existing Fluent instance.

allow_remote_hostbool, optional

Whether to allow connecting to a remote Fluent instance.

certificates_folderstr, optional

Path to the folder containing TLS certificates for Fluent’s gRPC server.

insecure_modebool, optional

If True, Fluent’s gRPC server will be connected in insecure mode without TLS. This mode is not recommended. For more details on the implications and usage of insecure mode, refer to the Fluent documentation.

Raises:
TypeError

If the session type does not match the expected session type.

classmethod from_container(*, dry_run=False, **kwargs)#

Launch a Fluent session in container mode.

Parameters:
ui_modeUIMode or str, optional

Defines the user interface mode for Fluent. Accepts either a UIMode value or a corresponding string such as "no_gui", "hidden_gui", or "gui".

graphics_driverFluentWindowsGraphicsDriver or FluentLinuxGraphicsDriver

Specifies the graphics driver for Fluent. Options are from the FluentWindowsGraphicsDriver enum (for Windows) or the FluentLinuxGraphicsDriver enum (for Linux).

product_versionFluentVersion or str or float or int, optional

Indicates the version of Ansys Fluent to launch. For example, to use version 2025 R1, pass any of FluentVersion.v251, "25.1.0", "25.1", 25.1, or 251. Defaults to None, which uses the newest installed version.

dimensionDimension or int, optional

Specifies the geometric dimensionality of the Fluent simulation. Defaults to None, which corresponds to Dimension.THREE. Acceptable values include Dimension.TWO, Dimension.THREE, or integers 2 and 3.

precisionPrecision or str, optional

Defines the floating point precision. Defaults to None, which corresponds to Precision.DOUBLE. Acceptable values include Precision.SINGLE, Precision.DOUBLE, or strings "single" and "double".

processor_countint, optional

Specifies the number of processors to use. Defaults to None, which uses 1 processor. In job scheduler environments, this value limits the total number of allocated cores.

start_timeoutint, optional

Maximum allowable time in seconds for connecting to the Fluent server. Defaults to 100 seconds.

additional_argumentsstr, optional

Additional command-line arguments for Fluent, formatted as they would be on the command line.

container_dictdict, optional

Configuration dictionary for launching Fluent inside a Docker container. See also fluent_container.

dry_runbool, optional

If True, does not launch Fluent but prints configuration information instead. If dry running a container start, this method will return the configured container_dict. Defaults to False.

cleanup_on_exitbool

Determines whether to shut down the connected Fluent session upon exit or when calling the session’s exit() method. Defaults to True.

start_transcriptbool

Indicates whether to start streaming the Fluent transcript in the client. Defaults to True; streaming can be controlled via transcript.start() and transcript.stop() methods on the session object.

pybool, optional

If True, runs Fluent in Python mode. Defaults to None.

gpubool, optional

If True, starts Fluent with GPU Solver enabled.

start_watchdogbool, optional

If True and cleanup_on_exit is True, an independent watchdog process is run to ensure that any local GUI-less Fluent sessions started by PyFluent are properly closed when the current Python process ends.

file_transfer_serviceAny, optional

Service for uploading/downloading files to/from the server.

use_docker_compose: bool

Whether to use Docker Compose to launch Fluent.

use_podman_compose: bool

Whether to use Podman Compose to launch Fluent.

certificates_folderstr, optional

Path to the folder containing TLS certificates for Fluent’s gRPC server.

insecure_modebool, optional

If True, Fluent’s gRPC server will be started in insecure mode without TLS. This mode is not recommended. For more details on the implications and usage of insecure mode, refer to the Fluent documentation.

Returns:
Meshing | PureMeshing | Solver | SolverIcing | dict

Session object or configuration dictionary if dry_run is True.

Raises:
UnexpectedKeywordArgument

If an unexpected keyword argument is provided.

ValueError

If ‘mode’ is passed in kwargs.

Notes

In job scheduler environments (e.g., SLURM, LSF, PBS), resources and compute nodes are allocated, and core counts are queried from these environments before being passed to Fluent.

classmethod from_install(*, dry_run=False, **kwargs)#

Launch a Fluent session in standalone mode.

Parameters:
ui_modeUIMode or str, optional

Defines the user interface mode for Fluent. Accepts either a UIMode value or a corresponding string such as "no_gui", "hidden_gui", or "gui".

graphics_driverFluentWindowsGraphicsDriver or FluentLinuxGraphicsDriver

Specifies the graphics driver for Fluent. Options are from the FluentWindowsGraphicsDriver enum (for Windows) or the FluentLinuxGraphicsDriver enum (for Linux).

product_versionFluentVersion or str or float or int, optional

Indicates the version of Ansys Fluent to launch. For example, to use version 2025 R1, pass FluentVersion.v251, "25.1.0", "25.1", 25.1, or 251. Defaults to None, which uses the newest installed version.

dimensionDimension or int, optional

Specifies the geometric dimensionality of the Fluent simulation. Defaults to None, which corresponds to Dimension.THREE. Acceptable values are from the Dimension enum (Dimension.TWO or Dimension.THREE) or integers 2 and 3.

precisionPrecision or str, optional

Defines the floating point precision. Defaults to None, which corresponds to Precision.DOUBLE. Acceptable values are from the Precision enum (Precision.SINGLE or Precision.DOUBLE) or strings "single" and "double".

processor_countint, optional

Specifies the number of processors to use. Defaults to None, which uses 1 processor. In job scheduler environments, this value limits the total number of allocated cores.

journal_file_namesstr or list of str, optional

Path(s) to a Fluent journal file(s) that Fluent will execute. Defaults to None.

start_timeoutint, optional

Maximum time in seconds allowed for connecting to the Fluent server. Defaults to 100 seconds.

additional_argumentsstr, optional

Additional command-line arguments for Fluent, formatted as they would be on the command line.

envdict[str, str], optional

A mapping for modifying environment variables in Fluent. Defaults to None.

cleanup_on_exitbool, optional

Determines whether to shut down the connected Fluent session when exiting PyFluent or calling the session’s exit() method. Defaults to True.

dry_runbool, optional

If True, does not launch Fluent but prints configuration information instead. The call() method returns a tuple containing the launch string and server info file name. Defaults to False.

start_transcriptbool, optional

Indicates whether to start streaming the Fluent transcript in the client. Defaults to True; streaming can be controlled via transcript.start() and transcript.stop() methods on the session object.

case_file_nameos.PathLike or str, optional

Name of the case file to read into the Fluent session. Defaults to None.

case_data_file_nameos.PathLike or str, optional

Name of the case data file. If both case and data files are provided, they are read into the session.

lightweight_modebool, optional

If True, runs in lightweight mode where mesh settings are read into a background solver session, replacing it once complete. This parameter is only applicable when case_file_name is provided; defaults to False.

pybool, optional

If True, runs Fluent in Python mode. Defaults to None.

gpubool, optional

If True, starts Fluent with GPU Solver enabled.

cwdos.PathLike or str, optional

Working directory for the Fluent client.

fluent_path: :class:`os.PathLike` or str, optional

User-specified path for Fluent installation.

topybool or str, optional

A flag indicating whether to write equivalent Python journals from provided journal files; can also specify a filename for the new Python journal.

start_watchdogbool, optional

When cleanup_on_exit is True, defaults to True; an independent watchdog process ensures that any local GUI-less Fluent sessions started by PyFluent are properly closed when the current Python process ends.

file_transfer_serviceAny

Service for uploading/downloading files to/from the server.

Raises:
UnexpectedKeywordArgument

If an unexpected keyword argument is provided.

ValueError

If ‘mode’ is passed in kwargs along with container parameter.

Notes

In job scheduler environments (e.g., SLURM, LSF, PBS), resources and compute nodes are allocated, and core counts are queried from these environments before being passed to Fluent.

classmethod from_pim(**kwargs)#

Launch a Fluent session in PIM mode.

Parameters:
ui_modeUIMode or str, optional

Defines the user interface mode for Fluent. Accepts either a UIMode value or a corresponding string such as "no_gui", "hidden_gui", or "gui".

graphics_driverFluentWindowsGraphicsDriver or FluentLinuxGraphicsDriver

Specifies the graphics driver for Fluent. Options are from the FluentWindowsGraphicsDriver enum (for Windows) or the FluentLinuxGraphicsDriver enum (for Linux).

product_versionFluentVersion or str or float or int, optional

Indicates the version of Ansys Fluent to launch. For example, to use version 2025 R1, pass any of FluentVersion.v251, "25.1.0", "25.1", 25.1, or 251. Defaults to None, which uses the newest installed version.

dimensionDimension or int, optional

Specifies the geometric dimensionality of the Fluent simulation. Defaults to None, which corresponds to Dimension.THREE. Acceptable values include Dimension.TWO, Dimension.THREE, or integers 2 and 3.

precisionPrecision or str, optional

Defines the floating point precision. Defaults to None, which corresponds to Precision.DOUBLE. Acceptable values include Precision.SINGLE, Precision.DOUBLE, or strings "single" and "double".

processor_countint, optional

Specifies the number of processors to use. Defaults to None, which uses 1 processor. In job scheduler environments, this value limits the total number of allocated cores.

start_timeoutint, optional

Maximum allowable time in seconds for connecting to the Fluent server. Defaults to 100 seconds.

additional_argumentsstr, optional

Additional command-line arguments for Fluent, formatted as they would be on the command line.

cleanup_on_exitbool

Determines whether to shut down the connected Fluent session upon exit or when calling the session’s exit() method. Defaults to True.

dry_runbool, optional

If True, does not launch Fluent but prints configuration information instead. If dry running a PIM start, this method will return a configuration dictionary. Defaults to False.

start_transcriptbool

Indicates whether to start streaming the Fluent transcript in the client. Defaults to True; streaming can be controlled via transcript.start() and transcript.stop() methods on the session object.

gpubool, optional

If True, starts Fluent with GPU Solver enabled.

start_watchdogbool, optional

If True and cleanup_on_exit is True, an independent watchdog process is run to ensure that any local GUI-less Fluent sessions started by PyFluent are properly closed when the current Python process ends.

file_transfer_serviceAny, optional

Service for uploading/downloading files to/from the server.

Returns:
Union[Meshing, PureMeshing, Solver, SolverIcing, dict]

Session object or configuration dictionary if dry_run is True.

Raises:
UnexpectedKeywordArgument

If an unexpected keyword argument is provided.

Notes

In job scheduler environments (e.g., SLURM, LSF, PBS), resources and compute nodes are allocated, and core counts are queried from these environments before being passed to Fluent.

get_fluent_version()#

Gets and returns the fluent version.

property health_check#

Provides access to Health Check service.

See the health check API for details.

Deprecated since version 0.32: Use session.is_server_healthy.

property id: str#

Return the session ID.

is_active()#

Whether the current session is active.

is_server_healthy()#

Whether the current session is healthy (i.e. the server is ‘SERVING’).

Deprecated since version v0.38.0: Function ‘is_server_healthy’ is deprecated since version v0.38.0. Use ‘is_active’ instead.

property rp_vars#

Provides access and modification of rpvars.

See the rpvars API for details.

property scheme_eval#

Provides access to Fluent field information.

Deprecated since version 0.32: Use session.scheme.

start_journal(file_name)#

Executes tui command to start journal.

stop_journal()#

Executes tui command to stop journal.

upload(file_name, remote_file_name=None)#

Upload a file to the server.

Parameters:
file_namestr

Name of the local file to upload to the server.

remote_file_namestr, optional

remote file name, by default None

wait_process_finished(wait=100)#

Returns True if local Fluent processes have finished, False if they are still running when wait limit (default 100 seconds) is reached. Immediately cancels and returns None if wait is set to False.

Parameters:
waitfloat, int or bool, optional

How long to wait for processes to finish before returning, by default 100 seconds. Can also be set to True, which will result in waiting indefinitely.

Raises:
UnsupportedRemoteFluentInstance

If current Fluent instance is running remotely.

WaitTypeError

If wait is specified improperly.

ansys.fluent.core.execution.session.session.using(session)#

Make a Fluent session active within a with block.

Top-level settings objects use this session when no settings_source is provided. The previous active session is restored when the block exits, including when an exception is raised.

Examples

>>> from ansys.fluent.core import using
>>> with using(solver_session):
...     Viscous().model.set_state("laminar")