Model & Display Setup#

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 - Planar and Spherical Section Cuts#

Position sections at entities filtered by Collections#
 1import hw
 2import hw.hv as hv
 3import os
 4
 5ses = hw.Session()
 6ses.new()
 7
 8scriptDir = os.path.abspath(os.path.dirname(__file__))
 9modelFile = os.path.join(scriptDir, "aerobox", "aerobox.fem")
10resultFile = os.path.join(scriptDir, "aerobox", "aerobox-LC1-2.op2")
11
12# Dictionary with dataType dependent result scalar settings
13resDict = {
14    "Displacement": ["Mag", "X", "Y", "Z"],
15    "Stress": ["vonMises", "MaxShear", "In-plane P1 (major)", "In-plane P2 (minor)"],
16}
17
18# Change window type
19ses.get(hw.Window).type = "animation"
20
21# Loop over data types, 1 page per data type
22for dType in list(resDict.keys()):
23    ap = hw.Page(title=dType, layout=9)
24    ses.setActive(hw.Page, page=ap)
25
26    # Loop over data components, one window per component
27    for i, w in enumerate(ses.getWindows()):
28        dComp = resDict.get(dType)[i]
29        ses.setActive(hw.Window, window=w)
30
31        # Load Model
32        w.addModelAndResult(modelFile, result=resultFile)
33
34        # Set scalar results
35        res = ses.get(hv.Result)
36        resScalar = ses.get(hv.ResultDefinitionScalar)
37        resScalar.setAttributes(dataType=dType, dataComponent=dComp)
38
39        # Plot results
40        res.plot(resScalar)
41
42        # Set frame with AnimationTool()
43        animTool = hw.AnimationTool()
44        # animTool.currentFrame=1
45
46        # Modify view with evalHWC
47        hw.evalHWC("view orientation iso")
48
49        # Add SectionCut at Max Entity
50        entityFilter = hv.FilterByScalar(operator="topN", value=1)
51        if dType == "Displacement":
52            # Set animation frame 1
53            animTool = hw.AnimationTool()
54            animTool.currentFrame = 1
55            # Create Collection via TopN filter
56            maxNodeCol = hv.Collection(hv.Node, populate=False)
57            maxNodeCol.addByFilter(entityFilter)
58            # Get centroid of element with maximum scalar value
59            maxNode = maxNodeCol.getEntities()[0]
60            # Add SectionCut Planar
61            secPlanar = hv.SectionCutPlanar(
62                label="Node " + str(maxNode.id),
63                gridSpaceX=100,
64                gridSpaceY=100,
65                gridText=True,
66            )
67            secPlanar.setOrientationByAxis("y")
68            secPlanar.setBaseNode(maxNode.id)
69            hw.evalHWC("view fit")
70            secPlanar.setAttributes(featureLines=True, transparency=True)
71        elif dType == "Stress":
72            # Create Collection via TopN filter
73            maxElemCol = hv.Collection(hv.Element, populate=False)
74            maxElemCol.addByFilter(entityFilter)
75            # Get centroid of element with maximum scalar value
76            maxElem = maxElemCol.getEntities()[0]
77            baseCoords = maxElem.centroid
78            # Add Section Cut Spherical
79            secRadius = 600
80            secSphere = hv.SectionCutSpherical(
81                label="Element " + str(maxElem.id), radius=secRadius
82            )
83            secSphere.center = baseCoords
84            hw.evalHWC("view fit")
85            secSphere.setAttributes(featureLines=True, transparency=True)
../../_images/image_HV_sections.PNG

Figure 1. Planar and spherical sections positioned using Collections and TopN filter

Example 02 - Systems#

Rectangular, circular and spherical systems based on nodes and coordinates#
 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)
15
16animTool = hw.AnimationTool()
17animTool.currentFrame = 26
18pCol = hv.Collection(hv.Part)
19[p.setAttributes(meshMode='transparent',color=(216, 216, 216)) for p in  pCol.getEntities()]
20
21hw.evalHWC('view projection orthographic | \
22        view matrix 0.174593 0.948911 0.262841 \
23                 0.000000 -0.964156 0.218925 \
24                -0.149918 0.000000 -0.199801 \
25                -0.227245 0.953121 0.000000 \
26                150.394730 587.232971 -658.386963 1.000000 | \
27        view clippingregion -129.361221 -25.731152 654.478882 \
28                738.350830 -722.333801 601.748169')
29
30model = ses.get(hv.Model)
31n1 = model.get(hv.Node,1898)
32n2 = model.get(hv.Node,1890)
33n3 = model.get(hv.Node,1895)
34
35sysRect = hv.System(type='rectangular',fixed=False)
36sysRect.label = 'Rectangular System'
37sysRect.color = '#ff0000'
38sysRect.labelVisibility = True
39sysRect.setOrientationByNode(origin     = n1,
40             axis       = n2,
41             plane      = n3,
42             axisplane  = 'X-XY')
43
44sysCyl  = hv.System(type='cylindrical')
45sysCyl.label = 'Cylindrical System'
46sysCyl.color = '#006400'
47sysCyl.labelVisibility = True
48sysCyl.setOrientationByCoords(origin    = [226.614,159.179,622.441],
49                xaxis   = [226.739,169.193,622.378],
50                xyplane = [207.319,159.158,623.268])
51
52model = ses.get(hv.Model)
53n4 = model.get(hv.Node,1547)
54n5 = model.get(hv.Node,1534)
55n6 = model.get(hv.Node,1537)
56
57sysSpher = hv.System(type='spherical')
58sysSpher.label = 'Spherical System'
59sysSpher.color = '#0000ff'
60sysSpher.labelVisibility = True
61sysSpher.setOrientationByCircleCenter(node1=n4,node2=n5,node3=n6)
62
63win.draw()
../../_images/image_HV_systems.PNG

Figure 2. Rectangular, circular and spherical systems based

Example 03 - Part Set from Interactive Selection#

Create a Part Set from an interactive selection and modify Part properties#
 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','h3d','NEON_FRONT.h3d')
 7
 8ses = hw.Session()
 9ses.new()
10win=ses.get(hw.Window)
11# Set Window to Animation
12win.type = 'animation'
13# Add Model
14win.addModelAndResult(modelFile)
15
16inSel = hv.InteractiveSelection()
17pCol=inSel.select()
18print('Selection type    = {}'.format(inSel.type))
19print('Collection size   = {}'.format(pCol.getSize()))
20print('{} selected'.format(inSel.type))
21print('')
22for p in pCol.getEntities():
23    p.color=(0,0,255)
24    print('    Part id = {} name = {}'.format(p.id,p.name))
25
26entSet = hv.Set(hv.Part,populate = False)
27entSet.addByCollection(pCol)
28entSet.setAttributes(label = "My Part Set",
29         drawSize  = 6,
30         drawStyle = 'wire',
31         color=(255,0,0))
32print('')
33print('Set size of "{}" = {}'.format(entSet.label,entSet.getSize()))
34
35pColRest=hv.Collection(hv.Part)-pCol
36for p in pColRest.getEntities():
37    p.setAttributes(meshMode='transparent',color=(240,240,240))
38win.draw()
../../_images/image_HV_Part_Set_from_interactive_selection.PNG

Figure 3. Modify Part Set from Interactive Selection