innovation intelligence ® 1 chapter 5: retrieving data from hypermesh entities

13
Innovation Intelligence ® 1 Chapter 5: Retrieving Data from HyperMesh Entities

Upload: bertram-doyle

Post on 28-Dec-2015

231 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: Innovation Intelligence ® 1 Chapter 5: Retrieving Data from HyperMesh Entities

Innovation Intelligence®

1

Chapter 5: Retrieving Data from

HyperMesh Entities

Page 2: Innovation Intelligence ® 1 Chapter 5: Retrieving Data from HyperMesh Entities

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

22

Retrieving Data from HyperMesh Entities - Overview

Topics Presented:

• HyperMesh Entities and Their Data Names• Using the hm_getentityvalue command

• Pointers and Flags • Process for Creating a HyperMesh Tcl Script to Retrieve Data on

HyperMesh Entities• Example: Automate Computing the Vector Sum of Forces

Page 3: Innovation Intelligence ® 1 Chapter 5: Retrieving Data from HyperMesh Entities

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

3

HyperMesh Entities and Their Data Names

• What are Data Names?• Generic references to the information that physically defines an entity in the

HyperMesh environment • Example: The x, y, and z coordinates that define a node’s location in three-

dimensional space. • This information is part of the entity’s definition and is consistent for all

solvers.

• Data Names can change from one HyperMesh version to the next. • For this reason, please refer to the online help. Information on the data

names can be found in the following location:

HyperMesh > Reference Guide > Scripts > Creating Scripts > Tcl > Using Data Names

Page 4: Innovation Intelligence ® 1 Chapter 5: Retrieving Data from HyperMesh Entities

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

4

HyperMesh Entities and Their Data Names

node when a load is applied to a node, this serves as a pointer to the node

comp1 x component of the vector

comp2 y component of the vector

comp3 z component of the vector

magnitude magnitude of the load vector

collector collector that owns the load (load collector pointer)

• How to access Data Names?• hm_getentityvalue command

• accesses data names and template info associated with an entity• Returns a string or floating point value

hm_getentityvalue entity_type name_or_id data_name_string flag

• Example:• Set the x component of a force with ID 12 to the variable force_x:

set force_x [hm_getentityvalue loads 12 "comp1" 0]• Several Data Names available for force loads:

Page 5: Innovation Intelligence ® 1 Chapter 5: Retrieving Data from HyperMesh Entities

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

5

HyperMesh Entities and Their Data Names

id The ID of the node (integer).

inputsystem Pointer to the node input system (pointer).

outputsystem Pointer to the node output system (pointer).

xThe x coordinate of the node in its local system (real).

yThe y coordinate of the node in its local system (real).

zThe z coordinate of the node in its local system (real).

• Example: Tcl script which prompts the user to select several nodes and then displays their x, y, and z coordinates

hm_markclear nodes 1*createmarkpanel nodes 1set nodes [hm_getmark nodes 1]if { ! [ Null nodes ] } { foreach node $nodes {       set xVal [hm_getentityvalue nodes $node "x" 0]    set yVal [hm_getentityvalue nodes $node "y" 0]    set zVal [hm_getentityvalue nodes $node "z" 0]    tk_messageBox -message "Node $node = $xVal $yVal $zVal" }}

• Several Data Names available for nodes:

Page 6: Innovation Intelligence ® 1 Chapter 5: Retrieving Data from HyperMesh Entities

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

6

Pointers and Flags

• Several of the data names in the two tables are defined as pointers.  

• A pointer is used to directly access another data name.  • For example, the collector and node data names for force loads are pointers.  • This means they “point” to data names available for either collectors or nodes.  • In order to retrieve any data from a pointer, the data name requested for the

particular pointer must also be supplied. • The additional data names are separated by a period or dot (.).

Page 7: Innovation Intelligence ® 1 Chapter 5: Retrieving Data from HyperMesh Entities

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

7

Pointers and Flags

• The following are a few examples on how a pointer is used. • To retrieve the node id that load 12 is applied to :

set node_id [hm_getentityvalue loads 12 "node.id" 0]

• To retrieve the y coordinate of the node that load 12 is applied to:•

set node_id [hm_getentityvalue loads 12 "node.y" 0]

• To retrieve the load collector name that contains load 12:

set ld_col [hm_getentityvalue loads 12 "collector.name" 1]

• For the collector name, notice the flag value is set to 1 as the expected return value is a string value as opposed to a numeric value.

• In the node example above, the flag value is set to 0, indicating that a floating point number is to be returned.

Page 8: Innovation Intelligence ® 1 Chapter 5: Retrieving Data from HyperMesh Entities

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

