Workflow

Interface to underlying gRPC Workflow

class ansys.dpf.core.workflow.Workflow(workflow=None, server=None)
A class used to represent a Workflow:

a workflow is a black box containing operators and exposing only the necessary operator’s inputs and outputs to compute a given algorithm

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

  • workflow (workflow_pb2.Workflow) –

Examples

Create a generic Workflow computing the minimum of displacement by chaining the 'U' and 'min_max_fc' operators.

>>> from ansys.dpf import core as dpf
>>> disp_op = dpf.operators.result.displacement()
>>> max_fc_op = dpf.operators.min_max.min_max_fc(disp_op)
>>> workflow = dpf.Workflow()
>>> workflow.add_operators([disp_op,max_fc_op])
>>> workflow.set_input_name("data_sources", disp_op.inputs.data_sources)
>>> workflow.set_output_name("min", max_fc_op.outputs.field_min)
>>> workflow.set_output_name("max", max_fc_op.outputs.field_max)
>>> from ansys.dpf.core import examples
>>> data_src = dpf.DataSources(examples.multishells_rst)
>>> workflow.connect("data_sources", data_src)
>>> min = workflow.get_output("min", dpf.types.field)
>>> max = workflow.get_output("max", dpf.types.field)
connect(pin_name, inpt, pin_out=0)

Connect an input on the workflow using a pin name.

Parameters
  • pin_name (str) – Name of the pin to connect. This name should be exposed before with wf.set_input_name

  • inpt (str, int, double, bool, list of int, list of doubles, Field, FieldsContainer, Scoping, ScopingsContainer,) –

  • MeshedRegion – Object you wish to connect.

  • MeshesContainer – Object you wish to connect.

  • DataSources – Object you wish to connect.

  • Operator – Object you wish to connect.

  • pin_out (int, optional) – In case of the input is an Operator, this is the output pin of the input Operator. Defaults to 0.

Examples

Create a generic Workflow computing the minimum of displacement by chaining the 'U' and 'min_max_fc' operators.

>>> from ansys.dpf import core as dpf
>>> disp_op = dpf.operators.result.displacement()
>>> max_fc_op = dpf.operators.min_max.min_max_fc(disp_op)
>>> workflow = dpf.Workflow()
>>> workflow.add_operators([disp_op,max_fc_op])
>>> workflow.set_input_name("data_sources", disp_op.inputs.data_sources)
>>> workflow.set_output_name("min", max_fc_op.outputs.field_min)
>>> workflow.set_output_name("max", max_fc_op.outputs.field_max)
>>> from ansys.dpf.core import examples
>>> data_src = dpf.DataSources(examples.multishells_rst)
>>> workflow.connect("data_sources", data_src)
>>> min = workflow.get_output("min", dpf.types.field)
>>> max = workflow.get_output("max", dpf.types.field)
get_output(pin_name, output_type)

Returns the output of the operator on the pin number.

Parameters
  • pin_name (str) – Name of the pin to get. This name should be exposed before with wf.set_output_name

  • output_type (core.type enum) – The requested type of the output.

set_input_name(name, *args)

Name an input pin of the workflow to expose it for future connection

Parameters
  • name (str) – Name of the pin to connect. This name should be exposed before with wf.set_input_name

  • *args (core.Operator, core.Input, int) – operator with it’s input pin number or input to name

Examples

>>> from ansys.dpf import core as dpf
>>> workflow = dpf.Workflow()
>>> workflow.add_operators([disp_op,max_fc_op])
>>> workflow.set_input_name("data_sources", disp_op.inputs.data_sources)
>>> from ansys.dpf.core import examples
>>> data_src = dpf.DataSources(examples.multishells_rst)
>>> workflow.connect("data_sources", data_src)
set_output_name(name, *args)

Name an output pin of the workflow to expose it for future connection

Parameters
  • name (str) – Name of the pin to connect. This name should be exposed before with wf.set_input_name

  • *args (core.Operator, core.Output, int) – operator with it’s outpt pin number or output to name

Examples

