MV3022: Optimize a 4Bar Model
In this tutorial you will setup an optimization problem using MotionView's Optimization Wizard for a 4bar model.
 Defining point coordinates as design variables
 Defining a response type 'Root Mean Square Deviation' for matching curves
 Using the responses as objectives
 Running the optimization and postprocessing the results
 [Optional] Infeasible Designs in MotionSolve optimization
 Introduction
 In this tutorial, the locations of the joints of a 4bar mechanism are
optimized to obtain a desired motion of the coupler. MotionSolve's DSA (Design Sensitivity Analysis)
capability is used to calculate sensitivities.The entire model is parameterized in terms of these four design
points: A, B, C and D. Since the model operates in 2D space (XY plane),
this leads to 8 Design Variables. The initial design is listed as in Table 1:
Table 1. Point X Y A 45 45 B 65 260 C 300 500 D 515 85
Review the Model
In this step, you will review the 4bar model in MotionView.
 Open the file mv_3022_initial_4bar_opt.mdl in MotionView.

Review the entities in the model.
Add Design Variables
 In the Project Browser, rightclick on Model and select Optimization Wizard from the context menu.

In the Design Variables page, click on the
Points tab.
The points are listed in Figure 3:
 For points A, B, C, and D, make the x and y coordinates design variables. Click the (Filter datamembers) icon.

In the Filter dialog, click to turn off the
Z check box.
 Click OK.
 In the Model Tree, select Point A, Point B, Point C, and Point D. Then click Add.

Modify the upper and lower bounds of the design variables according to Table 2:
You have finished the process of setting design variables.
Table 2. DV Lower Bound Upper Bound Point A(DV)  X 50 50 Point A(DV)  Y 50 50 Point B(DV)  X 20 80 Point B(DV)  Y 180 280 Point C(DV)  X 240 380 Point C(DV)  Y 400 620 Point D(DV)  X 180 520 Point D(DV)  Y 100 20
Add Response Variables
Now you will add response variables to the optimization.
 Trajectory of Coupler CM – DX
 Trajectory of Coupler CM – DY
 Click on the Responses page.
 Click on the button.

Change the Label to
'rms2_dx'
.  Click OK to create a response variable.
 Once the response variable is created, under Response Type, choose Root Mean Square Deviation.
 Doubleclick the Curve collector and choose Desired Coupler Path DX for the Desired Curve user input. This is the target curve for CoupleDX.

For Response Expression, type the expression
`DX({b_bc.cm.id})`
(DX of CM coupler body). 
Follow the steps again to create one more Root Mean Square
Deviation response. Use Table 3 to fill in the
details.
The completed Responses page should appear as shown in Figure 5:
Table 3. RV Desired Curve Response Expression rms2_dx Desired Coupler Path DX `DX({b_bc.cm.id})`
rms2_dy Desired Coupler Path DY `DY({b_bc.cm.id})`
Add Objectives and Constraints
In this step you will add two objectives to the problem.
 Navigate to the Goals page.

Under Objectives, click .
This will add an objective with the response rv_rms2_dx.

For Weight choose
1.0
retain the Type as min (you want to minimize the response).  Repeat these steps to add another objective. Choose rv_rms2_dy for the second objective.

For Weight choose
1.0
retain the Type as min.There are no constraints in this problem, so you have now finished model setup. The model is ready to solve.
Run the Optimization
Now you will run the optimization.
 Navigate to the Solutions page.
 Activate the Plot Optimization Summary check box.

Click on Save & Optimize to start the
optimization.
Once the optimization process is complete, the text window displays the optimized design variables values, final value of the responses and optimized cost function. The expected values of design variables are provided in Table 4:
Table 4. DV Expected From Optimizer p_0.x 0 0.0660 p_0.y 0 0.2796 p_1.x 40 39.97 p_1.y 200 199.71 p_2.x 360 360.07 p_2.y 600 600.26 p_3.x 400 400.44 p_3.y 0 0.0406
PostProcess
In this step you will postprocess the results of the optimization run.

Once the solution is finished, navigate to the Review
Results page.
The Summary tab lists the history of design variables, responses and objective functions in a tabular format. In this tutorial, the optimized design variables are from iteration 27.

Click the Plot tab. Plot Overall
Objective versus Iteration
variable.
The Plot tab helps to visualize variation of design variables, response variables and cost function using graphs. You can choose to plot any number of variables along the yaxis with respect to a variable along the xaxis.Note: You can also see how a particular design variable varied across an iteration. For example, select p_b.x (Point BX) in the Y list and click Apply.

Animate the configuration generated during any iteration.
 In the Animation tab, from the Iteration dropdown menu choose the iteration number you want to animate (for this tutorial, choose Iteration 27.
 Click Load Result to load the animation corresponding to the iteration you chose.
From this tab, you also have the option to export an archive of the model from any configuration.  Load the results from Iteration 27.
 Use the Archive Model location browser to choose a file path.
 Click Export.

Observe how the path of the coupler for the optimized result compares with the
desired target path.
Identify Infeasible Designs/Possible Recovery (Optional)
In this step, you will use a powerful feature in MotionSolve to obtain the optimal design by recovering from a failed iteration.
It is not uncommon for a mechanical system to be limited by some sort of physical constraints. In this four bar example, the Grashof constraints have to be satisfied in order to make the input link a crank. When optimizer chooses a new design, those constraints are likely to be violated regardless of whether they are added as optimization constraints or not. The optimizer in MotionSolve has a recovery mode to help recover from such infeasible design and let optimization proceed. To demonstrate how the optimizer recovers in this tutorial, you will change the initial design and see how it works.

Return to the Design Variables page and change the
nominal value, upper and lower bounds as shown in Figure 15:
The four bar mechanism should look like the example in Figure 16:
 Retain the Responses, Objectives and Constraints you defined earlier in the tutorial.

Run an optimization with a different Output file in the Solutions page as
4bar_opt_for_recover.py.
The number of iterations will change due to a different initial design.Important: Pay attention to the last column ‘Reduced Step’ in the solver output:In this example, the optimizer has found infeasible design in iteration 27; it is then told to reduce the step size until a feasible design is found.

Check the output files. In most cases, the output files could tell you why
solver fails at a specific point and how you can avoid it if possible.
When the optimizer recovers from an infeasible design, an additional folder ‘Infeasible Points’ is created; each subfolder contains the following information:
 dvValues.txt: Value of design variables
 4bar_opt_for_recover.abf: MotionSolve output file
 4bar_opt_for_recover.h3d: Animation file (provided only when available)
 4bar_opt_for_recover.log: MotionSolve log file
 4bar_opt_for_recover.mrf: MotionSolve output file
 4bar_opt_for_recover.xml: MotionSolve xml input file

Load 4bar_opt_for_recover.h3d in folder
Infeasible Point 1  iter2.
You can see that the system enters a lockup position before the solver crashes:

Check the result.
The result you see in the example is very close to what you get in STEP 5 and the cost function is reduced significantly. This shows you can get the optimal design even with infeasible design encountered in the intermediate step. However, the optimality is not guaranteed in some cases. When that happens, you can improve the result by adding proper constraints based on your investigation in previous steps. For four bar mechanism, you can add Grashof constraints. An example of how to do this in MotionSolve is included.