It interweaves modern computational techniques with traditional aspects of upper-level classical mechanics and thermodynamics courses, building from simple ...
COMPUTATION IN PHYSICS COURSES
An Incremental Approach to Computational Physics Education In Bradley University’s physics department, the author has developed an incremental approach to computational physics instruction. It interweaves modern computational techniques with traditional aspects of upper-level classical mechanics and thermodynamics courses, building from simple to more complex concepts and assignments. By directly programming and controlling all aspects of their computer applications, students can best grasp computational principles.
C
omputers are playing an increasingly important role in the lives, education, and duties of scientists and engineers. In particular, in the various fields comprising physics, the computer is now an indispensable tool for theorists and experimentalists alike for data acquisition, analysis and reduction, calculations, visualization, modeling, simulations, and so on. As a result, training undergraduate physics majors in the methods and techniques of computational physics has taken on a fresh urgency. (For the current state of computational physics in undergraduate physics curricula across the US, see the two related articles in this issue by Norman Chonacky and Robert Fuller.) Yet, it’s difficult for physics departments that have philosophical- and resource-related constraints to create extra courses and separate educational tracks to sufficiently meet students’ computational physics needs without compromising the traditional offerings that remain an important part of the undergraduate physics canon. I’ve devised a mode of integrating computational physics instruction into an undergraduate physics
1521-9615/06/$20.00 © 2006 IEEE Copublished by the IEEE CS and the AIP
KELLY R. ROOS Bradley University
44
curriculum, without a focused computational track or creating specific computational physics courses. Specifically, I’ve interwoven computation and numerical physics principles into the traditional format of two upper-level undergraduate courses, Classical Mechanics and Statistical Mechanics and Thermodynamics, which I’ve taught for 12 years at Bradley University. The approach is incremental in the sense that the students accumulate computational skills as they learn canonical topics. The courses still emphasize the core subject matter, but the computational tools help demonstrate the behavior of a particular solution, model, or system. Essentially, I augment these courses with computational topics without adversely decreasing the time spent on the traditional material.
Motivation and Basic Philosophy
I began this incremental approach to computational physics education approximately 12 years ago, shortly after I arrived at Bradley University. It was obvious from the start that my computational physics education efforts would have to be woven into the preexisting courses, due mainly to the resource constraints of Bradley’s small physics department. When I joined it, the department had five other faculty members, and the average teaching load was approximately 12 hours per semester. We had (and still have) a rather extensive service course offering because of the large number of en-
COMPUTING IN SCIENCE & ENGINEERING
gineering majors who take introductory physics as part of their engineering curriculum, so adding new computational physics courses was impossible. Even today, our department is unable, due to personnel constraints, to create new courses without negatively affecting the established curriculum. A further challenge to establishing new courses is our department’s emphasis on undergraduate research. In accordance with Bradley’s strategic mission, our department has made a strong effort to increase student involvement in research. As a result, we’ve created a core research group in surface physics (a strong area of emphasis in the Bradley physics department’s expertise), establishing a research infrastructure by acquiring atomic-scale surface sensitive instruments (with the aid of US National Science Foundation funding) and implementing a thriving undergraduate research program. With this emphasis on undergraduate research and the associated teaching load reductions for most of the faculty in the department, it’s impossible for us to add courses specifically in computational physics to our department’s teaching load. Thus, an integrated, incremental approach was and still is the only option available to me for forwarding the cause of computational physics education. The Bradley physics department has supported my interest in adding computational physics to our curriculum by acquiring several computers and creating a computational physics lab for the students in my courses. The availability of reasonably priced, fast PCs has made integrating computations into these courses easier, but perhaps the most compelling reason for working computational physics into my courses was my own curiosity and piqued interest in the subject. In 1995, I adopted the Classical Dynamics of Particles and Systems (4th edition)1 text on classical mechanics for my course. This edition was the first to include a chapter on chaos and nonlinear oscillations. Because of advances in PC technology and availability, it had just become possible to treat and practically study these computational ideas in an academic setting. Although the textbook has a wonderful treatment of chaos, I found that the students still weren’t grasping the material by merely reading the authors’ descriptions of the computations and working the analytical problems at the end of the chapter. Therefore, I learned to do the numerical calculations via computer myself and demonstrate them in class to augment the static presentation in the book. These demonstrations were a great learning experience for me, and I became fascinated with the subject. The fun of programming
SEPTEMBER/OCTOBER 2006
the computations associated with some of the chaotic systems, such as the damped driven pendulum (DDP), and my excitement in studying parameter-dependent behavior and learning to identify chaos overflowed into the classroom. But even with these presentations, the students still didn’t fully comprehend the idea of chaos, which can be an intangible, abstract concept if you haven’t done the calculations directly. Thus, I found the students needed hands-on experience with the computer calculations. The first hurdle was determining an efficient way for them to do their computer calculations. Because they would have to do the computational material incrementally within the confines of the courses, it was necessary to get them into the computations without spending precious class time on computer programming or software instruction.
I eventually abandoned the commercial software approach, mainly because it produced a barrier between the students and the direct calculations. Over the years, I’ve tried two different tools for student computations: • commercially available software with programming capabilities and • direct programming with a relatively high-level programming language. For a long time, I assumed that commercially available scientific software was the best method for student efforts because I assumed that it would prevent the students from becoming bogged down if they had to do the direct programming. However, some of the packages proved difficult to use, and I tried several different ones before I turned to direct programming. I eventually abandoned the commercial software approach, mainly because it produced a barrier between the students and the direct calculations that I deemed necessary for them to learn computational physics methods. In using the commercial software, they found the computer would essentially do much of the thinking for them once they correctly entered, for example, the differential equations that needed to be numerically solved. In effect, they were operating a “computational black
45
box” to do their calculations without really understanding what it was doing. I also suspected that the effort put into learning the commands and syntax of a particular mathematics software program probably wasn’t much less than the workload required to learn to program with a relatively highlevel language such as Fortran. Hence, I believe computational physics is best learned through direct programming. Commercially packaged programs are useful; we make supplemental use of several programs including Interactive Physics, Origin, and IGOR for graphing, fitting, visualization, and so forth. But I believe that direct programming maximizes computational learning and helps students achieve maximum understanding and control in numerically solving equations.
Computational Physics in Classical Mechanics
The Classical Mechanics course I teach is a juniorlevel physics class taken predominantly by physics majors—some engineering, mathematics, and chemistry majors trickle in from time to time, too. The course enrollment is typically eight to 12 students. We study Newton’s laws of motion, linear oscillations, nonlinear oscillations and chaos, classical gravitation, Lagrangian and Hamiltonian dynamics, central force motion, systems of particles, rigid body rotations, rotating reference frames, and coupled oscillations. When I began implementing computational methods into this course, it was solely to introduce topics in chaos and nonlinear oscillations associated with the corresponding chapter in the text. I’ve subsequently expanded the scope to integrate computational topics throughout the course. Much trial and error has gone into the curricular development, so what I describe here is the current state of the program as I’ve developed it over the past 12 years. I include numerical calculations and demonstrations where appropriate in the lectures, and the students do their hands-on computational work in the form of specific computational homework problems. I’ve found Nicholas Giordano’s Computational Physics 2 to be a good resource for computational homework problems. Overall, I assign approximately five to six solely computational assignments during a semester. The students are required to write up the solutions to these assignments as formal reports with at least as much detail as they are required to provide in the solutions to the analytical homework problems. A good starting point for introducing the students to computations is projectile motion with air resistance. We cover a simple velocity-dependent
46
model for the air resistance force, and I ask the students to numerically integrate the first-order differential equations to come up with the dynamic motion. I introduce this topic early in the course to get them into computations right away. Because the students can obtain sufficient accuracy with the simple Euler method, it’s a good exercise to illustrate how the definition of a derivative can be turned into a finite difference equation to accurately solve a first-order differential equation. With this exercise, the students learn the importance of using a sufficiently small time step, the concept of error control, and how to search for artifacts and ensure that their program is calculating correctly. I provide handouts explaining the fundamental Fortran commands needed to do the programming for the projectile. The programming required for this first assignment is sufficiently easy that the handouts are usually enough to get them going. Programming is a completely new concept for some students, so I tutor them one on one outside of course meeting times as necessary. The projectile assignment is a good warm up for the next computational assignment we encounter when we study linear oscillations. By working with their projectile program, the students become familiar with programming basics and debugging— at least the programming proficiency necessary to implement the Euler algorithm. In the linear oscillation assignment, I first require them to use the computer to plot the functions associated with the different solutions of the damped simple harmonic oscillator (SHO). Of course, they can do this type of function plotting on their calculators, but programming it on the computer gives them the most direct control over varying the parameters and keeps them in the programming mode, forcing them to practice and apply their programming skills in a slightly different way. In the same assignment, I then ask the students to program and study the nondamped SHO by numerically solving the differential equation. Because they’ve already solved and studied the SHO in detail analytically, they know what to expect in the behavior of their computer calculation. The Euler method applied to the SHO is notorious for not conserving energy, which usually causes consternation for the students with whom I’ve already stressed the importance of searching for artifacts and error control. I’ve found it instructional (and somewhat entertaining) to let them struggle with this energy artifact by attempting to eradicate it by adjusting the time step, dt, to smaller and smaller values. I only let them struggle long enough for their consternation to serve as a good motivation
COMPUTING IN SCIENCE & ENGINEERING
for learning the Runge-Kutta method and other higher-order methods that save the day for their SHO computational efforts. I introduce the Runge-Kutta method and the concepts behind the Verlet and Gear Predictor-Corrector algorithms, although we don’t typically apply anything more sophisticated than second-order Runge-Kutta. From this point, we study chaos in the DDP. I require the students to program the DDP computation using second-order Runge-Kutta, which typically constitutes a more challenging programming effort. I require them to study the system behavior as a function of different driving torques for a given set of the other physical parameters. Of particular interest is the DDP’s chaotic behavior: thus, I instruct them in the importance of using objective tools for determining when the system of interest has become chaotic. The students learn to produce phase space plots and Poincaré sections and to calculate Lyapunov exponents for some different values of the driving torque. In the DDP assignment, they also study the period-doubling effect that occurs in the transition to chaos in the DDP. The next topic that generates a need for numerical solution is Lagrangian dynamics. It’s somewhat unsatisfying for students to solve complicated mechanical systems with the elegant Lagrangian method only to come up with coupled differential equations, which aren’t solvable analytically and don’t—in and of themselves—convey any insight into the dynamic behavior of the system they represent. After their experience with the DDP, students are equipped to tackle the numerical solution of almost any differential equations describing a dynamical system generated from the Lagrangian formalism. I usually require them to numerically integrate and study the equations of motion of the double pendulum and ask them to study their favorite dynamical system, for which they produce the Lagrangian differential equations of motion (with the stipulation that it can’t be the simple pendulum). Beyond that, the students receive extra credit if they choose a system that displays chaotic behavior and then make a thorough, systematic study of its behavior and transition to chaos. The study of central force motion provides the appropriate arena for numerically studying the two- and three-body problems. In the computational assignments for this topic, I have the students verify Kepler’s laws, study the stability of elliptical orbits in the presence of other large masses, and by trial and error, determine how well their model reproduces the escape velocity of some known mass from the Sun.
SEPTEMBER/OCTOBER 2006
Finally, we revisit projectiles when we get to the chapter on rotating reference frames. The final assignment consists of numerical problems in which the students calculate the trajectories of realistic projectiles with the Coriolis deflection included, plot their results in 3D graphs, and study the effects of changing the various parameters on the deflection distances observed. By the end of their mechanics experience, the students have become pretty good programmers.
Computational Physics in Statistical Mechanics
I’ve taught the Classical Mechanics and Statistical Mechanics courses in sequence since I arrived at Bradley. The obvious benefit to this scheme is that most of the students have already been through the computational physics experience in the Classical
By the end of their mechanics experience, the students have become pretty good programmers. Mechanics course. Because they’ve become reasonably proficient in their programming skills, the second course provides a good opportunity to efficiently extend the students’ computational experience to stochastic computational methods that are fundamentally different from the methods they have learned in Classical Mechanics. In this second course, I cover statistical methods, probability distributions, statistical ensembles, interaction between macroscopic systems, statistical thermodynamics, macroscopic thermodynamics, partition function, classical ideal gases, quantum statistics of ideal gases, magnetism, and selected nonequilibrium topics. Because of the stochastic nature of these concepts, I first direct the students to review the topic of mapping introduced in Chapter 4 of the Marion and Thornton textbook.1 In the subsequent computational assignments, the students will need to program and understand a random number generator, and this mapping and the chaotic behavior of the output is the basis for random number generation. I ask the students to develop and study a linear congruential generator (LCG), which can produce a sequence of random numbers with a relatively large period. Because the students already have experience with studying and identifying chaos, it’s a natural extension of their previous work to understand why the LCG effectively produces random sequences in the chaotic regime. Also, this exercise helps students understand the importance of producing an LCG with a
47
period sufficiently long to not interfere with the time scale of the simulations they’ll program. Over the next few computational assignments, we begin to construct a Monte Carlo (MC) simulation, from simple to more complex. Because this is their first experience with the concept of a simulation, I use class time to elaborate on the differences between simulation and directly integrating deterministic equations. We then cover the basic ideas of the MC method, including the Metropolis algorithm, and I describe how to use it to build up a realistic MC simulation. (A good overview of the Metropolis algorithm appears elsewhere.3,4 )
The simulation the students have built throughout the semester will allow them to directly visualize many of the nonequilibrium topics we cover in the course. The first MC simulation assignment is the relatively easy process of simulating the deposition of metallic atoms onto a cold substrate—“cold” means they stick at their arrival position, and “substrate” means a simple square array of equivalent lattice sites. This assignment essentially requires the students to program the random arrival of atoms at random positions on a square lattice. In addition to being a simple “starter” application of the MC method, this activity allows a detailed study of the Poisson distribution, which is a special case of the binomial distribution they’ve studied analytically. In the next assignment, I ask the students to program a 2D random walk and study all aspects of the resulting dynamical motion. Instead of arriving at random places on a surface, a single atom is now allowed to make uniform hops on a square lattice with equal probability in any of four directions. With this assignment, the students study Gaussian probability distributions, the importance of a large statistical ensemble, the effects of varying the ensemble’s size, and dependence of the distance traveled in both x and y directions on the number of steps taken in detail. Next, the students upgrade the random walk MC simulation to study the structures created during classical diffusion limited aggregation (DLA),5 a phenomenon that applies to aggregation in any system in which diffusion is the primary means of transport. Essentially, DLA means “hit and stick”— that is, the DLA simulation is a hybrid of their two previous simulations involving both random walk-
48
ing between positions and random arrival at positions on a square lattice. The mobility of a randomly walking atom is quenched when it moves to a lattice site that’s adjacent to another atom—thus, it “hits” and “sticks.” This MC simulation is the first time the students are forced to consider the importance of boundaries and use periodic boundary conditions. Aggregation of the atoms in such a simulation produces dendritic structures, so I also have the students calculate the fractal dimension of their growing dendritic DLA structures. Many methods for calculating a fractal dimension exist, but the simple box-counting method is the one the students typically choose. A typical undergraduate physics curriculum traditionally contains little or no introduction to fractals and the concept of noninteger dimensions, so the purpose of this exercise is simply to expose students to an interesting and useful computational technique. The ultimate goal in incrementing the MC simulation’s complexity is to produce a relatively realistic simulation of the atomistic processes that occur at surfaces during epitaxial growth of thin films. During the initial stage of epitaxial growth a vapor of atoms is created in a vacuum near an atomically clean crystalline surface, the atoms arrive at random positions on the surface, move around in somewhat random directions, and become almost immobile when they happen to meet other atoms and form clusters. This thin film growth process contains many aspects of nonequilibrium statistical physics, which is the last subject we cover in the Statistical Mechanics course. The simulation the students have built throughout the semester, once modified to account for a few further atomic-scale processes (part of their last computational assignment), will allow them to directly visualize many of the nonequilibrium topics we cover in the course. One of these nonequilibrium topics is a well-developed analytical theory known as nucleation theory.6 In this formalism, the different atomic-scale processes are modeled with stochastic rate equations. Because epitaxial growth occurs under conditions far from equilibrium, it serves as a prototypical example of an analytical theory used to describe a nonequilibrium system. The rate equations are a set of coupled, nonlinear, first-order differential equations. The final computational assignment is to integrate these equations numerically to determine the behavior of various physical quantities as a function of time during epitaxial growth. The students then append their MC program to realistically simulate the growth under the same conditions and test the theory’s predictions. The numerical
COMPUTING IN SCIENCE & ENGINEERING
integration is relatively easy for the students by now; the required modifications to the MC simulation, however, require a little more effort, but it’s something the students can accomplish in a reasonable amount of time. In the past, I attempted to place on the students more ambitious workloads than those I describe in this article. To coincide with the topic of ideal gases, for example, I tried to have the students program a molecular dynamics (MD) simulation, with simple Lennard-Jones potentials. However, this effort requires too much of the students and can take up far too much time, although a few enterprisingly astute students in the past have taken up the challenge. The MD programs I developed (with these adventurous students) serve as good simulational demonstrations wherein, for example, we can directly visualize the connection between microscopic states and macroscopic observables. Because the students have become familiar with numerical integration by this time, and because MD is similar to the three-body gravitational problem they calculated in their mechanics course, they have an appreciation of what the MD simulation is doing even though they haven’t done the programming directly themselves. I’ve also had the students program an MC simulation of the 2D Ising model during our foray into magnetism; it’s a straightforward extension of the MC simulation they’ve built throughout the semester. Because of the course’s time constraints, lately I’ve only used the Ising simulations as class demonstrations to illustrate the qualitative aspects of ferromagnetic phase transitions. Again, the students have a good sense of what the Ising model program is doing as they have built up experience with their own MC simulations. One other motivating factor for introducing the Ising model is that Ernst Ising (the model’s creator) taught at Bradley University from 1948 to 1976, after which he was professor emeritus in the department until he passed away in 1998. The Ising model is thus a topic of historical pride in our department!
Difficulties and Advantages
One obvious drawback of integrating computational physics into the traditional format of physics courses is it’s potential interference with the course’s core subject matter. To avoid this, I try to keep the class time required for the programming and computational training to a minimum, but invariably these tasks take up more class time than planned. The pressure to get through everything we need to in the course builds and can only be relieved by providing cursory coverage of some of the
SEPTEMBER/OCTOBER 2006
topics and relying on students to read and study the subject on their own. Depending on how important you believe it is to introduce undergraduates to computational physics techniques somewhere in the undergraduate curriculum, this might or might not be a big price to pay. Another possible mechanism for relieving the time pressure is to increase the number of semester hours for each course from three to four. This might have a small impact on the students’ curricula, but it would make a big difference in providing sufficient time for integrating relevant computa-
Intertwining computations with the analytical treatment induces the students to be inquisitive and linger in studying systems they wouldn’t otherwise have had access to. tional techniques while completely covering all the canonical topics. Adding another semester hour in these courses could be a profitable maneuver, especially if it’s only in these courses where the students receive formal training in computational physics principles. Another obvious disadvantage of this method is requiring the students to learn a programming language. The direct programming approach worked smoothly for me in the past because the students had programming experience. As recently as five years ago, nearly every student in my mechanics course could program at least somewhat proficiently in Fortran, Basic, or C. However, as of late, it’s the rare student who can program. Perhaps one cause is the different emphasis computer science departments have placed on their introductory courses. Contemporary introductory computer science seems to focus on teaching operating systems and applications, and any emphasis on scientific programming appears to have vanished. For example, Bradley’s introductory class for Fortran (for years a required class for our physics majors) has been disbanded, and the introduction to C and C++ programming course, which at one time involved some component of scientific programming, has been retooled into something that would be unrecognizable to the scientific computing community. Some courses still offer instruction in Fortran, but it’s tucked in with other irrelevant topics and languages in the upper-level computer science offerings.
49
Thus, I’ve had to do the necessary programming training myself. For the most part, I’ve been able to teach the necessary programming through handouts and references I make available in the computer labs. Fortunately, the programming necessary to perform the computational assignments, at least initially, isn’t that sophisticated. But for those enrolling in these courses who have no previous programming experience, it requires a high level of dedication on the part of student and professor alike to make the computational experience work if it’s to be done via direct programming. I still believe that the direct programming approach is a less painful experience than instructing the students to use a particular software package with its unique set of commands and syntax. Plus, it gives students a level of control that they can’t achieve or even understand via merely “operating” software. An advantage of this approach to teaching computational physics is embedded inherently in the format itself. This approach is effective because I teach the computational techniques and topics in their natural habitat—that is, as routes to further understanding that are intimately connected to the specific physics topic we’re covering. In this sense, the computational techniques don’t constitute a separate field of physics; they comprise a set of
tools that are useful for studying and solving the particular problems that naturally arise in response to the need to go beyond the limitations of analytical techniques. Moreover, I think this approach gives students a break from the traditional aspects of all their other courses. Intertwining computations with the analytical treatment induces the students to be inquisitive and linger in studying systems they wouldn’t otherwise have had access to. In this way, I think they experience a refreshing departure from routine analytical work.
O
f course, experiences at other, larger physics departments have demonstrated that students can effectively learn computational physics in specific programs and courses. In such situations, instructors can spend more time driving home principles and cover many more and various topics. However, I believe that I’ve stumbled onto a way of injecting computational physics education into the undergraduate physics curriculum that can be just as effective as a complete program of study or separate course.
Acknowledgments I thank John Sathoff, Conley Stutz, and Doug Early for professional support and enthusiastic encouragement in the early days of implementing this approach to teaching our students the ways of physics computations, and James Craig Jr. for the same in recent years.
References 1. J.B. Marion and S.T. Thornton, Classical Dynamics of Particles and Systems, 4th ed., Harcourt Brace College Publishers, 1995. 2. N.J. Giordano, Computational Physics, Prentice-Hall, 1997. 3. B.A. Berg, Markov Chain Monte Carlo Simulations and Their Statistical Analysis, World Scientific, 2004.
Stay on Track IEEE Internet Computing reports emerging tools, technologies, and applications implemented through the Internet to support a worldwide computing environment.
www.computer.org/internet/ 50
4. S. Chib and E. Greenberg, “Understanding the Metropolis–Hastings Algorithm,” Am. Statistician, vol. 49, no. 4, 1995, pp. 327–335. 5. A. Witten Jr. and L.M. Sander, “Diffusion-Limited Aggregation, a Kinetic Critical Phenomenon,” Physical Rev. Letters, vol. 47, no. 19, 1981, pp. 1400–1403. 6. T. Michely and J. Krug, Islands, Mounds, and Atoms: Patterns and Processes in Crystal Growth Far from Equilibrium, Springer-Verlag, 2004, pp. 25–41.
Kelly R. Roos is an associate professor in the Department of Physics at Bradley University. His research interests are in experimental surface science but include computational modeling with Monte Carlo and molecular dynamics simulations. Roos has a PhD in condensed matter physics from Iowa State University. Contact him at rooster@ bradley.edu.
COMPUTING IN SCIENCE & ENGINEERING