ServerContext#

Gives the ability to choose the context with which the server should be started. The context allows you to choose the licensing logic for operators. For every context, DPF always checks if an Ansys license is available. By default, a Premium type of ServerContext is used, meaning that any operator requiring a license check-out can do so. The Entry context instead does not allow operators to check a license out, which will result in failure of operators requiring it. The default context can be overwritten using the ANSYS_DPF_SERVER_CONTEXT environment variable. ANSYS_DPF_SERVER_CONTEXT=ENTRY and ANSYS_DPF_SERVER_CONTEXT=PREMIUM can be used.

enum ansys.dpf.core.server_context.LicensingContextType(value)#

An enumeration.

Valid values are as follows:

none = <LicensingContextType.none: 5>#
premium = <LicensingContextType.premium: 1>#
entry = <LicensingContextType.entry: 4>#
class ansys.dpf.core.server_context.LicenseContextManager(increment_name: str | None = None, license_timeout_in_seconds: float | None = None, server=None)#

Can optionally be used to check out a license before using licensed DPF Operators. Improves performance if you are using multiple Operators that require licensing. It can also be used to force checkout before running a script when few Ansys license increments are available. The license is checked in when the object is deleted.

Parameters:
  • increment_name (str, optional) – License increment to check out. To improve script efficiency, this license increment should be consistent with the increments required by the following Operators. If None, the first available increment of this list is checked out.

  • license_timeout_in_seconds (float, optional) – If an increment is not available by the maximum time set here, check out fails. Default is: ansys.dpf.core.runtime_config.RuntimeCoreConfig.license_timeout_in_seconds()

  • server (server.DPFServer, optional) – Server with the channel connected to the remote or local instance. The default is None, in which case an attempt is made to use the global server.

Examples

Using a context manager >>> from ansys.dpf import core as dpf >>> dpf.set_default_server_context(dpf.AvailableServerContexts.premium) >>> field = dpf.Field() >>> field.append([0., 0., 0.], 1) >>> op = dpf.operators.filter.field_high_pass() >>> op.inputs.field(field) >>> op.inputs.threshold(0.0) >>> with dpf.LicenseContextManager() as lic: … out = op.outputs.field()

Using an instance >>> lic = dpf.LicenseContextManager() >>> op.inputs.field(field) >>> op.inputs.threshold(0.0) >>> out = op.outputs.field() >>> lic = None

Using a context manager and choosing license options >>> op.inputs.field(field) >>> op.inputs.threshold(0.0) >>> out = op.outputs.field() >>> op = dpf.operators.filter.field_high_pass() >>> op.inputs.field(field) >>> op.inputs.threshold(0.0) >>> with dpf.LicenseContextManager( … increment_name=”preppost”, license_timeout_in_seconds=1.) as lic: … out = op.outputs.field()

Notes

Available from 6.1 server version.

release_data()#

Release the data.

property status#

Returns a string with the list of checked out increments.

Return type:

str

class ansys.dpf.core.server_context.ServerContext(context_type=LicensingContextType.premium, xml_path='')#

The context defines whether DPF capabilities requiring a license checkout are allowed. xml_path argument won’t be taken into account if using LicensingContextType.entry.

Parameters:
  • context_type (LicensingContextType) – Type of context.

  • xml_path (str, optional) – Path to the xml to load.

property licensing_context_type#

Whether capabilities requiring Licenses checkout should be allowed.

Return type:

LicensingContextType

property xml_path#

Path to the xml listing the capabilities to load on the server.

Return type:

str

class ansys.dpf.core.server_context.AvailableServerContexts#

Defines available server contexts.

pre_defined_environment = <ansys.dpf.core.server_context.ServerContext object>#

DataProcessingCore.xml that is next to DataProcessingCore.dll/libDataProcessingCore.so will be taken

premium = <ansys.dpf.core.server_context.ServerContext object>#

Gets the Specific premium DataProcessingCore.xml to load most plugins with their environments.

custom_defined = <ansys.dpf.core.server_context.ServerContext object>#

Loads the xml named “DpfCustomDefined.xml” that the user can modify.

entry = <ansys.dpf.core.server_context.ServerContext object>#

Loads the minimum number of plugins for a basic usage. Is the default.

ansys.dpf.core.server_context.set_default_server_context(context=<ansys.dpf.core.server_context.ServerContext object>)#

Sets this context as default for any new server. Also applies it to the global server if it is running as Entry and requested context is Premium.

The context enables to choose whether DPF capabilities requiring a license checkout are allowed.

Parameters:

context (ServerContext) – Context to apply to the given server or to the newly started servers (when no server is given).

Return type:

None

Notes

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