Core#

ansys.dpf.core.core.load_library(filename, name='', symbol='LoadOperators', server=None, generate_operators=False)#

Dynamically load an operators library for dpf.core. Code containing this library’s operators is generated in ansys.dpf.core.operators

Parameters:
  • filename (str or os.PathLike) – Filename of the operator library.

  • name (str, optional) – Library name. Probably optional

  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the global server.

  • generate_operators (bool, optional) – Whether operators code generation should be done or not (default is False).

Examples

Load the mesh operators for Windows (for Linux, just use ‘libmeshOperatorsCore.so’ instead of ‘meshOperatorsCore.dll’)

>>> from ansys.dpf import core as dpf
>>> # dpf.load_library('meshOperatorsCore.dll', 'mesh_operators')
ansys.dpf.core.core.upload_file_in_tmp_folder(file_path, new_file_name=None, server=None)#

Upload a file from the client to the server in a temporary folder deleted when the server is shutdown

Parameters:
  • file_path (str or os.PathLike) – file path on the client side to upload

  • new_file_name (str, optional) – name to give to the file server side, if no name is specified, the same name as the input file is given

  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the global server.

Returns:

server_file_pathstr

path generated server side

Notes

Is not implemented for usage with type(server)= ansys.dpf.core.server_types.InProcessServer.

ansys.dpf.core.core.upload_files_in_folder(to_server_folder_path, client_folder_path, specific_extension=None, server=None)#

Upload all the files from a folder of the client to the target server folder path.

Parameters:
  • to_server_folder_path (str or os.PathLike) – folder path target where will be uploaded files on the server side

  • client_folder_path (str or os.PathLike) – folder path where the files that must be uploaded are located on client side

  • (optional) (specific_extension) – copies only the files with the given extension

  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the global server.

Returns:

paths – new file paths server side

Return type:

list of str

ansys.dpf.core.core.download_file(server_file_path, to_client_file_path, server=None)#

Download a file from the server to the target client file path

Parameters:
  • server_file_path (str or os.PathLike) – file path to download on the server side

  • to_client_file_path (str or os.PathLike) – file path target where the file will be located client side

  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the global server.

Notes

Is not implemented for usage with type(server)= ansys.dpf.core.server_types.InProcessServer.

ansys.dpf.core.core.download_files_in_folder(server_folder_path, to_client_folder_path, specific_extension=None, server=None)#

Download all the files from a folder of the server to the target client folder path

Parameters:
  • server_folder_path (str or os.PathLike) – folder path to download on the server side

  • to_client_folder_path (str or os.PathLike) – folder path target where the files will be located client side

  • (optional) (specific_extension) – copies only the files with the given extension

  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the global server.

Returns:

paths – new file paths client side

Return type:

list of str

ansys.dpf.core.core.upload_file(file_path, to_server_file_path, server=None)#

Upload a file from the client to the target server file path

Parameters:
  • file_path (str or os.PathLike) – file path on the client side to upload

  • to_server_file_path (str or os.PathLike) – file path target where the file will be located server side

  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the global server.

Returns:

server_file_path – path generated server side

Return type:

str

ansys.dpf.core.core.make_tmp_dir_server(server=None)#

Create a temporary folder server side. Only one temporary folder can be created by server instance. The folder will be deleted when the server is stopped.

Parameters:

server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the global server.

Returns:

path – path to the temporary dir

Return type:

str

class ansys.dpf.core.core.BaseService(server=None, load_operators=True, timeout=5)#

The Base Service class allows to make generic requests to dpf’s server. For example, information about the server can be requested, uploading/downloading file from and to the server can be done, new operators plugins can be loaded… Most of the request done by the BaseService class are wrapped by functions.

Parameters:
  • server (server.DPFServer, optional) – Server with channel connected to the remote or local instance. When None, attempts to use the global server.

  • timeout (float, optional) – Fails when a connection takes longer than timeout seconds to initialize.

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

Examples

