Documentation Center

  • Trial Software
  • Product Updates

Initialize Variables for a Mass-Spring-Damper System

This example shows how to use block variable initialization, and how it affects the simulation results of a simple mechanical system.

The model is a classical unforced mass-spring-damper system, with the oscillations of the mass caused by the initial deformation of the spring.

Create and Set Up the Model

  1. Create a simple mass-spring-damper system. Use the Mass, Translational Spring, Translational Damper, Mechanical Translational Reference, Ideal Translational Motion Sensor, PS-Simulink Converter, Solver Configuration, and Scope blocks, and connect them as shown in the following illustration.

  2. Prepare the model for simulation. On the top menu bar of the model window, select Simulation > Model Configuration Parameters. Under Solver options, set Solver to ode23t (mod.stiff/Trapezoidal) and Max step size to 0.2. Also adjust the Simulation time to be between 0 and 2 seconds, by setting Stop time to 2.0.

  3. Specify the initial deformation of the spring. Double-click the Translational Spring block. In the block dialog box, click the Variables tab, and then select the check box next to the Deformation variable. Once you select the check box next to a variable, its Priority changes to High, while Value and Unit assume the values specified in the variable declaration in the underlying component file. Change the Value to 0.1. Leave the Unit unchanged as m.

  4. Adjust the initial position of the sensor, to compensate for the spring deformation. Double-click the Ideal Translational Motion Sensor block and set its Initial position parameter value to 0.1 m as well. This way, when you simulate the model, mass oscillations center around 0.

  5. Simulate the model.

  6. Open the Variable Viewer. In the top menu bar of the model window, select Analysis > Simscape > Variable Viewer.

    The Translational Spring variable x, in the bottom row, has high priority and the target value of 0.1 m. This is the Deformation variable that you have just set up in the block dialog box. Its actual start value matches its target value, and therefore its Status column displays a green circle.

    The other high-priority variable in this model is the position, x, of the Ideal Translational Motion Sensor block, which is set inside the component file because it is necessary for the correct operation of the sensor. Its actual start value also matches its target value, and its Status column also displays a green circle.

    The rest of the variables in the model do not have initialization priority specified, therefore their Status column also displays green circles. The overall status at the bottom of the Variable Viewer window displays a green circle as well, and says that all the variable targets are satisfied.

Change Initialization Targets

You can now see how specifying different variable targets affects system initialization and simulation results.

  1. Specify the initial velocity of the mass. Double-click the Mass block, go to the Variables tab, select the check box next to the Velocity variable, and enter a value of 10. Keep the priority High and the unit m/s.

  2. Refresh the Variable Viewer by clicking .

    You can see that the solver has found a different initial solution, which satisfies your variable targets for spring deformation and mass velocity. The Status column displays green circles, and the overall status at the bottom of the Variable Viewer window also displays a green circle and says that all the variable targets are satisfied.

  3. Notice that when you refreshed the Variable Viewer, the scopes turned blank. This happens because solver runs the simulation for 0 seconds to find the initial solution and display it in the Variable Viewer.

    Rerun the simulation and examine the Velocity and Position scope windows, to see the effect of the new initial value for mass velocity on the simulation results.

Deal with Over-Specification

As you specify additional variable targets, sometimes it is possible to over-specify the constraints.

  1. Double-click the Translational Damper block, go to the Variables tab, select the check box next to the Force variable, and enter a value of 200. Keep the priority High and the unit N.

  2. Refresh the Variable Viewer.

    The overall status at the bottom of the Variable Viewer window now displays a red square and says that the solver is unable to satisfy all the high-priority variable targets. There are red squares in the Status column for the two high-priority variables with targets not satisfied, as well as for their parent blocks.

    Notice that the solver has been able to find a solution for model initialization. If you rerun the simulation, it runs without errors and you can see the new simulation results.

    However, the Variable Viewer shows that the model initialization solution does not satisfy your target values for block variables. This happens because placing high-priority constraints on all three elements of the mass-spring-damper system results in a conflict. You can resolve the over-specification issue by relaxing the priority of some of the conflicting variable targets.

  3. Double-click the Translational Damper block again, go to the Variables tab, and change the priority of the Force variable to Low.

  4. Refresh the Variable Viewer.

    The overall status at the bottom of the Variable Viewer window now displays a yellow triangle and says that all the high-priority targets are satisfied, but some of the low-priority targets are not satisfied. There are now two yellow triangles in the status column: one for the low-priority force variable f and one for its parent block, Translational Damper.

    Essentially, the solution found in this case is the same as when you previously specified high-priority target for the mass velocity, and the simulation results are the same.

  5. Another way to deal with over-specification is to keep the high priority on the damper force and relax the priority on mass initial velocity. Double-click the Translational Damper block again, go to the Variables tab, and change the priority of the Force variable back to High. Then double-click the Mass block, go to the Variables tab, and change the priority of the Velocity variable to Low.

  6. Refresh the Variable Viewer.

    Again, the Variable Viewer status says that all the high-priority targets have been satisfied and that some of the low-priority targets are not satisfied. However, because you changed the variable priorities, the solver now tried to satisfy the initial force on the damper rather than the mass velocity, and the solution is different in this case, as are the simulation results.

Related Examples

More About

Was this topic helpful?