Get the top 10% of the results from an analysis

Kleanthis
Kleanthis Member, Employee Posts: 6
Ansys Employee First Comment
✭✭✭
edited June 2023 in Structures

How to get the average value for the top 10% ranked output value for a predefined Named Selection? In post processing, it would take only the 10% top ranked output value (e.g. NLPLWK) in a predefined Named Selection (Mesh,Nodes,Face) and plot it. Then it would calculate the average of those 10% shorted values with their corresponding node without including the max value as it may be an outlier.

Comments

  • Kleanthis
    Kleanthis Member, Employee Posts: 6
    Ansys Employee First Comment
    ✭✭✭
    edited June 2023
    name = 'Udres'
    udrExpressionName = 'NLELWK'
    
    try:
        DataModel.GetObjectsByName(name)[0].Delete()
    except:
        pass
    
    
    ns ='Selection'
    # store link to solution
    solu=ExtAPI.DataModel.Project.Model.Analyses[0].Solution
    # add UDR
    newUDR = solu.AddUserDefinedResult() 
    newUDR.Name = name
    newUDR.ScopingMethod = GeometryDefineByType.Component
    newUDR.Location = DataModel.GetObjectsByName(ns)[0]
    newUDR.Expression= udrExpressionName
    
    newUDR.EvaluateAllResults()
    
    udr = ExtAPI.DataModel.GetObjectsByName(name)[0] # get the result 
    nodes = udr.PlotData['Node'] # get the nodal scope for the result
    results = [value for value in udr.PlotData['Values']] # get the nodal results 
    
    
    for result,node in zip(results,nodes):
            nomax.append([result,node])
    
    
    shortList = [[i[0],i[1]] for i  in (nomax)]
    #plotNodes = [str(i[0]) for i in shortList][1:-1]
    
    res=sorted(shortList)
    
    myres=res[(len(res)-int(0.1*len(res))):(len(res)-1)]
    
    a = [i[0] for i in myres ]   
    b=sum(a)
    c= len(a)
    average = b/c
    print (average)
    
    plotNodes = ''
    for i in myres:
        plotNodes = plotNodes + str( i[1]) + ','
    plotNodes = plotNodes[:-1] # remove last comma
    
    # reset plot
    newUDR.ClearGeneratedData()
    newUDR.ScopingMethod = GeometryDefineByType.ResultFileItem
    newUDR.ItemType = ResultFileItemType.NodeIDs
    # create string of plot nodes
    
    newUDR.SolverComponentIDs = plotNodes
    newUDR.EvaluateAllResults()
    
  • Kleanthis
    Kleanthis Member, Employee Posts: 6
    Ansys Employee First Comment
    ✭✭✭
    edited June 2023