automation of saving Stress Date of each Simulation results with Query commends in TCL

Junhyeong Kang
Junhyeong Kang Altair Community Member
edited October 2023 in Community Q&A

hi, im simulating e-Motor with varias RPM. my goal is automation of Query of Stress Data at each RPM in csv File. and now i try to do it with 3 different RPMs.

 i made a for-loop function to make Automation. the variable $subcase is for maximum stress of each simulation. and i just a other variable $i for query. and i got only lastest Stress data of rpm. which means i did simulation for 0, 10000, and 20000 RPMs . i got stress data only of 20000RPM. do you have some idea or should i fix some sentence in For Loop? 

hwi GetSessionHandle session
session GetProjectHandle project
project GetPageHandle page [project GetActivePage]
page GetWindowHandle window [page GetActiveWindow]
window GetClientHandle client
client GetModelHandle model [client GetActiveModel]
model GetResultCtrlHandle result
 
result GetContourCtrlHandle contour
 
contour SetDataType "Element Stresses (2D & 3D)"
contour SetDataComponent component vonMises
contour SetAverageMode advanced
contour SetLayer Max
contour SetEnableState True
contour SetResultSystem 0
contour SetDimensionEnabled solid True
contour SetDimensionEnabled shell True
contour SetEnableState True
 
client GetMeasureHandle measure 1
model GetQueryCtrlHandle myQueryName
model GetSelectionSetHandle mySetName [model AddSelectionSet  node]
mySetName Add all
lappend max_stress
set subcases [result GetSubcaseList "Base"]
foreach subcase $subcases {
result SetCurrentSubcase $subcase                  ;# nächsten Subcase auswählen
client Draw                                   ;# refresh View
for {set i 1} {$i < $subcases} {incr i} {
result SetCurrentSimulation $subcase
myQueryName SetDataSourceProperty result datatype Stress
myQueryName SetDataSourceProperty result shelllayer Upper
myQueryName SetQuery "node.id, node.coords, contour.value"
myQueryName SetSelectionSet [mySetName GetID];
myQueryName WriteData {D:/junhyeong/Spannungsdaten/$i.csv}
}
lappend max_stress [measure GetMaximum scalar]     ;# Maximum an Liste anhängen
 
}
 
# Export der maximalen Spannungen
set responses_file [open "struct_responses.json" "w"]
set line "\["
append line [join $max_stress ", "]
append line "\]"
puts -nonewline $responses_file $line
close $responses_file

Thanks in Advanced

