Você está na página 1de 20

Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Chapter 5: Results and Querying


Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query – Overview

• Applying Results

• Contour Plot

• Querying Results
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query – Applying Results

• From the result control object, you can access all other result-related
objects including, contour, iso value, tensor, vector etc…

• To apply any type of results, make sure that you have attached a results
file to the model that’s loaded in the animation client.

• Once you have a result control handle, you can get a handle to the
desired control using GetNameCtrlHandle (i.e.
GetContourCtrlHandle, GetTensorCtrlHandle etc…).

• The methods provided by the various control are almost identical (i.e.
SetDataType, SetDataComponent, etc…).
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query – Contour Plot

• Get the contour control handle and work with or without having a contour plot
displayed.

• From the result control, use GetContourCtrlHandle to get the contour control.

• Example: Apply a contour plot (assuming bumper.h3d model and results loaded
in the animation window). In this example, create a contour plot showing Stress
 vonMises  Max
my_result GetContourCtrlHandle my_contour
# set up request
my_contour SetDataType Stress
my_contour SetDataComponent vonMises
my_contour SetLayer Max
# update graphics
anim Draw
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query – Contour Plot

• If you type the code on the previous side in TkCon (use copy/paste), you
would expect to see a contour plot; however, no changes appear on the
screen.

• The reason is you have yet to enable drawing of contour plot. To enable
drawing of contour plot, you need two commands before the “anim
Draw” statement:
# enable drawing of contour plot
my_contour SetEnableState true
anim SetDisplayOptions contour true
# update graphics
anim Draw
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query – Contour Plot

• After adding these statements, you will actually see a contour plot, but it
is all “gray” color; this is because we are still at the model step (you can
animate the results by pressing on the traffic light to see the contour plot).

• Do this by setting the current simulation using the result control.


# go to first simulation
my_result SetCurrentSimulation 0
# update graphics
anim Draw

• Depending on use case, you can go to last step, for example, by using
the GetNumberOfSimualations command.
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query – Contour Plot

• Apply a contour on only part of the model (elements or parts)

• Use SetSelectionSet command in the contour control


• Create selection set
• Add particular IDs to selection set
• Set it as selection set to be used by contour control
# add part set
set set_id [my_model AddSelectionSet part]
my_model GetSelectionSetHandle my_set $set_id
my_set Add "id 2"
# enable set inside contour control
my_contour SetSelectionSet $set_id
# clean up (set not needed anymore)
my_model RemoveSelectionSet $set_id
# update graphics
anim Draw
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query – Contour Plot

• Rules to Remember when working with the contour control


• Data types names, data component names, or any other part of the request,
must exist in the list of results.
• You can get the list from the result control and check if it exists
• You can selectively apply results using selection sets
• You must enable drawing using two settings:
• Set enable state in the control (use SetEnableState command)
• Set display option in the animation client (use SetDisplayOptions
command)
• Make sure you enable drawing last (after setting up the request)
• If results don’t show up, make sure you’re not at the model step
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Exercise 5.1

Contouring Results and Contouring by Selection


Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query – Querying Results

• Previously looked at the Query Control

• Here we will look at Querying Results

• Commonly done in macros

• For the next example we will be:


• Extracting results for a set of elements
• Assume we have a contour plot of Stress -> vonMises -> Max
• We need to get the stress values for element IDs 100-110
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query – Querying Results

my_model GetQueryCtrlHandle my_query


# create an element set and add ids 100-110
set set_id [my_model AddSelectionSet element]
my_model GetSelectionSetHandle elem_set $set_id
elem_set Add "id 100-110"
my_query SetSelectionSet $set_id
# ask for ids and stress value
my_query SetQuery "element.id contour.value"
# clean up
my_model RemoveSelectionSet $set_id
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query – Querying Results

• Output the query results to a file

• Use the WriteData command

• For example, write data from my_query to C:/Temp/out.txt

my_query WriteData C:/Temp/out.txt

• Writes data to file in comma separated format:


id,value
109,7.525E+02
107,7.620E+02
100,7.200E+02
103,7.534E+02
104,7.478E+02
105,5.956E+02
106,5.302E+02
108,6.860E+02
110,7.287E+02
101,9.593E+02
102,9.842E+02
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query – Querying Results

