Server#
Contains the directives necessary to start the DPF server.
- ansys.dpf.core.server.has_local_server()#
Check if a local DPF gRPC server has been created.
- Returns
True
when a local DPF gRPC server has been created.- Return type
bool
- ansys.dpf.core.server.port_in_use(port, host='127.0.0.1')#
Check if a port is in use at the given host.
The port must actually “bind” the address. Just checking to see if a socket can be created is insufficient because it’s possible to run into permission errors like:
An attempt was made to access a socket in a way forbidden by its access permissions.
- Returns
True
when the port is in use,False
when free.- Return type
bool
- ansys.dpf.core.server.check_valid_ip(ip)#
Check if a valid IP address is entered.
This method raises an error when an invalid IP address is entered.
- ansys.dpf.core.server.shutdown_all_session_servers()#
Shut down all active servers created by this module.
- ansys.dpf.core.server.start_local_server(ip='127.0.0.1', port=32772, ansys_path=None, as_global=True, load_operators=True, use_docker_by_default=True, docker_name=None, timeout=10.0)#
Start a new local DPF server at a given port and IP address.
This method requires Windows and ANSYS 2021 R1 or later. If
as_global=True
, which is the default) the server is stored globally, replacing the one stored previously. Otherwise, a user must keep a handle on their server.- Parameters
ip (str, optional) – IP address of the remote or local instance to connect to. The default is
"LOCALHOST"
.port (int) – Port to connect to the remote instance on. The default is
"DPF_DEFAULT_PORT"
, which is 50054.ansys_path (str or os.PathLike, optional) – Root path for the Ansys installation directory. For example,
"/ansys_inc/v212/"
. The default is the latest Ansys installation.as_global (bool, optional) – Global variable that stores the IP address and port for the DPF module. All DPF objects created in this Python session will use this IP and port. The default is
True
.load_operators (bool, optional) – Whether to automatically load the math operators. The default is
True
.use_docker_by_default (bool, optional) – If the environment variable DPF_DOCKER is set to a docker name and use_docker_by_default is True, the server is ran as a docker (default is True).
docker_name (str, optional) – To start DPF server as a docker, specify the docker name here.
timeout (float, optional) – Maximum number of seconds for the initialization attempt. The default is
10
. Once the specified number of seconds passes, a second attempt is made with twice the given timeout, then if still no server has started, the connection fails.
- Returns
server
- Return type
- ansys.dpf.core.server.connect_to_server(ip='127.0.0.1', port=32772, as_global=True, timeout=10)#
Connect to an existing DPF server.
This method sets the global default channel that is then used for the duration of the DPF session.
- Parameters
ip (str) – IP address of the remote or local instance to connect to. The default is
"LOCALHOST"
.port (int) – Port to connect to the remote instance on. The default is
"DPF_DEFAULT_PORT"
, which is 50054.as_global (bool, optional) – Global variable that stores the IP address and port for the DPF module. All DPF objects created in this Python session will use this IP and port. The default is
True
.timeout (float, optional) – Maximum number of seconds for the initialization attempt. The default is
10
. Once the specified number of seconds passes, the connection fails.
Examples
>>> from ansys.dpf import core as dpf
Create a server.
>>> #server = dpf.start_local_server(ip = '127.0.0.1') >>> #port = server.port
Connect to a remote server at a non-default port.
>>> #specified_server = dpf.connect_to_server('127.0.0.1', port, as_global=False)
Connect to the localhost at the default port.
>>> #unspecified_server = dpf.connect_to_server(as_global=False)
- class ansys.dpf.core.server.DpfServer(ansys_path='', ip='127.0.0.1', port=32772, timeout=10.0, as_global=True, load_operators=True, launch_server=True, docker_name=None)#
Provides an instance of the DPF server.
- Parameters
server_bin (str or os.PathLike) – Path for the DPF executable.
ip (str) – IP address of the remote or local instance to connect to. The default is
"LOCALHOST"
.port (int) – Port to connect to the remote instance on. The default is
"DPF_DEFAULT_PORT"
, which is 50054.timeout (float, optional) – Maximum number of seconds for the initialization attempt. The default is
10
. Once the specified number of seconds passes, the connection fails.as_global (bool, optional) – Global variable that stores the IP address and port for the DPF module. All DPF objects created in this Python session will use this IP and port. The default is
True
.load_operators (bool, optional) – Whether to automatically load the math operators. The default is
True
.launch_server (bool, optional) – Whether to launch the server on Windows.
docker_name (str, optional) – To start DPF server as a docker, specify the docker name here.
- property info#
Server information.
- Returns
info – Dictionary with server information, including
"server_ip"
,"server_port"
,"server_process_id"
, and"server_version"
keys.- Return type
dictionary
- property ip#
IP address of the server.
- Returns
ip
- Return type
str
- property port#
Port of the server.
- Returns
port
- Return type
int
- property version#
Version of the server.
- Returns
version
- Return type
str
- property os#
Get the operating system of the server
- Returns
os – “nt” or “posix”
- Return type
str
- check_version(required_version, msg=None)#
Check if the server version matches with a required version.
- Parameters
required_version (str) – Required version to compare with the server version.
msg (str, optional) – Message for the raised exception if version requirements do not match.
:raises dpf_errors : errors: errors.DpfVersionNotSupported is raised if failure.
- Returns
True
if the server version meets the requirement.- Return type
bool
- ansys.dpf.core.server.launch_dpf(ansys_path, ip='127.0.0.1', port=32772, timeout=10.0, docker_name=None)#
Launch Ansys DPF.
- Parameters
ansys_path (str or os.PathLike, optional) – Root path for the Ansys installation directory. For example,
"/ansys_inc/v212/"
. The default is the latest Ansys installation.ip (str, optional) – IP address of the remote or local instance to connect to. The default is
"LOCALHOST"
.port (int) – Port to connect to the remote instance on. The default is
"DPF_DEFAULT_PORT"
, which is 50054.timeout (float, optional) – Maximum number of seconds for the initialization attempt. The default is
10
. Once the specified number of seconds passes, the connection fails.docker_name (str, optional) – To start DPF server as a docker, specify the docker name here.
- Returns
process – DPF Process.
- Return type
subprocess.Popen