School of Physics

An Introduction to
Computational Methods in Physics

This course is now finished for 2004-5

MODEL SOLUTIONS

There is no model solution for checkpoint 6. The model solution for checkpoint 5 is already available, but you should only look at it if you are not intending to present your own version.

Marksheets are available in the CPlab. Please check that all your marks are correctly recorded.

Foreword

The idea that physics is about solving equations analytically is a major misapprehension in undergraduate education. The mathematics underlying most problems of interest today cannot be solved analytically, and the contribution of computing in 20th century physics has been to solve intractable equations by converting them to algorithms. In the 21st century, computer simulation will leave mathematics behind, physical phenomena will be deemed understood when the underlying processes can be reduced to an algorithm rather than an equation.

This course aims to give you the essential skills underlying 21st century physics.

The material of this course is designed to be accessible anywhere on the Edinburgh University campus, through a World Wide Web interface. Much of the practical work of the course requires java libraries which can be accessed, via a window to the LINUX operating system on the Computational Physics laboratory. Typically, you will be in the CPlab when you are doing this course although it is possible to work remotely. Detailed information about the CPlab is here, but note that for 2003 we have a new window manager.

The contact hours for the course are 2-4 or 4-6 on Tuesday and Thursday. There will be an introductory lecture on Wednesday of Week 1 - you should sign up for one sesson per week within the CPlab where demonstrators will be available to provide help and the assess checkpoints. You must attend your chosen session (sign-in sheets will be provided). You may attend other sessions if space is available.

The language of the course is java. Java is not the language of choice among professional physicists (that's still fortran), however it is far more popular outwith the physics community as the language of the internet. We therefore believe that the transferable skill of JAVA programming is more valuable. The definitive guide to java is maintained by sun . You should already know the basics of compilation and execution

Schedule and Marking Scheme

The course involves the completion of a series of checkpoints, each requiring you to write and document some computer code in java. There are five compulsory checkpoints. Each checkpoint comprises a computer file containing the code and written documentation of the problem design. See the marking criteria for more details. When you have completed the checkpoint, show your work to a demonstrator who will mark it based on your understanding of the physics, the comprehensibility of the code to the demonstrator, and (of course) whether it does what it is meant to.

You must get the checkpoints marked by a Demonstrator during the CP Lab sessions.

In the unlikely event that you cannot find a demonstrator before the end of your appointed session you should arrange a time with Prof Ackland at the Thursday 4-6 session. Each checkpoint has its own deadline.

Checkpoint 1 should now be finished - model solution below
Checkpoint 2 should now be finished - model solution below
Checkpoint 3 should now be finished - model solution below
Checkpoint 4 should now be finished - model solution below
Checkpoint 5 should be finished by end of week 11
Checkpoint 6 should be finished by end of week 11


Late submission is not an option

Checkpoints 1-5 not completed by the deadline are subject to different criteria and can only score 50%. See section on "plagiarism" below.

The sixth checkpoint is challenging and aimed at "first class" students: it will take more than a week and you can obtain a good mark without it. Failing to do all of the first five checkpoints would be really stupid, check the marking scheme to see why.

It is expected that you will do much of the work of the course outside the formal sessions. The course material is available online.

You will be able to see the marks awarded by the demonstrators on the sign-up sheet. If you notice an error, please let Prof. Ackland know.

Plagiarism

In modern programming, borrowing or reusing other peoples' code is a virtue. However, it is not helpful in learning how to program. To balance these conflicting requirements, the following rules apply:

You may seek help from your classmates or by websearch provided you acknowledge that help as a comment within your code. If this is simply help with debugging or syntax, there is no penalty, and such cooperation is encouraged. If such help extends to copying sections of other people's code, this is still acceptable but may be reflected in a slightly lower mark for the checkpoint. Anyone caught plagiarising without acknowledging the source will fail the course.

Model solutions to each checkpoint will be made available online after the deadline has passed. The comments in the model solution will be incomplete. If you have been unable to write a working program by the deadline, you may obtain up to half marks by understanding the model solution, adding full comments in the code, and presenting it to the demonstrator in the same way as if it were your own work. You may also elect to present a classmates code in a similar fashion (acknowledged as above). The demonstrator will assess your understanding of how the code works, and may require you to make small adjustments to show your understanding.

Additional credit may be given to students whose help is acknowledged by others.

Many checkpoints provide links to codes which do similar things. This is intended to help you with syntax and finding appropriate classnames. You are free to reuse anything from any code which is directly linked from the CompMeth webpages. Indeed, your first step will often be to copy one of these codes in its entirety, then start modifying it. Code from some checkpoints will be reused later, so it is a good idea to ensure that you understand the code.

Prerequisites

The main prerequisite for this course is an elementary knowledge of the java programing language and unix (linux) operating system. Typically, this means the Scientific Programming component of Physics 2 (SciProg). If you have not taken SciProg, you should check your computing background with Prof. Ackland to ensure it is acceptable.

If you have passed the Computer Simulation 2h half course, you should not take the Computational Methods course. Instead, you should be taking the more advanced Computer Simulation course.

You should visit anew or refresh your memory of Scientific Programming. you should be familiar with java syntax and all the documented material of that course.

Online Resources

There are many books and online sites which provide information about the java programming language. You are encouraged to surf the internet for relevant material. However, unlike languages such as FORTRAN, java is not designed primarily for scientific computing and the available material reflects this,

The definitive reference source and a set of tutorials is at SUN.

There are a number of example codes available which you may find useful. A review of simple errors which have arisen will be maintained during the course.

Checkpoints for Computational Methods

1/ Dice and statistics Revise Checkpoint 5 from SciProg using your now-improved knowledge of statistics. Model solution

2/ 3D Vector3 class . Given the CartesianCoordinate and Complex class example, write a vector class and do some simple tests. Model solution

3/ "Particle" class: the particle has vector properties (position, velocity, force) and scalar properties (mass). Write a method to increment to particle's properties in time (numerical integration of equation of motion). Model solution

4/ Driven damped SHO. Plot the long-time analytic solutions as seen in Physics 1, and integrate the equation of motion numerically. Subsequently, simulate the driven damped pendulum (which gives a hint of chaos) Pendulum model solution Spring Model solution

5/ Interacting Particles Bohr model for hydrogen, by numerical integration in 2D. Then 2D Bohr model for helium and finally 3D Bohr model for helium. Repeat for gravity/planets and Lennard-Jones particles. Try to understand why only the latter is stable. Three-particle Model solution

6/ Molecular dynamics (optional) Periodic boundary conditions, arrays of objects, and measurement of the pressure of the 2D Lennard Jones gas from momentum crossing the boundary.