Ast 4101/Phys 4041

Computational Methods in the Physical Sciences

****

Fall 2012

 

M,T,W,Th 8:00-8:50 AM, Physics 143**

Instructor: Prof. Tom Jones, Physics 369,  twj@umn.edu

Office Hour: T 12:00-1:00 (or contact for appointment)

 

TA: Dinesh Shenoy, shenoy@astro.umn.edu

Office Hour: M 10:00-11:00, Physics 369 (or by appointment)

Personal website (with useful course guide information) http://homepages.spa.umn.edu/~shenoy/

 

 

The aim of this course is to provide an introduction to the use of computers in solving problems common to physical sciences. It is not a course designed to learn a programming language. I will assume a basic prior understanding of a high level programming language, C, C++, and/or FORTRAN. Any of these languages is acceptable, although FORTRAN is recommended, since your codes will be usually much shorter and simpler in FORTRAN. You will be expected to write programs in one of these languages (NOT in Mathematica, for example) for your class assignments and exams. You need not be expert in the language; through experience you will gain adequate skill during the course. The focus will be on problem solving and some of the numerical techniques commonly used for that purpose, as well as the strengths and weaknesses of these methods. Scientific programming is as much an art as a science, so students in this class will be expected on a regular basis to write, test and apply their own routines in one of the above languages in order to experience firsthand many of the issues associated with the subject. Wherever possible, examples will be selected from physics and astronomy contexts.

 

** We will meet each Thursday during the scheduled class time in Keller 2-170 for practical “lab” experience with the algorithms under discussion. The first meeting will be a basic tutorial on computational/programming skills. You will each need to open an account to use these computers (see below). You must do this before the first Thursday class.

 

      Course Outline:

 

1)  Some basic tools:

a.     Starting basics: differences between numerical and analytic arithmetic;

        Controlling and living with numerical errors

a.     Finite Differences

b.    Interpolation

c.     Differentiation

d.    Roots of Equations

e.     Integration

f.      Linear Algebra

g.     Discrete Fourier Transforms (FORTRAN: cfft1.f); (C++: cfft.cpp) (DS9)

2)  Random Processes & Monte Carlo Simulations

3)  Ordinary Differential Equations

4)  Partial Differential Equations

                                                                                                  

 

Official Text: “Computational Physics, An Introduction”, Second Edition by Franz Vesely (Kluwer)

Highly recommended reference: “Numerical Recipes, The Art of Scientific Computing”, by Press, Teukolsky, Vetterling & Flannery (Cambridge)

                                                                                                    

Basis for course grade:

*quasi-weekly homework assignments (in total 50% of course grade) (current assignment) (data)(past assignment)

*weekly lab participation (10%) (current lab exercise)(lab file1)(lab file2)(lab data)(Plot) You must attend a given lab to get credit for it.

*take-home midterm exam due in class on Monday, October 22 (15%) (exam)

*take-home final exam (25%) (exam) This exam is due no later than 1:30 PM, Thursday, Dec 20. It can be turned in to staff in Tate 356 or 358C or to your instructor or TA.

                          

Late homework policy: Homework assignments will be accepted one class date after they are officially due with no penalty; however, they will not be accepted at all after that. Generally, the due date will be a Tuesday.

 

 

General information

 

Important policies on homeworks and exams (be sure to read):

 

1) Students may use computers of their own choosing (information about CSE computer labs is listed below), provided they have the necessary compilers and suitable graphical software installed.

2) Routines must be programmed by the student in one of the languages listed above (C, C++, FORTRAN). General math packages such as Matlab or Mathematica can be used for verification purposes only.  Do not turn in solutions based on these packages. They will not be graded.

3) Source codes must be written by the student who turns in a given assignment; routines may not be copied from Numerical Recipes, for example. That defeats the purpose of the course.

4) Submitted problem solutions, in addition to requested application results and/or plots, must include the source code used to generate those results with enough coding comments that anyone can understand your plan and what your routine is supposed to be doing as it executes. A simple flow chart or equivalent logical outline may be included to indicate intended programming logic.

5) Write your routines in modular, object oriented forms and in a sufficiently general way that you can incorporate them easily into subsequent exercises. This will save you a great deal of effort later on, since many routines will be used again in lab exercises, subsequent homework and exams.

6) Students are encouraged to collaborate on the homework; however, the full solutions must be individually prepared and submitted.

7) Students must work independently on take-home exams; signed statements verifying independent effort will be required.

 

Getting an account on the CSE lab computers:

 

