session_utilities#

Session utilities.

Classes:

PostProcessing()

Encapsulates a CFX server for a PostProcessing session connection.

PreProcessing()

Encapsulates a CFX server for a PreProcessing session connection.

SessionBase()

Provides the base class for CFX sessions.

Solver()

Encapsulates a CFX server for a Solver session connection.

class ansys.cfx.core.session_utilities.PostProcessing#

Bases: SessionBase

Encapsulates a CFX server for a PostProcessing session connection.

class ansys.cfx.core.session_utilities.PreProcessing#

Bases: SessionBase

Encapsulates a CFX server for a PreProcessing session connection.

class ansys.cfx.core.session_utilities.SessionBase#

Bases: object

Provides the base class for CFX sessions.

This class is not intended to be used directly. Instead, use one of the from_install(), from_session(), from_connection(), or from_container() methods to create a session.

Methods:

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

Connect to an existing CFX server instance.

from_container([ui_mode, product_version, ...])

Launch a CFX session in container mode.

from_install([ui_mode, product_version, ...])

Launch a CFX session in standalone mode.

from_session(session[, case_file_name])

Launch a CFX session from another CFX session.

classmethod from_connection(ip: str | None = None, port: int | None = None, address: str | None = None, server_info_file_name: str | None = None, password: str | None = None, allow_remote_host: bool = False, certificates_folder: str | None = None, insecure_mode: bool = False)#

Connect to an existing CFX server instance.

Parameters:
ipstr, default: None

IP address for connecting to an existing CFX instance. When None, theThe ``"127.0.0.1" is used. You can also use the PYCFX_CFX_IP=<ip> environment variable to set this parameter. The explicit value of ip takes precedence over the PYCFX_CFX_IP=<ip> environment variable.

portint, default: None

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

addressstr, default: None

Address to connect to an existing CFX instance.

server_info_file_name: str, default: None

Path to the server information file written out by the CFX server. PyCFX uses the connection information in the file to connect to a running CFX session.

passwordstr, default: None

Password to connect to an existing CFX instance.

allow_remote_hostbool, default: False

Whether to allow connecting to a remote CFX instance.

certificates_folderstr, default: None

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

insecure_modebool, default: False

Whether to connect CFX’s gRPC server in insecure mode without TLS. This mode is not recommended. For more information on the implications and usage of insecure mode, see the CFX documentation.

Returns:
Union [PreProcessing, Solver, PostProcessing, dict]

Session object.

Raises:
TypeError

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

classmethod from_container(ui_mode: UIMode | str | None = None, product_version: CFXVersion | str | float | int | None = None, start_timeout: int = 60, additional_arguments: str = '', container_dict: dict | None = None, dry_run: bool = False, cleanup_on_exit: bool = True, start_transcript: bool = True, start_watchdog: bool | None = None, file_transfer_service: Any | None = None, solver_input_file_name: str | None = None)#

Launch a CFX session in container mode.

Parameters:
ui_modeUIMode, default: None

User interface mode for CFX. Options correspond to values in the UIMode enum.

product_versionCFXVersion or str or float or int, default: None

Version of Ansys CFX to launch. For example, to use version 2025 R2, pass any of CFXVersion.v252, "25.2.0", "25.2", 25.2, or 252. The default is None, in which case the newest installed version is launched. which uses the newest installed version.

start_timeoutint, default: 60

Maximum allowable time in seconds for connecting to the CFX server.

additional_argumentsstr, default: “”

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

container_dictdict, default: None

Configuration dictionary for launching CFX inside a Docker container. See also cfx_container.

dry_runbool, default: False

Whether to dry run a container start. If True, CFX is not launched but the configuration information that would be used is printed as if CFX is being launched. If dry running a container start, this method returns the configured container_dict argument.

cleanup_on_exitbool, default: True

Whether to shut down the connected CFX session on exit or when calling the session’s exit() method.

start_transcriptbool, default: True

Whether to start streaming the CFX transcript in the client. streaming can be controlled using the transcript.start() and transcript.stop() methods on the session object.

start_watchdogbool, default: None

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

file_transfer_serviceAny, default: None

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

