How to plot temperature time history on a set of nodes in Mechanical using DPF?

Rohith Patchigolla
Rohith Patchigolla Member, Moderator, Employee Posts: 175
100 Comments Photogenic Ansys Employee 5 Likes
✭✭✭✭

I have some nodes on which I want to plot temperature variation over time in a thermal analysis. I have not created a named selection for these nodes. How can I use Python Result object to plot time vs Temperature plot for these nodes?

Answers

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 175
    100 Comments Photogenic Ansys Employee 5 Likes
    ✭✭✭✭
    edited March 21

    Tested in 23R2 and 24R1.

    Step 1: RMB on Solution (of a thermal analysis) --> Insert --> Python Results
    Step 2: You can use the below script in a Python Result object in Mechanical to plot temperature time history on a set of nodes provided as an input via a list "nodeIds".

    def post_started(sender, analysis):# Do not edit this line
        define_dpf_workflow(analysis)
    
    # Uncomment this function to enable retrieving results from the table/chart
    def table_retrieve_result(value):# Do not edit this line
        import mech_dpf
        import Ans.DataProcessing as dpf
        wf = dpf.Workflow(this.WorkflowId)
        wf.Connect('contour_selector', value)
        this.Evaluate()
    
    def define_dpf_workflow(analysis):
        import mech_dpf
        import Ans.DataProcessing as dpf
        mech_dpf.setExtAPI(ExtAPI)
        dataSource = dpf.DataSources(analysis.ResultFileName)
        model = dpf.Model(dataSource)
    
    
        #Input node numbers
        nodeIds = [10265, 10266]
        scoping = dpf.Scoping()
        scoping.Location = 'Nodal'
        scoping.Ids = nodeIds
    
        temp = dpf.operators.result.temperature()
    
        time_freq_support = dpf.operators.metadata.time_freq_provider()
        time_freq_support.inputs.data_sources.Connect(dataSource)
        n_sets = time_freq_support.outputs.time_freq_support.GetData().NumberSets
    
        timeScop = dpf.Scoping()
    
        # Compute time history
        time_steps = range(1, n_sets + 1)
        timeScop.Ids = time_steps
        temp.inputs.time_scoping.Connect(timeScop)
        temp.inputs.data_sources.Connect(dataSource)
        temp.inputs.mesh_scoping.Connect(scoping)
        dpf_workflow = dpf.Workflow()
        dpf_workflow.Add(temp)
        dpf_workflow.SetInputName(temp, 0, 'time')
        dpf_workflow.Connect('time', timeScop)
        dpf_workflow.SetOutputContour(temp)
        dpf_workflow.Record('wf_id', False)
        this.WorkflowId = dpf_workflow.GetRecordedId()
    

    Step 3: RMB on Solution --> Evaluate all results