Server factory, server configuration and communication protocols#

Contains the server factory as well as the communication protocols and server configurations available.

class ansys.dpf.core.server_factory.CommunicationProtocols#

Defines available communication protocols

gRPC = "gRPC"

Client/Server communication via gRPC.

InProcess = "InProcess"

Load DPF’s libraries in the Python process, communicates via a CLayer (shared memory).

class ansys.dpf.core.server_factory.ServerConfig(protocol='InProcess', legacy=False)#

Provides an instance of ServerConfig object to manage the server type used. The default parameters can be overwritten using the DPF_SERVER_TYPE environment variable. DPF_SERVER_TYPE=INPROCESS, DPF_SERVER_TYPE=GRPC, DPF_SERVER_TYPE=LEGACYGRPC can be used.

Parameters
  • protocol (CommunicationProtocols, optional) – Communication protocol for DPF server (e.g. InProcess, gRPC)

  • legacy (bool, optional) – If legacy is set to True, the server will be using ansys-grpc-dpf Python module. If not, it will communicate with DPF binaries using ctypes and DPF CLayer calls.

  • ignore_dpf_server_type (bool, optional) – Default is False. DPF_SERVER_TYPE environment variable will be ignored if overwrite is set to False.

Examples

Use constructor parameters to manually create servers.

>>> from ansys.dpf import core as dpf
>>> in_process_config = dpf.ServerConfig(
...     protocol=None, legacy=False)
>>> grpc_config = dpf.ServerConfig(
...     protocol=dpf.server_factory.CommunicationProtocols.gRPC, legacy=False)
>>> legacy_grpc_config = dpf.ServerConfig(
...     protocol=dpf.server_factory.CommunicationProtocols.gRPC, legacy=True)
>>> in_process_server = dpf.start_local_server(config=in_process_config, as_global=False)
>>> grpc_server = dpf.start_local_server(config=grpc_config, as_global=False)
>>> legacy_grpc_server = dpf.start_local_server(config=legacy_grpc_config, as_global=False)

Use the environment variable to set the default server configuration.

>>> import os
>>> os.environ["DPF_SERVER_TYPE"] = "INPROCESS"
>>> dpf.start_local_server()
<ansys.dpf.core.server_types.InProcessServer object at ...>
ansys.dpf.core.server_factory.get_default_server_config(server_lower_than_or_equal_to_0_3=False)#

Returns the default configuration depending on the server version. - if ansys.dpf.core.SERVER_CONFIGURATION is not None, then this variable is taken - if server_lower_than_or_equal_to_0_3 is True, then LegacyGrpcServer is taken - DPF_SERVER_TYPE environment variable is set to INPROCESS, GRPC, LEGACYGRPC,

then this variable is taken

else DEFAULT_COMMUNICATION_PROTOCOL and DEFAULT_LEGACY is taken.

Raises

If DPF_SERVER_TYPE environment variable is set to unknown value.

ansys.dpf.core.server_factory.get_default_remote_server_config()#

Returns the default configuration for gRPC communication. Follows get_default_server_config

Raises

If DPF_SERVER_TYPE environment variable is set to unknown value.

class ansys.dpf.core.server_factory.AvailableServerConfigs#

Defines available server configurations

LegacyGrpcServer = ServerConfig(CommunicationProtocols.gRPC, legacy=True)

Using gRPC communication through the python module ansys.grpc.dpf.

InProcess = ServerConfig(CommunicationProtocols.InProcess, legacy=False)

Loading DPF in Process.

GrpcServer = ServerConfig(CommunicationProtocols.gRPC, legacy=False)

Using gRPC communication through DPF gRPC CLayer Ans.Dpf.GrpcClient.

Examples

>>> from ansys.dpf import core as dpf
>>> in_process_config = dpf.AvailableServerConfigs.InProcessServer
>>> grpc_config = dpf.AvailableServerConfigs.GrpcServer
>>> legacy_grpc_config = dpf.AvailableServerConfigs.LegacyGrpcServer
>>> in_process_server = dpf.start_local_server(config=in_process_config, as_global=False)
>>> grpc_server = dpf.start_local_server(config=grpc_config, as_global=False)
>>> legacy_grpc_server = dpf.start_local_server(config=legacy_grpc_config, as_global=False)
class ansys.dpf.core.server_factory.ServerFactory#

Factory for server type choice depending on current configuration.