Print temperatures node ids and locations using DPF inside mechanical

Erik Kostson
Erik Kostson Member, Employee Posts: 87
First Answer Name Dropper First Anniversary Ansys Employee

We have a named selection (say MY_NS surface scoped) and we want to obtain and print temperatures, node ids and locations in transient thermal analysis.

Comments

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 87
    First Answer Name Dropper First Anniversary Ansys Employee
    edited July 2023

    We can do that as shown below. The DPF script runs within the mechanical scripting inside a thermal analysis, and assumes we have a named selection called MY_NS. Further more this runs in 2023 R1 and onwards (so does not work in 2022 R2 due to an issue).

    # Import DPF
    import mech_dpf
    import Ans.DataProcessing as dpf 
    mech_dpf.setExtAPI(ExtAPI)
    
    #Get the data source (i.e. result file)
    analysis = ExtAPI.DataModel.Project.Model.Analyses[0]
    dataSource = dpf.DataSources(analysis.ResultFileName)
    
    #Create Named Selection Operator
    ns_op = dpf.operators.scoping.on_named_selection()
    ns_op.inputs.data_sources.Connect(dataSource)
    ns_op.inputs.requested_location.Connect('Nodal')
    #Name should be in all caps
    ns_op.inputs.named_selection_name.Connect('MY_NS')
    mymeshscoping = ns_op.outputs.mesh_scoping
    
    # Get node numbers for nodes in named selection
    mesh_data = ns_op.outputs.mesh_scoping.GetData()
    mesh_data.Ids #  node Ids
    #Then, let's grab the complete mesh through:
    
    # Get complete mesh
    model=dpf.Model(dataSource)
    mesh=model.Mesh
    #Now we can use the info on the mesh and on the node Ids to get information on the nodes of this named selection:
    # time
    #Get the time data corresponding to result sets
    time_provider = dpf.operators.metadata.time_freq_provider()
    time_provider.inputs.data_sources.Connect(dataSource)
    numSets = time_provider.outputs.time_freq_support.GetData().NumberSets
    timeids = time_provider.outputs.time_freq_support.GetData().TimeFreqs.Data
    
    #hget results
    # Get information for first node in named selection
    for mytime in timeids:
        temp=0
        i=0
        mytemp=dpf.operators.result.temperature(time_scoping=mytime,data_sources=dataSource,mesh_scoping=mymeshscoping).outputs.fields_container.GetData()[0]
        temp=mytemp.Data
        for idd in mesh_data.Ids:
            node1=mesh.NodeById(idd)
            print(mytime, idd, temp[i], node1.X, node1.Y, node1.Z)
    model.ReleaseStreams()
    

This discussion has been closed.