This document provides an overview of a textbook on computational physics. It introduces computational basics and various computational tools and methods used in physics simulations. These include programming basics, numerical analysis techniques like integration, differentiation, solving differential equations, and Monte Carlo methods. It also covers object-oriented programming, matrix computations, Fourier analysis, wavelets, nonlinear dynamics, fractals, and statistical modeling. The textbook aims to provide students the computational skills needed for modeling and simulation in physics.
How libraries can support authors with open access requirements for UKRI fund...
A Survey Of Computational Physics Introductory Computational Science
1. A Survey of
Computational Physics
Introductory Computational Science
Rubin H. Landau
Manuel Jose Paez
Cristian C. Bordeianu
PRINCETON UNIVERSITY PRESS • PRINCETON AND OXFORD
2. CONTENTS
Preface xxiii
Computational Science Basics 1
1.1 Computational Physics and Science l
1.2 How to Read and Use This Book 3
1.3 Making Computers Obey; Languages (Theory) 6
1.4 Programming Warmup 8
1.4.1 Structured Program Design 10
1.4.2 Shells, Editors, and Execution 11
1.4.3 Java I/O, Scanner Class with printf 12
1.4.4 I/O Redirection 12
1.4.5 Command-Line Input 13
1.4.6 I/O Exceptions: FileCatchThrowJava 14
1.4.7 Automatic Code Documentation o 16
1.5 Computer Number Representations (Theory) 17
1.5.1 IEEE Floating-Point Numbers 18
1.5.2 Over/Underflows Exercises 24
1.5.3 Machine Precision (Model) 25
1.5.4 Determine Your Machine Precision 27
1.6 Problem: Summing Series 27
1.6.1 Numerical Summation (Method) 28
1.6.2 Implementation and Assessment 29
Errors & Uncertainties in Computations 30
2.1 Types of Errors (Theory) 30
2.1.1 Model for Disaster: Subtractive Cancellation 32
2.1.2 Subtractive Cancellation Exercises 33
2.1.3 Round-off Error in a Single Step 34
2.1.4 Round-off Error Accumulation After Many Steps 35
2.2 Errors in Spherical Bessel Functions (Problem) 36
2.2.1 Numerical Recursion Relations (Method) 36
2.2.2 Implementation and Assessment: Recursion Relations 38
11. xvi contents
14.15,2 Exercise 2: Cache Flow 387
14,15,3Exercise 3: Large-Matrix Multiplication 388
15 Thermodynamic Simulations & Feynman
Quantum Path Integration 390
15.1 Unit I. Magnets via the Metropolis Algorithm 390
15.2 An Ising Chain (Model) 390
15.3 Statistical Mechanics (Theory) 393
15,3,1 Analytic Solutions 393
15.4 Metropolis Algorithm 394
15.4.1 Metropolis Algorithm Implementation 397
15.4.2 Equilibration, Thermodynamic Properties (Assessment) 397
15.4.3 Beyond Nearest Neighbors and 1-D (Exploration) 400
15.5 Unit II. Magnets via Wang-Landau Sampling o 400
15.6 Wang-Landau Sampling 403
15.6.1 WLS Ising Model Implementation 405
15.6.2 WLS Ising Model Assessment 408
15.7 Unit III. Feynman Path Integrals 0 408
15.8 Feynman's Space-Time Propagation (Theory) 408
15.8.1 Bound-State Wave Function (Theory) 412
15.8.2 Lattice Path Integration (Algorithm) 413
15.8.3 Lattice Implementation 418
15.8.4 Assessment and Exploration 420
15.9 Exploration: Quantum Bouncer's Paths 0 421
16 Simulating Matter with Molecular Dynamics 424
16.1 Molecular Dynamics (Theory) 424
16.1.1 Connection to Thermodynamic Variables 428
16.1.2 Setting Initial Velocity Distribution 429
16.1.3 Periodic Boundary Conditions and Potential Cutoff 429
16.2 Verlet and Velocity-Verlet Algorithms 431
16.3 1 -D Implementation and Exercise 432
16.4 Trajectory Analysis 435
16.5 Quiz ' 436
17 PDEs for Electrostatics & Heat Flow 437
17.1 PDE Generalities 437
17.2 Unit I. Electrostatic Potentials 439
17.2.1 Laplace's Elliptic PDE (Theory) 439
12. contents xvii
17.3 Fourier Series Solution of a PDE 440
17.3.1 Polynomial Expansion As an Algorithm 442
17.4 Solution: Finite-Difference Method 443
17.4.1 Relaxation and Overrelaxation 445
17.4.2 Lattice PDE Implementation 446
17.5 Assessment via Surface Plot 447
17.6 Alternate Capacitor Problems 448
17.7 Implementation and Assessment 450
17.8 Electric Field Visualization (Exploration) 452
17.9 Laplace Quiz 452
17.10 Unit II. Finite-Element Method 0 453
17.11 Electric Field from Charge Density (Problem) 454
17.12 Analytic Solution 454
17.13 Finite-Element (Not Difference) Methods 455
17.13.1 Weak Form of PDE 455
17,13.2Galerkin Spectral Decomposition 456
17.14 FEM Implementation and Exercises 460
17.15 Exploration 463
17.16 Unit III. Heat Flow via Time-Stepping
(Leapfrogging) 463
17.17 The Parabolic Heat Equation (Theory) 463
17.17.1 Solution: Analytic Expansion 465
17.17.2Solution: Time-Stepping 466
17.17.3 Von Neumann Stability Assessment 468
17.17.4Heat Equation Implementation 470
17.18 Assessment and Visualization 470
17.19 Improved Heat Flow: Crank-Nicolson Method 472
17.19.1 Solution of Tridiagonal Matrix Equations 0 474
17.19.2Crank-Nicolson Method Implementation
and Assessment 476
18 PDE Waves: String, Quantum Packet, and E&M 478
18.1 Unit I. Vibrating String 478
18.2 The Hyperbolic Wave Equation (Theory) 478
18.2.1 Solution via Normal-Mode Expansion 480
18.2.2 Algorithm: Time-Stepping 481
18.2.3 Wave Equation Implementation 483
18.2.4 Assessment and Exploration 484
18.3 Waves with Friction (Extension) 486
13. xviii contents
18.4 Waves for Variable Tension and Density
(Extension) 487
18.4.1 Waves on a Catenary 488
18.4.2 Derivation of a Catenary Shape 488
18,4,3 Catenary and Frictional Wave Exercises 490
18.5 Unit II. Quantum Wave Packets 491
18.6 Time-Dependent Schrddinger Equation (Theory) 492
18.6.1 Finite-Difference Algorithm 493
18.6.2 Wave Packet Implementation and Animation 494
18.7 Wave Packets in Other Wells (Exploration) 496
18.8 Algorithm for the 2-D Schrddinger Equation 496
18.9 Unit III. E&M Waves via Finite-Difference
Time Domain 0 499
18.10 Maxwell's Equations 499
18.11 FDTD Algorithm 500
18.11.1 Implementation 503
18.11.2 Assessment 504
18.11.3 Extension: Circularly Polarized EM Waves 506
19 Solitons & Computational Fluid Dynamics 508
19.1 Unit I. Advection, Shocks, and Russell's Soliton 508
19.2 Theory: Continuity and Advection Equations 509
19.2.1 Advection Implementation 510
19.3 Theory: Shock Waves via Burgers' Equation 510
19.3.1 Algorithm: The Lax-Wendroff Method for Burgers'
Equation 511
19.3.2 Implementation and Assessment of Burgers' Shock
Equation 513
19.4 Including Dispersion 514
19.5 Shallow-Water Solitons, the KdeV Equation 515
19.5.1 Analytic Soliton Solution 517
19.5.2 Algorithm for KdeV Solitons 518
19.5.3 Implementation: KdeV Solitons 519
19.5.4 Exploration: Solitons in Phase Space'and Crossing 520
19.6 Unit II. River Hydrodynamics 521
19.7 Hydrodynamics, the Navier-Stokes
Equation (Theory) 521
19.7.1 Boundary Conditions for Parallel Plates 524
19.7.2 Analytic Solution for Parallel Plates 526
14. contents • xix
19.7.3 Finite-Difference Algorithm and Overrelaxation 527
19.7.4 Successive Overrelaxation Implementation 529
19.8 2-D Flow over a Beam 530
19.9 Theory: Vorticity Form of the Navier-Stokes
Equation 530
19.9.1 Finite Differences and the SOR Algorithm 532
19.9.2 Boundary Conditions for a Beam 534
19.9.3 SOR on a Grid Implementation 536
19.9.4 Assessment 538
19.9.5 Exploration 539
20 Integral Equations in Quantum Mechanics 540
20.1 Unit I. Bound States of Nonlocal Potentials 540
20.2 Momentum-Space Schrddinger Equation (Theory) 541
20.2.1 Integral to Linear Equations (Method) 542
20.2.2 Delta-Shell Potential (Model) 544
20.2.3 Binding Energies Implementation 544
20.2.4 Wave Function (Exploration) 546
20.3 Unit II. Nonlocal Potential Scattering 0 546
20.4 Lippmann-Schwinger Equation (Theory) 547
20.4.1 Singular Integrals (Math) 548
20.4.2 Numerical Principal Values 549
20.4.3 Reducing Integral Equations to Matrix-Equations
(Algorithm) 549
20.4.4 Solution via Inversion or Elimination 551
20.4.5 Scattering Implementation 552
20.4.6 Scattering Wave Function (Exploration) 553
Appendix A: Glossary 555
Appendix B: Installing Packages 562
B.I Installing Java Developer's Kit 564
B.2 Using Classes and Packages 565
B.2,1 Including Packages '. 565
Appendix C: OpenDX: Industrial-Strength Data
Visualization 568
C.I Getting DX and Unix Running (for Windows) 569
C.2 Test Drive of DX Visual Programming 569
15. xx . contents
C.3 DX Tools Summary 576
C.4 DX Data Structure and Storage 577
C.5 Sample Visual Programs 579
C.5.1 Sample 1: Linear Plot 579
C.5.2 Sample 2: Fourier Transform 580
C.5.3 Sample 3: Potential of a 2-D Capacitor 580
C.5.4 Sample 4: Vector Field Plots 581
C.5.5 Sample 5: 3-D Scalar Potentials 582
C.5.6 Sample 6: 3-D Functions, the Hydrogen Atom 585
C.6 Animations with OpenDX 586
C.6.1 Scripted Animation with OpenDX 588
C.6.2 Wave Packet and Slit Animation 591
Appendix D: An MPI Tutorial 593
D.I Running on a Beowulf 593
D.2 Running MPI 597
D.2.1 MPI under the SGE Queueing System 598
D.2.2 MPI Under the Torque/PBS Queueing System 600
D.2.3 Running Parallel Jobs with Torque 602
D.3 Your First MPI Program: MPIhello.c 604
D.3.1 MPIhello.c Explained 605
D.3.2 Send/Receive Messages: MPImessage2,c 606
D.3.3 Receive More Messages: MPImessage3.c 608
D.3.4 Broadcast Messages 609
D.3.5 Exercise 610
D.4 Parallel Tuning 611
D.5 A String Vibrating in Parallel 614
D.5.1 MPIstring.c Exercise 617
D.6 Deadlock 618
D.6.1 Nonblocking Communication 619
D.6.2 Collective Communication 619
D.7 Bootable Cluster CD 0 620
D.8 Parallel Computing Exercises 620
D.9 List of MPI Commands < 621
Appendix E: Calling LAPACK from C 623
E.I Calling LAPACK Fortran from C 624
E.2 Compiling C Programs with Fortran Calls 625
16. contents xxi
Appendix F: Software on the CD 626
Appendix G: Compression via DWT
with Thresholding 635
G.I More on Thresholding 637
G.2 Wavelet Implementation and Assessment 638
Bibliography 641
Index 651