Calculate Area Weighted Temperatures on Surfaces/Faces in Mechanical with DPF

Mike.Thompson
Mike.Thompson Member, Employee Posts: 404
100 Likes 25 Answers 100 Comments Second Anniversary
✭✭✭✭
edited May 20 in Structures

This is an example of how you can do this with DPF. A temperature contour plot will give you an "average", but this is simply the sum of all the nodal temperatures divided by number of nodes. It does not to the area-weighted average.

This routine will do a DPF skin mesh, get the area of the elements, get the nodal temps, convert to elemental temps (average nodes to elements), then you can calculate the area weighting from: sum(ElemArea*ElemTemp) / Total Area

#Inputs:
NamedSelName = "MyNodes"  #Should be a nodal named selection

#Standard routine
import mech_dpf
import Ans.DataProcessing as dpf
mech_dpf.setExtAPI(ExtAPI)

analysis = Model.Analyses[0]
ds = dpf.DataSources(analysis.ResultFileName)

# Get Mesh
op = dpf.operators.mesh.mesh_provider() # operator instanciation
op.inputs.data_sources.Connect(ds)
my_mesh = op.outputs.mesh.GetData()
#Make a nodal scoping
nodal_scoping = dpf.Scoping(Location="Nodal")
nodal_scoping.Ids = ExtAPI.DataModel.GetObjectsByName(NamedSelName)[0].Ids
# Extract Skin mesh from solid mesh
skin_mesh = dpf.operators.mesh.skin(mesh=my_mesh)
skin_mesh.inputs.mesh_scoping.Connect(nodal_scoping)
skin_mesh = skin_mesh.outputs.mesh.GetData()
#Area of skin mesh
op = dpf.operators.geo.elements_facets_surfaces_over_time() # operator instantiation
op.inputs.mesh.Connect(skin_mesh)# optional
area_fc = op.outputs.fields_container.GetData()
area_f=area_fc[0]
#nodal temps
temp_op = dpf.operators.result.temperature()
temp_op.inputs.data_sources.Connect(ds)
temp_op.inputs.mesh.Connect(skin_mesh)
temp_fc = temp_op.outputs.fields_container.GetData()
temp_f=temp_fc[0]
#convert to elemental.
#Creates a field that is elemental from the nodal temperature field
nd_to_elem_op=dpf.operators.averaging.nodal_to_elemental_fc()
nd_to_elem_op.inputs.fields_container.Connect(temp_fc)
temp_elem_fc=nd_to_elem_op.outputs.fields_container.GetData()
temp_elem_f=temp_elem_fc[0]



#test to show the manual average calculation is equal to the DPF operator averaging.
ElId = 1  #This is the ID of the first element of the DPF skin mesh.  Not an element in the actual model.
E = skin_mesh.ElementById(ElId)
NdIds = E.CornerNodeIds
Area = area_f.GetEntityDataById(ElId)
NdTemps = [temp_f.GetEntityDataById(NdId)[0] for NdId in NdIds]
AvrgTemp = sum(NdTemps)/len(NdTemps)
print "Average nodal temps:" +str(AvrgTemp)
print "DPF Average elemental temp:" +str(temp_elem_f.GetEntityDataById(ElId)[0])

print "Do the area weighted average:"
TotalArea = sum(area_f.Data)

WeightedAverage=sum((temp_elem_f*area_f).outputs.field.GetData().Data) / TotalArea
WeightedAverage=Quantity(WeightedAverage, temp_f.Unit)
print "Weighted average temperature = " + str(WeightedAverage)
Tagged: