1
Quick Workshop 10: Running Workbench in Batch
19.0 Release
Introduction to ANSYS DesignXplorer
2
• Goal
– To use python batch scripts to automate an optimization study
• Model Description
– The geometry is a 2D rectangle, fixed on one side and with an applied force on the opposite side
– The problem is solved in Mechanical APDL
Input parameters
- Force magnitude
- Width and Height
Output parameters
- Maximum deformation
Overview
3
1. File > Open > Plate_pull.wbpj
2. Optionally, inspect the geometry, mesh, and analysis cells. If not familiar with Mechanical APDL, the following summary will provide the details necessary to understand the problem
Width
Height
Fixed support
Force (FX_MAG)
Max X displacement (MAX_U_SUM)
Height, Width, and FX_MAG are set as input parameters MAX_U_SUM is set as an output parameter
Project Startup
4
• Now we will begin to create a script by recording a journal file in Workbench that opens a project, changes parameter values, updates the project, and saves the project. We will then modify the script so that it can be run in batch
1. Close Plate_pull.wbpj by clicking File > New
2. Click File > Scripting > Record Journal > save the journal file as ChangeParameters.wbjn. All of the actions will now be recorded
3. Open Plate_pull.wbpj
4. Double-click on the Parameter Set bar set FX_MAG to 100.5, width to 0.02, and height to 0.01
5. Return to Project and click Update Project
6. Save Project as Plate_pull_ParametersChanged.wbpj
7. Click File > Scripting > Stop Recording Journal > click OK
Workbench in Batch
5
Open the journal file (ChangeParameters.wbjn) in a text editorThe journal file will look as follows:
We will now modify the journal file so that it uses variables to define the name of the project to be opened, the name of the project to be saved, and the parameter values
Workbench in Batch
6
8. Change the journal file to the following:
Workbench in Batch
7
9. Close Workbench
10. Open a command prompt. This can be done by clicking Windows > All Programs > Accessories > Command Prompt and type the following (with paths appropriate for your computer settings):
"C:\Program Files\ANSYS Inc\v190\Framework\bin\Win64\runWB2.exe" -B -R C:\Users\mboulos\Desktop\ChangeParameters.wbjn
The above will launch the script in batch. Look for C:/Plate_pull_ParameterChangeInBatch.wbpj to ensure that the batch script was run correctly
Workbench in Batch
8
• Now we will begin to create another script that opens a project, adds new Design Points, updates the project, and saves the project. We will then modify the script so that it can be run in batch
1. Open Workbench
2. Click File > Scripting > Record Journal > save the journal file as AddDesignPoints.wbjn. All of the actions will now be recorded
3. Open Plate_pull.wbpj
4. Double-click on the Parameter Set bar. In the Table of Design Points, enter the following settings in the empty row at the bottom of the table
P7-FX_MAG = 50
P5-width=0.01
P6-height=0.02
5. Click Update All Design Points
6. Save Project as Plate_pull_NewDesignPoints.wbpj
7. Click File > Scripting > Stop Recording Journal > click OK
Workbench in Batch
9
The journal file will look as follows:
We will now modify the journal file so that it creates many design points using a while loop and solves each DP in sequence using “try” and “except” to avoid stopping if certain DP updates fail
Workbench in Batch
10
8. Change the journal file so that variables are used to define the project names:
Workbench in Batch
11
9. Add a variable defining the number of new design points and arrays containing the various values for each parameter:
Workbench in Batch
12
Notice that the design point creation is composed of three steps
1. A new design point is created
2. The internal parameter name is extracted
3. Parameter value is adjusted
Workbench in Batch
13
11. Change the journal file so that all three parameter names are extracted, and the parameter values are adjusted in a loop
Workbench in Batch
14
• Notice that the design points are updated with manual specification of each design point to update. Since we now have 4 design points we must adjust this. Putting all design points within this UpdateAllDesignPoints line will allow for the update of all design points
Workbench in Batch
15
12. Change the journal file as follows:
Workbench in Batch
16
13.Close Workbench
14. Open a command prompt. This can be done by clicking Windows > All Programs > Accessories > Command Prompt and type the following (with paths appropriate for your computer settings):
"C:\Program Files\ANSYS Inc\v190\Framework\bin\Win64\runWB2.exe" -B -R C:\Users\mboulos\Desktop\AddDesignPoints.wbjn
The above will launch the script in batch. Open C:\Plate_pull_NewDPs.wbpj to ensure that the batch script was run correctly
Workbench in Batch
17
Try to use the same procedure to add goal driven optimization to this project. The project should do the following:
1. Open the project
2. Add a Goal Driven Optimization system to the project schematic
3. Set DOE parameter ranges for each parameter
4. Update the DOE
5. Update the Response Surface
6. Define Optimization Goals
7. Update the Optimization Cell
8. Save the project
After creating the script, compare your script file with addGDO.wbjn
Additional Work