>>> from ansys.dpf import core as dpf
>>> workflow = dpf.Workflow()
>>> workflow.add_operators([disp_op,max_fc_op])
>>> workflow.set_output_name("contour", disp_op.outputs.fields_container)
>>> fc = workflow.get_output("contour", dpf.types.fields_container)
add_operators(operators)

Add operators to the list of operators of the workflow

Parameters

operators (dpf.core.Operator, list of dpf.core.Operator) – operators to add to the list

Examples

>>> from ansys.dpf import core as dpf
>>> workflow = dpf.Workflow()
>>> disp_op = dpf.Operator("U")
>>> max_op = dpf.Operator("min_max")
>>> workflow.add_operator([disp_op,max_op])
add_operator(operator)

Add an operator to the list of operators of the workflow

Parameters

operator (dpf.core.Operator) – operator to add to the list

Examples

>>> from ansys.dpf import core as dpf
>>> workflow = dpf.Workflow()
>>> disp_op = dpf.Operator("U")
>>> workflow.add_operator(disp_op)
record(identifier=None, transfer_ownership=True)

Add the workflow to DPF’s internal registry with an id returned by this method. The workflow can be recovered by dpf.core.Workflow.get_recorded_workflow(id)

Parameters
  • identifier (str, optional) – name given to the workflow

  • transfer_ownership (bool) – if the owner ship is not transferred, the workflow is removed from the internal registry as soon as the workflow has been recovered by its id

Examples

>>> from ansys.dpf import core as dpf
>>> workflow = dpf.Workflow()
>>> disp_op = dpf.Operator("U")
>>> workflow.add_operator(disp_op)
>>> # ...
>>> id = workflow.record()
>>> workflow_copy = dpf.Workflow.get_recorded_workflow(id)
static get_recorded_workflow(id, server=None)

Recover a workflow registered (with workflow.record())

Parameters

id (int) – id given by the method “record”

Returns

workflow – workflow registered in dpf’s registry (server side)

Return type

core.Workflow()

Examples

>>> from ansys.dpf import core as dpf
>>> workflow = dpf.Workflow()
>>> disp_op = dpf.Operator("U")
>>> workflow.add_operator(disp_op)
>>> # ...
>>> id = workflow.record()
>>> workflow_copy = dpf.Workflow.get_recorded_workflow(id)
property info

Returns a dictionary with the operator names and the exposed input and output names

Returns

info – dictionary with “operator_names”, “input_names” and “output_names” key

Return type

dictionarry str->list str

property operator_names

Returns a list of the names of operators added in the workflow

Returns

names

Return type

list str

property input_names

Returns a list of the input names exposed in the workflow with set_input_name

Returns

names

Return type

list str

property output_names

Returns a list of the output names exposed in the workflow with set_output_name

Returns

names

Return type

list str

chain_with(workflow, input_output_names=None)

Chain 2 workflows together so that they become one workflow with all the operators, inputs and outputs exposed in both workflows

Parameters
  • workflow (core.Workflow) – This second workflow’s inputs will be chained with this workflow’s outputs

  • input_output_names (str tuple, optional) – the input name of this workflow will be chained with the output name of the second workflow If nothing is specified, this workflow’s outputs with the same names as the second workflow’s inputs will be chained

Examples

+-------------------------------------------------------------------------------------------------+
|  INPUT:                                                                                         |
|                                                                                                 |
|input_output_names = ("output","field" )                                                          |
|                      ____                                  ______________________                |
|  "data_sources"  -> |this| ->  "stuff"        "field" -> |workflow_to_chain_with| -> "contour"  |
|"time_scoping"    -> |    |             "mesh_scoping" -> |                      |               |
|                     |____| ->  "output"                  |______________________|               |
|  OUTPUT                                                                                         |
|                    ____                                                                         |
|"data_sources"  -> |this| ->  "stuff"                                                            |
|"time_scoping" ->  |    | ->  "contour"                                                           |
|"mesh_scoping" ->  |____| -> "output"                                                             |
+-------------------------------------------------------------------------------------------------+