# HS-1550: Shape Optimization Study Using HyperMesh and Abaqus

Learn how to perform a shape optimization using HyperMesh and HyperStudy. You will be using the finite element solver Abaqus, and HyperMorph to do the shape parameterization. This tutorial also demonstrates how to solve a problem when HyperMesh and HyperStudy are running in Windows and the solver is on a UNIX platform.

Before you begin, copy the model files used in this tutorial from <hst.zip>/HS-1550/ to your working directory.
In this tutorial, you will:
• Use HyperMorph to generate a shape variable.
• Run a study from inside HyperMesh.
• Perform a shape parameterization using HyperStudy.
• Set up a study.
• Write a script to run Abaqus on UNIX and register the script in the preference file.
• Run an optimization study.
The objective of this tutorial is to minimize the mass of a link that is connected to a shaft, given a stress constraint of 200MPa. The input variables are defined by the outer shape.

## Load the Model in HyperMesh

1. Start HyperMesh Desktop.
2. In the User Profiles dialog, set the user profile to Abaqus, Standard2D.
3. From the menu bar, click File > Open > Model.
4. In the Open Model dialog, open the link.hm file.
A finite element model appears in the graphics area.

## Perform Shape Parameterization in HyperMorph

1. From the Tool page, click HyperMorph.
2. Create domains.
1. Click domains.
The Domains subpanel opens, from which you can create domains for the shape parameterization.
2. Click the first arrow and select 2D domains.
3. Click the toggle and select all elements.
4. Click create.
Domains and handles are generated and will be used to manipulate the shape of the mesh and to generate shape perturbations required for the shape optimization.
3. Click return.
4. Create an input variable for the outer edge of the link.
1. From the HyperMorph panel, click morph.
The Morph subpanel opens, from which you can morph the shape of the mesh.
2. Click the second switch and select translate.
3. In the y val= field, enter -5.0.
4. In the graphics area, click the yellow handle located at the top-right corner of the link.
5. Click morph.
The first shape is generated.
5. Save the shape.
1. Go to the save shape subpanel.
2. In the name= field enter, sh1.
3. Click save.
6. Save the HyperMesh model by clicking File > Save > Model from the menu bar.
7. Close HyperMesh Desktop.

## Set Up Basic Solver Script

1. In a text editor, open HS-1550_solverScript.py.
The HS-1550_solverScript.py files enables you to run the solver on a local machine. This python script calls the Abaqus solver using arguments that you specify.
2. Change the path in the file to the Abaqus executable on your machine.
3. Modify any additional arguments, such as memory requests.
# import statements
import os
import platform
import subprocess
import sys

# user edits-------------------------------------------------------------------

# set executable path use forward slashes (/)
exe_path = '/my/path/to/executable/abaqus.exe'

# set abaqus arguments
command_arguments_list = ['job=' + sys.argv[1], 'memory=200Mb' , 'interactive']

# set log file name
logFile = 'logFile.txt'

# -----------------------------------------------------------------------------

# open log file
f = open('logFile.txt', 'w')

# get environment information
plat = platform.system()
hst_altair_home = ''
strEnvVal = os.getenv('HST_ALTAIR_HOME')
if strEnvVal:
hst_altair_home = strEnvVal
else:
f.write('%EXA_xx-e-env, Environment variable not defined ( HST_ALTAIR_HOME )')

exe_path = os.path.normpath(exe_path)
lstCommands = [exe_path] + command_arguments_list

f.write('platform: ' + plat + '\n')
f.write('hst_altair_home: ' + hst_altair_home + '\n')
f.write('command: ' + exe_path + '\n')

#Write the command in log file
f.write('Running the command:\n' + exe_path + ' ' + ' '.join(command_arguments_list) + '\n')

#Run the command
p1 = subprocess.Popen(lstCommands, stdout=subprocess.PIPE , stderr=subprocess.PIPE)

# log the standard out and error
f.write('\nStandard out' + '\n' + p1.communicate()[0] + '\n')
f.write('\nStandard error' + '\n' + p1.communicate()[1] + '\n')

# close log file
f.close()
4. Optional: Run HyperStudy on Windows with Study Directory in Unix and the Solver is Running on Unix
Restriction: Only for remote machines.
In order to run commands on a remote Unix machine, a local program must be installed to communicate the commands remotely. In this example, the program ssh is being used, but other equivalent or better programs exist. In most cases, the program’s protocols require authentication from a password. For this setup to work the environment needs to be configured to work without an active password entry. This setup may require help from your network administrators.
The ssh_remote.bat file is a sample (Windows) batch file to run a script on Unix (run_abaqus.sh) from a HyperStudy session running on Windows.
ssh user_name@unix_machine  "./run_abaqus.sh %1 %HST_APPROACH_VARNAM % %HST_STEP_INDEX% %HST_APPROACH_MODELS%"

The batch file uses the ssh command to log onto the Unix machine and execute the solver on the files created by HyperStudy. This script will be registered in HyperStudy as the solver script.

1. Open the ssh_remote.bat file
2. Change the generic parameter “unix_machine” to match the name of the remote Unix machine on your network.
3. Change the generic parameter “user_name” to match your logon on the remote machine.
Note: This logon should have been configured to work without a password between these two machines.
4. Open the run_abaqus.sh file.
The run_abaqus.sh file is a shell script which is designed to run the Abaqus solver on a UNIX machine. This file should be placed in your HOME directory on the Unix machine.
#!/bin/sh

