# ACU-T: 7001 Shape Optimization using HyperMorph

## Prerequisites

Prior to starting this tutorial, you should have already run through the introductory tutorial, ACU-T: 1000 HyperWorks UI Introduction, and have a basic understanding of HyperMesh, AcuSolve, and HyperView. To run this simulation, you will need access to a licensed version of HyperMesh and AcuSolve.

Before you begin, copy the file(s) used in this tutorial to your working directory.

Since the HyperMesh database (.hm file) contains meshed geometry, this tutorial does not include steps related to geometry import and mesh generation.

## Problem Description

Optimization, in simple terms, is the process of selecting a best input from a set of available alternatives. AcuSolve offers you two options to setting up an optimization study: design optimization and parametric studies. Design optimization enables you to optimize an objective function subject to certain constraints and satisfaction of flow equations. The design optimization may be considered as a sequence of cases, where each case first runs the optimizer and updates the design variables and then solves the flow equations for a number of time steps until convergence. Sample data is gathered at the end of each time step.

The optimizer solution consists of:

1. Constructing the response surface from the set of samples.
2. Running the optimizer on the response surface.
3. Updating the design variables.

The geometry for this problem consists of a simple pipe channel with perfectly circular cross-section as the base shape. Water enters the Inlet at the rate of 0.0003 kg/s and the outlet is a standard pressure outlet at zero relative pressure. Walls of the channel are no-slip walls.

## Open the HyperMesh Model Database

1. Start HyperMesh and load the AcuSolve user profile.
Refer to the HM introductory tutorial, ACU-T: 1000 HyperWorks UI Introduction, to learn how to select AcuSolve from User Profiles.
2. Click the Open Model icon located on the standard toolbar.
The Open Model dialog opens.
3. Browse to the directory where you saved the model file. Select the HyperMesh file ACU-T7001_ShapeOptimization.hm and click Open.
4. Click File > Save As.
The Save Model As dialog opens.
5. Create a new directory named ShapeOptimization and navigate into this directory.
This will be the working directory and all the files related to the simulation will be stored in this location.
6. Enter ShapeOptimization as the file name for the database, or choose any name of your preference.
7. Click Save to create the database.

## Set the Global Simulation Parameters

### Set the Analysis Parameters

1. Go to the Solver Browser, expand 01.Global, then click PROBLEM_DESCRIPTION.
2. Set Optimization to On.
3. Set the Mesh type to Fully Specified.

### Specify the Solver Settings

1. In the Solver Browser, click 02.SOLVER_SETTINGS under 01.Global.
2. In the Entity Editor , set the Min optimization cases to 10.
3. Set the Max optimization cases to 200.
4. Set the Optimization convergence tolerance to 1e-005.
5. Set Max time steps to 100.
6. Set the Convergence tolerance to 0.0001.
7. Set the Relaxation factor to 0.0.
8. Check that the Flow and Design Optimization flags are set to On.

### Set the Nodal Output Frequency

1. In the Solver Browser, expand 17.Output and then click NODAL_OUTPUT.
2. Turn On the Output initial condition field.
This will instruct the solver to write the initial state of the problem as the first output file.
3. Save the model.

## Create Mesh Motion and Set the Boundary Conditions and Material Model Parameters

### Create Mesh Motion

An optimization study can be performed in AcuSolve using either volume morph shapes or surface morph shapes. If volume morph shapes are used for simulation, you do not need to define mesh motion, as the volume nodes will move using the input from morph shapes. If surface morph shapes are used for simulation, interpolated mesh motion is needed to define the motion of volume nodes in the model. For this tutorial, surface morph shapes with interpolated mesh motion is used.

1. In the Solver Browser, right-click on 06.Mesh_Motion and click Create.
2. Name the mesh motion Volume_MMI.
3. Set the Type to Interpolated_Motion and the Number of Interpolated surfs to 3.
4. Click the data entry icon .
The Number of Interpolates surfs dialog opens.
5. Select Wall, Inflow, and Outflow.

### Specify the Boundary Conditions and Material Models Parameters

By default, all components are assigned to the wall boundary condition. In this step, you will change them to the appropriate boundary conditions and assign material properties to the fluid volumes.
1. In the Solver Browser, expand 12.Surfaces > WALL.
2. Click Inflow. In the Entity Editor,
1. Change the Type to INFLOW.
2. Set the Inflow type to Mass flux.
3. Set the Mass flux to 0.0003 kg/sec
4. Under the Interpolated Motion Surface section, turn on Display and Activate the interpolated motion surface.
3. Click Outflow. In the Entity Editor,
1. Change the Type to OUTFLOW.
2. Under the Interpolated Motion Surface section, turn on Display and Activate the interpolated motion surface.
4. Click Wall. In the Entity Editor,
1. Verify that the Type ia set to Wall.
2. Under the Interpolated Motion Surface section, turn on Display and Activate the interpolated motion surface.
5. Click Fluid. In the Entity Editor,
1. Change the Type to FLUID.
2. Select Water_HM as the Material.
3. Set the Mesh motion to Volume_MMI.
6. Save the model.

