This is an example of a DPF script to average based on APDL element type id. The idea is to NOT average across element types, and DO average within the same element type.
import mech_dpf
import Ans.DataProcessing as dpf
mech_dpf.setExtAPI(ExtAPI)
ops=dpf.operators
analysis = Model.Analyses[0]
ExtAPI.Application.ActiveUnitSystem=Ansys.ACT.Interfaces.Common.MechanicalUnitSystem.StandardNMM
analysis.Solution.Solve()
ds=dpf.DataSources(analysis.ResultFileName)
def GetMeshScoping():
"""
Get a mesh scoping container object to break up mesh element scoping by element type
"""
op = dpf.operators.metadata.property_field_provider_by_name() # operator instantiatio
op.inputs.data_sources.Connect(ds)
op.inputs.property_name.Connect('mapdl_element_type_id')
f = op.outputs.property_field.GetData()
types = set(f.Data)
type_dict = {}
for typeid in types:
type_dict[typeid]=[]
for elid, typeid in zip(f.Scoping.Ids, f.Data):
type_dict[typeid].append(elid)
SC = dpf.ScopingsContainer()
label_name = 'apdl_type_id'
SC.AddLabel(label_name)
for typeid, elemids in type_dict.items():
SC.Add(dpf.MeshScopingFactory.ElementalScoping(elemids), {label_name:typeid})
return SC
def GetStress():
"""
Get the stress tensor, average to nodal based on element type, calculate SEQV
"""
stress_op = ops.result.stress()
stress_op.inputs.data_sources.Connect(ds)
stress_op.inputs.mesh_scoping.Connect(GetMeshScoping())
stress_op.inputs.requested_location.Connect(dpf.locations.elemental_nodal)
eln_to_n_op = ops.averaging.elemental_nodal_to_nodal_fc()
eln_to_n_op.inputs.fields_container.Connect(stress_op)
von_mises_op = ops.invariant.von_mises_eqv_fc()
von_mises_op.inputs.fields_container.Connect(eln_to_n_op)
fc=von_mises_op.outputs.getfields_container()
return fc
def CompareStress():
"""
Compare the stress values from mechanical and DPF
"""
#Get the plot data for the mechanical object which is nodal values
P=ExtAPI.DataModel.GetObjectsByName("ElemType3SEQV")[0]
plot_dict={NdId:Val for NdId, Val in zip(P.PlotData['Node'], P.PlotData['Values'])}
#Get the field for type = 3
f=fc.Get({'apdl_type_id':3, 'time':1})
#calculate the difference between DPF and the
print "Object '"+P.Name+"' is defined for type 3"
P.Activate()
diff_dict = {}
for NdId, Val in zip(f.ScopingIds, f.Data):
diff_dict[NdId] = Val-plot_dict[NdId]
print "maximum difference between the mechanical plot object and the DPF calculation: "+str(max(diff_dict.values()))
fc=GetStress()
print fc
CompareStress()