8

Pointers and Flags

• Another example is with component collectors.  • There is no data name associated with a component collector to get the material

name, only the material ID.

• The following set of commands is used to get the material ID:

set matID [hm_getentityvalue comps 12 "materialid" 0] 

• A second set of commands would then be required to get the name of the material with that ID:

set matName [hm_getentityvalue mats $matID "name" 1]

• Alternatively, the component collector has a material pointer data name.  

• From this pointer, any valid material data name can be substituted by separating the pointer and the new data name with a period (.).  

• From the example above the following line can replace the previous two lines:

set matName [hm_getentityvalue comps 12 "material.name" 1]

Page 9: Innovation Intelligence ® 1 Chapter 5: Retrieving Data from HyperMesh Entities

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

9

Process for Creating a HyperMesh Tcl Script to Retrieve Data on HyperMesh Entities

1. Define the task to be automated.

2. Write the commands to a user-created *.tcl text file• Skip doing the task in HyperMesh as there are likely no commands to capture to

the command.cmf file; the task is to retrieve information, not to perform a HyperMesh action.

• Use HyperMesh Tcl commands to extract data on HyperMesh entities.• Use core Tcl commands to store extracted data in variables, retrieve, manipulate,

and display it.

3. Test the script from the Command Window.

4. Define the Utility menu button for the macro in userpage.mac file.

5. In the current HyperMesh session, reload the hm.mac file (this also reloads userpage.mac).

6. Run the script from the Utility menu.

Page 10: Innovation Intelligence ® 1 Chapter 5: Retrieving Data from HyperMesh Entities

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

10

Example: Automate Computing the Vector Sum of Forces

1. Request the user to select forces.2. If the user does not select loads, display a message stating this.3. Retrieve the X, Y, and Z component information from the user-selected

forces.4. Sum the X, Y, and Z components.5. Display the resulting X, Y, and Z components.

• The following HyperMesh commands are modified in this exercise.*clearmark() *createmarkpanel()

• The following HyperMesh Tcl commands are used in this exercise.hm_getentityvalue hm_getmark

hm_usermessage hm_errormessage

• The following core Tcl commands are used in this exercise.brackets [ ] expr

foreach ifset returnllength

Page 11: Innovation Intelligence ® 1 Chapter 5: Retrieving Data from HyperMesh Entities

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

1111

Practical Exercises

Exercise 5aDescription:

Create a HyperMesh Tcl script to automate the following task: • Request the user to select a component to be translated.• Request the user to select a HyperMesh defined vector along which the

component is to be translated.• Get the Xcomp Ycomp and Zcomp of the selected vector from the HyperMesh

database.• Request the user to enter in a translation distance.• Use all of the above information to translate the given component.

HyperMesh commands used*createmarkpanel hm_getfloathm_getmark hm_getentityvalue*createvector *translatemark*clearmark

TCL/TK commands used

set

HintsUse the provided c_channel-tcl_vector.hm file as it has a vector defined in it.

Page 12: Innovation Intelligence ® 1 Chapter 5: Retrieving Data from HyperMesh Entities

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

1212

Practical Exercises

Exercise 5b

DescriptionCreate a HyperMesh Tcl script to automate the following task:

• Request the user to select elements on which to create system.• Calculate the centroidal coordinates of each element.• Create a node at each of these centroidal locations.• Create systems with these nodes as an orientation node.

HyperMesh commands used*createmarkpanel *createnode

*clearmark *hm_nodelisthm_getmark *systemcreatehm_entityinfo

TCL/TK commands usedset forforeach evallindex llength

HintsThe majority of this assignment will be discovering where to find information about commands and how to apply the information you find. Be patient and use the resources available to you, including the HyperWorks online help.

Page 13: Innovation Intelligence ® 1 Chapter 5: Retrieving Data from HyperMesh Entities

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

1313

Practical Exercises

Exercise 5c:DescriptionStarting with the results of Exercise 4b:

Create a node at the centroid of the element. Translate the node in the positive direction of the element normal by an amount equal to the shortest diagonal of a quad element and the shortest side of a tria element. Create either a tetra element or a pyramid element using the original element node list and the new node created by the script.

HyperMesh commands used*createmark *createvector *translatemark

*createnode *createelement *collectorcreate*currentcollector hm_getmark hm_nodelist

hm_entityinfo hm_getentityvalue

TCL/TK commands usedfor foreachset ifelseif else

Hints

This assignment will require you to think more, but the process is still the same. Pay careful attention to vector directions and look closely at the data you have generated. What are some ways to make this cleaner in the user environment? What are some problems that you might encounter?