## Set Up Optimization Parameters

### Generate and Export Morph Shapes

HyperMorph is used to parameterize the shape of the design. You will create morph shapes by moving the surface nodes. The volume nodes will be taken care of using the interpolated mesh motion feature of HyperMesh.

1. In the panel area, click HyperMorph then select morph volumes.
2. In the morphing sub-panel, change mvols:active to mvols:skin only.

By changing this option to “skin only”, you only morph the surfaces and surface morph shapes are generated. If “mvols” is left to default, volume morph shapes are generated where all the nodes in the model are deformed (not just surfaces) during the morphing process.

Important: Do not click the solve button.
3. Click on return, then from the main HyperMorph menu panel, select morph volumes.
4. In the create sub-panel, click the elems collector and select all.
5. Click create.
A new morph volume is created.
6. Click return to exit to the main HyperMorph menu then select morph from the panel area.
7. Select the move handles sub-panel if it's not already selected. In the sub-panel, click the second arrow and select scale. Leave the x scale at 1.0 and set the y scale and z scale to 1.5.
8. Activate the handles collector by clicking on it.
9. In the modeling window, select the four edge handles at the pipe outflow, highlighted in grey in the figure below.
10. Click morph.
The grid is morphed.
11. Select the save shape sub-panel. In this panel,
1. Set the name field to outflow_expand.
2. In the second row, set the selector to as node perturbations.
3. Check that the coordinate system is set to global and click save.
4. Select No when asked to “Save perturbations for nodes at global and morph volume handles?”
Note: When you click save, a new entity folder, Shapes, will be created in the Model Browser. The shape outflow_expand will be created inside this folder in the Model Browser. You can turn off the display of the shape nodal perturbations by right-clicking on outflow_expand and selecting Hide. To show the shape again, right-click on outflow_expand and select Show. It is recommended to hide the shape display at this point before proceeding to next steps.
12. From the right side of the panel, select undo all.
13. Click move handles to return to the move handles sub-panel. In the sub-panel, reset the y scale to 1.0 and leave the z scale at 1.5.
14. Activate the handles collector then select all eight handles in the modeling window.
15. Click morph.
The grid is morphed.
16. Select the save shape sub-panel again. In the panel,
1. Set the name field to length_z.
2. In the second row, set the selector to as node perturbations.
3. Check that the coordinate system is set to global and click save.
4. Select No when asked to “Save perturbations for nodes at global and morph volume handles?”
18. Hide the shape display in the Model Browser
19. Click morph volumes to enter the morph volumes panel again then select the split/combine sub-panel.
20. In the second row, set the split type to No. of splits (# of splits) and enter 3 for the number of splits.
21. In the modeling window, select the edge of the morph volume marked by green crosses in the figure below.
22. Click split.
The morph volume is split at the locations of the crosses.
23. Click update edges to open the corresponding sub-panel. Click the first arrow and select update ends. Then, click the second arrow and select mvols. Finally, click the third arrow and select main-secondary.
Note: This option allows you to link any two edges together with a main-secondary relationship between two morph volumes. In this kind of relationship, the secondary edge is forced to follow the curvature of the main edge at the joining end of the two edges.
24. Activate the main morphvolmes collector and select the outer two morph volumes shown in the figure below. Then, activate the secondary morphvolumes collector and select the inner two morph volumes. After selecting the volumes in the order mentioned, click update.

The edges in the volume should resemble the figure shown below.

26. Select morph from the panel area then select the move handles sub-panel. In the sub-panel, click the second arrow and select scale if it's not already selected. Set the z scale to 1.0 and the y scale to 1.5.
27. Activate the handles collector by clicking on it then select the four middle handles in the modeling window.
28. Click morph.
The grid is morphed.
29. Select the save shape sub-panel. In the panel,
1. Set the name field to center_y.
2. In the second row, set the selector to as node perturbations.
3. Check that the coordinate system is set to global and click save.
4. Select No when asked to “Save perturbations for nodes at global and morph volume handles?”
30. Click undo all and hide the shape display in the Model Browser.
31. Exit the HyperMorph panel.

### Define the Design Variable

1. Right-click on 10.Optimization in the Solver Browser and select Optimization > DESIGN_VARIABLES from the context menu.
2. Rename the variable to outflow_expand and press Enter.
3. In the Entity Editor, set the Initial Value to 0.7.
4. Set the Lower Bound to 0.2.
5. Set the Upper Bound to 1.5.
6. Set the Max Update Factor to 0.02.
7. Follow the above steps to create two new design variables, length_z and center_y. Use identical parameters as above to define these two new design variables.

### Define the Response Variable

1. Right-click on 10.Optimization in the Solver Browser and select Optimization > RESPONSE_VARIABLES from the context menu.
2. Rename the variable to inflow_pressure and press Enter
3. In the Entity Editor, change the Response type to Surface Output.
4. Change the Response type to Surface Output.
5. Set the Surface elements component to Inflow.
6. Change the Output variable to Pressure.
This response variable will extract the surface integrated value of the pressure variable from the inflow surface.

### Define the Objective

1. Right-click on Optimization in the Solver Browser and select Optimization > OBJECTIVES from the context menu.
2. Rename the objective to maximize_inflow_pressure and press Enter
3. In the Entity Editor, set the Objective Type is set to Maximize.
4. Select inflow_pressure as the Response variable.

### Set Up the Nodal Shapes

1. Right-click on Optimization in the Solver Browser and select Optimization > NODAL_SHAPES from the context menu.
2. Rename the nodal shape to pipe_shapes and press Enter
3. Set the Number of shapes to 3.
4. Click inside the value field in the newly created Data: Shape row.
A Number of shapes dialog opens. You will notice that the number of available rows is equal to the number of points specific in the previous step.
5. In row 1, click the Shape field then click the Shape collector and select outflow_expand from the Select Shape dialog.
6. Click in the DV field in row 1 then click the Designvar collector and select the design variable outflow_expand from the Select Designvar dialog.
7. Similarly, select length_z as the shape and design variable for row 2 and center_y as the shape and design variable for row 3.
8. Click Close to exit the dialog.

### Set Up Optimization Controls

1. In the Entity Editor, expand 01.Global > 06.Optimization.
2. In the Entity Editor, select maximize_inflow_pressure as the Objective.
3. Verify that the Optimizer convergence tolerance is set to 1e-4.
4. Save the model.

## Compute the Solution

In this step, you will launch AcuSolve directly from HyperMesh and compute the solution.

### Run AcuSolve

1. Turn on the visibility of all mesh components.
For the analysis to run, the mesh for all active components must be visible.
2. Click on the ACU toolbar.
The Solver job Launcher dialog opens.
3. Optional: For a faster solution time, set the number of processors to a higher number (4 or 8) based on availability.
4. Leave the remaining options as default and click Launch to start the solution process.

### AcuGetDv and AcuGetRsp

AcuSolve provides two post-processing utilities specific to optimization problems, AcuGetDv and AcuGetRsp. AcuGetDv provides the values of the design variables for all the cases included in the solution. AcuGetRsp provides the values of the response variables for all the cases included in the solution.

1. Start AcuSolve Command Prompt from the Windows Start menu by clicking Start > Altair <version> > AcuSolve Cmd Prompt .
2. Change the directory to the present working directory using the cd command.
3. Enter the following command at the prompt:

acuGetDv

AcuSolve will print the values of design variables for each case.
4. To print the values of response variables, use the command:

acuGetRsp

Note: The order of columns in which the design variables and the response variables are printed by these commands is the order in which they appear in the INP file.

## Post-Process the Results with HyperView

Once the solution has converged, close the AcuProbe and AcuTail windows. Go to the HyperMesh window and close the AcuSolve Control tab.

### Open HyperView and Load the Model and Results

1. In the HyperMesh main menu area, click Applications > HyperView.
Once the HyperView window is loaded, the Load model and results panel should be open by default. If you do not see the panel, click File > Open > Model.
2. In the Load model and results panel, click next to Load model.
3. In the Load Model File dialog, navigate to your working directory and select the AcuSolve .Log file for the solution run that you want to post-process. In this example, the file to be selected is ShapeOptimization.1.Log.
4. Click Open.
5. Click Apply in the panel area to load the model and results.

### Create the Pressure Variation Animation

1. Click on the Results toolbar to open the Contour panel.
2. Select Pressure as the Result type.
3. Click the Components entity selector. In the Extended Entity Selection dialog, select Displayed.
4. Click Apply to display the pressure contour.
5. In the panel area, under the Display tab, turn off the Discrete color option.
6. Click the Legend tab then click Edit Legend.
7. In the Edit Legend dialog, change the Type to Dynamic scale, the Numeric format to Fixed, and the Numeric precision to 6. Click OK to close the dialog.
8. On the Animation toolbar, click the Animation Controls icon .
9. Drag the Max frame Rate slider to 10 fps.
10. Click the Start/Pause Animation icon to play the animation in the graphics area.

### Save the Animation

1. In the menu area, select Preferences > Export Settings > AVI.
2. In the Export Settings AVI dialog, set the Frame rate to 10 fps.
3. Set the JPEG quality to 99 and click OK.
4. On the ImageCapture toolbar, make sure that the Save Image to File option is On.
5. Click the Capture Graphics Area Video icon .
The Save Graphics Area Video As dialog opens.
6. Navigate to the location where you want to save the file, enter a name of your choice, and click Save.

## Summary

In this tutorial, you learned how to set up and solve a shape optimization problem with AcuSolve using HyperMorph. You started by importing the model database and then created mesh morphs. Then, you defined the design variables, the response variables, and set up the objectives of the problem using the response variables. Once the solution was computed using AcuSolve, you used the AcuSolve Command Prompt to get the design variables and response variables used for the optimization cases. Finally, you used HyperView to visualize how the shape of the pipe changed with the optimization steps.