Get results from different subcases

Christian Nörenberg
Christian Nörenberg Altair Community Member
edited March 2023 in Community Q&A

Hi,

I have a model of a rotating e-motor and solved the model with 3 different speeds with OptiStruct (as different loadsteps / loadcols).
Now I'm struggeling with the tcl commands for getting the value for the max stress for all 3 subcases.

The first steps are the same as for single speed:

hwi GetSessionHandle mySessionName mySessionName GetProjectHandle myProjectName set pageIndex [myProjectName GetActivePage] myProjectName GetPageHandle myPageName $pageIndex set windowIndex [myPageName GetActiveWindow] myPageName GetWindowHandle myWindowName $windowIndex myWindowName GetClientHandle myPostName set modelIndex [myPostName GetActiveModel] myPostName GetModelHandle myModelName $modelIndex myModelName GetResultCtrlHandle myResultName myResultName GetContourCtrlHandle contour_handle contour_handle SetDataType "Element Stresses (2D & 3D)" contour_handle SetDataComponent component vonMises contour_handle SetAverageMode advanced contour_handle SetLayer Max contour_handle SetEnableState True contour_handle SetResultSystem 0 myResultName SetCurrentSimulation 0 contour_handle SetDimensionEnabled solid True contour_handle SetDimensionEnabled shell True contour_handle SetEnableState True  # Maximum stress value myModelName GetQueryCtrlHandle myQueryName myModelName GetSelectionSetHandle mySetName [myModelName AddSelectionSet component] mySetName Add all myQueryName SetQuery "contour.max" myQueryName SetSelectionSet [mySetName GetID] myQueryName GetIteratorHandle qry_iterator

Now I can get the max stress for the first subcase with

set query_list [qry_iterator GetDataList] set max_stress [lindex $query_list 0]

and this command also works if I change the subcases manually.

image

But if I use the following for-loop to change the current subcase, the list / value is empty / "N/A":

# doesnt work set subcases [myResultName GetSubcaseList "Base"] foreach subcase $subcases { 	myResultName SetCurrentSubcase $subcase 	set query_list [qry_iterator GetDataList] }  # doesnt work either myResultName SetCurrentSubcase 1 set query_list [qry_iterator GetDataList]  myResultName SetCurrentSubcase 2 set query_list [qry_iterator GetDataList]  myResultName SetCurrentSubcase 3 set query_list [qry_iterator GetDataList] 

So what am I missing?

Thanks for your help!

Best Answer

  • Michele Macchioni
    Michele Macchioni
    Altair Employee
    edited March 2023 Answer ✓

    Hey Christian,

    a couple of different approches:

    #1 why not using default static measure max (ID = 1) and retrieve its value rather than using a query handle?

    #2 have you thought of creating an envelope load case upfront and contour it rather than use a loop?

     

    My 2 cents.

    Cheers

    Michele

Answers

  • Michele Macchioni
    Michele Macchioni
    Altair Employee
    edited March 2023 Answer ✓

    Hey Christian,

    a couple of different approches:

    #1 why not using default static measure max (ID = 1) and retrieve its value rather than using a query handle?

    #2 have you thought of creating an envelope load case upfront and contour it rather than use a loop?

     

    My 2 cents.

    Cheers

    Michele

  • Christian Nörenberg
    Christian Nörenberg Altair Community Member
    edited March 2023

    Hi Michele,

    I chose your first idea and my code looks like this (after the first big part of code from above):

    myPostName GetMeasureHandle measure_handle 1  lappend max_stress set subcases [myResultName GetSubcaseList "Base"] foreach subcase $subcases { 	myResultName SetCurrentSubcase $subcase 	myPostName Draw 	lappend max_stress [measure_handle GetMaximum scalar] } puts $max_stress

    At least when hyperview is started with GUI (which means without batch mode) it is important to "refresh" the view. Otherwise it will fail / crash (command is "myPostName Draw").

    Thanks for the help!

     

  • Michele Macchioni
    Michele Macchioni
    Altair Employee
    edited March 2023

    Hi Michele,

    I chose your first idea and my code looks like this (after the first big part of code from above):

    myPostName GetMeasureHandle measure_handle 1  lappend max_stress set subcases [myResultName GetSubcaseList "Base"] foreach subcase $subcases { 	myResultName SetCurrentSubcase $subcase 	myPostName Draw 	lappend max_stress [measure_handle GetMaximum scalar] } puts $max_stress

    At least when hyperview is started with GUI (which means without batch mode) it is important to "refresh" the view. Otherwise it will fail / crash (command is "myPostName Draw").

    Thanks for the help!

     

    Nice!

    Just FYI, you may want to consider to use HyperWorks Command Launguage (HWC) to short cut the path to the commands

    image

    you may find very useful to use the TCL wrap on top of these commands just by simply using the hwc statement before the command you get logged.

    I am also attaching a small tcl which does loop thru the load cases and create a snapshot of a contour plot. 

    You can see it uses this hybrid format and on top of this it uses the namespace postquery which allows you to access directly handles and other shortcuts bypassing the handle hierachy and taking care of handle garbage collection.

    image

    Sure this will super boost your productivity.

    Regards

    Michele