All students will need to open CSE computer accounts for use during the Thursday labs (and any other time they wish to use these computers). As a registered student you are automatically eligible. Please initialize your account before the first Thursday class in Keller 2-170. Information on opening an account can be found at http://cselabs.umn.edu/accounts. General CSE computer lab information can be found at http://cselabs.umn.edu/. The labs are usually open M-F 9:00-22:00, but closed on weekends. We have Keller 2-170 reserved during class time on Thursdays.

 

Basic information about the computers in Keller 2-170:

 

While some CSE labs include machines with Windows OS, we will use Linux in the lab for this course. All the machines in Keller 2-170 run Linux. These machines offer f77, f95, cc, c++ compilers, as well as the gnuplot, Supermongo (see below) and Techplot graphics packages, among others. Any suitable graphics package may be used, so long as the plots/images are clean and well-enough labeled for evaluation. Please do not use Excel for plots; it was not designed for scientific computation.

 

To load compilers on the Keller 2-170 Linux machines enter “module load compilers/compilers” on the command line after login.  To have this happen automatically every time you login, include the line ‘module initadd compilers/compilers’ in your .cshrc file that can be found in your home directory. This file controls your environment. If your .cshrc file already contains a line ‘module initadd compilers’, you should be OK. You can verify that a given compiler, say f95, is in your path by typing “which f95”. The system should return the location of the compiler executable. In this case that would be “/usr/bin/f95”.

 

Creating and editing source code files on these machines is generally best done using either emacs, vi or vim editors. They will not add nonprinting formatting commands that can confuse compilers.

 

If you are running Windows on your own computer, but want to emulate the Linux environment, including X-windows you may want to try the freeware offered at Cygwin. Specifically to enable X-window importing there is Cygwin/X. There are other X-term tools for Windows. Macs in OS-X, which runs Linux under the hood, should be able to create X-windows.

 

The machines in Keller can be accessed remotely if you have a tool that runs “ssh”. Ssh is a standard tool in Linux. 
A basic, freeware Windows too for this is PuTTy.  Mac users can utilize the OpenSSH client. 
 
The IP addresses of the Keller 2-170 machines are: 
cs2170-N.cselabs.umn.edu, where ‘N’ is an integer in the range [01,20]. If your local computer can import X-windows, 
then you can often even run graphics tools on the remote Linux machine and export the X11 graphics window to your 
local computers for display. This will usually require you to use the “-X” option of “ssh”. 
(Type “man ssh” on the Linux command line for details.)

 

Printing in the CSE Labs:

 

Printing help can be found here:  http://help.cselabs.umn.edu/printing

 

Plotting Help:

 

You can use any graphics package you wish, so long as it makes clean, easy to read plots and, when needed, images. I like Supermongo and DS9 for what we are doing in this class, but the choice is yours. I strongly discourage use of Excel spreadsheet plots, since they are usually very hard to evaluate.

 

Getting started with Supermongo

 

The graphics package “Supermongo”, installed on the cselabs machines, is a powerful, but simple tool for making plots, contour diagrams and surface plots. It includes a number of built-in math operations that make for flexible plotting and analysis. For repetitive or complex plots, “sm” allows the use of macrofile inputs. The full sm manual (228 pages) and a shorter sm tutorial are posted here in pdf format.

 

Note that to run “sm” on the Linux machines in Keller 2-170 you must first run “module load soft/sm”. When you initialize “sm” an X11 graphics window should open. You will continue to type sm commands inside the original text window you were using. To create an encapsulated postscript file of your plots you need to use the ‘device’ or ‘dev’ command in sm. Typing “dev postencap plotfile.eps”, for example, will open a file “plotfile.eps”. You would then enter whatever sequence of commands needed to generate your plot, just as you would in the X11 window, followed by “hardcopy” to save the plotfile. To return to an X11 graphics window type “dev x11”.

 

As a warm up exercise try making a simple plot using the data file here. Let the first column be the abscissa and the second column be the ordinate. As an aid you may try using the file here as an “input” macro. You can execute this macro command file by typing “input test.mn”, where ‘test.mn’ is the name of the command file to be implemented.

 

Information on obtaining the free “DS9” two dimensional visualization and analysis tool can be found here.

  

 

Some very useful information about basic programming skills is contained in these tutorial notes prepared by Pete Mendygral, a former TA for this class:

 

Tutorial notes

 

Some useful references on Fortran 90 programming are “Fortran 90 for Engineers and Scientists” by Nyhoff & Leestma and “Fortran 90/95 Explained” by Metcalf and Reid

 

Some example demo codes shown in class.