How to compare two transient runs and extract maximum of difference between nodal temperatures?

Options
Pierre Thieffry
Pierre Thieffry Member, Moderator, Employee Posts: 98
First Anniversary Ansys Employee Solution Developer Community of Practice Member Photogenic
edited June 2023 in Structures

We want to compare two thermal transient runs, under the assumption they contain results at the exact same time steps. As an end result, we want to get a plot of the maximum differences between nodal results over the entire time range - i.e. we only have one plot showing max(t2,t1) not at every time step but for the entire time range.

Who wants to try?

Tagged:

Best Answer

  • Pierre Thieffry
    Pierre Thieffry Member, Moderator, Employee Posts: 98
    First Anniversary Ansys Employee Solution Developer Community of Practice Member Photogenic
    Answer ✓
    Options

    Here’s a first solution, yet a bit tedious. I could not find a way to use the “minus” operator on fields_container with more than one field

    # Perform a comparison between two thermal transient runs
    # End result: a plot of the maximum differences over the full time range between the two runs for each node
    # V1: investigate by time step
    # Important: It is assumed both thermal results have been computed at the same time points
    
    import mech_dpf
    import Ans.DataProcessing as dpf
    
    import time
    
    time0=time.time()
    dataSource_th1 = dpf.data.DataSources() 
    dataSource_th2 = dpf.data.DataSources() 
    
    #please set the result file path to the right path
    dataSource_th1.SetResultFilePath(r'C:\temp\SAE\ComparaisonThermiques_files\dp0\SYS\MECH\file.rth','rth')
    dataSource_th2.SetResultFilePath(r'C:\temp\SAE\ComparaisonThermiques_files\dp0\SYS-1\MECH\file.rth','rth')
    
    
    timePointsOp =dpf.operators.metadata.time_freq_provider()
    timePointsOp.inputs.data_sources.Connect(dataSource_th1)
    
    timepoints=dpf.data.Scoping()
    timepoints.Ids=range(1,timePointsOp.outputs.time_freq_support.GetData().TimeFreqs.Data.Count+1)
    timepoints.Location="Time"
    
    t1 = dpf.operators.result.temperature()
    t2 = dpf.operators.result.temperature()
    
    tdisplay = dpf.operators.result.temperature()
    tdisplay.inputs.data_sources.Connect(dataSource_th1)
    
    t1.inputs.data_sources.Connect(dataSource_th1)
    t2.inputs.data_sources.Connect(dataSource_th2)
    
    t1.inputs.time_scoping.Connect(timepoints)
    t2.inputs.time_scoping.Connect(timepoints)
    
    tempdiff=t1 # copy from t1 to initialize data
    
    squareop = dpf.operators.math.sqr() # operator instanciation
    sqrtop= dpf.operators.math.sqrt()
    # Compute difference between t2 and t1 for each time steps, store in tempdiff
    for i in timepoints.Ids:
        tempdiff_t=dpf.operators.math.minus()
        tempdiff_t.inputs.fieldA.Connect(t2.outputs.fields_container.GetData()[i-1])
        tempdiff_t.inputs.fieldB.Connect(t1.outputs.fields_container.GetData()[i-1])
        squareop.inputs.field.Connect(tempdiff_t.outputs.field)
        sqrtop.inputs.field.Connect(squareop.outputs.field)
        tempdiff.outputs.fields_container.GetData()[i-1].Data = sqrtop.outputs.field.GetData().Data
    
    # Compute max over time
    tempDiffMax=tempdiff.outputs.fields_container.GetData()[0] # Retrieve Field for first time step
    for i in timepoints.Ids: # For each time point, compare existing max with time point and update data if needed
        actualMaxData=tempDiffMax.Data
        candidateMaxData=tempdiff.outputs.fields_container.GetData()[i-1].Data
        nbData=actualMaxData.Count
        for j in range(0,nbData): # Loop over nodes
            actualMax=actualMaxData[j]
            candidateMax=candidateMaxData[j]
            if actualMax<candidateMax:
                actualMaxData[j]=candidateMax
        tempDiffMax.Data=actualMaxData
    
    time1=time.time()
    
    print ('Evaluation over all time steps performed in :',time1-time0,'s')
    
    tdisplay.outputs.fields_container.GetData()[0].Data=tempDiffMax.Data
    
    wf = dpf.data.Workflow()
    wf.Add(tdisplay)
    wf.SetOutputContour(tdisplay)
    
    wf.Record("wf_id", True)
    

Answers