Traversing Results

The API for direct result access allows you to do postprocessing without result objects.

An example python function to compute minimum and maximum results follows. It begins by instantiating a result reader using the method analysis.GetResultsData(). Results are retrieved relative to the finite element model and queried using either the elementID (elemental result) or the nodeID (nodal result). The displacement result U is a nodal result, whereas the stress result S is a result on nodes of the elements. The displacement result stores a set of component values for each node, where the component names are X, Y, and Z.

The function first iterates over the nodeIDs to compute the minimum and maximum values. It then iterates over the elementIDs and the nodes of each element to compute the minimum and maximum values.


Note:  The second loop over the nodes is filtered to the corner nodes of the elements because stress results are available only on these corner nodes.


Finally, the results are written to the output file.

def minmaxresults(analysis):
    now = datetime.datetime.now()
    f = open("C:\\resultsInfo.txt",'w')    
    f.write("*.*.*.*.*.*.*.*\n")
    f.write(str(now)+"\n")
    #
    # Get the element ids 
    #
    meshObj = analysis.MeshData
    elementids = meshObj.ElementIds
    nodeids = meshObj.NodeIds
    #  
    # Get the results reader
    #
    reader = analysis.GetResultsData()
    reader.CurrentResultSet = int(1) 
    #
    # Get the displacement result object
    displacement = reader.GetResult("U")
    
    num = 0
    for nodeid in nodeids: 
        #
        # Get the component displacements (X Y Z) for this node
        #     
        dispvals = displacement.GetNodeValues(nodeid)
        #
        # Determine if the component diplacement (X Y Z) is min or max
        #
        if num == 0:
            maxdispx = dispvals[0]
            mindispx = dispvals[0]
            maxdispy = dispvals[1]
            mindispy = dispvals[1]
            maxdispz = dispvals[2]
            mindispz = dispvals[2]
        
        num += 1
        
        if dispvals[0] > maxdispx:
            maxdispx = dispvals[0]
        if dispvals[1] > maxdispy:
            maxdispy = dispvals[1]
        if dispvals[2] > maxdispz:
            maxdispz = dispvals[2]
        if dispvals[0] < mindispx:
            mindispx = dispvals[0]
        if dispvals[1] < mindispy:
            mindispy = dispvals[1]
        if dispvals[2] < mindispz:
            mindispz = dispvals[2]
    
    # Get the stress result object
    stress = reader.GetResult("S")
    
    num = 0
    for elementid in elementids:  
        element = meshObj.ElementById(elementid)
        #
        # Get the SXX stress component
        #
        stressval = stress.GetElementValues(elementid)
        #
        # Get the primary node ids for this element
        #
        nodeids = element.CornerNodeIds
        for i in range(nodeids.Count): 
            #
            # Get the SXX stress component at node "nodeid"
            #
            SXX = stressval[i]
            #
            # Determine if the SXX stress component is min or max
            #
            if num == 0:
                maxsxx = SXX
                minsxx = SXX
            
            if SXX > maxsxx:
                maxsxx = SXX
            if SXX < minsxx:
                minsxx = SXX
                
            num += 1
    #
    # Write the results to the output
    #
    f.write("Max U,X:Y:Z = "+maxdispx.ToString()+" : "+maxdispy.ToString()+" : "+maxdispz.ToString()+"\n")
    f.write("Min U,X:Y:Z = "+mindispx.ToString()+" : "+mindispy.ToString()+" : "+mindispz.ToString()+"\n")
    f.write("Max SXX = "+maxsxx.ToString()+"\n")
    f.write("Min SXX = "+minsxx.ToString()+"\n")
    f.close()