How to compute time dependent results difference between two nodes and display the results?

Pierre Thieffry
Pierre Thieffry Member, Moderator, Employee Posts: 107
25 Answers Second Anniversary 10 Comments 25 Likes
✭✭✭✭
edited June 2023 in Structures

After a nonlinear or transient run, I want to plot a graph that shows (uy@node1 - uy@node2)-(uy@node1 - uy@node2)@reftime. How can I achieve this in Mechanical?

Tagged:

Answers

  • Pierre Thieffry
    Pierre Thieffry Member, Moderator, Employee Posts: 107
    25 Answers Second Anniversary 10 Comments 25 Likes
    ✭✭✭✭
    Answer ✓

    There are two answers to this question - one in APDL, one with DPF and a Python result.

    While the code looks more complex for an APDL user, the Python results has several benefits:

    • Scoping could be added to select nodes to compare

    • Graph is a native Mechanical object

    • Results are unit dependent

    • Table can be easily copied

    APDL:

    set,last
    
    sho,png /post26 nsol,2,359,u,y,UY_OD ! Retrieve UY at node 359 
    nsol,3,360,u,y,UY_ID ! Retrieve UY at node 360 
    add,4,2,3,,UY(OD-ID),,,1,-1 ! Compute UY_OD-UY_ID
    
    *get,y_assem,vari,4,real,1.0 ! Get refvalue of above difference at time = 1.0 
    filldata,5,,,,y_assem ! Create vector with above refvalue
    
    add,6,4,5,,DELTA,,,1,-1 ! Compute (UY_OD-UY_ID)-refvalue
    
    prvar,2,3,4,5,6 ! Print all variables
    
    /xrange,1,30 ! Limit plot range to time from 1. to 30.s 
    plvar,6 ! Plot variable 6
    

    DPF/Python Result

    node1=359
    node2=360
    reftime=1.0
    
    model=dpf.Model(dataSource)
    all_times=model.TimeFreqSupport.TimeFreqs.Data # Retrieve all time values
    
    refIndex=all_times.IndexOf(reftime)+1 # Index of reftime
    
    timeIds=range(refIndex,len(all_times)+1) # List of time steps for time scoping
    
    nodeSc1=dpf.Scoping([node1],'Nodal') # scoping for uy at node 1
    nodeSc2=dpf.Scoping([node2],'Nodal') # scoping for uy at node 2
    
    uy1 = dpf.operators.result.displacement_Y(data_sources=dataSource,time_scoping=timeIds,mesh_scoping=nodeSc1) # operator for node 1 
    uydiff = dpf.operators.result.displacement_Y(data_sources=dataSource,time_scoping=timeIds,mesh_scoping=nodeSc1) # operator for end result 
    uy2 = dpf.operators.result.displacement_Y(data_sources=dataSource,time_scoping=timeIds,mesh_scoping=nodeSc2) # operator for node 1
    
    for time in timeIds: # Compute uy1-uy2 and store in uydiff    
        v1=uy1.outputs.getfields_container().GetFieldByTimeId(time).Data[0]
        v2=uy2.outputs.getfields_container().GetFieldByTimeId(time).Data[0]
        uydiff.outputs.getfields_container().GetFieldByTimeId(time).Data=[v1-v2]
    
    refval=uydiff.outputs.getfields_container().GetFieldByTimeId(all_times.IndexOf(reftime)+1).Data[0] # Retrieve refvalue at reftime
    
    uydiff=uydiff-refval # substract from previous results
    
    with open(r'd:\temp\udiff.txt','w') as f: # write results to text file 
    for time in timeIds:
        v1=uy1.outputs.getfields_container().GetFieldByTimeId(time).Data[0] 
        v2=uy2.outputs.getfields_container().GetFieldByTimeId(time).Data[0] 
        vdiff=uydiff.outputs.getfields_container().GetFieldByTimeId(time).Data[0] 
        f.write("{:16.9f}{:16.9f}{:16.9f}{:16.9f}{:16.9f}{:16.9f}\n".format(all_times[time-1],v1,v2,v1-v2,refval,vdiff))
    
    #Display in Mechanical
    dpf_workflow = dpf.Workflow()
    dpf_workflow.Add(uydiff)
    dpf_workflow.SetOutputContour(uydiff) 
    dpf_workflow.Record('wf_id', True) 
    this.WorkflowId = dpf_workflow.GetRecordedId()