#constuct the model directory
approachName=$1 runNum=printf %05i$2
modelString=$3 array=(${modelString//:/ })
modelName=${array[0]} myDir=~/${approachName}/run__${runNum}/${modelName}

#change the directory to model directory
cd $myDir #change the format from windows to unix dos2unix$1 $1 #edit this line to match your solver path and the appropriate arguments /my/path/to/solver/example/abaq631 job=$1 memory=200Mb interactive
5. Change the text formatting to be Unix compatible using the command dos2unix on the file: dos2unix run_abaqus.sh.
6. Make sure the file has executable permission, and enter chmod 755 run_abaqus.sh.
7. Edit the run_abaqus.sh file and modify the path to the executable and any other options to this command as needed.

## Register Abaqus as a Solver

1. Start HyperStudy.
2. From the menu bar, click Edit > Register Solver Script.
The Register Solver Script dialog opens.
2. In the Label and Varname fields, enter Abaqus.
3. From the list of solver script types, select Generic.
4. Click OK.
4. In the Path column of the script Abaqus, click .
5. In the Open dialog, open the python.exe file.
Tip: You can also copy and paste the same path and file from the Python Path field.
6. In the User Arguments column of the Abaqus script, click .
7. In the Open dialog, navigate to your working directory and open the HS-1550_solverScript.py file.
8. Optional: ONLY for REMOTE Machines: Register Abaqus as a solver.
9. Click OK.

## Perform the Study Setup

1. Start a new study in the following ways:
• From the menu bar, click File > New.
• On the ribbon, click .
2. In the Add Study dialog, enter a study name, select a location for the study, and click OK.
Note: The study directory MUST be your home on the mapped UNIX machine.
3. Go to the Define Models step.
1. From the Directory, drag-and-drop the HyperMesh (.hm) file link.hm into the work area.
2. In the Solver Input File column, enter link.inp.
This is the name of the solver input file HyperStudy writes during any evaluation.
3. In the Solver execution script column, select Abaqus.
4. In the Solver Input Arguments column enter, \$filebasename.

Optional. In addition, you may need to edit the Abaqus environment file (ex: <ABAQUS INSTALL>\v6.11\6.11-1\site\abaqus v6.env) to include:

ask_delete=OFF

or

comment the line ask delete=on if any.

This is needed because Abaqus prompts you to overwrite the old files when re-running the analysis. In order to eliminate the need for user interaction, you need to command Abaqus not to ask this question and overwrite.

5. Import variables.
1. Click Import Variables.
The Model Parameters dialog opens.
2. Expand Shape, and click sh1.S.
3. Change the Lower bound to 0.0 and the Upper bound to 1.0.
5. Click OK.
6. Go to the Define Input Variables step.
7. Review the design variable's lower bound, initial and upper bound range.

## Perform Nominal Run

1. Go to the Test Models step.
2. Click Run Definition.
An approaches/setup_1-def/ directory is created inside the study Directory. The approaches/setup_1-def/run__00001/m_1 directory contains the input file, which is the result of the nominal run.

## Create and Evaluate Output Responses

In this step you will create two output responses: Mass and Max_Stress.

1. Go to the Define Output Responses step.
2. Create the Mass output response.
1. From the Directory, drag-and-drop the link.dat file, located in the approaches/setup_1-def/run__00001/m_1 directory, into the work area.
2. In the File Assistant dialog, set the Reading technology to Altair® HyperWorks® and click Next.
3. Select Single item in a time series, then click Next.
4. Define the following options, and then click Next.
• Set Type to ABAQUS.dat.
• Set Request to TOTAL MASS.
• Set Component to MASS.
5. Label the output response Mass.
6. Set Expression to First Element.
7. Click Finish.
The Mass output response is added to the work area.
3. Create the Max_Stress output response.
1. From the Directory, drag-and-drop the link.obd file, located in the approaches/setup_1-def/run__00001/m_1 directory, into the work area.
2. In the File Assistant dialog, set the Reading technology to Altair® HyperWorks® and click Next.
3. Select Multiple items at multiple time steps (readsim), then click Next.
4. Define the following options, and then click Next.
• Set Subcase to Step-2.
• Set Type to S-Global-Stress components (PART-1-1).
• Set Request to E1 - E378.
• Set Component to vonMises.
5. Label the output response Max_Stress.
6. Set Expression to Maximum.
7. Click Finish.
The Max_Stress output response is added to the work area.
4. Click Evaluate to extract the response values.

## Run Optimization

1. In the Explorer, right-click and select Add from the context menu.
2. In the Add dialog, select Optimization and click OK.
2. Go to the Optimization > Definition > Define Output Responses step.
3. Click the Objectives/Constraints - Goals tab.
2. In the Apply On column, select Mass (r_1).
3. In the Type column, select Minimize.
2. In the Apply On column, select Max_Stress ( r_2).
3. In the Type column, select Constraint.
4. In column 1, select <= (less than or equal to).
5. In column 2, enter 200.0.
6. Go to the Optimization > Specifications step.
7. In the work area, set the Mode to Adaptive Response Surface Method (ARSM).
Note: Only the methods that are valid for the problem formulation are enabled.
8. Click Apply.
9. Go to the Optimization > Evaluate step.