Assignment 1

Part 2

In this part of the assignment you will write portions of a CMF program that will allow you to simulate a dynamical system and graphically display a phase portrait of its behavior.

1) Type "~^B" (to type ^B, hold down on the "Control" key and type "b") in the xterm window you used to start Prism. This will disconnect the xterm from Prism and allow you to use it again as a terminal. (You may get an irrelevant error message.)

2) Use the UNIX "mkdir" command to create a subdirectory under your home directory to hold the work you will be doing in the assignment. (Call it, say, HW1). From the xterm window, "cd" into that subdirectory. Use the command "cp ~edelman/1995/HW1/package/* ." to copy the files you will need for this assignment into the subdirectory you created. Use the "ls" command to list the files in the directory. You should find files named Makefile, phaseplot.fcm, solver.fcm, plot.fcm, and graphics.fcm.

3) Makefile is a file that tells the Unix make command how to compile and link the four CMF programs that make up the phaseplot application. Makefile instructs the make command to compile using the -g switch, therefore your executable can be debugged using Prism. Type "make" now to see how it goes about creating the executable "phaseplot" from the CMF programs phaseplot.fcm, solver.fcm, plot.fcm, and graphics.fcm.

At this point, given all the time it takes to link, you will see why people have joked this is more of a "linking machine" than a "thinking machine."

4) If you try to run the newly created executable on scout by typing "phaseplot" you will get the error message "CMOST: Cannot connect to cmni.". The problem is that scout is simply a workstation that is used as a compile server for people developing CM-5 applications. It is not a CM-5 "partition manager" (PM) and therefore it is not connected to any of the processing nodes (PNs) in the CM-5. Applications written in CMF must be executed on a PM and only PMs have cmnis (these are the interfaces between the PMs and the communication network that connects them with the PNs). Therefore, the error message is letting you know that you are trying to run your application on a workstation that is not a PM. To execute on a PM, use the DJM script you created in part 1 of this problem by typing "jsub run_prism" (I have had a few problems in the past with not being able to connect to CMNI, but just lately this is working)

5) When you used DJM to start Prism you gave it enough information to make an intelligent choice about which PM it should use to run Prism. It then started Prism on that PM. If you use Prism to execute a program you will be executing the program on the same PM.

See WARNING: If you have problems connecting, try the following cheat. "rsh" over to cm51, cm52, or cm53 directly. Set the displays again and try again. Also you can get some status information using "jstat" and "cmps." I've never managed to get prism to execute a job from scout rather than cm51, so if you figure out how to do this let me know. I think the problem is that there is no mechanism for setting the displays.

Use Prism to load and run "phaseplot". A blank window will appear on your screen. After several seconds it will disappear and the program will exit, printing "FORTRAN STOP" in the InputOutput window. Pretty dull now, but wait until you are finished!

6) Your job will be to fill in gaps in the phaseplot program. The code you write will simulate a dynamical system and display a phase portrait of its behavior in the window that appeared on your screen in Step 5.

The phaseplot program solves multiple ODEs simultaneously in parallel. All of the ODE state variables are set to their initial conditions in parallel and all time steps are taken in parallel.

Let`s start with an overview of the four parts that make up the phaseplot program: 7) Start by using your text editor to modify the routine set_initial_conds in the file solver.fcm. Your goal will be write code that will set the initial values of the state variables in such a way that the starting positions of the ODEs in the phase plane form a uniform grid.

Your first goal is to create two grids x and y of size grid_nx by grid_ny where x goes from min_x to max_x and y goes from min_y to max_y. This is not so different from Matlab's meshdom command for those who are familiar.

x may be obtained as a one liner using a spread along dimension 2, while y is a one liner using a spread along dimension 1. Each statement uses an array constructor to create a series of integers, elemental functions to scale the integers (and convert them to reals) and add the appropriate offset, and SPREADS to convert the resulting 1-D array to a 2-D array. (Note: It would probably make more sense to use two FORALL statements to accomplish this task, but the FORALL statement was not covered in the lectures.)

After writing the code you should check it using Prism. Reload the program and set a breakpoint at the call to set_initial_conds in phaseplot.fcm. You can use the slash to search the file if you wish. Run the program. When you get to the breakpoint, step into set_initial_conds and stop at the the END statement. View the contents of the x and y arrays to check your code. A "Text" representation of the data can be used to check the values of the arrays at the boundaries of the grids and "Graph" and "Colormap" representations can be used to make sure the interior points are OK. (Note: The visualization tutorial you worked through in the first part of the assignment may not have given you a very good understanding of the colormap and graph visualizers. If you need more help, click on Prism's "Print.." button, then click on the "Help" button in the window that pops up. This will give you access to CMview's Prism documentation.)

8) Now add the code that is needed in the routine plot_points in the file plot.fcm. Your code should take the state variables x and y, scale them, convert them to integers, and store them in the arrays int_x and int_y. The scaling involves converting the phase space coordinates to corresponding pixel coordinates. The boundaries of the phase space window are given by min_x, max_x, min_y, and max_y. The pixel coordinates go from zero to "width - 1" in the x direction and zero to "height - 1" in the y direction. Don't worry about the exact correspondence between phase space coordinates and pixel coordinates. It's OK if you're a pixel off in a given direction. Likewise, don't worry about whether to truncate or round to convert integers - just do what's easiest. You should be able to use two elemental assignment statements to do this transformation. You can check your work by running under Prism and looking for a uniform grid of points (respresenting the initial conditions of the ODEs) displayed in the phase space window that pops up on your screen. (Note: Don't forget that you need to convert your real array to an integer array as the final part of this transformation. Use the INT function to accomplish this type conversion.)

9) The final task in this part of the assignment is to add the code that updates the state variables each time you take a time step. This code will be put into the subroutine step in the file solver.fcm. We will use the Lienard form of the differential equations that describe the behavior of a nonlinear self-excited oscillator know as a "van der Pol oscillator". In the absence of external driving forces trajectories that start anywhere in phase space other that the origin are drawn to a single cyclic path called a limit cycle. This is the behavior you should observe in the phase space window when you have completed this step of the assignment.

The derivatives of the state variables are given by

x' = y - (x**3 - a*x)
y' = -x

To keep things simple, use Euler's Method, i.e. for each time step set the new value of each state variable to its previous value plus the product of the time step size and the derivative evaluated at the previous time step. (Note: To do this correctly you should create a temporary array to hold the state variable that you choose to update first. The values saved in the temporary variable (rather than the updated values of the variable) should then be used in the calulation of the other state variable.) All in all, you are typing three executable lines of code, one to define temp, one to define x, and finally the last one defines y. Also you need to correctly declare the temporary variable. (Note a is a parameter initially set to 2.0. Can you find where?)

When you are finished with this step you should have a program that plots points at the phase plane locations of the ODEs at every time step. You should be able to see these points move toward a limit cycle as time passes. In the final stages of the simulation all of the ODEs should be travelling along the path of the limit cycle in phase space.

Drawing lines between consecutive phase space locations for each of the ODEs would result in a clearer picture. In other words, it would be better to trace out the trajectories of all of the ODEs. This is what you will do in the next part of the assignment.

Go back to part 1.
Continue to part 3.
Return to the class home page.