Introduction to Computational Physics

Scientific Computation

Computers have revolutionized our society; this is particularly striking in the fields of Science and Engineering. These ``hard'' disciplines are seeing computers becoming part of the everyday routine of most practitioners in these fields. New branches of Science and Engineering have even appeared due to computers. In Physics, in particular, there once used to be theoretical physicists, trying to model mathematically the many phenomena encountered, and there were experimental physicists, trying to uncover new phenomena and measure appropriate quantities to prove or disprove the theories. Now there are also computational physicists, modeling phenomena numerically, and ``experimenting'' on computers using these models. Experimental mathematics, once a contradiction in terms, is now a reality.

A well-rounded researcher in theoretical physics must have had traditionally deep knowledge of theoretical models, with their necessary baggage of analytical mathematics, and an experimental physicist must have had to know the nuts and bolts of electronics, vacuum techniques, and so on. Nowadays both must also know much about numerical techniques and how to control computers. Computers have permeated our discipline to such an extent that they are at work in direct or indirect ways in virtually all ares of research. Computational physicist represent the extreme case where computers, by virtue of their power, have opened up entirely new avenues of research. It goes without saying that detailed knowledge of numerical techniques is indispensable in this case.

This of course is about physics, but seen from the point of view of a computational physicist. We will see many models dealing with various physical situations; we will explain the physics leading to these models and their mathematical background; we will then invariably try to further our physical intuition by obtaining numerical solutions for the models. Analysis of our results will lead us naturally to the use of graphical tools. The numerical techniques used in the solutions will be explained; their origin, their generality and their finite accuracy will be touched upon in all cases. But our course will not be a rigorous course on numerical analysis; we will be content to explain the ideas in an intuitive way, only being ``mathematically rigorous'' when absolutely necessary to further our understanding. ``Computational sciences'' are very different than ``computer science;'' the former aims at solving challenging science and engineering problems numerically, accurately and, above all, efficiently.

During this course you will hear much about computing, but relatively little about computers; most of our topics will apply to any computing platform. However, this chapter is an exception. To be concrete, we will assume that our computing environment is UNIX, using X-windows, and that the language of choice for our programming is C. This chapter intends to get us started in this computing environment.

One goal of this course is to get us to think in general terms about good programming practices. Let's face it: the numerical solution of models encountered in our research can seldom be achieved via pre-packaged software. Usually, a numerical solution can only be obtained via hand-written lengthy procedures. Who do you suppose will write these procedures? Good programming practices are indispensable in this endeavor.

Let's get started, shall we?

The Computing Environment

The ideal computing environment in today's world follows the following paradigm: a fast local workstation capable of high-resolution graphics for the local analysis of the results of large computations; a local compute/file server to develop algorithms and test physical ideas locally using scaled-down models; access to fast computers in the supercomputer centers; fast access to the Ethernet for using external compute servers and information sources.

This course will assume the implementation of this ideal computing environment via a local UNIX file/compute server and local workstations. Furthermore, we will standardize on the UNIX Operating System (OS) and X-windows as our software environment.

UNIX

The UNIX Operating System is the system of choice for the computational scientist; it is a very powerful and robust OS. Its functioning is based the notion of files. It instructs the CPU into a full multi-user multi-tasking environment, with virtual memory. The great advantage of UNIX is that it is available on a wide variety of computing platforms. The UNIX OS came historically in two major versions, the Berkeley BSD and AT&T System V. UNIX is not a proprietary OS, and various computer vendors have adopted it, specially in the world of workstations. This provides for a uniform computing environment for users, which is a great advantage in these days of increasingly fast networks, where one can use different computers, of very different compute power and architectures, yet find essentially the same OS.

Over the years, computer vendors have adapted their own versions of UNIX, usually with flavors resembling either BSD or System V. Some vendors have even gone from one flavor to the other over the years, as is the case with Sun Microsystem, which moved from BSD to System V in moving from SunOS 4 to Solaris. The functionalities of the different flavors of UNIX are the same for the the most part, but minor differences do exist in some commands, and major differences exist in the organization of the files on disk. At the level of the casual user, however, these differences are minor.

Linux was developed as a free publicly available UNIX OS. Its development took multiple paths that produced ever more powerful and reliable OS. On of the latest is the Ubuntu, version 9.10. Ubuntu is an operating system built by a worldwide team of expert developers. It contains all the applications you need: a web browser, office suite, media apps, instant messaging and much more.

Ubuntu is an open-source alternative to Windows and Office.

UNIX comes with (at least) four different command interpreters, or shells. The C-shell (invented by Bill Joy, the founder of Sun Microsystems, then at Berkeley), the Korn shell, the BASH shell and the Bourne shell, the "original" UNIX shell, still beloved by "real" UNIX hackers. Most systems support the shells, assuring that a user can customarize the environment to his/her needs. Small differences may exist between the shell interpreters on different systems, but the casual user will not be hindered by this. The csh command launches the C shell while the sh command launches the Bourne shell. These two commands are handy to change shell. Each user has his/her own default shell, as set in the /etc/passwd file file. We will use the C-shell syntax in these notes; our system default is a ``souped-up'' version of C-shell, called tcsh.

The X Window System

The X-window environment implements the concept of a ``window at a distance,'' arguably the major breakthrough responsible for the advancement of the computing paradigm based on the network. The X-window system is a trademark of MIT, where the software and the protocol were originally written at the Laboratory for Computer Science; it is now under the X-consortium.

One very important consequence of the implementation of the X-window system was the development of the workstations. These are sophisticated computers, with specialized software enabling them to act as X-servers. This makes for a clean distribution of labor between the computing part of a problem, best done on a compute server, and the handling of the user interface, including graphics, by the workstation. This allows the implemention of fast graphics at reasonable cost, compared to powerful standalone workstations.

The Internet

The revolution that computers are bringing to our lifes stems to a large extent from the interconnectivity between machines. This allows for a great variety of activities on the net: information exchange between people via e-mail, news groups, and bulletin boards; shared databases; repositories of scientific papers; searching for information on the net via Google and other search engines; information browsing on the World-Wide Web; interactive work on computers at a distance; and finally the ability to create and manipulate windows at a distance. These activities are rather routine nowadays, and very common among network users.

The C Language

In scientific computation, the most commonly used languages are PYTHON, FORTRAN, C++ and C. Both are used on machines of all sizes and architectures, from workstations to super-scalar servers and parallel supercomputers. The older of these languages, FORTRAN, was originally developed by IBM in the early 1960s. It has seen many improvements over the years, and is probably still a very widely used language among ``technical'' programmers, especially those who learned their skills in the 1960s and 1970s. However, this course will standardize on C (and C++), which enjoys ever increasing popularity due to its high-level constructs, the efficiency of the C compilers, especially the one written by the GNU organization, and its easy interface to computer hardware. It is also the language in which higher level functionality of UNIX is written (both C and UNIX were developed at Bell Labs in the early 1970s, with considerable overlap in personnel), making the connection to the OS efficient. Originally the language of choice of computer scientists, professional programmers and ``systems'' people, C is now also widely used in scientific applications. C++ introduces object oriented environment at an execution speed comparable to that from C. PYTHON is a script language (therefore slow at execution) that brings in amazing flexibility in coding. It supports objects and comes with very extensible numerical and graphical libraries

These languages interface very readily and efficiently; a PYTHON program can use C routines, and vice-versa, with little programming effort. This renders the choice of the language less critical for many applications. The important thing is to eventually become comfortable in one or two of these languages, and perhaps know a little of the other. This allows, for instance, to use PYTHON to "organize" a large code and use C or C++ to implement the compute intensive tasks.