But do not panic just yet, at least not because you read the word physics above. You really do not need to know much physics at all to get through this project. In fact all the essential class definitions involved in this simulation have been completely implemented by your textbook authors, and the methods in these classes already incorporate all the required physics dealing with gravitational forces, accelerations, and so forth. So as usual, your first tasks will be essentially just tests of the framework already provided for the Case Study.
Of course you will eventually be asked to take on some more challenging tasks. But these will really be programming problems, not physics problems.
To complete this project, follow the steps listed below:
After you have read a description of the Vector class, open Vector.java in the NetBeans editor and try to familiarize yourself with its contents. If you started by reading the textbook version, you should note that the actual source code is a bit more extensive than the textbook listing on page 432. But all you really want to do now is to understand the API well enough to see how it is used by the other two classes in this project. Since these textbook classes lack complete external documentation, you may frequently have to consult the source code itself as you proceed.
In this N-body simulation the Body objects might model individual celestial bodies (hence the name). These can include stars, planets, asteroids, and comets, as well as exotic objects like neutron stars or black holes. And of course all manner of combinations are possible, such as planets orbiting neutron stars or neutron stars orbiting each other (both of which have actually been observed).
You should now take a moment to scan pp. 457-460 in your text, or the equivalent Booksite discussion for Section 3.4. Then open Body.java in the NetBeans editor. You should note that the instance variables for a Body object include its mass (a double value) and two Vector objects, representing its location r and velocity v respectively.
You might also note that the actual API defined by Body.java is almost identical to the printed listing on page 460 of your text, except for a method named forceTo(). The textbook listing names this method forceFrom(), but in fact the bodies of the two methods are identical. The difference is really one of perspective: forceTo() returns the gravitational force exerted by the calling object (aka this) on some other Body object b. In the printed listing the method forceFrom() is supposed to return the force exerted by object b on the calling object. But unfortunately, that version has a sign error, which would make the gravitational force repulsive. So you will want to stick with the Booksite version here, not the textbook listing.
You should also be sure to look over the key method increaseTime(). This method first computes the total vector sum of the gravitational forces on each Body due to all the other Body objects. Then it makes use of Newton's second law of motion, which just states that the acceleration of a mass point is given by the net force acting on it divided by its mass. Following this law, increaseTime() causes each Body to advance along its path by an amount determined by its computed acceleration over a small fixed time interval.
At this point, Build the project and run Universe from the terminal window. For starters, you might try the sample input textfile 2body.txt which is available from Section 3.4 of the Booksite. Note that you will also need to supply the time-increment interval (in seconds!) as a command-line argument suggested in the program header comments. You might try entering 10000 for the input file suggested above. This value may not seem like a "small" time increment to you, but the values in the input textfile are appropriate for typical planetary motions (where the time scales should really be measured in months or years rather than seconds).
Note that you can easily find the required masses, distances, and so forth using Google. Just remember to get these quantities in MKS units (meters-kilograms-seconds). You might also want to remember that Newton's second law of motion, F = ma, can be combined with his law of gravitation to get ma = GMm/r2. Also note that circular acceleration is related to velocity and radius by the formula a = v2/r. And finally, if you find yourself in need of a calculator, remember there is one available on your system (look under accessories).
When you get this simulation running to your satisfaction, show your results to your lab instructor.
In any event, your first test of your new code should be made with a simple 2-body simulation such as 2body.txt. For this file, your version of MyUniverse should at least initially resemble the following image:
But note that if you let your program run for much longer times, the image might begin to look more like this:
Can you come up with an explanation for this behavior? Hint: you might try running your program again with, say, half the original time increment but for twice as long in real time. Do you get the essentially the same image?
To complete the formalities, show your results to your lab instructor.
When your project is complete and working correctly, demonstrate it to your lab instructor. Then, before you exit NetBeans, clean your Lab13 project. Finally, before you logout, switch back to your terminal and set your default directory back to csci/273.002/labs. Then create a JAR file of your Lab13 project folder, using the command
jar cf Lab13Project.jar Lab13Please leave both your Lab13 project folder and Lab13Project.jar in your csci/273.002/labs directory for the remainder of the semester.