Calculate average surface temperature of a group of surface named selections.
Ayush Kumar
Member, Moderator, Employee Posts: 468
✭✭✭✭
in Structures
Calculate average surface temperature of a group of surface named selections.
Tagged:
0
Comments
-
Adjust named selections in line 56:
import os import mech_dpf import Ans.DataProcessing as dpf def compute_temp(ns): rth_path = Model.Analyses[0].ResultFileName model = dpf.Model(rth_path) ds = dpf.DataSources(rth_path) streams = dpf.operators.metadata.streams_provider(data_sources=ds) streams_container = streams.outputs.streams_container.GetData() face_ns = ns ns_scoping = dpf.MeshScopingFactory.NamedSelectionScoping(face_ns, model) ts = dpf.Scoping() ts.Ids = range(1, model.TimeFreqSupport.NumberSets + 1) """Get total face area""" skin_mesh = dpf.operators.mesh.skin(mesh=model.Mesh) skin_mesh.inputs.mesh_scoping.Connect(ns_scoping) skin_meshed_region = skin_mesh.outputs.mesh.GetData() """Nodal temperatures""" nodal_temp = dpf.operators.result.temperature(mesh_scoping=ns_scoping, time_scoping=ts) nodal_temp.inputs.streams_container.Connect(streams_container) """Map nodal temperatures to element faces (average)""" ef_temp = dpf.operators.averaging.nodal_to_elemental_fc(fields_container=nodal_temp, mesh=skin_meshed_region) ef_temp_fc = ef_temp.outputs.fields_container.GetData() """Element face area""" elem_area = dpf.operators.geo.elements_volume(mesh=skin_meshed_region) elem_area_f = elem_area.outputs.field.GetData() elem_area_fc = dpf.FieldsContainer() elem_area_fc.Labels = ["time"] """Create FC of element face area over time""" for tid in ts.Ids: elem_area_fc.Add(elem_area_f, {"time": tid}) total_area = dpf.operators.math.accumulate(fieldA=elem_area_f).outputs.field.GetData().Data[0] """Weighted Tempertaure""" w_temp = dpf.operators.math.generalized_inner_product_fc() w_temp.inputs.field_or_fields_container_A.Connect(ef_temp_fc) w_temp.inputs.field_or_fields_container_B.Connect(elem_area_fc) w_temp_fc = w_temp.outputs.fields_container.GetData() w_temp_sum = dpf.operators.math.accumulate_fc(fields_container=w_temp_fc) w_temp_avg = dpf.operators.math.scale_fc(fields_container=w_temp_sum, ponderation=1.0 / total_area) w_temp_avg_fc = w_temp_avg.outputs.fields_container.GetData() model.ReleaseStreams() streams_container.ReleaseHandles() return w_temp_avg_fc nsList = ["F%s" % index for index in range(1, 7)] all_temp_fc = [] for ns in nsList: all_temp_fc.append(compute_temp(ns))
1