• Iterator class allows you to go over data one record at a time

• Use GetIteratorHandle on the query handle

• Use GetDataList on the Iterator Handle to get the values

• Use First, Next, and Valid to move through the records

• It is recommended to use a loop:

my_query GetIteratorHandle my_iter


for {my_iter First} {[my_iter Valid]} {my_iter Next} {
my_iter GetDataList
}
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query – Querying Results

• Create a list of data to be used at a later time

my_query GetIteratorHandle my_iter


set data_list ""
for {my_iter First} {[my_iter Valid]} {my_iter Next} {
lappend data_list [my_iter GetDataList]
}

• Variable named “data_list” is a list of lists containing the following data:

{109 7.525E+02} {107 7.620E+02} {100 7.200E+02} {103 7.534E+02}


{104 7.478E+02} {105 5.956E+02} {106 5.302E+02} {108 6.860E+02}
{110 7.287E+02} {101 9.593E+02} {102 9.842E+02}
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query – Querying Results

• Iterator handle is valid only for the current time step

• To get data for different time steps, you need to release the Iterator handle as
you set the current time step
# set the current subcase and get number of simulations
set subcase [my_result GetCurrentSubcase]
set sims [my_result GetNumberOfSimulations $subcase]
# loop through sims and set Iterator Handle
for {set step 0} {$step < $sims} {incr step} {
my_result SetCurrentSimulation $step
my_query GetIteratorHandle my_iter
for {my_iter First} {[my_iter Valid]} {my_iter Next} {
my_iter GetDataList
}
# release Iterator Handle
my_iter ReleaseHandle
}
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query – Querying Results

• Values can be reported on either elements or nodes


• Contour plot of stress – values reported on elements
• Enable averaging on contour plot of stress – values reported on nodes

• GetBinding command reports whether result is nodal or elemental


• Used on the contour, tensor, and vector control handle
my_model GetResultCtrlHandle my_result
my_result GetContourCtrlHandle my_contour
set entity_type [my_contour GetBinding]
set set_id [my_model AddSelectionSet $entity_type]
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Exercise 5.2

Querying Contoured Results and Creating a List of Results


Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query - Exercise

Exercise 5a

Description:

Assuming you have loaded bumper_deck_key and d3plot (located in


C:/Altair/hw11.0/tutorials/mv_hv_hg/animation/bumper), applied a
contour plot Stress  vonMises  Max and you are at the last time step.
Get all elements that have a stress value above 1200. Create a group
labeled “stress value > 1200” and make it visible.

Handles used

session, project, page, window, client, model, selection set

TCL/TK commands used

set, expr, GetNumberOfSimulations, SetCurrentSimulation

Hints

Find out what rules you can use to add entities to a selection set
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query - Exercise

Exercise 5b

Description:

Assuming you have loaded bumper_deck_key and d3plot (located in


C:/Altair/hw11.0/tutorials/mv_hv_hg/animation/bumper), applied a contour
plot Stress  vonMises  Max  Simple averaging and you are at the last
time step. Using the query control, get the top 100 entities with highest
values and extract the min, max and average. Output the results (min, max,
and average) to the Command Window.

Handles used

session, project, page, window, client, model, selection set, query, iterator

TCL/TK commands used

set, foreach, expr, SetAverageMode, SetQuery, lsort, lindex,

Hints

Find out what rules you can use to add entities to a selection set
Copyright © 2009 Altair Engineering, Inc. Proprietary and Confidential. All rights reserved.

Results and Query - Exercise

Exercise 5c (optional)

Description: Assuming you have loaded bumper.h3d, applied any contour plot
(elemental of nodal). Create a namespace named myspace. Using the query
control, get the maximum contour value for every time step in every loadcase and
then the overall maximum value for the loadcase. Output the following to the
console for every time step:
- Time step label - Max value
- Entity ID - Part ID
And at the end:
- loadcase label - Max value - Entity ID
- Part ID - Time step label
Handles used

session, project, page, window, client, model, query, iterator

TCL/TK commands used

set, foreach, expr

Hints

Make sure you use the iterator handle properly

Você também pode gostar