19.15.3. Using DPF with the Python Result Feature

When you add a Python Result object, the following script template is automatically included. The different parts of the script are described below:

ScriptDescription
def post_started(sender, analysis):
    define_dpf_workflow(analysis
PART 1, call define_dpf_workflow (auto generated).
# Uncomment this function to enable retrieving results from the table/chart

# def table_retrieve_result(value):
    # import mech_dpf
    # import Ans.DataProcessing as dpf

    # wf = dpf.Workflow(this.WorkflowId)
    # wf.Connect('contour_selector', value)

    # this.Evaluate()

PART 2, optional callback function for retrieving results from the table/chart.

Get the stored workflow by id and set the input value to the workflow.

Evaluate the workflow.

def define_dpf_workflow(analysis):

PART 3, start define_dpf_workflow

import mech_dpf 
import Ans.DataProcessing as dpf
mech_dpf.setExtAPI(ExtAPI)

PART 3.1, load dpf environment.

dataSource = dpf .DataSources(analysis.ResultFileName)

PART 3.2, take the file in the current analysis system that contains the source results (a dataSource).

u = dpf.operators.result.displacement()
nrm = dpf.operators.math.norm_fc()

PART 3.3, create needed operators

# timeScop = dpf.Scoping()
# timeScop.Ids = [1]
# u.inputs.time_scoping.Connect(timeScop)

PART 3.4, optional, set time scoping to the operator

u.inputs.data_sources.Connect(dataSource)
nrm.Connect(u)

PART 3.5, make the connections between the elements

dpf_workflow = dpf.Workflow()
dpf_workflow.Add(nrm)

PART 3.6, create the workflow and add operators.

dpf_workflow.Add(u)
# dpf_workflow.SetInputName(u, 0, 'time')
# dpf_workflow.Connect('time', timeScop)

PART 3.7, optional, set time scoping to the workflow.

dpf_workflow.SetOutputContour(nrm)
dpf_workflow.Record('wf_id', False)
this.WorkflowId = dpf_workflow.GetRecordedId()
PART 3.8, set the workflow’s output and record it.

Note:
  • Part 2 is optional and allows the user to retrieve results from the table/chart. More details and use case can be found in next section.

  • Part 3.1 imports the DPF environment. This will load all the mandatory DPF tools allowing you to use workflows, operators, fields container, etc.

  • Part 3.2 shows how you can access the result file from the current environment that the Python Result is operating under.

  • Part 3.3 shows how you can access various operators available in the DPF libraries.

  • Part 3.4 is optional and is to get results of desired time steps by setting time scoping to the operator.

  • Part 3.5 shows how to make connections between operators. All operators have certain inputs that they expect and certain outputs that they produce. Output from one operator can be connected as an input to another.

  • Part 3.6 consists of creating the workflow to evaluate and adding operators into it. All participating operators must be connected to a workflow.

  • Part 3.7 is optional and allows to set the desired input to the workflow (the given example is to set the time scoping to the input of the workflow, which works the same as Part 3.4.)

  • Then, part 3.8 shows how to set the output result you want (here it will be the output gotten from the norm operator). The recording step returns the workflow id, allowing you to get back the stored workflow using this scripting line:

    dpf_workflow = dpf.Workflow(WorkflowId)