Time Slicing Simulator

David Bélanger
dbelan2(à)cs.mcgill.ca
Hesheng Chen
hchen19(à)cs.mcgill.ca

About the Work Distribution

Work has been equally divided between the team members. Due to exceptional reasons, David did more work than Hesheng in the first week but did less work that Hesheng in the last week. Overall, this resulted in work equally distributed. Both team members touched up to some degree each part of the simulator either by designing it, improving it or fixing bugs. Both team members understand the design and the implementation done by the other team member. The CVS logs at the beginning of each files provides some idea on work distribution but the marker should take too much into consideration the number of log entries per user as some revisons involved more work and it also depends on the frequency that the user checks in his file.

Code Status

Note: The Load State... and Save State... commands are not working. Code was written for them but due to time constraints, they were not debugged. We chose to spent our time on more important part of the assignment. All other functional components of the simulator should be working. It may be necessary to restart the GUI sometimes.

Extra Features

  1. Block graph simplification: All relays are removed, inputs and outputs correctly updated to reflect same model.
  2. Dependency graph simplication: All constants are removed from the dependency graph.
  3. A script to compute the best K. More on this in the Mass Spring section.

Files

Links to files are found in the appropriate sections. All files can be found here.

Tools

  1. Model Editor

    Files:
    
    editorApp.py
    simclasses.py
    MySimpleDialog.py - No changes.
    circletest.bd
    circletest.sim
    massspring.bd
    massspring.sim
    

    Changes in editorApp.py consist in adding a menu item Export to exp env... and an action command. This function exports a diagram in a format understandable by the experimentation environment. In simclasses.py, we can find the implementation of the Export method. It generates code that will build classes in the experimentation environment. The BD editor does not need the classes of the solver environment, it just generates text strings that is python code.

    We followed the following convention. Files ending in .bd are the files obtained by using the "Save as..." command, no change was done to the format of these files. Files ending in .sim are the model exported to the simulator format.

  2. Simulator

    1. Simulator UML Design
    2. Simulator Implementation
    3. Files:

     
    1. Simulator Manual
    2. How to start the simulator: command int and gui.
      1. working with textual interface
        1. Type the following command to start cmdint.py (commandinterprator): python cmdint.py
        2. As soon as you starting the commandinterprator, the system will provide you with all the available commands and their purposes.
        3. After the above information, the system will show a '>' prompt' and wait for you command input.
        4. At the any time, you can type 'help' command, which will show the above information again
        5. For each specific command, you can type 'man commandname' to get the command usage and commmand purpose. For example, typing 'man outputblocks' will produce the following information.
      2. Working with GUI

        To select variables to be plot. Click variable's name in list then click on the SetX or SetY buttons to set the x-axis and y-axis variables respectively. The SetToFile and ResetToFile buttons specifies the fields to save to a file (Simulator -> Save Results). If none selected, nothing is saved.

Experiments

  1. The Circle Test
    1. The set of first order equations:

    2. The corresponding block diagram for the circle test:

    3. Running result and plots

      Time Plots

      Two time plots were done, first one is Int1 vs time and the 2nd one is Int2 vs time (step size 0.1, comm_int 0.01, t = 0 to 10). Both are sine waves:

      Phase Plots

      Circles from bad to good. All plot uses a communication interval of 0.01 and runs from time 0 to 10.

      stepsize = 2 gives:

      green uses stepsize 1.0, gray uses step size 0.5 and red uses a step size of 0.25:

      Using a step size of 0.01, we get a nice circle:

      A good step size is 0.01. We compute the integrals by approximation. A small step size gives a better approximation. By using a step size small enough (say 0.01), we know the integration will be well approximated.

  2. Mass-spring
    1. The mathematical equations are:
      dx2/dt2 = - K/M * x
      x(t = 0) = 0.3
      v(t = 0) = 0
      mass = 0.23
      restlength = 0.2

    2. The set of first order differential equations

    3. The casual block diagram

    4. massspring.sim is the model file loaded in the time-slicing simulator.

      A class was written (findk.py) to estimate the parameter K. The command used to run the code is python findk.py. The script runs the simulation several times with K values in [1,10]. A step size of 0.01 is used. It outputs the maximum value:

      output

      the optimal k is  3.1
      the optimal error is 0.0777074355888
      
      Also, the k values and the corresponding errors were store in file ktest. Below is a plot of the sum of square errors versus the K value. Also note that we used our Plot from file... function to plot it!

      Plot below used best K. Blue curve is computed by simulator and orange curve is the measurement data.

      Parameters are:

      step size 0.001
      comm int 0.06
      start time 0
      end time 4
      K = 3.1