Annotations#

Some examples require external input files. Before you start, please follow the link in the Example Scripts section to download the zip file with model and result files.

Example 01 - Notes attached to Entities#

Following the standard steps (setting up the window, loading the model/result files, and contouring the results), the code defines the noteDict dictionary that contains the information used to create the notes. Specifically, it defines a list of element IDs, a list of font sizes, and a list of colors.

Next, the code loops over the lists in the noteDict dictionary and creates four notes, each attached to a different element, using a different font size and color. Finally, the latest note object is used to extract the field dictionary using getFieldDictionary() method and print out the content.

 1import hw
 2import hw.hv as hv
 3import os
 4
 5scriptDir = os.path.abspath(os.path.dirname(__file__))
 6modelFile = os.path.join(scriptDir, "aerobox", "aerobox.fem")
 7resultFile = os.path.join(scriptDir, "aerobox", "aerobox-LC1-2.op2")
 8
 9ses = hw.Session()
10ses.new()
11win = ses.get(hw.Window)
12win.type = "animation"
13
14win.addModelAndResult(modelFile, result=resultFile)
15res = ses.get(hv.Result)
16resScalar = hv.ResultDefinitionScalar(
17    dataType="Composite Stress",
18    dataComponent="vonMises",
19    layer="Max"
20)
21res.plot(resScalar)
22animTool = hw.AnimationTool()
23animTool.currentFrame = 1
24hw.evalHWC("view orientation iso")
25
26noteDict = {
27    "elements": [493, 353, 674, 733],
28    "fontSizes": [16, 12, 12, 12],
29    "colors": ["#FF0000", "#FFFFFF", "#FFFFFF", "#FFFFFF"],
30}
31
32for elem, fsize, col in zip(
33    noteDict.get("elements"), noteDict.get("fontSizes"), noteDict.get("colors")
34):
35    n = hv.Note(
36        label="Element " + str(elem),
37        attachmentType="element",
38        attachment=[1, "element", elem],
39        text="Element: {entity.id}\nValue = {entity.contour_val}",
40        textColorMode="user",
41        textColor=col,
42        borderColorMode="user",
43        borderColor=(20, 20, 20),
44        fillColor=(31, 73, 125),
45        fontSize=fsize,
46        transparency=False,
47        moveToEntity=True,
48        screenAnchor=False,
49    )
50
51fieldDic = n.getFieldDictionary()
52for key in list(fieldDic.keys()):
53    print("{:35s} {:3s} {:50s}".format(key, " = ", fieldDic[key]))
../../_images/image_HV_notes.png

Figure 1. Notes attached to entities with getFieldDictionary() output

Example 02 - Measure Position#

After the standard steps (setting up the window, loading the model/result files, and contouring the results), the code sets the model orientation using the HWC view command and creates objects n1, n2, and n3 for nodes ID 207, 11, and 44 respectively. These three nodes are used to create a new rectangular system (sysRect) that will be assigned to the MeasurePosition entity.

Next, a list of node objects (nodeObjectList) is created for nodes ID 1075, 999, 1568, and 1266. At this point, all the required variables are defined and a new MeasurePosition is created. The node objects are assigned to it via the addEntities() method and the system attribute is set to sysRect.

 1import hw
 2import hw.hv as hv
 3import os
 4
 5ALTAIR_HOME = os.path.abspath(os.environ['ALTAIR_HOME'])
 6modelFile   = os.path.join(ALTAIR_HOME,'demos','mv_hv_hg','animation','dyna','bumper','bumper_deck.key')
 7resultFile  = os.path.join(ALTAIR_HOME,'demos','mv_hv_hg','animation','dyna','bumper','d3plot')
 8
 9ses = hw.Session()
10ses.new()
11win=ses.get(hw.Window)
12win.type = 'animation'
13
14win.addModelAndResult(modelFile, result=resultFile)
15res = ses.get(hv.Result)
16resScalar = hv.ResultDefinitionScalar(dataType='Displacement',
17                dataComponent='Mag')
18res.plot(resScalar)
19animTool = hw.AnimationTool()
20animTool.currentFrame=26
21
22hw.evalHWC('view projection orthographic | \
23         view matrix  0.174593   0.948911    0.262841 \
24                 0.000000  -0.964156    0.218925 \
25                -0.149918   0.000000   -0.199801 \
26                -0.227245   0.953121    0.000000 \
27                 351.268646 512.829834 -658.386963 1.000000 | \
28         view clippingregion -251.830444  96.738075  555.359558 \
29                837.470154 -722.333801 601.748169')
30
31model  = ses.get(hv.Model)
32n1 = model.get(hv.Node,207)
33n2 = model.get(hv.Node,11)
34n3 = model.get(hv.Node,44)
35
36sysRect = hv.System(type='rectangular',fixed=False)
37sysRect.label = 'Rectangular System'
38sysRect.labelVisibility = True
39sysRect.setOrientationByNode(
40            origin     = n1,
41            axis       = n2,
42            plane      = n3,
43            axisplane  = 'X-XY'
44)
45
46nodeIdList = [1075,999,1568,1266]
47nodeObjectList = [ model.get(hv.Node,id) for id in nodeIdList ]
48
49measurePosition = hv.MeasurePosition()
50
51measurePosition.addEntities(nodeObjectList)
52measurePosition.label               = 'Position'
53measurePosition.displayLabel        = True
54measurePosition.displayId           = True
55measurePosition.color               = (0,0,0)
56measurePosition.fontSize            = 12
57measurePosition.numericFormat       = 'scientific'
58measurePosition.numericPrecision    = 3
59measurePosition.transparency        = False
60measurePosition.autohide            = True
61measurePosition.prefix              = True
62measurePosition.system              = sysRect
63
64win.draw()
65print(measurePosition.getMeasureProperties())
../../_images/image_HV_measure_position.PNG

