connectivity#
Connect to Ansys Fluent and transfer files and cases between sessions.
This package provides the gRPC connection to a running Fluent process
(FluentConnection),
file transfer strategies for standalone, containerized, and remote (PyPIM)
Fluent deployments, and helpers for transferring case/data files between
solver sessions.
Classes:
|
Provides a file transfer service based on the gRPC client and gRPC server. |
|
Provides the file transfer strategy. |
|
Encapsulates a Fluent connection. |
|
Provides a file transfer service based on PyPIM and the |
|
|
|
Provides the local file transfer strategy can be used for Fluent launched in the standalone mode. |
Exceptions:
Raised when port is not provided. |
Functions:
|
Transfer case between instances. |
- class ansys.fluent.core.connectivity.ContainerFileTransferStrategy(image_name=None, image_tag=None, port=None, mount_target=None, mount_source=None, certs_dir=None)#
Bases:
FileTransferStrategyProvides a file transfer service based on the gRPC client and gRPC server.
Examples
>>> import ansys.fluent.core as pyfluent >>> from ansys.fluent.core import examples >>> from ansys.fluent.core.connectivity.file_transfer_service import ContainerFileTransferStrategy >>> case_file_name = examples.download_file("mixing_elbow.cas.h5", "pyfluent/mixing_elbow") >>> solver_session = pyfluent.launch_fluent(file_transfer_service=ContainerFileTransferStrategy()) >>> solver_session.upload(file_name=case_file_name, remote_file_name="elbow.cas.h5") >>> solver_session.settings.file.read_case(file_name="elbow.cas.h5") >>> solver_session.settings.file.write_case(file_name="write_elbow.cas.h5") >>> solver_session.download(file_name="write_elbow.cas.h5", local_directory="<local_directory_path>")
Methods:
__init__([image_name, image_tag, port, ...])Provides the gRPC-based remote file transfer strategy.
download(file_name[, local_directory])Download a file from the server.
file_exists_on_remote(file_name)Check if remote file exists.
upload(file_name[, remote_file_name])Upload a file to the server.
- __init__(image_name=None, image_tag=None, port=None, mount_target=None, mount_source=None, certs_dir=None)#
Provides the gRPC-based remote file transfer strategy.
- Parameters:
- image_name: str
Name of the image.
- image_tag
str,optional Tag of the image.
- port: int, optional
Port for the file transfer service to use.
- mount_target: str | Path, optional
Path inside the container where
mount_sourcewill be mounted to.- mount_source: str | Path, optional
Existing path in the host operating system that will be mounted to
mount_target.- certs_dir
str,optional Directory containing the TLS certificates. The default is
None.
- download(file_name, local_directory=None)#
Download a file from the server.
- Parameters:
Examples
>>> import ansys.fluent.core as pyfluent >>> from ansys.fluent.core import examples >>> from ansys.fluent.core.connectivity.file_transfer_service import ContainerFileTransferStrategy >>> case_file_name = examples.download_file("mixing_elbow.cas.h5", "pyfluent/mixing_elbow") >>> solver_session = pyfluent.launch_fluent(file_transfer_service=ContainerFileTransferStrategy()) >>> solver_session.settings.file.write_case(file_name="write_elbow.cas.h5") >>> solver_session.download(file_name="write_elbow.cas.h5", local_directory="<local_directory_path>")
- file_exists_on_remote(file_name)#
Check if remote file exists.
- Parameters:
- file_name: str
File name.
- Returns:
Whetherfileexists.
- upload(file_name, remote_file_name=None)#
Upload a file to the server.
- Parameters:
- Raises:
FileNotFoundErrorIf a file does not exist.
Examples
>>> import ansys.fluent.core as pyfluent >>> from ansys.fluent.core import examples >>> from ansys.fluent.core.connectivity.file_transfer_service import ContainerFileTransferStrategy >>> case_file_name = examples.download_file("mixing_elbow.cas.h5", "pyfluent/mixing_elbow") >>> solver_session = pyfluent.launch_fluent(file_transfer_service=ContainerFileTransferStrategy()) >>> solver_session.upload(file_name=case_file_name, remote_file_name="elbow.cas.h5") >>> solver_session.settings.file.read_case(file_name="elbow.cas.h5")
- class ansys.fluent.core.connectivity.FileTransferStrategy(*args, **kwargs)#
Bases:
ProtocolProvides the file transfer strategy.
Methods:
__init__(*args, **kwargs)download(file_name[, local_directory])Download a file from the server.
upload(file_name[, remote_file_name])Upload a file to the server.
- __init__(*args, **kwargs)#
- download(file_name, local_directory=None)#
Download a file from the server.
- class ansys.fluent.core.connectivity.FluentConnection(ip=None, port=None, password=None, address=None, channel=None, allow_remote_host=False, certificates_folder=None, insecure_mode=False, cleanup_on_exit=True, remote_instance=None, file_transfer_service=None, slurm_job_id=None, inside_container=None, container=None, compose_config=None)#
Bases:
objectEncapsulates a Fluent connection.
Methods
exit()
Close the Fluent connection and exit Fluent.
Methods:
__init__([ip, port, password, address, ...])Initialize a Session.
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_finalizer_cb(cb[, at_start])Register a callback to run with the finalizer.
wait_process_finished([wait])Returns
Trueif local Fluent processes have finished,Falseif they are still running when wait limit (default 100 seconds) is reached.Attributes:
Provides access to Health Check service.
- __init__(ip=None, port=None, password=None, address=None, channel=None, allow_remote_host=False, certificates_folder=None, insecure_mode=False, cleanup_on_exit=True, remote_instance=None, file_transfer_service=None, slurm_job_id=None, inside_container=None, container=None, compose_config=None)#
Initialize a Session.
- Parameters:
- ip
str,optional IP address to connect to existing Fluent instance. Used only when
channelisNone. 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
channelisNone. Defaults value can be set by the environment variablePYFLUENT_FLUENT_PORT=<port>.- password
str,optional Password to connect to existing Fluent instance.
- address
str,optional Address 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.
- container: ContainerT, optional
The container instance if the Fluent session is running inside a container.
- compose_config: ComposeConfig, optional
Configuration for Docker Compose or Podman Compose.
- allow_remote_hostbool,
optional Whether to allow connecting to a remote Fluent instance.
- certificates_folder
str,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.
- ip
- Raises:
PortNotProvidedIf port is not provided.
- create_grpc_service(service, *args)#
Create a gRPC service.
- Parameters:
- service
Any service class
- args
Any,optional additional arguments, by default empty
- service
- Returns:
Anyservice 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,intor 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 toTruewhich will wait for up to 100 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_EXITenvironment variable to specify the number of seconds and alter the defaulttimeoutvalue. 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.
- Raises:
subprocess.CalledProcessErrorIf the cleanup script fails to execute.
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()
- property health_check#
Provides access to Health Check service.
Deprecated since version 0.32: No longer required at this level.
- register_finalizer_cb(cb, at_start=False)#
Register a callback to run with the finalizer.
- wait_process_finished(wait=100)#
Returns
Trueif local Fluent processes have finished,Falseif they are still running when wait limit (default 100 seconds) is reached. Immediately cancels and returnsNoneifwaitis set toFalse.- Parameters:
- Raises:
UnsupportedRemoteFluentInstanceIf current Fluent instance is running remotely.
WaitTypeErrorIf
waitis specified improperly.
- class ansys.fluent.core.connectivity.PimFileTransferService(pim_instance=None)#
Bases:
objectProvides a file transfer service based on PyPIM and the
simple_upload_server()method.- Attributes:
- pim_instance: PIM instance
Instance of PIM which supports upload server services.
- file_service: Client instance
Instance of Client which supports upload and download methods.
Methods
upload(
file_name, remote_file_name ) Upload a file to the server.
download(
file_name, local_directory ) Download a file from the server.
Methods:
__init__([pim_instance])Initialize PimFileTransferService.
download(file_name[, local_directory])Download a file from the server.
download_file(file_name[, local_directory])Download a file from the server supported by PyPIM<https://pypim.docs.pyansys.com/version/stable/>.
file_exists_on_remote(file_name)Check if remote file exists.
Check pypim configuration.
upload(file_name[, remote_file_name])Upload a file to the server.
upload_file(file_name[, remote_file_name])Upload a file to the server supported by PyPIM<https://pypim.docs.pyansys.com/version/stable/>.
- __init__(pim_instance=None)#
Initialize PimFileTransferService.
- Parameters:
- pim_instance: Any, optional
PIM instance.
- download(file_name, local_directory=None)#
Download a file from the server.
- download_file(file_name, local_directory=None)#
Download a file from the server supported by PyPIM<https://pypim.docs.pyansys.com/version/stable/>.
- Parameters:
- Raises:
FileNotFoundErrorIf the remote file does not exist.
PyPIMConfigurationErrorIf PyPIM is not configured.
- file_exists_on_remote(file_name)#
Check if remote file exists.
- Parameters:
- file_name: str
File name.
- Returns:
Whetherfileexists.
- is_configured()#
Check pypim configuration.
- upload(file_name, remote_file_name=None)#
Upload a file to the server.
- Parameters:
- Raises:
FileNotFoundErrorIf a file does not exist.
- upload_file(file_name, remote_file_name=None)#
Upload a file to the server supported by PyPIM<https://pypim.docs.pyansys.com/version/stable/>.
- Parameters:
- Raises:
FileNotFoundErrorIf the file does not exist.
PyPIMConfigurationErrorIf PyPIM is not configured.
- exception ansys.fluent.core.connectivity.PortNotProvided#
Bases:
ValueErrorRaised when port is not provided.
Methods:
__init__()Initialize PortNotProvided.
- __init__()#
Initialize PortNotProvided.
- class ansys.fluent.core.connectivity.RemoteFileTransferStrategy(server_ip=None, server_port=None, certs_dir=None)#
Bases:
FileTransferStrategyProvides a file transfer service based on the gRPC client and gRPC server.
Methods:
__init__([server_ip, server_port, certs_dir])Provides the gRPC-based remote file transfer strategy.
download(file_name[, local_directory])Download a file from the server.
upload(file_name[, remote_file_name])Upload a file to the server.
- __init__(server_ip=None, server_port=None, certs_dir=None)#
Provides the gRPC-based remote file transfer strategy.
- download(file_name, local_directory=None)#
Download a file from the server.
- class ansys.fluent.core.connectivity.StandaloneFileTransferStrategy(server_cwd=None)#
Bases:
FileTransferStrategyProvides the local file transfer strategy can be used for Fluent launched in the standalone mode.
Examples
>>> import ansys.fluent.core as pyfluent >>> from ansys.fluent.core import examples >>> from ansys.fluent.core.connectivity.file_transfer_service import StandaloneFileTransferStrategy >>> mesh_file_name = examples.download_file("mixing_elbow.msh.h5", "pyfluent/mixing_elbow") >>> meshing_session = pyfluent.launch_fluent(mode=pyfluent.FluentMode.MESHING, file_transfer_service=StandaloneFileTransferStrategy()) >>> meshing_session.upload(file_name=mesh_file_name, remote_file_name="elbow.msh.h5") >>> meshing_session.meshing.File.ReadMesh(FileName="elbow.msh.h5") >>> meshing_session.meshing.File.WriteMesh(FileName="write_elbow.msh.h5") >>> meshing_session.download(file_name="write_elbow.msh.h5", local_directory="<local_directory_path>")
Methods:
__init__([server_cwd])Local File Transfer Service.
download(file_name[, local_directory])Download a file from the server.
file_exists_on_remote(file_name)Check if remote file exists.
upload(file_name[, remote_file_name])Upload a file to the server.
- __init__(server_cwd=None)#
Local File Transfer Service.
- Parameters:
- server_cwd: str, Optional
Current working directory of server/Fluent.
- download(file_name, local_directory=None)#
Download a file from the server.
- Parameters:
Examples
>>> import ansys.fluent.core as pyfluent >>> from ansys.fluent.core import examples >>> from ansys.fluent.core.connectivity.file_transfer_service import StandaloneFileTransferStrategy >>> mesh_file_name = examples.download_file("mixing_elbow.msh.h5", "pyfluent/mixing_elbow") >>> meshing_session = pyfluent.launch_fluent(mode=pyfluent.FluentMode.MESHING, file_transfer_service=StandaloneFileTransferStrategy()) >>> meshing_session.meshing.File.WriteMesh(FileName="write_elbow.msh.h5") >>> meshing_session.download(file_name="write_elbow.msh.h5", local_directory="<local_directory_path>")
- file_exists_on_remote(file_name)#
Check if remote file exists.
- Parameters:
- file_name: str
File name.
- Returns:
Whetherfileexists.
- upload(file_name, remote_file_name=None)#
Upload a file to the server.
- Parameters:
- Raises:
FileNotFoundErrorIf a file does not exist.
Examples
>>> import ansys.fluent.core as pyfluent >>> from ansys.fluent.core import examples >>> from ansys.fluent.core.connectivity.file_transfer_service import StandaloneFileTransferStrategy >>> mesh_file_name = examples.download_file("mixing_elbow.msh.h5", "pyfluent/mixing_elbow") >>> meshing_session = pyfluent.launch_fluent(mode=pyfluent.FluentMode.MESHING, file_transfer_service=StandaloneFileTransferStrategy()) >>> meshing_session.upload(file_name=mesh_file_name, remote_file_name="elbow.msh.h5") >>> meshing_session.meshing.File.ReadMesh(FileName="elbow.msh.h5")
- ansys.fluent.core.connectivity.transfer_case(source_instance, solvers, file_type, file_name_stem, num_files_to_try, clean_up_temp_file, overwrite_previous, workdir=None, container_workdir=None)#
Transfer case between instances.
- Parameters:
- source_instance
object Fluent instance (tested for meshing instance)
- solversiterable
Sequence of solver instances
- file_type
str “case” or “mesh”
- file_name_stem
str Optional file name stem
- num_files_to_try
int Optional number of files to try to write, each with a different generated name. Defaults to 1
- clean_up_temp_file: bool
Whether to remove the file at the end
- overwrite_previous: bool
Whether to overwrite the file if it already exists
- workdir
str,optional Working directory that is accessible by the Fluent client as well as PyFluent.
- container_workdir
str,optional If using a Fluent container image, specifies the working directory that is accessible by the Fluent client inside the container, which should also be mounted to the container from the host system path specified in
workdir.
- source_instance
- Returns:
- Raises:
MeshWriteErrorIf mesh cannot be written from
source_instance.