Answers

  • Adriano A. Koga
    Adriano A. Koga
    Altair Employee
    edited October 2023

    are you sure that the RPM is the subcase and not simulation?

    Maybe this is what is not working, but it depends on your result file.

  • Junhyeong Kang
    Junhyeong Kang Altair Community Member
    edited October 2023

    are you sure that the RPM is the subcase and not simulation?

    Maybe this is what is not working, but it depends on your result file.

    hey Adriano,

    i made for look inside of foreach Loop. here u can see my TCL Code below.

    i made variable i to compare with subcases(every simulation of different RPMs). every Stress Data of each RPM Simulation should be Saved. but now i have a new problem. i made simulations of 0, 10000, 20000 RPM. and it was saved but the Data of 3 txt file are Results of  20000RPM simulation result... i dont know why its like this. do you know reason? Thanks in Advanced

     

    hwi GetSessionHandle session
    session GetProjectHandle project
    project GetPageHandle page [project GetActivePage]
    page GetWindowHandle window [page GetActiveWindow]
    window GetClientHandle client
    client GetModelHandle model [client GetActiveModel]
    model GetResultCtrlHandle result
     
    result GetContourCtrlHandle contour
     
    contour SetDataType "Element Stresses (2D & 3D)"
    contour SetDataComponent component vonMises
    contour SetAverageMode advanced
    contour SetLayer Max
    contour SetEnableState True
    contour SetResultSystem 0
    contour SetDimensionEnabled solid True
    contour SetDimensionEnabled shell True
    contour SetEnableState True
     
    client GetMeasureHandle measure 1
    model GetQueryCtrlHandle myQueryName
    model GetSelectionSetHandle mySetName [model AddSelectionSet  node]
    mySetName Add all
     
    lappend max_stress
    set subcases [result GetSubcaseList "Base"]
    foreach subcase $subcases {
    result SetCurrentSubcase $subcase                  ;# nächsten Subcase auswählen
    client Draw                                   ;# refresh View
    for {set i 0} {$i < $subcase} {incr i} {
    result SetCurrentSimulation $i
    myQueryName SetDataSourceProperty result datatype Stress
    myQueryName SetDataSourceProperty resuslt shelllayer Upper
    myQueryName SetQuery "node.id, node.coords, contour.value"
    myQueryName SetSelectionSet [mySetName GetID]
    myQueryName WriteData {D:/junhyeong/Spannungsdaten/test.txt}
     
        file rename -force D:/junhyeong/Spannungsdaten/test.txt D:/junhyeong/Spannungsdaten/${i}.txt
    }
    lappend max_stress [measure GetMaximum scalar]     ;# Maximum an Liste anhängen
    }
     
     
    # Export der maximalen Spannungen
    set responses_file [open "struct_responses.json" "w"]
    set line "\["
    append line [join $max_stress ", "]
    append line "\]"
    puts -nonewline $responses_file $line
    close $responses_file
  • Adriano A. Koga
    Adriano A. Koga
    Altair Employee
    edited October 2023

    hey Adriano,

    i made for look inside of foreach Loop. here u can see my TCL Code below.

    i made variable i to compare with subcases(every simulation of different RPMs). every Stress Data of each RPM Simulation should be Saved. but now i have a new problem. i made simulations of 0, 10000, 20000 RPM. and it was saved but the Data of 3 txt file are Results of  20000RPM simulation result... i dont know why its like this. do you know reason? Thanks in Advanced

     

    hwi GetSessionHandle session
    session GetProjectHandle project
    project GetPageHandle page [project GetActivePage]
    page GetWindowHandle window [page GetActiveWindow]
    window GetClientHandle client
    client GetModelHandle model [client GetActiveModel]
    model GetResultCtrlHandle result
     
    result GetContourCtrlHandle contour
     
    contour SetDataType "Element Stresses (2D & 3D)"
    contour SetDataComponent component vonMises
    contour SetAverageMode advanced
    contour SetLayer Max
    contour SetEnableState True
    contour SetResultSystem 0
    contour SetDimensionEnabled solid True
    contour SetDimensionEnabled shell True
    contour SetEnableState True
     
    client GetMeasureHandle measure 1
    model GetQueryCtrlHandle myQueryName
    model GetSelectionSetHandle mySetName [model AddSelectionSet  node]
    mySetName Add all
     
    lappend max_stress
    set subcases [result GetSubcaseList "Base"]
    foreach subcase $subcases {
    result SetCurrentSubcase $subcase                  ;# nächsten Subcase auswählen
    client Draw                                   ;# refresh View
    for {set i 0} {$i < $subcase} {incr i} {
    result SetCurrentSimulation $i
    myQueryName SetDataSourceProperty result datatype Stress
    myQueryName SetDataSourceProperty resuslt shelllayer Upper
    myQueryName SetQuery "node.id, node.coords, contour.value"
    myQueryName SetSelectionSet [mySetName GetID]
    myQueryName WriteData {D:/junhyeong/Spannungsdaten/test.txt}
     
        file rename -force D:/junhyeong/Spannungsdaten/test.txt D:/junhyeong/Spannungsdaten/${i}.txt
    }
    lappend max_stress [measure GetMaximum scalar]     ;# Maximum an Liste anhängen
    }
     
     
    # Export der maximalen Spannungen
    set responses_file [open "struct_responses.json" "w"]
    set line "\["
    append line [join $max_stress ", "]
    append line "\]"
    puts -nonewline $responses_file $line
    close $responses_file

    Like I mentioned before, you need to take care with the difference of 'subcase' and 'simulation'.

     

    Make sure that you're changing the correct one inside your loop.

    image

    Additionally, you could much easily use HWC commands for some of these commands, except the query.

    https://community.altair.com/community?id=community_question&sys_id=db72fa0adbec8d10cfd5f6a4e2961950&view_source=searchResult