Get Harmonic results with DPF

Options
Mike.Thompson
Mike.Thompson Member, Employee Posts: 279
First Anniversary First Comment 5 Likes Ansys Employee

Get the harmonic results with DPF and compare them to the Mechanical results. Uses an operator to combine the real+img components together to get the amplitude results (same as mechanical results)

Tagged:

Comments

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 279
    First Anniversary First Comment 5 Likes Ansys Employee
    edited February 28
    Options

    FYI the code snippet from the model attached in original post is below:

    #-----------------------------------------------------------------------------------------
    #Keep this suppressed.
    #Use this code in the scripting console
    #-----------------------------------------------------------------------------------------
    #Snippet will extract the results of the harmonic analysis with complex (real and img) results.
    #It will convert it to an amplitude, and compare this against post processing objects in mechanical.
    
    #This general process is based on a single node and single freq. for purposes of comparison to Mech. results.
    #The mesh scoping and time/freq. scoping of the operators can be changed to make it more general across the mesh and freq. domains.
    #-----------------------------------------------------------------------------------------
    #User Inputs:
    FreqSet = 5                 #Frequency Set you want to get results for
    NsName = "Measure Node"     #Named Selection exact text name
    #-----------------------------------------------------------------------------------------
    
    #General Import Stuff
    import mech_dpf
    import Ans.DataProcessing as dpf
    mech_dpf.setExtAPI(ExtAPI)
    analysis=Model.Analyses[0]
    dataSource = dpf.DataSources(analysis.ResultFileName)
    
    #Get the node Id you want to measure
    MeasureNdId = ExtAPI.DataModel.GetObjectsByName(NsName)[0].Ids[0]
    MeshScoping = dpf.MeshScopingFactory.NodalScoping([MeasureNdId])
    print "Named Selection = '%s' with Node Id = %s" % (NsName, MeasureNdId)
    
    #Get the time freq. support for the results file (set, step, substep, freq. info)
    TFSOp = dpf.operators.metadata.time_freq_provider()
    TFSOp.inputs.data_sources.Connect(dataSource)
    TFS = TFSOp.outputs.time_freq_support.GetData()
    #Make a frequency scoping to know what freq. to export
    FreqScoping = dpf.TimeFreqScopingFactory.ScopingByStepAndSubstep(1,FreqSet,TFS)
    print "Frequency for results: %s [Hz]" % TFS.GetTimeFreq(FreqSet-1)  #subtract 1 for a zero-based index
    
    #Get the displacement via dpf operator
    u = dpf.operators.result.displacement()
    u.inputs.data_sources.Connect(dataSource)
    u.inputs.mesh_scoping.Connect(MeshScoping)
    u.inputs.time_scoping.Connect(FreqScoping)
    uFC = u.outputs.fields_container.GetData()
    
    #Convert the complex result (real and img.) to an amplitude result
    #This will be consistant with mechanical
    AmpOp = dpf.operators.math.amplitude_fc() # operator instantiation
    AmpOp.inputs.fields_container.Connect(uFC)
    AmpFC = AmpOp.outputs.fields_container.GetData()
    #print AmpFC
    print "DPF Results for Node: %s [X,Y,Z] with units=%s" % (MeasureNdId, AmpFC[0].Unit)
    #print AmpFC[0].Data
    DpfValues = [Quantity(V, AmpFC[0].Unit) for V in AmpFC[0].Data]
    print DpfValues
    
    CheckObjIds = [51,54,62]
    CheckObjs = [ExtAPI.DataModel.GetObjectById(Id) for Id in CheckObjIds]
    for Obj in CheckObjs:
        Obj.SetNumber=FreqSet
    Obj.Parent.EvaluateAllResults()
    for Obj in CheckObjs:
        Obj.RenameBasedOnDefinition()
    
    MechValues = [abs(Obj.Maximum) for Obj in CheckObjs]
    Diffs = [((MechValues[i] - DpfValues[i]) / MechValues[i]) * 100. for i in range(3)]
    print "% Difference in the dpf values to Mechanical object values"
    print Diffs