Get Harmonic results with DPF

Member, Employee Posts: 385
25 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭

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

  • Member, Employee Posts: 385
    25 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited February 2024

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

    1. #-----------------------------------------------------------------------------------------
    2. #Keep this suppressed.
    3. #Use this code in the scripting console
    4. #-----------------------------------------------------------------------------------------
    5. #Snippet will extract the results of the harmonic analysis with complex (real and img) results.
    6. #It will convert it to an amplitude, and compare this against post processing objects in mechanical.
    7.  
    8. #This general process is based on a single node and single freq. for purposes of comparison to Mech. results.
    9. #The mesh scoping and time/freq. scoping of the operators can be changed to make it more general across the mesh and freq. domains.
    10. #-----------------------------------------------------------------------------------------
    11. #User Inputs:
    12. FreqSet = 5 #Frequency Set you want to get results for
    13. NsName = "Measure Node" #Named Selection exact text name
    14. #-----------------------------------------------------------------------------------------
    15.  
    16. #General Import Stuff
    17. import mech_dpf
    18. import Ans.DataProcessing as dpf
    19. mech_dpf.setExtAPI(ExtAPI)
    20. analysis=Model.Analyses[0]
    21. dataSource = dpf.DataSources(analysis.ResultFileName)
    22.  
    23. #Get the node Id you want to measure
    24. MeasureNdId = ExtAPI.DataModel.GetObjectsByName(NsName)[0].Ids[0]
    25. MeshScoping = dpf.MeshScopingFactory.NodalScoping([MeasureNdId])
    26. print "Named Selection = '%s' with Node Id = %s" % (NsName, MeasureNdId)
    27.  
    28. #Get the time freq. support for the results file (set, step, substep, freq. info)
    29. TFSOp = dpf.operators.metadata.time_freq_provider()
    30. TFSOp.inputs.data_sources.Connect(dataSource)
    31. TFS = TFSOp.outputs.time_freq_support.GetData()
    32. #Make a frequency scoping to know what freq. to export
    33. FreqScoping = dpf.TimeFreqScopingFactory.ScopingByStepAndSubstep(1,FreqSet,TFS)
    34. print "Frequency for results: %s [Hz]" % TFS.GetTimeFreq(FreqSet-1) #subtract 1 for a zero-based index
    35.  
    36. #Get the displacement via dpf operator
    37. u = dpf.operators.result.displacement()
    38. u.inputs.data_sources.Connect(dataSource)
    39. u.inputs.mesh_scoping.Connect(MeshScoping)
    40. u.inputs.time_scoping.Connect(FreqScoping)
    41. uFC = u.outputs.fields_container.GetData()
    42.  
    43. #Convert the complex result (real and img.) to an amplitude result
    44. #This will be consistant with mechanical
    45. AmpOp = dpf.operators.math.amplitude_fc() # operator instantiation
    46. AmpOp.inputs.fields_container.Connect(uFC)
    47. AmpFC = AmpOp.outputs.fields_container.GetData()
    48. #print AmpFC
    49. print "DPF Results for Node: %s [X,Y,Z] with units=%s" % (MeasureNdId, AmpFC[0].Unit)
    50. #print AmpFC[0].Data
    51. DpfValues = [Quantity(V, AmpFC[0].Unit) for V in AmpFC[0].Data]
    52. print DpfValues
    53.  
    54. CheckObjIds = [51,54,62]
    55. CheckObjs = [ExtAPI.DataModel.GetObjectById(Id) for Id in CheckObjIds]
    56. for Obj in CheckObjs:
    57. Obj.SetNumber=FreqSet
    58. Obj.Parent.EvaluateAllResults()
    59. for Obj in CheckObjs:
    60. Obj.RenameBasedOnDefinition()
    61.  
    62. MechValues = [abs(Obj.Maximum) for Obj in CheckObjs]
    63. Diffs = [((MechValues[i] - DpfValues[i]) / MechValues[i]) * 100. for i in range(3)]
    64. print "% Difference in the dpf values to Mechanical object values"
    65. print Diffs

Welcome!

It looks like you're new here. Sign in or register to get started.