Server

Contains the directives necessary to start the dpf server.

ansys.dpf.core.server.has_local_server()

Returns True when a local DPF gRPC server has been created

ansys.dpf.core.server.port_in_use(port, host='127.0.0.1')

Returns True when a port is in use at the given host.

Must actually “bind” the address. Just checking if we can create a socket is insufficient as 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.

ansys.dpf.core.server.check_valid_ip(ip)

Raises an error when an invalid ip is entered

ansys.dpf.core.server.shutdown_all_session_servers()

Close 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)

Starts a new local DPF server at a given port and ip. Requires Windows and ANSYS v211 or newer be installed. If as_global is set to True (default) then the server is stored in the module (replacing the one stored before). Else, the user must keep a handle on his/her server

Parameters
  • ip (str) – IP address of the remote or local instance to connect to.

  • port (int) – Port to connect to the remote instance on.

  • ansys_path (str, optional) – Root path containing ansys. For example /ansys_inc/v212/. Defaults to the latest install of ANSYS.

  • as_global (bool, optional) – Stores this ip and port as global variables for the dpf module. All DPF objects created in this Python session will use this IP and port. Default True.

  • load_operators (bool, optional) – Automatically load the math operators

Returns

server

Return type

server.DpfServer

ansys.dpf.core.server.connect_to_server(ip='127.0.0.1', port=32772, as_global=True, timeout=5)

Connect to an existing dpf server.

Set this as the global default channel that will be used for the duration of dpf.

Parameters
  • ip (str) – IP address of the remote or local instance to connect to.

  • port (int) – Port to connect to the remote instance on.

  • as_global (bool, optional) – Stores this ip and port as global variables for the dpf module. All DPF objects created in this Python session will use this IP and port. Default True.

  • timeout (float) – Maximum timeout to connect to the DPF server.

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, as_global=True, load_operators=True, launch_server=True)

Instance of the DPF server

server_binstr

Location of the dpf executable.

ipstr

IP address of the remote or local instance to connect to.

portint

Port to connect to the remote instance on. Defaults to 50054.

timeoutfloat, optional

Fails when a connection takes longer than timeout seconds to initialize.

as_globalbool, optional

Stores this ip and port as global variables for the dpf module. All DPF objects created in this Python session will use this IP and port.

load_operatorsbool, optional

Automatically load the math operators

ansys_pathstr, optional

Path containing ansys. For example /ansys_inc/v212/

launch_serverbool, optional

Launch the server on windows

property info

Recover server information

Returns

info – dictionary with “server_ip”, “server_port”, “server_process_id” “server_version” keys

Return type

dictionary

property ip

Get the ip of the server

Returns

ip

Return type

str

property port

Get the port of the server

Returns

port

Return type

int

property version

Get the version of the server

Returns

version

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 that will be compared with the server version.

  • msg (str, optional) – Message to be contained in the raised Exception if versions are not meeting.

: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)

Launch ANSYS DPF.

Parameters
  • ansys_path (str) – Full path to ANSYS. For example: ‘C:Program FilesANSYS Incv211’

  • ip (str, optional) – IP address of the server. Default to localhost.

  • port (int) – Port of the server. Defaults to the default DPF port 50054.

Returns

process – DPF Process.

Return type

subprocess.Popen