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#

At the beginning of the script the combination of data types and associated four components the user wants to analyze are specified in a dictionary. The code than loops over all data types and creates one page per data type with a four window layout for each component. A spherical section cut will be positioned at the maximum scalar result.

The code runs through the following steps: The pages are created with the Page class, the title is set according to the data type. In each window the model will be loaded via the Window class using the addModelAndResult() method.

The scalar results are loaded using the ResultDefinitionScalar class. The maximum values are found using a collection via the Collection class and the addByFilter() method. If the entity binding is of type element the center of the section cut is the centroid of the element, queried with centroid attribute of the element object.

The section cuts are added add the base coordinates using the SectionCutSpherical class with a given radius, feature lines and transparency turned on.

 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#

Following the standard steps (setting up the window, loading the model/result files, setting the required simulation step), the model view is set using evalHWC() with the HWC view command.

Three systems are created using the hv.System(type='rectangular'), the hv.System(type='cylindrical') and the hv.System(type='spherical') class constructors.

The rectangular system is positioned by three Node objects setting origin, axis and axisplane. The cylindrical system is defined using coordinate lists/tuples instead of node objects. The spherical system uses the setOrientationByCircleCenter() method with 3 node objects.

 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#

Following the standard steps (setting up the window, loading the model file), the script starts an interactive part selection using the InteractiveSelection class. The collection returned by this class is used to create a part set using the Set class. The color of all parts in this set is changed to blue and the draw style to wireframe.

 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

Example 04 - ApplyStyle Default Settings#

The script uses the ApplyStyle class with the default settings to apply the attributes of the currently active model to all the models in the other animation windows of the active page.

1import hw.hv as hv
2
3applyStyle = hv.ApplyStyle()
4applyStyle.setAllAttributes('default')
5applyStyle.apply()
../../_images/image_HV_apply_style_default_settings.png

Figure 4. ApplyStyle with default settings from active window to all animation windows on active page

Example 05 - ApplyStyle Source and Target#

This variant of ApplyStyle uses the ApplyStyle class with all attributes set to True. The source model is a model in a non-active window, the target list consists of two Window objects in different pages and a Page object. Using the page object will change the style of all models in this page, independent from the page layout.

 1import hw
 2import hw.hv as hv
 3session=hw.Session()
 4
 5source = session.get(hw.Window,page=1, window=4)
 6
 7targetList = [session.get(hw.Window,page=1,window=3),
 8              session.get(hw.Window,page=2,window=4),
 9              session.get(hw.Page,  page=3)]
10
11applyStyle = hv.ApplyStyle()
12applyStyle.setAllAttributes(True)
13applyStyle.source = source
14applyStyle.setTarget(targetList)
15applyStyle.apply()
../../_images/image_HV_apply_style_non_active_source_target_list.PNG

Figure 5. ApplyStyle from non-active source window to window and page target list