Ast 4041/Phys 4041

Computational Methods in the Physical Sciences

****

Fall 2017

 

M,T,W,Th 8:00-8:50 AM, Tate B65**

Instructor: Prof. Tom Jones, Tate 285-02, twj@umn.edu

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

 

TA: Brian O’Neill, oneill@astro.umn.edu

Office Hour: M 10:30 Keller 1-200 (or by appointment)

TA website http://homepages.spa.umn.edu/~oneill/CompPhys

 

 

The aim of this course is to provide an introduction to the use of computers in solving the kinds of problems common to physical sciences. That is, it is a course to develop problem solving skills; it is not a course designed to learn a programming language, although you will write codes. I will assume a very basic prior understanding of, or incentive to learn a high level programming language, C, C++, and/or Fortran. Any of these languages is acceptable, although modern Fortran is encouraged, since your codes will be usually much shorter and simpler. For assignments, exams and labs you will be expected to write programs in one of the above languages (NOT in Mathematica, Python or Matlab, for example). Prior expertise in the language is not critical; through experience you will gain adequate skill during the course. (Many previous students in this course have accomplished this.) The course focus will be on problem solving using some of the basic numerical techniques commonly applied for that purpose, as well as on the strengths and weaknesses of these methods. A goal of the course is for you to gain confidence in your ability to select appropriate methods to solve problems you may encounter going forward. 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, example applications will be selected from physics and astronomy contexts.

 

** We will meet each Thursday during the scheduled class time in Keller 1-200 for practical “lab” experience with the algorithms under discussion and their extension. The first meeting (on the first Thursday of the semester) will be a basic tutorial on computational/programming skills. You will each need to open an account to use these computers (see below). It is essential that you do this before the first Thursday class.

 

      Course Outline:

 

1)  Some basic tools:

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

        Controlling and living with numerical errors

        Learning to recognize errors and other limitations

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 for visualization)

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 (Springer)

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, due Oct 3) (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. You will need to turn in what you accomplish during each lab in order to get that credit.  **The first lab is Thursday, Sept 7.**

**take-home midterm exam due by class time on Tuesday, October 24 (15%) (exam)

**take-home final exam (25%) (exam). The final exam will be due by 5 PM, Monday, December 18. Homework and exam solution submissions are electronic.

 

All homework assignments and exams should be submitted by email to the course TA according to instructions given here. Read carefully!

                          

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 for credit 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 and/or plotting purposes only. Do not turn in solutions (including source codes) 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. The underlying goal is to clearly present your plans for the code, to help isolate any problems.

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 1-200 (a dual boot, Windows/Linux-based location but Linux during our lab). 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 7:00-22:00, but closed on weekends. We have Keller 1-200 reserved during class time on Thursdays. Other Linux labs are in Keller 1-250, 4-240, 4-250 and Lind 40. Your cselab account should give you access to any of these.

 

Basic information about the computers in Keller 1-200:

 

While some CSE lab machines run the Windows OS, we will use Linux in the lab for this course. All the machines in Keller 1-200 are dual boot with both Windows and Linux. These machines offer f95, cc, c++ compilers, as well as the gnuplot, Tecplot and “supermongo” (sm) graphics packages, among others.  Any suitable graphics package may be used to provide graphical presentation of results, 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. The plots are often unusable for anything quantitative.

 

To use the above compilers and various other basic tools on the CSE public computers you should check the .bashrc file in your home directory to make sure it includes the line “module load soft/gcc java perl gnu local compilers system x11”. 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”.

For information on modules in Linux see 
https://cseit.umn.edu/knowledge-help/addremove-software-linux-machine
To see a full list of modules on the CSE system type “module avail”.
If you want to check if a particular application XXX is linked to your login, type
“which XXX”. If it is linked, the response will include the path to the executable. If nothing shows, that application is not linked to your login. You will then need either to include that path in your .bashrc file or the necessary “module load” statement there (or enter from the command line) after your login.

 

 

Creating and editing source code files on these machines is generally best done using emacs, gedit, vi or vim editors. They will not add nonprinting (invisible) formatting commands that can confuse compilers. Some other text editors, like Word, will do that, so should be avoided.

 

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 directly.

 

The Linux 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 tool for this is PuTTy
Mac users can utilize the OpenSSH client. 
 
In addition the CSE labs now have installed software that allows you to connect through a browser. 
Check this site.
 
The IP addresses of the Keller 1-200 machines are: 
csel-kh1200-N.cselabs.umn.edu, where ‘N’ is a two digit integer in the range [01,19]. If your local computer can import X-windows, then you should be able to 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.) The Linux machines in the other CSE labs (for example, Keller 1-250 are analogous. Just substitute kh1250 for kh1200 in the above address).

 

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, accurate and easy to read plots and, when needed, images. I personally like Supermongo and DS9 (you can get it free online. Google it.) for what we are doing in this class, but the choice is yours. Gnuplot is quite popular, and available on pretty much any Linux system. Tecplot, another powerful and general plotting tool is also available. Again, I strongly discourage use of Excel spreadsheet plots, since they can be very hard to evaluate. If you want to use Supermongo you need to put “module load soft/sm” in your .bashrc file.

 

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. The GNU Fortran 95 compiler is available on the CSE system. More recent versions, such as Fortran 2008 are not.

 

Some example demo codes shown in class (to be added in due course). (Set 1) (Set 2)