How to implement Utilization factor procedure in IPython DPF (Mechanical)
Hi,
I'm trying to plot utilization factor based on Von Mises stress and arbitrary yield value. My similar script works in CPython, however in Mechanical Python Rsult I'm getting 0s. Von Mises Elemental Mean is plotting correc, but next step is not yielding results
def define_dpf_workflow(analysis):
import mech_dpf
import Ans.DataProcessing as dpf
mech_dpf.setExtAPI(ExtAPI)
dataSource = dpf.DataSources(analysis.ResultFileName)
#operator init
seqv = dpf.operators.result.stress_von_mises()
mean = dpf.operators.averaging.elemental_mean()
div = dpf.operators.math.component_wise_divide()
#get von mises elementalnodal, step 1
seqv.inputs.data_sources.Connect(dataSource)
seqv.inputs.time_scoping.Connect([1.])
seqv.inputs.requested_location.Connect('ElementalNodal')
#von mises passed to mean operator
mean.Connect(seqv)
#scalar field with single value for all scoped elements
element_ids = mean.outputs.getfield().ScopingIds
yield_f = dpf.FieldsFactory.CreateScalarField(numEntities=len(element_ids), location=dpf.locations.elemental)
yield_f.Data = [355.]*len(element_ids)
#division operator with von mises and scalar field
div.inputs.fieldA.Connect(mean.outputs.field.GetData())
div.inputs.fieldB.Connect(yield_f)
#workflow
dpf_workflow = dpf.Workflow()
dpf_workflow.Add(seqv)
dpf_workflow.Add(mean)
dpf_workflow.Add(div)
#plot
dpf_workflow.SetOutputContour(div)
dpf_workflow.Record('wf_id', False)
this.WorkflowId = dpf_workflow.GetRecordedId()
Thank you
Bartosz
Answers
-
I am not sure how it worked in CPython but your field for yield should have Scoping support as well.
Since you know about fieldA, try copying scoping from FieldA (yield_f.Scoping = mean_field.Scoping). I modified your code below.
def define_dpf_workflow(analysis): import mech_dpf import Ans.DataProcessing as dpf mech_dpf.setExtAPI(ExtAPI) dataSource = dpf.DataSources(analysis.ResultFileName) #operator init seqv = dpf.operators.result.stress_von_mises() mean = dpf.operators.averaging.elemental_mean() div = dpf.operators.math.component_wise_divide() #get von mises elementalnodal, step 1 seqv.inputs.data_sources.Connect(dataSource) seqv.inputs.time_scoping.Connect([1.]) seqv.inputs.requested_location.Connect('Elemental') #von mises passed to mean operator mean.Connect(seqv) mean_field= mean.outputs.field.GetData() #scalar field with single value for all scoped elements element_ids = mean.outputs.getfield().ScopingIds yield_f = dpf.FieldsFactory.CreateScalarField(numEntities=len(element_ids), location=dpf.locations.elemental) yield_f.Data = [355.]*len(element_ids) yield_f.Scoping = mean_field.Scoping #division operator with von mises and scalar field div.inputs.fieldA.Connect(mean_field) div.inputs.fieldB.Connect(yield_f) #workflow dpf_workflow = dpf.Workflow() dpf_workflow.Add(seqv) dpf_workflow.Add(mean) dpf_workflow.Add(div) #plot dpf_workflow.SetOutputContour(div) dpf_workflow.Record('wf_id', False) this.WorkflowId = dpf_workflow.GetRecordedId()
0