Calculate average surface temperature of a group of surface named selections.

Member, Moderator, Employee Posts: 479
100 Answers 250 Likes 100 Comments Second Anniversary
✭✭✭✭

Calculate average surface temperature of a group of surface named selections.

Tagged:

Comments

  • Member, Moderator, Employee Posts: 479
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭
    edited February 2024

    Adjust named selections in line 56:

    1. import os
    2. import mech_dpf
    3. import Ans.DataProcessing as dpf
    4.  
    5. def compute_temp(ns):
    6. rth_path = Model.Analyses[0].ResultFileName
    7. model = dpf.Model(rth_path)
    8.  
    9. ds = dpf.DataSources(rth_path)
    10. streams = dpf.operators.metadata.streams_provider(data_sources=ds)
    11. streams_container = streams.outputs.streams_container.GetData()
    12.  
    13. face_ns = ns
    14.  
    15. ns_scoping = dpf.MeshScopingFactory.NamedSelectionScoping(face_ns, model)
    16. ts = dpf.Scoping()
    17. ts.Ids = range(1, model.TimeFreqSupport.NumberSets + 1)
    18.  
    19. """Get total face area"""
    20. skin_mesh = dpf.operators.mesh.skin(mesh=model.Mesh)
    21. skin_mesh.inputs.mesh_scoping.Connect(ns_scoping)
    22. skin_meshed_region = skin_mesh.outputs.mesh.GetData()
    23.  
    24. """Nodal temperatures"""
    25. nodal_temp = dpf.operators.result.temperature(mesh_scoping=ns_scoping, time_scoping=ts)
    26. nodal_temp.inputs.streams_container.Connect(streams_container)
    27. """Map nodal temperatures to element faces (average)"""
    28. ef_temp = dpf.operators.averaging.nodal_to_elemental_fc(fields_container=nodal_temp, mesh=skin_meshed_region)
    29. ef_temp_fc = ef_temp.outputs.fields_container.GetData()
    30.  
    31. """Element face area"""
    32. elem_area = dpf.operators.geo.elements_volume(mesh=skin_meshed_region)
    33. elem_area_f = elem_area.outputs.field.GetData()
    34. elem_area_fc = dpf.FieldsContainer()
    35. elem_area_fc.Labels = ["time"]
    36. """Create FC of element face area over time"""
    37. for tid in ts.Ids:
    38. elem_area_fc.Add(elem_area_f, {"time": tid})
    39.  
    40. total_area = dpf.operators.math.accumulate(fieldA=elem_area_f).outputs.field.GetData().Data[0]
    41.  
    42. """Weighted Tempertaure"""
    43. w_temp = dpf.operators.math.generalized_inner_product_fc()
    44. w_temp.inputs.field_or_fields_container_A.Connect(ef_temp_fc)
    45. w_temp.inputs.field_or_fields_container_B.Connect(elem_area_fc)
    46. w_temp_fc = w_temp.outputs.fields_container.GetData()
    47.  
    48. w_temp_sum = dpf.operators.math.accumulate_fc(fields_container=w_temp_fc)
    49. w_temp_avg = dpf.operators.math.scale_fc(fields_container=w_temp_sum, ponderation=1.0 / total_area)
    50. w_temp_avg_fc = w_temp_avg.outputs.fields_container.GetData()
    51.  
    52. model.ReleaseStreams()
    53. streams_container.ReleaseHandles()
    54. return w_temp_avg_fc
    55.  
    56. nsList = ["F%s" % index for index in range(1, 7)]
    57. all_temp_fc = []
    58. for ns in nsList:
    59. all_temp_fc.append(compute_temp(ns))

Welcome!

It looks like you're new here. Sign in or register to get started.