solver_input_file_namestr, default: None

Name of the solver input file to start a CFX-Solver session.

Returns:
Union [PreProcessing, Solver, PostProcessing, dict]

Session object or configuration dictionary if dry_run = True.

Raises:
UnexpectedKeywordArgument

If an unexpected keyword argument is provided.

Notes

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

classmethod from_install(ui_mode: UIMode | str | None = None, product_version: CFXVersion | str | float | int | None = None, journal_file_names: None | str | list[str] = None, start_timeout: int = 60, additional_arguments: str = '', env: Dict[str, Any] = {}, cleanup_on_exit: bool = True, dry_run: bool = False, start_transcript: bool = True, case_file_name: str | None = None, run_directory: str | None = None, results_file_name: str | None = None, solver_input_file_name: str | None = None, cwd: str | None = None, topy: str | list | None = None, start_watchdog: bool | None = None, file_transfer_service: Any | None = None)#

Launch a CFX session in standalone mode.

Parameters:
ui_modeUIMode

User interface mode for CFX. Options correspond to values in the UIMode enum.

product_versionCFXVersion or str or float or int, default None

Version of Ansys CFX to launch. For example, to use version 2025 R2, pass CFXVersion.v252, "25.2.0", "25.2", 25.2, or 252. The default is None, in which case the newest installed version is launched.

journal_file_namesstr or list of str, default: None

Paths to CFX journal files that CFX is to execute.

start_timeoutint, default: 60

Maximum time in seconds allowed for connecting to the CFX server.

additional_argumentsstr, default: “”

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

envdict[str, str], default: {}

Mapping for modifying environment variables in CFX.

cleanup_on_exitbool, default: True

Whether to shut down the connected CFX session when exiting PyCFX or calling the session’s exit() method.

dry_runbool, default: False

Whether to dry run a container start. If True, CFX is not launched but the configuration information that would be used is printed as if CFX is being launched. The call() method returns a tuple containing the launch string and name of the server information file.

start_transcriptbool, default: True

Whether to start streaming the CFX transcript in the client. Streaming can be controlled using the transcript.start() and transcript.stop() methods on the session object.

case_file_namestr, default: None

Name of the case file to read into a CFX-Pre session.

run_directorystr, default: None

Name of the run directory to monitor with a CFX-Solver or CFD-Post session.

results_file_namestr, default: None

Name of the results file to read into a CFD-Post session or start a CFX-Solver session.

solver_input_file_namestr, default: None

Name of the solver input file to start a CFX-Solver session.

cwdstr, default: None, default: None

Working directory for the CFX client.

topybool or str, default: None

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

start_watchdogbool, default: None

When cleanup_on_exit is True, this parameter defaults to True. An independent watchdog process ensures that any local GUI-less CFX sessions started by PyCFX are properly closed when the current Python process ends.

file_transfer_serviceAny, default: None

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

Returns:
Union [PreProcessing, Solver, PostProcessing, dict]

Session object or configuration dictionary if dry_run = True.

Raises:
UnexpectedKeywordArgument

If an unexpected keyword argument is provided.

Notes

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

classmethod from_session(session: Self, case_file_name: str = None)#

Launch a CFX session from another CFX session.

Supported combinations are:

  • Launch a Solver session from a PreProcessing session. The current state of the case is captured when the Solver session is initialized.

  • Launch a PostProcessing session from a Solver session. The current results (if any) are automatically loaded into the PostProcessing session. If the Solver is currently running, this method waits until the run is complete before returning the initialized PostProcessing session.

Parameters:
sessionSessionBase

Existing CFX session.

case_file_name: str

Name of the case file to use when starting a Solver session from a PreProcessing session. This is used to determine the run name for the CFX-Solver. It does not need to be supplied if a case file has already been saved by the PreProcessing session (for CFX 2026 R1 and later). The .cfx extension is not required and is ignored if present.

Returns:
Union [PreProcessing, Solver, PostProcessing]

Session object.

Raises:
TypeError

If the session type does not match a supported session type.

class ansys.cfx.core.session_utilities.Solver#

Bases: SessionBase

Encapsulates a CFX server for a Solver session connection.