Connect to an existing DPF server >>> from ansys.dpf import core as dpf >>> #server = dpf.connect_to_server(ip=’127.0.0.1’, port = 50054, as_global=False) >>> #base = dpf.BaseService(server=server)

make_tmp_dir_server()#

Create a temporary folder server side. Only one temporary folder can be created by server instance. The folder will be deleted when the server is stopped.

Returns:

path – path to the temporary dir

Return type:

str

load_library(file_path, name='', symbol='LoadOperators', generate_operators=False)#

Dynamically load an operators library for dpf.core. Code containing this library’s operators is generated in ansys.dpf.core.operators

Parameters:
  • file_path (str or os.PathLike) – file_path of the operator library.

  • name (str, optional) – Library name. Probably optional

  • generate_operators (bool, optional) – Whether operators code generation should be done or not (default is False).

Examples

Load the mesh operators for Windows (for Linux, just use ‘libmeshOperatorsCore.so’ instead of ‘meshOperatorsCore.dll’)

>>> from ansys.dpf import core as dpf
>>> base = dpf.BaseService()
>>> # base.load_library('meshOperatorsCore.dll', 'mesh_operators')
apply_context(context)#

Defines the settings that will be used to load DPF’s plugins. A DPF xml file can be used to list the plugins and set up variables.

Parameters:

context (ServerContext) – The context allows to choose which capabilities are available server side.

Notes

Available with server’s version starting at 6.0 (Ansys 2023R2).

initialize_with_context(context)#

Defines the settings that will be used to initialize DPF. A DPF xml file can be used to list the plugins and set up variables.

Parameters:

context (ServerContext) – The context allows to choose which capabilities are available server side.

Notes

Available with server’s version starting at 4.0 (Ansys 2022R2) for InProcess Server and starting at 6.0 (Ansys 2023R2) for Grpc Servers.

initialize()#

Initialize a DPF server without a context.

release_dpf()#

Clears the available Operators and Releases licenses when necessary.

Notes

Available with server’s version starting at 6.0 (Ansys 2023R2).

property server_info#

Send the request for server information and keep the info into a dictionary

Returns:

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

Return type:

dictionary

download_file(server_file_path, to_client_file_path)#

Download a file from the server to the target client file path

Parameters:
  • server_file_path (str or os.PathLike) – file path to download on the server side

  • to_client_file_path (str or os.PathLike) – file path target where the file will be located client side

download_files_in_folder(server_folder_path, to_client_folder_path, specific_extension=None)#

Download all the files from a folder of the server to the target client folder path

Parameters:
  • server_folder_path (str or os.PathLike) – folder path to download on the server side

  • to_client_folder_path (str or os.PathLike) – folder path target where the files will be located client side

  • (optional) (specific_extension) – copies only the files with the given extension

Returns:

paths – new file paths client side

Return type:

list of str

upload_files_in_folder(to_server_folder_path, client_folder_path, specific_extension=None)#

Upload all the files from a folder of the client to the target server folder path.

Parameters:
  • to_server_folder_path (str or os.PathLike) – folder path target where will be uploaded files on the server side

  • client_folder_path (str or os.PathLike) – folder path where the files that must be uploaded are located on client side

  • (optional) (specific_extension) – copies only the files with the given extension

Returns:

paths – new file paths server side

Return type:

list of str

upload_file(file_path, to_server_file_path)#

Upload a file from the client to the target server file path

Parameters:
  • file_path (str or os.PathLike) – file path on the client side to upload

  • to_server_file_path (str or os.PathLike) – file path target where the file will be located server side

Returns:

server_file_pathstr

path generated server side

upload_file_in_tmp_folder(file_path, new_file_name=None)#

Upload a file from the client to the server in a temporary folder deleted when the server is shutdown

Parameters:
  • file_path (str or os.PathLike) – file path on the client side to upload

  • new_file_name (str, optional) – name to give to the file server side, if no name is specified, the same name as the input file is given

Returns:

server_file_pathstr

path generated server side