How to automate the results plotting of 'cooling rates' in a thermal analysis?

Erik Kostson
Erik Kostson Member, Employee Posts: 233
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭
edited July 19 in Structures

Say we want to plot a form of cooling rate in a thermal analysis, so perhaps like Tempertaure@time2 - Tempertaure@time1/dt, where dt is the time (step) between time 2 and 1, how can we do that using scripting?

Best Answer

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 233
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited July 19 Answer ✓

    One of many possible ways is shown below:

    model=ExtAPI.DataModel.Project.Model # refer to Model
    analysis = model.Analyses[0]
    reader = analysis.GetResultsData() # get results data of first analysis in the tree
    solution = analysis.Solution
    
    ns=model.NamedSelections.Children[0] # change nodal named selection / picks the first one
    
    DataSets=reader.ListTimeFreq
    
    with Transaction():
        for t in range(0,len(DataSets),1):
            sol1=analysis.Solution.AddTemperature()
            sol1.Location=ns
            sol1.Identifier="T_" + str(t)
            sol1.DisplayTime = Quantity(float(DataSets[t]), "sec")
        for t in range(0,len(DataSets)-1,1):
            dt = DataSets[t+1]-DataSets[t]
            udr=analysis.Solution.AddUserDefinedResult()
            udr.Location=ns
            udr.Expression="(T_"+ str(t+1) + "-" + "T_" + str(t) + ")/" + str(dt)
    solution.EvaluateAllResults()
    reader.Dispose()
    

    and finally another possible way:

    model=ExtAPI.DataModel.Project.Model # refer to Model
    analysis = model.Analyses[0]
    reader = analysis.GetResultsData() # get results data of first analysis in the tree
    solution = analysis.Solution
    
    ns=model.NamedSelections.Children[0] # change nodal named selection / picks the first one
    
    DataSets=reader.ListTimeFreq
    j=0 # local variable
    with Transaction():
        sol1=analysis.Solution.AddTemperature()
        sol1.Location=ns
        sol1.Identifier="T_" + str(0)
        sol1.DisplayTime = Quantity(float(DataSets[0]), "sec")
        sol1=analysis.Solution.AddTemperature()
        sol1.Location=ns
        sol1.Identifier="T_" + str(1)
        sol1.DisplayTime = Quantity(float(DataSets[1]), "sec")
        dt = DataSets[1]-DataSets[0]
        udr=analysis.Solution.AddUserDefinedResult()
        udr.Location=ns
        udr.Expression="(T_"+ str(1) + "-" + "T_" + str(0) + ")/" + str(dt)
        for t in range(2,len(DataSets),1):
            sol1=analysis.Solution.AddTemperature()
            sol1.Location=ns
            sol1.Identifier="T_" + str(t)
            sol1.DisplayTime = Quantity(float(DataSets[t]), "sec")
            dt = DataSets[t]-DataSets[t-1]
            udr=analysis.Solution.AddUserDefinedResult()
            udr.Location=ns
            udr.Expression="(T_"+ str(t) + "-" + "T_" + str(t-1) + ")/" + str(dt)
    solution.EvaluateAllResults()
    reader.Dispose()
    
This discussion has been closed.