session_utilities#
Session utilities.
Classes:
Encapsulates a CFX server for a PostProcessing session connection. |
|
Encapsulates a CFX server for a PreProcessing session connection. |
|
Provides the base class for CFX sessions. |
|
|
Encapsulates a CFX server for a Solver session connection. |
- class ansys.cfx.core.session_utilities.PostProcessing#
Bases:
SessionBaseEncapsulates a CFX server for a PostProcessing session connection.
- class ansys.cfx.core.session_utilities.PreProcessing#
Bases:
SessionBaseEncapsulates a CFX server for a PreProcessing session connection.
- class ansys.cfx.core.session_utilities.SessionBase#
Bases:
objectProvides 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:
- ip
str, default:None IP address for connecting to an existing CFX instance. When
None, theThe ``"127.0.0.1"is used. You can also use thePYCFX_CFX_IP=<ip>environment variable to set this parameter. The explicit value ofiptakes precedence over thePYCFX_CFX_IP=<ip>environment variable.- port
int, 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 ofporttakes precedence over thePYCFX_CFX_PORT=<port>environment variable.- address
str, 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.
- password
str, 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_folder
str, 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.
- ip
- Returns:
Union[PreProcessing,Solver,PostProcessing,dict]Session object.
- Raises:
TypeErrorIf 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_mode
UIMode, default:None User interface mode for CFX. Options correspond to values in the
UIModeenum.- product_version
CFXVersionorstrorfloatorint, 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, or252. The default isNone, in which case the newest installed version is launched. which uses the newest installed version.- start_timeout
int, default: 60 Maximum allowable time in seconds for connecting to the CFX server.
- additional_arguments
str, default: “” Additional command-line arguments for CFX, formatted as they would be on the command line.
- container_dict
dict, 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 configuredcontainer_dictargument.- 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()andtranscript.stop()methods on the session object.- start_watchdogbool, default:
None If
Trueandcleanup_on_exitisTrue, 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_service
Any, default:None Service for uploading or downloading files to or from the server.
- solver_input_file_name
str, default:None Name of the solver input file to start a CFX-Solver session.
- ui_mode
- Returns:
Union[PreProcessing,Solver,PostProcessing,dict]Session object or configuration dictionary if
dry_run = True.
- Raises:
UnexpectedKeywordArgumentIf 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_mode
UIMode User interface mode for CFX. Options correspond to values in the
UIModeenum.- product_version
CFXVersionorstrorfloatorint,defaultNone Version of Ansys CFX to launch. For example, to use version 2025 R2, pass
CFXVersion.v252,"25.2.0","25.2",25.2, or252. The default isNone, in which case the newest installed version is launched.- journal_file_names
strorlistofstr, default:None Paths to CFX journal files that CFX is to execute.
- start_timeout
int, default: 60 Maximum time in seconds allowed for connecting to the CFX server.
- additional_arguments
str, default: “” Additional command-line arguments for CFX, formatted as they would be on the command line.
- env
dict[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()andtranscript.stop()methods on the session object.- case_file_name
str, default:None Name of the case file to read into a CFX-Pre session.
- run_directory
str, default:None Name of the run directory to monitor with a CFX-Solver or CFD-Post session.
- results_file_name
str, default:None Name of the results file to read into a CFD-Post session or start a CFX-Solver session.
- solver_input_file_name
str, default:None Name of the solver input file to start a CFX-Solver session.
- cwd
str, 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_exitisTrue, this parameter defaults toTrue. 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_service
Any, default:None Service for uploading or downloading files to or from the server.
- ui_mode
- Returns:
Union[PreProcessing,Solver,PostProcessing,dict]Session object or configuration dictionary if
dry_run = True.
- Raises:
UnexpectedKeywordArgumentIf 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:
- session
SessionBase 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
.cfxextension is not required and is ignored if present.
- session
- Returns:
Union[PreProcessing,Solver,PostProcessing]Session object.
- Raises:
TypeErrorIf the session type does not match a supported session type.
- class ansys.cfx.core.session_utilities.Solver#
Bases:
SessionBaseEncapsulates a CFX server for a Solver session connection.