Figure 2. Position measures using node id list and print measure properties

Example 03 - Measure Minimum Distance#

After the standard steps (setting up the window, loading the model/result files, and contouring the results), the code sets the model orientation using the HWC view command and creates objects n1, n2, and n3 for nodes ID 207, 11, and 44 respectively. These three nodes are used to create a new rectangular system (sysRect) that will be assigned to the MeasurePosition entity.

Next, three collections are created. col1 is a node collection populated with nodes from component ID 3 using the addByID() method. col2 is a component collection populated with component named “Mounting Bracket” using the addByComponentName() method. col3 is a component collection populated with components that include the nodes from col1, i.e. it includes component ID 3.

Subsequently, a new collection colHide is created by combining col2 and col3 using simple arithmetics on the collection objects. All other components in the model are then hidden and a new MeasureDistanceMinimum object is created to measure the minimum distance between entities in col1 and col2. The collections are assigned to to the measure object via the addEntities() method and the system attribute is set to sysRect.

Note

In HyperView, the component entity is represented by the Part class.

 1import hw
 2import hw.hv as hv
 3import os
 4
 5ALTAIR_HOME = os.path.abspath(os.environ['ALTAIR_HOME'])
 6modelFile   = os.path.join(ALTAIR_HOME,'demos','mv_hv_hg','animation','dyna','bumper','bumper_deck.key')
 7resultFile  = os.path.join(ALTAIR_HOME,'demos','mv_hv_hg','animation','dyna','bumper','d3plot')
 8
 9ses = hw.Session()
10ses.new()
11win=ses.get(hw.Window)
12win.type = 'animation'
13
14win.addModelAndResult(modelFile, result=resultFile)
15res = ses.get(hv.Result)
16resScalar = hv.ResultDefinitionScalar(dataType='Displacement',
17                dataComponent='Mag')
18res.plot(resScalar)
19animTool = hw.AnimationTool()
20animTool.currentFrame=26
21
22
23hw.evalHWC('view projection orthographic | \
24         view matrix  0.429744 0.751905 0.499958 \
25                 0.000000 -0.469094 0.659022 \
26                -0.587913 0.000000 -0.771538 \
27                 0.018125 0.635925 0.000000 \
28                 460.527435 157.489700 -354.629974 1.000000 | \
29          view clippingregion -251.830444 96.738075 555.359558 \
30                837.470154 -722.333801 601.748169')
31
32model  = ses.get(hv.Model)
33n1 = model.get(hv.Node,207)
34n2 = model.get(hv.Node,11)
35n3 = model.get(hv.Node,44)
36
37sysRect = hv.System(type='rectangular',fixed=False)
38sysRect.label = 'Rectangular System'
39sysRect.labelVisibility = True
40sysRect.setOrientationByNode(
41            origin = n1,
42            axis       = n2,
43            plane      = n3,
44            axisplane  = 'X-XY'
45)
46
47col1 = hv.Collection(hv.Node,populate=False)
48col1.addByID(hv.Part,3)
49
50col2 = hv.Collection(hv.Part,populate=False)
51col2.addByComponentName(['Mounting Bracket'])
52
53col3 = hv.Collection(hv.Part,populate=False)
54col3.addByID(hv.Node,col1.getIds())
55
56colHide = col2 + col3
57[p.setAttributes(meshMode='shadedMeshLines') for p in  colHide.getEntities()]
58colHide.reverse()
59model.hide(colHide)
60
61measureDistanceMinimum = hv.MeasureDistanceMinimum()
62measureDistanceMinimum.addEntities(col1,col2)
63
64measureDistanceMinimum.label               = 'Minimum Distance'
65measureDistanceMinimum.displayLabel        = True
66measureDistanceMinimum.displayId           = True
67measureDistanceMinimum.color               = '#000000'
68measureDistanceMinimum.fontSize            = 12
69measureDistanceMinimum.numericFormat       = 'fixed'
70measureDistanceMinimum.numericPrecision    = 3
71measureDistanceMinimum.transparency        = False
72measureDistanceMinimum.autohide            = False
73measureDistanceMinimum.prefix              = True
74measureDistanceMinimum.system              = sysRect
75
76win.draw()
77print(measureDistanceMinimum.getMeasureProperties())
../../_images/image_HV_measure_distance_minimum.PNG

Figure 3. Minimum distance measure between between node and part collections