COM IONAL PHYSICS Fortran V&on
This page intentionally left blank
COMPUTAT S Version
Professor of Theoretical Physics Calvomziainstitute of Rchmlogy
Dawn C. Meredith Assistant Professor of Physics Univmsity of New Ham-pshire
'
A Member of the I'erseus Books Group
L
This book was tmtsset by Elkabeth K, Wmd ushg the 'Q@ &xt-processingsyskm running on a Bigibl Equipment Gomodion n 2@m cornpuk~Camera-read~f i i d COPY ww produced on an Appb WerWrikr. FoElswing is a list ofbadernsks used in tke book: V M , VMsMion, W S , W axe &&emaks af Bi@MEquipment Copoaion.
UES, HCFJIS*** CA-DISSPM is a &&emmk of Computer boci-s In&rn&iond,Enc. W= is a bdernmk ofAT&T. XBM-PC is a. W e m m k of Xnteraliond Bushess Mitchhes, MackWsh is a Wademmk of Apple Compukr,Inc, %Won& 4010 iisla &demwk of%k&anix Enc. GO-235 isa mdentak af Graphon Copomtion. WDS3200 is a trdemwk of Humizn Dwiped Sys&ms. %X is a trMemwk of the A m e ~ c mMahernaied Society. PST is a Wemask sf Mme Computers,Enc. Kermit Isa Mexnwk af Wdt Bisnq &oduc:tiox1s, S;mis a r e g b k ~ d of SW Mcrasp&ms,Inc.
Koonin, Skven E. version) I SWen E. Koonb, Dawn Nereditk. p. cm. Includes index. 3.
physie+D@ processing, 2. Physic+Computer p r a g m s , puter program lmguage) 4. Nume~calmalysis. I, Meredith, Dawn,
IE. Title, Q620.XE4K66 1 M 530.1"W02855133-d~L9 ISBN 0-201-X 2774-2 ( h ~ d ~ ~ e r )
90-129
ISBN 0-201-38623-2 [pperback)
Copyight 8199l)byWestviecvPress, a member of the Per~eusBooks Group All rim& resemed. No part of this text publiatjon may be reproduced, stored in a reeied system,or kansmitbd, in my fom or by my me=, ekc&anic,mechicat, phoacopyhg, recordhg, or o t h e m h , wigbout the prior Wtten permimion of the publisher. Prinkb in the Unikd S b k s ofbefica. Prxblhfied simulkneouslyin CmiltZa, 1 0 9 8 ' 7 6 5 4
Preface
Computation is an integral part of modern science and the ability to exploit effectively the power offered by computers is therefore essential to a working physicist. The proper application of a computer to modeling physical systems is far more than blind "number crunching," and the successful computational physicist draws on a bdanced mix of analytically soluble examples, physicd intuition, and numerical work to solve problems that x e otherwige intractable. Unfortunately, the ability "to computen is seldom cultivated by the stmdard zrniwrsity-level physics crtrri culum, as it requires an inteaation of three disciplines (physics, numerical analysis, and computer programming) covered in disjoint courses. Few physics students finish their undergraduate education knowing how to compute; those that do usually leara a L i ~ t e dget of techniques in the coufse of independent work, such as a research projed or a senior thesis. The materid in. this book is ~ m e d r e f i ~ n geomputationd sEns in advanced undergraduate ar be@nning graduate students by providixrg experimce in using a computer to model physical systems. Its s q e includes the minimam set of numerical techaiques needed to od"' physics" on a mmputer. Each of these is developed In the text, often hmristicdy, and is then applied t o solve non-trivial problems in classical, qnantum, and statisticd physics, The= latter have been chosen to enrich or a t e n d the standard undergraduate physics curriculum, and so haw considerable intrinsic interest, quite independent of the computationd principles they illustrate, This book should not be thought of as setting out a rigid or definitive curriculum. I have restricted its scope to calculations that satisfy simultaneously the criteria of illustrating a widely applicable numerical technique, of being tractable on a microcomputer, and of having some parhicalm physics interest. Several import ant numeric& techniques have therefore been o ~ t t e dspEae , iaterpdatim asld the F a t Fburier Transform among them. Computational Physics is perhaps best thought of as establishing m environment rer ring opportunities for further eqloration. There are =my possible extensions and embelEshmerrts of the materid prescjnted; using mevs iana&nation dong these liaw is one of the mom rewwding parts of working through the book.
C"omp.utat%'onal Pltysz'cb?is primwily a physics text, For xnknrum benefit, the student should have taken, or be taking, undergraduate courses in dwsical meclzanic~,quantum mechanics, stat;jstical mechmics, and advanced cafculus m the mathematical methods of physics. Tbis is slot a text on aurnerical analysis, as there hahs been no attempt at rigor or completeness in any of the expositions of numerical techniques. However, a prior course in that subject is probabb not essential; the discussions of numerical techniques should be accessible to a student with the physics background outlined above, perhaps with gome reference to any one of the excellent texts on numerical andysis (for example, [AC~O], [Bu81], or [Sh84]). This is dso not a text on computer programming. AIthough I have tried to follow the principles of good programming throughout (see Appendix B), there has been no attempt to teach programming per se. Indeed, techniques for organizing and writing code are somewhat peripheral to the main gods of the book. Some familiarity with programming, at least to the extent of a one-semester introductory course in any of the standard high-level languages (BASIC, FORTRAN, PASCAL, C), is therefore essentid. The choice of language invariably invokes strong feelings among scientists who use computers. Any language is, after d,only a mews of expressing the concqts underlying a program. The contents of this book are therefore rdevant no m&ter what lanpae;e one vvorfis in. However, some laneage had to be elrosen to implement the programs, and I have selected the Microsoft dialect of BASIC standard on the IBM PC/XT/AT computers for this purpose. The BASIC language has many well-known deficiencies, foremost among them being a lack of local subroutine variables and an awkwardness in expressing structured code. Nevertheless, I believe that these are more than balanced by the simplicity of the language and the widespread ftuency in it, BASIC'S almost universal avdability on the microcomputers most likely to be used with this book, the existence of both BASIC interpreters convenient for writing and debugging programs and of compilers for producing rapidly executing finished programs, and the powerful graphics and I/O statements in this language. I expect that readers familiar with some other high-level language can learn enough BASIC "on the Ay'' to be able to use this book. A synopsis of the language is contained in Appendix A to help in this regard, and further information can be found in readily available manuds. The reader may, of course, elect to write the programs suggested in the text in any convenient 1anguag;e. This book arose out of the Advanced Computational Physics Laboratory taught to third- and fourth-year undergraduate Physics majors
at Csiltech during the Winter m d Spring of 1984, The content ilnd presentation have benefitted grea;t.ly fram the many inspired suggestims af M,-C. Chtt, V. PGnisc11, R. WiUiarns, md D. Meredith. Mrs. Mereditb wads also af great wsistance in producing the find fom of the mannscript and programs. I. also wish to thank my wife, Laarie, ibr her extraordinary galienct;, anderstanang, and support during my twa-year involvemeat in this project.
This page intentionally left blank
Preface to the FOR
Edition
At the request of the readers of the BASIC edition of Computational Physics we offer this FORTRAN version. Although we stand by our original choice of BASIC for the reasons cited in the preface t o the BASIC edition it is dear that many of our readers strongly prefer FORTRAN, and so we gladly oblige. The text of the book is essentially unchanged, but ofthe codes haw been trmslated into standard FQRTRAN-7had will run (with some modification) on a variety of machines. Although the programs will run significmtly faster on mainframe computers than on PC%$we have not increased the mope or complegty af the calculations. Resdts, therefore, are still produced in "red time'" and the codes r e m ~ n . suitable for interactive use, Another development since the BASIC edition is the publication of an excellent new text on numerical analysis (Nclmerical Recipes [Pr86]) which providecs detajled discussions md code for state-of-th-at dgorithms. We highly recommend it as a compaaion to this text. The FORTRAN versions of the code were written with the help of T.Berke (who designed the menu), G . Buzzell, and J. Parley. We have also profited from the suggestions of many colleagues who have generously tested the new codes or pointed out errors in the BASIC edition, VVe gratefully acknowledge a grant from the University of New Hampshire DIS Covery Computer Aided Instruction Program which provided the initial impetus for the translation. Lastly, our thanks go to E. Wood for typesetting the text in T&jX.
Stevetn E Koonz'n
Pasadeaa, CA August, 1989
Dawn C. 1Medith Durham, NE
This page intentionally left blank
How to Use This Book
This book is organized into chapters, each containing a text section, an example, and a project. Each text section is a brief discussion of one or several related numerical techniques, often illustrated with simple mathematical examples. Throughout the text are a number of exercises, in which the student's understanding of the material is solidified or extended by an andyticd derivation or through the writing and rnnning of a simple program. These exercises are indicated by the symbol m. Also located throughout the text are tables of numerical errors. Note that the values listed in t h a e tables w r e taken from runs udng BASIC code on an IBM-PC. When the machine precision dominates the error, your values obtained with FORTRAN code may diger. The example and project in each chqter are applications of the numericd techniques to particular physical problems. Each includes a brid expmition of Ihe physics, f~llowedby a discussim of how the numericd techniques are "c be applied, The examples and projects diRer mly in that the student is expected to use (and perhaps modify) the program that is @ven for the forxner in Appendix B, while the book provides &uidanee in writing progrms to treizt the latter through a series of steps, dso indicated by the symbol m. However, programs for the projiects have dso b e n included in Appendk C; these can swve as models far the student's o m p r o g r a or as a means of investigating the physics without having to write a major progrm "from ~cratch",A number of susetated studies &ccompany each example and project; these guide the student in exploiting the programs and understanding the physical principles and numerical techniques invdved. The progFrams for b d h the examples and projects are avdfable either sver the Internet network or on diskedtes. Appendix E: describes how to obtain files over the network; &ernativdy, there is aa order form in the back of the book .far IBM-PC or Macintosh formatted diskettes. The codes are suitable for running on any computer that h a a FORTRAM77 standard compiler. (The IBM BASIC versions of the code are also available over the network.) Detailed instructions for revising and running the codes are @venin Appendix A. A "laboratory" format has proved to be one effective mode of presenting this material in a university setting. Students are quite able to
zii
Rout to U@emis Book
m k throagh the text on their w n , with the instmctor being a v d 1 d e for consultation and to monitor prosess t;Broup;h brief personat interviews on each chapter. Three chaptens in teen weeks (60 hours) af instruction has proved to be a reasonal>le pace, with students typicdy writing two
of the p r o j ~ t sduring this time, and usiag the "cmned" codes t s work through the physics of the remaining project a~ndthe examples. The dgkrt chapters in this book should therefore be more than sufficient for a one-semester course. Alterrr;n;tively,this book em be nsed ta provide supplementary material far the usud m r s e s in cla@icat,quantum, and statisticd mechanics. Many of the examples and proJects are vivid ill=tratims of basic concepts in these subjects and are therefore suitable for clasgroom dennonstratims os independeIll study.
Contents
Preface, u
Preface Lia the FORTRAN Editiaa, iz Haw to use this baak, zi Chapter 1: Basic Mathematical Operations, 1 2 -1 Numerical diEerentiatioa, 2 1.2 Nnnterieal quadratwe, 6 1.3 Finding roots, 11 1.4 Sernidz~ssicdquantiz-atioa of molecular vibrations, Project I: Scattering by a central potential, &O
14
Chapter 2: Ordinary DiEerential Equations, 25 2.1 Simple methods, 26 2.2 Multistep and impEcit method@,89 2.3 Range-Kutta methods, $2 2.4 StabiEdy, $4 2.5 Order and chaos in. two-disniensiand zndion, $7 Project 11: The stmcture of white dwmf s t a s , 46 11.1 The equations of eqailibrium, 46 11.2 The equation of state, 47 11.3 S e d i ~ gthe equations, 50 B.4 Solving the equalians, 51
Chapter 3: Boundary Value and Eigenvalue Prablems, 55
3*1 The Numerov dgorithm, 56 3.2 Direct intepatian of boundav value problems, 57 3.3 Green" function solution of boundary value problems, 61 3.4 Eigenvalues of the wave equ;t;tion, 64 3.5 Stittioaary solutions of the one-dimensional Schroedinger equ* tion, 67
ziu
Contends
Project 111: Atomic structure in the Martree-Fa& approximation, Y23 f 11.1. Basis af the Hartre@Fock approximation, 72 IfI,2 The tw-electron problem, 75 112.3 Many-electron systems, 78 If 1.4 S~Ivingthe equations, 80 Chapter 4: Special Functions and Gausshn Quadrature, 85 4.1 Specid funcZlion~,85 4.2 Gaussian quadrature, 9b 4.3 Born and eiXcond qproSrnadions ta quantum scattering, 96 Project IV: Partial wave solution of quantum scattering, 108 IV.1 Partial wave decomposition of the wave function, 109 IV.2 Finding the phase shifes, 104 IV.3 Sdving the equations, 1135
Chapter 5: Matrix Operations, 109 5.1 M;xtrix inversion, 109 5.2 Eigenvalues of a tri-diagonal matrix, 11 2 5.3 &duction to tri-diagond fom, f L5 5.4 Determining nudear charge densities, Id0 Project V: A schematic shell model, 188 V.1 Definition of the model, 184 KZ The exact dgenstates, 196 V.3 Approximat;e eigenstates, 158 V.4 Solving the model, 149
Chapter 6: Elliptic Partial Differential Equations, 145 6.1 Disercdizatian and the varizttiond principle, 24 7 6.2 An idesstiw method for boundav value problems, 151 6.3 More on, discretizatio~,1155 6.4 Elliptic equations in two dimensions, 157 Project VI: Steady-state hydrodynamics in two dimensions, 158 VI.l The equations and their diseretization, 159 VI.2 Boundary conditions, f 68 VI.3 Solving the equations, 166
Chapter 7: Pwrabofie Partial DiEerenlial Eqaatiarzs, 169 7.1 Naive discretiz;ztion and instabilities, l69 7.2 Impficit schemes m d the inversion of tri-diagond matrices, 174 "7.3 DiRusion and boundary value problems in tw dimensians, 179 7.4 Iterative methods for eigenvdue problems, 181 7.5 he time-dependent Schroedinger equation, 186 Prdect VXI: Self-osganizaeion in chemical. rextions, 189 V11.1 Descriptiolz of the model, I89 V"11.2 Lillear st abi2ity andysis, 191 VE.3 Nun2erirzd solution of the model, r"$d Chapter 8: Monte Carto Methods, 197 8.1 The basic Mmte Carlo strategy, 198 8.2 Generating random. variables with a spedfied &&ribation, 205 8.3 The algorithm of Metropolis et al., 210 8.4 The Isiag model in two dimensions, 215 Project VIIZ: Quantum Mm& Cado for the H2mdecule, 221 VIII.1 St&ement of the problem, 231 VIII.2 Variational Monte Carlo and the trial wave function, 288 VIII.3 Monte Carlo evaluation of the exact energy, $85 VXII.4 Solving the problem, 229
Appendix A: How to use the programs, 231 AI Insfaflation, 231 A.2 Files, $32 A.3 CompiZatian, 233 A.4 Execution, 635 A5 Graphics, L97 A.6 P r w ~ a mStructure, $88 A.7 Menu Structure, 259 A.8 Default Value Revision, 241 Appendix B: Programs for the Examples, 849 B,l Example 1, 243 B.2 Exanlplc 2, 256 B.3 Exa~nple3, $73 B.$ Exampks 4, 295 B.5 Exan113le 5, 316 B.6 Exan3ple G, $89
B.7 Example 7, 370 B.8 Example 8, 991
Appendix C: Programs far the Projects, C.1 Project I, 409 6.2 Project If, 421 C.3 Project XII, 4914 C.4 Project W , 454 6.5 Project V, $W C.6 Project, VX, 494 C.7 Project VII, 580 C.8 Project VIfI, @S
Appendix D: Cornman UGilif;y Code@,567 D.1 Standardization Code, 567 D.2 Hardware and Compiler Specific Code, 570 D.3 General Input/oatpu%Codes, 574 D.4 Graphics Codes, 598 Appendix E: NeLwork Fife =ans&r, 681
Index, 631"
The problem with computers is that they only give answers -attributed do P. Picasso
Chapter I
Basic Mathematics Operations Three numerical operations -- differentiation, quadrature, and the finding of roots -are central to mhst computer modeling of physical systems. Suppose that we have the ability to calculate the value of a function, f ( s ) , at any value of the independent variable z. In digerentiation, we seek one of the derivatives of f at a given value of x. Quadrature, roughly the inverse of differentiation, requires us to calculate the definite integral off between two specified limits (we reserve the term "integration" for the process of solving ordinary differential equations, as discussed in Chapter 21, while in root finding we seek the d u e s of s (there may be several) at which f vanishes, If f is knourn mafyticatly, it is almost always possible, with fortitude, to derive expEcit formulas for the defivatives of f , aad it is aften possible t s do so for its degnite integal as well. However, it is often the ease that an m d y t i d method cannot be used, even though pife cm evaluate f (S)itself. This might be either because some very complicated numerid procedure is rquired to e d u a t e f and we have no suitable analytical formula upon which to apply the rules of digerentiation and quadraturn, or, even worse, because the wily we can. generate f provides ns with its values at only a set; of discrete abseissm, In these situations, we must employ qpro&m&e form&% expressing the derjvatives and integrd in terms of the values of f we can compnte. Moreover, the root8 of 41 but the simplest functions cannot be found anatyticdly, and nuzrrericd methods are therefore essentialt. This chapter dealfs d t h the computer redigation of these three basic operations. The centrd technique is to appradmate f by a simple function (such as first- or second-degree polynomial) upon which these
ensue
2
2. Basic Mathematical Qpervrdians
Figure 3.1 W u e s of f on an equdEy-spud ladtice. Dmhed lines how the hear interpslalion.
operaLioas caa be performed easily, We will derive only the Simpleet and mo& commonly used fomdas; fufbr treatments can be h n d in many textbooks an nmericd andysis.
1.l Numerical diEerentiatiolz Let us suppose that we we interested in the derivative at z = 0, f'(0). (The formulas we will derive can be generalized simply to arbitrary z by translation.) Let us also suppose that we know f on an equally-spaced lattice of z vdnes,
and that our god is to compute an approximate value of fE(0)in terms of the f, (see Figure 1.1). We begin by using a Taylor series to expand f in the neighborhood
whem all derimtives are evduated at z = 0. It is then simple to verify that
where O(h4) means terms of order h4 or higher. To estimate the size of such terns, we c m assume that J and its derivatives are aJ1 of the same order of magnitude, as is the case for many functions of physical rdemnee. from f i as given by (1.2a), we find, after a Upon subtracting sEght rcjarrangea;lc?n%,
'
The term involving f f N vanishes as h becomes small and is the dominant error associat;ecl with the finige dfference q p r o ~ m i t t i mthat Tetijtin~mly the f i r ~ term: t This "%point" formula would be exact if f were a second-deetje poly~omid in the 3-point interval [-h, +h], because the third- and all higherorder derivatives would then vanish. Hence, the essence of Eq. (1.3b) is the assannptian that a quadratic p o l y n o ~ dinticrrpolatiofi of f throu& the thrw points z = &h, O i s v&d. Equation (1.3b) is a very naturd result, reminiscent of the formulas used to define the derivative in elementary calculus. The error term (of order h2)can, in principle, be made as small as is desired by using s m d e r and smder d u e s of h. Note also that the 8ynmetric difirence about z = O is used, as it is more aecurate (by one order in h) than the forward or badward CliRerenm form~las:
These "2-pointw formulas are based on the assumption that f i s well agproSma2ed by a fineas fanctian over the intervds between z = O and z = &h* As a concrete example, consider evaluating ff(z = 1) when f (g) = sin 2. The exact answer is, of course, cos 1 = 0.540302. The following FORTRAN program evaluates Eq. (1.3b) in this case for the value of h input:
4
1. Basic Mathemalical Operations
FRIlT
10
READ
* , %HT=
*,
VALUE OF ft
C. LE,
O
TO STOP)
WI
IF (B .LE, 0) STOP F P R ~ E = ( S X(x+E>-SXN(X-B] W >/(2*~> DIW=EXACT-FPRIME PRTMT 28,W,BIFF
FOMAT(~=',Elb.$,5X,%MOR=~,E1668) GOT15 10
20
ElD
(If you are a beginner in FORTRAN, note the way the value of H is requested from the keyboard, the fact that the code will stop if a nonpositive d u e of R is entered, the natural way in whi& variable names are chosen and the mathematical formula (1.3b) is transcribed using the SIN function in the sixth line, the way in which the number of significant digits is specified when the result is to be output to the screen in line 20, and the jump in program control at the end of the program.) Result8 generated urlth this progrm, as W& as with s i d a r ones evaluating the forward and backward difference formulas Eqs. (1.4a,b), are shown in Table 1.1. (AU. of the tables of errors presented in the text wre generilted f f ~ mBASIC progras; the numbers may vary from those obtdned from FQRTRATJ code, especidy when numerical roundoff dominates.) Note that the result improves as we decrease h, but only up to a point;, after which it becomes worse, This is because arithmetic in the computer i s performed with only a limited precision (5-6 decimai digits for a single precision BASIC variable), so that when the difference in the numentor of f;he appro~mafsionsis formed, it is subject to large "roundoff" erfors if h is smdl and fi and diger very little. For example, if h = 10-7 then f2
= sin (1.000001) = 0.841472 ; f-l = sin (0.999999) = 0.841470 ,
so that fi -lml= 0.000002 to six significant digits. When substituted into (1.3b) we find f t m 1.000000, a very poor result. However, if we do the arithmetic with 10 significant digits, then
which gives a respectable f' rr: 0.540300 in Eq. (1.3b). In this sense, numerical differe~ltiationis an intrinsically unstable process (no well-defined limit as h --+ 01, aud so must be carried out with caution.
Table 3.1
h 0,50000 0,20000 0,10000 0,05000 0.02000 0.01000 0,00500 0.00200 0,00100 0,00050 0,00020 0,00010 0.00005 0.00002 0,00001
Error in cvduating d;sin t / d ~ l ~= =0.5403@ ~
S ~ e ( ; r i e Forward
Bsckwd
%point $point Eq. (1.3b) Eq. (1.4a) 0.228254 0.022233 01003595 0,087461 0.042938 0,000899 0,021258 0.000225 0.008453 0.000037 01000010 0,004224 0,0000X0 0,002108 0,000820 -0,000014 0,000403 -0,000014 0,000403 0,000105 -0,000163 -0.000014 --0.000312 -0.000312 0.001476 0.000284 0,000880 0,000880 01000880 0.003860
2-point Eq. (1.4b) -0,183789 -0.080272 -0,041139 -0.020808 -0.008380 -0,004204 -0,002088 -0.000848 -.0.000431 -0.000193 -0.000312 --0,000312 -0.00090Zf 0.000880 -0,002100
Symmetric &point Eq. (1.5) 0,001092 0.000028 0.000001 0,000000 0.000001 0.000002 0.000006 -0,000017 -O.O00019 0.000115 -0,000188 -0.000411 0.000681 0.000873 0,000880
It is poasible to improve on the Spoint formula (1.3b) by rdating f to lattice points fnrther removed from z = 0. For example, using Eqs. (1.2), it is easy to show that the U5point" f o d a
caneels dl derivatives in the Taylm series through fourth order. Computing the derivative in this way amumee that f is well-appdmated by a fonrth-degree polynomial over the &point !interval [-21r,2h]. Although reqniring more computation, this approximation is considerably more aecurate, as can be e e n from Tabfe 1.1. In fact, an curacy earnparable to Eq. (1.3b) is obtained with a step some 10 times larger. This ean be an important eonsideration when many d u e s of f must be stored in the computer, as the greater accnracy dows a sparser tabnlatibn and so saves storage space. However, because (1.5) requires more mathematical operations than does (1.3b) and there is considerable urncellation among the varions terns (they have both positive and negative coefficients), precision p m b l ~ mshow ~ up at a larger value of he Forrndit8 for higher derivatives can be conatnrcted by taking appro-
6
l. Basic Mathematical Ogrzrations
Table f .2 4- and S-pint BiRerence: formulas for de~vativw
priate combinations of Eqs. (1.2). For example, it is easy to see that
so that an appraximation to the second derivative accurate to order h2 is
DiEerence formulm for the various derivative^ of f th& are accurate to a higher order in h can be derived straightforwardly. Table 1.2 is a summary of the 4 &ad5-pdnt ewressiaas. Using any function for which you can evduate the derivatives analytically, investigate the accuracy of the formulas in Table 1.2 for various vdues af h. Exercise 1.1
1.2 Numerical quadrature In quadrature, we are interested in calculating the definite integral of f between two limits, a < b. We can easily arrange for these values to be points of the lattice separated by an even number of lattice spacings; i.e.,
is an even integer. It is then sufident for us to derive a formula for the integral from -h to +h, since this formula can be composed many times: a+2h
b
f (s)dz =
f (4
+
a+4h
f(.)dz
+ + * *
*
f (462%
*
(1.8)
The basic idea &hind all of the quadrature formulas we wilI discuss (technically of the closed Newton-Cotes type) is to approximate f between -h and +h by a function that can be integrated exactly. For example, the simplest approximation can be had by considering the intervals [-h, 01 and [O, h] separately, and assuming that f is linear in each of these intervals (see Figure 1.1). The enor made by this interpolation is of order h2f ", so that the approximale iate& is
which is the weU-known trapezoidaf rule. A better approximation can be had by realizing that the Taylor series (1.1)can provide an improved interpolation of f. Using the difference formulas (1.3b) and (1.7) for f' and f",respectively, for 1s put
which can be intepated readily ta give
This is Sinnpsonk rule, wEch em be seen to be accurate to two orders higher than the trapezoidd rule (1.9). Note that the error i s actually better than would be expected naively from (1.10) since the x3 term gives no contribution to the integral. Composing this formula according to Eq. (1.8) gives
As an example, the following FORTRAN program calculates 1
e"dz = e - I = 1.718282
using Simpson's rule for the value of N = llh input. [Source code for the lmger program like this that are embedded in the text are cont;ained m tbe Gmplubats'oncrl Phgaics diskette or avdlabIe over Xaterne~, (see Appendix E); the shorter codes can be easily entered into the reader's computer from the keyboard.]
8
I , Basic Mathematical QpraEdons C chaplb.rS"or m C ( X ) =EP(X) E X A ~ = E ~ (1-2, I.
30
*
!Sact;ion t o ia%epat e
PRZRT ,"ETER I EVm ( ,LT, 2 B ' 3 STIZP) Rm*,1 ZP (1 .LT. 2) SmP IF (NOD(1,2) .HE. 0 ) I=@+$
E=%./#l
.
S W = m C( 0 ) FAC=2 DO 10 X = l , W - I f F (FAC .Eq, 2.) T H D
@
!contribation from X=O !factor for Siapson% rule !loop over Xattice paints ?factors altemage
FAG4 ELSE: FAC=2.
m
IF X=S*LI 10
SW=Sm+FAG*mC(X) COrnICrnE S W = S ~ +(1~,)C XXBfT=Srn*H/3.
!X at thfe point
icontribution t o the fntegsa2 ?contribatioa fron X=%
L)I~=~AC*I"-XZIIT
PRIBT 20,I,DIW 20
FO~AT(6X,i#=i,XS,6X,8~WR=\ElEi.Ef) 60TQ 30 !get motker v a u a oQ I
EED
Resdts are shown in Table 1.3 for variaus d m s of N , together Prith the v d w s obtained nsine; the trapezoidd rule. The improvement from the kigber-order f a m d a i s evident. Note that the resdts are skabltj in the sense that a wdI-dehed limit is obt~xredas N becomes very lztrge and ths! mesh spacing h becams @m&; round-aff arms me unimportant because dl vdue8 of f enter irzte, the quadratare formda Pvith the same s i p , in corrtrast to what happens in numerical diRert?ntiation, An important issue in quadraturn is how s a d an h is necessary to compute the integral to a Egiwn accuracy, Although it is passible to derive rigorous error bounds for the formulas we have discussed, the simplest thing to do in practice is to run the computation again with a smaller h and ob~ervethe chmges in the results.
Table 1.3
Errors in evaluating
1
eZdz = 1.718282
W, ~
N 4
8 16 32 64
h 0.2500000 0.1250000 0.0625000 0.0312500 0,0156250
Trapezoidal Eq. (1.9) -0,008940 -0,002237 --0.000559 -0.000146 -0.000035
~
Simpson's Eq. (1.12) --0.000037 0.000002 0.000000 0.000000 0,000000
Bode's Eq. (1.13b) -0.00QO01 0.000000 0.000000 0.000000 0.000000
Higher-order quadrature formulas can be derived by retaining more terms in the Taylor expansion (1.10) used to interpolate f between the mesh points and, of course, using commensurately better finite-difference approximations for the derivatives. The generalizations of Simpson's rule using cubic and quartic polynomials to interpolate (Simpson's $ and Bode's rule, respectiveb) are:
The! results olE applying Bode's rule are &so @venin Table 1.3, where the improvement is evident, afthough a;t the expense of a more involvt3d computation. (Note that for this method to be applicable, N must be a multiple of 4.) Although one might think that formulas based on interpolation using polynomials of a very high degree would be even m r e suitable, this is not the cme; s;u& pdpornids tend to osciUate vidently and lead go an inaccurate interpolation, Moreover, the coefFicients of the vailues of f at the vaious lattice paints em have both positive aad nega i v e signs in higher-order farxnulas, maEng rouad-oE error a potentid problem. It is therefore usually safer to improve accuracy by using a low-order method and making h smder rather than by resorting to a higher-order formula. Quadr ature formulas accurate to a very high order cm be derived if we give up the requirement of equdlycspaeed abscissae; these are discussed irr Chapter 4. Exercise 1.2 Using any function whose definite i n t e p d you can compate anitlytically, investigate the acuracy of the mrious guadrat;ure nreth-
m
10
d . Ba@ie IkPh&ematieol Operations
ads discussed above far aBerent vdaes of h, Same care and G on sense must be! exerciwd in the wpfication of the numericat quadrature formulas discussed above. For example, an integral in which the upper limit is very large is best handled by a change in vaiable. Thus, the Simpsonk s l e eduation of
with g(z) constant at large z, would result in a (finite) sum converging very slowly as b becomes large for fixed h (and taking a very long time to compute!). However, changing variables to t = r -l gives
whi& can then be evdualed by any of tlne formulas ure hwe discnssed. Integrable sinmlar4tiies, vvhich caase the naive Ibrmdas "co give nonsense, can dso be hmdled in a simple way. For example,
has an integrable singularity at = 1 (if g is regular there) and is a finite number. However, since f ( z = 1) = m, the quadrature f o m d a s &scussed above @v@an infinite result, An accurae result can bc? obtained by changing variables to t = (1- z)'i2 to obtain
which is then approdmated vvith no trou'ble. Integrable singularities can also be handled by deriving quadrature formulas especidy adapted to tl~em,Sunpose we me intefested in
where f (2)b e h m s as Cs-'I2 near 5 = O,with C a.constan%.The integral from h to 1 is regular and can be handled easily, while the integral from O to h can be approximated as 2ch'I2 = 2hf (h). IN
Exweise 1.3
M"fite a program to calculate
%singone of the quadraturn formula8 diswssed above and investigate its accuracy for various values of h. (Hint: Split the range of integration into tvm parts and make a agerent dhange of variable h each integral ta handle the siagufafities.)
1.3 Finding roots The find deznentary operation that is commmly mqnired is to find a root of a function f that we can compute for arbitrary z. One surefire method, when the appraxim;bte location of a root (say at I = %@) is known, i s to guess a trial value of z guaranteed to be less than the root, and then to inerease this trM d u e by smdl positive steps, backing up and halving the step size every time f changes sign. The values of x generated by this procedure evidently converge to $0, so that the search can be terminated whenever the step size falls helm the mqnired talefance, Thus, the fanowing FORTRAN proe;rano finds the positive root of the function f (g) = z2 - 5, 50 = = 2.236068, to a. tolerance of 1 0 ~ ~ using z = f as an initid guess and m initid step size of 0.5: C
ch&plc.for FWCCX) =X*X-5, TOLX=1,E-OB
!fmction wkosa root i s sought !toleruce fox %hiesewch !inf.lsia guess l initf a i l i m c f i o n ? i n i t i d step ! i n i t i a i z s come
X=%.
FOD=WBC(X)
.
DX= fr
ITER=@ 10
COaTSME XmR=SITm+I X=X+E)X PRIIT *,XTER,X,SQET(&,)-X
IF ((FQm+FWC(X))
.LT. 0) TZfEg ! f f sign change, back up
X=X-DX xlX=DX/Z
EID SF IF (ABSCDX) STOP EHD
!increfaen* iteration, corn$ !step, X !ou.lspat cummt values
! arrd havet the attap
.GT. TOLX) GOTO 10
Results far the sequence of z d u e s me shown in Table 1,4, evidently convergiatg to the correct answer, dthough orrly after some 33 iterattions. One must be careful when using this method, since if the initid step size I
Table 2.4
Iteration
Error in finding the pwitivr: root o f f (z)= z2 -- 5
Sear&
Hewton Eq. (1.14)
Secant Eq. (1.15)
if3 too large, it is possible ta step over the root desimd when f has several. roots, r Exercise 1-4 &an the code above far vmious t~lermces,irr;itid
guesses, and ini.t;id ~ t e psizeis. Note that sometimes you might find convergence to the negative root. What happens if you start with an initial gGess of -3 with a step ~ i z eolt 6?
A more efficient algorithm, Newton-Raphson, is available if we can evaltuate the derivative of f for ubitrary a. Tfiis method generates a sequence of values, g', eonverljng to zo under the assumption that f is locally linear near $0 (see Figure 1.2). That is, l
f (g') f '(S')
'
is also shown in Table 1.4, The application of this method to finding where the rapid convergence (5 iterations) is evident. This is the algorithm usually used in the computer evaluation of square roots; a linearization of (1.14) about shows that the number of significant digits doubles tvith ea& itmation, as is evident in Table 1.4. The secant method provides a happy compromise between the eg ficiency of Newton-Raphson and the bother of having to evduate the de~vative.If the derivative in Eq. (1.14) is approximated by the differ-
F i v e 1.2
Geometrical bases of tbe Newton-Rrtphm (left) and se-
cant (fight) methods.
ence formula related to (1.4b),
we obtain the following 3-term I' and zi-l (see Figure 1.2):
recursion formula giving S'+' in terms of
Any two approximate values of $0 can be used for +@ and s ' to start the algorithm, which is terminated when the change in z from one iteration to the next is less than the required tolerance. The results of the secmt method for our model problem, starting with values z0 = 0.5 and z' = 1.0, m also s h w a in Table 1.4, Prcrvided that the initid gue8s;aes ase dose to the true root, convergenm to- the exact answer is dmast as rapid as that of the Newton-Rapksan dgorithm,
Exercise 1.5 Write programs to solve for the positive root of sZ- 5 using the Newton-Raphsan a d secant methods. Invwtigate the behavisr of the latter vvith changes in the initial guesse~for the rmt.
D
When the function is badly behaved near its root (e.g., there i s m inflection point near so)or when there are several roots, the "automatic" ME?wt;on-Raphsonafld secant methodts can fail to converge at dl m converge to the wrong mswer if the initid guess for the root is poox. Henee, a safe and conservative procedure is to use the seaeh dgorithm to loe&e $0 a p p ~ o ~ m a t e and l y then to uae one of the wtomatic meehods.
14
1. Basic Mathernatiurl Qperatians
Exercise 1.6 The function f ( s ) = tanh z has a root at + = 0. Write a p r q r m to show that the Newton-Rqhson method does not co~verge for an iaStid gueshi of z X l. Cm you understand what's going wrong by considering a graph of tanh I? From the explicit form of (1.14) for this problem, desive the critical value of the initid guess abave which coavergence will not occur, Try to solve the problem using the secant method. m a t happens for vmious initial guesses if you try to find the z == O mot of tan z usiw either method?
1.4 Semiclassical quantization of molecular vibrations As an =ample combining several basic mathematicall operations, we consider the problem of describing a diatomic molecule such as 02, which wnsists of two nuclei bound together by the electroas that; orbit about them. Sinm the nnclei are much heavier than the electrons we czm assume that the latter move fat enough to readjust inst;arrtmeously to the changing position of the nudei (Born-Oppenheimer approximation). The problem is therefore reduced to one in which the motion of the two nudei is governed by a potential, V, depending only upon r , the distance between them. The physical principh mspmsibb for generating V will be discussed in detair in Project VIII, but on generd grounds one c m say that the potential is attractive at large distances (van der W d s interaction) and repulsive at short distances (Coulomb interaction of the nuclei and Pauli repulsion of the electrons). A commonly used form for V embodying these features is the Lennard-Jones or 6-12 potential,
which has the shape shown in the upper portion of Figure 1.3, the minimum occurring at rmim= 2'j6a with a depth %. We will assume this form in most of the discussion below. A thorough treatment of the physics of diatomic molecules can be found in [He501 while the Born-Oppenheimer approximation is discussed in [Me68]. The great mass of the nudei allows the problem to be simplified even further by dewupling the slow rotation of the nuclei from the more rapid changes in their separation. The former is well described by the quantum mechanical rotation of a rigid dumbbell, while the vibrational states of relative motion, with energies E,, are described by the bound
Fignre 1.3 (Upper portion) The Leaamd-Janes potentrid and the inner and outer turning point8 kLt, a neg&ive energy. The &;take&tine show8 Ch~fp~rabolicapproxhation to the potential, (Lawer parlion) The corresponding trajectory in ghatcie spwe.
state solutions, +%(F), of a one-dimension$ Schroedinger equation,
Here, m i s the r f ~ d ~ mws ~ e d of the two nucfei, Our ~ ain. l this exampb i s to find tht! enerdes E,, given a particular potential. This can be done wwtly by salving the &Rerentid eigenvdue equation (1.17); numerical methods for doing so will be discussed in Clrapter 3. Hawever, the great mass of the audei. implies that their motion i s neafly dasical, so that approdmate values of the vibrationd ener@es cE, can be obtaliwd by conrjidering the clmsieal motion of the nuclei in V and then applying '"quantization ruks" to d e t e r ~ n e the energies, These quantizatio~rdes, origindly postulatd by N. Bobr and Sornrnerfeld and Wilson, were the bwis of the "old" quantum tbwry
I6
1. Basic XkialFhematiml Operations
from which the modern formulation of quantum mechanics arose. However, they can also be obtained by considering the WKB appraximation to the wave equation (1.17). (See [Me681 for details.) Confined dassical motion of the internudear separation in the potential V(7) can occur for energies -Vo < E < 0. The distance between the nuclei osdllates periodically (but not necessarily harmonically) between as shown in Figure 1.3. Durinner and outer turning points, q, and rout, ing these oscillations, energy is exchanged between the kinetic energy of relative motion and the potential energy such that the total energy,
is a constant (p is the relative momentum of the nuclei). We can therefore think of the oscillations at any (jven energy as defining a dosed trajectory in phase space (coordinates r and p) along which Eq. (1.18) is satisfied, ab; s h m in the lower portion of Figzlre 1.3, An explieit eqnaLim for this trajectory can be obtained by solving (1.18) for p:
The classid motion desaibed above occurs at any enerw between. 0. To qnmtize the motion, and hence obtain approximations to the eigenvdues E, appearing in (1.IT), we consider the dimensionless action at a, @ven energy,
-6 a;nd
where k ( r ) = h-lp(r) is the local de Braglie wave number and the integral is over one complete cyde of oscillation. This action is just the area (in units of h) enclosed by the phase space trajectory. The quantization rules state that, at the allowed energies E,, the action is a hdf-integral multiple of 2a. Thus, upon using (1.19) and recalling that the oscillation passes through each value of r twice (once with positive p and once with negative p), we have
where n is a nonnegative integer. At the limits of this integral, the turning points Q, and rout,the integrand vanishes.
To specialize the quantization condition to the Lennard-Jones potential (l.16), we define the dimensionless quantities
so that (1.21) becomes
is the scded potentid. The quantity 7 is a dimensionless measure of the quantum nature of the problem. In the dassical limit (a small or m large), 7 becomes large. By knowing the moment of inertia of the moleeule (from the energies of its rotational motion) and the dissociation energy (energy reqnired to separate the molecule into i t s two constituent atoms), it is possible to determine from observation the parameters a and 'Vo and hence the quantity 7. For the H2 molecule, 7 = 21.7, while for the HD molecule, 7 = 24.8 (only m, but not h,changes when one of the protona is replaced by a deuteron), and for the much heavier O2 molecule made of two lBO nuclei, 7 = 150. These rather I q e vdues indicate that a s e ~ c l u s i c d appro~xnationis a valid dwcription of the vibratianal motion. The F O R T U N program for Exmple 1, whose source code is cantained in Appendix B asld in the file EXMPLI.FOR, findg, for the d u e of y input, the values of the E, for which Eq. (1.22) is satisfied. After all of the ener@eshave been h n d , the corresponding phase pace trajwt* ries we dram. (Befora attempting to gun this code on yovr camputer syaern, you should review the m&t3rid on the progrms in ""Howto use this book" and in Appendix A.) The following exercises are aimed at increasing yovr undemtmding of the physical principles and numerical. methods demonstrawd in this example. Exwcise l.'? One of the most important aspects of using ie computer a tool to do pbysics is knovving when to have confidence that the program is giving the correct answers. In this regard, an egsential teat ia the d e t ~ l e dquantitative comparison of results urith what is known in =a'lytieaffy soluble situations. Modify the code! to use a pasabotic potential
m
;as
18
1. Basic Malhematic-al Operations
(in subroutine POT, taking care to heed the instructions given there), for which the Bohr-Sommerfeld quantization gives the exact eigenvdues of the Schroedinger equation: a series of equdly-spaced energes, with the lowest being one-half of the level spaeing above the minimum of the potentid. Far sever& vdues of 7, compare the numerical resalts .for this case with what you obtain by solving Eq. (1.22) a n e t i c d y . Are the phase spwe trajectosies what you eqect? Exercise L8 Another important test of a- working code i s to compare its results with what is expected on the basis of physical intuition. Restore the code to use the Lemard-Jones potential and run it for 7 = 50. Note that, as in the case of the purely pmabolic potentid discussed in the previous exerdse, the first excited state is roughly three times as high above the bottom of the well as is the ground state and that the spacing8 between the few lowest states are rougllly constant. This is because the Lennard-Jones potentid is roughly parabolic about its minimum (see Figure 1.3). By calculating the second derivative of V at the minimum, find the ""spriag conatat" and show that the fi.equency of small-amplitude motion is expected ta be:
B
Verify that this is wnslstent with the numerical resuks and explore tbis agreement for different values of y. Can you understand why the higher energies are more densely spaced than the lower ones by comparing the Lennard-Jones potential with its parabolic approximation?
=
Exwcisos %.Q bvwiance of results under changes in the numerical algorithms or their parameters can give additional confidence in a calculation. Change the tolerances for the turning point and energy searches 'be done at mn-time or the number of Simpson's rule points (this by choosing menu option 2) and observe the effects on the results. Note that because of the way in which the expected number of bound states is calculated (see the end of subroutine PARAM) this quantity can change if the energy toferance is vwied.
Exareise 1.10 Replace the searches for the inner and outer turning points by the Newton-Raphson method or the secant method. (When ILEVELZ 0, the turning points for ILEVEL - l are excellent starting values.) Replace the Simpson's rule quadratare for s by a higher-order formula [Eqs. (l.13a) or (1.13b)I and observe the improvement.
B
Table 1.5
Experiment& vvibraLional energi~af the E2 molecule
Exercise 1.1% Plot the E , of the Lennard-Jones potential as functions of 7 for 7 running from 20 to 200 and interpret the results. (As with many other short calculations, you may find it more efficient simply to run the code and plot the results by hand as you go along, rather than trying to automate the plotting operation.)
r
Exercise 1.12 Fbr the Hlz mofecufe, observations show &at the depth of the potedial is 6 == 4.747 elf and the location of the pdentid minimum is Tmjn = 0.74166 A. These two quantities, together with Eq. (1.23),
imply a vibrationd frequency of mare t h m four times lager t h m the experiraentdly absemed energy difference between the ground and first vibrationd state, 0.525 eV. The Zennard-Jones shillpe is therefore not a very good description of the potentid sf the Hz molecnk. Another defect is that it predicts 6 h a n d states, while 15 are known to exist. (See Table 1.5, whose entries are derived from the data quoted in [Wa67].) A better andytic form of the potentid, with more parametws, is required to repmduce gimdtaneou6ly the depth and location of the minimum, the frequency of smaU amplitude vibratians about it, and the total number of bound states. One such fom i~ the Morse potentid,
which &so C= be ~olvedanalyticrzlly. The Marse potentid has a minimum a;t the expected locat;ian a d the parameter P can be a u s t e d to ht the curvature of the miaiI-nurn to the observed excitatioa enerw of the first
2Q
l. Basic Mathematical Qperatians
Figure X,% Quantitim involved h the krcatte~i~g of a particle by central patentid.
a,
vibrational state. Find the value of P appropriate for the Hz molecule, modify the pf~gramabove to use the Morm potent;iaI, and cdcdate the spectmm of vibrational statas. Show that st much more reasonable nu=ber of levels is now obtained. Compare the energies with experiment and with those of the Lennard-Jones potential and interpret the latter digererrces.
Project I: Scattering by a central potential h this, project, urt; uriU investigate the dassical scattering of a particle of mms nz by a centrd poteatid, in particula the Lennad-$ones potentid c0nsiderci.d in Section 1.4 above, h a scattePing event, the partide, with. initial kinetic t?nergy E z~ndimpact parameter b, approaches the potential from a large distance, It is deflected during its pasage n e a e h force center and eveatudy emergee with the same enera, but moving at an. angle O with respect to its original direction. Since the potentid depends ' upon an& the distance of the partide fronn the force center, the aagular momentum is conserved and the trajedory Lies in a plane. Thcr pdar coordinates of the partide, (P,@), are a convenient way to describe its motion, as shown in Figure 1.1. (For details, see any textbook on dasdcal mechanics, such M [Go80].) Of basic interest is the deflection function, O(b), giving the final scattering angle, 0,as a function of the impact parameter; this function also depends upon the inddent energy. The differential cross section for scattering at an angle 0, do/dQ, is an experimental observable that is
related to the defiection function by
Thus, if dOldb = (dbldO)-l can be computed, then the cross section is known.. Expressions for the deflection function c m be found analytically for only a very few potentials, so that numerical methods usually must be employed. One way to solve the problem would be t o integfate the equations of motion in time (i.e., Newton's law relating the acceleration t o the force) to find the trajectories corresponding to various impact parameters and then to tabulate the final directions of the motion (scattering angles). Tbis would involve integrating four coupled first-order differential e q u a tions Eos two coordinates and t h i r velocities in the scattering plane, discussed in Section 2.5 bebw. However, since a n p l a r rxramerrtum is conserved, the evdution of B is related dire6tly to the radial motion, and the probhrn can be reduced to a one-dimensiond one, wEch can be s d v d by quadratare. This fatter approach, which i s simpler and more accurate, is the one we will, pursae here. To d e ~ v an e clbppropriaGe expression for 8 , we begin vvjth the conservation of arrgular momentum, which implie8 &hat
is a constant o-f the motion. Here, dB/& is the augtrlas velocity and v is the asymptotic velocity, related to the bombarding energy by E = i m v 2 . The radid motion owurs in an eRective potentid th& is the sum of V and the centrifugal potential, so that energy conservation implies
If we use
F
as the independent variable in (1.21, rather than the time, we
can write
t yields and salving (1.3) for d ~ / o t thrtn
22
2 . Basic Mathematical Ofterations
Recalling that 0 = n when r = oo on the incoming branch of the trajectory and that B is always decreasing, this equation can be integrated immediately to give the scattering ande,
where r,i. is the distance of closest approach (the turning point, determined by the outermost zero of the argument of the square root) and the factor of 2 in front of the integral accounts for the incoming and outgoing branches of the trajectory, which give equal contributions to the scatterixlg angle. One find transformation is useful before beginning a numerical calculation. Suppose th& there exist8 a distmce rr,,, beyond which vve can safely nedect V. In this case, the integrand in (1.6) m i s h e s as T - ~for large r , so that numericd quadrature could be very ineRcient. In fact, since the p o t e ~ t i dhap aa eEect for r > rm,, , we would just be "wasting time" "describing stra;igJRt-line nrotisn, To hanae this situation &cientXy, note that since 63 = O when V = 0, Eq. (1.6) implies that
which, when substituted into (I.6), results in
The integrals here extend only to rm,, since the integands becme equd when T > Our goal will be to study scattering by the Lennard-Jones potential (1.16), which we can s a f e set to zero beyond P,,, = 3a if we are not interested in e n e e e s smaller than about The study is best done in the hlloMring sequence of steps: Step 1 Before beginning any numerical computation, it is important to have some idea of what the results should look Like. Sketch what you think where the the deflection function is at relatively low energies, E 6 will take place in a predominantly peripheral collisions at large b 5 ,,F at tractive potential and the more central collisions will LLbounce"against the repulsive core. What happens at much higher energies, E > Vo,where
1. Scattering by( a cent& potential
the attractive pocket in V can be neglected? Note that for values of b where the deflection function has a maximum or a minimum, Eq. (1.1) shows that the cross section will be infinite, as occurs in the r&nbow formed when light scatters from water drops. Step 2 To have analytically soluble cases against which to test your program, calculate the deflection function for a square potential, where V ( r )= U. for r < Fmax and vanishes for r > r,,,. What happens when U. is negative? What happens when U. is positive and E < Uo? when
E > U@?
Step 3 Write a program that calculates, for a specified energy E, the deflection function by a numerical quadrature to evaluate both integrals in Eq. (1.8) at a number of equally spaced b values between O and F,,. (Note that the singularities in the integrands require some special treatment .) Check that the program is working properly and is accurate by cafculating deflection functions for the square-well potentid discussed in Step 2. Campwe the accuracy with that of asl dterndive procedure in which the first intepal in (1.8) is evdaated andytiea;lly5rather than mmeri cdy. Step 4 Use your propam to cdc.ulilLee the degection function far scattering from the Lennard-Jones potential at selected values of E ranging from 0.1 to 1 0 0 h . Reconcile your answrs in Step I with the result8 you obtGn. Calcu1;at;e the diflerentid cross section as a function of @ at these energies. Step 5 E your progrm is working comectly, ycru &odd observe, for ener@w E K t a siqulmity in the deflection function whese O appeaas to apprawh -m at some critical vdue of b, brit,that depends on E. This singularity, which disappears when E becomes larger than about V@, is characteristic of Uorbiting." In this phenomenon, the integrmd in Eq. (1.6) has a linear, rather than a square root, singularity at the turning poiat, 80 thitt the scattering aggle becomes logiurithrnically iagnite. That is, the eEective pohential,
has a parabolic maximum and, when 6 = bcrit, the peak of this parabola is equal to the incident energy. The trajectory thus spends a very long time at the radius where this parabola peaks and the particle spirals many times around the force center. By tracing bcrit as a function of energy
23
24
1. Basic Mathematical Operations
and by plotting a few of the effective potential8 involved, convince yourself that this is indeyed what's happening. Determine the x n ~ m u a ne n e r far ~ vvbich the Lennard-Jones potenkid exhibits orbiting, either by a d u t i o n of an agprcfpriate set of equatons invalviag Y and its derivatiw~ar by a systematic numerical investiwtion of the deflection function. If you pufsue the latter approach, ysu Iulight have to reemider the treatment of the aingdafities in %he numerical. quadratures.
Chapter 2
Ordinary Differentia Equations Many of the laws of physics are most conveniently formulated in terms of differential equations. It is therefore not surprising that the nurnericd sdution af differentid equations is one of the mast common tasks in modeling physicd systems. The most general form of an ordinary differentid equation is a set of M coupled first-order equations
where is the independent variablt? and y is a set of M dependent variables (f is thus an M-component vector). Differentid equations of higher order can be written in this first-order form by introducing auxiliary functions. For example, the one-dimensional motion of a partide of mws m under a force field F ( z ) is described by the second-order equation
If we define the morne~rtum
then (2.2) becomes the two coupled first-order (Hamilton's) equations 0% P ~~~
dt
.
nz "dt
*
= F(z),
which are in the h r m of (22). It is therefore suficient ta ccznsjdes in detGl anly nnetlrods for first-order equations, Since the matrix structure
of coupled differential equations is ofthe most natural form, our discussion of the case where there is only one independent variable can be generalized readily. Thus, we need be concerned only with solving
for a single dependent variable y(g). In this chapter, we will discuss several methods for solving ordinary differentid equations, with emphasis on the initial vdue problem. That is, find g(%)given the vdue of y at some initial point, say y(z = 0) = yo. T h i ~ kind of problem occurs, for example, when we are given the initial position and momentum of a particle and we wish to find its subsequent motion using Eqs. (2.3). In Chapter 3, we will discuss the equally important boundary vdue and eigenmlue problems.
2.1 Simple methods To repeat the basic probjem, we me interested in the solution of the differential equation (2.4) with the initial condition y(z = 0) = go. More specificitlly, W are u s u d y interested in the d u e of y at a particular value of I, say z = 1. The general strategy is to divide the interval [O, 11 inLo a large number, N,of equdlg spaced subintmds of length h = 1IN and then to develop a recursion formula relating y, to y,-l, ...l, where y, is our approximation to g(+, = nh). Such a recursion relation will then dew a step-by-step integatioa of the digeratid equation earn a:=Qto1=1, One of the simplest algorithms is Euler" smethod, in whi& we consider Eq. (2.4) at the point x, and replace the derivative on the left-hand side by its forward difference approximation (1.4a). Thus,
so that the recursion relation expressing
in terms of y, is
This formula has a local error (that made in taking the single step from g, to that is O(h2)since the emor in (1.4a) is 6 ( h ) . The LLglobal" error made in finding y(l) by taking N such steps in integrating from I = O to r = 1 is then NO(^^) a Q(&). This error decreases only
linearly with decreasing step size so that half as large an h (and thus twice as many steps) is required to halve the inaccuracy in the final answer. The numerical work for each of these steps is essentially a single evaluation af f . As an example, consider the differentid equation and boundary condition
-= -zy dz
; y(0)
whose solutioiz is y = e-g2/2
=1,
(2.7)
.
The following FORTRAN program integrates forward from s = O to I = 3 using Eq. (2.6) with the step size input, printing the result and its error zls it goes along. G chap2a.for mIG(X,Y)=-X*U f dy/& 20 PRIlT *, "ntar step size ( .l@. O to stop)' REm *, H IF' (H .LE. 0,) STOP !nmbsr of steps to reach. X=3 MSTEP=3./W V=l, !y(O)=I DO 50 IX=O,WSTEP-5 !loop over steps X=IX+H !last X value !new Y ~2~3.~4 fram Eq 2.Q Y=Y+H*FUBG(X,Y) DTFF=EXP f -Q. S* (X+H) **2]-Y !compme with axaet v a u a PRIBT *, IX,X+B,P,DIW 10 COIQTINUE i a t a ~again with new v a u a o f H GOTO 20
Em Errors in the results obtained for
with various step sizes are ghown in the first two cdunms of Tabh 2.1. As expected fmm (&G), the errors decrease linearly with smaller h. However, the fractional error (error divided by y) increases with I as more steps me taken in the ilttegratlon asrd y beeernes smajtler.
28
1, Ordinary Diflemntial Equatrions
Table 2.2
k
Error in integrating dy/cbz
E d e r ? method ~ Eq. (2.6) @(l) ~(3)
z:
-zy with gf 0)
Taylor series
Eq. (2.10) ~(1)
~(3)
1.
ImpEcit method Eg, (2.18) ~(1) ~(3)
Exaeise 2.1 A simple aad aftm stringent test of an =cur&@nmericd integration is to use the find vdue of y abtained as the initid condition to integrat;e bacbwxd fram the find vdue of a: to the starting poia_t. The
m
extentt to which the resulling vdw of y differs from the origind initial condlition is then a measure of the i n a c e u r ~ y Apply this test to the e x a p l e above. Although Euler's method seems to work quite wen, it is generally unsatisfactory because of its low-order accuracy. This prevents us from reducing the numerical work by using a larger value of h and so taking a smaller number of steps. This deficiency becomes apparent in the example above as we attempt to integrate to larger values of z,where some thought shows that we obtain the absurd result that y = 0 (exactly) for z > h-'. One simple ~olutionis to change the step size as we go along, making h smaller as s becomes larger, but this soon becomes quite inefficient. Integration methods with a higher-order accuracy are usually preferable to Euler's method. They offer a much more rapid increase of accuracy with decreasing step size and hence greater accuracy for a fixed amount of numericd effort. One dass of simple higher order methods can be derived from a Taylor series expansion for y,+l about :,y
From (2.4), we have Y,
r
= f(zm,va) 3
which, when substituted into (2.8), results in
where f and its derivittives are to be evaluated at (g,, g,). This recursion relation has a local emor O(h3)and hence a global error 6 ( h 2 ) ,one order more accurate than Euler's method (2.6). It is most useful when f is known analytically and is simple enough to differentiate. If we apply Eq. (2.10) to the example (2.7), we obtain the results shown in the middle t m columns of Table 2.1; the improvement over Eder" method is dear. Algorithms with an even greater accuracy can be obtained by retaining more terms in the Taylor expansion (2.8), but the algebra soon becomes prohibitive in a31 but the simplest czases. 2.2 Multist ep and implicit met hods Another way of ~ E e v i n ghigher accuracy is to use recursion relations that relate y,+z not just to yn, but also to poiats funther "h the past;,n say yn-1, h - 2 l .. To derive such fcrrmulas, we can intef3rate one step of the differential equation (2.4) eznctly to obtain
..
The problem, of CaQrse, is that we d d t know j owr the intmval of integration. However, we can use the values of y at I, and z,-l to provide a linear extrapolation of f over the requirc?d inlervd:
where f i E f ( z i , y i ) . Inserting this into (2.11) and doing the s integral then results in the Adms-Bashforth two-&ep method,
Related higher-order methods can be derived by extrapolating with 6igher&gee polynomials, For example, if f is extrapdated by a cubic pdynsmid fitted to f,, f n m l , f n m 2 , and fnmst the Adams-Bashforth four-Step method results: I
Note that because the recursion relations (2.13) and (2.14) involve several previous steps, the value of y~ alone is not sufficient information to get them started, and so the vdues of ly at the first few lattiee points must be obtained from some other procedure, such as the Taylur series (2.8) or the Range-Kutta metbads discussed below. Apply the Adas-Bashforth two- and four-step dgorithms to the example defined by Eq. (2.7) using Euler's method (2.6) to generate the vdues of y needed to start the recursian relation. Investigate the accuracy of g(%) for vaious values of h by comparing with the walfytied resdts a d by appfyj,ng the reversibiEty teat described in Exercise 2.1.
R
Exc3rcise 2.2
The methods we have discussed so far me ""expfidt" in inhat the gn+l is given directly in terns of the drezldy known value of y,. '"2nnplicit" methods, in wKcb m equation must be solved ta determine % + l t oEer yet another means of achieving higher accuracy. Suppose wre conaidclr Eq. (2.4) at a point r,+l/l (n f # ) h mid-way between two lattice points:
= f(%,+l/l9
~ R + 1 / 2 )*
If we then use the symmetric difference approfinnatian for the derivative by the average of (the analog of (1.3b) with h -+$ h ) and replace its values at the two adjacent lattice points [the error in this replacement is O(h2)],we can write
wkich eorrespands to the recursioa, rel;ation
'
2.2 MulEli~teqpand inapilielib metfaads
This is iillwell and p o d , but the appearmce of g,+$ on both sides of this equation (an implicit equation) means that, in general, we must solve a non-trivial equation (for example, by the Newton-Raphson method discussed in Section 1.3) at each integration step; this can be very time eoctszlming. A particulas ~implification.occurs if f is linear in y, say f(gF3) = g(z)y, in which case (2.17) can be solved to give
When applied to the problem (2.7), where g(%) = --g, this method gives the results shown in the last tvvo columns of Tabfe 2.2; the quadratic behavior of the error with h is clear. Exercise 2.3 Apply the Taylor series method (2.10) and the implidt method (2.18) to the example of Eq. (2.7) and obtain the results shown in Table 2.1. Investigate the accuracy of integration to larger vdzles of z,
m
The Adas-Moulton. methods are bath mdtistep and implicit. For example, the Adams-Modton two-step method can be deriwd from (2.11) by using a quadratic polynomid passing through Awl,f,, asld
m,
&+l3
t o interpolate f over the region from I, to r,+l. The implicit recursion relation that resdts is
The corresponding three-step formula, obtained with a cubic polynomial interpolation, is
Implidt methods are rarely used by solving the implicit equation to take a step. Rather, they serve as bases for Upredictor-corrector" algorithms, in which a "prediction" for y,+l based only on an explicit method
31
is then 'korrected" to give a better value by using this prediction in an. implicit method. Such dgorithxns have the advantage of atlawing a e m tinuous monitoring of the accuracy of the integration, for exmpXe by making sure that the corre&ion is small. A commonly used predictorcorrector algorithm with local error O(h5)is obtained by using the explicit Adams-Bashforth four-step met hod (2.14) to make the prediction, and then caleul&ing the correction with the Adams-Maulton three-step method (2.201, using the predicted value of y,+l to evaluate f,+l on the right-hand Elide.
2.3 Runge-Kutta methods As you might gather Erom the preceding section, there is quite a bit 05 freedom. in writing down dgorithnrs for integating differentid equations and, in fact, a large number of them exist, each having it atvn pecdiarlties and advmtages, One very convenie~tand widely used cla9.s of methods are the Range-Kutta dgorithms, whielt come in varyiag orders of accuracy, We derive here a second-order mrsion to @ve the spirit of the appromh and then simply state the equations for the third- and carnmoxliy used fourth-order methods, To derive a second-order Runge-Kutt a algorithm (there are actually a whde fmily of t b m chmacterized by a continuous parmetef), we approximate f in the integral of (2.11) by its Taylor series expansion about the mid-polnt of the intepation intervat. Thus,
where the error arises from the quadratic term in the Taylor series, as the linear term integrates to zero. Although it seems as if we need to know the appearing in f in the right-hand side of this equation for vdue of g,+, it to be of any use, this is not quite true. Since the error term is already O(h3),an approximation to y,+l whose error is O(h2)is good enough. This is just what is provided by the simple Euler's method, Eq. (2.6). Thus, if we define k to be an intermediate approximation to twice the difference between g,+,/, and y, the following two-step procedure gives y,+l in terms af g%:
This is a second-order Runge-Kutta algorithm. It embodies the general idea of substituting approximations for the values of y into the right-hand
side of implicit expressions involving f . It is as accurate as the Taylor series or implicit methods (2.10) or (2.171, respectively, but places no special constraints on f , such as easy differentiability or linearity in y. It also uses the value of y at only one previous point, in contrast to the multipoint methods discussed above. However, (2.22) does require the evafuatGion of f twietj for each step dong the lattice. Range-Kutta schemes of higher-order can be derived in a relatively straightforward way. Any of the quadratare formulas discussed in Chapter 1can be used to approximate the integral (2.11) by a finite sum of f d u e s , For example, Sirnipson's mle yields
Schemes for generating successive approximations to the g's appewiing in the right-hmd side of a commensurate accuracy then complete the algorithms. A third-order algorithm with a local error O(h4)is
It is based on (2.23) and requires three evaluations of f per step. A fourth-order algorltbm, whieb r e q ~ r e sf to be evaluated four times for each integration step and has a local accuracy of O(hS),has been found by experience to give the beat balance betwmn accurwy and computational egort. Id can be written as fouows, with the ki as intemediate va~iabXes:
Exercise 2.4 Try out the second-, third-, and fourth-order RungeKutta methods discussed above on the problem defined by Eq. (2.7). Compare the camput ationd eEort for a given accuracy with that of other methods.
W
r Exercise 2.5 The two coupled first-o&r equatims
define simple harmonic motion with period 1. By generdizing one of the single-variable formulas given above to this two-variable case, integrate thege equations with any particular initid conditions you choose and investigate the aceurwy with whi& the system returns to its initial state at integrd valum of t.
2.4 Stability A major consideration in integating &Rerentid equations is the Burnericd stability of the dgorithm used; i.e., the extent to whick rouad-off or other errors in the namericd computation em be ampfified, in many cases enough ifar this "noise" to dominate the resuks, To illustrate the problenr, let us attempt to improve; the accuracy of Euler's method and approximate the derivative in (2'4) directly by the symmetric difference approximation (1.3b). We thereby obtain the three- term recursion relation g%+%= 3,-2 4- 2hf(gn,gn) 4- 0 ( h 3 )9 (2.27) which superficidb looks about as useful as either of the third-order formulas (2.10) or (2.18). However, consider what happens when this method is applied to the problem
whose solution is y = em". To start the recursion relation (2.271, we need the vdue of y, as well as go = 1. This can be obtained by using (2.10) to
(This is just the Taylor series for emh.) The following FORTRAN program then uses the method (2.27) to find y for vdues of r up to 6 using the vdue of h input:
8.4 Stability
Table 2.2
C: chap=lb.for IQ PRIHT *,"n%er 8UD
*,
Integration of d g l d z = --g with g ( @ )-- X
vdue of step size ( .Is, O to step)"
E
XF (H .LE. O) STOP P;lutIrnS=rzi YZEM=i.-EI+H+*2/2 ISmP=6./B BQ 20 ZX=2,15TEP X=IX*H WLUS=YPUIIWS-IZ+B+TZE mImS=TZEEO
!V(O) I P (B)
tZsop over X vdtles !X at this step !Y frem Eq. 2.27 Iro23, vaXaarzr
Y-ZIERQ=YPLVS
EXACT=EXP(-X) *, X,EXAm,EXAm-YZEW
20
l g t i c valas at this p o h t
PRINT COITXmE;
Note how the three-term recursion is implemented by keeping track three local variables, YPLUS, YZERO, and YMINUS. A portion of the output oS tkjs code run for h -. 6.1 is shown in Table 2.2. For s m d values of I, the numerical solution is only slightly larger than the exact value, the error being consistent with the O(h3) estimate. Then, near z = 3.5, an oscillation begins to develop in the numerical solution, which becomes dternately higher and lower than the exact values lattice point by lattice point. This oscillation grows larger as the equation is integrated further (see values near z = 6 ) , eventually overwhelming the exponentially decreasing behavior expected. The phenomenon observed above is a symptom of an instability in the algorithm (2.27). It can be understood as follows. For the problem of only
35
(2.28), the recursion relation (2.27) reads
We can solve this equation by assuming an exponential solution of the form g, = AT" where A and r are constants. Substituting into (2.29) then results in an equatim for F,
the constant A being unimportant since the recursion relation is lines. The salations of tbis equatlon are
nrhere we have indicated approxinraeions valid for h < I, The positive root is sEgHtly less than m e and eone8po1lds to the expomutidy decreasing solution we are after. However, the negative root is slightly less thaa --X, and so corresponds to a spurious solution
whose m-itude increases with n and which oscillates ffom fat;tfce point to lattice point, The general solution to the linear difference equation (2.27) is a linear combination of these two exponentid solutions, Even though we m'tght carefully arrrtnge the initial vdues ya and yl so that only the d e c r e ~ i n g sdution is present Tor smalt s, numericd round-off during the recursion relation [Eq. (2.29) shows that two pasitive quantities are subtracted to obtain a smaller one] will introduce a amall admixture of the "bad" solution that will ewntualfy @W to domin&e the results, This instability is dearly wsociated with the thme-tern nature of tbe recursion rdation (2.29). A good rule of thumb is that instabilities and round-off problems should be watched for whenever integrating a sdutim that decreases strongly as the iteration proceeds; such a situation should therefore be avoided, if possible. We will see the s m e sort of instability phenomenon ag&nin our discussion of second-order diRerentid equatians in Chanter 3. Exweise 2.6 Investigate the stability of sever& other integralion methods discussed in this chapter by apphing them to the problem (2.28). Can you give analytical arguments to explain the results you obtain?
B
g.5 Order and chaos in two-dimensional motion
2.5 Order and chaos in two-dimensional mation A fundamental, advantage of. udng computers in physics is the ability to treat systems that caxlnot be sdved astdyticdly, In the usual situation, the numerical resdts gmeraited agree qu&tatively with the intnition W h a t developed by studfirtg soluble models and it is the quantitaive values that are of real interest. However9 in a few cases computer results defy our intuition (and thereby reshape it) and numerical work is then essentiat for a p r v e r understanding. Surprisindy, such cases include the dynmics of simple classic& systems, where the generic behavior diEers quala'tcatively from that Qf the models covered in a traditiond Mechanics course. In this example, we will study mme of this surprising behavior by intepat;ing numerically the trajectories of a partide moving in two dimensions. General discussions of these systems can be found in [Hego], [Ri80], and [Ab78]. WC? consider a particle of unit mass moving in a potentid, V, in two dimensions and a4sunte that V is such that the particle remains confined for all times if its energy is low enough, E the momenta can,jug&e to the two coordinates ( s , g ) are (p,, p,), then the Hamiltonian takes the form
Given any particular initid v d u e ~of the coordinates and nromenta, the particle's trajectory is spedfied by their time evolution, which is governed by four coupled first-order differentid equations (Hamilton's equations):
For any V, these equations conserve the energy, E, so that the constraint
restrict S the trajectory to lie in a thre-dirnensiond manifold embedded in the four-dimensional phase space. Apart from this, there are very few other geaerd statements that caa be made about the evolution of the system. One impart ant class of two-dimensional Hamiltonians for which additiond statements about the trajectories can be made are those that ape
37
38
2. Oranary Biflemnitlial Equations
intwrabke. Far these potentids, there is a semnd function 06 the coordinates and momenta, apart from the energy, that is a constant of the motion; the trajectory is thus canstsrtined to a two-dimensionat ma6fold of the phase space. Two familiar kinds of integrable systems are separable an& wntral potentids. h the separable c a ~ ,
where the V,*, are two independent functions, so that the Hamiltonian separates into t w pards, each involving mly one wordinate and its conjugate momentum,
The mations in a: and g therefm deeouplt,from each other and each of the is separately a constant of the motion. (Equivalently, Hamiltonians ESPY H, - E, is the second quantity conserved in addition to E = H, + h.) In the ease of a centrd poteatid,
so that the angular momentum, p8 = %p, - yp,, is the second constant of the motion and the Hmiftonian can be written m
Pthwe p, is the zraolnenturn conjug& to r. The aCt&tiorrd constraint on the trajectory present in integrable systems allows the equations of motion to be "solved" by reducing the problem to one of evaluating certain integrals, much as we did for one-dimensional motion in Chapter 1. All of the familiar analytically soluble problems of classical mechanics are those that are integable, Although the dynamics of integrable systems are simple, it is often not at aI1 easy to make this simplidty apparent. There is no general analytical method for deciding if there is a second constmt of the motion in an arbitrary potential or for finding it if there is one. Numerical calculations are not obviously any better, as these supply only the trajectory for given initial conditions and this trajectory can be quite complicated liar cases, as can be seen by recdling the Lissajous patterns
h.5 Ondc?rand chaos in two-dimensional motion
Figme 2.3 Ikajectode~of a particge in a two-dimens;iana;l separaplanes, Several ~ n (g,py) d ble potentid as they appear in the trajectorim corrmpa~&rrgto the s m e energy but di@erentinitid condiljone me shorn. najectories A and E are the gmiting ones h a ~ n g vanlshina; .Egand E@,rmpwtively.
of the
(2,g)
trajectories that arise when the motion in both coordinates
An analyds in phase space sugests one way to detect integrability from the trajeetary done. Consider, for exmple, the caae of a sepafable potent;id. Be~ausethe motions of each of the two coordinates are indepeadent, plots of a trajectory in the ($,p,) and ($,py)planes might look as shown in Figure 2.1. Here, we have assumed that each potential V = ,hrzs a single &Rjmum vdue of 0 at particular vdues of z a d g, respectively, The particle move8 on a closed contaur in each of these two-dimensional projections of the four-dirnensiond phase space, each contour looking like that for ordinay one-dirnensimd motion shown in Figure 1.3. The aseas of these contours depend upon how much energy is associated with each coordinate (i.e., E, and E,) and, as we consider trajectories with the s m e energy but with diEerent initid condlitions, the area of one coatour will sMnk as the other grouls. In each plwe t h m is a lidtine; contoar that is appraxhed when all of the energy is in that particular coordinate. These cantoars axe the intersections of the twedimensiand phasa-spaee manifolds containing each of the trajectories and the (y,py)or (z, p,) plot is therefare termed a "surfxe of seetiori." The efistence of them crlosed contours signds the integrability of t htr. sys-tem. Althon& we are able to construct F i e r e 2.1 only because WC?understand the integrable motion involved, a similar plot can Be abtained
39
Figwe 2.2 (Left) Toraid& mmgold coatalniag Ghe trajectory of a, pslrticle in a centrd potentid. (Right) Surface of ~ s t j o nthrough this m h f o l d ad 21 r=: 0.
;Eron %hef rgectory done, Suppoae that every t h e W &smm m e of the coordinates, say 2, to pass throuejh zero with pz > Q , W plot the locaf;ion of the partide on the (g, p,) plane. In other words, crossing through the z = 0 plane in a positive sense triaers a Ustroboscopenwith which art! observe the (y,p,) variables. If the periods of the 2 and y motions are incommensurate (i.e., their ratio is an irrational number), then, as the trajectory proceeds, these observations will gradudy trace out the full (g,p,) contour; if the periods are commensurate (i.e., a rational ratio), then a series of discrete points around the contour will result. In this way, we can study the topology of the phase space associated with any given tonian just from the trajectories alone. The general topology of the phase space for an integrable Hamiltonian can be iUustrated by considering motion in a central potential. For fixed vdues of the energy and angular momentum, the radial motion i s bounded between two turning points, pin and rout,which are the solutions of the equation n
These two radii define an annulus in the (E, y) plane to which the trajectory is confined, as shown in the left-hand side of Figure 2.2. Furthemore,
h.6 Qrdttr and chaos in tzoa-dimensiond mot-l"on 4%
Figme 2,8 Pmible batuxez~of the sudwe mtion af a general integrable system. E a ~ H d label elliptic m d hyperbdic fixed points, respectively, wjhife the curve labded S is a sepaszttrix,
for a fixed value of r , energy conservation permits the radial momentum to take on o d y one of twa d u e s ,
These momenta define the two-dimensional manifold in the (I, y,p,) space that contains the trajecdosy; it charly has the tapdogy of a torus, as shown in the left-hand side of Figure 2.2. If we were to construct a (gypy) sudace of section by emsidering the z = 0 plane, are would obtain two dosed contours, as shown in the right-hand side of Figure 2.2. (Note that y = r when I = 0.) If the energy is fixed but the angular momentum is changed by vi~rybgthe initial conditions, the dimensions of this torus change, as does the m a of the contour in the sudace of section, The toroidal topoloa of the phase space of a central potential cian be shown to be common to all i n t e ~ a b bsystems. The manifold on which
the trajectory lies for @venvdaes of the consta~tsof the motion is c d e d an u"imrimt toms," and these a ~ tm a y of them for a gven mergy. The general surface of section of such tori looks like that s h m n in Figure 2.3. There me cefiajrr k e d points asodated with trajectories that repeat themselves exactly after same pefiod, The elliptic fixed points correspond to trajectories thafr are stable under smafl perturbations. Around e x h of them is a family of tori, bounded by a sepasatrix. The hyperboEc fixed pdnts occur at the Intersectioas of sepruratdces and me stabb under perturbations dong one of the wes of the hyperbda, but unstabb d m g the ather * An interesting guestion, is @Whathappens to the lori of an infqmblr: &@em under a perturbatha that destmys the integprtbihty cif the Hamittonian B", For sma31 perturbatiom, 'host" of the tori about an eBiptic fixed point become slightly distorted but retain their topology (the KAM theorem due to Kolmogorov, Arnold, and Maser, [Ar68]). However, adjacent reg;ions of phase spwe become "chmtic", dving sudwes of section that are a seemingty random splatter af points. Within these chaotic regions =CS nested yet other &ptk fixed point;s and other chaatic regions in a fantastic hierarchy. (See Figure 2.4.) Large deviations from integrability must be invegtigated numerically. One convenient case for doing so is the potentid
which was originally introduced by HQnon and IIeiles in the study of stellar orbits thro~gha gilrlaxy [He64]. This potential can be thought of as a perturbed harmonic osciuator potential (a small constant multiplying the cubic terms can be absorbed through a rescaling of the coordinates and energy, so that the magnitude of the energy becomes a measure of the deviation from integrability) and has the three-fold symmetry shown in Figure 2.5. The potential is zero at the origin and becomes unbounded for lasge values of the coordinates. However, for energies less than 116, the trajectories remain confined within the equilateral triangle shown. The FORTRAN program for Example 2, whose source code is contained in Appendix B and in the file EXMPL2.FOR, constructs surfaces of section for the B6non-WcliXles poteatid, The method used is to integrate the equations of motion (2.31) using the fourth-order Runge-Kutta algorithm (2.25). Initial conditions are spedfied by putting s = O and by giving the energy, g, and p,; p, is then fixed by energy conservation. As the integration proceeds, the (s,g) trajectory and the (y,p,) surface
i9.5 Qder and chaos in two-drimensional motion
Figure 2.4 Nested tori for a. slljightly perturbed integrable system, Note the hierarchy of eltliptk orbits inlerspersed with chwtic regions. A magnification af this hierarchy would show the same pattern repeat& on a smdler scale and so on, ad trrfiitum. (Reproduced &am [Ab78],)
of section u e displayed. Pointis on. the latter are calculated by w;tt;ching for a time step duPing which a: changes sign. When this happms, the precise l~clitti~n of the point an the surface of section plot i s determined by switching t o 2 a~ the independent variable, so that the equations of motion (2.31) beeorne
and then integating one step bwkwasd in a: from its vdue after the time step to 0 [He82]. If the value of the energy is not changed when new initial conditions are specified, all previous surface of sectisn pdnts c m be plotted, so that plots like those in Figures 2.3 and 2.4 can be built up after some time. The p r o g m exploits a symmetry of the Henon-X-feiles equations af motion t o obtain two trajectories &om one set of initid conditio~s,This symmetry can be seen from the equations of motion which me invariant
43
Valley
Figure 2.8
muipolentiait eont;ours of the IXknani-XXe3es potentid,
Eq, (2.35).
if + -+ -I and p, -+ -p,. Therefore from one trajectory we can trivially obtain a "reflected" trajectory by flipping the sign of both I and p, at each point along the original trajectory. More specifically, if we are interested in creating the surface of section on the z = 0 plane we $ready have z = -g, and only the sign of p, must be changed. Practically this means that every time we cross the I = 0 plane we take the comesponding y and p, values to be on the surface of section, without consideration for the sign of p,. If p, is greater than zero it is a point from the initial trajectory, while if p, is less than zero then that point belongs to the reBected trajectory.
2.5 Oder and chaoe in two-9mensitrnal motion
The following exercises are aimed at improving your understanding of the physical principles and numerical methods demonstrated in this example, Exercise 2.7 One necessary (but not suffident) cheek of the aecuracy of the integration in Hamiltonian systems is the conservation of energy. Change the time step used and observe how this affects the accuracy. Replace the integration method by one of the other dgorithms discussed in this chapter and observe the change in accurrccy and eficiency, Note that we require an algorithm that is both accurate and eficient because of the very long integration times that must be considered. kxercise 2.8 Change the potential to a central one (function subroutine V) and observe the character of the (z, y) trajectories and surfaces of section for v a ~ o n sinitial conditions. Compwe the resub with Figure 2.2. and verify that the quatative hatares don't change if you use a diEerent centrd patentid. N d e that yaa wi11 have to adjust the energy and scale of the potential M, that the (r,y) trajectory does not go beyond the equilateral triangle of the HQnon-Heilespotential (Figure 2.5) or else the grapEcs subroutine will fail,
U
Exercise 2.9 If the sign of the y3 term in the Henon-Heiles potential (2.35) is reversed, the Hamiltonian becomes integrable. Verify andyticdy that this is so 'by making a canonicd trmsformation to the variables zrf: y and showing that the potentid is sepasabl~in these variables. MafEe the corresponding chmge in sign in the GO& and &save the character of the sadaces of metion that result for various injtid conditions at a given energy. (You should keep the energy below 1/12 to avoid having the trajectory become unbounded.) Verify that there are no qualitative differences if you use a different separable potential, say the harmonic one of Eq. (2.34). m
U
Exereiw 2.10 Use the code to construct surface8 of section for the
Hhnon-Heiles potentid (2.35) at ener@es ranging from 0.025 to 0.15 in steps of 0.025. For each enera, consider various initid conditions and integrate each trajectory long enough in time (some will require going to t m 1100) to map out the surface-of-section adequateb. For each energy, see if you can find the elliptic fixed points, the tori (and tori of tori) around them, and the chaotic regions of phaee space and observe how the relative proportions of each change with increasing energy. With some patience and practice, you should be able to generate a plot that resembles the schematic representation of Figure 2.4 around each elliptic trajectory.
45
46
h. Ordinary Diflemntial Equations
Project 11: The structure of white dwarf stars White dwarf stars are cold Objects eomiposed largely of heavy nudel and thdr associated electrons. These stms me one possible end result of the conventiond nuclear proces8es that build the elements by binding rrrrcfeons into nuclei. They are often composed of the most stable nudeus, '@Fe, with 26 protons and 30 neutrons, but, if the nucleosynthesis terminates prematurely, C nudei might predominate. The structure of a w&te dwad star is detemined by the interplay between pavity, wEch acts to cornpress the star, and the degeneracy pressure of the electrons, vvhicb tends to resist eompressim. fn this project, we will investjgate the structure of a white dwasf by integrating the equations dtefiniq this eqrtiXibfiurn. VCTe W% determine, among other things, the rdation between the stark rnahts a d its radius, quasltiLies that can be deterxnined ffsm observation. Discussions of the p2rysics of wkite d w d s can be found in [Ch57], [Ch84], and [Sh83].
11.1 The equations o f equilibrium We assume that the star is sphericalk symmetric (i.e., the state of matter at any given point in the star depends only upon the distance of that point from the star's center), that it is not rotating, and that the effects of magnetic fields are not important. If the star is in mechanical (hydrostatic) equilibrium, the gravitational force on each bit of matter is balanced by the force due to spatial variation of the pressure, P. The gravitational force acting on a unit volume of matter at a radius r is
F,.,
Cm
= --z,
P?
where G is the gravitational constant, p(r) is the mass density, and m(r) is the mass of the star interior to the radius r :
The force per unit volume of matter due to the changing pressure is -dP/dr. When the star is in equilibrium, the net force (gravitational plus pressure) on each bit of matter vanishes, so that, using (II.1), we
11. The st;ruckre of white dwarf star8
A digereatid relation betwen the anss and the density can be obtained by differentiating (11.2):
The description is completed by specifying the "equation of state," an intrinsic property of the matter giving the pressure, P(p), required to maintain it at a given density. Upon using the identity
Eq. (11.3) can be written as
Equations (11.4) and (11.5) are two coupled first-order differential equat;ims that determine the structure of the star for a given equation of state, The v d u a of the depeadent variables at r = O a e p = p,, the central density, and m = 0. 1ntegr;hlim outward in r then giws the density profie, the radius of the star, R, being detemined By the point at which p vanishes. (On very general grounds, we expect the density to decrease with increasing distance from the center.) The total mass of the star is then M = m(&). Since both R and M depend upon p,, variation of this parameter d a w s stass of rligerent masa; to be studied,
11.2 The equation of state We must now deternine the equatioxl of s h t e appropri&e fctr a white dvvad. As ment:ioned above, we will assume that the matter consists of large nuclei aad th&r electrons, The nuclei, b e i q heavy, cont;ribute nearly atl of the mass but make almost; no contribuLim to the pressure, since they hardly move about at. d.The dectmns, hwever, contribute virtudly abl of the pressure but essenlidy none of the mass, VVe will be intexsted in densities fas ge&er than that of ordinmy mat;ter, where the electrons am no longer bound to individuitl nuclei, but mther move fredy ~ af electrons thmufi the naakrid. A good model is then a free F e r gas at zero tamperiature, treated with relativistic Xcfnematics. h r matter at; a. @ven mass densi.2,~~ the numb= density of electrons
47
where M, is the proton mass (we neglect the small difference between the neutron and proton masses) and Y, is the number of electrons per nucleon. If the nudei are all $@Fe,then
4
while Ye = if the nuclei are I2C; electrical neutraiity of the matter requires one electron for every protoll. The free Femi gas is studied by considering a large volume If containing N electrons that occupy the lowest energy plane-wave states with momentum p < pt. Remembering the two-fold spin degeneracy of each plarie wave, we have
where n = N / V . (We put h = e = 1 unless indicated explidtb.) The totat energy density sf thege electrons i s
whicfi can be integitted to @vet
% ( l2 + z2)(1 f I ~ ) ~ - log /~
The variaMe z chasacberizes the electron density in terms of
the density at which the Fermi momentum is equal to the electron mass, m,*
11. The &tmrchins,aJ"white dwarf stars G mmner, the pressure is related to how In the usual thermodyn the eneru chwges with volume at k e d N :
Using (11.10~)to find
and differentiating (II.lOa,b) results in
where c' = de/ dz. It is now straightforward to calculate dP/dp. Since P is most naturally expressed in terms of ,I we must relate I to p. This i s most easily done using (11.10~)and (11.6):
Thus, p0 is the mass density of matter in which the electron density is no. Differentiating the pressure and using (11.12, II.13a) then yields, after some algebra,
49
11.3 Scaling the equations It is often usefd to xd-btee equations desellibing a physicd system to dimensiodess form, both for physical. insiglice and for xturnesicd convenience (i.e., to avoid dealing with very l a g e or very s m d nwnbers in the computer), To do this for the equations of white dwasf &metare, we introdwe dimensiodess radius, density, and milss vwiables:
with the ra&us and mass scdes, & and Ma, to be deternzined for convenience. Substituting into Eqs. (IIe4,11.5) and using (11.14) yields, after some reanangement ,
If we now choose MO and & so that the coeEeients in pmerrtheses in these two equ&ions are unity, we find
a ~ tdhe dimensiadess diEerential equations me
g that 7 i s given by Eq. (11.14) These equations axe compkted by rec with r = p'/3. The scaling quantities (II.13b) and (II.17) tell us how to relate the structures of stars with digerent Ye and hence reduce the nnnnericd work to be done. Spedfiedy, if we have the solution for Ye = 1 at some value of pc = p,/po, then the solution at any other Ye is obtained by scaling the density as Y;', the radius as Ye,and the mass as Y .:
J% The structurcl? of while dwarf stars
To give some feeling for the scales (11. IT), recall that the solar radius and mms axe
while the density at the center of the sun is m 1150 gm cmw3. We therefore expect white dwarf stars to have masses comparable to a solar mass, but their radii will be considerably smaller and their densities will be much higher.
11.4 Solving the equations We are now in a position to solve the equations and determine the properties of a white d w d . This cm be done in the folladng sequence af steps. Step 1 Verify the steps in the derivations given above. Determine the leading behavior of E and 7 in the extreme non-relativistic (z &: 1) and relativistic ( x > 1) limits and verify that these are what you expect from simple arguments. Andyze Eqs. (II.IBa,b) when ifs and F are finite and p is smdl to shsw thztO j? vanishes at a finite ra&us; the star therefore has a well-defined surface. Determine the function4 form with whieh p vmishes near the surf=@. Step 2 Write a program to integrate Eqs. (11.18) outward from F = O for Ye = f , Calculate the density p r d e s , total masses, and. radii of stars with selected d u e s of the dinaeasimbss centrd density p, ranging from 10-' to 1Q6.By changing the radial step and the integration algorithm, verify that your s~lutionswe accurate, Show that the totd kinetic and rest enera of the electrans in the star is
where E/V is the energy density given by (11.10) and that the total gravitatimal energy of the star can be written as
Use the scaling discussed above to cast these integrals in dimensionless form and calculate these energies for the solutions you've generated. Try to understand all of the trends you observe through simple physicat reasoning.
51
r Step 3 A commady tl~edde~clLiptimof stellar slrructuse involves a
pdytropic equation of state,
where PO,p0 ,and l? are constants, the latter being the adiabatic index. By suitably scaling Eqs. (II.4,5), show that a star with a polytropic equation of state obeys Eqs. (11.18) with
The degenerate electron gas therefore corresponds to F = 413 in the extreme relativistic (high-density) h i t and I? = 513 in the extreme nonrelativistic (low-density) limit. Patropic equations of state provide a simple way to dudy the effects of varying the equation of state (by changing l?) and also give, for two spedd vdnes of r", andytieal solutions wainst whieh numericill so~ checked, For this latter palpose, if is most convenient lutions c a be to recast Eqs. (11.18) as a single second-order differential equation for p by solving (II.18a) for and then differentiating with respect to f and using (II.18b). Show that the differential equation that results (the LaneEmden equation, [Ch57]) is
and that far ]E'
==
2 the mlutian i s
p 'pc-sin r" F
*
while for I? = 615 the solution is
Use these analytical solutions to check the code you wrote in Step 2. Then study the structure of stars with different adiabatic indexes I? and interpret the results,
I ' The struct-UFY? of ullaile &a$ stars N
Step 4 If things are working correctly, you should find that, as the
central density of a white dwarf increases, its mass approaches a limiting value, (the Chandrasekhar mass, MCh)and the star becomes very small. To understand tkis aad to get an estimat;e of Mch, we cm faurn the steps in an argument originally given by Landau in 1932. The total energy of the star is composed of the gravitational energy (W < 0) and the internd energy of the matter (U > 0). Assume that a star of a given total mass has a constant density profile. (This is not a very good assumption for quantitative purposes, but it is valid enough to be useful in understanding the situation.) The radius is therefore related simply to the total mass and the eonstmt density, Calculate U and W h r this density profile, assuming that the density is high enough so that the electrons can be treated in the relativistic limit. Show that both energies scale as 1/R and that W dodrriltes Zf when the totd mass exceeds a cert%incriticd vdue. It then becomes energetically favorable for the star to collapse (shrink its radius to zero). Estimate the Chandrasekbar mass in this way and compare it to the =salt of your numeric& calculation, Also verify the correcgness of this rtrgumexlt by showing th& U and W for your solutions found in Step 2 become equal and opposite as the star .approaches the finriting mass, Seep F; Scde the mass-radius rdation you found in Step 1 to the cases and I2C nuclei. Three white dwarf stars, Sirius B, corresponding to 40 Eri B, and Stein 2051, have masses and radii (in units of the solar values) determined from observation to be (1.053 f0.028,0.0074& 0.0006), (0.48 it 0.02, 0.0124 0.0005), and (0.50 k 0.05 or 0.72 f.0.08, 0.0115 f 0.00 121, respectively [Sh83]. Verify that these values axe consistent wit h the model we hwe developed. What can you say abbot the compositions of thege stws? m
53
This page intentionally left blank
Chapter 3
Bound
Many of the important differentid equations of physics can be cast in the Earm of a linear, second-order equalim:
where S i s an inhomogeneous ("drivingn) term and k2 is a real function. When kZ is positive, the solutions of the homogeneous equation (i.e., S = 0) are oscillatory with local wavenumber k,while when k2 is negative, the solutions grow or decay exponentidly at a local rate (- kZ)* . For example, consider trying t o find the dectrostatic poteratiaf, @, generated by a localized charge distribution, p(r). Poisson's equation is
which, far a spbericdly symmetric p and Qtr, simplifies to
The standard substitution
then results in which is of the form (3.1) with kZ = 0 and S = -4rrrp. In a similar manner, the quantum m e c h ~ e awave l fanetion, for a partide of mass m
56
S. Boundarq, Value and Eigenvalue Problems
and energy E moving in a central potential V ( ? )can be written as where YAMis a sghericd harmonic and the radid wave function R satisfies
This is also of the form (3.11, with S = 0. The equations discussed above appeas unremarkable and readily treated by the methods discussed in Chapter 2, except for two points. First, the boundary conditions imposed by the physics often appear as constrdnts on the deptjndent vdablr, at t m sepmfe points of tke independent variable, so that solution as an initial d u e problem is not obviously possible. Moreover, the Sehroedinger equation (3.5) is an eigenvdue t the energies that had to physicdy acequatim in which we m u ~ jsad ceptable solutions satisfying the appropriate boundary eonditiws. This chapter is concerned with methods for treating such problems. We begin by deriving aa integration atgorithm parlieulaxly well suited to equal;ims of the form (3.1), and then discuss boundary value and eigenvalue problems in turn.
3.1 The Numerov algorithm There is a particuldy simple an& eficient method for integating secondorder differential equations having the form of (3.1). To derive this method, cammonly c d e d the Numerov or Cowling's method, we begin by approximating the second derivative in (3.1) by the three-point difference formula (1.7),
where we have written out explicitly the 6 ( h 2 ) "error" term, which i s derived easily from the Taylor expansion (1.1, 1.2a). From the differentid equation itself, we hitve
3.8 Birst integmtfiorz of boundarg value pr~bbms 57
When this i s substituted into (3.6), we can write, after some rearrangement,
Solving this finear equation for either gn+1 or gn-l then. provides a recursion relation. for integrating &ther forwxd or bukward in s, with a. bcal
error O(hs). Note that this is one order more accurate than the fourthorder Runge-Kutta method (2.25), which might be used to integrate the problem as; two coupbd first-order equations. The Nunrerw seheme is also more efficient, as each step requires the computation of k2 and S at only the lattice points, Exercise 3.1
Apply the Numerov dgorithm to the pmblem
e~ Iategrate from s = 0 to a: = 1 with vwious ~ t e p~ i z and the eaciency a ~ l dxcuracy with some of the methods discussed in Chapter 2. Note that yon will have to use some h;pedd prowdure (e.g., a Taylor series) to generate the value of yl E y(h) needed to start the three- term recursion relation. 3.2 Direct integration of boundary value problems As a concrete illustration of boundmy value problems, consider trying to solve Poisson's equation (3.4) when the charge distribution i s
wEch has a told charge
The e x x t solution to this problem is b +(F) = I - -(v 2)e-', (3.10) 2 from which @ = r-'# follows immediately. This solution has the expected behavior at large r , 4 4 1, which corresponds to 4! -+ v-', the Coulomb potential frm a unit charge.
+
58
9;
Boundary Vhlue and Eigenvalue Problems
Suppose that we try to solve this example as ;an ordinmy initial vdue problem. Since p has no singular behavior at the origin (e.g., there is no point charge), @ is regular there, which implies that 4 = rQ vanishes at r = 0; this is indeed the case for the explicit solution (3.10). We could then integrate (3.4) outward from the origin using the appropriate rearrangement of (3.8) (recall k2 = 0 here):
However, to do so we must know the value of (or, equivalently, d+/dr = O at r = 0) in addition to q ! ~= 0. This is not a very happy situation, s i n e gSil is part of the very function we're tr~ringto find, and go is not knovvn a pva'ori. We will discuss below what to 1Co in the generd c m , but in the pre~entexmpk, &nee we have asl mdytical golutim, m cm find = $(P = h) from (3.10). The following FORTRAN program does the antward integration to r = 20, storing the sxrlution in m &gray and printing the exact r e d t and efror as it gws along. G cbp3a.for
BIEmSTOM PHI(0:200) EXACT(R)=1 (E+2)*EXP(-B)/2 SOUME(R) S-R*EXP (-R) 12 H=.$ I.
-
ISmP=20./eE C01ST=8*+2/12 SMI=O.
SZ=SOURCE(E) PHX(a)=o PHI( l)=EXkGI"(B) ao 10 XB=I,IS~P-I R=(IB+l)*B SX"=SOUECECR)
!=ray for %he solm%fun ? exact solm%iorr !sowce i w e tion
!xa&ia step !nmber o f p i n t a to R=20 ! ~ o m t a tin E-erov method !arouce; a$ R=O Iso-ca at MB[ i b ~ m d w~ ~ ~ d iatt R=O i ~ n !exact value a% Sfrst poiat rloop ior O U ~ W W ~i x t e ~ a t i o n ?radius a% next point. !sowee a% next poh% !Eq. 3.11
PH~(xR+~)~~+PHI(TR)-PEX(TR-I)+C:OIST*~SP+~~~ *SZ+SX] SM=SZ !roll v a n s s SZ=SP
PRXIS *, R,EXA~(R),P~I(IR+~),EXACT-FHI(IR;+II 10
CORTIrnE STOP
$3 D i m t intclgration of baundary value problems
Table 8.1
Errors in salving the Paisan pfablem defined by %a,
(3.4,3.9)
Note haw computation is minimized by kwping track of the vdues of S at the current and adjacent lattice points (SZ, SM, and SP) and by computing the constant h2/12 appeaing in the Numerov formula (3.11) &side of the ixltegration loop, Results genwated by this progrm axe giwn in the first three columns of Table 3.1, which show that the ~umericdso1af;ionis rather accurate for t however. Tbe error per step gets larger at large r small v, All is ~ o well, (the error after the 20 steps from T = 0 to r = 2 is 3 X 10-', while during the 20 steps from r = 18 to r = 20, it grows by 1.2 X IQ-', 4 times as much), and the solution afiB beeorne quite inaccurate if continued to even larger radii. This behavim is quitre surp~gingbecause the error6 in, the Numerov ietegration should be get.t;ing smdler at large r as gi becomes a constant. firther symptoms of a problem em be found by considePing a mare general caM. Mlt3 then h m RO andytical farmda to give us @ near the origin, which we need to get the three-term recursion relation started. One way to proceed is find @(0) by direct numerical quadratare of the Coulomb potentid,
perhaps using Simpson's rule. There will, however, dways be some error wsoeiated with the vdue obtajxled. We c m simulate such an, ermr in, the code above (suppose it is 5%) by inserting the line (just before the DO
59
fSO
S. Boundarg Value and Eigenualua Prablenas
The code then gives the ersors listed in the fourth cafumn of Table 3.1, Evidently disaster has struck, for a 5% &ange in the initial conditions has induced a 50% error in the solution at large r. Xt is simple to understand what hsts happened. Solutions to the homogeneous version of (3.4),
can be added to any particular solution of (3.4) to give yet another solution, There are tvvo linearly indepenhnt Iromogeneous solutions, and q5 W constant ; @
F-'
.
The general solution to (3.4) in the asymptotic region (where p vanishes and the equation i s homogeneous) can be written as a linear combination of these two functions, but the latter, sub-donainant soIution is the physical one, since we know the potentid at large r is given by @ -, l lr. hprecision in the gnecification of rP at the origin or any numericd roundoff e m in ehe inteeation process c m idroduce a, small admixtare of the at, large r. q5 p soXutim:,which eventudy do~xlale-s The cure fbr this diBeul"cy is &raightforward: subtrwt a multiple of the "'bad," anphysical solugion, to the homogeneaus ewatioll from the numerical result to guarantw the physical behavior in the wymptotie region. It is easy to see that the 'bad" results shown in the fourth column linearly with r for large r. The following lines of code (which can be inserted just before the n a p statement) then fit the last 10 points of the numericd solution to the form (and subtract mr from the numerical results to guarantee the angropriab large-r behavior.
9.8 Gmen'g finctisn golution of boundlsry value problem#
The errors in 4 so obtdned are shown in the final column of Table 3.1; the solution is emn more accur&e at large r than the uncorrected one found when the exact value of PHI(1) is used to start the integration. In this simple example, the instabilities we not too severe; satisfmtory rwults for moderate d u e s of r are obtained with outwasd integration when the exact (or reasonably accurate apprauimate) value of PHI(1) is used, Alternatively, it is also feasible to integate inwasd, otarting at lasge r 6 t h qi = Q,independent of r. This results in, a sdution that often satisfies aiecur&ely the boundasy mndition at r = 0 and avoids having to a quadratare to determine the (approximate) stmting value of
PHI(1). Solve the problem defined by Eqs. (3.4,3.9) by Numerov integation inward from large r using the known wymptotie behavior of tiJ fof the starting values. IIow welI do& your solution satisfy the boundary condition 4(r = 0) z= 01
m
Exercise 3.2
3.3 Green's function solution of boundary value proble When thc? twa salations to the homogeneous equation have very digerent behaviors, some extra precautions must be taken. For example, in describing the potential from a charge distribution of a multipole order l > 0, the monopole equation (3.4) is modified to
which has the two homogeneous solutions For large r , the first of these solutions is much larger than the second, so that ensuring the correct asymptotic behavior by subtracting a multiple of this dominant homogeneous solution from a particular solution we have found by outward integration is subject to large round-off errors. Inward integration is also unsatisfactory, in that the unphysical r-' solution is fikely to dominate at @maltr . One possible way to generate an accurate solution is by combining the two methods. Inward integration em be used to obtain the potentid for r greater than some intermediate radius, r,, and outward integration can be used for the potential when T < +m. As long as r , is chosen so that
61
162
3. Bsundarg Value and BigenuaZue Problems
neither homogeneous solutim is d o ~ a m tthe , outer and inner patenlids obtained respectively from these two integrations will match at F, and, together, descrjlbe the a t i r e sdution. Of course, if the inner and outer potmtids don't quite match, a mult;iple of the hamqeneous golution cm be added to the former to comect for m y hficiencies in aur knowledge of Qr(r= 0). Sometimes the two homogenmns solutions have sach &Eere& behwiars that it is impossible to find a d u e af r, that permits sartisfactory integration of the inner and outer potentids. Such cases can be solved by the Green's function of tlre homogeneous eqluatim. To illustrate, let us consider Eq. (3.1) with the boundary condition 4(x = 0) = #(r = m) = 0. Since the problem is linear, W can w ~ i t ethe sdution as
whert; G is a Green's suction sati~fying
It is clear that G satisfies the homogeneous equation far z f si. However, the derivative of G is discontinuousat I = z', as can be seen by integrating (3.14) from s = r f - E to z = zi f E, where E is an infinitesimal:
The problem, of course, is to find G. This can be done by eoxlsjderinig two solutions to the homogeneous problem, arnd (6>, ~.tltiSfSringtbe boundary conditions at rt: -- O and z = so, respective?ly,md nomaiized so that their Wrmslrian,
is unity. (It is easy to use the homogeneous equation to show that W is independent of 2). Then the Green's function is given by
where r , and z> are the smaller and larger of r and z', respectively. It is s and evident: Ghat this expression for G satisfies the h o m ~ e n e m eguatim the discontinuity condition (3.15). From (3.13), we then have the explidt
3.4 Eigenvaluedr of the wave egeralz'on
This expression can be evaluated by a numerical quadrature and is not subject to any of the stability problem we have seen associated with a direct integration of the inhomogeneous equation. and gi> can In the case of arbitrary kZ,the homogeneous solutions be found numericdly by ouward and inward integr&ions;, respectively, of initial value problems and then normalized to satisfy (3.16). However, for simple forms of k2(x), they are known analytically. For example, for the problem defined by Eq. (3.12), it is easy to show that
are one possible sel of hornqeneaus solutions satisfying the approplliatte boundary conditions and Eq. (3.16). Exercise 3.3 Solve the problem definedby Eqs. (3.9, 3.12) for I = O using the Green's function method. Compare your resdts with those obtajned by direct integration and with the andyticd solution.
m
r Exercise 3.4
Sphel.iedly sy
etric solvtioas to the equa;t;ian
l e d to the ordinary diRerenlia1 equation
with the boundary conditions 4(r = 0) = +(P -r W) = 0. Here, a is a constaat. Write a program %osolve this problem using the Green's function when p is given by Eq. (3.9). Compare your numerical results fir varims; v d u e ~Of a with the andytical golution,
What happens if you try to solve this problem by integrating only inward or only outward? What happens if you try a solution by integrating inwmd and outward to an intermediate zn&ching radius? Bow do your results change when you v a y the rnalching radius?
63
84
3. Boundarg Vialwe and Eigenvalue Problem8
3.4 Eigenvalues o f the wave equation Eigenvalue problems involving differential equations often arise in finding the normal-mode solutions of wave equations. As a simple example with wEch to iuustrate a method of solution, we consider the normal modes of a stretched string of uniform mass dendty. After a suitable scaling of the physical quantities, the equation a d boundary conditions defining these modes cm be mitten zw
Here, Q < 5 < I is the aeded coordinate dong the string, 4 is the transverse displxement of the string, and k: is the constant wavenumber, line d y related to the frequency of vibration. This v a t i o n is an eiwnvdw equationi in the sense th%t solutions satisfying the boundary conditions exist only for particular values of k, {k,), which we must find. Furthermme, it is linear m d homogeneous, so th& the normdzation of the dgenfunction comesponding to any ol the k,, is not fixed, bat can be &osen for convenience. The (un-normalized) eigenfunctions and eigenvalues of this problem are weU-known analyticdly ;
+,,
km = nn ; g5n
sin nz3: ,
(3.20)
where n is a positive integer. Them provide a useful Gbe& of the nurnericd methods for solving thiz; problem. One suitable general strategy for numeric& solution of an eigenvdue problem is an itersltive oon. VVe? mesa a trial eigenva9ue and gemrate a solution by integrating the differential equation as a initial d u e problem. If the resulting solution does not satis@ the boundary conditions, we change the trial eigenvalue and integrate again, repeating the process until a trial eigenvalue is found for which the boundary conditions are s&sfied to within a predetermined tderanec;. For the problem at hand, this strategy (known picturesquely as the "shootingn method) can be implemented as follows. For emh trid value of k, we integrate forward from z = O with the initial conditions
The number 6 i s arbitra~yand can be &osen for convenience, since the problem we are solving is a homogeneous one and the normalization of the solutions is not specified. Upon integrating to s = 1, we will find, in general, a non-vanishing value of 4, since the trial eigenvalue will not be
3.4 Bigemvalues of the wave equation
one of the true eigenvdues. We must then readjust k and integrate ~ a i n , repeating the process until we find ~z = 1) = 0 to within a specified tolerance; we will have then found an eigenvalue and the corresponding eigenfunction. The problem of finding a value of k for which &(l)vanishes is a root-finding problem of the type discussed in Chapter 1. Note that the Newton-Raphson method i s inappropriate since we cannot differentiate explicitly the numerically determined value of #(l)with respect to k and the secant method could be dangerous, as there are many eigenvdues and it might be difficult to control the one to which the iterations will ultimately converge. Therefore, it is safest to use a simple search to locate an approximate eigenvdue and then, if desired, switdt to the more efidemtt secant methed. The following FORTRAN program finds the lowest eigenvalue of stretched string problem (3.19) by the shooting method described above, printing the trial eigenvdue as it goes along. The search (beginning at line 10) is terminated when the eigenvalue is determined within a preci. initial trial eigenvalue and the seareh step size are set sion of 1 0 ~ ~The in the second ~ n third d lines. C chp3b.for
RrnL K ! i n i t i a v a n s s t o stwt search
K=1.
BK=Z,
10
IfOU=S. E 4 5 CA= IITGRT(K, PHXP) PHIClW=tPHIP COmIWE K=K+DE CALL ImGRT (K,PHGP) IF (PHIP*PBTOm .LT. 0)
Em
iasmch t o l e r m t s !fi& FEIP a t f i r s t p e s a fox X: !save i n i t i a l PEIP value ing of search loop Iiacreatalz2; II ! c a ~ u l a t ePEIXP f o r t h i s X:
X=K-DX
THEB ! i f PBSP chagea sign, ba&
DK=DK/~
! and Wve3 t h e aeap
up
IF
IF (ABS(BK)
.m, mu) ~ o m$0 Ican$inue mtil fIK i s s m d 1 enough
EXACT=$.*ATAI(I.) PRIIT STGP
*,
p
!exartt v d m e ~ i
eigenvaae, error =\,EE,EXIm-g
65
643
S. Bouradarg Value and Eo'genvalue Pwblems
Ern !sabzoatina t o c d c d a % aphi(s=l)= FEZP for value of R h p a t SmWWIIE IITGRT(K, PIXIPI ItML K DATA I S ~ P 2001 / !8etap li9t;lice pmaeLers B=%.CBSmP PHIR=O. !i n i t i d canditians PHXZ=.0% CI)IST= (K*B) *+2/%2, !can;9tm%in Imszov meLhod, DQ IQ SX-2,NSmF-2 !forwad recmsian eo X=f FHTP=2*( 5 . -5.*CQm'5T] *PBX Z -( Z tCQBST)+PETPI !Eq 3 . 8 PEEP=PBIFI(%+CBIST) !the real o f Eq,3.8 PHIM=PHIZ ! r o l l valnes l
10
PBXZ=PIXIP COmXmB PRflT *, ZI,BEIP RErnEE
EBB
When run, this program generates results that converge to a value close to the exact answer, a, the error being caused by the finite integration. step and the vdue of TOZK. Exercise 3.5 Use the program above to find some of the higher eigend u e s . Note that the numaicd inzcuracies became greater as the eigenvdue increases and the integration of the more rapidly oscillating eigenfunction becomes inaccurate. Change the search algorithm to the more eBcient secaxlt method, How close does p r initial guess have to be in order to converge to a given eigenvdue? Change the code to correspond to the boundary eonditians
and verify that the numerical eigenvalues agree with the analytical values expected, Exercise 3.6 The wave equation in cylindrical geometry often leads to the eigenvalue problem
m
9.5 StaEt'onarg solutions of lfre one-dimensional Schroeditager equation
The andytical eigenfuactims are the re&= cylindricat Bessd funetian c->f order zero, the eigenvdues bdng the zeros of this function: Show that the substitution 9 = r-'f2# changes this equation into one for which the Mumerov dgarithaa is suitable and modify the code &m to solve this problem. Compare the numerical eigenvalues with the exact vdues.
3.5
Stationary solutions o f the one-dimensional Schroe-
dinger equation A. rich e x a p l e of the shooting method far .eigenvdue problems is the task of finding the stationary quantum states of a particle of mass m moving in a one-dimensional potential V(%).Well assume that V ( % has ) roughly the form shown in Figure 3.1: the potential beeome-s irtfinite at, r = and s =,.,g (i.e., there are 'walls" at these positions) and has a weEl somewhere in between. The timeindependent Schroedinger equation md boundary conditions defining the stationary states are [MeGB]
which is of the form (3.1) with
We must find the energies E (eigenvatues) for which there is a nonzero solution to this probXem. At one c>f these eigeavdues, W q e c t the eigenfunction to oscillate in the dassically dowed regions where E > V(+)and to behave exponentidly in the classically forbidden regions where E < v(%). Thus, there will be '4bound" solutions with E < 0, W&& are localized vvithin the well and decay exponenZ;idy toward the walls and gcontinuum" solutions with E > 0, which have roughly constant magnitude throughout the entire region between the walls, The eigenvalue problem defined by Eq. (3.21) can be solved by the shooting method. Supphse that we are seeking a bound state and so take a negative tdal eigenvalue. Upon integrating toward larger z from i m i n , we can generate a solution, +<, which increases exponentially through the clasicauy forbidden redon and then oscillates beyond .the left turaing pojnt in the classically allowed region (see the lower portion of Figure 3.1). If we were to continue integrating past the right turning point,
fir
68
S. Boundary Value and Eligenvalzre Pmblczms
Figwe 9,1 (Upper) Schematic patentid used in the dbcnmion of the one-~mensionatSclzrrzedinger equation, (hwer) Solutions $P<wd +> aP the Schraedinger eqnation at an arbitrary energ E < Q, The lef% turning point, is used m the matching point. When 6 is m eigeavalue, the de~vativeis continuous at the matching paint,
the integation, wodd become numericdly unstable since, even, at an exact eigenvalue where $<(z), = 0, there can be an admixture of the undesira;ble exponenliay gowing ~ ~ I u t i oAs a . a general rule, integration into a classicay forbidden region is fikefy to be inaceurat;e, Thmefort;, aYt each mergy it is wiser to epenerata a second solu.t;ian, $>, by inlegating from g,, toward s m a e r g. To determine whether the enegy is an E?igenvalue, and $> carr be compared a;t a msatehing point, s , cho~en so that neither integration will be inaccurate. (A convenient choice for s, is the left turning pcrint .) Since both and y5> satisfy a, homagenems equation, thdr nomalizations can dwaya be chosen so that the two functions are equal at r,. An eigenvalue is then signaled by equality of the desivatives at ;z, i.e., the sdutions naatGh smoothly; as is invoked in analyticd sQlvtions of such prablenns. Thus,
If we wpro~ma;t;ethe derivatives by thdr simplest finite diEerence approximations (1.4) using the points s , and $,-h, an equivalent condition is since the nomalizations have been chosen to guarantee +< (s, ) = +> (1,). The quantity in Eq. (3.23) is a convenient scale for the difference, which
+
9.5 Stationary solutions of t-he one-dimensional Schrwdi~gerquodian
can be chosen to make f V p i c d y of order unity. l t might be the value of at x, or the maximum value of ,$t or $>. Note that if there are no turning points (e.g., if E > 0 for a potential like that shown in Figure 3.1), then s , can be chosen anywhere, while if there are more than two turning points, three or more homogeneous solutions, each accurate in different regions, must be patched together. The program for Example 3, whose FORTRAN source code is given in Appendix B and in the R h EXMPE3,FOR, solves fof the seationmy states of a one-dimensional potential by the algorithm described above on a lattice of size determined by the parmeter EFTS. The potentid is assumed to be of the form V ( z ) = &v(z), where the dimensionless function v ( s ) has a minimum value of -1 and a maximum value of +l. (This can always be guaranteed by a suitable linear scaling of the energies.) If the coordinat;e is scded by a physied length a , the Shrwdinger equation (3.21) can be written as
where
is a dimensionless memure of the clmsicd nature of the system and 6 = E/% is the dimensionless energy. All eigenvalues therefore satisfy e > - 1. The function4 form of the patentid defined by the grogram can be any one of three analytical types (square well, parabolic well, and Lennard-Jones potential); the square well may also include a square bump, and the parabolic well may be flattened symmetrically about z = 0. For the value of 7 input, a number of states are sought using an initial trial energy and energy increment. For each state, a simple search on the e n e r g i s made to try to zero the function f defined by (3.23) and, when an approximate eigenvalue is located, the secant method is employed becomes less than the value of the matching tolerance (this value may be changed at run time) For each trid eigenvalue, the Schroedinger equation is integrated forward and bxkward, and the two salations are matched at the left-most turning point where the behwior of the wave if there is function changes from oscillatory to exponential (near ,.,I no such turning point). As the search proceeds, the trial eigenvdue i s displayed, as is the current step in the energy, the current value of f , a ~ d the number of nodes in, the trial wave function. As the solution is
69
78
9. Bopmdarg Value and Bigenvalue Problems
likely to be inaccurate when it is integrated into a dassicalfy forbidden region, the program also indicates whether or not this is the case. When an eigenvalue is found, it is indicat;ed on a g a p h of the potentid by a line at the appropriate level between the left-most and right-most turning points and the eigenfanction is dso gaphed. A dificulty arises fram the ibrbitrary phase of the wave function and the dependence of the sign of f cm that phase. If we are arbitrary &oat; the sign of $, then the sign off is also arbitrary. However, since the search procedure uses the sign of f as a sign4 for crossing a root, this situation must be avoided. Therefore, to ensure that f is a continuous function of e n e r o the sign hctor is completdy determined once the seaseh is started, Often in quantum mechanics, the a v e r d sign of the wave function i s of little consequence. However, in this program the sign of + ( S ) determines the sign of f which in turn signats the crossing of a root. Therefore, to ensure that f is a continuous function of energy we must choose the sign of +(z) carefully. At the beginning of the search a sign is chosen arbitrarily (e.g., $<(h)> 0). This sign convention continues as the energy changes until a new node appears in the trid wave function, To keep f continuous, th& gains the node mast the portion of the wave function (+< or retajn the s m e sign betvveen steps in the search, (By drawing a few graphs you can convince yoursdf that this is the case.) This new s i p convention is retained until another node q p e m , when the new sigxl is chosen by the s m e criterion, The following exercises can help to improve your understmdi~gof the physicd principles and nunrericd methods illustrated in this example. Exercise 3*7 Verify that the code gives the expected mswers for the eigenvalues of the square-well and parabolic-well patentids (y = 50 mjght be a mnvenient mlue to use), Observe how the dismtinuity in the derivative at the matching point is smoothed out as the energy converges to each eigenvalue. Also note the increase in the number of nodes with increasing eigenvalue and, for the parabolic well, the behavior of the solution. near the turning gdnts. For states with l q e quantum numbers, the amplitude of the aftcillations becomes larger new the turning points, consistent with the behavior of the WKB wave function, which i s proportional to the inverse square-root of the classical velocity, (E v ) - ' / ~Find . some solutions in these potentids also for values of y that are small (say 10) and large (say 2001, corresponding to the extreme quantum and daf;ical limits, respectively;
3.6 IS;tat:onary solutions of the one-dimensional Sckrodinger wuation
Exmciw 3*8 For the m d y t i c d y salable square and pafaboGc welh, investigat;e the eEects of &angin% the integration method from the Numerw dgoaithm to the '"nsve" one obldned by appra~matingthe seeond derivative by just the three-point formula (1.7); that is, neglecting the 6 ( h 2 )term in (3.6).
r
16xweist3 3.9 Change the progam so that the eigenvdues me found by integrating only forward and demanding that the wave fanceian vanish Qbserw the problems that arise in trying to integrate an exat g,,,. ponerttidy dying sdution into a classicadly forbiddea regon, (It is wise to keep 7 relatively small fiere so that the instabilities don't become tas large.) r
Exercise 3.10 When the potential. is reflection symmetric about z = 0, the eigenfunctions will have a definite parity (symmetric or anti-symmetric about I = 0) and that parity will alternate as the quantum number (energy) increases. Verify that this is the case for the numerical solutions generated by the code. Can you think of a way in which the parity can be exploited to halve the numerical effort involved in finding the eigenvalues of a symmetric potentid? ff so, modify the code to try it oat. Exercise 3.11 If we consider a situation where v(%) = O for r < I,. and I > S,,, (i.e., we remove the walls), then the zero boundary conditions at $he ends of the lattice are inappropriate for weaMy bound ~ t a t e s ( E 6 0) since the wave function decays very slowly as 1 and g,, are therefore More appropriate boundary conditions at r
Change the code to implement these boundary conditions and observe the eEeet on thc? wave functions afld energies of the states n e a zero energy. Note that if we were to normaEze the wave functiaa in the conventional way, the contributions from these exponential tails would have to be included. Can you derive, in the style of the Numerov algorithm, a numerical redzation of these boundary conditions accurate to a high order in DX? Exercige 3.22 Check nzrmericdly that, for a given golentid, two eigenfunctions, $E and +h, corresponding to different eigenvdues E and E', am orthogond,
B
+~(2)$k(2)dg=
0,
7%
72
S. Boundary Value and Eigetavalue Problemor
as iis m q ~ r e dby the general principle8 of quantum mechanics, m
Exercise 3.13 For small, intermediate, and large values of 7,compare
the exact eigenvdues of the Lennard-Jones potential with the semidassicd energies generated by the code for Example 1. Exercise 3.14 Investigate the eigenfunctions and eigenvalues for potential~you might have encountered in learning elementary quantum mechanics: the Cfunetion potential, a finite square-well, double-well potentials, periodic potentials, etc. This may be done by dtering the potentid in subroutine POTNTL. Interpret the wave fundions and eigenvdues you find. (Note that the code will sometimes have trouble finding two eigenvalues that are nearly degenerate.)
m
Project III: Atomic structure in the Hartree-Fock approximation The self consistent field approximation (Hartree-Fock) is known to be an aemrate descfipti~nof many of the properties of multi-eledron atorns and ions. In this appraxirnatim, each electron is described by a separate single-partide wave funetion (as distinct from the many-electron wave function) that solves a Schroedinger-likeequation. The potential appearing in this equatioa is that generded by the average motion of & of the other electrons, and so depends on their sinde-particle wave fiaelions. The resdt is a set of an-fine= eigenvdue equalions, wEch c m be solved by the methods introdumd in this chapter. In this project, we vviU solve the seIf-consistent field equations to deternine the pound-st&e ~itracture of small atomic systems (e.g., the atoms aod ions of the elements in the periodic table from Hydrogen through Mean). The totd energies cdculated em be compmed direct& with experimental values. The brief derivation we give here cm be supplemented with the maLerid found in [Be68], [Me68], and [We80].
111.1 Basis of the Hartree-Fock approximation ltonian for N dectroas moving about a heavy nucleus of ehar~;ge Z located at the ori@a can be writtea as
Here, the {ri) are the locations of the electrons, m and -e are the electron mass and charge, and rij E ri - rj is the separation between
electrons i and j. The three sums in (111.1) embody the electron kinetic energy, the electron-nucleus attraction, and the inter-electron repulsion. As is appropriate to the level of accuracy of the self-consistent field approximation, we have neglected much smaller terms, such as those assodated with the spin-orbit int;eraction, hypefine interactions, recoil motion of the nucleus, and relativity. A proper quantum meehanicd description requires that we specify the spin state of each electron, in addition to its location. This can be done by giving its spin projection on some fixed quantization axis, = f 1/2. For convenience, we will use the notation (E$,oi) to denote all of the coordinates (space and spin) of electron i. The seE-consistent field method8 ase based on the Rayleigh-Ritz vmiationalt principle, which states that the ground &ibCe eigenfanctim of the Hamiltonian, @(gl,$2,. ..,z N ) ,is that wave function that minimizes the eqectation value, of H, subject to the constraints that B! obey the Pauli principle (i.e., that it be anti-symmetric under the interchange of any two of the z's) and that it be norrvlrilized to unity:
(The notation d N z means integration over all of the spatial coordinates ation over all of the spin coordinates of the N electrons.) Furthermore, this minimum value of E is the ground state energy. A calculation of (111.2) for any normalized and anti-symmetric trial function P therefore furnishes an upper bound to the ground state energy. The fifartree-Fock qproSmatioa is based on restl.icting the trial wave function to be a Slater detex~nant:
Here, the $,(I) are a set of N orthonormd single-particle wave functions; they are functims of the coor&nates of only a siagle electron. The determinant is that of the M x N matrk formed as a and zi each take on their N possible values, while the factor ( N ! ) - ' / ~ ensures that $P is normalized according to (111.3). The physical interpretation of this wave orbitd function is that each of the dectrons moves independently in under the average inguence of all the ather electrons. This turns out; to be a good apprainrdion to the t m wave function of an atom because
4
9. Boundary Value and Eigenvalue Pmblern9
the smooth Coulomb interaction between the electrons averages out many of the det&ls of their motion.
Uairrg the properties of determinants, it is easy to see that @ has the required anti-symmetry under interchange of any two electrons (a determinant changes sign whenever any two of its columns are interchanged) and that i s properly normalized according to Eq. (111.3) if the singleparticle wave fmctiorrs are orthonormd:
Since the Hamiltonian (111.1) does not involve the electron spin variables, the spins decouple from the space degrees of fredom, so th& it is ua;efd to writGe each sinde-pmticle wave functioa as a, product of spme and spin functions:
(111.6) where o, = f1/2 i s the spin projection of the orbit4 a. The orthonormality constraint (111.5) then takes the form
that orbitals c m be orthogond by dther their spin or spac~edependence, The computation of the energy (111.2) using the wave function defined by (IB.4-6) is straightforward but tedious. After some algebra, we have 6 3 0
In this expression, the one-body matrix elements of the kinetic energy are
the electron density i s the sum of" the sinde-paftiele densitirss,
the electrostatic potential generated by the electrons is
(Ill.1l a ) so that V ~ P= ,-4aezp(r)
,
( I l l .l lb)
and the exchange matrix elements of the inter-electron repulsion are
The interpretation of the various terms in (111.8) is straightforward. The kinetic energy is the sum of the kinetic energies of the single particle orbitals, while the electron-nucleus attraction and direct inter-electron repulsion are just what would be expected from a total charge of -Ne distributed in space with density p(r). The final term in (111.8) is the exchange energy, which arises from the anti-symmetry of the trial wave function (111.4). It is a sum over all pairs of orbitals with the same spin projection; pairs of orbitals with different spin projections are 'distinguishable" and therefore do not contribute to this term. The s t r a t e a of the self-consistent field approaeh should now be clear. The variational wave function (111.4) depends on a set of "parameters": the values of the single-particle wave functions at each p&nt in s p w , Variation of these parameters M, as to minimize the energy (111.8) while respecting the constraints (111.7) results in a set of Euler-Lagrange equations (the Eartree-Fock equations) that define the "best" determinental wave fanctim afld @ve m optinad bauad on the tot& enerw. Because these equations are somewhat compficated in detail, we conaider first the tw-dectrm problem, and then turn La situations with thrw or more electronis.
111.2 The two-electron problem For two electrons that don't interact with ewh other, the ground ~titteof their motion around a nudeus is the %a2configuration; i.e., both electrons are in the same real, spherically symmetric spatid state, but have opposite spin projeetions, It is therefore naturd to take it trial wave function for the interacting system that redizes this same configarsttion; the corresponding two single-pastick wave functions me
76
9. Boundary ltalue and Eigenvalere Pwbkens
so that the many-body wave function (111.4) is
This trial wave function i s anti-sy etdc under the interchange of the r the interchmp of th electron q i z s bat is symmetric coordinates. It respects the Pas p h d p l e , since it is antis under the interchange of all variables describing the two electrons. The normalization condition (111.5) becomes
while the energy (111.8) becomes
a
(111.16) with (IIL10) reducing to p(.)
1 4nr2
= 2 x -R'
(r)
and (IIl.11b) becoming
Note that the a&ange energy i s attractive and has a magnitude of onehalf of that of the direct inter-electron repulsion [resulting in a net factor of 114 in the find term of (III.16)] and that various factors of two have entered from the mm over the two spin projections. A common variational treatment of the two-electron system ("poor man's Hartree-Fock") takes R to be a hydrogenic 1s orbital parametrized by an effective charge, Z':
where a is the Bohr radius. The energy (EL16) is then minimized as a func%iianof Z" to find m approximation to the wave function and energy. This procedure, which i s detailed in many textbooks (see, for example,
111. Atomic 9tructum in &c: Narlrm-FNX: appro%imaEion
[Me68]), results in
In carrying out this minimization, it is amusing to note that the kinetic energy scales as while all of the potential energies scale as E*, so that, at the optimal Z', the kinetic energy is -112 of the potential. This is a specific case of a more general virid theorem pertaining to the HartreeFock approximation (see Step 1 below). ation jfQrthe tweelectron problem The full Hatree-Fock app is very much in this same variational spirit, but the most general class of normalized singlepartide wave functions is considered. That is, we consider E in Eq. (111.16) to be a functional of R md require that it be stat;ianary with respect to all possible norm-conserving vdations of the single-particle wave function. If the normalization constraint (111.15) is enforced by the method of fiagrane aadtipEers, for an afbiitrav vsiatim of 6R(r) we require
where E is a Lagange rnultipXier $0 be d e t e r ~ n e daft= variation so that the solution is pmperly nomalized. The standard techniques of vmiatio~dcdcdas then lead to
which is satisfied if R solves the Schroedinger-like equation
Choosing E (the "single-partide energy") to be an eigenvalue of the singleparticle Hamiltonim appearing in (111.23) ensures that R is nomalizable. Equations (III.18,23) are the two coupled non-linear differential equations in one dimension that form the Hartree-Fock approximation to the original six-dimensional Schroedinger equation. Note that only one-half of @ appears in (111.23) since each electron interxts only with the other and not "with itself"; inclusion of the exchange tern in the energy (III.16) is necesswy to get this bookk~pine;right.
TT
78
S. ET-oundargr Vixlue and EigenvaZue Probbms
The assmption of spherical symmetry is m enomous simpEfication in. the two-dectron pro'filem, as it dowed us to reduce the aigenvdue problem for the sin$e-partide wave function aad the Poisson equation folc the potentid from three-&measion4 partid diEerrtntial equations to ordinary differentid equations. For the two-electron problem, it is plausible (and true) that a spherical& sy etric solution has the lowest energy* However, for most many-eleetmn systems, spheric& symmetry of the density m d potential axe by no metbns gailranteed, In principle, non-spherical solutions should be considered, and such "&famedB wave functian~are in fact -the optimal ones for describing the structure of certain nuclei. To undwstand what the probhrn is, let us assume that the potentid 4t is spbericdy symmetric, The solutions to the single--partide Schroe&nger equation in such s potential me orga~zedinto "sheas," each characte~zedby an arbitd angular momentum, I, a ~ ad r d i d quantum number, n. Within each shell, all 2(2l f 1) orbitals associated with the vasious vdues of a, a;nd tbe projection of the orbltd m e f a r momentum, m, are degenerate. The orbitds have the form
However, we must decide which of these orbitals to use in constructing the Hartrw-Pock determinant* Unless the number of electrons is such thak all of the 2(2I 1)substates of a given shell are filled, the density as given by (111.10) will not be spherically symmetric. This, in turn, leads to a nonsymmetric potential and a much more &%cult single-particle eigenvdue equation; the general problem is therefore intrinsically three-dimensiond. A slight modification of the rigorous Hartree-Foch method (the filling or central-field approximation) is useful in generating a spherically symmetric approximation to such "open-shell" systems. The basic idea is to spread the vdence electrons uniformly over the last occupied shell. For example, in discussing the neutral Carbon atom, there would be 2 electrons in the i s shell, 2 electrons in the 29 shell, and 2 electrons spread out over the 6 orbitals of the 2p shell. (Note that we don't put 4 electrons in the 2p shell and none in the 29 shell since the single-partide energy of the latter is expected to be more negative.) Thus, we introduce the number of electrons in each shell, Nnl, which can take on integer values between 0 and 2(21+ l),and, using the wave functions (III.24), write the
+
density (111.10) as
In writing this expression, we have used the identity
In the same spirit, the energy functional (111.8) can be generalized to open-shell situations as
with the exchange e n e r a being 1
E,, = --
13-1"
C N,rNalp C
A=if-l*\
nlnt18
Ia.this expression, I is the i n t e p d
(111.27) where r< and r> are the smaller and larger of r and r' and the 3 - j symbol v ~ s f i e swhen l l'+ A Xis odd and otherwise has tfio vdue
+
(-l
+ l[+ A)! (l - l' + A)! (l + lt - A)! (I
X
5 + +
+ l'+ X + l)! P!
- l')!(JJ - l f ) !@ - X)!
where p = ( l l' A). In deriving these expressions, we have used the multipole decomposition of the Coulomb intesitedion and the standard techniques of angular momentum algebra (Br68]. The Hartree-Fa& equations defining the optimal radial wave functioans aovv foUow from the calculus of varialioas, as in the two-electran
80
S. Boundary Value and Eigenudue Problems
case. Lagrange multipliers Ear are introduced to keep each of the radial wave function normalized and, after some algebra, we have
The eigenvalue equation (III.28a) can be seen to be analogous to (111.23) for the two-electron problem, except that the exchange energy has introduced a non-loc&ty (Fock potential) embodied in F and has coupled together the eigenvalue equations for each of the radial wave functions; it is eagy to show that these two eqvations are equivalent when tbere is a single orbital with l = 0. It is useful to note that (III.26b, 28b) imply that the exchmge energy can be also be writ.tt3lt as
and that, by multiplying (III.28a) by R,r and integrating, we can express the single pastilcle eigenvdue as
111.4 Solving the equations For the numeric4 solution of the Eartree-Pock equa;tisats, we must, jimt adopt a system of units. Far comparison with experimental vdues, it, i s convenient ta merrsure all lea@hs in Angstroms m d 41energies in dectraa
volts. If we use the constants
then the Bahr radius and wdberg have their correct vdues,
For a lmge atom with many electrons, the accurate solution of the Hatree-Fock equsttions is a considerable tmk. Rawever, if we consider the ground states of systems with at most 10 electrons (requiring three shells: 18, 29, and 2p), then the numerical work can be managed in a reasoxlable m o u n t of time. A lattice of several hundred points with a radid step size of 0.01 A extending out to B 3 A should be sufficient for most cases. The best appmach to developing a progrm t;o tistve the Bartree-Fsck equations is to consider the two~eleetra~ problem fir~t,for which t h e is only a sinde radial wave function solving a locd eigenvdue equation, and then to consider the more complex case af several, orbit&. The attwk can be made through the following sequence of steps. Step 1 Verify the dgebslz leading to the find equations presaged above for the two-electron system [Eqs. (III.16,18,23)] and for the multielectron system [Eqs. (III.18,26,28)] and make sure that you understand the phygi~dyincipfes behind the defivations. Prove the virial theorem that the kinetic energy is 112 of the potential energy. This can be done by imagining that the single-particle wave functions of a solution to the Hwtree-Pock equations are subject to a nam-preserving scaling trmdormation,
r
-
~a (r)
+
,
X(~P)
where r is a dimensionless scaling parameter. Show that the total kinetic energy in (111.8) scales as r Z ,while 4 of the potential energies scale as r. Since the energy at the Hartree-Fock solution is stationary with respect to any variation of the wave functions, use
to prove the theorem.
82
3. Boundary k l u e and Bigenualucr Problr?ms R
Step 2
Write a program to calculate the energy from (III.16) if
R is known at all of the lattice points. This will require writing a subroutine that calculates @ by solving (111.18) (you might modify the one given earlier in this chapter) and then evaluating suitable quadratures for the various terms in (111.16). Verify that your program is working by calculating the energies associated with the hydrogenic orbitat (111.19) and comparing it with the analytical results [remember to normalize the wave function by the appropriate discretization of (III.15)]. Step 3 Write a subroutine that u ~ the s shooting m t h o d to solve the radial equation (111.23) for the lowest eigenvdue e and corresponding normalized wave function R if the potential Q i s given at the lattice points. The zero boundary condition at the origin is easily implemented, but the boundary condition at large distances can be taken as R(r = L) = 0, where L is the outer end of the lattice. (Greater accuracy, particularly for weam bound states, can be had by imposing instead an exponential boundary condition at the outer radius.) Note that the radial scale (i.e., R and the radial step size) should change with the strength of the central charge. Verify that your subroutine works by setting @ to O and comparing, for Z = 2 and Z =; 4, the cdculated wave function, c?igenvdue, and enerrgy of the 1s orbital with the analytical hydrogenic vdues. Skep 4 Combine the subroutines developed in Steps 2 and 3 into a code that, given a value of Z, solves the two-ejectrm Hartme-Fock equations by iteration, An iterdon scbe-zneis as MIows, the organization into submutines being obvious: i ) "Guess" an initial wave function, say the hydrogenic one (111.19) with the atpprapPiibte v h e of Z*. ii) Solve (111.18) for the potentid generated by the initial wave function and calculate the total energy of the system from Eq. (111.16). iii) Find a new wave function and its eigenvdue by solving (111.23) and normalizing according to (111.15). i v ) Calculate the new potential and new total energy. Then go back to ii) and repeat i i ) and iii) until the total energy has converged to within the required tolerance. 8
At each iteration, you should print out the eigenvdue, the total energy, and the three separate contributions to the energy appearing in (111.16); a plot of the wave function is also useful for monitoring the calculation. Note that the total energy should decrease as the iterations proceed and will converge relatively quickly to a minimum. The individual contributions to the energy will take longer to settle down, consistent with the
111. Atomic structure in the Hartme-fick appro~mation 83 Table IE1X.X: Binding enerees (in eV) of small atomic sysLems
fact that it is only the total energy that is stationary at the variational minimum, not the individud cmpaoeats; a f ; convergence, the virid theorem discussed in Step 1 should be wtisfied. Try bednning the iteration procedure with different single-particle wave functions and note that the converged solution is still the same. Vary the values of the lattice spacing and the bovndmy radius, &, and prove that your results are stable under these chmges* Step 5 Use: your progrm to solve the Eatre-Fack equation8 for centrd c h a s e s Z = 1-9. Compare the total, energies obtained with the experimental values @WEin N = 2 column of Table III.1. (These binding energes, wkich are the negative of the toed energies, me obtined from the measured ionization potentids of atoms and ions given in [WeTl].) Compare your results &so with the w w e .functions and msociated variational energies given by Eqs. (III.19,20). Note that both approximations shatlld give upper bounds to the =act energy. Give a, physical explanation for the quafitative behwior of the discrepancies as a functioa of Z. C m you use second-order pc?ft;urbationtheory to show that the discrepancy between the Bartree-Fock a ~ exact d eaergies should become a mnstztnt for large Z? Show that for Z = 1, the Hartree-Fo& approximation predicts that the H- ion is unbound in that its e n e r g is greater than thnt, sf the H &torn and so it is energetically hvorabb to shed the extra electron. As can be seen from Table 111.1, this is not the ease in. the red world. In finding the Z .= 1 sdution, yaa might discover thhal convergence is quite a delicate business; it Is very emy for the density to change so much from iteration to iteration that $fie lowest eigenvdue of
m
84
9. Boundary Value and Ei~c~inutxlue Pmblemsr
the sinde-particle H I t o ~ mbwames positive. One way to dleviate this problem is to prewnt the density from chmging too m a d from one itePation to the next, for exmpfe by averagng the new density and the old following step ii) above. SIep 6 Modify your tw&-electronprogram to treat systems in which several orbitds are involved. let is ea~iestto first modify the c d c d a t i ~ n of the total enesw for a @ven set of r d i d wave firactions to indude G,, This ia most convedeatly done by cdcnlating and storing the E",l of Eq. (III.28b) and using Eq. (III.29). Because of the Fock term, the eigenvalue equations (III.28a) cannot be treated by the shooting met hod we have discussed. However, one krcheme is to treat the cdeulated from the previous set of wavf? funetions as infiomogeneous $ems in solving for the new set of wave functions, For trid vatues of the t.,l cdcu1a;t;ed from (111.30) using the previous set of wave functions, (III.28a) can be sdved as uncoupled inhomogeneoas bmndasy vduts problems using: the Green's function method of Eq. (3.18); after normalization according to (III.24), the solutions serve as a new set of wave functions. The twoelectron systems can be used to check the accuracy of your modifications; for these systems you should find that the exchange energy i s -1/2 of the direct inter-electron intewtim enerfSy and that the d u t i o a s converge to the same results as those generated by the code in Step 4. Use this Bartree-&ck code to cdcdate the wave fundons and merges for some of the other systems listed in Table 111.1 and compare your results with the experimental values; interpret what you find. A convenient set of initial wave functions are the hydrogenie orbitals, given by (111.19) for the 16
m
for the 29 and 2p states, respectively. The optimal common value of Z* in these expressions should be determined for any system by minimizing the toed energy.
Chapter 4
Functions and Gaussian Quadrature .S
In this chapter, we discuss two loosely related topics: algorithms for computing the special functions of mathematical physics (Bessel functions, orthogonal polynomials, etc.) and eflicient methods of quadrature based on orthogond functions. In most scientific computing, large libraries supply almost all of the subroutines relevant to these tasks and so relieve the individlzd from the tedium of writing code, h f x t , there is usually little need to know very much about hovv these subroutines work in detail. However, a roug6 idea of the methods used is useful; this is what we hope t o impart in this chapter.
4.1 Special functions The speclaI functions of mathematicd physics were largely devdoped long before large-scde numeric& camput ation became feasible, w h n mtll ytical methods were the rule. Neverthefess, they are still relevant today, for two reasons. One is the insight m d y t i c d solutions offer; they mide our int&tion and provide a framework for the qualit(ative interpretation of more compEcated problems, However, of particdar importance! to numerical work is the fact that specid functions often aflow part of a problem to be solved analyticdly and so dramatically reduce the m o t l M of computation required for it full sdution, As aa inustratian, con~idera one-dimension4 harmonic osciUator moving under an externd perturbation: its f r e q u m c ~W, ~ ,i~ being changed with time. Suppose that the frequency h a its unperturbed value, wo, for times before 2 == 0 and for times after t > T,and that we are interested in the motion for times long after the perturbation ceaws. Given the oscilfator" sinitid coordinate m d vf?focity, one strdghtforwmd methad of
solution is to integate Lhe equations of motion,
as an initid-vdue problem using one of the methods discussed in Chapter 2. However, t h i ~would be ineaicjient, M the motion after the perturbation stops (t > T) is well understood and is readily expressed in terms of the "specid- sine md cosine fuacttio~sinvolved, I($ > T)= s(T)cos
- T) + w c ' v ( ~sin ) wo(t - T ) .
Sinw thwe are very efficient methods I;or computing the trigonometric functions, it is wiser to integate numericalb only the non-trivial part of the motion (0 < t < T ) and then to use the velocity and coordinate at 1: = T to compute directly the sinusoidd function @ven above. Aftbough this example might seem trivial, the concept of using special functions to "do part of tht? arork" is a general one. A useful resource in deali~gwith specid functions is the findbook. of Mathematical Functions [Ab64]. This book contains the definitions and properties of most of the functions one often needs. Methods for computing them are also given, as well as tables of their values for selected arguments. These last are particularly useful for checking the accuracy of the subroutines you are using, Recursion is a pwticdarly simple way of computing some sgeGid functions. Many functions are labeled by an order or index and satisfy recursion rel&ions with re~pectto this labd. If the function can be cornputed explicitly for the few lowest orders, then the hkher orders can be found from these formulas, As an example, consider the computation of the Legendre polynomiais, &(I), for is1 _< I and 4 = 0,1,2,. ... These are important in the solution of wave equations in situations with a sphericat symmetry. The recursion relation with respect to degree is
= I, forward recursion in Using the explicit values Fa($)= 1 and PI(%) I yields PI for any higher value of I required. The following FORTRAN program accomplishes this for any value for s and I input.
ELSE IF (L .Eq. O ) PL=O
.
mm lexplick* form for L=0
ELSE IF (L .EQ. 1) TBm PL=X ELSE PH=i
.
!axpXicit i o m for L=% !valass to s t a r t r e ~ w s i o n
PZ=X
!loop f o r forti~mdrecwsion DO 10 XG=I,L-1 PP=( (2+fL+ l) *X+PZ-EL,*PM)/(IL+l] !&q. 4.1 PM=PZ !rolil v d a e s PZ=PF GOWTIW$
PL=PZ EBB T F PRIm *,X,L,PL GOTO 20
EBD This eode works wlth no problem, md $he r e ~ d t swrw with the v&ues &ven in the tables to the arithmetic precision of the computer. We can d ~ mrngute a the derivlatives of the Legendrt, pdynamids with this dgorithm using the relatioxl
Otber sets of arthoganal palynomials, such as Hermite and Laguerre, can be treated similwly.
As a second example, consider the cylindrical Bessel functions, $,(I) and Y,(s), which arise as the regular and irregular solutions to wave equations In cylindr'rcd gwmetries. These funetions satisfy the recursion relation 2% C,-'(Z) Cn+1(5) = ;Cn(%) , (4.3)
+
where C,, is either J, or Y,. To use these recursion relations in the forward direction, m need the vdztes of and @I. These me most ewify o b t ~ e d from the polynomial appravimations given in [Ab64], formulas 9.4.1-3.
88
4, S p c i d Functions and Gau~lsianQuadratam Table 4.1 Forward recursion fbr the irregular Bexssel function Vn(2)
where y = $13 and
Jo(z) = z-'/2fo cos B
&(g)
= z-'i2fo gin B
(4.w
where fo = 0.79788456 - 0.00000077~-'
- 0.00552740~-' - 0.00009512y-~+ 0.0013723~y-~- 0.00072805~-~
(4.4d)
+ 0.00014476~-~+ E ; IE
Similar expressions for J1 and Ylare given in Sections 9.4.5-6 of [Ab64]. Mote that these formalas we not Taylar sedes, but rather polyna~a;fs whom coefficients have been djusted to best represent the Bessd functions aver the Intervds dverr.
Table 4.2 Gannputatian af the regulrr~:Bmeel funetian Jn(2) Pt
Exact vdae
famrr~:drmrsiran backward recursion
+
0 0,223891E 00 1 O.ti76725E $- 00 2 0,3528346 -5.00 3 0.1289436 4.00 4 0.339951E 01 5 0.703963E 02 6 0,120243E 02 "7.J74944E 03 8 0.221795E 04 9 0.2492346 -. 05 i o a.251s39~ 06 11 0,2304286 07 l 2 0.193270E 08 13 0,14949414: 09 14 0.101295E 10
-
-
-+00 + 00
0,OQOOQOE 0.000rt00E: 0.000@OOi5' 0.000000E -0,0000Q2E -0.OO0075E -O.o@@355rs" -0,0205596 -0.1403Ei3E -0.110234B -0.978959B
+ 00
-+00 - 01 - 02 - 02
- 03 - 03 - 02
- 02
0.1506Q2E -. 10 0.38794OE 110 0,233337E g0 0,867350E 11 0.228676E l1 0.473828E: 12 0.808826E 13 0.117678E 13 O.l4Sr93E f 4 0,167650E 15 0.169200E 116 0.155000E 17 0.1300003 18 Q.100000E 19 0.00000OE 19
-
-
--
-
-
-
b d w a r d recursion
tt.oooaooE + oo
+
o.ooooo0E 00 0,0000006 -I. 00 0,000@00E 00
+
o,ooooooE - or a , o o a a o ~-~oz
- oz
0,ooooooE 0,000o00E 0,~oooooE 0,000000E O.OOO0OOE O.oOo000E
- 03
- 04 - 05 - 06
- 07
o.oooao'i"~- 08
0.000830E 0.1072956
- 09
- IQ
Let us now attempt to cdenlate the Y , by fomard recursion using (4.3) together with the polynomial approximations for the values of Yo and Yl. Doing so leads to results that reproduce the values given in the tables of Chapter 9 of [Ab64] to within the arithmetic precision of the computer, For e x a p l e , we find Ghe results fisted Table 4.1 for a -- 2, 1%is natural to try to compute the regular solutions, J,, with the same forward recursion procedure. Using Eq. (4.4a) and its analog for Jx, we find the errors listed in the third column of Table 4.2; the exact values are given in the second column. As can be seen, forward recursion gives good results for n < 5, but there are gross errors for the higher values of n. It i, relatively easy to understand what is going wrong. We can think about the recursion relation (4.3) for the Bessel functions as the finite difference analog of a second-order differential equation in n. In fact, if we subtraet 2C, from both sides of (4.3), we obtain
which, in the l i ~ oft continuous n, we can czpproxinzate by
In deriving this equation, we have used the thrc?e-point fiaite diEesence formula (1.7) for the second derivative with h. = 1and have identified the local wavenumber, k2(n). Equation (4.6) will have two linearly independent solutions, either both oscillatory in character (when k2 is positive, or when n < r ) or one exponentidly growing and the other exponentidy decreasing (when k2 is negative, or n > I). As is clear from Table 4.1, Y, is the sdution that grows exponentidly with inerea~ingsz, scr that no loss of predsion occurs in farwad recursion. However, Table 4.2 shows that the exact vdues of J, decreahse rapidly with incmwing n, and so preci~ion is lost rapidly as forward recursion proceeds Beyand n = g , TEs disease i s the s m e as that; errcountesed in Chapter 3 in integrating exponentidy dying solutions of second-order differentid equations; its care is &so the same: avoid using %berecursion relation in the direction of decrewing vdues of the function. Exercise 4.1 Use Eq. (4.1) to show that recursion of the Legendre polynomials is stable in either direction.
To compute the regular cylindrical Bessel functions accurately, we can exploit the linearity of the recursion relation and use Eq. (4.3) in the direction of decreasing n. Suppose we are interested in J,(2) for n 5 10. Then, choosing Jlq= O and JI3= 1X &B arbitrarily small number, we c m recar backwards to n =; 0. T h e resulting sequence of numbers will then reproduce the J,, to within an arbitrary normalization, since, as long as we have Ghosen the initial vdue of n high enaugh.?the required solution of the difference equation (4.3), which grows exponentially with decreasing n, will dominate for small n. The sequence can then be normalized through the identity
The following FORTRAN code evaluates the regular cylindrical BesseX functionts using badward recursion.
g00
PRXIT +, "%er nax v d x e 09 n (.Jle. 60; .It. O R W *, mILx I F (IMAX ,LT. 0 ) STOP I F (IHAX
PEGIT
*,#
.GT.
t o stop)"
60) mAX=60
&%ex vazue o f x p
READ * , X C
.
3 f la3mX)=Q
!baekwwd r e c w s i a ~ s
When run for NMAX=14 and X=2, it gives the unnormalized values (i.e., after line 10) shown in the fourth column of Table 4.2 and the errors in the find d u e s shown in the fifth calurrrn of %hattable. The results are surprisingly aecur;zte, e m far vdues of sz dmtl to 14. An dkrnatiw way of obtaining the constant with which to n o m a z e the whole series i s to calculate the value of Jo(2) from the polynomial approximation (4.4a). m Exercise 4.2 Run, the code above for various d a e s of MMAX at k e d X, By wrnparing with tabulated vdues, verify thaG the resufts are accurate as long as NMAX is large enough (somewhat greater than the larger of X and the maximum order desired). Change the normalization algorithm to use the approximations (4.4a,c) for Ja.
92
4. S p i d Funclr"or?9and Gau8arian Quadratam Exercise 4.3 The regular and irregular spherical Bessel functions, jr and nj, safisfy the recursion relaeion
whae 81 is either jr or % l . The explicit formalas far the few laarest mders atre sin a ; jl=.--sin z cos 3= 3 I== sin rt: -cos X: ,
IZ:
= --COS z ; *2:
%g
'
%g
8
cos z sin, z
c -
$2
Z
3
COS 2-- z2
sin z
.
At z = 0.5, the exact vdues of the fultetiotrs of order 2 are
Show that 122 can be c&ulatced either by explicit evdu&ion or by forward mcur~ionand canvim yourself that the latter method will work for all 1 and z. Investigate the calculation of jz(0.5) by forward recursion, exglieit evduatim, and by backward reeursioa and show that the first two methods c m be quite inaccurat;e, Can you see why? TZlus, even if expl;lcit expressions for a fnneLjon me available, the stability of backward recursion can make it the method of clrdce.
Our discassion h a iflvstr&ed s m e pitfds in comput;ing the some commonly used spedal functions. Speeifie methods useful for other functions can be found in the appropriate chapters of [Ab64].
4.2 Gaussian quadrature In Chapter 1, we discussed several methods for computing definite integrals that were most convenient when the intepand was known at a series of equally spaced lattice points. While such methods enjoy widespread use, espeddly when the integrand involves a numerically-generated solution to a differential equation, more efficient quadratare schemes exist if we can evaluate the integrand for arbitrary abscissae. One of the most useful of these is Gaussian qu&ature. Cansida the problem of evaluating
The f"omdasdiscussed in Chapter 1 were of the form
where are the equatly spaeed lattice points. Here, we are referring to the "elementaryn quadrature formulas [such as (1.9), (1.11), or (1.13a,b)],and not to compound formulas such as (1.12). For example, for Simpson's rule (1.11), N = 3 and
fiom the derivation of Simpson's rule, it is clear that tfie fbrmula is exact when f a p d y n o ~ a lof degrw 3 or less, whi& is comrneasurate wigh the error estimate given in Eq. (1.11). More generay, if a quadrature formda based on a Taylor series rrses N points, it will inteqate exactly a polynomial of degree N l (degree N if N is odd). That is, the N wei&ts PU, can be &men to satisfy the N binear equatioas
-
(When N is odd, the quadrature formula is also exact for the odd monomid z N . ) A greater predsion for a given amount of numerical work can be achieved if we me willing to give up the requirement of @quay-spaced quadr&are points. That is, we will choose the x, in some aplimaS sense, subject only to the constraint that they lie within the interval [-l, 11. We then have 2N parametefs at our disposd in co~structingthe quadrature formda (the N z,'s and the N w,'s), and so we should be able to choose them so that Eq. (4.9) is satisfied far p ranging from O to 2N - 1. That is, the quadrature formula using only N arefulfy chwen poinks cwr be made exwt for pdynomials of degret! 2N - 1or bss, This is clearjy mare emcienl than using equdly-qaced abscissa, To see how to best choose the 2,' we corrsidef the Legendre palynsmids, which are orthogonal on the interval [- 1,1]:
944
4. Specl'af Furactions
and Gaussl'sn Quadraturn
It is easily shown that Pi is a polynomial of degree i with i roots in the interval [-l, l]. Any polynomial of degree 2N - 1 or less then can be written in the form where Q and R are polynomials of degree N of the required integral (4.8) is then
- 1 or less. The exact value
where the second step Wows from the orthagondity of .PN to all polynomiats of degree N - 1 or less. If wa now take the s, to be the N zeros of &,then application of (4.8) gives (exactly)
It remains to choose the W, so that; R (a poly~omidof degree N - 1 or less) i s integrated exactly. That is, the W, satisfy the set of linear equations (4.9) when the 2, are the zeros of PN. It can be shown that W, is related to the derivative of .PN at the corresponding zero, Specifidly; 2 20% = (1 sk)[P~(z,)12' TMs completes the specification of what is known as the Gauss-Lt;$endre quadratare formda. Note that it c m be appl-ied to any d e f i ~ t ein_r;egraf between finite lirnits by a simple linear cbange of variable. That is, far an integral between limits I = a and I = b, a change of variable to
-
redues the integrd to the form required, Other non-linear changes of variable that make the integrand as smooth as possible wilt alao improve the accuracy, Other types of wthogond pdynomids provide useful Gaussian quadraturn formulas when the inlegrand has a particular form, Ebr example, the Laguerre polynomials, .Li, which are orthogond on the interGd [O,m] with the weight function e-", lead to the Gauss-Laguerre quadraturn
4.3 B ~ r nand eQonal approsimatr'ons to quantum scattering
where the z, ase the roots of LN and the W, are related to the values of LN+I at these points. Similarly, the Kemite polynomials provide GaussHermite quadratare formulas for integrals of the form OQ
ems'f(z) dz
.
These Gaussian quadrature formulas, and many others, are given in Section 25.4 of [Ab64], which also contains tables of the abscissm and weights. In the practical application of Gaussian quadrature formulas, one does not need to write programs to calculate the abscissae and weights. Rather, there are usually library subroutines that can be used to establish arrays containing these numbers. For example, subroutine QUAD in Example 4 (see Appendix B) establishes the Gauss-Legendre absdssae and weights for many different values of N. As a general rule, Gaassian quadrature is the method of choice when the integrand is smooth, or can be made smooth by extracting from it a function that, is the weight for a stmdard set of orthogond polynomid~. We must, of course, also have the a b s t y to evduate the integrmd at the required abscissae. H the integrmd varies rapidly, we can compound the basic Gsussiaa quadra;t;urefolrmula by applying it w r ~ e v e r dgubintervds of the range of integrat;ion, Of course, wkea t be integfand east be evaluated only at equally-spaced abscissm (such as when it is generated by integrating a differential equation), then formulas of the type discussed in Chapter 1 must be uged. As an iBustration of Gaussian qudrature, coxtsider using a 3-point Gauss-Legendre quadrature to evduate the i n t e r &
Making the cSIange of variable to
results in
For N = 3, the Gauss-Legendre abscissae and weights are
95
96
4. Smeial fineEs'ow and Gaussian Quadmture
Straightforward evaluation of the quadrature formula (4.8) then results in I = 4.66683, while a Simpson's rule evaluation of (4.14) with h = 1.5 gives 4,66228. Gaussian quadrat me is therefore more accurate than Simpson's rule by about a fxtor oT 27, yet requires the same number of evalluations of the integrand (three). r
Exercise 4.4
Cansider the integal
Evduate this intega3 using some of the quadratare formulas discussed in Chapter 1and using Gauss-Legendre quadrat are. Note that the behavior of the integrmd near z = f l i s cause fsr some caution. Compme the accuracy and eficiexley of these v&ous methods for diRerent numbers of abscissa^. Note that this integral can be evatuated exactly with a 4bonepoint" Gauss-Chebyshev quadrature formula oE the foMn
with sm
col3
rZ,
31";
N-4-1 (See Section 25.4.40 of [Ab64].)
wn=-
71"
N+1
72
sin2 -T N+1
.
4.3 Born and eikonal approximations to quantum scatter-
ing In this example, we will investig;ate the Born and eikonal approximations suitable for describing quantum-mechanical scattering at high energies, and in particular cdculate the scattering of fast eledrons (energies greater than several 10's of eV) from neutral atoms. The following project deals with the exact partial-wave solution of this problem. Extensive discussions of the quantum thwry of scattering are given in many texts (see, for example, [Me68], [Ne66], or [Wu62]); we will ody review the essentials here. For particles of mass m and energy
scattering from a central potential V ( r )is described by a wave function
4.3 Born and eikonal ~pppodnzatiansto flantun scerlteriw
l@ (r) that satisfies the Schroedinger equation,
with the botrndary conditian at l a r e distances
Here, the beam is incident along the z direction and B is the scattering angle (angle between r and a). The complex scattering amplitude f embodies the observable scattering properties and is the basic function we seek to detmine. Tbe digeratid cross section is given by
a d the tot& crass section is
In general, f is a function of both E" ajnd B. At this point, many elementmy trc~at;meabof scattering introduce a partid-wave demmpositim of !P, express f in terns of the phase shifis, m d then proceed to discuss the radid S&roc?&nger equation in each pasdid wave, from wEch the phwe shift and hence %beexwt cross wetion, e m be cdculat-ed, We will use this method, wki& is most apprapri&e when the energies are low and only a few partial waves me important, in Project IV bdow. However, in this example, we will con~idertwo approximation schemes, the Born and eikond, which are appropriate to high-mergy situations when many partial waves conkibute, Both, the Born and dkanait approximations are based on an exact integral expression for the scattering amplitude derived in many advanced treatments: m e r V ( ~ )(p) g d3r . f ( B ) = -2rfi2 Here, the wavenumber of the scattered particle is kf, so that and kr*i= cos B. It is also convenient to introduce the wavenumber of the ixrcident particle, ki = kg. The Born approdmation (more precisely? the firs%Born a p p r o ~ m a tion) congists of wsuming that the scattering is weak, ao that the fult scattering wave function @ differs vefy littb from the incident plane wave,
97
98
$. Spct'ctl Fsnctzt'ons and Gawsdarn Quarfralure
exp(iki*r).Making this replacement in (4.20) results in the Born scattering amplitude,
Here, we have introduced the momentum transfer, q = kt - ki, so that
and have used the identity
Note that the Born apprasmation to the scattering amplitude depends only upon q and not separately upon E &ad 8. Better approximations to l! in Eq. (4.20) result in correspondingly better approsnaations to f . OM pogsible improvement is the eikand &pproximation, v d d at high energies and small scattering angles. (See [Wa73] or [Ne66].) This approximation is semiclassical in nature; its essence is that each ray af the incident plane wave suBers a phase shift as it passes tbrough the potential on a straight-line trajectory (see Figure 4.1). Sin= this p h a e shift depends upon the imp& pasameter af the raLy, the wavefronts of tbe wave fitnction asle distorted after passing through the paential; it i s tlris distortian that carries the scattering information.
To derive the dkond approimatioa, we will put, without lass of generafity, (42 3 ) @(F)= eiki"@(r),
+
where is a slowly-vaving function describing the distortion of the hcident wave. Tfpoa inserting thhis into the origind Schmedinger equatian (4.161, we obtain an equation for
+:
+ term can
If we now assume that y5 varies slowly enough so that the be ignored (i.e., k is very large), we have
Here, we have introduced the coordirtilLe b in the plane transverse to the incident be=, so that
Rom synrmelry considerations, we expect that y3 will be azimnthdy symmetric and so independent of 6. Equation (4.25) can be integrated immediagefy and, using the boundmy condition that; $I -.a 1 rua x -4 -W since there is no distortion of the wave befare the pasticle reaches the potentid, we have
V (h, zf) dz'
.
(4.26)
Having obtained the eikonal approximation to the scattering wave function, we can now obtain the eikonal scattering amplitude, f.. Inserting Eq. (4.23) into (4.20), we have
Using (4.251, we can relate V $ directly to &$/at. Furthermore, if we restrict our consideration to relatively small scattering angles, so that q, W 0, then the z integral in (4.27) can be done immediately and, using (4.26) for 4,uve obtain
with the '"rofile fuactian"
Since X is azimuthally symmetric, we can perform the azimuthal integration in (4.28) and obtain our final expression for the eikonal scattering amplitude,
In deriving this expression, we have used the identity [compare with Eq. (4.22)] e-iqb cos 4 d
~ ,
Note that in contrast to fB, f, depends upon both E (through k) and p. An impurtmt praperty of the exact scattefiag mp2itude is the optical theorem, which relates the total cross section to the imaginary part of the forward scattering amplitude. After a bit of algebra, one can show that jC, satisfies this rela4ion in the limit that the inddent momentum becomes large compased t s the length scde over wkicb the potentid vwies:
The Born appro~mcat;iancannot lead to a scattering mplitude that respects this relation, as Eq. (4.21) shows that fr, is purely red. It is also easy to show that, in the extreme high-enerw Emit, w h r e K -+ oo a ~ Xd becomes small, the Born and eikond amplitudes become equal (see Exercise 4.5). The eibonal formula (4.30) also can be related to the usual partial wave expression for f (see Exerdse 4.6). One practical applie&ian of the appradmatiuns discussed above is in, the calculation of the scattering of hi&-energy electrons from neutral atoms. In general, this is a complicated multi-channel scattering problem since there can be reactions leading to find states in which the atom is excited. Hov~ever,as the rewtion pmbabillties ase smdl in comparison to elastic scattering, for many purposes the problem can be modeled by the scattering of an electron from a eentrd potential. This potential represents the combined influeam of the attraction of the central nuclear charge (Z) and the screening of this attraction by the Z atomic electrons. For a neutral target atom, the potential vanishes at large distances faster than r-l. A very accurate approximation to this potential can be had
4.8 Born and eQonal appwdmations to quantum scattering
by solving for the sel&consistent Eartree-Fodc potential of the neutral atom, as was done in Project III. However, a much simpler estimate can be obtained using an approximation to the Thornas-Fermi model of the atom given by Lenz and Jensen [Go49]:
with
and S
= 4 . 5 3 9 7 ~ ' / ~ ~.' / ~
Here, the potentid is measured in eV and the radius is measured in A. Note that there is a possible problem with this potential, since it is singular as r-' at the origin, and so leads t o a divergent expression for X at b =. 0. However, if the poten.tial is regularized by taEng if to be a canstmt within some small radius r,iB, (say the radius of the atoms ls shell), then the cdculated cross sectian will be unaEected except at xnornentnm trmsfers fage enough so that gqrmin > 2. Qur god is to c m p u t e the Born and eikond wpro~mationsto the differential and t o t d cross eections for a given cetllrd potentid at a specified incident energy, and in particular for the potential (4.32). To do this, we must compute the integrals (4.211, (4.29), and (4.30) defining the scattering amplitudes, as well as the integral (4.19) for the total cross section. The FORTRAN progrm for Example 4, whose source code is @yen in Appendix B, as; well in the file EXMPL4,FQR, does these edcdadions and papbs the results on a semi-log plot; the t s t d cross se~tiongiven by the opticd theorem, Eq. (4.31), is also ealcufated. The incident paticle is wsunned to have the mzlss of the electron, and, as is appropriate for atomic systems, all lengths are measured in A and d l energies in eV, The potentid can be chosen to be a square well of radius 2 A, a Gmssian well af the farm
or the Lenz-Jensen potential (4.32). All potential8 are assumed to vanish beyond 2 A. hrthermore, the r-' singularity in the Lenz-Jensen potentid i s cutoff inside the radius of the Is she11 of" the target atam,
201
102
4. Speial
hnctions and Gaussian Quadmlure
Because the diRerentiaf crws sections 'become very peaked in $he forward direetion at the high energies where the Born and eikond approfirnations are vdid, the integration over cos 6 in Eq. (4.19) is divided into two regions far a mare accurate integraiola of tbe forward peak. One of these extends from B = 0 to B = Bcut,where ~cut&,r
f
= 2~ = 2kR,.t sin 58,ut
and RC.&is 1k . for the Lenz-Jensen potential and 2 A for either the squareor Gaussian-well potentials, and the other eaends from B,,b to x. AU integrds are done by Gauss-Legendre quadraturn usiny; the s m e number of points, and the Bessel function of order zero required by Eq. (4.30) is evaluated using the approximations (4.4). The fouowing exercises are aimed at improving your understanding of this p m g r m and the physics it describes. m Exercise 4.5 Verify the dgebrs in the derivations above. Show that in the limit of very high energies, where X is small, so that sin X w the Born and eikond results are identicd, Also prom that the eikand amplitude satisfies the optical theorem (4.31) in the limit where the inei&nt momeaturn becomes large in comparison with the length scde of the potentid. Exercise 4.6 Show that if the eonventiond expression for f in terms of a sum over partial waves [Eq. (IV.4) below] is approximated by an integal over I (or, equivdently, over b = Ilk) and the sma-ll-&/lmge-l approdmation &(cos 8 ) F;I JO(l@)
m
Investigate, is used, Eq. (4.30) results, with the identification ~ ( b=) either numerically or mdytically, the vddity of this; relation between the Bessef function of order zero and the Legendfe polynomids.
Exercise 4.7 Test the Born approdmation. crass sections generated by the code by comparing the numerical d u e s 4 t h the analytical Born results for a square or Gmssim well of depth 20 eV and for varying incident energies from 1 eV to 10 keV. Verify for these cases that ~ ( bas) computed by the code has the expected values. bestigate the variat;ion of the nunrezlicd results with & a g e s in the number of quadratare points. (Note that only particular values of N are allowed by the subroutine generating the Gauss-Legendre abscissx and weights.) m
IV. Partial wave sohtion of quantum scattering
Exereise 4.8 Fix the depth of a square well at 20 eV and cdculate for various incident energies to get a feeling for how the differential and total cross sections vary. Compare the square well cross sections with those of a Gaussian well of comparable depth and explain the differences. Show that the Bmn and eikond results i c p p ~ s deach other at high energies for either potential and that the optical relation for the eikonal amplitude becomes better sadisfied at higher energies.
m
Exercise 4.9 Using the Lenz-Jensen potential m d a fixed charge and inddent energy, say Z = 50 and E = 1000 eV, investigate the sensitivity of the calculation to the number of quadrature points used and to the small-r regularization of the potential. Calculate the cross sections for various Z ranging from 20 to 100 and for E ranging from 10 eV to 10 keV; intergmt the trends you observe, Exercise 4 x 0 Use the program constructed in Project I to calculate the classical differential crass wctim for electroas scattering frem the Lenz-Jensen potential for various Z and incident energies. Compare the results with the Born and eikonal cross sections, Cm p u e~titblishm analytic& connection between the classical description and the quantum approximations:' (See [Ne66] for a detajled discussion.)
m
Project IV: Partial wave solution of quantum scattering Ta this project, we will use the method of partid waves to solve the quantum scattering problem for a partide incident on a central patentid, and in particular consider the low-energ scattering of electrons from neutrd atoms. The strategy of the method is to employ a pafliaI wave expansion of the scattering wave funetion to decampme the thr~-dirmensiond Schroedinger equation (4.16) into a set of uncoupled one-dimensional ordinmy diEerentid equations for the radial wave functions; each of these is t b n soltved as a boundary-vdue problem to determine the phme shift, and hence the scattering aplitude.
IV.1 Partial wave decomposition of the wave function The standard partial wave decomposition of the scatLering wave funetion @ ie
When this expmsion is substituted into tbr! Schroedinger equation (4,161, the ra&aX wave functions we found to satisfy the r d i d diEerengiaf
103
Although this is the same equation as that satisfied by a bound state wave function, the boundary conditions are different. In particular, R vanishes at; the origin, but it hils the large-r aaymgto-ticb e h d o r
RI -+ kr[cos Grjr(kr)- sin 61nl(ks)],
(IV.3)
where jl and nl are the regular and irregular spherical Bessel functions of order I. (See Exercise 4.3.) The scattering amplitude f is related to the phase shifts by
f (B) = 5
(2f
+ l)ei61sin 6rq(cos 8) ,
(N.4)
I=O
and the total cross section is easi?y found from Eq. (4.19) and the arthogonality of the Legendre polynomials, (4.10):
Although the sums in (W.4,5)extend over all I, they are in practice limited to only a finite number of partid waves, TUs is because, for large I, the repulsive centrifugal potential in (IV.2) is effective in keeping the particle mtside the rmge of the potential and so the phase shift is very s m d . If the patentid is negiigible beyond a radius r,,, an estimate of the highest partial wave that is important, lmax, cm be had by setting the turning point at this radius. T h s ,
+
~max(lmax
=E,
2mrkax
wbich leads to E,,, brm,,, This estimat;e is usuatly slightly low, since penetration of the centrifugd barrier leads to non-vanishing phase shifts in. part;ial waves somewhat, higher %hagthis.
IV.2 Finding the phase shifts To find the phase shift in a given partial wave, we must solve the radiat equation (TV.2), using, for example, the Numerov method discussed in Chapter 3. Although the boundary conditions specified by (IV.3) and the vanishing of R at the ongin are non-local, we can still integrate the
f V, I""art;ialwave klolution of qvrantvna scattering
equation as an initid value problem. This is because the equation i s linear, M) that the bonndary condition at large r can be satisfied simply by appropriately normalizing the solution. If we put Rl(r = 0) = 0 and take the value at the next lattice point, R I ( ~= h), to be any convenient smdl number (R will generally rise rapidly through the centrifugal barrier and so we must avoid overflows), it would seem that we were ready to use the Numerov method. However, k(r = 0) is infinite. The solution is to use Eq. (1.7) for Ry(h), along with the known valuesRI(0),Rt(h),and k(h) to find R1(2h). Now we can (See Figure IV.1.) Here, integrate outward in r to a radius r(') > P,,,. V v a ~ s h e sand B must be a line= cambination of the free solutions, krji(kr) and kmr(kr):
R[') = ~kt(')[cosbrjl(kr('))- sin 61nr(kr('))].
(m6) Although the constant A depends upon the vdue chogen for R(T = h), it is largely irrelevant for our purposes; however, it must be kept small enough so that overflows are avaided* Knowing anly R!') does not allow us to solve for the two unknowns, A > t(l), and 61. However, if we continue integrating to a larger radius then we dsa have
&I2)
-
.
= ~ k r ( ~ ) [ c6tjr(kr(2)) os sin 61nl(kr(2))]
(IV.7)
Equations (IV.6,7) can then be solved for tir. After a bit of algebra, we
where jj') = jr(kt(')), etc. Note that this equation determines sl only within a multiple of n, $though this does not affect the physical observables [see Eqs. (IV.4,5)]. The correct number of ir's at a given energy can ned by comparing the number of nodes in R and in the free solution, krjr, which oecar for T < pmX. With the conventionid deenitims we have used, the phase shift in each paftial wave vmishes at hi& energes and approaches fia at zero energy, where Ni is the number of bound states in the potentid in the b'th partial wave.
IV.3 Solving the equations Our gad in a nrtmesicd treatmenL of this problem is to investigate the scattering of electrons with mer@iesffom 0.5 tlV to 10 keV from the potential (4.32); a radius r,,, = 2 A is reasonable. For the charge Z
105
106
4. S m i a l Elmctiaw and Gausst'an Quadraturn
Figwe IV.1 (Upper) Schematic chentGfagilrl potentid (dahed line) and eRective tot& pakntid (saEd line) in a pastlid wave I r 0. The i n d e n * energy is Am shawn (horizontal Iiae), as are the range of the potential (rmax) and the twa matching radii, r(') and.)'(F (Lower) Schemagc scattering wave fnnction, RI (solid line), and free wave func*ion, &P& (dwhed line), fox "thesame erituadian.
w d energ E spedfied, the program should cdculate the p h a e sMft and plot the ra&d wave function for each imiportaant pastid wave, and then s m the contributions fram each t to find the total cross section and the diRerent;id crass section a9 a function of 8 from 0' to 180°,say in 5' steps, This program can be constructed and exploited in the following sequence of steps. Step 1 Wdte a subrougiae that camputea the values of the Legendre polynomials for the degrees and angles required and stores them in an array [See Eq. (4.1).] Aiso write a subroutine that computes jl and nr for a given value of r . (See Exercise 4.3). Cheek that these routines are working correctly by comparing their results wit h tabulated values. Seep 2 Wrige a a;ubrontiae f i a t calculates the? phwe shift, in a specified partial wave. Use the Numerov method to integrate to r(') and then
r
JV. Padial wave solution of quantum scattering
Figure IV.2 WeaHy-bound levefs of the LeneJanmn posential. Levek with a negative p;trity (p and f) are shown by dwhed curves.
and then determine the phase shift from Eq. (IV.8). Note that to is too close to rfl), problems with numerical precision may arise if (both the numerator and denominator of (IV.8) vanish), while too great a distance between the matching radii leads to wasted computation. Check that your subroutine is working properly by verifying that the calculated phase shift vanishes when V ( T )is set to 0 and that it is independent of the choice of the matching radii, as Iong as they are grea;2;er t b a v., .&so check that the phase shifts you find far a square-well poteatid agree with tharse that y o can ~ cdcufate andytically, Note th& since quite a bit sf numel.ical work is invdved in the cdculation of the Lenz-Jensen potentid (4.32), it is most efficient if the d u e s of V at the lattice points are stored in an array to be used in the intqration of all impartant partial w&veS. Seep 3 Write a mdn pragram that, for a e b q e m d energ, calls the subroutines you have congtructed in pedaming the sum aver partial waves to calculate the totd md diEerentia2 croh;s sections. Verify that your estimate of I,, is reasona;ble in that 4 non-vmisbing phwe shifts are computed but .that no computationd eEort is wasted an partid waves for whiCh the phase sEA is negZi&ble.
Step 4 Study the cross section as ia function of e n e r o for severd Z, say 20, 50, and 100, Show that, at low energies, resonances occmring in particular partid waves m&e the m&ar distributions quite camplex and the t o l d cross sections very ener&y-dependent,bat that alT[quantities
m
107
become smooth &ad monotonic at Egh energies. Tabulations of experimental data with which to compare your results are given in [Ki71]. Also compare your high energy results with the Born aad eikond approxirnatisns genera;ted by the p r s r a m in Example 4, Step 5 To unhstafld the ]low-energ resoaances, colasider F i e r e N.2, whi& gives the enerdes of w e A y bound levels in the LenzJensen potentid as a function of Z. By studying the cross section at a fixed energy of 5 eV as s function of Z, how th& the regions new Z = 46 and Z = 59 reflect the extensions of the 2p and Id bsuad st&es into the continuum. By examiaing the Z =. 59 cross swtion, anguIas distribution, p h ~ shifts, e and rodid wave funetiona as functions of eneru mrar E = 5 eV, show that; the resonance is indeed in the I = O a r t i a l wave. Note that sin= the Lenz-Jensen poteatid is bwed on the ThornasFermi approfimation, it is not expected to be accurate in the outer region of the atom. The resonance energiw and widths you find %hereforediRer guantitatively from tho8e that are foand in experiment.
m
Step 6 Use the UlarItree-Fock code from Ffoject 111 to generate the direct potential, @, for the neutral He atom and modify your program to calculate the scattering of electrons from this potentid. Note that when the energy of the inddent electron is large, it is easily "distinguishable" from the electrons in the atom, and so any effects of the Pock (exchange) potential will be small. Compare your results with those produced with the Lenz-Jensen potential. A further discussion of the electron-atom scattering problem can be found in [Bo74].
m
Chapter 5
Matrix Operations Linearization is a common assumption or approximation in describing physical processes and 80 finear systems of equations are ubiquitous in computational physics. Indeed, the matrix manipulations associated with finding eigenvalues or with solving simultaneous linear equations are often the bulk of the work involved in solving maay physical problems. Ia this chapter, we will discuss brieffy twa of the more non-trivid matrix operatiormst inversion and diagondization. Our treatment here will be confined largdy to @directB methods appropriate fm "dense" mattries f where most of the elements are on-zero) of dimension less than severd hundred; iterai;tive methods for treating the very large sparse matrices that wise in the discredization of ordinary and partial dcligerentid equations will be discussed in the foaming two chapters. As i s the case with the special functions of the pmvious chapter, a vwiety of library subroutines ernploying several different methods for golving matrix problems are usudly avdlable m any large computer. Our dis;eussions bere me therefore limited to selected basic methods, to give a Aavor of whad has to be done, More detailed treatments can be found in many texts, for example [Ac70] and [Bu81].
5.1 Matrix igxversian Let us consider the problem of inverting a square ( N x N ) matrix A. This might arise, for example, in solving the linear system
for the unknown vector X, where b i s a known vwtor. The most naturd way of doing this is to follow our trJning in elementary algebra m d use Cramer's rule; i.e., to evaluate A-' as being proportional to the transpose of the matrix of cofactors of A. To do this, we would have to cdcnlate
110
5, Matrig Operations
N 2 deterdnants of matrices of dimension ( N - 1) X ( N - 1). If these were done in the most naive way, in which we w u l d evduate
for the determinmt of the N x N mat;rix A, where P is one of the N ! permutations of the N columns, Pi is the i'th element of P, and ( - ) P is the signature of E", then the numericd work would be horre~bo.tls. Far example, of order N ! multiplications are required to evaluate (5.2). For N = 20, this is some 2 x 1 0 % multiplications. ~ On the fastest computer currently available, 10s multiplications per second might be possible, so that some years are required just to invert this one 20 x 20 matrix! Clearly, this is not the way to evaluate determinants (or to invert matrices, as it turn8 out). One of the simplest practical methods for evaluating AmSis the Gauss-Jordan method. Here, the idea is to consider a class of elemen_t;asy row apttrations on the matrix A. These Involve multiplying a paticdar raw of A by a canstant, interchmging twa rows, or adding a multiple af one row to another. Each of these t h r e operations can, be represented by left-multiplying A by a simple matrix, T. For example, when N = 3, the
will multiply the third row by 2, interchmge the first and second rows, ancl subtrwt one-half of the first; row from the tKrd row, respectively. The Gauss-Jordan strategy is to find a sequence of such operations, which, when appEed to A, reduces it to the unit matrix. That is, so that T = A-' is the required inverse. Equivdently, the same sequence of operations applied to the unit matrix yields the inverse of A. A practical method to find the appropriate sequence of row operations is best illustrated by example. Consider the 3 X 3 matrix A and the unit matrix:
We first apply transformations to zero all but the first element in the first column of A. Subtracting 4 times the first row from the second yields
and then subtracting twice the first row from the third yields
We now go to work on the second column, where, by adding 1/3 of the secscoad raw to the first;, we can zero EtU but the second element:
and, multiplying the second row by -1/6 yields
Findly, we can reduce the third column of TA to the r e q ~ r e dform by adding 113 of the third row to the fimt and sec-ond rms, and then mdtiglying the tErd row by -1:
This finds the required inverse. A. moment's thought show8 how t k s dgadthm c m be geaera-lized to an 1V x N rnafix and that, when this is done, it requires, for Iwge N, of order N 3 multiplications and additions. Thus, it is computationally tractable, as long as N is not too fwge. In practice, several subtleties are important. For example, it might happen that, at some point in the pracedure, the diagond element of TA vanishes in the column we are working on. In this case, an interchange of two rows will bfing a noa-va~shingd u e to this '"ivotn element (if no such row interchange can do this, then the matrix A i s singular). In fact, numericd accuracy requires that; rows be interchanged to bring into
f l2
5. Matrix Operations
the pivot pasition that element in the column being worked on that has the largest absolute vdue. Problems associated with numerical roundoff can also arise during the inversion if elements of the matrix differ greatly in magnitude. For this reagon, it is often useful to scale the rows or columns so that afl entries have roughly the same magnitude ("equilibration"). Various special cases (such as when A is symmetric or when we are only interested in solving (5.1) for x and not for A-' itself) can result ia reductioas of the numerical work. Far exmple, in the latter c a e , we can apply T only t o the vector b, rather than t a the whde unit matrix. Rndly, if we are interested in computing only the deterdaant of A, successive row transformations, whicfi have a simple and easily calculable egect on, the determinant, can be used to bring TA to lower or upper d i ~ o n dform (all ekntents vmishing a b m or b d w the diagonal, respectively), and then the deteminant can be evaluated simply as the product of the diagond elements, Exercise 5.1 Use Eq. (5.2) to show that interchanging the rows o f a matrix changes the sign of its determinaxlt, that adding a multiple of ane row to anot her leaves its determinant unchanged, and that multiplying me row by a c o n s t a t mdtipfies the deteminant by that saxne constant.
m
Exercise 5.2 Write (or just flowchart) a subroutine that will use the Gauss-Jordan method t o find the inverse of a given m&rix, 1ncorporat;e pivoting as described above 2 0 Improve the numerical accuracy.
E
5.2 Eigenvalues of a tri-diagonal matrix We turn now t o the problem of finding the eigenvalues and eigenvectors of an PC7 X N matrix A; that is, the task of finding the N scdars X, and their associakd N-component vectors 4, that satisfy Equivdently, the eigenvalnes are zeros of the N" %h degree characteristic polynomid of A:
n(xnN
PA(A) det (A - XI) =
A)
.
(5.77
n=l
For simplicity, we will restrict our discussion to matrices A that w e r e d and symmetric, sa that the eigenvalues Etre always r a l and the c?igenwctors can be chosen to be arthanormal; this is the most common: type of matrix arising in modeling physical systems. We will also consider only cases where atl or many of the eigenvalues are required, and possibly their
&,l? bf"igc3nvotues a tri-diagonal ntcrkria:
associated eigenvectors. If only a few of the largest or smallest eigenvalues of a large matrix are needed, then the iterative methods described in Seetion 7.4, whicb invalve successive applications af A or its inverse, can be more eaeient. The generat strategy for diagonalizing A is to reduce the task to the tractable one of finding the eigenvdues and eigenvectors of a symmetric tri-diagonal matrix; that is, one in which all elements are zero except those on or neighboring the diagonal. This can always be accomplished by applying a suitable sequence of orthogonal transformations to the original matrix, as described in the next section. For now, we assume that A has been brought to a tri-diagonal form and discuss a strategy for finding its eige~vdaes, To find the eigenvdues of a symmetric tri-diagonal matrix, we must find the roots of the characteristic polynomial, (5.7). This polynomial is &wn in terms of the element8 of A by the deterzninmt
(5.8) where all elements not shown explicitly are zero and where the symmetry of A implies that A,, = A,,. To find the zeros of Payany of the root finding strategies discussed in Section 1.3 can be employed, providing that we can find the numerical value of PA for a given value of X. This latter can be done conveniently in a recursive manner. Let P,(A) be the value of the n x n sub-determinant of (5.8) formed from the first n rows and columns. Clearly, P, is a po?ynomid of degree n, PN = .PA (the polynomial we are after), and
p ~ ( h=) At1 - X ; &(X) = (A22 - A)& (A) - A& . (5.91 Moreover, by expanding the determinmt for P, in terms ol' the minors of the n'th colurn, it is easy to derlve the reearsion relakion
3.13
This, together with the starting values (5.9), allows 8n efficient evaluation of pA* m
Exercise 5.3
Prove Eq. (5.10) above.
Several features of the problem above help considerably in finding d used, it is quite the roots of .PA. If m algorithm like Neartank s m h ~ is easy to differentiate (5.10) once or twice with respect to X and so derive recursion relations altovving the simple evaluation of the first or second derivatives of PA(X).More importantly, it is possible to show that the number of times the s i p chastge~in the sequence
is eqad to the number of eigenvdues less than X, This faet is umful in several. way~3: it is a, means of m&ing sure Lbat no roots are skipped in the search for eigenvduea, it provide8 a gimple lay of loedzing a root initially, and it can be used with the simple search prowdue to locate the root accurately, althou@ perhaps not in the most efieient vvay possible. To make a systematic search for all of the eigenvdues (roots of Pa), it is esserrtid to know where to b e n looking. If we me working through finding the entire sequence of eigenvalues, a natural guess for the nexthighest one is some distance above that eigenvdue just found. Some guidance in how far above and in how to estimate the lowest eigenvalue can bo found in. Gerschgorin" bbounds an the eigenvdurss. It is quite simple to show that
and th&
for dl n. For the tri-diagonal forms under consideration here, the sums over j in these expressions involve only two terms. The lower bound, Eq. (5.11a), is a convenient place to begin a search for the lowest eigenvalue, and the difference between the upper and lower bounds gives some measure of the average spacling between eigenvdues,
5.3 ReSduetion to tri-diagonal form
lExwcim 5.4 Write a subroutine that finds aS1 of the dgenvalues of a tri-diagonal maitrk using the procedure &&crib4 above, together vvith any root-finding dgorlthm. p u fincl convenient. Test your subfoaine on an IV x N tri-diagond matrix of the form
t
whose eigenvalnes are known andytically to be
5.3 Reduction to tri-diagonal form
To apply the method for finding eigenvdues discussed in the previous section, we must reduce a general real symmetric matrix A to tri-diagonal form, That, is, we must find an orthogo~alN X N matrix, 0,satisfying where Ot iis the transpose of 0,such that O'AO is tri-diagonal. Elementary considerations af linear algebra imply that the eigenvdues of the transformed matrix are identical to those af the oiiginail matllix. The problem, of m r s e , is to fiad the preGiaje farm *of 0 for my pafticular matrix A. We discuss in this section two methods far egecting such a trm~formatisrr. The Householdt?r method is a common and convenient strategy for reducing a rxraldx to tri-8iagond form, It takes the miltrh Q to be the prodnct of N - 2 of'chogond m&rices, each of which sucetlissively traasforms one roar and column of A into the required form. (Only N - 2 transformations are required as the last two rows and columns are already in tri-diagonal form.) A simple method can be applied to fixrd each of the 0,. To be mose explidt about how the Wouseholdftr dgorithzn. ucrorks, let us consider finding the Brst mhogonal transfomation, Q which we will choose to a;nniPuilate mmt af the first row and column of A; that; is,
125
Here, k(') is a possibly non- ishing element and the matrix is the result of applying the transformation to the last N - 1 roars and columns of the original matrix A. Once O1 is found and applied (by methods discussed below), we can choose 0 2 8 0 that it effects the same kind of transformation on the matrix A(?);that is, it annihilates most of the first row and column of Lkizt matrk a d Lrmsforms its last N - 2 rows m d coltlmns:
Continued orthogonal transformations of decreasing dimension defined in this way will trmsform, the ori&nd maLrix into a tri-diagond one dtes a total of N -. 2 transformations, the diagonal elements of the transformed nrat;rix being
and the OR-d;iagondelements being
It remdns, of courm, to find -the predse form 0.f each of the Q,, We IUzzstra;te the proceduze with Ox,which we take ta be of the h r m
where O is an N - l-dimensional column vector of zeros, at is a similar row vector, and P is an (H- l) x ( N - l) symmetric matrix satisfying
if 0 is to be arthogond. (In these expressions and the following, for simplicity we have dropped all superscripts and subscripts which indicate that it is the first orthogonal transformation of the sequence (5.13) which is being discussed.) A choice for P that satisfies (5.17) is
-
In this expression, I is the N l-dimensional unit matrix, u is an N dimensionat unit vector satisfying
and the last term involves the outer product c&
U
- 1-
with itselt Each element
of (5.18) therefore reads
-
where n and m range from 1 to N 1. (It should cause no confusion that the indices on P and u rmge from 1 to N - l, whife- thase on the full matrices 0 asld A range fram 1to N.) Under a transformation of the form (5.16), A becomes
where we have defined an N - l-dimension& vector ar ss all elements but the 6rst in the first column of A; th& is, ai =: Aicr,z for i ranginl; ffom l to N - l. Upon comparing (5.20) with the desired form (5.14), it is apparent that the action af l? on, this vector must yield where k is the vector
k = [k,0,O,...,01'.
Equation (5.21) is what we must solve to determine U, and hence the required transformation, P. To do so, we must first find the s d a r h, which is easily done by taking the scalar product of (5.21) with its transpose and using the idempotence of P [Eq. (5.17)]:
so that k = f a . Raving found k (we will discuss the choice of the sign in a moment), we can then rearrange (5.21) as
Upon taking the scalar product of this equation with itself, using a k k= rtAzla, and recalling (5.22), we have
so that we can then solve (5.21) for
U:
This completes the steps necessasy to find P, To recapituJaLe, we first solve (5.22) for k, then calculate the square of the scalar product (5.24), form the vector U according to (5.25), and then finally P according to (5.18). In evaluating (5.24), considerations of numerical stability recommend taking that sign which makes the right-hand side largest. Note that we need evduate only the square of the scalar product as the vector u enters P bilinearly. Note also that a full matrix product need not be performed in evaluating A@).Indeed, from (5.18,20) we have
where the symbol A ia tlzis exprese~ionrstands for the square symmetric m&rix famed from the last N l rows m d columns of the origind matrix. Thus, to evaluate A@),once we have the vector u we need only calculate the vector Au and the scalar utAu. Finally, we note that n a m e ~ c dstabigty durhg the successive trasfarmations is improved if the diagonal element having largest absolute m a g ~ t u d eis in the upper ldt-baad corner of' the sub-nz&fix being trmsfo~med. Tlris can dwaye~ be arranged by a suitable interchange of rows and columns (which leaves the eigendues invwimt) &er each of the arthogand traasfamations is applied.
-
By writing either a detailed flowchart or aa w t u d subroutine, convince yourself that you understand the Householder algorithm descdbed above.
r Exmciae 5,5
With an algorithm for transforming A to tri-diagonal form, we have specified completely bow to find the eigenvalues of a real symmetric matrix. Once these are in hand, the eigenvectors are a relatively simple matter. The method of choice, inverse vector iteration, works as foEows. Let 4:) be any guess for the eigenvector associated with X,. This guess cm be refined by evduating
Here, E is a s m d , non-zero scalar that allows the matrix to be inverted. It is easy to see that this operation enhances that component of 4:) along
5.3 Redu~tirrnIf0 Eri-diagonalfarm
the true eigenvector at the expense of the spurious components. Normalization of (p?), followed by repeated refinements according to (5.27) converges quidtly to the required eigenveetor, often in only two iterations. An dternative to the Householder method is the Lanczas dgodthm [Wh77], which is most suitable when we are interested in many of the lowest eigenvalues of very large matrices. The strategy here is to construct iteratively a set of orthonormal basis vectors, ($,), in which A is explicitly tri-diagonal. To begin the construction, we choose an arbitrary = 1. We then form normalized so that first vector in the basis, the second vector in, the basis as where All = +:kgbl (it i s not the element of A in the first row and = 1: column), and Cz is a normalization chosen to ensure that $i$2 = 0. Subsequent vectors in the basis are It is easy to show that then constructed r-ecursively W with Thus, each successive is that unit vector which is coupled to qb, by A and which is orthogonal to both gb, and The matrix A is explicitly tri-diagonal in this basis since Eq. (5.30) shows that when A acts on @ ,, it yields only terms proportional to and $,+l. Continuing the recursion (5.30) until +N is generated completes the basis md the representation of A in it. The Lanczos method is well-suited to large matrices, as only the ability to apply A to a vector is required, and only the vectors $, and A*, need be stored at any given time. We must, of course, also be careful to choose 9%so that it is not an eigenvector of A. However, the Lanczos method is not appropriate for finding all of the eigenvalues of a large matrix, as round-off errors in the orthogonalizations of (5.30) will accumulate W the recur~ivegeneralion of the basis proceeds; i.e., the scalar products of basis vectors with large n with those having small n urilji not mnish identiedy. The red utility af the La-nczw dgorithm is in cwes where many, but not dl, of the eigenvd~esare required, Suppose, for example, that W
119
are interested in the 10 lowest eigendues of a matrix of dimension 1000. What is done is to generate recursively some number of states in the basis greater than the number of eigenvdues being sought (say 25), and then to find the 10 lomst eigenvdues and eigenvectors of that lirnited sub-matrix. If an arbitrary linear combination (say the sum) of these eigenveetors is then used as the initid vector in constructing a new basis of dimension 25, it can be shown that iterations of this process (generating a linrited basis, diagon&zing the correspondint.; td-diagonal mdrix, and using the normazed sum of lowest eigenvectors found as the first vector in the next basis) will converge to the required eigenvalues and eigenvectors. Exaeise 6.6 Write a subroutine that uses the Lanczos method to generate a complete basis in which a symmetric input matrix A is tridiagonat. The proearn should output the diagonal and a@-diagond elevectors themriidves. Show by ments of A in this bmis, m well W the biit~ii~ explicit exmple that if the &mensim of the matrix is too large, round-0% errors cause the basis w e r a t e d to be inwmrate. Try cming this problem by doing the computation in double-precision. withmetic and obwwe the resdts.
m
Exercise 5.7 A simple limit of the Larrczoa3 procedure far generating and truncatiag the bads is d e n we ~e interegted in only the! lowest eigenvdue and retain only and to form a 2 x 2 matrix to be diagondized. Show thae tlre lawer eigenvdue of this matrix is dways less than or eqaad to AI1, so that iterations of the procedure lead to a monotonic d y decreasing estimate far the Iawe8t eigenvdue of AL. This paocedure is d a ~ d related y to the time-evolution alga~ithmdiseusmd in Section 9.4.
5.4 Determining nuclear charge densities The distribution of electric$ charge within the atomic nudeus is one of the mast basic wpects of nuclear structure. The interxtions of decbrons and muons with the nucleus c m be used ta determine this distr3bution with great precision, as these particles interact almost exdusively t hrongh the well understood electromagnetic interxtion (for a general discussion, see (Fo661). In this example, we will explore how the experimentally determined cross sections for the elastic scattering of high-energy (several 100 MeV) electrons from nudei can be andyzed to determine the nuclear charge distribution; the method relies on the solution of a set of linear equations by mt;tLrix inversion. To illustrate the basic idea, we begin by considering the scattering of non-relativistic electrons of momentum k and energy E from a locatized
5.4 Determining nuclear &awe densitias
charge distribution, p(r), that contains Z protons, so that
and that is fixed in spaee. The electrons interact with this chmge distribution through the Coulomb potential it generates, V(r), which satisfies IPai~~on's equation, V'V = 4 n a p , (5.33) where a = 1/137.036 is the fine structure constant. (We henceforth work in w i t s where K -- e = 1, unless explicitly indicated, m d note that he = 197.329 MeV-h.) The Born appro~matianto quantum sc&tering t2iscussed in the pmvious chapter illustrates how electron scattering cross sections carry information about the charge distribution, atthough precision work r e q ~ r e s a better approdmat;ion to the sc%ttering, as discussed bdow. Equations (4.18,4.21) show that the Born cross section for scattering through an mgle 8 is proportional to the square of the Fourrier tran~forsnof the potential at the momentum transfer q, where q = 2k sin +B. The Fourier transform of (5.33) results in
where is the Faurier transfom of the charge density; Thus, the difirentid cross section can be written as (we use o as a shorthand notation for dgjdS1):
Here, the Rutherford cross section for scattering from a point charge of strength Z is
m is the electron mass, and the nudear 'form factor" is F ( q ) = Z-'p(q). For the spin-0 nudei we will be considering, the charge density i s sphericdly symmetric, so that p(r) = p ( r ) , and
F h ) = F(p) =
dr r sin qrp(r) .
121
Equation. (5.36) illustrates how dectron scattering is used to study nude= structure, Deviations of the mewured c r a ~ ssection from the Ruthefiord vdue are a, &reet mewure of the Fourier trmsform of the nuclear chmge density, It d s o shows that scatterings at hi& momentum trmsfers are needed to prsbe the nucleus on a fine spatial scale, As nuclear sizes are typically several fermis ( 1 0 - l ~cm), a spatial resolution better than 1 fm is desirable, implying xnomeaturn transfers of sewraj. fm-' and so beam energies of several hundred MeV. (Recall that 2k is the =&mum momentum. transfer that can be whieved with a beam of momentum h.) At energies of sew& handfed MeV, the electron is highly dativistic (the electron mass is only 0.511 MeV) and so the discussion above must be redone beginning with the Dirac equation rather than the Sehroediner equation. One trivial. change in the find expressions that result is tha'c ultra-relativistic kinematics are used for the electron (i.e., its momentum is proportional to its energy), so that the momentum transfer can be
The only other modification to Eq. (5.36) is that the Rutherford cross section is reptwed by the Mott cross section,
where the additional factor of cos )B in the scattering amplitude arises from the spin-$ nature of the electron. Let us now consider haw meaured crass sections are to be andyzed to determine the charge density. Suppose that we have a set of I experimental values of the cross section for elastic scattering of electrons from a particular nudeus at a variety of momentum transfers (e.g., angular distributions at one or several beam energies). Let these values be @,P and their statistical uncertainties by Ai. Suppose also that we parametrize the nuclear chmge density by a set of N pwameters, C,, so that p ( r ) = p(r; {C,)). O f course, the C's must be chosen so that the normalization constraint (5.32) is satisfied. That is,
A specific choice for this parametrization will be discussed shortly.
5.4 Determining nuclear charge ctensilieil
The usual methods of data andysis [jCSe69]state that the "best" values of the parameters C, impled by the data are those that minimize
subject to the normalization constraint (5.41) above. Here, of is the '%heoreticdwcross section cdeulated from the appropriate Matt cross section and nuclear form factor; it depends parametriedly upon the C%. This minimum value of xZ measures the quality of the fit, a satisfactory value being about the number of degrees of freedom (the number of data points less the number of parameters). There are several computational. strate@afor finding the parameters that minimize xZ or, equivdently, that satisfy the N non-linear equations
This is a, specific: exmgle of the commonly encountered problem of &nirnizing a non-lineas function of several parmetws; it is d e n fraught with &Bedties [Ac70], not the least of which is finding a local minimum, rather than the globd one usudly mug&, Most strat&es are based on an iterative refinement of a ""g%essnfor the sptinrd C,, sad, if this guess isr dose to the required solution, there is usudly no problem. One ~ommonlyused approarh i s to compute the direction of the N-dimensional gradient [lefthand side of (5.43)] either analytically or numerically at the current guess and then to generllte the newt guess by stepping some distance in C-space directly away from this direction. Alternatively, a multi-dimensional generalization af the Newton-Raphson method, Eq. (1.14), can be used. The simple approach we will adopt here is based on a local linearization of of about the current guess, C:. For small variations of the C's about this point,
C, = c:+Gc,,
the theoretical cross sections can be expanded as
so that
x2 is given by
123
where of is the theoretical cross section corresponding to the current guess, C'. The charge normalization constraint (5.41) can be linearized similarly a
where we have assumed that the current guess is normalized properly, so that Z({C:)) = Z. Equations for the &C's which make x2 stationary can be had by requiring
Eere, we have introduced a L a g r w p multiplier, 2X, to ensure the proper charge normalization. Some simple algebra using Eqs. (5.44,45) then results in the Eineatr equations
h r a given guess for the C", Eqs, (9.47) can be sofved to de2;erdne what change in the C's will reduce XZ, subject to the validity of the linearization, The new impraved values can thm be amd as the next guess, the process being continued until X Z converges to a minimum. To solve Eqs. (5.471, it is convenient to define the (N 1)x (N 1) matrix
+
and the N
+ l-component vector
+
(The inctices m a ~ ndin thege expressions range aad identify X from 1to N.) Equations (5.47) can therefore be written as
which is simply s d w d by inversion o;f" the symmcetpic matrix A:
After the process described above caBverges to the optimal values to the C'ss,m can then enquire into the precision with which the parameters are d e t e r ~ n e d ,This can be related to the matrix A defined above as faBaws. Let us consider an ensemble of data mts in whicb each experimental cross section fluctuates independently abaut its mean vdue. That is, (aoyb~;) = ~ t, & ~ ~ (5.52) where (. ..) denotes ensemble average, and 6of is the deviation of offrom its; mean d u e . Such fliuetuations lead to fluctuations of the G'"sabout their optimal value. Since the b, are linearly related to the experimental cross sections by (5.48), these fluctuations are given by (5.51) as
Upon using this equation twice (for 6C, and &C,) and taking the ensemble average, we have, after some algebra,
The uncertainties in the density parameters can be translated into a more physical statement about the correlated uncertainties in the density itself by expanding the parametxized density about the optimal parameters. In particdar, the correlated ancertdnties in the densities at radii r m$ r f can 'be writtemr as
Thus, ( 6 p ( ~ ) b p ( r ) ) 2can / 2 be taken as a measure of the precision with which p ( ~ is ) determined, although it should be remembered that the
uncertainties in the density determined at different spatial points are correlated through (5.55). We now turn to the parametrisation of p(?). On general grounds (for example, the validity of treating the nucleus as a sharp-surface, incompressible liquid drop), we expect the charge density to be fairly uniform within the nuclear interior and to fall to zero within a relatively thin surface region. This picture was largely confirmed by early electron scattering experiments [Ho57], although the measured cross sections extended only to momentum transfers less than about 1.5fm-' , WE&is barely enough resolution to see the nuclear surface. Such data could therefore yield only limited information, and a suitable form for the density with only three parameters was found to be af the form of a Fermi function:
as illustrated in Figure 5.1. Since it turns out that 4.4&/t > 1, the parameter p0 is essentidly the central density [i.e., p(r = Q)] the parameter &J is the radiua where the charge demity d r o p to one-hdf of its centrd vdue, and g, the surfaGe tEckn-s, is a measure of the distance over which this drop occurs, These thrw parametm are, of course, not all independent, as po c m be related to & and d by the normalization constraint (5.32). Systematic studies of electron scattering from a number of lrudei showed that, .for a nucleus with A nucjmns, suitable vdues were = 1 . 0 7 ~ ' /fm. ~ t = 2.4 f a Mare modern studies of eleclron scattering use higller energy b e a s , and so cover momentum transfers to approximately 4 fa-'. A typical crxampfe of the r a g e and quality of the data is shown in F i ~ r e5.2. Such data have led to a number of "modei-independent'' analyses [Fr75], in which a very flexible parametrization of the charge is used. One of these [Si74] takes the charge density to be the sum of many (of order 10) Gaussian Yumpsn, aad adjusts the location of each lump and the amount of charge it carries to best fit the data. An alternative [Fr73], which we pursue here, assumes that the density vanishes outside a radius R, considerably beyond the nuclear surface, and expands the density as a finite Fourier series of R" terns, That is, for r < E, we take N
C, sin
rp(r) = ta=2
5.4 Determining nuclwr &aqe densities
Figure 5.1 The Fermi function parametzization of the nuclear charge denkty, The density fags ta axle-hdf of its centrd vdne at the rdiua Ra;the dktmce aver which the dendty drops from 90% tto 10% of its central vdue is .t. (Aftm lE0571,)
and for T > R, we take p ( r ) = 0. Equations (5.32) and (5.381, together with some stm&&tforward dgr?bra7show that
F(q) =
4rR2 N
sin qB E CB(-)" (qR)Znn- n2r2qR
(5.59)
%=l
These expressions, together with Eqs. (5.38,40), can be used to derive explicit foms for Win7and hence for the x2 minimization procedure described above. It is usefd to note that the n'th term in. the Fanrier expmsion of the dendty &ves a csntributhn to the farm factar that is peaked neaf q, E nn/R. Hence, truncation of the sedes at N implies little control over Fourier components with q larger than q~ = N Z / & . This m ~ m u mwaveaurnber contained in the pmametrization must be wmmen;urate with the n r d m u n r momenturn transfer cavered by the exthen data at lager momenturn perimeatal data, gm&,. If QN <
127
Figure: 5.2 Experimentd cross iaaitions fcx the dasfic scattering of dectrans from " ~ , iIan energy of 449.8 MeV. (Born [6;180f.)
5.4 Determining nccclear charge dera~ilies 129
trmsfers w i l l not be well described, wK1e if qjy 3 qwX, thm the CB's with n > q,,R/n will not be we#-determined by the fit. We now return to the d e q u w y of the Born appradmation far describing the experimental data. For charge distributions of the shape expected (roughly like those in Figure 5.l), the relatively sharp nuclear surface induces zeros in F(q). That is, there are particular momentum transfers (or equivdently, scattering angles) where the Born scattering amplitude vmishes. At these d a e s of q, correctians assoei&edi with tbe distortion of the pladle wave of the incident electron by the nuclear Coulomb potential becorne reldively mare impoftant, so that the experimentd data has these zeros largely filled in, often to the extent that they become merely shoulders in a rapidly falling cross section (see Figure 5.2). A precision determination of the nadear charge density from the meaured m s s sections therefore requires a mare sophisticated description of the ~ ~ a t t e r i nofgthe electmns from the Coulomb potential. The rigorous solution to this problem involves salving the Dirac equa tion for the dectran in the Coulomb potentid generated by the assumed charge distribution [Ye54, Fr73]. This results in a calculation very similar to th& done in Project IV: a partid wave decompositioa, solution of the radial equation in each partial wave to determine the phase-shift, and then summation over partial waves to determine the scattering amplitude at each scattering angle. While such a calculation is certainly possible, it is too long for interactive programs. However, the eibond approximation to Dirac scattering c m be sufieiently accurak and resuXts in a reasonable amount of a n s m e ~ dwork. The eikond approximation for ultra-relativistic electrons scattering from a charge distribution results in final expressions very similar to those derived in Section 4.3 [Ba64]. The cross section is related to a complex sea2;tering ampgtude, f , by
and the scattering amplitude is given by the Fmrier-Bessel transform [compare Eq. (4.30)]
where the profile function is the integral of the potential along the straightline trajectory at impact parameter b:
For the particular parametrization (5.571, p vanishes beyond R, and V ( r ) is simply -Zn/r in this region. It i s therefore convenient to split the impact parameter integral (5.61) into regions 6 < R and b > R, so that the latter i x l l e ~ a cm l be done analyticdy. This results in
f = h u t e r + hnner = fauter
R
ik:
~ ~ ( p b ) [ e " ~( ~l)] bdb ,
(5.62)
where
with X = qR. In this expression, S,, is a Lommel function (essentially the incoxnplete i n t e g d of tfie produe$ of a Bessel function and a power), which has the usefd aymptotic expaslsion for l a g e X S,,(X)
x ' - ~[l - ( p - X2 - v Z 4"
{(p-
- v 2 ) ( ( p --
- vZ} -
(5.64)
X4
Note that since we will typically have R 2 8 fm a i d q 6 1fm-I, X will be 8 or mare, sknd so the number of terms s h w n shodd be q ~ - t sufficient. e The inLerior contributim to the scattering ampEtude, h,,,,, involves the potential far r < R m d so depends upon the. detailed form of the nudear charge density. Given the simple relation between the potential and density through Poisson's equation (5.33), it should not be too surprising that it is possible to express ~ (
~(b= ) -zcu log
a
~ ~ p ( ~ ) # ( ad~ l p,)
(5.65)
where #(g)
= log
The parametrization (5.57) then allows the profile function to be written in the form
with the change of integration vmiable z = P / R . Equations (5.61-64,66) complete the specification of the eikonal cross section in terns of the nuclear charge density. It is also easy to show that the quantities Win are @wn by
Several fine points remain to be discussed before turning to the program. One is that the nucleus is not infinitely heavy, and so recoils when struck by the electron. To correct for thig, the cross sections calculated above, which have all been for an electron impinging on a static charge distributian, must be divided by the factor
where M is the target mass (roughly A x 940 MeV). Note that this correction vmishes as M becomes lage compared to E. Second, beemm of the e ~ ~ l attrxtion, ~ m b electrons at the nucleus have a sfightly fiigher momentum. than the beam vdue, h the eikonal treatment, tMa c m be approAmalely corrected for by replacing q in afl of the formdas by
and by multiplying the eikonal scattering amplitude by (q.~/q)'. Bere, is a suitable average of the Coulomb potential over the nuclear volume, conveniently given by 4 Zahe
v
where R. i s the nuclear radius. SimilaIy, in the Born approximation (5.40), the nudear form factor is to be evduated at q e ~'bad , the Matt eroBs section is still to be evduated at q. The F O R T U N pro@- for Exmple 5, whose listing c m be found in Appendh B and in the file EXMT"LS.FOR,uses the method described above to analyze electron scattering cross sections for the nuclei 'OCa ( Z = 201, S8Ni (Z = 28), and 208Pb(Z = 82) to determine their charge densities. Many &Ee;rent daka sets for each target, taken at a mriety
of beam energies and angles (see, for example, [Fr77]), have been converted for equivalent cross sections at one beam energy [Ca80].The integrds (5,62,Ii6b967b)are e d u a t e d by 20-paint Gauss-Legendre quadratwe a d the matrix inversion repired by (5.51) is pedarmed by rul eficient implementation of Gauss-Jordan elimination [Ru63]. After requesting the target nucleus, the boundary r d i u s R, a d the number of sine functions N, the program iterates the procedure described above, displwing at ewh iteration plots of the fit, fractiond emor in the fit, m d the char@ density of the nucleus, tagether with the dacss of the G's and the density. The progrm also d10ws for initid iteratiorits with fewer sines t h m we ultimately required, the number then being increased on request, This technique improves the convergence of the more rapidly oscillating campone~tsof the density as iL reduees the effective dimension of the X2 search by first converging the smoother density components. Mote that, a;e each iteration, only points at an eEective marn~?~ftum transfer smdler tkim that described accuratdy by the current number af sine8 are used in calculating The following exercises w i l l be useful in understanding the physical ;md numericd principles iraportmt in this cajcalation.
=
To deck that the progrm is working properly?use the tzlikond famulas and Fermi-function chmge density described abave t a generate a set of "pseudo-data" cross sections ranging from p between 0.5 and 4 fm-'. Make sure that these cross sections are given at intervals typical of the experimental data and also assign errors to them typical of the data. Then verify the extent to which the correct (i.e., Fermifunction) charge distribution results when these pseudo-data are used as input to the program. One potential source of error you should investigate is the "completeness error". That is, the ability of a finite Fourier series to reproduce densities of the tom expected. This can be studied by changing the number of eines used in the fit. Exercise 5.8
Exercise 5.9 Run the eode with the actual experirnentrtl data to determine the charge densities for the three nuclei treated. Study the quality of the fit and the errors in the density extracted as functions of the number of expansion terms used. Also vedfy that the fitting' procedure converges to the same find solution if the initial guess for the density is varied within reasonable limits. Note that the converged solutions do not have a uniform interior density, but rather show "wiggles" due to the specific shell-model structure of each nucleus.
V: A schematic shell model
m Exercise 5.10 density,
Extend the program to calculate the moments of the
and their uncertainties for integer k ranging from 2 to 5. This can be doneconveniently by using Eq. (5.57) to express these moments directly in terms af the C,. VePify that the size of these raomeats is consiskd scaling of the nuclear radius. with an Exercise 5.11 A simple model for the doubly-mqic nucleus 40Ca is a Slater determinant constructed by putting four nucleons (neutron and proton, spin up and down) in the 10 lowest orbitals of a sphericallysymmetric harmonic osdllator potential. Show that the charge density predicted by this model i s
U
m being the nucleon mass and w being the harwhere ro = monic oscillator frequency. Determine the value of ro (and hence w ) rewired to reproduce the experimentd vdue a f t he road-mean-square radius ( M z ) 9and then compare the detailed form of p predicted by this model with thag obtatined from the data, Exercise 5.12 Modify the progam so tEt& it crilculates the Born, rather thaa. eikond, cross seetim a;nd show that the fomer is grossly inadeqaate to describe the data by compasing the Born cross sections for cljstribution with the experimental data.
m
Exercise 5.13 Modify the program to calculate the "off-diagonal" uncertainties in the density determined using Eq. (5.55) and show that the correlation in the uncertainties largely decreases as the separation of dke points increases.
m
Project V: A schematic shell model The assumption of particles moving independently in a potential is a coms many-partide mon approdmation in treathg the quantum m e c h ~ c of systems, For exmple, this picture underlies the Wa&ree-Fock method for treating the many electrons in an atom (see Project III), the shell model for treating the many ~aclt?onsin a ~ueleus,a d rnaxly models far treat;ing the quwks in a badron, Bowever, it is only a r ~ u g happro~mat;ion
133
Figwe V,% Zllnstra,Ibn, of the orbitals in the s~hematicshell modd.
in many cases and a detailed description of the exact quantum eigenstates often r e q ~ r e sconsideration of the "residual" interactions betwen the particles makiing up the system;. In atoms and Badrons, the residual interactions we not strong enough to induce quatative chane;es in the spectmnr expected horn simpfy placing the partides in digezent arbilds. In audei, however, the coherence aknd s t r a g t h of tfre reddud interactions can l e d to a 'kollective" behaviar in whieh, many nucleons pitstieipate in the meitations and the charmter of the dgeastates is quite diEerent from that expected n~vely. Reastic cdculatians of the eEeets of residual interactians are quite campalex astd involve the diagaaaifizattion of large matrice8 expregsirng the way in which the interaction moves particles among the orbitals [Mc80]. Hoatever, the phenomenon of cdle~tivitJtcan be illustrated by a schematic shell model introduced by by Lipbin et al. [Li65], which we consider in this project, The modd is non-trivid, yet simple enou& to be soluble with only a mo&st aumericd diaganalization. It has therefore served as a testing ground for approximations to be used in treating many-body systems and is &so the prototype for more sophisticated group-theoretic models of nuclear spectra [Ar8l].
V.1 Definition o f the model The schematic model consists of N distinguishable partides labeied by n = 1 , 2 , .. ,N. Each of these can occupy one of two orbitals, a lower and an upper, having energies +1/2 and -112 and distinguished by s = -1 and s = +1,respectively (see Figure V.1). There are then zN states in the
.
model, each defined by which partides are @up'' and which are "down", and each having an unperturbed energy (in the absence of the residual interaction) equal to one-half of the difference between the number up and the number dawn..
V. A schematic shell modd
or
Figwe V.3 IBuatration of the re~idrrdirtter~tion~in the wrefiematic modd.
The residud interaction in the stllilematic model is one that changes simultaneously the states of any pair of pils'cicks; it therefore cottpks sta?t;esof the unpertuhed system. In particular, i"tis convenient to take a residual interaction of rjtrmgth -V that, promates any two partides or that drops any two that are "up" to "dawn", that are CEdown" ta gL"up'9 as illustrated in Figure V.2. An interactiart that simultanwusly rrtises one pasticle m d lowers m ~ t h ~ fclm : &so be included, but introduces no quatatively new features. To define the model preGi~dy,it i~ ewiest to use the lanf5rzag;e of second quantization and introduce the operators a i , and their adjoints, a,,, which. re~pectivelycre& and ~lnnikifatea padicle in the srBitrtl ns. As the model is constructed so that no mofe than one particle earn occupy each orbital, it is convenient to endotv them operators with the usual fer&on wti-c~rnmutationrelzn;tions, (V.la) (V*1b) (V.le) The operator ai,a,, then counts the number of particles in the orbital ns t (i.e., it has eigenvaiues O and l),while the operators aLla,-l and anela,l respectively raise or lower the n'th partide. In terms of these operators, the I f a ~ l t a n i mfor the model can be mitten as
135
where we nmd not worry about the unphysied ra9 = =L: term h the residual interaction since an attempt to raise or lower the s m e particle twice yields a van_isEng state.
V.2 The exact eigenstates The Hamiltonian described above can be represented as a matrix coupling the gN states among themselves. Apart from symmetry and a vanishing of many of its elements, this matrix is not obviously special, so that its numerical diagonalization to find the exact eigenstates md eigenvalues is a substantial probiem'for all but the smallest values of N. Fortunately, the relatively simple structure of the problem allows it to be expressed in the liar language of the group SU(2) (the quantum angular momentum operators), a transformation that carries us a good deal of the way to an exact diagonalization and also affords some insight into the problem. Let nk; define the operakors
Thus, J, measures (one-half of) the difference between the number of "upn partides and the numb= of "dawn" particles, wKk-? J+ m d Jcoherently raise or lower all of the partides. Using these operators, the Hamiltonian (V.2) can be written as
where we have iatrodueed the opclra;t;ors I 1 J, = -(J+ f J - ) , J, = --i(J+ - J - ) . 2 2 Using the fundamental anti-commutation rules (V.1), it is easy to show that the three operators J,, J* satisfy the commutation rules of a quantum angular mumeaturn: Thus, although these L6quasi-spinn operators have nothing to do with a physical angular momentum, all of the techniques and experience in dealing with quantum spin operators can be applied immediately to this problem.
V. A schemalie shell model
We can be@n by realizing that ~ i n the e total quasi-spin operator commutes with J,,,,,, it commutes with the H l h d a n and thus each eigenstate of II can be labeled by its total quasi-spin, j , where j ( j 1) is the eigenvalue of J ~ The . eigenstates therefore can be classified into nondegenerate multiplets of 2 j + 1 states each, all states in a multiplet having the same j;the Hadltoaian has a non-wnishing matrix element between two states only if they belmg to the same multiplet, Bowever, since B does not cornraute with J,, its eigenstates wiB R& be simultaneously eigenstate~of this frt'tter operator. To see what values of j are allowed, we can dassify the zN states of the model (not the eigenstates of H) according to their eigenvdues of &, The m e state with the largest eigenvdue of Jz has all particles up, corresponding to an eigenvdue m = * N . We therefore expect one multiplet of 2 N 1 = N + 1 states corresponding to j = N. Turning next t o states with n = 4 N - 1, we see that there are N states, corresponding to one of the & particles down and all of the rest up. One linear combination of these N states (the totally symmetric one) belongs to the j = multiplet, implying that there are N - 1 multiplets with j = $ N - 1 . Continuing in a similar way, there are # N ( N - 1) states with m = -$N - 2 (two particles down, the rest up}, of which one linear combination belongs to the j = $ N multiplet and N - 1 linear combinations belong to the j = f N - 1 multiplets. There are thus ~ N ( N - 3) multiplets with j = # N - 2. By continuing in this way, we can classify the 2N states of the model into multiplets with j running from $ N down to 0 or i, if N is even or odd, respectively. Because W involves only the quwi-win aperat;ors, its action within a multiplet depends only upon the value of j involved. For a given N , the spectrum of one multiplet therefore serves for all with the same j and, in fact, also serves for multiplets with this j in systems of larger N. We can therefore restrict our attention to the multiplet with the largest value of j, + N . By these considerations, we have reduced the problem of diagonalizing the full Kamiltonian to one of diagondizing (V.4) in the N 1 eigenstates of J, belonging to the multiplet with j = -$N. We can label these states as im), where m runs from - j to j in integer steps. Using the usual formulas for the action of the angular momentum raising and lovvering operators,
+
-3 +
i
+
137
we can write the elements of E in this basis a%i
Thus, R is tri-diagonal in this basis and in fact =parate8 into taro un~ m =. - j , - j 2, *. ,, j azd m =L coupled problems invo1.ving t h state6 -j l,-j 3,. . ,f j - 1 when N is even ( j is integral) and the states m =;: - - - j , - j + 2 , . . . 1 + j - - 1 and m = -j+1, - - j + 3 ,..., + j when N is odd ( j is half-integral). For smdl values of j , the resulting matFices can be diagondized rtsldyticdy, while for 2mger systems, the namericd methods discussed in this chapter can be employed to find the dgenvdues m d eigenvectors, The quasi-spin method d a w s us to m&@one ather atatemat about the e x x t solution of the model. Let
+
+
+
.
+
be the unitary operator effecting a rotation in quasi-spin space by an angle of n about the axis (2 $ ) ~ 2 ' / ~It. i, emy to see that this rotation t r a ~ f o r m sthe quwi-spin operators as
+
ltonian (V.4) transforms as Hence, if tj is an eigenstate of H with energy E, then R+ is an eigenstate of JI with energy -E. Thus, the eigenvdues of H come in pairs of equal magnitude and opposite sign (or are 0). This also allows us to see that if N is even, at least one of the eigenvalues will be zero.
V.3 Approximate eigenstates We turn now to approximate methods for solving the schematic model and consider fint ordinary Rayleigh-Schroedinger perturbation theory. If we treat the J, term in (V.4) as the unperturbed Hamiltonian aod the Jz term as the perturbation, then the unperturbed eigenstates are Im) with unperturbed energies = m and the perturbation series is m) = 0, the energies are an expansion in powers of V. Since ( m unperturbed in first order and are perturbed in second order as
Ji
EC)
V, A schematic shelf model
Using Eq, (V.9) for the matrix elerrxents irtvolved, expgcit expressions for
$be? ~ecould-orderener@es can be derived; the fourth-srder t e r m can. d s o be done wi"c a bit of patient dgebra. While the weak-coupling (smdl-V) limit can be treated by straightforward perturbation theory, m agproxirnahn for the strong-coupling (large-V) situation is not so obvious. One appealing approach is the semidassicd method, vdid in the Emit of large N [Ka79, ShSD]. The dimssion be@ns by considering the equ&ions of motion far the timedependence of the expectat;ion values of the quai-spin operators: d (V.13) i- (Ji)= ([Ji, E ] )9 dt where Ji is any one of the three components of the quai-spin, Using the Hamiltonian (V.4) and the commutation rules (V.6), it is easy to write out Eq. (V. 13) for each of the three components:
d z(Jz)
-2v(JyJz
+ JZJ,)
(V.14e)
UnfortunaLely, these equations do not form a closed set, the time derivatives of expectation values of single quasi-spin operators depend upon expectation values of bilinear products of these operators. However, if we ignore the fact that the J's are operators, and put, for example, then a closed set of equations results:
(V.15a) (V.156)
(V.15c) It is easy to show that Eqs. (V.15) conserve
+
J 2 ( ~ 2 f) (~ J ~ )( J~ Z)? , so that a convenient parametrization is in terms of the usud polar angles, ( J , ) = J cos 8 , (J,) = J sin 8 cos t$
, ( J Y )= J sin 8 sin 6 ,
(V.16)
139
where
If we further define ithe variables
and O 5 q 5 2n, then, upon introdudng the convenient p1 5 coupling constant xzdVVssz2JT,, Eqs. (V.15) can be written as
@E(p,q ) X sin 2q = @E@, g) 3 = I + 2-33 dt RT @P
(V.18a) (V.186)
*
Here, E is the eqeetation vdue of the H
E(P,q) g ( H ) = (Jz) - ~
-
( ( J z ) (~J V ) ~ )
(V.19a) (V.196)
By these manipulations, we have transformed the quasi-spin problem ialo o m of a time-dependeat classical system with 6Lmomentum'" and "coordinate" q satisfying equations of motion (V.18). As these equations are of the canonical form, p and q me canonicay conjugate and (V.19b) can be identified as the Hamiltonian for this classical system. Our hrivation h a been heuristic, but not rigomus, A more careful calculation defines the classical Eamiltonian as the expect ation. vdue of the quantum Hamiltonian between coherent states [Ya82]. However, the only modification this procedure gives to our results is the redefinition:
Note that the EX ltonim so derived is a v a ~ a t i o a done, therefore the quantum ground state energy will be lower than the minima in the dassical energv: We can now infer properties of the quantnm eigenstates by analyzing this classical system. Using Eq. (V.ISb), we can calculate the trajectories in phase-space; i.e., the value of p for a given q and E = (H). Equivalently, we can consider contour lines of E in the (p,q) plane. In an analysis of
9 F l m e V.3 Contours of the HwiIlaGan (V.29b) for the we& eaup b g cM = 8 and X = 0.25. The contour pm&aig through Cp = 0, g = 0) has zero energy. The upper and lower boundary lines p = f are contours at energy &*N,respectively. Successive cantoars shown diger in energy by 1, (F~arnKs791.)
these contours, it is useful to distinguish between weak (X < 1)and strong ( X > 1) coupling cases. Figure V.3 shows a typical weak-coupling ease, N = 8 and X = 0.25. The trajectory with the lowest allowed energy, which we can identify with the ground state of the quantum system, has p = - $ N , E = - $ N , and q satisfying the differential equation (V. 18b). Note that this trajectory r a g e s over aJ1 v d u e ~of Q. LR the strong coupfing case, X r 1, the tr;t,jectaries look as shown in Figure V.4, which mrresponds to N = 8 and X = 2.5. There me now minima in the energy surface at p = - $ N I X , Q = a/4, 5~14, which, using the equations of motion (V.18), can be seen to correspond to stationary points (i.e., time-independent solutions of the equations of motion). The energy at these minima is E = - N ( x X-')/4, which we can identify as m estimate af the ground 8taGe enexggr. There is therefore a "phase ternsition" at X = 1 where the g o ~ n dstate chmges h x n one whercl
+
Ffgwer V.4 Sim2ar l o Figure V.3 for the stro~gcoupling, cam ll\C = 8,
= 2.5. The points Al,ar B1,2 me minima masma, respectively, and C J - . ~ .Dlm4 ~ are sacliae points. Gontours through the saddle points, which have energy A ~ N are , dram as dashed lines; thme separ&e trajectories that are locdbed and exleadd in tp. Succwive caatours diger in energy by l. (Ram [Ka73],) X
p = - N to one where p > -{ N , the energy being continuous across this trmsition. This quditative clsmge in the nature of the ground state is a direct consequence of tfie coherence and strength of the interactians among the particles. It should dso be noted that, in direct andogy with the usud quaatuln double-weU, problem, the presence of two degenerate minima in Figure V.4 suggests that the ground and first-excited states will be nearly degenerate, the splitting between them caused only by '%tunnefingBbetween the wells. The se~clmsica-landysis can be extended to predict the energies of excited states as 4 1 , essentially by applyinf~the andog of the BahrSommerfeld quantization rule given in Eqs. (1.20,21) [Sh80]. One finds that M controls the quantum nat;ure of the problem, Prith the system becoming more ""classicaln as the number of particles inaeitses. In the weak coupling case, all trajectories extend over the full range of q. How-
V, A schematic shell mode2
ever, for strong coupling, there are two types of trajectories: those that vibrate around the energy minima or maxima (and are hence confined to limited regions of p) and those that extend throughout all q. It is easy to show from (V.1Sb) that the transitions between these two behaviors ocEl = J (e.g., the dashed lines in Figure V.4). In andogy with the usual quantum double-well, we expect states associated wit h the confined trajectories to occur in near?y degenerate pairs, the degeneracy being broken more strongly as the energy increases above the minima or decreases below the m&ma. V.4 Solving the model The simple semidassical picture we have discussed above can be tested by an analysis of the exact eigenstates of the model. This can be carried sequence of steps. out through the fQllowia(~ m Step 1 Verify the algebrzhia the di~cussioaabove. In particular, s h w that Eq. (V.4) is a valid representation of the Hamiltonian. Also evaluate the second-order perturbation to the energies, Eq. (V.12). Step 2 Verify the correctness of Eqs. (V. 14,18,19) and the discussion of the energy emtours in the strong md weak coupgng cwes, h the
m
strong coupling case, liaemize the equations of motion about the xaifiima d that the frequency of harmonic moticm about these as m d m a a ~ show points is [2(xZ This is the spacing expected between the pairs of newly degenerate states in the exact spectrum.
-
Steg 3 Write a prqram that finds the eigenvduer~of the tri-rliagond Hamiltonian matrix (V.9), perhaps by modifying that written for Exercise 5.4. Note that the numerical wvork can be reduced by treating basis states nrith even and odd m separately and by using the symmetry oE %he spectrum about E = 0. In addition, yoiu can save yours& some tedious bookkeeping concerning the size of the bases by taking N even only. U
Seep 4 Use the p r o e m written in Step 3 to cdcdate the spectrum of the model for selecged vafues of N between 8 and 40 and for valnes of X between 0.1 and 5. At we& coupling, compare your results pvith the perturbation estimates (V. 12). For strong couplings, compare your ground state energy with the s a i d a s s i c d ~jstimateand verify the? expected paifwise degeneracy of the Isw-fying states. Also cornpase the excitation enerfies af:these states with your estimate in Step 2. Wow doea the accuracy of the semi-classic& estina;ille cfiizlnge with N ?
143
Step 5 W ~ t a, e proe;ram that takes the eigenvdues found in Step 2 and solves for the ei@;envectorsby inverse vector iteration [Eq. (5.27)]. For selected vztdues of N and X , compute the expectation vdue oT J, for e x k eigenvecltor , In a seanidasdcra-f interpret atim, this expectaLioe vdue can be ictentiged with the dime-average of p aver the associatt3d trajectory in phase space. Verify that (J,) changes through the spectrum in accord with what you expect from Figareer V.3, V.4,
r
Chapter 6
Partia Differentia Equations Pmtid differential equations are involved in the description of virtudly every pksical situation whem qumtities vary in space or in: ;apace and time, These indude phenomena as diverse W diRueioa, electramagsetic waves, hydrodynamics, and quantum mechanics (Schroedinger waves). In aILl but the simpXest cases, these equations cannot be solved analytieafly and sa numericd methods must be employed for quantitative resuXds, In a typicd numericd treatment, the dependent vwiatsks (such as tempmature or ekctricd potentid) are described by their d u e s at discrete points (a lattice) of the independent variables (e.g., space and time) and, by appropriate discmtizstion, the partial diBerentid equation is ~ d u c e d to a large set of difference equations. Although these difference equations then can be solved, in principle, by the direct matrix methods discussed in Chapter 5, the large size of the matrices involved (dimension comparable to the number of lattice points, often more than several thousand) mitkes such m q p r o z h impractical. Fartunately, the Iocdity of the origind equations (i.e., they invofw only low-order derivatives of the dependent vasiables) makes the resulting digerence equa;tims Usparse" in the sense that most of the elemengs of the matrices involved vanish, Far au& matrices, iter&ive methods of inversion and diagonajbization can be v e v eaeient. These methods ase the subject of tkis and the fdlfswing chapter* Most of the physiedly important partid digerentid equatio~sare of second order and can be clwsified into three types: parabolic, eEptie, or bypwbofic, Roughly speaking, parabofic equat;ians involve only a
146
6,Elliptic Partial Dr'flesntioE Eguations
first-order derivative in one variable, but have second order derivatives in the remajning vaiables. Examples are the diEasion equation and the time-dependent Schraedringer equation, which are first order in time, but secand order in spitce. Elliptic equations involve second order derivatives in each of the independent variables? each derivativt? having the s m e s i p when &B terms in the equation me grouped on one side. This class indudesj Poisson's equation for the electrostatic potentid and the timeindependent SeAroedinger ewation, both in. two or mare spatial variables. Finally, there are hyperbolic equations, wEch involve secand derivatives of opposite sic, such as the wave equatian describing the vibrations of a stretched string. In this chapter, we win discuss some numerical methods appropriate for eUiptic equ&ions, resewing the discussion of parabofit: equations for Chqttlr 7. Hyperbolic equations often can be treated by methods similar to those we discass, although unique difiedties do arise [Ri6?]. For concmteness in our ascussion, FV~?will consider particular farms af'dipLic bounday d u e a d eisnvdue problems fof a fidd q5 in two sp* tial dimensions (I, y). The boundary value problem involves the equation
Although this is not the most general elliptic form, it nevertheless covers a wide variety of situations. For exampie, in an electrostatics problem, 4 is the potentid and S is related to the charge density [compare Eq. (3.2)], while in a steady-state heat diffusion problem, q5 is the temperature, and S is the local rate of heat generation or loss. Our discussion can be generalized strGghtforwardly to other elliptic cases, such as those involving three spatial dimensions or a spatially varying diffusion or dielectric constant. Of course, Eq. (6.1) by itself is an ill-posed problem, as some sort of boundary conditions are required. These we will take to be of the Dirichlet type; that is, t$ is specified on some large dosed curve in the (z, g ) plane (conveniently, the unit square) and perhaps on some additional curves within it (see Figure 6.1). The boundary value problem is then to use (6.1) to find 4 everywhere within the unit square. Other dasses of boundary vdue problems, such as Neumann (where the normal derivative of 4 is specified on the surfaces) and mixed (where a linear combination of 4 and its normal derivative is spedfied), can be handled by very similar methods.
6.1 Dzacmtizatisn and the variational princiiple
Figwe @,l (Left) A twedimen~iandboundary vdutr, problem d t h DirichIet boundary conditions, Vdnes af c j aupe speci6d on the edlr;ee of the unit square and on the surfacw Within, (Right) Discre~zalion. of the problem on a uniform carledan lattice.
The eigenvalue problems we will be interested in might involve an equation of the form
toe;e%herwith a set of D i r i a e t boundmy coaditions. Thia. might arise,
fClT exmple, as the time-independent Schroedinger equation, where c(r is the wave function, V proportiond to the potential, and E is refated to the eigenvdue. Sueh an eqtzation nright dsa be used to describe the fields in an acoustic or electromagnetic waveguide, where E i s then related to the square of the cut-oE freque;ec;r, The eigenvdue problem then confor sists of finding the vdues e~ and the associated eigenfunctions which Eq. (6.2) and the boundary conditions are satisfied. As methods for sdving such problems are closely related, to those .for sdving a relateir parabolic equ;zlion, we will defer their discussion to Chapter 7.
6.1 Discrethation and the variational principle Our first step is to cast Eq. (6.1) in a form suitable for numerical treatment. To do m, we degne a laLtice of points covering the region of interest in the (2,y) plane. For convenience, we take the lattice spacing, h, to be uniform and equal in both directions, so that the unit square in covered by N x N lattice points (see Figure 6.1). These points can be labeled by indices ( i ,j ) , each of which runs from O to N, so that the coordinates of the point (i,j ) are (+i = ih, gj = jh). If we then define # i j = 4 ( $ i 7 y j ) , and similarly for Sij, it is straightforward to apply the th~ee-pointdifference approximation (1.7) for the second derivative in each direction and
141
so approximate (6.1) as
or, in a more convenient notation,
Here,
61 is the second-difference operator in the i index,
and 6; is defined similarly. Although Eq. (6.3) is the equation we will be solving, it is useful to derive it in a digerent way3 based on a vwiatianal principle. Such asr approah is handy in Gases where the coosdinates are not carte&&%W &iscussedin Sectian 6.3 below, or when mare accurate diRerexlccj.formdas are required. It also is guaranteed to lead to symmetric (or he difirence equations, an often usefd praperdy. The variational method also cords some insight into haw the galufion dgorithnr urorks. A good review of this approach can be found in [Ad84]. Consider the quantity E, defined to be a functional of the field 4 of
In some situations, L": has a physic-zll interpretation. For e x m p l e , in ekcdmstatics, -V# is the electric field and S is the charge drmsity, so that E is indeed the total energy of the system. However, in other situations, such as the steady-state diffusion equation, E should be viewed simply as ;z useful quantity, It is easy to show that, at a solution to (6.1), E is stationary under all variations 64 that respect the Diridlet boundary conditions imposed. Indeed, the variation is
which, upon integrating the second derivative term by pmts, becomes
6,l Biscretization and the variational principle
where the line integral is over the boundary of the region of interest (C) ancl n is the unit vector normal to the boundmy. Since we consider o d y vasiations; that respect the bouadau conditions, S# vanishes an C, sa th& the line integrd does W well, Demanding that 6E be zero for d such variations then implies that q5 satisfies (6.1). This then furnishes a vaiatioad grindple fi>P our boundary d u e problem. To derive a discrete approsnnatioa to the partid diEerentid equation based on this vafiational principk, are first approximate E: in terms of the d u e s of the 5eld at the lattice points m d then vary with respect to them. The sirnplest approximatim to E is; to employ the two-point ~ difference formula to approximate each first derivative in ( ~ 4at) the points halfway betwwn the lattiee poiats and to use the trapezoid2 ruk for the integrds. This bads to
Putting
-@E =o @+ij
for all i j then leads to the difference equation derived previously, (6.3). Of course, a more accurah diser&iztttion cm be abtdned by using better approfimations for the first derivativw a d for the integds, t a E ~ gcase that the accuracies of bath are commenszlrate. It is also emy to show from (6.7) that not only is E stationary at the solution, but that it is a d ~ r n u n ras ~4311, Exercise 6.1 Show that the vanishing of the derivatives of Eq. (6.7) with respect to the vdues of 9 a,t the lattice points lead to the difFerence Eq. (6.3). Prove, or argue heuristicdy, that E is a minimum when 4 is the cmrect solution.
Exereilre 6.2 Use the diRertsntiation fbsmulas @ven in Table 1.2 to derive discretizations that are more accurate than (6.3). Can you see how the baandary conditions are to be incorporated in these higher-order form&=? What are the correspon&ng discretizaLions of E andogous to (6.7)? (These are not trivial; see [F178].)
R
We must now &scuss where the boundary conditions enter the set;
of Ijnear equations (6.3). Unless the coordinate system is we11 adapted to the geametry of the surface8 on wbicb the boundam conditions are imposed (e.g., the surfaces are straight lines in cartesian coordinates or
149
150
6,Elliptic Partial Diflerential Ewationol
arcs in cylindrical or spherical coordinates), the lattice points will only roughly describe the geometry (see Fig. 6.1). One can always improve the accuracy by using a. non-uniform lattice spacing and placing more points in the regions near the surfaces or by transforming to a coordinate system in which the boundary conditions are expressed more naturally. In any event, the boundary conditions will then provide the values of the 4ij at some subset of lattice points. At a point far away from one of the boundaries, the boundary conditions do not enter (6.3) directly. However, consider (6.3) at a point just next to a boundary, say (i, N - 1). Since 4iN is spedfied as part of the boundary conditions (as it is on the whole border of the unit square), we can rewrite (6.3b) as
that is, +ilv enters not as an unknown, but rather as an inhomogeneous, known term. S i ~ l a r f yif, a Neumann bollndary mndit;ion were imposed at a surface, say a+/ay = g(%) at y = 1 or, equivalently, j = N , then this could be approsmated by the discrete boundary candition which means that at j = N
- 1, Eq. (6.3) would become
These consideratims, and a bit more thought, show that the discrete approximation to the differential equation (6.1) is equivalent to a system af Enem equations for the unknown vdues of tt, at the intex;ar poi~ts,In a matrix notation, this cm be written aa
where M is the matrix appearing in the linear system (6.3) and the inhomagentjous term s is proportional to S at the interim points and is linewly rdated to the specified vdues of g) or it-s derivatives on $he boundafies, In any sort of prrtcticaf situation there are a very lasge number of these equations (some 2500 if N = 50, say), so that solution by direct inversion of M is impraetied, Fortunately, since the discrete approximation to &he Laplacian involves only neighboring points, most of the elements of M vanish (it is sparse) and there are then effident iterative techniques for solving (6.9). We begin their discussion by considering an analogous, but simpler, one-dimensional boundary value problem, and then return to the two-dimensiond case,
6.2 An iterative method f ~ boundarg r value problems
6.2 An iterative method for boundary value problems The one-dimensional bounday vdue problem analogous to the two-dimensional problem we have been discussing can be written as
with +(0) and 4(1) spedfied. The related variational principle involves
which can be discretized on a uniform lattice of spacing h = 1/N as
when varied &h rtlspect t o cbi9 thls yields the difference equation which is, of course, just the naive discretization of Eq. (6.10). M&hods of solving the boundary value problem by integrating forwmd m d backwad in a: were Gsenssed in Chapter 3, but we can d s o and + N , as a set consider (6.13), together with the known values of of linear equations. For a modest number of points (say N 6 loo), the liaear system above c m be solved by the direct methods discussed in Chapter 5 and, in fact, a very eEcient specid dircrct method e ~ s t for s snch ""ti-distgand" systems, as discussed in Chapter 7. Howwr, to illustrate the iterative methods appropriate for the large sparse nnatriees of' elliptic partial diEercr;ntial equatiians in two or more dimensions, we begig by rewriting (6.13) in a "solved" form for 4i:
Although 'this equation i s not manifestly useful, since we don%know the 4's on the right-hand side, it can be interpreted as giving us an "improved" value for 4i based on the values of 4 at the neighboring points. Hence the strategy (Gauss-Seidel iteration) is to guess some initial solution and then to sweep systematically through the lattice (say from left to right), succesasivelly replacing cif, at each point by an improved vdue. Note that the most "ccurrent'pvdne8 of the 4ikl are to be used in the right-hand side of Eq. (6.14). By repeating this sweep many times, m initial guess for q5 can be "relmed" to the correct solution.
3.51
152
6. Elliptic Partial Digerential Eggation8
To investigate the wnvergenee of this p r o d m e , W generdize Eq. (6.14) so that at each step of the relaxation is replaeed by a linear mixture of its old value and the Uimproved"one given by (6.14):
Here, w is a parmeter that can be djluisted to control the rate of r d w ation: "over-relmation" corresponds to w < l, wG1e @under-relwittian" s rate ofre1;txil;tian means w > 1. The optinzaf vdue of'w that n r ~ m i z e the will be discussed below. To see that (6.15) results in an 'improvement" in the solution, we calculate the change in the energy functional (6.12), remembering that all 4's except +i are to be held fixed. After some algebra, one finds
so that, M long W 0 < u < 2, tbe, energy nevw incmases, and should thus converg;t! t;o the r e q ~ r e dminimum vdne as the sweeps proceed. (The existence of other, spurious minima of the energy would imply tb& the Enear system (6.13) is not well posed.)
Exercise 6.3 Use Eqs. (6.12) and (6.15) to prove Eq. (6.16). As au. example of this relmation method, let us consider the m e dimensional boundary-value problem of the form (6.10) with
The e x x t solution is +(g)
= %(l - 2)
and %heenergy is
9 = -0.64286. 14 The following FORTRAN code implements the relaxation algorithm and prints out the energy after each sweep of the 21-point lattice. An initial guess of +i = O is used, which is clearly quite far from the truth. _E7=---
C cbpba,for
60
PARAHETER (ISTEP=20 !la$fies size BfHEEilSIDXIT PHX(O:XBST~),~(~:ISTEP) !fie26 ancl h**r?*s@nrce PRINT * ,"n%sr msga ( .X@. O fo atop) p !relmaeioxz parmet er READ OmGA IP (QEEGA .LE. 6) STOP
*,
6.2 An i;tclrabiue method for kundarg vadus pmbkms
3153
C
10
H=%./ISmP DO 10 IX=O,ISmP X=IX*B S(ZX)=B*H*I2*X+X PHIC X X ) = ~ . CORTZlB(iJ1E
!fill h**2taomcs ?iafffal guess for f i e l d
C
DO 20 ImR=i,500 DO iS %X=1,1STW-l
~rrr~=~~an(r~-~
!rsla.alion loop !sweep tkoagh laittice ~ + ~ a x ~ x ~!Q. + i ~6.34 +s~
~x~~t~
PHI (rz>=
COmfEm
IF (HQD(XTER-1,201
.
E=O DO 30 IX=l,BS%P
.me0) mm
!soaretimes talc
t
~ (e,gi> ,
energy E
E=E+ C ( P H (IX)-PBX ~ (IX-i>>/fx>**2)/2 R=E-~(Z~I*P~I(IX)/I~*+~ CQ#TIBrNE
]E=E+B PRIIT
20
*,#
itssation = ',itsr,Qensra
=
\,E
Ern IF GOmXm GOTO 50 =D
Resufts for the enere;y as a fnnct;iart of iteration number we shmn in Table 6.1 for t h r &Rerent ~ vdues of u, Desgite the rather pom initid guess for #, the iterations converge m d the converged eaergy is independent of the relaation pafameter, but digers ksomewhtat h a n the exact answer due to discretization enors (i.e., h not vanishingly small); the discrepancy can be reduced, af course, by increshsing N. A detiled =amination of the solution indicates good agreement with the analyticd result. Note thitt the rate of convergence clearly depends upon U. A general analysis [Wa66] shows that the best choice far the relwation p a r a e t e r depends upan the lattice size arrd on the &-metry af the problem; it is u s u d y $reater t h m 1. The ap%irndd u e can be determined empiriedly by exadning the convergence of the solution for only a few iterations befare chooaing a d u e to be used for many iterations.
154
6. Elliptic Partbl Difirenttaf Equations
Table 6.1 Ca~vergenceaf the energy functiand dnkng relaxation sf a l-D bounday vdtlue problem
Iteration
= 0.5
o = 1.0
w
= 1.5
Exercise 6.4 Use the code above to vefify that the e n e w approaches the analytical vdue as the lattice is made finer, Investigate the accuracy of the soiutioa. at each of the lattice points and note thatt the enerw can be considerably more accurate than the sdutim itself; this is a naturd consequeaw of the minimization of E at the comeet solution. Use one of the higher-order discretizations you derived in Exercise 6.2 to solve the problem.
The itppdication of the relaxation scheme described above to two(or even three-) dimensional problems is now straightforward. Upon solving (6.3a) for 4i j , we can generate the analogue of (6.15):
If this algorithm is applied successively to each point in the lattice, say sweeping the rows in order from top to bottom and each row from left to right, one can show that the energy functional (6.7) $ways decreases (if w is within the proper range) and that there will be convergence to the required golution,
Several emsideratioas c m seme to enhance this convepnce in practice. First, starting from a good guess at the solution (perhaps one with simitar, but simpler, boundary conditions) will reduce the number of iterations required. Second, an optimal d u e of the relaxation parameter shoufd be used, either estinrahd a;nalyticdy or determined empiricay, W described abave. Third, it may sometimes be more efficient to concentrate the relaxation process, for several iterations, in some sub-area of the lattice whex the trial sdution is k m n to be particularly poor, thus not wasting effort on already-relaxed parts of the solution. Finally, one can always do a calculation on a relatively coarse lattice that relaxes with a s m d amount of numerical work, aad then interpalate the solution found onta a h e r lat2;ice to be used as the s t e i n %guess for further iterations. 6.3 More on discretiza$iam It is often the c a e that the energy functimaf defining a physicaf problem has a form more complicated than the simple "htegrd alof the square oi' the derivativrs'9that we have been considering so far. lFor example, in m dectrostaties problem with spatidy-varying dielectric properties or in a &@usion probfern with zb spatidly-varying diffusion caeBcie?nt, the boundary-value problem (6.1) is modified to
where D ( s , y) i 8 the dielectric constant or difigion eoeificient, and the corresponding energy functional is [compare Eq. (6.4)]
Although it is possible to discretize Eq. (6.18) directly, it should be evident from the previous discussion that a far better procedure is to discretize (6.19) first and then to differentiate with respect to the field variables to obtain the diEermee equations to be d w d . To see how this works out in detail, consider the analog of the onedimensional problem defined by (6.11),
The discretization andagous to (6.12) is
E56
6. Elfliptic Partial Diflema#id Equations
where Di-1/2 is the diffusion mnstant at the half-lattice points. This might be known directly if we have an explicit formula for D(%),or it might be approximated with appropriate accuracy by $ (-Di ~ i l). - Note that, in either case, we have taken care to center the diEerendng properly. Variation of this equation then leads directly to the corresponding difference equations [compare Eq. (6. U)],
+
These can then be solved straightforwardly by the relaxation technique described above. A problem treated in cylindrical or spherical coor&aat;es presents v(3f~much the s m e kind of situta2;ian. For example, whea the diffusion or dielectric properties are independent of space, the energy functional in cylindricd cooranates wiB involve
where r is the cylindricad radius. (We suppress here the integrations over the other coordinates.) This is of the form (6.201, with D ( T )= r m d an additional factor of r appemiag in the source i&graX. Discretization on a lattice ri = hi in analogy to (6.21) then leads to the analog of (6.221,
-- 0, this equation just
or equivdentfy; that t d s us that rpL = = 0. This is to be expected, as, in the electrostatics l a n g a ~ e Gauss" , llaw allows no radial electric field at r = 0. 1"IC i = 1, and 42, but Eq. (6.24) gives an equation involving three unknowns, +a, putting 450 = W a rough approAmation t a the zero-derivatim boundwy condition gives an equation involving only t w unknowns, whi& is what we expect a% a boundary on the basis of our experience with the ca_rtesim problems discussed above. A more elegant discretization of problems with cylindrical symmetry naturaUly incorparatw the zero-derivative baunda~ycondition at F =r. 0 by working on a lattice defined by = ( i - 3)h. In this case, Eq. (6.24) is still v&d, but for i = 1the eoeffieient oftbe term involving $i-2 m&~hes, giving directly an equation with only two unknowns, 41 and #z. At i
@+/@F= 0 at
T
6.4 Elliptic equations in iwo dimensions
Exercise 6.5 Verib that variation of Eq. (6.21) leads to Eq. (6.22). Write down explicitly the discretizations of Eq. (6.23) on the Ti = ih and ri = ( i f )h lattices and verify their variation leads to (6.24) in either ease. Why can the contribution to the ener$y f u n e t i o d from the region between r = O and F = # h be safely neglected on the ri = ( i - $ ) h lattice to the same order as the accurxy of approdmation used for the derivative?
-
6.4 Elliptic equations in two dimensions The application of relaxation methods to elliptic boundary value problems is illustrated by the program for Example 6, which solves Laplace's equation, V2+= 0, on a uniform rectangular lattice of unit spacing with Dirichlet boundary conditions specified on the lattice borders aad on selected paints Psithin the lattice, This situattion might describe the shadystate temperature distribution within a plate whose edges and certain interior regions we Held at specified temperatures, or it might describe an dectrostatics problem. speGiEed by a nuIliber of equipotentid surfwes. During the iterations, the potential is displayed, as is the energy functional (6.7) to monitor convergence. The code's source listing c m be found in, Appendix B and in the file EXMPL6.E"OR. The following exercises, phrased in the language of electrostatits, might hdp you t a understaind better the physicd and numeric& prindpres ilfustrated by this example. m Exerelsc? 6.6 Vctrify that- the sdutions comesponding to particular boundary conditions in the interior af the lattice a g e e with your intoition, You might try M n g a single interim point to a potential &Rereat ;from that of the boundary, R i n g tvvo symmetricalfy located points to different potentids, or fixing a whole line to a given potential. Other passibilities include constructing a "Faraday cage" (a closed region bounded by a surface at fixed potentid), studying a quadrupaie pattern of boundary cmditians, or cdculating the capacitance of various configurations of conductors. Study of what happens when you inerease or decrease the size of the 1at;tice is dso interestiw. m Exercise 6.7 For a given set of boundary conditions, investigate the effects of under-relaxation and over-relaxation on the convergence of the relaxation process. Change the discretization of the Laplacian to a higherorder formula as per Exercise 6.2 and observe any the changes in I h e solution or the eficiency with which it is appmached.
157
Modify the code to solve Poissonk equation; i.e., d o w for a charge density to be specified throughout the lattice. Use this to study the solutions for certain. simple charge distributions. For example, you might try computing the potential betwen two (line) &ages as a function of their sepafation and comparing it vvith yonr malyticd a p e c t ationa. Exmcise 6.8
Exe-reisfs 6.9 Modify the code to use Neurnann boundary conditions on sdected borders and iderior regions of the l a t t i ~ Study , the solution for simple geoanetries and compare it with what ycru expect.
W
r
Exercise 6.10 Modify the code to allow for a spatidy-varying dielec-
tric constant. (Note that you must change both the relaxation formula and the energy functional.) Study the solutions for selected simple geometries of the dielectric constant (e.g., a half-space filled with dielectric) and simple boundary conctitions, An dter~ativeto the Diridlet bounday conditions are periodic boundary conditions, in which the potedials on the left and right and top and bottom borders of the rectangle are constrained to be equd, but otherwise afbitraq. That is,
W
Exereiscl 6.11
for all i and j . This might correspond to the situation in a crystal, where the charge density is periodic in spaee. Modify the code to incorporate these boundary conditions into Poisson's equation and verify that the solutions look as expected far simple &age distributions. Exercise 6.12 Change the relaxation formula and energy functional to treat situations with an wimudhd symmetry by re-interpreting one of the coordinates as the cylindrical radius while ret4ning the other as a cartesim coordin&e. Use the resulting pragrm to mod4 a eapacitof made of two circular disks, and in particular calculate the capacitance and potential field for varying separations between the disks. Compare your results with your expectations for very large or very small separations.
m
Project VI: Steady-state hydrodynamics in two dimensiorrs The description of the flow of fluids i s one of the richest and most chdlenging problems that can be treated on a computer. The non-linearity of the equations and the complexity of phenomena they describe (e.g., turbulence) sometimes make computational fluid dynamics more of an
art than a science, and several book-length treatments are required to cover the Geld adequately (see, for example, [Ro76]). In this project, we will consider one relatively simple situation that can be treated by the relaxation methods for elliptic equations described in this chapter and that will serve to give some idea of the problems involved. This situation is the time-independent flow of a viscous, incompressible fluid past an object. For simplicity, we will take the object to be translationally invariant in one direction transverse to the Bow, so that the fluid has a non-trivial motion only in two-coordinates, (I, g); this might describe a rod or beam placed in a steady flow of water with inddent speed Vo. We will also consider only the case where the cross section of this rod is a rectangle with dimensions 2W transverse to the fiow and T along the flow (see Figure VI.1). This will greatly simplify the coding needed to treat the boundary conditions, while still allowing the physics to be apparent. We begin with an exposition of the basic equations and their discretization, f o u w with a brief disevssion of $he boundmy eon&tions, and then give some guidance in writing the pragarn and in a t r x t i n g some understanding from it.
VI.1 The equations and their discretization In describing the flow of a f i ~ through d spxe, at least two fields are important: p, the arms den~ity,and V, the vdacity, of the Aluid eft3ment at ea& point in space. These are related throu& two fundamental eqnatims
The first of these (the continuity equation) expresses the conservation of mass, and states that the density can change at a point in space only due to a net in- or out-flow of matter. The second equation (NavierStokes) emresses the emserva%ionof momentum, ltnd states thaL the velodty changes in response to convection, (V V)V, spatial variations in the pressure, VP,and viscous forces pV2V,where U is the kinematic viscosity? arisunzed constant in our discussian, In generd, the pressure is given in brms Of the density and temperature through an "equation of state'" and when the temperature vwiee3 m weB, m addition& equation embodying the conserntion of energy is dsa required. We win assume: that the temperature is constant throughout the fiuid. g
l60
6. Elliptic Partial Digerential Epations
Figure VI.1 Geometry of the twdinrensiond Aow past a pfa~Ieto be treated in this project,
We vviU be interegted in studying time-independent fioars, so that time derivative8 can be die2 to zero in them equations. firthermore, we win assume that the fiuid is incompressible, so that the density ia constant (this is a good approximation for water under many conditions). Equations (VI.1) then become
V*"GI=O; 1 (V* V)V = --VP+vv2v. P
(V1.2~)
(V1.2b)
For two-dimensional flow, these equations can be written explicitly in terns of the I and y components of the velocity field, denoted by zl and v , respectively:
Equations (VL3) are three scalar equations for the fields u, v , and P. While these equations could be solved directly, it is more convenient for two-dimensional problems to replace the velocity fields by two equivalent scalar fields: the stream function, $(z, g), and the vorticity, ((S,g). The first of these is introduced as a convenient way of sa-ti~fyiagthe continuity equation (VI.3a). The stream function is defined so that
It is easily verified that this definition satisfies the continuity equations (VI.3a) for any function $ and that such a euists for all flows that satisfy the continuity condition (VI.2a). hrthermore, one can see that (V = V)$ = 0, so that V is tangent to contour lines of constant the "stream lines". The vorticiey is defined a8
+
+,
which i s seen to be (the negative of) the curl of the velocity field. From the definitions (VI.4), it follows that C is related to the stream function 'Ztt by v2+= C = (V1.6) An equation for C can be derived by differentiating (VI.3b) with respect to y and (V1.3~)with respect to I. Upon subtracting one from the other and invoking the continuity equation (VI.3a) and the definitions (VI.4), one finds, after some dgebra,
Findly, an equation for the pressure can be k i v e d by diaereal;i&ing (VI.3b) with respect to z and adding it to the derivative of (V1.3~) with respeet to ye Upon expressiag a;LI velocity fidds in tezm~of the s t r e m function, one finds, dter a bit of rearrm@ng,
162; 6. BllipEic Partial Riflerential Eqwotionkr
Fimrct Vf .2 The lattice to be used in c&culathg the fluid flow P~ISTL the plate illustrate;$ in Figure V1.1,
Equations (VI.6-8) are a set of non-linear elliptic equations equivalent to the origind hydrodynamic equations (VI.3). They are particularly convenient in that if it is just the velocity field W wmt, o d y tne two equations (VI.6,7) need be solved simultaneously, since neither involves the pressure. If we do happen to want the pressure, it can be obtained by solving (VI.8) for P after we have found and C. To solve Eqs. (VI.6,7) numerically, we introduce a two-dimensiond lattice of uniform spacing h having N, and N, points in the r and y directions, respectively, aod use the indices i and j to measure these coordinates. (See Figure VL2.) Note that since the centerline of the rectangle is a line of symmetry, we need only treat the upper half-plane, y > 0. Moreover, it is convenient to place the lattice so that the edges of the plate are on lattice points. The location of the plate relative to the up- and downstream edges of the lattice is arbitrary, although it is wise to place the plate far enough forward to allow the 'Lw&e" to develop behind it, yet not too close to the upstream edge, whose boundary conditions can influence the flow pattern spuriously. It is also convenient to scale the equations by measuring all lengths in units of h and all velocities in units of the incident Buid velocity, Vo. The stream function is then measured in units of &h, while the vorticity is in units of &/h, and the
+
VI. Steodg-stab
ftyddgnamr'cs in two dimensions
pv.
pressure is conveniently scaled by Upon differencing (VI.6) in the usud way, we have (V1.9) (8; @)id (fi!+)ij = Cij 9 where 62 is the symmetric second-difference, as in Eq. (6.3b). Similarly, (VI.7) can be differenced as
+
where the symmetric first-difference operator is
The lattice Reynolds number, R = &h/v, is a diand similarly for mensionless measure of the strength of the viscous forces or, equivalently, oE the speed of the incident stream. It is rdated to the physical Reynolds a m b e r Re by repking the mesh spacing by the width of the reetage: Re = 2WKIv. Finally, the pressure equation (VI.8) can be differenced as
VI.2 Boundary conditions In order for the elliptic problems (VI.6-8) to be well posed, we must s p e w either the d u e s or the narmd derivatiws d the dream. function, the vorticity, md the pressure at boundaries of the lattice shown in F i p r e VI.2, These boundaries c m be classified into three groups, in the n o t a i m af Figure VX.3: i) the centerline boundasies (A and E); ii) the boundaries contiguous with the rest of the fluid (F, G, and
H); iii) the boundaries of the plate itself (B, C, and D). We treat $t and (' on each of these in turn, followed by the pressure boundary conditions. Throughout this discussion, we use unscaled (i.e., physical) quantities. It also helps to recall that in the freely flowing fluid (i.e., no obstruction), the solution is u = V& v = 0, so that II, = Voy and
5 = 0. The boundary conditions an the centerline su&aces A md E are detemined by symmetry, The y camponeat of the velocityf v , must vanish here, so that the 2 dell-ivative of $ mnishes. It follows that; A and E are
3.63
l64
6, Elliptic Partial Eziflerential Eguations
Figwe VI.8 Boundw candjitionsr t o be i m p a d on the stream function and vorticity.
each stream lines. Moreover, since the normal velocity (and hence the s h on~ B, C, and D, the entire snrfaee t angentid derivative of +) also ABCDE is a single stream line, and we may arbitrarily put $ = O on it. Note that the velodties depend only upon the derivatives of so that the physical description is invariant to adding a spatially independent l this stmmEne fix@@ colnstant to the s t r e m funetion; the e f i o i ~ eof $on the constant. Ekom syanmetry, we can also conclude %h&the vortidty vmishes on A, and E. The boundary conditions on the upstream surface F are also fairly straightforward. This surface is contiguous with the smoothly flowing incident Auid, so that specifying
+,
as is the case far upstream, seems reasonable. Similarly, if the lattice is large enough, we may expect the upper boundary G to be in free flow, so
is one appropriate choice. The downstream boundary H i s much more ambiguous and, as long as it is sufficiently far from the plate, there should be
many plwsible choices, Hawever, the boundary coar&tions on. a boundary that approahes the plate can influace the shape of the solutioa foa~d. One conveaient ghoice is to say that nothing changes beyond the lattice boundarv. so that At the walls of the plate (B, C, and D), one of the correct boundary conditions is that the norxxlairl velodty of the Buid is zero. This we have used &ready by ~ t q d r i a gthat this surface be a sr;treamline, Wowever, the other boundary condi.eion appropriate for viscous Am i s that the tmgeatid velocity be zero. hplementing this by setting the normal derivative of $ to zero wauld be aa overspecific&ian of the emptic prObkm for $J, Irtstead, the "na-sEp" boundary condition is imposed on the vodieily; Consider a point z'j m the upper surf"ace of the plate, C. We c m write the s t r e a fanctian at the point on lattiw spacing above this one, i j l, as a Tqlor series in 9:
-+
Since, at the wall,
and
a2+ a%
-=."m-=
ay2
@Y
C
5
because av/@z= 0, (VI.12) can be reduced to
which provides a Dirichlet boundary condition for C. (This is the general form of the boundary condition; recall that we had previously specified eij = O on the plate boundaries.) The same kind of arguments can be applied to the sudaees I3 and D to yield
Note that there is an ambiguity at the 'corners", where surfaces B and C and D and C intersect, as here the vorticity can be computed in
two ways (horizontal or vertical difference of $l) In.practice, there w e severd ways of resolving this: use one form and verify that the other gives similar values (a check on the accuracy of the calculation), use the average of the two methods, or use the horizontal value when relrwring the point just to the right or left of the corner and the wrticd vdue when rel&ng the poine jlrst above the cosaer, The boundary cmditians for the pressurn on ~uflf(izce~ we of the Neumann type, and follow from Eqs. (VI.3). We leave their explicit finiteagerence form in terms of $ and. f as m exercise, Note that from symmetry, aPl8y = O on the centerlines A and E.
VI.3 Solving, the equations Our general strategy will be t a d v e the coupled non-linear @Upticequations (VI.9,10) for the stream function and vorticity using the relaxation methods discussed in this chapter. One possibb iteration scheme $aes as follotirs. We bedn by chwsing trial vdues comc3span&ag to the freeflawing solution: 2E, = y and f =. O , We then perform one relruration sweep The Dirichlet boundary condiof (VI.9) to get an improved d u e of tions for ( on the walls of the plate are then computed from (VI.13) and then one relaxation sweep of (VI.10) i s performed. With the new value of C so obtained, we go back to a sweep of (VI.9) and repeat the cycle many times until convergence, X f required, we can then salve the pressure equation (VI.11) with Neumann boundary conditions det ned from (VI.3). This iteration seherne can be implemented in the fauowing sequence of steps:
+.
Step X, Write a section of code to execute one relmatiorz sweep af (VI.9) for given C and subject to the boundary conditions discussed above. Be sure to d o w for an arbitra3i.y ~ e l m a t i ~parameter* n This code c m be dapted from that for Example 6; in gmtiedaf, the technique of using letters on the scrwn as a crude contour plot can be useful in displibying
m
+.
of code that cdculates the boundary condion the d a t e wdls if $J is known.
Step 2 Write a section
tions for
Step 3 Write a section of code that does one relaxation sweep of (VI.10) for C if ij, is given. Build in the boundwy conditions discussed above and be sure to allow for an arbitrasy relaxation pmameter. If you have a contour plotting routine and a sufficiently high-resolution terminal, it is usefrt2 to display w d C on the screen together.
m
Step 4 Combine the sections of code you wrote in the previous three steps into a program that execute6 a number af itera;tions of the empled $-C problem. Test the convergence of this scheme on several coarse l a t t i e ~far several different Eeynolds ~umbersand chaices af relzwration parameters.
Step 5 Calculate the flow past several plates by w i n g your program to convergence on some large lattices (say 70 X 24) for several increasing values of the lattice Reynolds number. A typical size of the plate might be W = 8h and T = 8h, while lattice Reynolds numbers might run from 0.1 to 8. For the lager Reynolds numbers, you might find instabilities in the relaxation procedure due to the nonlinearity of the equations. These can be suppressed by using relaxation parameters as s m d as 0.1 and by using as trial solutions the fiow patterns obtained at smaller Reynolds numbers. Verify that the flow around the plate is smooth at small Reynolds numbers but that at larger velocities the flow separates from the b a d edge of the plate and a small vortex (eddy) develops behind it. Check also that your solutions are accurate by running two ernes with digerenit lattice Eeynolds numbers but the same physicd fteynolds numb=.
Ttvo physicdly interesting quaatities that can be compu.t;ed from the flow pattwn we the net pressure and vis~ousforces per unit area of the plate, FP and F@,By spnnetry, these act in the z directian and are measured conveaientfy in tarns of the flow of momentum incident on the face of the plate per unit area, 2Wpr/02. The pressure force is given m
Step fi
where the integrals are over the entire front and back surfaces of the plate, T h i s shows dearly that it, is only the rdative d u e s of the pressure over the plate surfaces that matter. These can be obtained from the flow solution using Eqs. (VI.3b,c). Consider, for example, the front face of the plate. Using (V1.3~)~ together with (M.4,6) and the fact that the velocfties vmish at the plate surface, we can write the &rivif,tie of the pressure along the front face as:
Hence, C from the Bow solution can be integrated to find the (relative) pressure along the front face. Similar expressions can be derived for the
3.68
6". Elliptic firdial Bigerential Equations
top and back faces, so that the pressure (apart from an irrelevant additive constant) can be computed on all faces by integating up the front face, across the top, axld dawn the back face. The net viscous fbm per unit area of the plate is due only to the flaw past the top (and bat tom) surfaces and is given by However, since the boundary canditions on the top surfwe of the plate require av/8z = 0, this can be written as
wfsieh i s conveniently ev;iiuat;c;d from the flow solation- fnvestigate the v ~ i a t i o eof the viscous and presjsure forces with Eeynolds number and compare your re8uXt.s with vrvhat you expect. Step 7 Three other geornedries can be investigated wit;& ody nrinar modifications of the code you've constructed. One of these is a Ujumg", in which. the thickness of the plate is increased until its Bownstrem edge meets the downstream border of the lattice (H). Another is a pair of rectangular plates placed symmetrically about a centerline, so that the fluid can flow between them, as well around them (a crude nozzle). Finally, two plates, one behind the other, can also be calculated. Modify your code to treat each, of these cases and explore the flow patterns a%various Reyndds numbers.
Chapter 7
Differentia Equations Typical parabolic pwtid differential equations one encounters in physical situations are the diffusion equation
where D is the (possibly space dependent) digusion constant and S is a souree fun&ian, and the time-dependent Schroedinger equation,
where V is the poterrtid, In cantrat to the boundary d u e problems encountered in the previms clrapter, thesje problems me generdly of the initial d u e type. That is, we are @wnthe field 4 at an initid time and swk t a find it at a later time, the evolutian being subjtsct to ccjrtgn spatial boundary conditions (e.g., the Schroedinger wave function vanishes at very large distaaces or the temperature or he& flux is specified on some surfaces). The methods by which such problems are solved on the computer are b a s i d y straightforward, although a few subtfeties are involved. We will d m see thiLt t h q provide a n&ur& way of solving eEptic eigetnvdue problenrs, particdasly if it is o d y the few lowest or highest eigenvdues that we required.
7.1 Naive discretization and instabiliitie~ We begin oar diseus~ianby treating digusion in one dimension with a uniform diausion constant. VVe take z to vmy between 0 and 5 and a6sume Diriehlet boundary conditions that s-pedfy the valiue of the fi&d
170
7. Pambslic Partial Diflemntial Eqaotions
at the end points of this irrtervd. After appropriate scalirtg, the andague
As usud, we a p p r u ~ m a t ethe spatial derivatives by finite diRerenees an a uniform lattice of N 1 points having s p i n g h = 1/N, while the time derivative is apgmdmated by the simpkst first-order diAFerexzce fomala assuming a time step A$. Using the supesacript .n: to l&d the tirncl step I 4(t,), 1, = nag), we can approximate (7.3) as (that is,
+
At i = 1 and i = N - 1, this equation involves the Dirichlet baundasy conditions specifying fbo and + N . Equation (7.4) is an ezplicit differencing scheme since, given q5 at one time, it is straightforward to solve for 4 at the next time* Indeed, in an obvious matrix notation, we have: where the action of the operator E is defined by
As an exmple of haw this expUcit acheme d g h t be applied, consider the case where S = O with the boundary conditions #(O) = 4(1) = 0. Suppose that we are given the initial cundit;ion sf a Gausaian catered about 2 = 112,
where the latter two "image" Gaussians approximately ensure the boundary conditions at + = 1 and s = 0, respectively, and we seek to find # at later times. The following FORTRAN code applies (7.5) to do this on a fatdice with. R = 25. G chp"l".Por PIRMmER (ISmP=2S) CIIMEHSIOI PEP (0:I S T B )
ay f o r etalut ian ! i o m of the malytical solutfon GAUSS (X ,T)=EXP(-20 *[X-, Q)**2/ (1.. +~o*T) )/SQRT< $+80*T> EXACT(X,T)=GAVSS(X,T)-GAUSS(X-~. pT)-GAPIS5(X+f.f.,T> H= =.I. /#STEP !
7.1 Naive diacmtizotion and indltabilities
60
!get input irom t e m i W PRIaT *, R &%er tiars step and C D c a l tbs (Q t o s t o p ) ' RBAf) *,BT,TIME I F (DT .EQ. O ,) STOP MImR=TXMB/DT DTH=BT/E**2
T=O , Paxfo)=o. PHI(ISEP)=O DO 1 0 ZX=i,ISmP-1 ~~~(ax)=ai~cletrx*a~T~ I
10
30
COrnXrnE !loop aver time steps DD 20 ImR=l,IXTER !old PBX at l a s t ph* POD=O , !aaw PHI a% this p o h % DO 30 XX=l,lS4I"W-I P ~ M = P B x ( I X ) + D ~( P* ~ U + P B XCII+1)-2*PHI (IX> 1 !roll P a w valtrs P O ~ = P H(XIX) ?stars new v a n e PEX(1x1= P ~ V COVXXFIm I F (MOO(TTm,i0) Q) mEl !@=%pm% evarg SO steps P R I m *, "iteration = ,=B, t h s = #,X-*BT T=XmB*DT Da 40 ~ ~ = ~ D ~ $ ~ ~ ~ % DI~=PEL crx)-gnm(ax*a, T) PRIIT *, "hi \ PHI(XX),' emor R , DDTW
.m,
40
GOBTTXm
M D IF 20
60WIWE GOTO fiO EHIt
Typical results from this code are shown in Flgure 7.1. Things seem be working fine far a time step of 0,00015 and the results agree reasonably well with the matyticd solution, af a spreading Gau~sian,
to
111
172
7.Parablie Partial Diflemnts'al Equation8
This time step is, however, quite small compared to the natural time scate of the solution, t sc! 0.01, so that many steps are required before anything interesting happens. If we try to increase the time step, even to only 0.001, things go very wrong: an unphysicd instability develops in the numerical solution, which quickly acquires violent oscillations from one lattice point to another soon after t r= 0.02. It is easy to understmd what is happening here. Let the set of states II?\ be the eigenfunctions of the discrete operator A with eigenvdues ex. Since R is an hemitian operator, the eigenvdues are real and the eigenvectors can be &wen to be orthonormial. We can expmd the solu.tian at m y time in this basis as
The exact time evolution is given by
so that each component d the solution should evolve as
This eorrespmds to the correct bebavior of the diEusion equation, where short-wavelength components (with larger eigenvalues) disappear more rapidly as the solution 'smooths out". However, (7.5) shows that the expLidt scheme will evolve the expmsian eoeScimts a9
As long as At i s chosen to be small enough, the factor in (7.6) approximates e-mt~.L\tand the short-wavelength components damp with time. However, if the time step is too large, one or more of the quantities 1 - exAt has an absolute value larger than unity. The corresponding components of the initial solution, even if present only due to very small numerical round-off errors, are then amplified with each time step, and soon grow to dominate, To quantify this limit on At, we have same guidance in that the eigenvdues of H are known analytically in this simple madel problem. It is easily verified that the functions (+A)i
= sin
Xni 191
7,&Implicit; schemes and the inuer~irtnof trCdiagona2 matrims
Figwe 7.1 Results for the one-dimexldonal diffusion of a Grtussian; a rs 0.04 i~ used in. calculations, a) and b) result from the ex,pficit algorithm (7.5) while c) is the irnpEcit alg;orilhm (7.8).
fixed lattice sgaeing k
173
174
7. Parabolic Partial Difierential Elquatiom
are (un-normalized) eigenfunctions of H with the correct boundary conditions on a lattice of N l points far X = 1, 2, ..,,N - 1 and that the assodilLed eigenvdues are
+-
The largest eigenvalue of H is EM-I M 4hma,which corresponds to an eigenvector that; dternates in sign. from me latiee point to the next. 1- ~ ~ - ~
n
7.2 Implicit schemes and the inversion of tri-diagonal matrices One way around the instability of the explicit algorithm described above i s to retain the general farm of (7.4), but to replace the second space derivative by that of the solution at the new time. That is, (7.4) is modified to 4 4 = --(6 1 2 4n+l )i S? * h2 At This is an implieit scheme, since the unknown, +"+l, appears on both side of the equation. We can, of course, solve for #"+l as
+
1
7.1 Implicit scheme8 and the tneersisn of tri-dicganal matrices
This scheme is equivalent to (7.5) to lowest order in At. However, it is m&better in that larger time steps can be used, as the operator (1 Bat)-' has eigenvdues (1 exAt)-', all of whose moduli are less than I. for any At. All components of the solation therefore deersme with eaCh time step, as they should. Although this decrease is inaccurate (i.e., not exponential) for the most rapidly osdllating components, such cosnpsnents should not be large in the initid concllitions if the spatid discretization is accurate. In any eve&, there is no amplification, which impties stability. For the lowly varying wmpoaents of the ~olutionearresponding to s m d eigenvdues, the evolution closely approdmates the exponentid at each dim@ajtep. Note that; if m had tried to be more accurake than (7.7) and had used the average of Ghe second space defiva;tiws at the two time steps involved,
+
+
so that the time kolution is effected by
this wodd h w been h o s t as good as the implicit @&erne,because the c0mponent;s of the solution are diminished by fwtors whase absolute V ~ U E Eare S lese t b m one, A potential drawback of the implicit scheme (7.8) is that it requires the solution of a set of linear equations (albeit tri-diagonal) at each time step to find 4n+'; this is equivalent to the application of the inverse of the matrix 1 Hat to the vector appearing in brackets. Since the inverse itself is time-independent, it might be found only once at the beginning of the calculation w d then used for all times, but application s t i l l requires of order N 2 operations if done directly. Fortunately, the faflowing algorithm (Gaussian elimination and bzk-substitution, [Va62]) provides a very efficient solution (of order N operations) of a tri-diagonal system of equations such as that posed by Eq. (7.8). Let us consider trying to solve the tri-diagonal linear system of equations At$ =. b for %heunknowns $i:
+
Here, the A:" are the only non-vanishing elements of A and the bi are k n w n vasttities. This is the form of the problem posed by the evaluation
175
of (7.8) for where t$o and conditions, In pafticular ,
$N
are given by the Dirichlet boundary
To salve this system. of equat;ions, we assume that the sdution satisfies a one-term forward recursion relation of the form where the c*i and pi are coefidents to be determined. Substituting this into (7.11), we have which can solved for qSi to yield with
1
Upon comparing Eq. (7.14) with (7.12), we can identify the following backward recur~iaarefation8 far the a" and P%:
=r i ( ~ t pj bi) .
(7.166) The stratem to solve the system shodd naw be clear. We will use the recursion relations (7.15,16) in a backwards sweep of the lattice to d e t e r ~ n the e ai and pi for i running from dV - 2 down to 0. The starting vdlzes to be used are
which will guarantee the correct value oft$ at the last lattice point. Having determined these coefficients, we can then use the recursion relation (7.12) in a forward sweep from i = O to N 1 to determine the solution, with the starting value q5o known from the boundary conditions. We have then determined the solution in only two sweeps of the lattice, involvinlg of arder N withmetic operations. The foUowing code implements the algorithm (7.8) for the model diffusion problem we have been considering. Results are shown in Fig~ it is dear that accurate solutions ean be obtained with ure 7 . 1 ~where a much larger time step than can be used with the explidt scheme; the
-
7,sImplicit
scheme8 and
the inversion of Ini.diagcmal madrias
increase in numerical effort per time step is only about a factor of two. Note that the ai and -(i are independent of b, 8o that, as the inversion must be done at every time step, it is more effcient to compute these coefficients only once and store them at the beginning of the calculation (DO loop 15); only the Pi then need be computed for each inversion (DO loop 30). G chapm.rfor PmAMmEB ( I S m P = 2 5 ) DJMEgSIOB PBI(0:NSTEP)
!lattice paa-mater ?=ray for eola%ion
PrmEsraH aLpaA(o:~s~~~),~rnh(o:~smpl ,CRMNACO:~~~STEP~ tmalflical soXu%iaa
GAUS~(X,T)=~P(-~~,*[X-~~)**~/(~.+~Q*?~))/SQRT(~+~O*T)
50
EXACT(X ,T)=GAUSS (X, T)-GAUSSf X-S. ,T) -GADS$ (X+$ + ,T) EI=I.IISTEP !abt&in h p a t fzem % @ m i n a BBTm E h t e r tiS11~l s$ep d z;otal t b s ( 0 t o e-t;op)* R E 0 *,BT,TI#E
*,
XF (DT .EQ.
0.)
STOP
L)TH=BT/H*+2
T=O. PPICO)=O. PHI( I S ~ P =Q. )
10
DO l 0 XX=$,'IPSmP-I PHI(EX) =EXACT( IX*H, T) CO~I]rJU& ! i h d &FHb md t?ArnB once AP=-Dm !A coeff icien$s AZ= i,+2*am ALPBA(~VSTEP-I)=o. I s t w t i n g valuaa G ~ ~ A < H S T BI=P - i~ /AZ DO 5 = l - !backumd svsgip ALPHA( E X - % ) =GAM[MA(IX) *l@ GAMA(XX-l)=-%, / (AZ+AP*ALPEfA (EX-1) 1 CQITImE: ! t h e loop ao zo I T g R = i , g r m E BETA(EJSTEP-.I)=PHE(ESmP) !find BETA a t thisj; the
.
15
f 77
DO 25 IX=HSTW-~,X,-% Iba~kwardsweep B~~(Ix-~)=GA~~~Ix~*~AP*BETA(IIC)-PBX~XX~ 1
comxm !find new
Pfff
! a i $ i a l value ! f o m a d sweep
40
PHI(Q)=O. DO 30 IX=O,ISTEP-1 ~ar(rx+l)=~~aa(xX)*PHICfx)+Elma~XX~ 601TI8W !aa%pa% e v s q 10th time step IF fMaD(ITBR, IQ) .EQ. 0 ) THEI PBfm *, "ee~a%ion = l , I=&, t b s = 8,XTEB+I)T T=T;mR*DT DO 40 IX=%,BfSmP-I DIP=PHI (1x1-EXACT( f X*E ,I'] PRXIT *, phi = \ PPHI(IX), Qrrox = 5 DIFF CQHTIEFIJE;
Ern fH 20
GOETIMUE GOTO 50 EBB
=
Exrtrdm 7.2 Use tHe, code above to investigate the accurwy and stabady of the ixnpgcit dgorithm for various vdues of At and far vmious lattice spacings. Study the evdutim of various initid conditions and verify that they correspond to your intuition, Incorporate sourGes or ginks &ng the lat.tiee and study the solutions that arise when 4 vanishw everywhere st; t = 0,
Exercise 7.3 Modify the code above to apply the algorithm (7.10) and stn* its stability properties. Explore the eff:ects of taking digereat linear combinations of 4" and #"+l on the right-hand side of Eq. (7.9)
m
(e.g.,
$4" f
a@"+').
m Exercise 7.4
A simple way to impose the Weummn boundary can-
+
is to require that ltbl = Gfto hg. Show that this iropi_lesthat the forward recursion of (7.12) is to be started with
7.9 Diflusion and Boundary value problems in two dimensions
What is the analogms expression impfied by the more a~eur&econsGraLint 4%= #% , 2hg? mat we the initial conditions for the backward recursion of the a and p coeacicients if Neunxann boundary caditions we imposed at the right-hand edge of the lattice? Modify the code above to incorporate the boundary condition that 4 have vanishing derivative at I = 0 (as is appropriate if an insulator is present in a heat conduction problem) and observe its effect on the solutions. Show that the inversion scheme for tri-diagonal matrices discussed above cannot be applied if periodic boundary conditions are required (i.e., @N = #@).
+
Exercise 7.5
Solve the boundary &e
problem posed in Exerdse 3.4
by diseretization and iwer~ionof the resulting tri-diagonal matrix. Cornpare your solution with those obtained by the Green's f~nctionmethod and with %beandyticd resdt.
7.3 Diffusion and boundary value proble sions
in t;wa dimen-
The diseustsion above shows that diEusion. in one amension. is best handled. by an impliGit method and that the required inversion of a tri-&&&and matrix is a mlativtlly ~isnplletask. It is therefore nal;urat to attempt to extend, this approach to two or mare spatid dimensions;. For the twodimensional dilfnsion equation,
the discretization is straightforward and, following our development for the one-dimensional problem, the time evolution should be effected by
where
Unfortunately, while H is very sparse, it is not tri-diagonal, so that the algorithm that worked so well in one dimension does not apply; some thought shows that H cannot be put into a tri-diagonal form by any permutation of its rows or columns. Wmw, the fact that W em be witten as ak sum of verators that sepatttely iavolve digerences only in the %" or g' indices:
l79
X 80
7, Parvxbiolic Partial Llriflerential Epations
means that an expression equivalent to (7.17) through order At is
This c m now be eduaded exaetly, as ea& of the required inversions involves a tri-diagonal matrix. In particulw, if we define the auxiliary function 4n+1/2,we c m write
+ +
Thus, (1 ~lj&t)-'is applied by forward and badtward sweeps of the lattice in the j direction, independently for each value of i. The application of (1 Hiat)-' is then carried out by forward and backward sweeps in the i direction, independently for each value of j . This "alternatingdirection" scheme is easiiy seen to be stable for all values of the time step and is generdized straightfommdfy to three dimen~ions. The ajbility to invert a tri-&&%on&matrix exaetIy itnd the idea of treating mpwatdy each of the second derimtives of the Laplacia~dso provides a dass of iterative alternating-direction methods [Wa66] for salving the elliptic bsundmy value problems discussed in Chapter 6. The m a t ~ xi n v o l d is witten as the sum, of sewrd parts, each cont~ning second &Rerences in a d y one of the lattice indice@,h two dimensions, for example, we seek to solve [see Eq. (6.3b)j
If we add a term w 4 ta both side8 of this eqzxatios, where w is a cansbant discvssed below, the re~ultingexpression can be sdved for # in Wo dieerelrrd ways:
This pair of equations forms the basis for an iterative method of solution: they are solved in turn, 4 on the right-hand sides being taken as the previous iterate; the solution involves only the inversion of tridiagonal matrices. The optimal choice of the @accelerationparamet er". w ,depends on the matrices involved and can even be taken to vary from one iteration to the next to improve convergence. A rather complicated
analysis is required to find the optimal values [Wa@6].However, a good r d e of thumb is to t&e where cu and p are, respectively, lower md upper bounds to the eigenvdues of Ifi and Hi.In generd, these alternating direction methods are much mare efficient than the simple rdaxatioa scheme &iseu~hsedin Chitpter 6, dthough they are sfightly more: complicated to program. Wote that there is a stight campgcation when bounday conditions are also wecified in the interior of the lattice,
7.4 Iterative methods for eigenvalue proble Our analysis of the diffusion equation (7.1) shows that the net result of time wolutian is to enhance thorn components of the solution with snnder eigenvalues of E relative to those with laxger dgenvdacjs. Indwd, for very long times it is only that cornponeat Pviah the lowest eigenvdue that is sipificant, dthou& it has very snn& mplitude, This situat;ion sugests a sckeme for fin&ng the lowest eigenvdua of an el&pticaperator, a8 defined by (6.2): guess a trid eigenvector and subject it to a Gctitious time evolution that will "filtern it to the eigenvector having lowest eigenvalue. Since we are dealing with a linear problem, the relentlessly deereasing or increasing magnitude of the solution can be avoided by renormalizing mtinuoudy a63 time proceeds, To make the discussion concrete, consider the time-independent Schroedinger equation in one dimension with h = 2m = 1. The eigenvdue problem is
with the narmazation condition
(4 can always be chosen to be red if V is). The corresponding energy functiond is On general grounds, we know that E is stationary at an eigenfunction with respect to variations of C$ that respect the normalization condition and that the value of E at this eigenfunction is the associated eigenvdue.
282
7,Pambalic Parlial Diflewntial Equations
To derive a discrete approkmation to this proMem, we discretize E
and the uram&zation constrdnt t&es the farm
Varia'cion with re~pectto g5i gives the eigendue problem
pJith E entering as a Lagrange maltiplittr ensuring the no~malization, (6ompwe d t h the, derivation of the Rartrw-f"o& eq~ationsgiven in Project 111.) We can interpret (7.27) as defining the problem of finding the real eigenvdues and eigenvectors of a (large) symmetric tri- diagond matrix representing the operator B. Although direct methods for sdving this problern were discussed in Chapter 5, they cannd be applied to the very large banded matrices that arise in two- and three-dimensimd prablems* However, in such ernes, one is usadly intemted in the few Mghes;t or lowest eigenvalues of the problem, and for these the diffusion analogy is appropriate. Thus, we consider the problem.
wkem r is a 'Y&en time, For convenience, we suppose that things have been arranged so that the lowest eigenvdue of X is positive definite. (This can be guaranteed by shifting B by a spatially-independent constant chosdn so that the regultant V;; Is positive for all d.) To solve this "fake" digusion problem, any of the atgoritbms d i g cussed above can be employed. The simplest is the explicit scheme andogous to (7.5): (7.28) 4"+' (1 - HAT)^^ , where Ar is a small, positive parameter. Kere, the symbol m i s used to indicate that is to be norm&zed to unity according to (7.26). For an initial guess, we can ehoose q5O to be anything not orthogond to the exact eigenfunction, although guessing something close to the solution will speed the convergence. At eadt step in this refining process, computation of the energy from (7.25) furnishes an estimate of the true eigenvdue.
-
As an example, consider the problem where
this corresponds to a free partide in hard-walled bax of unit length. The anafytied solutions for the normatized eigenfnnctions as@ and the associated eigenvalues are Here, X is a --zero integer. The following FORTRAN progam implements the scheme (7.28) on a lattice of 21 points and calculates the energy (7.25) at every fourth iteration. The initial trial funetion q5 %(l-s) is used, which rou&fy approdmates the shape of the exaet gzound state. C ckap7c.for
%OQ
PBRAEETm (NSTW=20 f la%%i68 parneter D T ~ I S I O IPHI CO:I S ~ P ) !s c x ~ t i o ~ E= r ,/BSTEP !obtah inpa% irom screen PRIIT *, R &tar step size ( ,sq. O to stop)R BEAE) *, DT
XF (DT .EQ, Q. ) STOP DTE=BT/t3**2 !initial guess for PBX
DQ 10 IX=O,BSmP X=IX*H
arrx(xx>tx+(i , - X ) 10
COrnIrnE: CALL I Q a(PBX ,'lQSTEP]
t n o m a i z e guess !ftera%ion loop
DO 20 f TEE=%,200 POrn=O* DO 30 IX=I,ISTP-I !apply [%-E*DT) P%EV=PEZ(IX)+DTB* (POf,D+PEII (I21+1)-2*PIXI (XX) POU=PBf(IX)
)
PEILS (IX)=PHgv 30
COmXMa !caJccaa%e
hergy, Eq. (7.25)
184
7. Parobolic Partial Bifierenlial Bpations
E=E+(PHI(IX)-PE1 (IX-11)**S? 68m11fila
50
PRSIT mT)XF
* , I
itera%ion= \ ITER,
energy =
', E
SWWVTXMEZ HOW (PHI,BilSTEP) RImISIOl PHX(0:HS"X"EP) XIORM=O.
lQ .
DO 10 TX=Q ,ISTEP mOM=X;1POEH+B&XCIX)**2 COmSmE XNORB=SqRT(BTSTEP/XHORN>
DO 20 TX=O ,BSmP Pax(xx)=PEI(xx)+maw 20
COWXmE. RErnW
END
The xsufts generated by the code above for severd diEerent vdues of AT me shown. in Table: 7.1 Note that far vatues of AT ~f~l&er than the stability limit, $ hZ fi. 0.00125, the energy converges to the expected answer and dws so more rapidly for larger AT. Eowever, if AT becomes too large, the large-eigenvdue componeats of trid dgenfuactian me aplified r&her than diminished, and the eaerD obtdned finally wrresponds to the lawest eigenvdue of H , the exact fisite diEerenw value of which is [see the discussion following Eq. (7.6))
Tkis phenamenm then sugesgs h m to find the eige~valueaf:an operator with the largest absolute value: simply apply H to a trial function many times.
7.4 Itemtive methodsfor eigenvalue problems Table "11 Ganvergence a-f the lowest eigenvdue of the maare-wdl problem. The analytic rmult L 9.85960; the e x a t finile-difference vdue is 9,84933.
Although the procedure outlined above works, it is unsatisfactory in that the Braitation on the size af AT caused by the laLtice spacing often result;s in having to iterate many times $a refine a, poor trid function. This can be alleviated to some extent by choosing a good trial function. Even better is to use an implicit scheme [such as (7.8)] that does not amplify the large-eigenvalrue eamponents for my value of AT, Another possibility is to use exp(- HAT) to refine the trial function. While exact c d d a t i o n of this nrzltrix can. be diseult if large dimensionrs me imvdved, it can be wea-=presented by its series expmsion tbrougb a finite nunrber of terms. This series is e a y to evduaLe since it involves only applying _IS many times ta a trial ~ t a t eand generay a larger AT can be used than if only the first order approximation to the exponential, (7.281, is employed. We have shown sa far how the method we have discussed c m be used to fiad the lsvvest or highest eiigenvdue of m operator or matrix. To see hovv to find other eigenvdues and their assacirtLed eigeduaclions, consider the problem oT finding the second-lawest eigeavdue. We fir& find the lowest eigenvdue and eigenfunction by the method described above. A t r j d function for the ~econdeigenfunctim is then guesged and refined in tbe s m e way, tikking care, however, that at each s t q e of the refinemeat the solution rem&n orthogonalI;a the lowest dgextfunctian already faund.
185
This can be done by continuously projecting out that component of the solution not orthogond to the lowest eigenfunction. (This projection is not required when there is some symmetry, such as reflection symmetry, that distinguishes the two lowest solutions and that i s preserved by the refinement algorithm.) Having found, in this way, the second-lowest eigenfunction, the third lowest can be found similarly, taking care that during its refinement, it remains orthogond to both of the eigenfunctions with lower c?igenvdues. This process cannot be applied to find more than the few lowest (or highest) eigenvectors, however, as numerical round-off errors in the orthogonalizations to the many previously-found eigenvectors soon g o w to diodnate, Although the methods described h o v e have been iuustrated by a one-dimensional example, it should be dear that they caa be appIied directly to find the eigenvdues and eigenfunctions of elliptic operators in two or more dimensions, for example via Eq. (7.19). r Exercise 7,8 Extend the code giwn &mto find the eigenfunctiaas
and eigenvdues af the fifst t-wo exeited sta"ces of each parit;y in the onedimensional square-well. Compare your results with the: exwt solutions and with the analytic4 finite-difference vdues. Exercise 7.7 Write a program (or modify that given above) to find the few lowest and few highest eigenvdues and eigenfunctions of the Laplacian. operator in a two-dimension& region consisting af a s q u m with a square hole cut out of its center. Investigate how your results vary as functions of the hiize of the hole,
7.5 The time-dependent Schroedinger equation The nummical treatment of the tinte-depe~dentSchroedinger equation for a particle moving in one dimension provides a good illustration of the power of the techniques discussed above and some striking examples of the operation of quantum mechanics [Go67]. We consider the problem of findjng the evolution of the (complex) wave function 4 under Eq. (7.2), given its value at some initial time. After spatial discretization in the usual way, we have the parabolic problem
where H is the operator defined in (7.27) and we have put h. = 1. To discretize the time evolution, we have the possibility of employing the analogue of any of the three methods discussed above for the digusion equation. The explicit method related to (7.5), in which the evolution
7.5 The time-dependent Sehrdinger eqzscgtio~z 187 is effected by (1 - iHAt), is unstable for any value of At because the eigendues of this ape~ator,
have moduli (1
+ e:&t2)2/2
greater than unity. The implicit scheme analogous to (7.8), in contrast, is stable far all At, as the moduli of the eigenvdues of the evolution operator, (1 E I A ~ ~ ) - 9' / ~
+
are always less than one. This is still unsatisfactory, though, as the numerical evolution then does not have the important uaitarity property of the exact; evolution; the norm of the wave function contimally decreases with time. Fortunately, the a n d w e of (7.10) turns out to be very suitable. It is
This evolution operator is manifestly unitary (recd that B is hemi tian) with eigenvdues of unit modulus, so that the norm of 4 cornpaged according to (7.26) is the same from one time to the next. (Of course, the square of the real wave function in (7.26) is to be replaced by the modulus squared of the complex wave function.) The algorithm (7.30) also has the desirable feature that it approximates the exact exponential evolution operator, exp(- i H At), through second order in At, which i s one more pQWeF than would h~ been supposed For wtud numeric& computation, it is efficient to rewrite (7.30) as
This form eliminates the sweep of the lattice required to apply the numerator of (7.30). To find, at each time step, the intermediate function X defined by (1
+ i5l HAt)x = 2Q
we write this equation expficitly as
,
3.88
7,Parabolic ParEt"nlDifferential Equations
which, upon dividing by -i&t/2hz becomes
This has the form of (7.11), and can therefore be aolved by the twc~sweep method discussed in. connection with that equation, The FORIICRAN program for Exmple 7, whose sour= code is contained in Appendix Ef and in the file EXMPL7,FQR, nses the method described above to solve the time-dependent Schroedinger equation, Severd analytical forms of the potential (square well or banier, Gaussian well or barrier, potential step, or parabolic well) can be defined on a point lattice whose size is set by the pasameter BPTS. An initial Gaussian or Lormtzim wavepacket of specified average position, average momentum, and spatial width can {;hen be set up on the lattice and evolved under the boundasy condition that d, v d s h at the lattice boundaries. The probability density, l+lz,and potentid are displayed at the requested frequency, while the total prohabillties and average positions of those portions of the wavepacket to the left and right of a specified point are displayed at every time step. The time evolution is continued until the user requests termination of the program * The following exercises will be useful in improving your understanding of' this example. Exercise 7.8 Test the accuracy of the integration by integrating forward for some time interval, changing the sign of the time step, and then continuing the integration for an equal time i n t e d to see if you return to the initial wavepwke. Note that the mergy edctllated in subrcrutine E~EBcYis conserved independent of the time step. Verify that this should be so using Eq. 7.30.
m
Exereise 7.9 Verify that wavepackets in the absence of any potential and wavepackets in a parabolic potential well behave as you expect them to. Exercise 7.10 Send wavepackets of varying widths and incident energies at barriers and wells of various sizes and shapes. Interpret all features that you observe during the time evolution. For square-well and step potentials, compare the fractions of the initid probability transmitted and reflected with the analytic$ values of the usual transmission and refiection coefidents. Set up a resonance situation by considering scattering from potential8 wit6 a "pocket" in them and observe the separation of the initial wavepacket into prompt and delayed components. Set up a "double-well" tunneling situation and observe the evolution. m
Exercise 7.11 Replace the evolution algorithm (7.30) by the unstable explicit method or the non-unitary implicit method and observe the eEects.
m
Replace the vanishing Diridlet boundary condition iibt one lattice end by s zero-derivstivr! Neuxnann botxndary ca~ditiomaxld observe what happens when a wavepadet approaches.
a
Exercise 7.12
In two- m d thr~dimensiondcdculatioas, the l a g e number of lattice points forces the use of as lwge a lattice spacing as is possible, so that higher-order approximations to the spatial derivative become necessary [F178]. Replace the 'three-pointn formula for the spatial second derivative by the more accurate afive-point" one listed in Table 1.2. Dwdop an algorithm, to invefi the pentacdiqmaf matrix indved in the time evolution. Itrapfern& this in the code aad observe any &ages in the results or the computationd cadency.
r Exereri~e7.13
Project VII: Sel&organization in chemical reactions Recent work in several branGhes of physic~h= shown that the solutions of nm-linear equations can display a rich mriety of phenomena. Among these i~ "patdesn selectionn,in which stabb, non-trivid patterns in space and/or time emerge spontaneously from structureless initial conditions. In this project, we win invwtigate axlafyticdly and name~cdlya model of chenaied rextions, the "Bmsalator", whose solutions exhibi.t;behavior thal, is very s i d a r to the striking phenomena, observed in actud chernied systems [Wi74]. Our discussion fdlows that of [Ni77] and [Bo76].
VII.1 Description of the model We consider a network of chemical reactions in which reagent species A and B are converted into product spedes D and E through intermediates X md Y :
(Vll.la) ( V l l .lb ) ( V l l .le) ( V l l .l d ) We assume that the concentrations of A and B are fixed and are spatidy uniform and that the species D and E are 'dead" in the sense of being chernicdly inert or being removed from the reaction volume. We adso assume that the processes (VII.la-d) are sufficiently exoergic to make
190
7.Parabodic Partial Bigerential Equations
$he reverse reactions negEgibft3. Under these conditions, we can mite the foflowing equations for the evdution of the conwntratims of X and Y :
Here, kn-d are the rate constants for the reactions (VII.la-d), respectively, and Dxtu are the diffusion constants of the species X,Y. It is convenient to scale the non-linear diffusion equations (VII3) to a dimensionless form. If we measure time in units of k;', space in units of l , a &asacteristic size of the reaction vsfume, X asld Y in uaies of (kd/k,)fr A in units of (k$/kEk,)i, B in units of kd/kb, and DXPYin units of kd12,then Eqs. (VII.2) become
s it is clear that the caastmdh; A and B can be of order horn t ~ seang, unity, although D X t y might be considerably smaller, depending upon the vdue of I. One trivial golutian ta these equations can be fauad by assudng that X and Y are independent of space and time, Setting all derivatiws .to zero yields a set of dgebraic eguatians that can be aofved for the equilibrium point. After a bit of algebra, we find that equiifibrium fs at
To completely specify the model, we must give the spatial boundary condiLions. Of the various passible ehoices, t w we of parlicular pbJrsid interest. Il"bese are the 'no-flux" boundaq conditions, in whi& the nosmajl derivatives d X and V are reqdred to vmish sn the surface of the reaction volume (as might the case if the chemistry takes plwe in a closed vessel) and the "fixed" boundary conditions, where X and Y are required to have their equilibrium vdues on the surface of the reaction volume.
VII.2 Linear stability analysis To get some insight into the behavior of this system before beginning to compute, it is useful to andyze the behavior of smdl perturbations about the equilibrium stiitte. To do so, W pnt
where F represents the spatial variables and &X,6Y are small quantities dependent upon space and time. Inserting this into (VII.3) and linearizing in the g r n a qnantities, we have
We now speci&ze to the no-flux boundary condition in one dimension. We can then expand SX as Q0
bX(r,t ) =
X
G x , ~ ~ ~cos ' mzr
,
(V11.6)
m=@
and similwly for SY, Were, Q r 2 1 is the spatid camdinate and the w, indicate the stability of eea& n o m d mode, fn particdw, Re w, < O indicates a stable made thzbt damps in time, w&le Re c ~ >. , O inrficalles an unstable perturbatioa that grows; a complex o, indicates a mode that afso oscillates as it grours or damps. For the fixed boundary conditions, the expansion analogous to (VII.6) involves sin mrrr rather than cos mrr. Upon introducing %he Faurier expmsion into the lioearjzed equations (VII.5a,b) aad equating the coefficients of each spatial mode, we obtda the fanowing hamageneous eigendue equations:
Xt is easy to see that these hold for both ltypes of boundary conditions and that the eigenvdues then saeisfy the characteristic equ;ktion
with
292
7, PamboZie Partid Diflerentiot Equations
Figure VX1.Z Stabgity of the u ~ f a r mequilib~umst9;te with rapect to osaatory beha~ar,The m = 0 mode is isbent for fixed boundary conditions, (Ram [%i77f.)
(We have here written X. md l$ explicitly in terms of A and B). The roots of this equation are
Z = ,{a,
- pm f [(a, +
-4 ~ ~ ~ 1 ~ ' ' ) *
A detailed ana?ysis of Eqs. (VII.S,10) reveals several interesting aspe&s about the &ability of the aniform eqvllibrium state. It is ewy to see that if m becomes large for fixed values of A, B, and D X y, , then the w$ become very negative; modes wit h large wavenumbers are therefore stable. Let us now imagine that A and Dxev are fixed and B is allowed to vary. Then, since there we complex roots only if the discriminant in (VII.10) is negative, we can conclude that there will be oscillating modes only if
Since we must have A, > Q, this implies that there are oscillations only
t
I
t
1
I
I Stable
StabiXity of the uniform. eqrrilibrium state with respect ta exponentiay grourine, pertuxbati~ns(From [Ni77].)
Figme lr61.2
Furthermore, if there is a complex dgexvdue, its real part will be pasitiive (an unstable mode) only if
The situation is sururmsized in. Figure TJ1f.l. Modes with red, paitive frequeades are preseat only if ampntA ~ B 1 0, which implies that
If W imagine m to be a continuous variable, then it is easy to see that B,, h= a minimum vdue of
O f course, siftce tbe physied vdues of m are restricted ta integers, as B is increased from 0, the non-oscillzjttory mode m, that first becomes
I94
7.ParaBolic Partial Diflerendial E w a l i ~ n s
unstabfe at B --- B, is that wWhjch i~ c l o ~ e to ~ tthe minimum, as s h o w in Figure VXI.2, To summafiee thia discussion?the uniform eq~libriumstate is unstable with respect to perturbations that osdllate in time when B > B. or B1for no-Bux and fixed boundary conditions, respectively. Similarly, it is nastit,bIe with respect to perhrbalions %hadgrow exponeatidy in time when B > B,,
'VI1E.3 Numerical solution o f the model Although the stability analysis presented above gives some hint at the behavior of the system for various ranges of the pxameters, the h X lridness of the model in the non-linear regime can be revealed only by numerical experiments. These can be carried out through the fallowing steps. Step 1 V e ~ f ythe dgebra in the stability andysis discacased above, Assame a fixed. value of A = 3: in a ane-dimension& situatiamr,and cdcdate the h, and B, for a set of values of the diffusion constants of order 1 0 ~ ~ . How do your results change if the reaction t&es place in the unit square in two space dimensions?
m
m i t e a progam that solves the non-linear digusion equations (VII.3a,b) in one dimension on the interval [0,1] for the case of no-fittx boundary conditions; a rewonable number of spatid points might be between 25 m d 100. The diRasion t e r m shodcl be treated. irnpEcitly to preved unphysicd numericat inst&ili-ties, mrhile the reaction terms can be tre&ed exp2icitly. ZIave your progrm plot out X and V at each time step.
r tet~p2
Step 3 Use your one-dinze~siondproerram to investigate the behavior of the solutions for different values of B, DX*y.A reasonable place to start might be Dx = 1 x I O - ~D, y = 4 X l@-$; the linear stability analysis should then give some guidance as to what values of B are interesting. Investigate initial conditions corresponding to smooth sinusoidal and point-wise random perturbations of the uniform equilibrium configuration (the latter can be generated with the help of function RANR~S, found at the end of Appendix D.3, or your compiler's intrinsic random number generator). Verify that you can find cases in which the system refmes back to the u n i h m state, in whieh it a m p t o t i c d l y a~>proa&es a time-independent solution with a non-trivial spatial variation (dissipative structure), and in which it approaches a space- and time-dependent oscillating solution. Throughout, make sure that your time step is small enough to allow an accurate integration of the equations.
m
Vile Se~-c3rganixationin chemical reactions
Extend your one-dimensionat. mde la szolve the Brusselator with no-flux boundary conditions in two spxe dimensions using, for example, an alternating-direction algorithm like Eq. (7.19). Plot your results for X at each time. (The technique of displaying an array of characters, as in Example 6, can be useful.) Investigate parameter ranges and initial candiltions as in Step 3. Step 4
195
This page intentionally left blank
Chapter 8
Monte C Methods Systems with a large number of degrees of freedom are often of interest in physics. Among these are the many atoms in a chunk of condensed matter, the many electrons in an atom, or the infinitely many values of a quantum field at all points in a region of space-time. The description of such systems often involves (or can be reduced to) the evaluation of integrals of very high dimension. For example, the classical partition interacting through function for a gas of A atoms at a temperature l/@ a pair-wise potential v is proportional to the 3A-dimensional integral
The straightforward evafzration of an i n t a g d like this by one of the quadr&ure formulas discussed in Chapters 1 or 4 is conrpletely out sf the question except for the very smdest values of A. To see why, suppose that the quadraturn allows ea& coordin&e to take on 10 digerent vdues (not a very fine discretization), so that the integrand must be evaluated at points. For a modest value of A = 20 and a very fast computer capable of some 107 evaluations per second, this would take some 2 . 0 ~ ~ seconds, more than 1oa4 times the age of the universe! Of course, tricks like exploiting the permutation symmetry of the inteffrand can re-duce this estimate considerably, but it still should be dear that direct quadra1;ure is hopeless, The Monte Carlo methods discussed in "this chapter we ways of efficierttty evaiuading integrds of Egh dimension. The name &MonteCarlo" arises f"rom the random or U&mce" chwacter of the method and the f a o u s casino in Monaco. The essentid idea, is not ta evaluate the integrand at every one of a large number of quadrature points, but rather
198
8,Monte Carlo Method8
at only a representative random sampling of abscissm. This is and~goua to predicting the resalts of an election on the basis of a poll of a smdl number of voters. Although it is by no means obvious that aoything sensible can come out of random numbers in a computer, the Monte 6x10 strateg turns out to be very appropriate fof a brad dass of: problems in statisticd a d quantum mechanics, Mare d e t ~ l e dpreseat;ttions of the method than that given here can be found in [Ha641 and [Ka85].
8.1 The basic Monte Carlo strategy Even though the reai pawer of Monte Caflo methods is in evduating multi-dimensional intepds, it is easiest to illustrate the basic ideas in a one-dimensional siluation. Suppose that; we have to evduate the iatepal
for s m e padicular function f . Chrtpters 1 and 4 discussed several &E &rent qudratare formulw that employied vdues of f at very particular values of 2. (e.g., equally spaced). However, an alternative way of evaluating I is to think about it as the average o f f over the interval [Q, l]. In this bight, a plau~liblequadrature formula is
Heref the werage of f is evaluated by consideriag its values at N abscissae, {si),chosen at random with equal probabitity anywhere within the interval [0,1]. We discuss below methods for generating such "randomn numbers, but for now it is sufident to suppose th& there is a computer function that provides as anmy of them as are required? one after the other, Note thia't these is n s such FOETRAN-"7 function, but many compilers provide their own (e.g., RAN in VAX FORTRAN) and we provide function RANNOS (found in the file UTIL.FOR and listed at the end of Appendiv D.3). To estimate the uncertainty agsoeiated with this quitdrature fornufa, we can consider fi ziii f ( z i ) as, a random variable and invoke the central limit theorem for large N. From the usud laws of statistics, we have
where o; is the variance in f ; i.e., a measure of the extent to which f deviates from its average value aver the region af integration,
8.1 The basic Monte Carlo s t r a t ~ g
Equation (8.3) reveals two very important aspects of Monte Carlo qudratun;. Rrst, the uncertainty in the estimate of the integd, 01, decreases as Hence, if more points are used, we will get a more precise ansarer, although the error decreases very slovvly with the number of points (a factor of four more numericd work is required to halve the uncertainty in the answer). This is to be contrasted with a method like the trapezoidal rule, where Eqs. (1.8,1.9) show that the error scales like N m 2 , which affords a much greater accuracy for a given amount of numerical work. (T6is advantage vanishes in multi-dimensional cases, as we discuss below.) The second important point to realize from (8.3) i s that the precision is greater if of i s smaller; that is, if f is as smooth as possible. One Irimit o f t E s i s when. f i~ is aconstant, in which cwe we need its vdue at only me point to define its aver%@. T"a see the other limit, consider a situation in whi& f i s zero except for a very narrow peak about gome vdue of 2, If the 86 have an equd probabiliv to lie anywhere between 0 and 1, it is probable that a;U but a few of them will lie outslide the peak of f , and that only these few of the fi will be non-zero; this will lead to a poorly defined estimate of I. As an example of a Monte Carlo evaluation of an integral, consider
The following FORTRAN program calculates this integral for the value of N input, together with an estimate of the precision of the quadrature. G cbp8a.lBor XITEGER S m DATA SEm198765432g/ DATA E;ZIACT/, 78640/ NgG(X)=CEI./(1 .+X*+2) C
10
!seed 203:
amber generator
!aaPytic aawer t fmct;ioar t o int e p a t e
PRTBfT *, "%er nmber of posts (Q to stop) B REAII) *, M XP (I .EQ, 0) STOP
C SUW=O.
!zero s w s
5VW2=01
DO 20 IX=Z,lil
!loop over s w l e s
F X = W C (EkBI(SEm))
SGW=SMF+FX
!&d con$ribations to s m s
199
200
8. Monte Carlo Me&
Table 8.1 Monte Carlo evaluation of the integral (8.4) using two digerent wei&t functions, ~ ( 8 ) .The exact vdue i s 0.78540.
Results of running this program fur various values of N are given in the first t h ~ e ecolumns of Table 8.1, The cdculated result, is eqnd to the exact value within a few (usually less than one) standard deviations and the quadratare becomes more predse as N increases. Since Eq. (8.3) shows that the uncertainty in a Monte Carlo quadratare is proportional to the variance of the integrand, it is easy to devise a general scheme fur reducing the variance and improving the efficiency of the method. Let us imagine multiplying and dividing the integrand by a positive weight function w(z), normalized so that
8.1 The bosic Monte Carlo utmb-egy
The integral can then be written as
If we now make a Change of variable from z to
then the integral becomes
The Monte Catlo eduation of this integral proceeds as above, namely ayeraging the values of f /w at a random sampling of points uniformly distributed in y over the interval [0,1]:
The potentiat benefit of the change of &able should now be clw. If we choose a m that behaves approurimately as f does (i-e., it is lage where f is large md small where f is small), then the integrand in (8.7), f /w, can be made very mooth, with a consequent reduction in the variance of the Monte Carlo estimate (8.8). This benefit is, of coarse, contingent upon being able to find an appropriate w and upon being able to invert the relation (8.6) to obtain z(y). A more general way of understanding why a change of variable is potentially useful is to realize that the nnifonn distribution of points in y implies that the distribution of points in x is d y l d x = w(s). This means that points are concentrated about the most "importantn values of x where w (and hopefully f ) is large, and that little computing power is spent on calculating the integrand for "unimportantn values of s where PD and f are small. As an example of how a change of variable can improve the efficiency of Monte Carlo quadrature, we consider again the integral (8.4). A good choice for a weight function is
201
202
8-Monte Carto Mei;ho&
which is positive definite, decreases monotonicdly over the range of integration (as does f), and is normalized correctly. Moreover, since f l w = 314 at both s == O and a: =I I, W well appraimat;es the behavior of f . According to (8.6), the new integration variable i s
WE&can be inverted to &ve
The following FORTRAN code then evaluates I according to (8.8). G ch@b. for IETEGER S W DATA Sm18878543221
!seed f a r radom &-&er
gaerator
78640/ !=aytic vazua !imctfon to i n t e ~ a t s mMC(X)==:./(i,+X**2) WEZGBT(X)= (4, -2+X)13, !neigh%f a c t fon !X as a imcdion of P XX
DATA =ACT/.
C $0
PRIIT
*,
mm
+, l4
P
&tax
nwber of p o h t s ( 0 t a srop)
IF' (R *EQ*01 STOP C
SUm=o. s~m2=0. DO 20 III=I,B Y=RAE(SEa)
?~eZ?a SW8
!Isop ovax smp2ss
x=xx (Y) F X = F ~(X) C /%IEILGET(X) ? i ~ r e g ~ ~ d SWW=SWF+m !adcl contritnrtions ts s m 2=mW2+FX*+2 COlJTfl U E FAVE=SW/I ? averages F21VE=SUMF2/1 SXGMA=S~RTC(F~AVE-FAVE**~]/I) !emox
28
PRXsfT
+
8
*,
i n t ~ e a f=PrFAVEr8 +- ',SLGldhr)
GOTO 10
EHD
ttrrof
"EXACT-FAVE
8.1 Tbe Zta&t"cMonte Carlo stmlegg
Results of running this code for various values of N are shown in the last twa colurns of Table: 8.1, where the improvement over the zo = 5, case
treated previously is evident, The one-dimensional discussion above can be readily generazed to d-dimensional integrals of the form I = j d d z f (X). The analog of (8.2) is
with the severat components of the random points xi to be dosea independenlf y, Thus, the following FORTRAN proe;~amcdedat;es
that is, it eolnpares the area of a quadrant of the unit eirde to that of the unit square (B is the unit step function): C c;hp8c*fox
XmEGm
!seter& fox r d o n nmber gsnera%or
SED
DATA SEm/3274927/
.
EXbm=4.*ATAP 1 ) C
20
!pi
PRIHT *, heer srubsr af p h % s(0 %a atop)" RErn *, P IF (H .EQ. 0) STOP
C
!zero comt $loop over santplsa
IGQWT=O DQ 20 XX=1,B X=MlCSErn) U=MlaT($Em>
10
.
SF ( (X**2+V**2) LE 1. ) XCOWT=ICOVET+ 1 COITXrnB v r a = m ~ ( z c o v ~ ~ ) / ~ ?pa/?r SICM=SQRTCPI4*(1, .-PZrlr)/I] f emor faRXlT *, e B pi = 4*PX4,"p",4+S3C;MiA,hrxar = ',EXACT-WPI4 GOTO 20 EEL)
When run, this program generatc3d the satisfactory result of 3.14241= 0.0232.
203
Exercise 8.1 verify that the error estimate used (two Enes &er line 10) of this program is that given by Eq. (8.3).
U
The & a g e of vwiable discusmd above can dso be generdized $0 many dimensions. For a weight function w(x) normalized so that its integrd over the re@on of integration is unit& the approp~atenew mriable of integration is y, where the Jacobian is = w(x). It is generally very difficult (if not impossible) to construct x ( y ) explicitly, so that it is more convenient to think about the &an@ of variable in the multi-dimensiond c a e in the Ben- discussed above; i.e., it distributes the points xi(yi) with distribution W. Various practical methods for doing this fof a r b i t s q w will be discussed below, Although the results were satisfactory in the examples given above, Monte Carlo quadmure does not wpear to be pasticulaly efficient, Even with the "pod" choice of W ,the rc3sdts in Table 8.1 show a precision of only about 10-' for N = 5000, whereas the conventional trapezoidal formula with 5000 points is accurate to better than 1 0 ~ However, ~ . consider evaluating a multi-dimensional integral sueh as (8.1). Suppose that we are willing to invest a given amount of numerical work (say to evaluate the integrand N times), and wish to compare the effieiencies of conventiond arid Monte Carlo quadratuma. In a conventioaiaf quadrature, say a mdti-dimension4 analog of the trapezoid4 rub, if $here are a totd af IV points, then e x h dimeadon of a d-dimensiand intern& is braken up . analog of (1.9) shows into ~ ' intervds 1 ~ of spwing h N - I ~ ~ The that the emor in the integral over eaeh cell of volume hd in the integration region is o(hd+l),so that the total error in the conventional quadrature i s for large d, this decreases very slowly with increasing N. On the other hand, Eq. (8.3) above shows that the uncertainty of a Monte Carlo quadratare decreases as N - ' / ~ ,independent of d. Assuming that the prefactors in these estimates we dl of order unity; we see that Monte Cwlo quadratare is more eficient when d 2 4. Of course, this estimate depends ia detail upon the conventional quadrature scheme we use or how good a weight function is used in the Monte Carlo scheme, but the basic point is the very different way in which the two errors scale with increasing N for large d
8 3 Generating rcrtlciom variables wi& a $pi$~iecl dzstr-s"bul;iots 205
8.2 Generating random variables with a specified distribution
The discussion above shows that Monte Cm10 qndratnre involw two basic operations: generating abscissm randomly distributed over the integration volume with a specified distribution w(x) (which may perhaps be unity) and then evdaating the function f l w at these abscissae. The second operation is straightforward, but it is not obvious how to generate "random" numbers on a deterministic computer. In this section, we will coyer a few of the stmd;asd method8 umd. The generation of uniformly distributed random numbers is the computer operation that underlies any treatment of a more complicated distribution. There we numerous methods for pedoming tkis bwic task and for cheching that the results do indeed correspond to the uniform random numbers required. One of the most common algorithms, and in fact that used in the VIAX FORTMM RAN function, is a '"near cmgruential" method, which "grows" a whole sequence of random numbers fram a, nsr?ed" n u b e r . The cunent member of the sequertee is rauftiplied by a first "magic" number, incremented by a second magic number, and then the sum is t&en moduk, a third magic number. Thus,
where i is the mquerrce label and, a , c, and m are the magic numbers, The littder me often very h g e , with their precise values depending upan the word length of the c-ornputer being used. Note tha%the zi cmnot be truly "random" W they aise from the swd in a well-defined, deterministic algorithm; indeed, two sequences g r w n from the the s m e seed are identical. Fbr this remoa, they are often termed "'pseudo-random", Nevertheless, for m a y practicd purposes pseudo-random numbers generated in this way can be used as if they were truly random. A good discussion of uniform random number generators and of the tests that can be applied to determine if they are working properly can be found in [Kn69]. We have dready seen how to choose one-dimensional random variables distributed as a specified weight function W(%). According to the discussion in the previotxs section, the procedure is to choose y, the ineomplete iaf;egra-l of W , u n i h d y , and then to find z by inwrting Eq, (8.6). Thus, if we are faced with evduating the integrat
with g a relatively smooth function, it is sensible to generate z between 0 and oo with distribution and then to average g over these d u e s . According to (8.5), we have
The followi~~g FORTRAN subroutine generates values of X with the required distribution, c chap8d.for
suBRawrm WCDST(X) XBTEGm S E D
DATA SEm C
/88341927/
.
X=-LOG ( I-UIEI(SEm) )
REmm EID
Excsreim 8.2 Verjfy that the code above generatea X with the reqlrired distribution, for example by generating aad h i s t o g r m ~ n ga large number of vdues of X. Use these v d u e ~to evitluii;te 1 and its uncertainty for 9(2) = 5, zZ,md z3 and compare your results with the analytical vdueg. Can you understand the trend in the uncertainties cdcdaled?
m
WMe the method of generating the incaqlete integral is infdfible, it requires that we be able to find + ( g ) , which can be done analytically only far it relilrtively s m d class of functions. For example, if we had wmted to US@
in our efforts to evaluate Eq. (8.4), we would have been faced with solving a cubic equation to find g(%). While this is certainly possible, choices of w that might follow more closely the behavior of f generally will lead to more complicated integrals that cannot be inverted analytically. However, it is possible to do the integral and inversion numerically. Let us imagine tabulating the values for which the incomplete integral of w takes on a series of uniformly spaced values y(j)zz j / M , j = 0, 1,... ,M that span the interval [Q,l]. Thus,
8.2 aneratin@r a n d ~ mvariables with a specified distribution
Figwe 8,1 fllmtration of the von Nemmann rejection method fox generating raindom numbers distributed =carding to a gven di~triba$ion w(a;).
...
Values of z(j) with j an integer chosen from the set 0, 1, ,M with equd probability will then approximate the required distribution. (Some special treatment is required ta handle the end-point6 g' = 0 and j = M properly.) To generate the d , is, of course, the problem. This can be done by integrating the differential equation dyldz = w(z) through the simple discret;ization,
Since
-
= 1/M, we have the convenient recursion relation
which can be used with the starting vdue I(@)= 0. Another convenient method for generating one- (or hulti-) dimensional random variables i s von Neurnann rejection, whose geometrical basis ia illustrated in Figure 8.1. Suppose we are interested in generading a: between O and 1 with distribution W(%) and let cul(z) be a positive function such that W'($) > W ( $ ) over the region of integration. Note that this
307
means that the definite integral of W' is greater than 1. A convenient, but not always useful, choice for w f is any constant greater than the maximum value of W in the region of integration. If we generate points in two dimensions that uniformly fill the area under the curve W'(%) and then "accept" for use only those points that are under zu(z), then the accepted points will be distributed according to W. Practically, what is done is to chohse two random variables, gi and q, the former distributed proportional to W' and the latter distributed uniformly between O and 1. The value zi is then wcepted if q is less than the ratio w ( z i ) / w f ( s i )if; a point is rejected, we simply go on and generate another pair of and ? , I . This technique is dearly @%dentonly if zuf is close to W throughout the entire range of integration; otherwise, much time is wasted rejecting useless points. Exercise 8.3 Use von Neumann rejection to sample points in the and evaluate the inteinterval [Q,l] distributed as w ( z ) = $(l- !p2) gral (8.4) and its uncert$nty with these points. Compare the efficiency af your cdculation far vmious choices af W'.
The Gaussian (or normal) distribution with zero mean and unit variance, w(g) = (2r)-'/2e-"'/2 , plays a central role in proobablliity thwry and so is often needed in Monte Carlo cdcdatims* It, is possible, but not too efficient, to generate this distribution by inverling its incomplete integrd using pofynonaial approximations to the emor function, A more ""clever" method is based an the central L i ~ theorem, t which states th& the sum of a large number oE uniformly distributed r a d m numbers will appraach a Garnssian distribution. Since the mem and varianm of the unifom distribution on the disinterval [0,1] are 1/2 and 1/12, respectively, the sum of 12 unifo* tributed numbers will have a mean value of 6 and a v%sianee of 1 and will very dosely approximate a Gaussian distribution. Hence, the following FORTRAN subroutine returns a Gaussian random variable, GAUSS, with zero mean md unit w i w c e : C chafle, %or G apubrowt;ine to gsllnsraeer the n o m a l y distrih%ed amber GAUSS SUBBQWIEBIIIST(GAUSS1
xaJmem s m DATA SEEf)/39249287/
c
8.8 Generating mndom variable&with a specified distribution
Exercise 8.4 By histagramming a large number of the values of GAUSS produced by the subroutine above, convince yourself that their distribution is very close to normat. Can you derive a quantitative esti-
m
mate of the extent to which this di~txibutiandeviates from a Gaussian? Compare with the results of summing 6 or 24 uniformly distributed random numbers. (Note that these latter sums have means of 3 and 12 and varimces of and 2, respectively.)
4
Another efficient method for @witting normally distributed vmiables is to consider a Gaussian distribution in two dimensions (gI, zz), for which the number of points in a diRerentiail area is pmportional to Zn. terns of the usual polar coordinates
the distribution is
e - * P ~ dr d@,
or, if u = ) r a y the distribution is Hence, if we generate u between 0 and m with an exponential distribution and B uniformly between O and 2 1 then ~ ~ the corresponding values of 21
= (2u)'i2 COS B , 1 2 = ( 2 ~ ) ' /gin ~ B
will be distributed normally. Thus, the following FORTRAN subroutine returns two normdy distributed random variables, GAUSS1 m d GAUSS2:
209
Monte Carlo Methda
210
DATA 53B/39249181/ ~~13.24159261
C
TWoU=-2.*LoG(i.-R4E(SEED)> RADIUS=SQBT(T~~~OUI
TWETA=2*PX*RAI(SEEf)) GAUSSI=RADIUS*CflS (T13:ETA)
GAUSS2=RUXUS*SIl(mETA) RETUM
END
To generate a Gaussian distribution with mem 3 and variance c2,
we need only take the vdues pnerated by this subroutine, mdtiply them by a,and then increment them by g.
8.3 The algorithm of Metropolis et al. Prltbugh the methods we have discussed above for generating rmdom numbers according to a specified distribution can be very efficient, it is cliEcdt ar impossiMe to generalize them to s m p l e a complicated weight function in many dimeagions, and so can &ernative approach is required. One vary generd way to produce random vasiables tvith a given probability distribution of arbitrary form is known as the Metsopofis, Rosenbluth, Rosenbluth, Teller, and Teller algorithm [Me53]. As it requires only the ability to calculate!the weight function for a givcln vdue of the integration vwiablest the allgorithm has been appliecl widely in statisticall rnechanies problems, where the weight &netion of the eanoaicd ensemble can be a very complicated function of the coordinates of the system [see Eq. (8.l)] and sa carrot be sampled conveniently by ather methods, Howevm, it is not without its drawbacks, Although the dgorithm of Metrc)pOXi~et laE, can be ixapiemen~edin a variety d ways, we begin by describing one simple realization. Suppose that we want to generate a set of points in a (possibly multi-dimensional) space of variables X distributed with probability density w(X). The Metropolis algorithm generates a sequence of points, X@,XI,. .. , as those visited successivefy by a randam w&er moving through X space; as the wdk become8 longer asld longer, the points it connects a p p r o ~ m a t e more closerly the desired Bistribution. The rules by whieh the randam wdk proceeds through canfiguratlm space are as follows. Suppose that the wdker i s at a pojnt X, in the
8.8 The algorithm of Metropofs'set d.
sequence. This new uniform about X,. the ratio
To $emrate X,+1, it makes a trial step to a new paint X,. point caa be chosen in any convenient manner, for example at random within a multi-dimensional cube of small side 6 This triaf step is then "aecepted" or @reJlectednaccording to
If r is larger than one, then the step is aecepted (i.e., we put X,+1 = Xt), while if r is less than ane, the step is wcegted with probability r . This latter is conveniently accomplished by comparing r with a random number q uniformly distributed in the interval [0,1] and accepting the step if q < r If the trial step is not accepted, then it is rejected, and we put X,+x = X,. This generates X,+x, and we may then proceed to generate Xnf by the same process, making a trial step from X,+1. Any arbitrary point, Xo, can be used as the starting point for the random walk. The following 8ubrout;ine illustrates the app1ieat;ion of the Metropolis dgarithm to s a n k a two-dimensioad distribution in the vmiables X1 m d X2. Each edE do the subroutine executes mother step aif the raadam wdk and retarns the n a t vduw of X1 and X2; the m ~ progrm n mast irritidze these variables, as well as set the vdue of DELTA and define the distribution WEIGHT(XI,X2).
.
C chap8g.f"~~ C subroatlne to %&B
i n Ihs Watropolis algorith SWROWZIE MEmOF(Xl,X2,UEIGRT,D&T&) EXTEWAL WEIGBT a slap
ICITEGER SEED
DATA SEm/39249%87/ !%as a trial stevp in squme aben% [X1,X2) XIT==XI+DELTA+(2*RAI(SaD)-J,) X2T=X2+DaTA* (2*RAB (S-)1) RATEO=WIEXGmf XIT ,X22")/GifFSTGHT(X%, X2) SF (RATLO GT. RAB(SEED)) THEE !s2ep accctpled
.
Xi=X1T X2=X2T
EEB LF"
REwm EHD
This code cauld be made more efficient by saving the weight function at the current point of the random walk, so that it need not, be computed
21l
212
8. Monte Carlo Methds
again when deciding whether or not to xcept the trial step; the e d u a t i o n of W is often the most time-consuaaing part of a Monte Cm10 cdcdation. using the Metropolis algofithm. To prove thatr the dgorithm described above dow indeed generate a sequence of points distributed according to W, let us consider a large number of wdkers starting from diRerent initid points and moving independently through X space. If N , ( X ) is the density of these walkers at X &er rs steps, t b a the ne%number of wdkers moving from paint X to point Y in the next step is
Here, P ( X -r Y) is the probability that a walker will make a transition to Y if it is at X, This equation shows that there is equi2ibrium (no net change in population) when
and that changes in N ( X ) when the system is not in equilibrium tend to drive it toward equilibrium (i.e., A N ( X ) is positive if there are @too many" walkers at X, or if N,(X)/N,(Y) is greater than its equilibrium value). Hence it is plausible (and can be proved) that, after a lmge number of steps, the population of the wdkers will settle dawn to its equiEbrirxm distribution, l&, It rennalns to show that the transition probabilities of the MetropoEs aigorithm lead to an equilibrium distribution of walkers N , ( X ) u ( X ) . The probability of maEng a, s$ep f r m X to Y is;
where T is the probability of making a trial step from X to Y and A is the probability of accepting that step. If Y can be reached from X in a single step (i.e., if it is within a cube of side 6 centered about X), then
T ( X + Y) = T(Y -r X ) , so that the equilibrium distribution of the Metropolis random walkers satisfies
If w ( X ) > w(Y), then A(Y 4 X) = 1 and
while if w (X) < w (Y) then
and A(X -r Y )= 1. Hence, in either case, the equilibrium population of Metropofis walkers satisfies
so that; the wdkers axe isrdwd distributed with the correct distribution. Note that although we made the discussion concrete by choosing Xt in the neighborhood of X,, we can use any transition and acceptance mles that; satisfy
Indeed, one limiting choice is T ( X -r Y )= w(Y), independent of X, and A = 1. This is the most efficient choice, as no trial steps me '%.wtzstedn through rejection. Hawewer, tkis doice is sonnewhat impractical, because if we knew haw to sample W to take the trial step, we wouldn't wed to use the dgodthm. to be@n with. An obvious que~tioni s "If trial steps are to be t&n within a nei&borhood of X,, bow do W choose the step size, S?" To answer this, suppose that X, is at a maximum of W, the most likely place for it to be. If 6 is large, then w(Xt) will likely be very mu& smaller than w(X,) and most t r i d steps will be rejected, Leading to an ineficient s a p l i n g of W . E 6 is very s m d , most trial steps will be accepted, bnt the rmdom w d h r will never move very fm, and so &so lead to a poor smpfing of the distribntion. A good r d e of thumb i s that the size af the trial &ep shodd be chosen so th& about half of the t ~ gteps d me accepted. One bme of applying the Metropolis dgorithm. to sampfe a distribution is that the points that m&e up the random walk, Xo,XI , .. are not independent of m mother, simply from the way in wEch they were is likely to be in the n4ghborhood of Xpbe T~us, generated; fhat is, while the points might be cfistributed properly W the walk becomes very long, they are aot statidicay independed of one another, and some w e
.
214
8,Monte Carlo Methd8
must be taken in using them to calculate integrals. For example, if we cdculate w ( X ) f(X) I= S S w(X) by averaging the vdues of over the pojnts of the raadom wdk, the usual estimate of the variance, Eq. (8.3), is invalid because the f ( X i ) are not statistically independent. This can be quantified by cdculating the auto-corrdation. function
Here, (
...) indicates average over the random walk; e.g.,
Of course, C(O) = 1, but the non-vanishing of C for k
+ 0 means that the
f 's me not independent. Whal can be done in practiw is ta compute the i n t e p d and its variance using psints dong the raxrdam wdk separated by a fixed intervd, the intervd being chosen so that there is eRecliveiy no cofrelation between the points used, Aa appropriate sampliag intervd the vdue of k: for which C becomes smaa;l (say can be estimated O.I)* Another issue in. applying tbe Metrapofis algorithm is where to stmt the random walk; i.e., what to t h e for X @ ,In prindple, w y location is suitable and the rehs~ft~ wiU be independent of tEs choice, m tbe wdker will ""term&zc?" after some number of steps. In practice, an appropriate starting point i s a probable one, whefe w i s large. Some number of" themalization steps then can be taken before actual sampling be@ns to remove m y depeadence on the starting point. E x e r c i ~8.5 Use the dgorithm of Metropolis et al. to sample the norrmd ddistribntion. in one dimension. For various erid step sizes, study the acceptance ratio (fraction of trial stepa accepted), the correlation function (and hence the appropriate sampling frequency), and the overall computational efficiency, Use the randam vasiables you generate to
R
and estimate the nncestainty in youf ansarer. Study how your resdts depend upon where the random wdker is started afzd on how many thermalization steps you take before beginning the sampling. Compare the efficiency of tbe Metropolis algorithm with that. of a cdcuhtim that uses one of the methads discussed in Section 8.2 to geaerate the narxnd distribution. directly, 8.4 The Ising model in two dimensions Models in which the degrees of freedom reside on a lattice and interact locally arise in several areas of condensed matter physics and field theory. The simplest of these is the Ising model [Hu63], which can be taken as ;z crude description of a magnetic materid or a binary d o y , h this example, we will use Monte Carlo methods to calculate the thermodynamic properties of t;his model, Xf we spe& in the magnetic laaguage, the rsing model consists of a set of spin degrees of freedom interacting with each other and with an external mqnetic field. These might represent the magnetic xnonzents of the &oms in a solid, We will consider in particular a model in two spatial dimensiws, where the spin mriablee are locat;ed on the sites of an N, x Ny square lattice. The spins can therefore be labeled as Sij, where i ,j are the indices for the two ~ipittiill,directions, or as S,, where a is a generic site label. Each of thme spin variables can be either "up" (S, = f l) or "down7' (S, = - 1). This mimics the spin-1/2 situation, although note that we take the spins to be c l ~ s i c degrees d of freedom and do not impose the angular momentum earnmutat ion rules characteristic of a quantum description. (Doing so would correspond t o the Heisenberg model.) The Bmiftoaian. for the system is conventionalfy written as
Here, the notation (up) means that the sum is over nearest-neighbor pairs of spins; these interact with a strength J (see Figure 8.2). Thus, the spin at site i j interacts with the spins at i f U and i j f 1. (We %same periodic boundary conditions on the lattice, so that, far example, the l m r neighbars of the spins with i == IV, are thaw with i = 1 m d the left-hand neighborn of those with j = 1 are those with j = Ng; the lattice therefore has the topology of a torus.) When J is positive, the energy is lower if a spin is in the same direction as its neighbors (ferromqnetism), while when J is negative, a spin wifl tend to be mti-aligned with its
226
8. 2Monl"e Carlo Me?&&&
* Figure 8.2 Schematic illu;stCratianof the tww&mea~ionaJ. hing mad$,
neighbors (anti-ferromagnetism). The term involving B represents the iaterwtion of the spins with an extern& magnetic field, which tends to align aU. spins in the s m e dimc$ian. We will be interested in the therxnodynmics of this system. In this case, it is convedent da measure the coupling energies J md B in units of the temperature, so that heating the system corresponds to decreasing these couplings. Configurations of the system axe spedfied by gjving the values of all N, x N, S N, spin variables md the weighting of any one of the 2N8 spin configurations, S, in the canonical ensemble i s
where the partition function is
8.4 The fsing model in two dimensions
c quantities we will be intertlsted are the nzagnetizal;ion
the susceptibility
the energy
E=
E~(s)H(s) V
(8.21~)
S
and the specific heat %t constant field,
In the limit of an infinitely large lattice (N,,, -+ m), it is possible to sdve the Ising modd exactly; discussions of the solution, origindy due to Onsager, can be found in [Hu63] and [Mc73]. The expressions are sinnpled at B == 0, In this limit, the - e r g is dven by
and the specific heat is
wMfe the mapetization i s given by
for J
r Jc m d vanishes for J < JC.In these expressions,
the complete elliptic integrals of the first and second kinds are
237
228
8,Monte Cark Methods
= 0.4406868 is the critical value of J for which K = 1, where Kl has a logilrithmie singdwity, Thus, a& thermodynmic Tune tians are singular at this caupli~g,strondy sugesting a phase transition. Tbis is confirmed by the behavior of the mametization, which vanishes below the critic4 coupling (or above the critical temperature), and can take on one of two equal and opposite values above this coupling. A numericat solution of the fsiag model is usefd both W an illustration of the techniques we have been discufjsingand because it can be generalized readily to more complicated Hamiltonians [Fo63]. Because of the la-rgt, number of terms invoked, a direct evaluation of the sums in Eqs. (8.21) i s out of the question. (For even a modest 16 x 16 lattice, ~ ~ configurations.) Hence, it is most eEthere are 2256M 1 0 different cient to generate spin configurations S with probability w(S) using the Metropous algorithm and then, to average the required observables over these configurat;ims. Z'o impjeraent the Metropolis dgorithm, we could make our %ridstep from S to St by chan@ng a l l of the spins randomly. This would, howenr, brine; us to a canfiguration very &Rerent from S, and so there vvould be a, high probability of rejection. It is therefore better ta take smdler steps, and so W consider tnid confipratioas that differ from the previous one only by the fiipping af one sjpin. This is done by sweepiing systemalIcally through the l&tic@and considering whether or not to flip each spin, one at a t h e . Hence, we emsider two configurations, S and S t , differing only by the Aipping of one spin, S, E Sa. Acceptance of this trid s t q depends upon the ratio of the w&ght functions, z = em2', and J,
Spedficdy, if r > 1 or if r < 1 but larger than a nniformiy distributed random number bet;ween O and 1, then the spin S, is flipped; othervvise, it is not. From (8.18), it is dear that only terns involving Sij will contribute to F , so that after some algebra, W have Here, f is the sum of the four spins neighboring the one being flipped. Because f can take on only 5 different values, 0,352, f 4, only 10 different values of r can ever arise (there are two possible values of S,); these can be convenient?y calculated and stored in a table before the calculation begins so that exponentials need not be calculated repeatedly. Note that if we had used trial configurations that involved flipping several spins, the cdculation of r would have been much more cormplic;zted.
VIII. Quantum Monte Cads for the H2 molecub
The program for Example 8, whose source listing is given in Appendix B and in the file EXMPL8.FOR, performs a Monte Carlo simulation of the Ising model using the algorithm just described. An initially random configuration of spins is used to start the Metropolis random walk and the lattice is s h m d t e r eltery WREQ @weep,if requested. Thermalization sweeps (no calculation of the observables) are allowed for; these permit the random w d k to "settle d o w " before abservables are aecumdated, Values of the energy, mametization, susceptibility; and speeigc heat per spin are displayed as the calculation proceeds, as is the fraction of the trial steps mcepted, One hatare of this p r a g r a requires further explmatian. This is a simple technique used to monitor the sweep-tosweep correlations in the observables inherent in the Metropolis algorithm. The basic obsenrables (energy and magnetization) are computed every )IFRW sweeps. These v&ues are then binned into L"groupswwith HSIZE members. For e ~ goup, h the means and standard deviations of the e n e r o and m~gaetiz&ionme ca-lcdated, As more groups are generaled, their means are combined into a p n d aver%@, One wa;v 80 campute the uncert&nty in this grand average is to treat the grwp means as independent measurments and to use Eq. (8.3). Alternatively, the uncertainty can be obtained by averaging zGhe standard deviatians of the goups in quadrature, If the s a p l i n g frequency is sufficiently large, these two estimates wiU agree. However, if the sampfing frequency is toa snnafl and there are significant correlations in the suecessiw measurements, the vdues witbin each group will be too narrowly distributed, and the second estimate of the uncertainty win be considerably smdler t h m the first. These two estimates of the uncertainty for the grand average of the energy and magnetization per spin are therefore displayed. Note that this technique is not so easily implemented for the specific heat and susceptibility, as they are themselves Auctuations in the energy and magnetization [Eqs. (8.21b,d)], and so only the uncertainties in their grand averages computed by the first method are displayed, The following exercises will be useful in better understanding this example: Exercise 8.6 When J = 0, the Hamiltonian (8.18) reduces to that for independent spins in an external magnetic field, a problem soluble by elementary means. For this ease, obtain analytical expressions for the thermodynamic observables and verify that these are reproduced by the program.
S
219
220
8. Monte earls Meth&
Exercise 8.7 Use Eqs. (8.22) to calculate and gfaph the e x x t energy, spedfic heat, m d mqnetization per spin Ior an infinite latticc? at B ==; 0 and far J running from O to 08.
m
Exercise 8.8 Modify the code to compute the sweep-to-sweep correlation functions for the energy and the magnetization using (8.17). Using runs far a 16 X 16 lattice far B == Q a d for severd d u e s af 9 between 0.1 and 0.6, estimate the proper sampling frequency at each coustrength. S h m that the two estimates of the ancert&nties in the energy and magnetization wewhen a proper sampling frequency is used and that they disagree when the samples are taken too often (a reasonable group size is 10). Also show that the sweep-$*sweep correlations become stronger when the system is close to the phase transition (critical slowing down).
m
Exereim 8.9 Run the code to obtdn rwdds for 8 X 8, l6 X 16, and 32 x 32 lattices at B = O for a sequence of ferromagnetic couplings from 0.1 to 0.6; pay p&ieulw attention to the region new the expected phwe trmsition. Compare youf results with the exact behavim of the infinite lattice and show that the finite size smooths out the singularitim in the c obsermbles. Notice that the size of the mqnetic dom&n~i\ becomes very 1mge new the critical coupling.
m
Urn %hecode to explore the themodynmics of the model for finite B and for mti-ferromagnetic couplings ( J < 0). Also consider simdations of a model in which a given spin Sij interacts with its neighbors ferromagnetically and with its diagonal neighbars SiWlj-l,
rr Execiee 8,20
Exercise @.l2 The ""heat bath" adgarithan is an dtemative to the Metropolis dgori%hmfor saxnpliq the citnodcd ensemble. h this method, the particular spin being considered is set to -1 with probability l/(l+ g ) and to f 1with probability #/(l + g ) , where g = exp[2(Jf B)]. This can be interpreted as plitcina; the spin in equiiPibriurn with a heat bath at the s p e d e d te:mpera;ture. Verify that this d p i t h m comsponda to putting A f and t&ng
m
+
-
T(S -+ S') = w(sl) w(S') w ( S ) in Eq. (8.16) and so leads to a correct sampling of spin configurations. Modify the code to use the heat-bath dgorithm and compare its efficiency with that of the convention& Metropolis dgorithm.
+
VJlJ, Quantum Hontt? Carlo for the If2 molecule
Project VIII: Quantum Molite Carlo for the H2 molecule In this project, we will consider Monte Carlo methods that can be used to edculate the ezaeb p~opertiesof the graund states of qua~ltunrmanybody systems. These methods are based on the formal similarity between the Schmedinger equation in imaginary time afld a multi-dinzeasional diffusion equation (recall Section 7.4). Since the latter can be handled by Monte Carlo methods (ordinary diffusion arises as the result of many random microscopic collisions of the diffusing partides), these same techniques can also be applied to the Schroedinger equation. However, the Monte Carlo method i~ no panacea: it can make exact sta;tements about only the ground state energy, it requires an already well-chosen vafiationd wave function for the ground state, and it is generally intractable for f e r ~ o nsystems. Hawever, them have been successful appfications of these techniques to liquid 4 ~ [Ka81], e the electron gas [Ce80], small molecules [Re82],and lattice gauge theories [Ch84]. More det d e d diseussions can be found in these references, as well as in [Ce'TS], which contains a good e n e r d overview. VIII.1 Statement of the problem The specific problem we will treat is the sdmcture of the H2 molecule: two protoas baund by two electrons. This will be done within the context of the =curate Born-Oppenheimer approximation, which is based on the notion that the heavy protons move slowly compared to the much li&ter electrons. The potential governing the protons' motion at a separation S, U(S),is then the sum of the inter-proton electrostatic repulsion and the eigenvalue, &(S), of the two-electron Schroedinger equation:
The electronic eigenvdue is determined by the Schroedinger equation Here, the electronic wave function, !Po, is a function of the space coordinates of the two electrons, r1,2 and depends parametricdy upon the inter-proton separat;im. If we are interested in the electron;ic gound stitte of the molecule and are willing to neglect small interactions involving the eleedro~shspin,then we e m =same that the electrons are in m mtisymmetric spin-singlef;state; the PauE principle then =quires tfta$ !Po be symmetric under the interchange of rl and r2. Thus, even though the electrons are two femims, the spakid equation sart;i&ed by their wave
221
222
8*lMorsle Caris Methods
Figure TJ1l;I.l Coordhate~used in de~ribingthe E2 maEecuEe,
firnetion is andogous to that for two bosans; the ground state wave function !Po will therefore have no nodes, md can be chosen to be positive everywhere. The electron kinetic energy appearing in (VIn.2) is
where m is the efeetron mass, while the potentid V involves the attraction
of the e l w t m s by each nudeas and the inter-.electron repalsion:
If we place the protons at locations rt f S on the z-axis, then the distance betwen eleetmn I tznd the left or right proton is 1
and the dktances betwwn electron 2 and the protons, r ~ haxe , ~$jven * (See Figure VIII.1.) % sirnilwly, The interelectmn distmce is ~ 1 = Our goal in this project is therefore to solve the six-dimensional partial differential eigenvdue equation (VIII.2) for the lowest eigenvalue E. at each S, and so trace out the potential U ( S ) via Eq. (VIII.1). This potential should look much like the 6-12 or Morse potential8 studied in Chapter 1; the depth and location of the minimum and the curvature of U &out this minimum are related to observable properties of the NIz spectrum. We will also be able to calculate the exact ground state energies of two-electron atoms, Eo(S = 0). (These same systems were treated in the Hastree-Fock apprasmation in Projject ID.)
VIII. Quantum Monte Carlo for the H2 molecule
WIf.2 Vargwtional Monte Carlo and the trial wave function We begin by discussing a variational Monte Carlo solution to the eigenvalue problem. If @(r)is any trial wave function (which we can choose to be real) not orthogond to the exact ground state qo,then an upper bound to the electronic eigenvalue is the variational energy
where we have used r as a shorthmd notation far the six coordinates of the problem, rl,z, and have written (VIIIAb) in a somewhat unconventional way. Note that this last equation can be interpreted as giving the variation4 energy as the average of a 'local energy",
over all of the six-dimensional F-space with weighting w(r) m e2(r). Hence, to evdnale the vaGalioad energy by a Monte Caslo quadrature;, all we need do is generate configurations (values of r l , ~ distributed ) according to (by the Metropolis algorithm, for example), and then average E wer these configurations. It should be clem thaL this method can be generalized readily to spterns invofving a l m p r number af coordinates. The choice of QF is crnstr.iZined by the requirements that it be ~imple enough to allow a convenient evaluation of e2 and E , yet dso be a good approximation to tht? true gound state, go. hdeed, if we are fortunate enough to choose a @ that is the exact solution, then E is independent of r, so that; the, Monte Carlo quadratare gives the exact e w r a with zem variance. Thns, not only will the v;triadiond baand become better as Q[, better approdmates P,but the vasimee in tlxe Monte Carlo quadra;t;ure will become smauer. The trid wave function should &so be symnaetdc under the interchange of the t w electrons' sspatid coordin&es, but it need not be normatized properly, as the normalization cancels in evaluating (VIII.4). One plausible choice far the drid wave functian ie a correlated product of molecdar orbitds:
223
224
8. M~rateCarlo Me&
Here, the first two factors are an independent-particle wave function placing each electron in a molecular orbital in which it is shared equally between the two protons. A simple choice for the molecular orbital is the symmetric linear combination of atomic orbitals centered about each proton, (V I I I ,6b) (b(ri)= empi&/" + e - p i ~ / a with the variationd parmeter a to be determined below. The find factor in the trid wave function, f , =presses the correlation between the t w electrons due to their Coulomb repulsion. That is, we expect f to be smd when rl2 is smdl and to approach a large constant value as the electrons become well separated. A. convenient and reasonabk choice is
where a and p asle additional positive variaLional parmehrs. Note that ,8 controls the distace over which the trid wave function @healsR$0 its uncofrelfated vdue as the two electrons mpwate, The s i n d ~ i t yof the Coulomb pstentid at short distances places addition& constraints on the trial wave function. ff one of the electrons (say 1) approwhes one of the nudei (say the left one) while the other electron remains fixed, then the potential t e r n in c becomes large ands negative, since T ~ Lbecomes smdl. This must be cancelled by a corresponding positive divergence! in the kinetic energy term if we are to keep E smooth a d have a smax variance ia the Monte Carlo quadratare. Thus, ~ 0, which means the trial wave function shoald have a C k u s p * b rt l = that the molecnlar orbit& shotlfd satisfy e2
V ~ $ ( ~IL G~ = finite tefnrs.
(VIIl.7)
Similar conditions must dso be sat;isfied whenever any one of the distmces va~lishe~. Using (VIII.6) and a bit of algebra, it is easy FZR,L, or to see that these constraints imply that a satisfies the transeendentd equation
and that a = 2ao, where a0 = h2/mez is the Bohr radius. Thus, P is the only variational parameter at our disposal. Note that these Coulomb cusp conditions would not have been as important if we were to use some other quadrature method to evaluate the variational energv, as then each
VIII* QetanGttm Mante Carla for the
H2 molecule
of the divergences in E would be cancelled by a geometrical rZ weighting in the associaLIed dis;tanee. With the trial wave fundion specified by Eqs. (VZ11.6), explicit expressions can be worked out for ~ ( rin) terms of the values and derivatives Bf: cfZ and f . Note that; this form of the trid function is not appropriate for very large proton separations, as it contains a finite amplitude to find the two eleetrans close to the same proton.
VIII.3 Monte Carlo evaluation of the exact energy We now turn to a hrlo~teCwla method for evduatiag the egaet electronic eigenvalug, [email protected] is baged upon evolution of the imaginary-time Schroedinger equation to refine the trial wave function to the exact ground state. In particular, the latter can be obtained by applying the operator exp(-at/&) to the trial state @ and considering the long-time limit t -+ W. (See the discussion concerning eigenvdues of elliptic operators given in Section 7.4 for further details.) Thus, we define
where E,(tf) is an as-yet-undetermined c-number function. Note that as long as (Po/@) 0, @(t)wig approach the (un-normalized) exact ground state !Ifoas t becomes large. Our method (Path IRtegsal Monte Carlo) is equivalent to evaluating the path integral representation of (VI1I.S) numericdy. An alternative method (Green's Function Monte Carlo, [Ce79]) would be to filter with the inverse of the skif'ted Hamiltonian, instead of the exponential in (VIII.9). To compute the exact ground state energy &, we consider a slight generalization of the variational energy (VIII.4) using the hermitidty of
+
It should be clear that E(t = 0) = E,, the variational energy associated with m, that E($ --. m) = Eo, and that E ( t ) is independent of the function E,(tt). Equatian (VIIZ.10) expresses the exact enerlir;l)"in a form suitable for Monte Carlo evaluation. To see this, we define G(r, t ) = @(r)@(r, t), so that (VIXL. 10) becames
225
236
8,Monte CarloMethods
The exact energy E ( t ) is thus the average of the local energy E over the distribution G(r, t). (Note that for the problem we are considering, G is positive definite since neither @ nor has any nodes.) A Monte Carlo evduation of E therefore mquires an "ensemble" of N configura tions (rl ,.. ,rN) distributed according to G(r, l ) , through which E($) can be estimated by
.
, N
with an expression for the variance in analogy with (8.3). Note that if @(r)is in fact the egaet ground state go,then ~ ( r = ) E@,independent of
r, and so E($)= E. with zero variance. Of course, the expressions above are of no practical use withoat a way to generate the ensemble of configurations. At t = 0, G(r, t ) = ao th& a method like that of Metropolis et al. can be used to generate the initial ensemble, typiea3ly having N ss: 30 members, To evolve the ensemble in tim% note that since dlJL!
a--at = (E, - H ) @ ,
G satisfies the evolutiorr equation
We have used here an obviaus notation far the spatid derivatives, Equation (VIII.13b) em be interpreted as a diffusion equation for G, with a drift function
It shows that the kinetic energy acts to diffuse G, that D tends to keep G confined to regions where i s large, and that the Usource'' increases G where e(r) is smallest. The evoftttiorr of G over a short time from t to t At can be repreaented thmugh order At by the integrd ktzrncll
+
W1II. Quantum Monte Car20 for the
molecule
whem P(,, r'; At) = exp{ -[ ~ ( r-)~ , ( t ) ] ~ t / h . )
This kernel (which is positive definite) can be interpreted as the conditional probability for a configuration to evolve from r' at time t to r at time At. This probability contains a factor associated with the kinetic energy, whieh, acts to diffuse the system about r' through a normalized Gaussian probability distribution wit h variance &At/ m and mean DA2. The other fxtor in B is associated with the locd energy, which acts to keep the system in regions of space where e is most negative by enhancing the probability for jumps to occur to such locations. The quantum mechanical structure of the exact ground state is thug determined by the balazlce between these t~vocompeting tendmcies, The algorithm for evolving the ensemble should now be evident. A configuration at time 1 at the point r' generates a contribution to G(r, t f At) equd to P(r, r'; At). This is realized by placing in the new ensemble a eonfipration, r chosen according to the distribution
+
and then weieting the importance of this configuration by
One way of effecting this weighting in prwtiec? is to replicate or delete the configuration in the new ensemble with probabilities given by this latter function. In this case, N fluctuates from time step to time gtep but can be held roughly constant by continuous adjustment of E,. Indeed, to keep drG(r, t ) (and hence N ) constant, E,(t) should be equal to E(t), so that E, also furnishes an estimate of E(t). An alternative way of effecting the weighting is to assign an importance (i.e., a weight Wi) to each configuration in the ensemble when aver&ng E. to compute the energy. Th& is, the aummand in (VIII.12) is modified to W i ~ ( r iAt ) . each time step, Wi for each c0nfiguril;tion is multiplied by the first f w b r in (VII1.f 61, with E, readjusted to keep average weight of ewb configuration in the easemMe equd to 1, This latter method requires less bookkeeping than does that of rqlicating and deleting, but can be heficient, as a ~0nfigurat;ion thag lzappents to acquire a very small weight is stiU. followed during the evolution,
227
228
8. Monte Carlo Hethdg
h summay, the method is aa fonows. The system is described by an ensemble of coniipratians, each having a relative might in desmibing the propertie8 of the system and initiaUy distributed in r aecarding to the trial function l@(r) The overall efficiency of the method is clhse?y related to the akccuracy af this trial function. To evolve the ensemble in, time, each member is moved in r with a shifted Gaussian probabgity function [the second factor in Eq. (VIII.IG)] and its weight is multiplied by the first fwtor in Eq. (VlII.15). The quantity En(t),wU& is ad;jnsted after each time step to keep the average vveight of the ensemble equd to 1, provides an estimate of the energy, as does the ateighted aver%@af ~ ( rover ) the ensemble at any time. Furthermore, once the total evolution time is sufficiently large to filter the trial wave function, continued evolution generates independent ensembles distributed according to the exact ground state wave function, which allows the statistics to be improved to any required accuracy. Note that since the e n s e d l e move8 through c d g u m t i a n space ed by At, which must be sufficiently s m d so that Eqs. (VIII.I5,16) are accurate, the estimates of the energy at successive time steps will not be statistically independent. Therefore, in forming averages and computing variances, care must be taken to use ensembles only at intervals of t sufficiently large that the values are uncorrelated. SuGh i n t e r d s are cenveniently d e t e r ~ n e dby e x a d ~ n g the ; autocomeldion fumtions of the estimate. Alternatively, one can use the method af binning the values into groups, as discussed in connection wit h the Ising cdcalation in. Section 8.4, It shodd dso be noted that the finite time step requires that calculations be done for several different values of At and the results extrapdaed to the At = O li&t. A useful way to set a scale for At i s to note that the average step the Gaussian distribution ~ ; must be s m d compared to the in (VIII.16) is roughly ( h ~ t / m ) ' /this length se&s in the wave function. Expectation values of observables other than the energy in the exact ground state are not simply given by this method. To see this, consider the gound state expectation value of some observable A that does not commute with the H
VlIl. Quantum Mmte Carlo for the H2 molecule
Evaluation of this integral requires an ensemble of configurations &S@ 1'. However, the diffusion process described above generates an ensemble astributed as G = g?@, wKch is not what is required, Although this ensemble can be used, through a rather complicated dgorithxn, to cdcdate ex& gfound st& expectation values, a good estimate can be had by using it directly to cdculate the first term in
the second term being evduated easily with an ensemble distributed Wcording to g2.Thus, this expression provides a way of perturbatively carrecting the expectation value in the trial state; some algebra shows that -- @, it is accurate to secand order in the emor in, the trial function,
VIII.4 Solving the problem The Monte C a l o methods described above can be applied to solve for the properties of the H2molecde throagh the faaowing sequence of steps. S h p I Verify that Eq. (VII1.8) and thechcsicecu = 2ao imply that the wave fnnction (VTT1.6) satl~fiesthe Coulomb cusp condition. Derive explicit analytical expressions for ~ ( r[Eq. ) (VIII.5)] and D(r) [Eq. (VIII.I.I)] for the wave function (VIII.6).
r
Step 2 Write a code that uses Moate Cm10 quadrature to cdculate the mriat;iond e m r g estimate associ%ted with the trial wave hnction (VIII.6). You will need subroutines to evaluate m2 and E for a given configuration. Sample Q' using the Metropolis algorithm. Study the mto-cornelation funceSon of E t a deternnine the minimum acceptable sampling frequency along the random walk, r
Step 3 For various inter-proton separations, S, find the parameter P that minimizes the electron eie;envdae and so determine the variatianal p o t a t i d for the Mz molecule. Verify t h t the nnce;rtaint;iesin your results behave with P as expected. Your vdue at S = O can be compared with the variational results obtained in Project III using scaled hydrogenic and fttl.1.XIEartrw-Fack wave functions. Step 4 Verify the validity of Eqs. (VIII.15,16) by making a Taylor expansion of G(rt,t)about r and then doing the resulting Gaussian r' integrals. (You will also have to make the approximation D(rt) E;: D(r), which is accurate to O(ht).)
229
=
Sdep 5 Test the Path I n t e e d Monte Carlo scheme for finding the exact graund state enerw of a Eamiltonian an the simple situation of a particle in a one-dimeneion-ali hamonic-oscif2ator potentid. Write a p r o g r a that assumes a Gaussisur trial functian with an incorrect; width and verify that the time evolution refines the m e r w in the expected way. An ensemble of 20-30 members &odd be snseient;, hvestigate how the y & t y of your reslllts vmies with the error in the trid wave funclion and with the time step you use,
Step f3 Carrrrbine the progrms you wrote in Sttlrps 2 and 5 into one that d e t e r ~ n e sthe exact eigenvdue of the ground state elf the twoelectron prablem and so determine the exact Kz nildeculm potentid ad vaious separations. In particular, deterdne the location of the minimum in the paentiitl and coaapae with the empirical vdnes @wn in Section 1.4, Use the trid functions deterdned in Step 2 and verify that your exaet ener@es are always lower thaa the vasiatimd vdues. Also verify that your exact r e d t e are independent of the preciae choice of P and that they extrapolate srnootlrly as a fuflction of Bt. Determine the binding energy of the He &om by considering S = 0 and eompme urith the exact vdue given in the di8cus~ionof Project 111.
m
Appendix A
How to Use the Programs This appendix contains the information needed to execute the Computational Physics codes. To foEow the instructions below, you must be familia with your computer's operating system, FORTRAN compiler, linker, editor, and graphics package. If you are unfamiliar with any of these, consult your computer system documentation before proceeding. You may also find it useful to have a FORTRAN language reference (e.g., [Ko87]) handy.
A.1 Ixrstdf&iomz Before anything else can be done, you must install the codes by downloading them from diskette to your computer or transferring them over the Internet network. Network transfer is much quicker and free (see Appendix E for details), but requires software and network connections that; are not uxriversdy avdable. The other modes of distribution are fBM-PC or Macintcssh fomatted diskettes; m order farm for these is in the b x k of tEs book. For those users who purchase the disketta md astj glmning to run the codes on an IBM-PC as Mac the irhstallatim proseduse is simply $0 copy the codes into a directory on the hard drive. Mwever, if you are not planning to run. the codes on m IBM compatible or Mac, then downloadipg may not be simple. and will depend on the details of yaur hardwme. The general scheme i s to find a PC or MW connected via modem or net-urork to your machine, and then to use a file trmsfer p r o ~ r m(e.g., KERMIT) to trafzsfer the Computaliclnal Physics files. Yatr &ght even find it necegsary to go through. one or more intermediate machines to get to yaurs. If you are inexperienced with file transfer, consult a locd expert, Once you download the files on your machine, we suggest you back them up immediate& on media that caa be read directly by that machine.
232
A, How to &7ðe Progranas
A,% Fifes There me five categories af file8 included on the fimpzrtatio~aalPh~lsics diskette: t e e codes, common utilie programs, physics p r ~ p a m s data , aes, and indude files. These were written in xeordance with FORTRAN77 stmctmds (with two exceptions noted below) and therefore should run on my ma&ine with a FORTRAN-77 compiler. The Estings for the examples are in Appeadix B, the projects in Appendix C, and the conamon uf;ifity codes in Appendix D. 1) The text codes are the short codes that appear in the text. They are n m e d CHAPnx.FOR, where 6x1' indicatles, the &apter nuaaber, m d 'X' is a letter to digereatiate codes within the s m e chaplter. Due to l a d of space on tbe diskette, only the longer of these codes we induded; the others; cm be entered from yovr keyboard. These =quire no editing to m, with the exception of those in Chapter 8 wfiich requipe a random nunber generator that is non-standard FORTRAN-77, E your compibr does not provide one, use the function RAHH~S,wh_ichis in file T7TXL.I"OR. 2) The first five common utiiity FORTRAN codes are called by, and therefore must be Enked with, each of the physics p r q r m s , UTIL.FOR contains the routines for menuing, 110, file opening/dosing, etc. SETTJP.FOIR contdns xl'l the vadables a d routines that are hmdwwe and compiler dependent, e.g., sereen length m d terminal unit m m Ber. Uou may need to edit this file to get the motst eacient and attrmtive output. (See section A.3.) The three remaining utility codes are graphics files: GRAPHIT.EI1, GUPHIT,XIO, m d GRAPEIXT,BLK, which, provide the interface between the physics code and your grapKcs pacbge, These three files contajxl the same subroutines, but for digerent typeer of grapucs packages. You will need to link in only one of these. GRAPHIT-HI calls a high-level package, e.g., a paehage that can draw axes with one call; GRAPHXT.LO calls a low-level pwkage, e.g., a paekage that is only capable of drawing primitives such as lines and circles and so requires many c d s to draw the axes; and GRAPHIT.BLK contains empty subroutines for a non-existent package. This last file is included so that there are no unsatisfied calls at link time. If you want to prodam plots, see section A.5. The last utiliLy code, STRIE",FQR, strips all V'-deimited comments out of FORTRAN wdies. The '!' is not standwd but we have ased it for clear documentation. 3) The sixteen physics codes for the examples and projects are named EXMPLn.FQR md PEOJs,PQR, where 'n' indicates the chapter, With two exceptions, these do not require editing to run (see A.3).
A,$ Compilation 4) The three data files all have the .DAT extension and contain data to be read into EXMPL5.lFOR at; run time. They requim no editing. 5) The indude files contain common blocks and variable type declarations that must be included in the FORTUN codes to compile: them. (We have not conformed to the default typing supported by FORTRAN, e.g., not all variables starting with the letters 'I' through 'N' are integem). The file n m e extension indicate^ in which, codes the file mast be included, Those $hat have $he ALL a t e n ~ i a nmust be included in d the programs except STRIP.FOR and the text codes. They contain variables for graphics (GRFDAT.ALL and UISGRF.ALL), menuing (MENU.ALL), and I/O (IO.ALL). Those that have the extension En or Pn (where 'n' indicates the chapter) belong to a particular example or project. The file rime indicates the funetion of the wriables included in. the common block. The MAP files cont&n variable^ to map the menu items to the program parameters. There are only seven of these. The PARAM files contain all the parameters that are constant during one calculation. There are sixteen of these. The one exception to t h w n ng conventions is tBe file UISGRF.ALL. Thia file i~ onlg used with GEAPWIT.LO. Each include file is list& with the mast closdy relatd code: t h w with E h or Pa extensions we listed with the corresponding emmple ar praject in Appendix B or C, GEFDAT.ALL and 'EIISGRF".ALLme in Appendix Da4,MENU.ALL i s in Appendix D.3, a~ndIO.ALL is in Appendix D.2. All of these files are induded in the pmgrarxls by the compiler with the XICLWE statement, Tbis is the other non-stmdard stitt-emeat i~ the codes. We have used it both because rniuly compiler^ support it, and because it is a sfmificant aid in program development and maintenance,
A.3 Compilation To prepme the codes for compilation is a matter of simple (but possibly
tedious) editing. 1) First, if your FORTRAN compiler does not support the rrnuDB statement, you muse edit each d the physies and utility p r o g r a s ta inehde the common block files. (See the previous section for a description of these files.) Before doing so, heck your compiler manud to see if it provides this statement or one with a different name but serving the same purpose (e.g., USE). In some compilers, this command is treated as a FORTRAN statement, while in others, it is a compiler directive, if m& a statment with E your compiler's equivdent stateis provided, simply repIwe ~ ~ G L W ment. Note that the indude file nrtrnes muet be ezactlgl the same in the
233
234
A. Haw to U8e the Pmgmm;s program and in the directory, If your operating system is c a e sensitive (e.g., UNIX), the names must be in the same case as well. 2) The other FORTRAN-77 non-standard grammar in the codes is the '!!"comment; delimiter. If your compiler doea not xcept this &ar%cter, then you must compile, link, astd run the progrm STRLP to change all of the files (this includes utility codes, physics programs, and common blocks, but not data files). This program is itself completely st;andasd, but you must set TEm equd to the urrit number connected to your keybowd. STRIP will prompt yen for input and output file names, Wfim @ving names for the stripped versions of the indude Eles, remember that the name of these files mast match exactly that @wn in the grogram XHamE statement. Therefore, this process is easier (especially if your operating system does not allow version numbers) if you keep the stripped and unstripped versions of the code in BiRerent direetaries. A sample session on the VAX i s given below. Note that the '9' is the VAX/VMS prompt, the unstfipped files are in the directory old: the stripped versioas are placed in directory new:, abnd the words in brackets [ ] are comments, not to be typed in. Cco~pi Ja STEXP. FOR] f 3 M STBIP.QEIJI f e x e ~ u ~SmIP. e EXE] [STRIP prampts f o r inpatl ENTER MAME QF FOBmAM BMGRAN old:ampZf,for [user input] [STRfP prempts far outpn%l ENTEB IRHE OF MEW FILE nsa:empll,ior [user h w t 3 fSTlkIP proafpt3 DO YOU UXSB TO STAIIZAWIZE ABOTHER F I U ? $ foreran strip.for $ l i n k strip.obj $ x m strip,sxa
EBTEE lAME OF FOEaAW PWGRPM
faso
~n.. L]
neru:pwm.si DO YOU WISH TO STAIOIARI)TZE ABOTtfER FfLE? fY3
3) The next step is to edit the subroutine SENP in the file SETUP.FOR. Instructions are given in that file. You must edit in constant values for variables that control the I/O. For example, you will need to know how many lines there are on your terminal (usually 24), unit numbers for I/O to the screen (these are 5 and 6 on a VAX), unit numbers for output files, and your own preference for default output (e.g., will you usually want graphics sent to the terminal?)
4) This last step is optional, and involves the three other routines in SETUP,FQR that are also hardware dependent, These rautines come H, and EBB. with dl the Iines commented out, e x c q t S W W W S b f E , Subroutine CLIEhR clears the scrmn by sending e s c q e characteris to the terminal. The appropriate sequence for your terminal is located somewhere in the terminal manual-probably in one of the appendices. This routine simply keeps the screen from looking too cluttered; it is not essentid. Code far VT200, Tektronix 4010, and PST screens is provided and can be used as a template for other screens. The last two routines (onoo~and TMODE) switch the terminal between graphics and text mode and viCf? versa, These are only applicable if you have a te both graphics and text screens (e.g., GO-235 and HDS3200 terminals) and plan to use graphics. Again, the appropriate escape sequences are in the t e r ~ n amanud. l With these changes completed, you can now compile the physics program, UTIL.FOR, SETUP.FOR, and GRAPHIT.BLK; link them together; and execute. For example, on a VAX you would type: $ i o r l r a e~2i.for,satup.ior,uti1.i~x~graphkt.b1k; $ I f & exmpli,obj ,sstap.obj,ati.1.obj ,graphi.2;.obj $ run amp1l, csxe
During compilation, you must be sure thaL the SMCLWE files are present in the default directory*
A.4 Execution Background: Befolre ruxlning a y code, you should read the relevmt chapter and the preface to the code in Appendix B (for examples) or C (for projects). The text provides general infarmation about the algorithms and physic~,the Appendix provides details that will be of interest o d y if you run t h s e codes.
Execudion: Here we discuss the canventions that me fallowed, more or less closdy, by $1 af the programs; exceptions are noted in Appendicw B and C. All of the programs are designed to be run interactively. Each begins with a; eitle page describing the physied problem to be investigated and the output that will be produced. Next, the m4rr menu is displayed, $iving you the choice of entering parameter vdues, exmining parameter v d ~ e srunning , the pmgrm, or teminating the pragfam. Xf you ehoose to run the pragrm, execution proceeds w d output is sent to the requested devices, Far many of the progrms, the ed~ulittioxlhas a definite end
(e.g., finding the cross section at a given energy), while for other programs (e.g., those involving time evolution) there is no clear end. In the second case, you are asked (at a frequency that you spedfy) whether you wish to continue the m n or return to the mdn menu. When the edcdation is finished, all values are zeroed (except the default parameters), and the main menu is re-displayed, giviv you the opport;uoity t o redo the cdcufation with a new set of parmeters or ta end execntion. IlnipuG: There me two time8 when the pro@- waits for input, First, the progam pauses for you to exmine output to the screen (e.g., the title page, o page of resdts, a plot); the execution is resumed when you press the fiturn. key. Second, the p r o p m will pause for you to enter ib parameter vdue. M paameter values have default d u e s &splayed in brackets [l; t o accept the default value, press &returnvat the prompt. g you choo~eto input a new value, but use the incorrect fomat, the program reprompts for input, If you input a d u e ontside the range set in the menu, the program prompts fur input, s t a t i ~ gthe rmge of vdues dowecf. Reall numbers must be input in 89.2 far t, TEs is a cornpromise in order t o allow default d u e s , The user input fanctioas ( G E T ~ Tand G . ~ I I T ) accept default d u e s by reading the input into a string variable and &ec&ng for zero length. If the string is not empty, the pasmeter d u e m s t be read from the string wbich aet~a m internal unit.. Therefore, the read m s t be formattd since list-directed r e d s from internal files are nat standad. Note that some compilers do not insist on. the exponential (i.e., 1.23 and 1.23~+0are both understood), or do allow Est-directed reads to internd units, so the formzbLting restrictions can be relaxed. Fortunately, integers may be entered in the "natural" way, as left justified numerals with no decimal. This is because the program twks a decimal point after the last non-blank character in the input string, and then r e d s the number from the string using F?. 0 famat, In many programs you will be prompted for input outside of the main menu. This hitppens for several reasons. first, if the input paameters failed to pass a check, the program re-prompts for input. Second, guidance may be needed in choosing parameter values (e.g., the range of partial waves in PROJ4 depends on the input energy), and the program prompts for these values after reasonable default values have been cdcda"ced. Third, cafculations can often dfow the cfimge of parmelers during the run (e.g., the time step can be altered during time evolution), and the propam prompts for these value8 during a run.
Please note that our "defensive programming" has not been airtight. It is possible to crash the program or get meadngiess results by entering inappropriate parameters. The default parameters for each code are listed in Appendix B or C in brackets [l. See A.8 for details on chan@jngdefault vdues* Output: To accommodate a variety of situations, there are several choices for run-time output. Text output can be displayed on the screen and/or sent to a file. Graphics output can be displayed on the screen and/or sent to a hardcopy device. The data used to generate graphics can also be sent to a file. You may choose the type of output by changing the default values in SETUPSFORor by altering I/O parameters from the menu at run-time,
A.5 Graphics One drawbad to programming in FORTRAN is that there are no standard F0 RTRAN graphics. This puts you in one of three situations: l)you orl2) your graphics pacbge is executed inhave no graphics package at & dependently of the program that creates the data (i.e., it reads in the data from a file) or 3) your graphics packwe can be called from a FORTRAN progam, If you have no graphics package, you should edit SETUP.FOR and 0, and GWFIL=O so that no graphics ilse produced. Because the gapkica output geatty enhances many of these progrms, you Illight wish to consider purehaajing such a packwe. For those users whose paphics package mast read the data from a file, the propams wiU (on request) output graphics data to a file. If you edit SETUPSFORso that GWFIL=I, GRFBRD=@, and O ~ R H = Ographics data will always be sent to a file, but never to the screen or hardcopy device. Findly, for those who have a FORTRAN cdable package, you will have to modify our codes to work with your package. To facztate this task, we provide a set of routines (contained in GRAPHIT.HI and GRAPHIT.LO) to act as an interface between the physics programs and a gc?nerd @;rap&= pwkage. The pbsics programs cdl the routi~esin the GRAPHIT files, which in turn call graphics package routines. This way, you only need to modify one GRAPHIT code instead of all of the physics codes. The code is docmented far ewe of nno&fication. GIRAPEXIT.EX calls the high level graphics package CA-DISSPLA; GRAPHIT.LO calls the low-level package UIS graphics (for the VAXstation). If you have either one of these packages, you can produce graphics with no further work, although you should read Appendix D.4 for information spedfic
238
A. How
Ijg
Eiae the P ~ m t n s
to your package. Also, routines for GKS on Sun workstations (written by Michel Valli&,resat Drexel University) are a d a b l e over the network (see Appendix E). Otherwise, use either GRAPHIT.HI or GRAPIIIT.LO, whichever i s more appropriate, as a template to create routines to call yonr graphics pachge.
A.6 Program Structure To facilitate code modification, we have attempted to conform to general "good" programming practices, sueh as those discussed in [Ke78]. The code far e d p r ~ e a mh= been formatted to m&e it easiex fo r e d , To the extent possible, variable names have been &own mnemonically and loops have been indented, as have sections of the cod- con$raUd by IF statements. Running comments on the right-hand side of many statment EEG@ indicate what; coxnputation is b&nl~;done. "I"o keep c d a to subroufinee as undnttmd, but as informadive, acl pasible, v&ables that me c o ~ s t mfor t one run are passed in cornman blo&~,while vhatiles that change are passed in d s . Afl vdab1es met apficitly typed. T h i s gives a check on typographical errors (using a VAX FORTUN compiler switch) and provides a dictionary for variable namee. pdor&ng Iiidtd The progr-8 are o r g ~ z e din mbfoutinw, w d W& defined %=XI&. The subrautines that pdoraa the edcdations are at the beginning of the code, and within thwe routines the most important lines are listed in boldface. The bookkeeping and I/O routines ws Ested at the end, atnd we have tried to keep these adfarm from chapter to chapter. A header deseE.ibes the pmpoae Of the subzaatjne axld the vaiables it uses. These are five types: XIPUT and oWPW wiables (which are passed to the subroutine in the call statement), variables (which are used only within that subroutine), NlrcTIOIS (which are de.fi.~i&by FORTRAN mrcnor routines), and oLoefi variables (whieh are passed in common blodts). Below we list the purpose of the subroutines that are eammoa $0aU the codes, wEle specific details for eaeh code prwede the wde listing in Appendices B and C. f Em"
P A ~ M
displays header screen, initializes constants (e.g., PI = 3.1415826), and sets up the array8 needed for the menu. It is in this raul-ine that defadt d u e s aab firrrits for input parweters we get, calls the menuing routine to obtain input parameters and then cdcul&(es any pasakanete~sthat are functions of other input pmmeters. Eiks are opened and do154 here, and the
A, 7 Menu Stm~I~rt?239
program stops in this routine, if so requested. Chedrs are performed to ensure that paramet er values are reason able. outputs parameters to the teminal or file. outputs text data to a terminal or file. outputs graphics data to a terminal or file. presides over the calculation. It calls the output routines we11 ills the routines that do the cdcdatioaa, and often. performs cdeu1ations itself.
A,7 Menu Structure We give here a brief overview of the variables and subroutines that create and execute the menu. The menu is made up of up to 99 individual items, each item is described by eight pasameters: BaPE, YITETS, IRULS, mo5t imgortmt p a m & @ ~ HLOLIH, HHIltm, NSTWG, MPRHPT, HTAG, is HWPE wbielz describes the action to be perfbrmed. T h i ~parameter f d s into one of three categories: 1) those that get input from the screen non^, rvx, BOOLUX, CBSTR), 2) those that provide flow control within the menu (YESKIP. AOSKTP , HCADIC, SKIP, ~UIT),3) and thwe thed;i; control the display of information ( W ~ X T PPRIBT, . C U T M , #TITLE. TT=). The function of the other parmeters depends on the vdue of WPPE and are given below. Each of these pmameters are FORTRAN arrays dimensioned to 100. The index of the array corresponds to the index of the menu item. The one exception is MSISTRIC which (since rarely used) is dimendoned to 10. These parameter &naysare: passed via in the indude file MEllilff.ALt, There we four routhes that are used in running the menu. Subroutine (in file UTIL.FOR) initializes menu parameters that are common to all programs; subroutine TEXT (in each example or project) initializes the m e ~ uparameters speGjfic to th& pro@&=. Subroutinfl ASK (in fife UTIL.FQR) executes the menu items by pedorming the aetion dictated by MWPE. Subroutine P~~TAGs(in file UTIL'FOR) prints a aummasy of menu items. Presiented here is a summary of menu pwmeter fuactians for each vdue of HTPPE. Any parameter not listed for a pwticdw type is not zl~ed.
240
A,
Now to Use the Pr0gmnz-s
get a floating point %umberfrom the screen menu prompt shorter prompt used in. PRTAGS default value minJmum dowed value m&muan &lowed vdue get an integer from the screen menu prompt shorter prompt used in PBTACS minimum. dowed vdue m~mum &awed vdue defadt value get a yes/no mswer from the screen menu prompt shorter prompt used in BETAGS default value (O=no, l=yes) get a chaacter string &am the aacrwn menu prampt @hartexprompt used in PRTAGS milximum number of chmacters dowed index of ~ [ S ~ H forGthis item (since nsTmG is dimensioned to 10 only) default vdue
get a menu choice (integer) from screen and branch meau prompt of form 'm nan a n ..', controls menu brmching; the m'th nn vdue i s the menu item brached to when user chooses menu item m. Because of the farm of the string, menu items c m only go from I to 99. the absolute vdne equds menu choice; if less dfrm zero the default vdue is nat ebmed, if greiates than zero default is &aged (useful when a menu choice i s dsa a pwametef choice). minimum sowed value m&mum &lowed vdue default vdue
.
A, 8 D e f ~ u l fflalzbe Revision
get a yesfno answer from screen, skip on yes menu prompt RTAGS : shorter prompt used in fmhGs MMALS: menu item to skip to on yes nrms : default value (O=no, l=yes)
MTYPB=YESXIP: WMPT:
get a yes/no answer from screen, skip on no menu prompt shorter prompt used in PRTICS menu item to @kipto art no arrTs : default value (O=no, l=yes) E ~ P E = S K I P : skip uncon&tionally W~ALS: menu igem to skip $0 RTYPB=IOSKIP: hfPWT: TAGS : 8mkLS:
RTYPE=UIIT : pause a ~ dwait for user to press return before IIIIPHPT:
coxltioiuing menu prompt
H~PE=Q~]XT : quit menu and return to cding routine HnPE=PPRIHT:
print description of a range of menu items by calling PRTAGS
8LQLXM: MHILIR:
index of first, menu item i n d a af lwt menu item
HnPE=TITLE : print information without getting input (in i s K and
PRTAGS) infamation to be prhted HMLIM: number of blank lines ta s u p bdore printing nltrxLxn: number of blank iines lo skip after prhting EPWT:
print information without getting input (in ASK only) infornation to be printed RLoLxn: number of blank Enes tm 8Eg befare printing ~ I L I Mnumber : of blank lines to skip after printing
I(TYPE=HTITLE: HPEWT:
A.8 Default Vdue Revision At some point the default vdues set in the progrms will rrot carrespond to your needs, a d chwging vdues at run-time throngh the menu will become tedious. When this happens you will want to dhange the default
242
*sly apnlau! ~ v x y apl d E! pale~ols%aama$v$s3nmwvd Aq panyap are q 3 g 'sao!~aam!p ~ rCem aaaql alp 12123 no^ .uo!snauIp rCvaa a q l o l pnba s l azp a3!93~1 m n m p m aql os 'aqs Xv~repampap aql w q l ~a-l
An%aq a o u m ~ppg v ~ O 8$u~ad J a~!$$'itjp aaqurnu e y l b a l d m mz a *waw ~ -a%Q%s tfat&ZXn'fldNvx&xoJaqS Aq paayiap @alqQYeh 0 3 $as @m @ % P R @say3 saw~$amo~ *sA:r?sm W X ~ p ~mH nz?xW a! paafrcr)~:,am sranpA alq%aap mnurptxr pm rurn-uxTam *s1plapasam JCBJa~aqqt e yq a 3 a s aq$ a a ~ "saa -FA ral3esep JQJ at pm ' s a p fear ;rqj mm a1 %anpn au/saA ui am SanpA a p ~ j a pmay$ -sAem naam nf s a n p sa%aaufmj s$p%jappisamnu pm pars$% a n s a a p ay$ ! & ~ g aafltnozqas r ut! $as @3!skqfirld*(anoqvg * y-g) X O ~ * ~ Q ~ n! B Sam sa3~oq3011 ~ F % J ~ ( I *apes aqg a! ~ a n p ~
Appendix B
Programs for the Examp B.1 Example 1 Algorithm This program finds the semiclassical approximations to the bound state energies of the Lennard-Jones potentid for the input vdue of 7 = ( 2 m a 2 ~ o / ~ 2 )The ' / 2 basic . problem is to find, for each integer n, the vdue of E, for which Eq. (1.22) is satisfied. After the number of bound states is estimated (end of subroutine PAW), the energy for each level is found (DO loop 100 in subroutine arrclroar) using a secant search (subroutine SEARCH) to locate the zero of f = s- (nf$)rr. Subroutine acTxog calculates the action, s, for a given energy by using simple searches to locate the inner and outer tmoing pdnts m d then using Simpson's rule to edcdate the integral, with. a special treatment for the squae-root behavior near the turning points, The patentid is defined by function POT, If you dedde to chmge the podefiial, be sure tha'c the minimum is norm&aed to a vdue olF -4axrd that POmXM in. subroutine IHXT is set eqnd to the eqdgbriurur .X vdue of the new potentid. These requirements ensure that both the energy m d turning point s e a c h e ~begin at remonable vdues: the mergy sear& at --l and the tnrnixrg point search at PDTMIIII. Input The only physical parameter is 7 [SO.] which i s the dimensionless measure of the qumturn nat;ure of the problem. The rnfimum number of bound levels that can be found is k e d by the parameter M A X L a = f 00. If NLEVEE is calculated to be luger than this, you will be prompted for a new value of y until NLEVEL is small enough (subroutine PCAECK). The numerical parameters are the energy seach tolerance [.0005], the turning point search tolerance [.0005], and the number of points used in evaluating the action integral [100]. The graphing parameter ECRF [80] determines the number of points used in drawing the pha~e-spxetrajectories (subroutine GRFOUT), The limit on WGRF is set by the parameter BAXGRF= 1000,
Output After each Ievd is found, the number of $he level, the energy, and dassied turning points ( b i n and wax) axe printed, Whea a;U the energies are found, the phase-space trajectories k ( s ) = y graphed for each level (subroutine CRFOUT). cCCCCcCCCcccccCccccCcCCccccccCccccccccccCCCcccCcCcccccccccccccCc~cCccccc PRmM EXWLI C E x m l e 1: Bohr-SomerEeld q u a n t l z a t i o n f o r bound s t a t e s o f t h e C
C C C
Lennard-Jones P o t e n t i a l COWUTATTONAL PHYSICS (FORTMM WRSXON) by Steven E, Roonin and Dawn C, Meredith Copyright 1989, Addison-Wealay P u b l i s h i n g Company
ccCcCecccececcc~ccccccccccccceccccc~ccceccecccecccceccccccecccccccc~cccc S
G A U INIT CONT& RUE
CALL PAMM C&LL MCWON GOTO END
! d i s p l a y header screen, s e t u p parameters
fmain loop/ e x e c u t e once f o r each set of param ! g e t i n p u t from s c r e e n ! s e a r c h f o r bound s t a t e s
5
CCCCCCCCCCCCCCCCCCCCGGCCCCGCCCCGCCCCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC SUBROUTINE mCEEIN C f i n d s t h e bound s t a t e s of t h e Lennaxd-Janes p o t e n t i a l C from t h e Bohr-Somerfeld q u a n t i z a t f o n r u l e C~CCCCCGCCCCCCCGCCCCGCCCCCGCCCCCCCGC~CCGCCCGCCCCCCCGCCCCCCCCCCCCCCCGCCCC C Global v a r i a b l e s : INCLUDE "SO.ALLe IMCLUDE VPAMMeE1' C Local v a r i a b l e s : =&L S ! c u r r e n t v a l u e of a c t i o n m& El ! c u r r e n t v a l u e o f energy M U X I , X2 f current turning points M U F1 I f ~ a c t i o n l 2 pi12 -ilevel*pi TNTeGER X M a L !c u r r e n t Level !energy of bound s t a r e mAL ENERGY ( Q :M L V L ) M& XZN (0:WLVL) !inner turning p a i n t !outer turning p a i n t REAL XOUT ( O :WLVL) !nu&er of l i n e s p r i n t e d t o t e r m i n a l INTE(;ER NLINES INTEGER SCmEN !send t o t e r m i n a l TNTECER PAPER !make a h d r d ~ o p y INTEGER FILE Isend t o a f i l e DATA SCmEN, PMER, FTLE/f, 2,3/
-
cc~~~~cc~cc~c~Ccccc~cccccceccc~ccccccccccccec~c~e~ccccC:cccc~c C
o u t p u t s u m a r y of parameters I F (TTERN) CALL PRPllOVT {OUMIT,NLIMES) I F (TFILE) GALL PRIUIQUT(TUMf T, NLTNES) JF (GFXLE) CALL PWOUT(GUWZT,NLINES)
c C
oeazab for b a n d rrtateo Elm-5. El=-PT42
C:
tt>eqAn at the wall bottam !the acrtion i a erro tharo
states -1 G
L t H T , F 1 , X J , ~ ) fsrolr& f o r e%gesvaXae I rrteze va3urar this stake
C C
text output IF (TTERM) CALL TXTOUT {GUNIT,I L E n L , El,XI,X2, NLXNES) I F (TFTLEf CALL TXTOUT TUN^ T,f LEVEL,El,X1,X2, ElLINESf
e h"l=EX-BX
!mess t o bagAn mazah f o r m a t ZCWQI,
C
roa c
comzm IF ITTERM) CALL PAUSE ("0 IF (TTERM) CALL CUAR
C C
continue
*
.' ,l)
graphics output TF (GTERH) CALL GWQUT (SCREEW, ENEKY, XTN,XOUT] TF (EFTLE) CALL GWOUT (FTLE,ENERGY, X f I XOUT 1 IF" (GWRDGP J CALL GWOUT (PAPER,ENERGY,XIN,XOUT)
C
RETURN END
ececcc~ccecccccccccccccccccccceccceccccccccecccccecccccccccccccececccecc SUBROUTINE SEARCH (M,El,F1,XI,X2f C finds the N t t t h bound state C El is passed in as initial guess for the bound state energy
and returned as the true bound state enercfy with turning paints XI and X 2 C PI fs the function which goes to zero at a bound state G F1 = actlon/2-(ntl/2jxpl G
C
cccccccccce~Cccccccccce~cccccceecccccceccce~~~cccccccccccccccc~c~ccccccc C Global variables: INCLUDE v P m M . E 1 '
C Input/mtput variables:
INTEGER N El,E2 RE= F1,F2 RE& S REAL X1,X2 C Local variables: W% BE
!current Level (input) !trial energies ( I I O ) !f =aetion/2-pi* (n+l/2f f 1/01 taction (output1 !turning paints (output) !increment in enerw search
ccCccccecccccccccec3cceccceccccecc~cccccC:cceccccccccccccccccceccccccccc~c C me@@ a m % arnesrw i n oder t;o h g i n sear& L2=81+=5 ( E l ) / 4 , BE=2*EZOL C
C
ao
use reeonnt; aaart=h to fAnd tbe hemd ataka XF (ms {DE) .@E. EZOL)
&C3eXOkE(EZ,n,X2,8) (R+. *F1 rs (xn *m. s 2 ) F5)
Dm-Ez* (E2-El) / (82-F1) ELSE
Dma * Ern ZIr C
El=RZ E*"%=F2 EP=El+DTZ IF (E2 .tBl. 0 ) ]EIP=-BTQ& 50
E m IF e RETURN
END ~C~~~~~C~CCCCCCCGCCCCGCCCCCCCCCCCCCCC~~~~~~C~~CCCCCCC~CCCCC SUBRQUTINE ACTION (E,XI, XZ, S) C calculates the (action intagra2)/2 ( S ) and the classical turning C points (XI,X2) for a given energy (E)
cCccCceecccecccccccccceccceccccccecceccccecc~cccc~cccccecccccccecccccccc C Global variables: C Inputloutput variables: mAL E mAL S REAL X I , X 2 C Locaf variables: DX =&L M SUM INTEGER IFAC INTEGER SX REAL X MAL POT
fenerw (Input) !actfon toutput) ? turnfng points (output1 !increment in turning point search !quadrature step size
!sum for integral !coefficient for Simpsonts rule !i n d e x cm X !current X value in sum !potential as a function of X (function1
cccecccccccccceccccccceeccccccceccccccccccceccceccccccecccccccc~ccccecec C
$ i d i n n e r tumAng poink; b g i n @amehat Che w d l bottom =*Q-%
so
DX=. l ZIP (DZ .@ XTQL) l!* XI-XI-DX
ra (Pm(m)
lusar a 5 i ~ k esear&, p i n g iawwd .GB. E) PrnH
X1e.CDx DX=DX/Z -'TO
E m 33' 50
rnD
m
C
G
fieChe -tar
DX=. 2
turning polnk; bagin sararab at tba w a Z l bottom
120
fP {OX .G%. moL) %m lwre &-2r X2=Z2+aX m' (Pm4x2) .a. m X2mX2-DX DX=DX/I E m ZB GQlM 12Q
@a%w*rd
aaaz& pi-
gm C C
S*+onC
E
m t e f z m XT+B t o XZ-B 1) 'IQPIPI=m"IPSS.f
x r {rnD (WE@,2)
.m.
H= (x2-~1 ) /=TB B m S m P (E-EOT(=+g) Z a-2 DO 200 ==2,=TS-2
mut; h t &&up .fee
x=n+=*If Ik* {=&C
.SQ, 2) T m rnzm.14
Bt-
m
=A-2 X@
SW=SW+m&C*S@Z(B-POT(X)) 200
camzm s-sm+smv
(E-@=
(xz-n)I
amSwH/3
C C
ap(;;tp3, for h b v i o r oE firs& SmBW+SmZ{S-Pm(XltB)) *2*fI/9 S-BW+B=F (a-~ae ( ~ 2 - I P *2*l~f/3 )
Iaet ifttam&e
C MTVRH
BND
cccccccccccc~ceccccccccccccecccceccccecceccccceccccccccccccc FUNCTION POT (X) the Lannazd-Jones potential at X
ccccccccccccI;ccccccceccccceccccccccceccccccceccccceccccceecccccceccceccf: ccccccccccccccccccccccccccccccccecc3ccccccceccccccccccccccccccccccccecccc C If you change the potential, normalize to a minimum of! -X C and change the value of POTHIN in subroutine INfT to t h e C new e ~ i l i b r i u mposition (i.e. the X value at which t h e Ecrce is zero) U m 1 1 ~ 4 - J e ~ ap%mtiljl e in re8Zed ttrriiblrr C P m r * (X**(-3.2)-X** ( - 6 ) ) RETURN
END
cccccccccccccccceeccccccccceecceccccccccccccccccccccccccccccccececccccf:c SUBROUTINE IWIT C initializes constants, displays header screen, C initializes menu arrays for input parameters
cccceececcecceccceccccccccccccC:ccceceC=Cceccceccceccccccccccccccccccccccc
248
B. Pr~granzsfor the Ezamples C Global variables: INCLUDE 'IIO.ALLC INCLUDE "MU *ALLf INCLUDE ' P W M , E I " C Local, p a r a m e t e r s : GHmCTERe80 DESCRP DTaNSION DESCRP (20) ZNTEGER NHEAD,NTEXT,NCMPH
{program d e s c r i p t i o n !nu&er
o f l i n e s for e a c h d e s c r i p t i s n
ceccecccc~cccCccccccece:ccccccceccccccccC:cececccccccccccccc"ccC:ecccccccccc C
g a t environment p a r a n t e t e r s CALL SETUP
c C
display header screen DESCRP (1) ' E X M L E 1 ' 83SCW(2)= ' B o h r - S o m e r f e l d q u a n t i z a t i o n f o r bound s t a t e t DESCRP(3)- % n n ~ g l a s o f t h e 6-12 p o t e n t i a l "
NXEA8=3
c C
C G
t e x t outgut description DESCjRP(9)= ? e n e r g y and c l a s s i c a l t u r n i n g p o i n t s f o r e a c h s t a t e f NTEXT=1 graphics output description DESCRP/S)= "phase s p a c e (wavenuniber v s , p o s i t i o n ) p o r t r a i t f of classical trajectoriese BESCW ( 6 )
wcm~a=a c G G
CALL WEADER (DESCRP,NBmD, XJ"L"EXT, M G W W ) calculate constants PI=4*ATAEJ (I.0) PQTMfN=2** (l.0/6.0)
C C:
s e t u p m n u arrays, beginning with constant p a r t
CALL MEMU
e M T P E 113) -FLOAT M P W T (13f = "ntar gamma-sqrt f 2*m*a**2*V/hbar**2} MT&G (13) = " a m a (dimensionless) '
(d i m e n s i o n l e s s )
WEOLIM (53)=1. MHILIM (13)=500.
e MTYPE t 14 ) =SKIP LS (14j.535. G
MTVPE ( 38 f =FLOAT MPWFT (381 = , E n t e r t o l e r a n c e f o r e n e r g y s e a r c h ( s c a l e d u n i t s ) ' Energy s e a r c h t o l e r a n c a ( s c a l e d u n i t s ) " MTAG fJ8) MLQLIM(38) =. 00001
-
TM(38)=, 01
"
C
NTYPE ( 3 9 ) =FLOAT MPmPT (391.. +'Enter tolerance for turning point search (sealed unitsf' MTAG ( 3 9 ) = Turning point search tolerance f sealed units)' MLOLZM (381=. 00002 MWILIM(39)-.0l MREALS (39) 0005
-.
c
MTYPE ( 40 1 -NUM N P W T I Q O ) = 'Enter nu&er
of points for action Integral' MT&G(40/= *Nu&er of quadratuse points for action integral' MLQLIM (40)120. MXILIM(4Of=SOQO. MINTS (40)-100
c MTYPE ( 4 I ) =SKIP M A L S 1 4 1 ) =GO. C
MSmNG (MIMTS[ "65)1 =
eexmpll,txtf
e MTVPE f 7 6 ) =SKIP L5 ( 7 5 )=80. C
MSTRNG(MINTS(86))= %exmpll.grf' C
MTYPE 4 871 =NUM lrlPMPT(87)m "nter
nu-r of points to be usad in graphing' MTAG(87)a 'Nu&er of graphing pointsf MLaLfM(87)= 10. NN3LIM 4 87) PIIAXGW-2 MINTS(87)- 80
C
MTWE (88) =SKIP MRMLS (88)=%Q C
RETURN END
c~~ec~~~~c~ccccec~cccc~cceccccc~cecccccc~ccc~~~ccccccccccce SUBROUTINE P A W C gets parameters from screen C ends grogram on request C closes old files e maps menu variables to program variables C opens new files !C caZeuXates all derivative parameters C performs cheeks on parameters CCCCCCCCCCCGCCCCCCCCCCCCCCCCGGCGCCFCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCC C Globaf variables: INCLUDE %MEN ALLF INCLUDE @ZO.ALLe IHCLUDE 'FAWM,El" U,
INCLUDE *=.Elt C Local variables:
REAL S R m L El REAL X1,X2 C Function: LQCTCAL LQGCVT
fcurrent value of action !current value of energy !current turning points !converts 1 and O to true and false
ccc~cccc~ccccccc~cccccecccc~ceccccccccc~ccceccccecf:eeccccccceeccccccCccc G
gatinputfromtermlnal CALL C L E M CALL ASK (1,ISTOP)
c G
C C
e C
stop program if requested IP ( r n m(XMASNI ~ ~ .ea. STQPt caLL FINISM close fifes if necessazy IF (TNA14E .m. MSTRNG (MINTSf ITMAMEt)) + CALL FLCLQS (TNRME,TUNITf IF (GHAME .NE, MSTRNG (MINTS(ZCMmE)) ) + CALL PLCLQS (GHAME,GUMIT) physical and numerical parameters XTOL=mALS (EXTOL) NOTS=MINTS IINPTS)
C C
text outfrut parameters TTERM=LoGCvTtMXHTS(lTT&RMl} TFILE=LWeVT(NIMTStTTFILB)f T H ~ = M S T R M (MINTS C (xTNaw graphics output parameters GTERM=LoGCVT(MINTS(TGTERM]f GBmCPmLOGCVT (MXMTS(IGBRD)) GFXLE-LQGWT(HXHTS(5GFILE)f GMM=MSTRNG (MINTStXGNAm1 f MGRT=MINTS (IHGW1 open files JF (TFILE) CALL FWPEN (TEA=, TUNIT) IF (EFILE) GALL FMPEN(GMm,GUHXT) files may have been renamed WSTRMG (MINTS4 XTNAmf1=TNAME MSTRHG (MINTS (IGMAW)f =GHAME
cal&rtaa
total n-ar
Elm-EZQL IHT (B/PZ-.5 ) +l check value of GA)IMA CALL PCNECK
s f fsvcrls
C CALL C L m R C
RRTrnN SUBROUTINE OCWECX C ensure that the nuniber of states is not greater than the size of C the data arrays; if so prompt for smaller G ~CCCCCCCGC~CCCCCCC@CCC~CCCC"CCCGCCCGC1CGCCC~CCCC~CCCCCCCCCCCCCC~CCCCCCCCCC
C Global parameters: IMCLUDB 'PAMH.EIf INCLUDE * =NU. ALL" INCLUDE * IOIALLe INCLUDE * m P . E l r C Local parameters: mAL S REa E WAt
XI,X2
C Function: GETFLT
! action
!small negative energy lclassical turning points !returns a floating point variable
ccCceCcccccCcceccceccccccccccccecceecccccecccccccccccccecccccccccceccccc 10 TF ((NLEVEL-I) .GT. mXLVL) THEN WRITE (QUNIT,lS) NLEWL,mXLVL MHSLIM (IGAMm)=G&TPLT
( m ~(rcmm) ~ s / ~ , ~ O L Tt1:GAnmj M
@
MWILIM(IGAMW), 'Enter a smaller gama')
.c
E=-ETOL CALL ACTION (E,X I , XZ, S ) NLEVEL=INT(S/PI+.5 )4-1 GOTO 10 END IF C 15
P O m T ("'rota1
+
nu&er
o f levels
,is,
' 1 i s larger than maximum allowable ( = f , i 3 , t ) r 1
C
=TURN END
cceccccccecccececccceccccc~cccccccccecceeccecceccccceccccccF:cccceccccccc SUBROUTINE PRMOUT(MUNfT,NLINES) C ourputs parameter: s u m a r y to the specified unit
cccccccccccccececec~cccecccccccccccccccccecccccccecccccccccccecccccccccc C Global variables: INCLUDE ' X0.ALL6 INCLUDE *PPARAM.EI" C Inputloutput variables: INTEGER MWbT INTEGER NLINES
! u n i t nuaer for output (inputJ !nu&er of lines written so far (output)
ce~cccc~cc~~cecc~cccccc~ccecccccccccccccec~ccecccccecceeccccccccccc~cccc XF (MUNIT .Ea. OUNST) CALL C L E m
252
B. Programs for the Erctsmples C WRITE mITE mITE WmTE WRITE mITE mITE
(MUHIT, 2 ) (MUMIT, Q) (MUM1T, 6 ) ETOL, XTQL (MUNIT,B) PEPTS (MUMIT, f Cl) G A M , NLEmL (MUMSK 1 2 ) (MUNIT, 2 )
C I F (MUNf T .ME. GWf Tf THEN m I T E (MUMST, 201 W I T E (NUNIK ,251 END SF C
HLIMES=? C
2 4
6 8 10 12 20 25
+
FORmT ( * 1 FQRMT f * Output ffom example 1: Bohr S o m e x f a l d Q u a n t i z a t i o a v ) FO-2" ( ' E n e r w t o l e r a n c e = l , E12, S, p o s i t i o n t o l e r a n c e m*, E12.5) FORmT ( * nnuder o f q u a d r a t u r e p o i n t s =\ XI$) F O m T ["or g a m a =@, FF8.2,* t h e r e a r e ', 14, * l l e v e l s : * ) F O W T ("all w a n t i t l e s are e x p r e s s e d in s c a l e d u n i t s ) ' ) F O M T (8X, r L e v e f l , @X, @ E n e r g y P t112X,'Xmfnt, 12X, eXmaxcl F Q W T (8X, '-----P , ex, , 12X, "---p , 1 2 X ,,----" 1
C MTUW END
ccccccCcccccccCccccccceeccccccccccccccecccccccccccccceccc~cccecccccccccc SUBROUTINE TXTOUT (MUNI T, XLEVEL, E, X I , X2, NLINESI one s t a t e to t h e r e q u e s t e d u n i t
C writes r e s u l t s f o r
cecccccccccccccccccccccccecccccccCccccccccccccccccccccccccC:cccceC:ccececc C Global variables: INCLUDE 'IO.ALLv C I n p u t variables: INTEGER MUNIT INTEGER XLEVEL mAL E REaZ X1,X2 INTEGER NLINES
! o u t p u t unit s p e e i f i e r !current l e v e l I e i g e n enerr3y ! c l a s s i c a l t u r n i n g points Inu&er of l i n e s p r i n t e d so f a r
ccccccccceccccceccccccccceecccecccccc~cccccccecccccccccccccecccccccccccc C
if s c r e e n i s full, c l e a r s c r e e n and r e t y p e h e a d i n g s IF f (MOD (NETNES, m L I N - 6 ) EQ. 0) -4.AND. (NUNPT .E@. OUNIT) t THEM
.
CALL PXLUSE(ftto c o n t i n u e , , . ' , l ) CALL e z E m @RITE (MUMIT, 20) m f T E (MUNIT,25) END I F C
mXTE (WUNIT, 30) ILEVEL,E,Xl, X2
e
C
keep t r a c k of p r i n t e d l i n e s o n l y Ear t e r m i n a l o u t p u t XI? (WHIT .&Q. OUNIT} NLINES=MLINES+l
c 20 25 30 C
F O m T (8X,
tZevel\
,X,
# @X, F O W T (834, *-----' F O m T (8X,T4r3 (8X,FBe5)f
' E n n e ~ " 12X, "-."---P ,,
'XXrninf, 12X,
- -
12X
fXmax@l 1
,?----"
RETURN END
CCCCCCCCCCCCCCCCCCCCGCCCCGCCCCCCCCCCGCCCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCGCC
SUBROUTINE GRFOUT(DP;IIICE,ENERGY,XTES,XOUTi C o u t p u t s p h a s e s p a c e p a r t r a i t s aE t k s bound s t a t e s t o t h e t e r m i n a l C and/or a f i l e CCCCCCCCCCCCCCCCGCCCGCCCCGCCCCCCG~CCCGCCCCCCCCCCCCCCCCCCC~CCCCCCCCCCCCGC C Global p a r a m e t e r s : 1NCLUDE ' IO ALL* SMCLUDE ' P A W - E l ' INCLUDE "WIIAT. ALL * e Input variables: INTEGER DEVICE !which & v i c e is being used? ienercjry of bound s t a t e MAL ENERGY ( D :W L V L ) XIN (O:rclAXLVLl !inner turning point !outer turning point REAL XOUT (Q:mLVL) C Local p a r a m t e r s : XIJIPEEER ILEVEL ! l e v e l index !step size for X RUL N I x index INTEGSR I X RE& I2 ! c u r r a n t energy m& K t W G W ) !current w a v e n d e r X [MXGRF1 !current position CTER* 9 CG&MM, CM !Gama,nlevel as a & a l a e t s r s t r i n g REAL POT ? p o t e n t i a l (function) TMTBGER LEN,NLEN ?length o f c h a x a ~ t e rd a t a INTEGER S C W E N !send t o t e r m i n a l INTEGER PWER !make a hardcopy INTEGER FfM Isend to a f i l e
.
DATA SCREEN,Z>APER,FILE/1,2,3/
~cceCc~ccccc~~ccc~ccccceccececcccccccccecc~ccceeccccc~~c~c~~c~cc~~ccc C
messages f o r t h e i m p a t i e n t XP [DEVICE ,NE, SCREEN) WRITE (OUNIT, 2 0 0 )
c C
c a l c u l a t e parameters f o r graphing I F (DEVICE .NE, FILE) THEN NPLOT=l !how w n y p l a t s XPLOT=I,
c *SWT(l.+ENERGU(NLEVEL-1)1 YMINm-VmX XMIN=XIN (NLEmL-1) XmX=XOVT (@LEVEL-1 ) YOVAL=XNTN
xavax_l=o.
!limits on d a t a p o i n t s
IF (MOD( N G W , Z ) NPOINTmNGW
.EB. 0) NGW=NGRF+1 !keep nu&er
a f p o i n t s odd
C XLX~=I ISYM=I
I l i n e and s y & a l
styles
IFREQ-0 NXTICKeS NVZIICX=5
CALL CONVRTfaW,GGAm,LEN) l t i t l e s and labels caLL IGWRT (NLEWL, CH, NLENI INFo=* NLEVeL = V / C N (1;NLEN) T X T L E = 9 e m i e l a s s i c a l l y Quantized T r a j e c t o r i e s , G a m a = l / / C G M m m E L , ( 2 ) =f s s c l e d p o s i t i o n * ( 2 f =* acalecf wave nu&srf -EL C U L GTDEV (DEVICE) TP (DEVICE .EQ. SCREEN) CALL GMODE CALL I;NLNm END SF C C C
! d e v i c e nomination !change t o g r a p h i c s mode !draw a x e s
c a l c u l a t e c l a s s i c a l p h a s e s p a c e t r a j e c t o r y f o r e a c h bound s t a t e by f i n d i n g t h e s c a l e d w a v e n u d e r a s a f u n c t i o n o f X a n d E n a r w DO 50 ILEVELmO,NUVEL-1 EsEMERGV ( XLEVEL) W= (XoUT(XLE-Lf -XIW (ILEVEL1 f / ( 1MGRF-I f I 2 1 !step s i z e X (1J =KIN (ILE-L) R (1)43.
C
DO 20 IX-1, (NGW-1)12 X (IX+1)=XIN (ILEVEL)+ (1x1 *H K (IX+1) (E-POT(X(IX+1)f 1 IF (R(IX) .LE, O f THEN K ( X X I =O. ELSE K (1x1=GMm*SQRT (KIXX))
-
! s c a l e d wave n u h e r
IF 2Q
CONTINUE:
G
30 C C
DO 30 X X I ( M C W + ~ ) / ~ ~ N G W -!graph ~ i s s y m e t r i c about x-axis x (IX+lI=X (wGw-Ixt K (IX+1)=-K (NGRF-XX) COWTXHUE
output r e s u l t s IF fDEVICE .EQ. FXLE) THEN WRSTE (GUNST,?S) E WRITE (GUNIT, 70) (X (1x1,R(fX), IX=I,NGml ELSE
(=;ALLXYPLO"IC(X, X ) END IF
50
CONTI HUE
e
c
end grapbing session I F (DEVICE .ME, F I L E ) CALL GPAGE(DEVICE1 I F (DEVLCE .Ea. S M E N ) CALL TMODE
C 70 75
100 C
!close graphing packaw !switch to text mode
F O M T (2 (5X,E11.3) F O W T (/,VosiGion v s , wave n u d e r for Energy =r,IPE11.3) F O W T f / , * Patience, please; autput going to a file-'l
RETURN END
e~~c~~~~~ec~c~~c~cecc~ccccceeccccceeee~cceccccc~ccccccccc[:ccccec~ c~~cc~~ec~e~~~~~~cc~cc~~ccecccececcccc~cc~cccccec~ceecC:cccc C param.el G
RE&
PI
M& POTMXN =&L G A M M
....,
!pi=3,15159 !x value at equilibrium
REAL ETOL MBZ XTOL INTEGER NPTS INTEGER NLEVEL
!=sqr~(2*mass*length**2*patc?ntia1/hbar**2~ !tolerance for energy search !tolerance for turning paint search ! n u W r of integration paints !total nunber o f bounds states (depends on g a m a )
INTEGER NiERF G F XMTeGER m L V L
!nu&er of paints far graphics output !maximum number of graphing points !m;ucinrum nudax of wanturn levels
C
C
F m a T E R ( W G W = f 000) PAMMETER ( W L V L = 1 0 0 1 C
COMOH / COHST / Pf,POTWIN pemM I / ETOL, XTOL, NPTS, WGRF COMON / PCALC / NLEVEL
como~/
GCCCCCCCCCCCCCCCCGCCCCCGCCCCCCCCCGC~CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC CCCC(J~CCCCGCC~CCCGCCCCCCCGCCCCC~CCCCCCCGGCCCCCCCCCCCCCCCCCGCGGCCC:CCCCCCC C map,ef, f NTEGER X G m m , ZETOL, TXTOL, f NPTS, f M G W PARAMErnER ( I G A M = L 3 1 TER (XETOL = 38 ) TER (XXTOL = 39 ) PAMMETER (INPTS = 48 ) PAMWTER ( X N G W = 87 )
256
B. Programs for the Ezamples
B.2 Example 2 ALlgorilthm The propam integrates trajectmies in the Ffdnon-Heiles potential (Eq. 2.35) and finds the corresponding surfaces of section (abbreviated t o SOS in the code). Subroutine ARcAaB creates the surface of section for one d u e of the energy by c&ng subroutine w sonce for each set of initid conditions request&, Subroutine SOS prompts for initial vdues of y and p,, calculates p, from energy conservation (recall r = 0 on the surface of section), and executes the time integration (subroutine S ~ P ) until the =quested number Df s~lrf.$eeof section points have been found. Subroutine STEP takes a time step using the fourth-order Runge-Kutta step (subroutine RUBICE); derivatives of the coordinates and momenta are cdcdated by subroutine ~ A and L functions ~ E ~ z and I V mE;m.This row tine also checks for crossings of the the trajectory with the y-axis (i.e., whenever z = 0). If a crossing is found, it temporarily switches to I as the independent mriable and idlegrates bwk to find the surfxe of section intersection as described h the text. Tbe form.of the potential may be chmged by editing the potential v and its deriv;zt;ivesDERIV and ~ B X VwEch axe located in function V. You will also need to & w e the grapMng limits far the trajectory in subroutine T R J I ~and should review the values DYO and TOLY(subroutine IBIT) used in seaching. The limits on the energy (also subroutine IPIT) should be the sxnaUest and largest vdues of energ that @ve rise to bounded moLioxl. Input The physical parameter entered from the main menu is the energy [.l].The initial conditions for y [O.] and pp [Q.] are requested from subroutine SOS so that more than one get can be used in creating a, single surface of section. Limits on y depend only on the energy and are calculated by subroutine LIMITS; limits of p, depend on the energy and g, and are cdculated in so$. The numerical parameters are the time step [.l21 and the number of surface of section points 11001. As soon as the requested number of surface of section points are calculated for one set of initial conditions, you will be prompted for the number of additional surface of section points [O]; if you answer none, you will be asked if you want additional initial conditions; if you answer no, the surface of section is complete and you return to the main menu. The maximum surface of section points is fixed by MIXSS= 10,000. The only graphics parameter is the number of points in the trajectory to be plotted [4000]. This is needed to prevent output files from becoming too large and plots from becoming too cluttered.
Output The text output at each surface of section crossing includes the t h e , kinetic mergy, potential energy, totd eRer0, a d percent change ia energy since the integration began. The graplria output is the trajectory (output as the integration proceeds) and the surface of section points (output when the requested number of points have been found). All sarface of section paints wcrtmulated since the exit from the m&n. menu ape plotted together, dowing the creation of sections similar to those s h a m in Figure 2.3. Becmse thc? trajwtory is described by. a great deal of data, the Lrajectory is nafi saved in an array, acnd the foaawing output procedures have been adopted: 1) the trajectory i s never output to a Be (only surface of section data are saved to file if requested), 2) if both graphics to the screen and graphics to hardcopy are requested, the trajectory is sent only to the screen, but the surface of section is sent to both the screen and hardcopy, and 3) if both text and graphics are requested to the screen, only the graphics is sent to the screen. ccccccccCeccccccccccccccccceccccccccccccccceccccceccceceeccE:ccc~eccccccc P R W M M EXWL2 Example 2: T r a j e c t a r i e s in t h e Henon-Weiles p o t e n t i a l C COWUTATXONAL PHYSICS (FORTRAN VERSION) C by S t e v e n E. Koonin and Dawn C, Meredith C C o r n r i g h t 1989, Addison-VuTesley P u b l i s h i n g Company C
eccCeccccccecccCceccccccccccccccccececcccecceccececcceceeccccecc~ccecccc S
CALL fNIT CQWTIEIUE CALL PAmN CALL ARCNON
! d i s p l a y header s e r a a n , s e t u p p a r a m e t e r s !main l o o p / e x e c u t e once f o r e a c h s e t of param ! g e t i n p u t from s c r e e n t e a l c u l a t e s s u r f a c e o f s e c t i o n f o r one e n e r g y
GOTO 5
END C~CCCCCC~GCCCCCCCC~CCGCCCCGCCCCCCCCCCCC~CCCCGCCCC~CCCCCC~CCCCCCCCeCCCCCC SUBRQUTXNE ARCWON C c a l c u l a t e s s u r f a c e of s e c t i o n (SOS) f a r one e n e r g y C a l l o w s f o r s e v e r a l s e t s of i n i t i a l c o n d i t i o n s
ceeee~cE:~~ecceecceccc~cecc~cceccccccccceecccccf:~cc~ccccccccccccccccccccc C Global v a r i a b l e s : INCLUDE: * IO. ALL' ZNCLUDE * P m m . E 2 ' e Local variables: M A L SSU (MAXSS) ,SSPY (FfRXSS) INTEGER NCROSS INTEGER ANQTRR INTEGER DEF TNmGER DBFNTW XMmGER MORE TNTEGER SCREEN IMTEGER PAPER
!s u r f a c e o f s e c t i o n p o i n t s ! t o t a l number of SOS c r o s s i n g s ! s t a r t w i t h a n o t h e r set a f i n i t ecnd? ! d e f a u l t number a f 505 p o i n t s !minimum number of SOS p o i n t s !how many more SOS p o i n t s ? Isend t o t e r m i n a l !make a hardcopy
288
B. Pmgrams for Me Ezawles INTEGER FILE
!send t o a f i l e
C Functions:
INTEGER YESNO !yes o r na i n p u t TMTeGER GETINT !integer input DATA SCREEN, PAPER, FXLE/1,2,3/
ccccccccccCcCccccccccccccccccccccccccccecccccccceecccecccccccccccccccc~c 50
NCROSS=O CQmIliifm
!no s u r f a c e of s e c t i o n p o i n t s yet !loop ever: i n S f i r J aaad2lt;ions SQS (E-SS, SSEY, SSY) !aal&atr @=faof section CALL CLEM !allow f o r another set. of i n l t cond WNQTWR=YESNQ{O,'Do you want a n o t h e r set of i n i t i a l e a n d i t i a n s ? @ ) mQzm*EQ*21
+
DEF=MIW(100,WSS-N50S1 ! d o n P t exceed s t o r a g e space DEFWTN=MIN (10,M X S S - N W MaREmGETINT (D@, DEFMIEJ ,=SS-NSOS, "NW m n y s u r f a c e of s e c t i o n p o i n t s ? ' ) NSOS=NSOS+MOm 50
C I F (GWRDCP) CaLL GWOUT(ITAPER,SSY,SSPV,l)
!lzrdepy once p e r energy
G
RfSTURPJ END
cccceccc~ceecccceccccccceccccccccceecccecccccccccceccccc~~cccece~ccccccc C C C C
SUBROUTINE SOS (NCROSS, SSPY, SSY j f i n d s t h e s u r f a c e of s e c t i o n p a i n t s (SSPY,SSYl f a r a s i n g l e s a t o f i n i t i a l conditions; MCROSS keeps t r a c k of t h e t o t a l number of Sot3 p o i n t s found for a l l i n i t i a l c o n d i t i o n s
c~CcccccGeeecCcccccccceccccccceecccccccccccccececceccccccccccccceccccc~c C Global v a r i a b l e s :
INCLUDE "O.ALLC INCLUDE "PAW.E2" C Passed v a r i a b l e s : m& SSV ( M S $ ),SSPY I m X S S ) Isurface of s e c t i o n p o i n t s ( o u t p u t ) INTEGER NCROSS ! t o t a l n w s r of S05 c r o s s i n g s ( 3 / 0 ) C Local v a r i a b l e s :
mm
T
MAL V m f 4 f m& OLDVm 44) I N m G E R NLf NES INTEGER NBEGXN LaGICAL CROSS =L PY-X INTEGER MOW INTEGER TV= REAL TSTOP IPTmGER SCWEN INmGER PAPER INmGER FILE C Functions:
!t i m
? c o o r d i n a t e s and momnta !previous v a l u e s of VAR !nu&er of l i n e s w r i t t e n t o t e r m i n a l !index of f i r s t SOS p o i n t f o r c u r r e n t i n i t eond lhave w e j u s t c r o s s e d a SOS? I l i m i t s on PV f o r t h i s E !how many more SOS p a i n t s ? !dependent v a r i a b l e index ! t i m e a t l a s t stop i n integration !send t a t e r m i n a l !make a hardcopy !send t o a f i l e
!get intagereboolean input from screen INmGER GETSMT, YESNO REAL V !potential function %AL GETFLT !get real input from screen DATA S C ~ E M , P W P E R , F E L E / 1 , Z 1 3 /
cccccccccccccceccccecccceccccccecceeecccc"~cce~ccccccccccccccccceeC:~c~c~c C
prGmpt fox: initial V and PT; obtain PX from E n e r g y conservation WRITE (OURIT,*)
"
%RITE (OUNXT, * ) ' X n p t inf tial conditions (recall X501 :' WltX"f {(OUEJIT, * l ' ' Entar faitiar va1wa for ye)
C C
output s u m a r y o f parameters XF ( ( T T E M ) AHD , ( .MOT, GTERM) ) CALL PWGUT ( O m I T , NLINES, V?Rj
.
IF (TFPLE) CaLL PRMOUlC (TUNIT, NLlCNES, V-) EF { W I L E ) CALL PMOUT (GUNIT, NLIN&S,VAR)
setup initial values DO 5 0 0 I V m = 1 , 4 OLDVm f XV&R) =VAR ( IVARf CONTINUE T=0. TSTOP=T NBE-f;ZEs=wCROSS+l XF ( T m J C T ) GALL TRJXNTtTDEVI
!prepare for graphing traj
I F (.NOT. GTERMf TWEW IF (TTERM) e a L L PAUSE f p to continue, I F (TTERM) CALL C m R ELSE CALL GRFOUT(SCREEN,SSY,SSPY,MBEGSN) END I F
..',,3 J ?graph SOS points
see if user wishes more SOS p a i n t s CA=
CLEAR
MQm=GETINT(O,O,WSS-NSOS,'Wow NSOS=NSOS+MOm I F (MORE ,GT. O f TEEN NLIPJES=O XP ( T M J C T ) GALL TRJGNT (TDEV) TSTOPmT GOTO 5 0 EMD I F
m n y more 502% p o i n r ~ ? ~ )
260
B* P~ogramsfor the EzckmpTes C
g r a p h i c s o u t p u t t o a f i l e , once p e r i n i t i a l ~ o n d f t i o n I F (GFXLE) CALL GMOUT (FILE, SSYf SSPVIEIBEGXN)
C RETURN END
cccccccccccCcccccceecccccccccccccccccccccccccccceccccccccccccccccccccccc SUBROUTINE STEP (T, VAR, OLDVAR, NCROSS, SSV, SSPY, NLINES TSTOP) C i n t e g r a t e s one t i m e s t e p and ehscks f o r SOS c r o s s i n g C f i n d s SSY and SSPY on s u r f a c e of s e c t i o n
ccccccccccceccccccccccccc~ccccccccccccccccccc~ec~ecccccccecccccccccccccc C Global v a r i a b l e s : INCLUDE "IQ. ALLr INCLUDE " PAMM,E2f C Passed. v a r i a b l e s : M U SSY (WXSS), SSPY ( m X S S ) INTEGER NCROSS REAL T -L VAR(4) =L OLDVM (41 INTEGER NLINES REAL TSTOP C Local v a r i a b l e s : LOGICAL CROSS REAL E,EPOT, EKXN INTEGER ETIME INTEGER IVAR C Function; REAL V INTEGER SCWEM INEGER PAPER INTEGER FILE DATA SCMEM, PAI?ER, FXU/1,
!surface of s e c t i o n p o i n t s ( o u t p u t ) ! t o t a l nuniber of SOS c r o s s i n g s (X/O) !rim ( X l Q ) ! c o o r d i n a t e s and moments [T/0) !previous v a l u e s of V= (I/O) Inurn of lines w r i t t e n t o t e r m i n a l ( l l 0 ) ! t i m e a t l a s t s t o p In i n t a g ( i n p u t )
fbave w e j u s t c r o s s e d a SOS? !energies ?nu&er of t i m s t e p s !dependent f u n c t i o n index !value af t h e p o t e n t i a l !send t a t e r m i n a l ! m k e a hardcopy !send t o a f i l e
ccccccccccc~c~cc~cecccccccccccccccecccccC:ccccccccccccccc~ccccccc~ccccccc
=as@=.EUSE. IP=wTSm
!tab a
-K*ta
statpi
G
1), V m ( 2 )? ) * * 2 t W (4)**2)1 2 - 0
leralauliate ana=Alas
C I F (TRAJCTf THEN !output t r a j e c t o r i e s , b u t o n l y ITIME=(T-TSTQPIITSTEP !for a finrited t i m e I F ((ITINE .EQ, NTRJ+I) .AND. (TDEV .EQ, SCmENlf THEH CALL 105JeE: !let user know we're s t i l l i n t e g ELSE XI?' (XTIm -LE, NTRJ) THEM CALL TR30UT(VAR,QLDVARJ !output t r a j e c t o r i e s END TP END I F
e !&ck;
e
for so@ cz~seSng
I:
M)
)==(mm) 100
COrnXrn
C
(moss) !gin& 50s crooslinc~m& oukpk r a d C a ~~afPS~B~Ss.t.1 !ifin& 8SV and SSPY R W a (-SS, m,Q & D W ) !@tom SOS inlaraerction@ SSul (H-OSS) =W(P)
33'
!=sat old vaueo
IF ((TDEV .NE, S C m E N ) .&BID. (TTEW)) CALL TXTOUT (OUNIT*T, E, EPOT, EKf16, XVtf16E51 !text output IF (TFILE) CALL TXTOUT TUN^ T, T,E, EFQT,ERININLIXJE5j
+
ErJDZE G
=TURN
END
~~~~~~~~~~~c~~l~e~~e~ccc~c~cc~~c~cccccccccccccce~ccc( SUBROUTINE RUN= (CRQSS,V M , OLDVAR] C u s e s 4th o r d e r Rung@-Kutta a l g o r i t h m t o i n t e g r a t e t h e G f o u r coupled ODE'S: C t h e independent v a r i a b l e is determined by t h e v a l u e of CRQSS
ccceecccccccccccccceccccccccccccccccccccec~ccccccccccccccccecccc~cccccc~ C Global v a r i a b l e s :
INCLUDE ' PkmM. E2@ C Passed v a r i a b l e s :
LOGIC= CRQSS RE= V M f 4 f REAL OLDVAR 14 f C Local v a r i a b l e s : mAL F ( 4 f REAL K l ( 4 f ,R2(4),K3(9),R40 mAL X INTEGER I
!is t h i s t o f i n d sos c r o s s i n g ? ( i n p u t ) ! c o o r d i n a t e s and momenta { o u t p u t ) !previous v a l u e s of Vmtlnyzut) !derivatives lincremnts !step size? ?dependent v a r i a b l e index
eccCcccccCcccccccccccccccccccececcccccccccccccccceeecccecccccce:ccccccccc *TSW C
X%(X) =E*F {S f
v~{I~~mm(I)+ (I] x1l2 . Q %Q0
COgTZm
C
D6 200 X=%, 4 I2 (X) =E*F (X)
v=
( 2 )=OLDVrn (X) +E2 (X) 1 2 . 0
262
B, Pr~granasfor the Ezamples 290
COmIm
C
K3 (I)=R*F (X) VAB (Z)&LW= (I)+R3 (X) 300
CQWXm
C DO 400 I=%,4 nr (11=M*E(3) (X)
400
+ (X2 ( X ) +2*K2 (X)+2*K3 (1:)+K1 (3)) / 6
CWZIlLifm
c RETURN
END CGCCCCG@CCCCCCCCCCCCCGCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCCCCCCCCCCCCC~CCCCCCC SUBROUTINE EVAL (F,VAR, CROSS 1 C E v a l u a t e d e r i v a t i v e s F e v a l u a t e d a t VAR C The independent v a r i a b l e i s determined by CROSS
cccccecccCcccce~tccccccccccccccccccccceecccccccccccccceccccccccccccccccc C Passed variables:
WAL VAR ( 4 ) m A L Ff4) LOGICAL CROSS C Local v a r i a b l e s : RBAL DIENON C Functions: REAL XDERIV,YDERSV
!variables (input) ! d e r i v a t i v e s of v a r i a b l e s (output1 !is t h i s f a r a s u r f a c e of s e c t i o n ? ( l n p u t ) ! f a c t o r t o caXe SQS !X
and y d e r i v a t i v e s of the p o t e n t i a l
ccccCc~c~c~ccec~ccce~c~ccccccccccccccecc~c~cccccccccccccc"cccccccccc~c C
&o iZnd swzfrcrr o f rrocrtion, aZ3, dmrZvoltAvarr .*re d i v i b d by EX:
DmoM=2' 0 XF (-0ss)
DENQWm(3)
C
P ( 2 )*a(4)/DESOM
( m ( r j,-(g)
(m
8
/ama~ (2) 1 /Dma
C =TURN
END
cccccccccccccccccccccecccceccccccccccccccccccecccecceccccccccccccccccccc RE& FUNCTION V ( X , Y 1 C CalculaGes t h e p o t e n t i a l and f o r c e s
c C
If you change t h e p o t e n t i a l , you may a l s o need t o change DYO and TQLY
C f o r Y l i m i t s e a r c h e s , as w e l l a s l i m i t s f o r X and Y i n TRJINT
ccccecccCcccc~ccccccccccccecccccececcccccccccccccccccccccccccccccccccccc C
Passed v a r i a b l e s :
REAL X.Y C Functions:
mhL XDERIV,UDERIV
!coordinates !X
and y d e r i v a t i v e s of the p o t e n t i a l
~c~c~ccccccc~ce~~~~~e~c~cccccc~ccecccecccccecccccccccceeeccccccccccccc V= (X**2+Y**Z)
/2+X**2*V-Y**3/3
C
C
=F-
e END
ecc~ec~c~~c~c~~~~~cceccec~ccccccccccccceccc~ccccccccccecc~cc~cccccc SUBROUTINE LIMXTS C Find l i m i t s on U from energy c o n s e r v a t i o n u s i n g a s i n p l e s e a r c h C This l i m i t i s a n t h e s u r f a c e o f s e c t i o n where X=O,
~~c~~c~c~~~c~e~c~~c~ceccccccecccccccf:ecccecccccccccccccc~ccceccccc
RE&
! s t e p i n simple s e a r c h !potential (function)
DV
RE-AL V
Ccccccccccc~cecccceecccccccccccccccccccccccceccccccccccccccccccccccccccc !@a=*
atarGing a% 0
far
fa 1.
i a where all the
imcrall that: X=Q.O on SOS m f P
%a
tDT*rn*%QLY) C
8 sear& fozr
DTaYQ
1 .@E. I&XNIE) -H
rr
DYmDTl2. EHBfE ( o x e mTQLT)
~o
atncting a t O
!-H i a wbsra a21 the ?amarm i r potat2 eaers fm~a1 x d . 0 OR SOS
20
C RETURN
END
ccccc~ccccccceecccccececcccccceeccccccccccccccccccccceeccccccceecccccccc SUBROUTTHE SNIT C i n i t i a l i z e s c u n s t a n t s , d i s p l a y s header s c r e e n , C i n i t i a l i z e s a r r a y s f o r i n p u t parameters
cccc~ccccccccccccccccecccccccccceccecccccceccecccccccccccccccccccccccccc C Cfcbal variables:
XNCLUDE "Q.ALLe INCLUDE * m NENU,ALL' INCLUDE "PAMN.E2$ C! Local parameters: CWmCTERX80 DESCRP BImNSIQN DESCm (20) INmGER NHEAD,NTEXT,NGMPM
!program description In-er
of lines for each descriptian
eccccc~eceeeeccceccccccccc~ecccccccccE:ccccc~ccccccccc~c~cccccc~C:c~cc~e CALL
C C
SETUP
!get environment parameters
display header screen Zr DESCW (1) = "&&@LE DESCRP(2)= qrajectories in the Wenon-Neiles potentialf NWmD=2
C C
text output descriptfon DESCRPf3)m 'kinetic, potential, and total enerwi' BESCBP ( 4 1 = + %and percent change fn anerg?l at surface o f section crossing" ETTEXTmZ
C:
C
graphics output description DESCRPf5)= 'trajectory and surface of section" NGWH=X
c CALL READER (DESCW, NHEAD,NTEXT, NGRAPN 1 C!
C
calculate constants (used in search for limits on yl aYcz=a, I T o m = . 0005
e lcanstant part of =nu
(C=ALL mNU C
MTVPE 1 I S ) -FLOAT M P W T f 3 3 ) C Enter Energyf MTAG (13)= *Energyr
MLQLIM (131=Q. Q MWILIM ( 2 3 ) =l, 016. M W L S (13)=. 1 C:
H T W E f l41 =SKSP m m s (14)=35. C MTYPE (38) =FLQAT MPWPT 138) = 'Enter time stepf NTAG (38)= ' Time? step' MLOLfM(38)=. 000QI MWTLIM (38) =.2 mEats (38) 12
-.
G
NTYPE ( 39 ) -NUM MPMPT(39)= * E ~ t e e rn&er
of surface of section points"
MTAG(39)-
' N u h e r of s u r f a c e of s e c t i o n p o i n t s '
MLOLIM(39) 110 MMXLIM 4 3 9) ==SS MINTS (39)-100 C
MTYPE ( 4 0f =SKZP MRmLS (401 =GO.
C MSTRNG (MINTS (75) ) = eexmpl2. t x t C MTVPE ( 7 6 ) =SKIP mEA1;S (761=80. C
MSTRNG (MIWTS (86)) C
-
*exmpJ2,qrf *
M T E E (87f =NUM NPMPT(87)= ' E n t e r nu&er of p o i n t s i n t r a j e c t o r y t o p l o t ' MTAG (87) = 'Nu&er af p o i n t s i n t r a j e c t o r y R MLGLZM ( 87 f =B HHILIM (87)-10000 MINTS (87)-4080 f:
MTUPE ( 881 =SKIP M-LS (88) =$a.
C RETURN
END
cccccccccccccccceccccc~cecccccccccecccccecccccccceccccccccccccececcccccc SUBRQUTZIVE P C C C C C C
p t s p a r a m e t e r s from s c r e e n
e n d s p r o g r m on rewest closes old f i l e s maps m n u v a r i a b l e s t o program v a r i a b l e s o p e n s new f f les c a l c u l a t e s a91 d e r i v a t i v e parameters
ceecccccccceccccecccceccccccecceccccccccccceccccccccccceccccccccccccc~Cc C Global variables: INCLUDE * MENU. ALL"
C Local v a r i a b l e s : INTEGER SCMEN !send t o t e r m i n a l INTEGER PMER !make a haxdcogy INTEGER FILE ?send t o a f i l e C map h t u e e n m n u items and p a r a m e t e r s INmaR SE, ITSTEP, INSQS,TNTR3 P-METER (IE 23 ) TER (ITSTEP m38 1 P m m T E R (INSOS =39 ) P-METER (XNTRJ 87 1 C Function: WGSCBL LBGGVT ! c o n v e r t s 1 and O t o t r u e and f a l s e
-
266
B. Programs for the El~amples DATA SCREEM,PAPER,FTLE/1,2,31
CCCGCCCCCCGGCGCCCCCCCCCCCCCCCCCCCCCCCCCCCGCGGCCGCGCCCCCCCGCGCCCCCCCGCCCC C get input from terminal CALL CLEAR CALL ASK ( 1,ISTOP ) stop program if requested I F ( m A L S ( I m T N ) .EQ. S T W ) CALL FINISH close files if necessary IF (TNAm NE, NSTRNG (MINTS (ITHAHE)1 ) + CALL FLCLOS (TNAME, TUNIT) I F (GMAME .NE, MSTRNE (MIHTS (IGHAME) ) 1 + CALL FLCLOS (GMAm, GUNIT )
.
physical and numerical parameters E I N I T m m U S (IE) T S T E P = W A L S (ITSTEP 1 NSOS-MINTS (INSOS)
text output TTERM=LoGCVT (MINTS ( I T T E N ] 1
TFXLE=LOGCVT(MXHTS(ITX"XLE)l TMM-MSTRNCfMIHTS(ETNANE})
graphics outr>ut GTEM-LoGCVT f MINTS [IGTERNI 1 G m C P = L O C C V T (MINTS (XGXRf)] f
GFK~=LoC@VT(MINTS(IGFZLE]) GNM-HSTRNG (MINTS ( XGNAlulE) 1 HTRJmMINTS (INTRJ) trajectories ere output ONLY if graphics are available ( i t ' s too =eh data to output to a file) since traj can only go to one device, these are sent to the screen TMJCT=,FALSE. TBEV=O IF (GTERM) THEN TDEV=SCB&EN TMJCT=."TRUE. ELSE I F fGRRDCF) m N TDEVmPmER TMJCT=.TRUE. END I F
open f i l e s IF (TFILE) CALL PWPEM (TNAME,T m I T l I F (GFILE) CALL FWPEN(GMAm,GWZT) files may have been renamed
>
M S m G (MIWTS (ITN=) =THAm MSTRNC (MINTS ( IGrJAmf ) =ENAME
c a l c u l a t e CHIN and CMaX ( l i m i t s an Y on t h e s u r f a c e of s e c t i a n ) CALL LIMITS
C
G RETrnN
END
ccccccecccccceCccccccccccccccccccccccccccccecccccceccccccccecccccccc~ccc SUBROUTINE PMOUT (NUMXT, NLINES, V m ) C o u t p u t s parameter s u m a r y t o t h e s p e ~ i f i e du n i t
cecccecceccccccec~~ccccc~ccceccccccccccccccccccCccccccccccccccccccCcccc!~ C Global v a r i a b l e s :
INCLUDE "IQ.ELLLe INCLUDE CPAMM.E2" C Passed v a r i a b l e s : INTEGER MUNXT ZMTEGER NLINES MAL V M ( 4 ) C Lacal v a r i a b l e s : INTEGER Z
! u n i t nurnber Ear output ( i n p u t ) I n u h r of l i n e s w r i t t e n so f a r f I / O ) ! i n i t i a l v a l u e s of ~ o o r dand mamenta (1) !independent variaZIle index
ccccc!cccccccecccccccceeccecececccecI:ccccce~ccecccccccccccc~ccC:cc~ccccccc I F (MUNIT .EQ. OUNIT) CALL C M A R C
WTE WRITE WRITE m1TE WRITE mITE
fMUNIT,2f (MUNIT,4) (MUBIT, S) TSTEI? (MUMIT?la) EXNIT (MUNIT, 8 ) mIH, C M , SQRT (2"EXMZT) (MUNIT, 12) (VAR ( X I , I=I,I ) WRITE (NUNIT, 2)
e C
d i f f e r e n t header f o r t e x t and g r a p h i c s E f l e s XF (MUNIT -EQ. GWIT) THEN mTTE (MUNIT, 20) WTTE (MUMIT, 2 5 )
EUE mITE (MUNIT, 30) llaRITE (MUHIT, SS) mIm [PIUNIT, 4 0 ) RRITE {MUNIT, 2) END I F C
PlLXNESrll c! 2
FOmT
("1
4
FOmT
(I
6 8 12 20
+
Output from example 2: T r a j e ~ t o r i a si n t h e H e n ~ n - ~ ,
'HHeiles P o t e n t i a l * )
T f
Time step
, E12 * 5t
F O m T ( V m i n -rfF6.3, 5 X , # Y m x = f # F 6 , 3 , 5 X , T ~ m a x=%F6,3) FORMT ( @ X i n i t = " ,F6,3, 5X, ' YVPnSt-f ,F6.3, SX, ?PPX1.nit=f,F6.3, 45XI?PYinit=6,F6.3) F O M T (?X, 7 aon SOSC,? X I 'PY on SOSf 1 F 1 ,?X,
268
B. Programs for the Bzrampiles 30
+
35
40
F O M T (S~,'Time\,SX,~Binet1c~,4X,*Pot:ent1,a1,'~~X~~Total~, 7X,*P@rcentf} F O W T ( 2 3 ~ ,Energy', ,Gx, 9 n e r g y f 6X, e E n e r ~ t7% , @Change81 FamT {CJX, F ----\ H , -------F 4X, L--------5 GX, @
+
6X,
f
1
C
MTURW EWD
c~ccccccc~cccccecccccccccccccccccccccc~ccccccccccceccccc~cececccceeccccc SUBROUTINE TXTQUTfNUNIT,T,E,EPOT,EKfN,NLfNES] C writes o u t e n e r g y d a t a a t e a c h sos c r o s s i n g
cc~ecc~~~ecceccccc~cccccccecccc~c~cccE:f:cccccccccccC:C:eccc~ccccccce~e C Global v a r i a b l e s : INCLUDE 'fO.ALL* INCLUDE * PAMN E2' C Passed variables: T N m G E R MUNIT XWmGER NLIHES WaL E, &POT,EKIN RmL T
.
loutput u n i t s p e c i f i e r (I) !nu&er of l i n e s p r i n t e d t o s c r e e n (ZlC3) ! e n e r g i e s [X) ! t i m (1)
cCccecccccccccccccceececccccceeccccccccccc~ccccccceccceecceccecccccccccc C
C
if this is a new page, r e t y p e h e a d i n g s f F ((NLINES .EQ. 0) .AND, (MUHIT .EQ. OUIST)) TmN CALL CLEAR mIITE tMDNIT, 3 0 ) 'IrJRfTE (MUNIT, 35) m I T E (MUMIT, 40) m I T E (MUNIT, 2 ) NLImS=ILINES+4 else if s c r e e n i s f u l l , c l e a r s c r e e n a n d r e t y p h e a d i n g s ELSE TF f (MOD(NLIHES, TRMLIN-4 f .EQ. 0) + .AND. (MUNIT .EQ, OUNIT) 1 THEN CALL PAUSE['I;o c o n t i n u e , . . * , , l f CALL CLEAR mIm (MUMIT, 30) m I T E (MUNIT, 35) WTTE {MUNXT, 40) m I T E IMUWIT,2) NLXN&S=MLfNES+4 END IF
G mSTE (MUNIT, 20)T, EKIN, EPBT, E, ABS ( (E-EINIT) IEINIT)
c G
keep t r a c k o f p r i n t e d l i n e s o n l y f o r t e r m i n a l o u t p u t I F (MUNIT .EQ, OUNIT) NLINES=NLXRES+I
c 20
2 30 35 40
FORNAT (5XflPE12,5,3 (5X, aOF7.5) ,5X,3PESOt3) F O m T ("1 F O m T ($X, 'Time\ 9 X , * K i n e t i c t , 4XI @E"ot@nt:iaL* ,5 X , * T o t a l p , i ?X, 'P e r c e n t ' 1 PORMT (23X, "nargy' c6, 'Energyf I 6X, t E n e r w r , ?Xt 'Change8 1 F O R m T (9X, - - - - F , 9X, @ - - - - - - - I , 4X, ---------E, fjXt @
fjx* '
4"
1
c mTURN
END
eccccccccccecccCcc~cecccceccccecccccccceceec~ccccccccceececccccccccccccc SUBROUTINE GRFOUT (DEVICE,SS%'# SSDV,MBEGTNI C outputs surface of section from WBEGIN to N50S CCCCCGCCCCCG~CCGCCCCCCCC~CCCCCCCCCCC~CCCCCG~CCCCCGCCC~GCCCCCCCGCCCCCCCCC C Global parameters:
INCLUDE ' IQ,ALLt IWCLUBE V A m M . E2C INCLUDE *GWDAT*ALL" Xnput variables; INTEGER DEVICE RE& SSY (mXSS),SSPV ( W S S ) SNTEGBR MBEGIN G Local parameters: INTEGER I INTEGER SCWBN INTEaR PAPER INTEGER FILE DATA SCmEN, PAPER,FfLE/1,
?which devim i s being used? f Y and PY values on SOS !beginning SOS for these init cond !indexes SOS points !sand to terminal !make a hardcapy !sand to a file
ccccccceccccceecccccc~c~cccccecccc~ecccccceccecccccecccc~ceccccccccccccc C C C
messages far tba Lpatient IF (DEVICE .NE. SCREEN) WRZTE (OUNIT,100)
e
calculate paremters for graphing IF (DEVICE .NE* FIL;E) TWEN
G
!how many plots
'IJPLOT=iE IPLOTm2
e e
if both screen and gapes are usad , only SOS axe sent tc paper IF I (GTERM) .MD. (DEVICE EQ, PAPER)) TWEN WPLOT=1. XPLOTmP GTDEV (DEV~CE~ !device nomination END IF
.
C (2"EINIT1 YMIM=-YmX xmx=eMAX XMIN=CMf;E;I YOVAL=CMIW VmX-SQRT
!hoxiz axis i s y ! v e r t axis is py
XOVAL=O.
C
EIPQINT=NSQS
c ILINE-S 1SYMm5 f FREQ=l NXTICKm7
!line and symlr>ol styles !this choice gives uneanneeted dots
21"Q B. Pr~gramsfor .the Ez~mples NYTICK-7 C
IhlFO=" -EL (3,) =.."U" W E & (2)='PYf
c CALL L N L H m END I F C C
output r e s u l t s
IF (DEVICE .EQ. FILE) THEN WRITE (GUNIT, 70) (SSY ( I ) , SSPV (I)c I-NEEGfNt %SOS) ELSE CALL XUBLOT f SSY ,SSPY) END fF C
and qrapbing session I F (DEVICE .NE. FILE) CALL GPAGEfDEVICE) ! c ~ o s eg r a p h i n g package IF (DEVICE .E@. SCREEN) CALL TMODE ! s w i t c h back t o t e x t mode
C
c 70 100
F O m T
(2f5X,E12.3))
F O m T l/,Vaatiencs,
please; o u t p u t gaing to a f i l e e e l
c RETURN END
cccccceccCccccccceeccccccccccccccccccccecccceccccccccccccccceecccecceccc SUBROUTINE TRJINT (DEVICE) C prepares t o g r a p h t r a j e c t o r i e s
ccccccccccccccccccccccccccccccecccccceeccccCcccccccecccccccccccccccccccc C!
Global p a r a m e t e r s : INCLUDE "0. ALL' INCLUDE GWDAT ,ALL1
C Input variables: INTEGER DEVICE
INTEGER LEN WAL X ( 4 t , Y x t ( 4 ) ZNTEGER SCmEW INTEGER P&PER INmGER FILE DATA SCaEN, PAPER, FTLE/1,2,3/
!which d e v i c e i s b e i n g used2 !energy as a c h a r a c t e r s t r i n g !length s f s t r i n g ! c o r n e r s of the t r i a n g l e Isand to t e r m l n a l !make a hardcopy !send ts a f i l e
cccc~cccccCccecccccccecccecccceccceccccecccccccccccccccecccceecccccccccc NPmT-2
?how m n y p l o t s
IPLoTml c YW-3.
YMIN=-, 5 X M = S O R T ( 3 . ) / 2. XMINm-XMX Y OVAL=O,
! c o r n e r s af bounding t r i a n g l e
XOV;AL=O, I :
NPOIMT-4 C
ILINEm1 ISYMm5. IFWQ=0 MXTICRm4 NY "I1CF[=4
?fine and s y d o l s t y l e s
C
CALL C O N m T (EINIT, CE, LEM) TXTLE=tHenon-Wailea P o t e n t i a l , Energym8//CE MBELflfs r X ' mBEL(2)='Yv' C
CALL GTDEV (DEVICE) I F (DEVICE .EB. CALL LNEhlAX
S W E N ) CALL GMODE
!device nomination !change t a g r a p h i c s made !draw axes
C X (l)= X M X V (1)=YMXN X (2)=XMIN Y (2) =YMXW X/3)=0. V (3) = Y W
!draw t h e bounding t r i a n g l e
X(.lrt=X(l)
V (4)=Y l l f CUL XYPLOT ( X , Y 1 C
RETURM END
cccccccccccceccccccccccccccececcccccccccccecccccccccccceccccecccccc"ccccc" SUBROUTIRE TRJOUT (V=, OLDVAR) one l i n e segment per c a l l
C outputs trajectory,
eccccceccccccccccccccccccccccccccceccccccccccccccccccccccccccccccccccccc C Global parameters: INCLUDE 'PARAN. E2 ' INCLUDE @GRFXIAT.=Lr C Input variables: mAL VAR 1 4 1 RE= OLDVm ( 4 1 C Local parameters: RE= X ( 2 ) , Y 1 2 1
! c o o r d i n a t e s and nomtpnta I p r e v i a u s v a l u e s of VAR !coordinates
c~eccccccceccecccccecceccceccccccccccccceceec~cccC:ccc~cccccccccccccccccc NOOINT-2 X (l)=OLBVM (2) Y (l} =OLDVAR (2) X (2)=Vrn(ll
Y 12) =VAR (2) GALL, XYOLOT (X,V)
rnTURN END
63. Pr~gmna9for the Ezamples CCCCCCCCCeCCCCCCCCCCCCCCCCCCCGGCCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGC SUBROUTZNE NOTICE C 1st u s e r know w a p r a s t i l l computing, even though t r a j e c t o r y i s r z f t C being p l o t t e d
ccc~ccccccccc~c~cccc~c~ccC:cc~ccccccccececcccccc~ccecc~ccccceccc~cccc C Global v a r i a b l e s :
INCLUDE GRFDAT,ALL* ZNFO=? S t i l l cornouting, b u t no l o n g e r p l o t t i n g CALL LEGEND =TURN
...@
END
ccccccCe~eCecCeecccccccccccccccecccccccccccceccccccccccccccccccccecceccc ccccccceceeccecceccceccccccceccccC:ccccc~ecceccccececccccccccecccc~~ceccc C param.c32
e
m& m= m=
TNTEGER NSOS REAL CMIN, CMX
! c o n s t a n t s f o r s e a r c h t o f i n d l i m i t s on y !i n i t i a l energy ! t i m e s t e p value tnunber of surface of s e c t i o n p o i n t s ! l i m i t s a n Y c o o r d i n a t e fox t h i s v a l u e of E
TRZIJCT INmGER TDEV I I m C E R 1VTR+T
Eare t r a j e c t o r i e s t o be p l o t t e d fwbera are t r a j e c t o r i e s t o be p l o t t e d l p o i n t s i n t r a j to b @ r o t t e d
DYO, TOLY EINIT
TSTEP
G
LOGIC=
e INTEGER =SS tmrzxirnum nunber o f s o s p o i n t s TER (mXSS=100QO)
c coma^ / C ~ N S T I / COWQM / W A M M I COMON / PCALG / C O m O M / TPLOT /
como~/ e P a w
nuo,Tol;i EZMIT
TSTEP,NSOS CMSN,CMX
TDEV,TRWJGT,NTRJ
B.3 Example 3 Algorithm This program finds the stationary state8 olt" the one-dimensional Schroedinger equation for a particle in a box (i.e., the potential goes to infinity at the edges of the lattice) with various shapes for the bottom. The parameter r,defined in the t a t , controls the daasical nat;nre of the system; the larger 7,the more classical the system. Three analytical foms of the potential bottom are available (subroutine P O T I ~ ) :square well, paraboBc, and Lennard-Jones. In addition, the square well can have a square bump, and the paratolic well can be flattened symmetrically about z = 0. The potentids are a i l normalized so that the minimum is at - 1, and the maximum (exclusive of the hard walls) is at +l. If you code in another potentid, be sure t o follow this conv~ntion.The minimam and nr~murnvduea of z are set in subroutine IBIT and axe digerent far each pdentid. Also in subroutiae PC)Tm, guesses are made for the ground state energy ( = a m ) and ground state energy spacing (DEBQT). These are based on the analyticlll values for the square asld paraboIic weus, m d sn a parabolic appro~mationfor the Zmard-Jmes potential, m d are funcr;ions of 7. ClElgm is aetually one 5fth of the expected spacing, and E& is t w energy steps belaw the expected pound state. The search win find the ground state energy if it starts with these vdues. If you code ia your own potentid, y m should dso code in appropriate vdues for E B O T a~ d DEBQT. lFor each level gought above the stwt;ing e n w g (IF loop 5 in subroutine nrcaor), a search is made to find the energy for which Eq. (3.23) is satisfied. A simple seuch is used until f changes sign, whereupon Lhe secant method is employed (IF loop 10 in subroutine ssn~ca).To find f for a given energy, the Schroedinger equation is integrated leftward and rightward (subroutine RUNERV) using the Numerov dgorithm, and the solutions are matched at the leftmost turning point (IF loop 1in subroutine IYUYIERV).The seafch normally stops when f becomes smaller than TOLF, but will also stop if DE becomes smaller than machine precision, or if the number of skps taken exceeds the vdae of EIAXSTPinput, This last feature is added t a dlow gracefd recovery from searches that have "gone wild"; thi~ situation is Ekely to anrise, for example, when t w levels are newly degenerate. When a search is tjnded, you have the option of finding another hvel or returning to the m&n menu. Subroutine DETAIL deterdaes the phwe of the wave function based on the procedure given in the text, counts the number of ~ a d e s ,and detects inteigat;ion into dassicdly forbidden re@oas,
274
IS, P~ograpnsfor the gzamples Input The physicd parameters are 7 [30] and the shape of the potential [Lennard-Jones]. The numericat p z m e t e r s are the matching tolerance [&.E-051(when f is smder than this value, the search ends), the number of lattice points [l601 whose upper limit is determined by the parameter WAXLhT= 1000, and the maximum number of search steps allowed [50]. At the beginning of each search you are prompted for a starting energy and energy step. If you have just left the main menu, the default vdues are E B O ~ Hand DEBoT from subroutine P O T m ; if you have just found a level, the default spaeing is the spacing used at the kginning of the most recent search, and the default energy is the sum of the eigenvalue just found and the default spaeing. The e n e r g is in units of the potential depth G* Output As the search proceeds, the progam output8 the energ, the energy spacing, f , and the number of nodes. In addition, the last column, Meled 'Wbrbddn", displays a "y~!s"if the integmim has entered a dassiedly forbidden re@on; otherwiw, a "no", W e n m &genvdue is found, the dgenvdue, number of nodes, and elassicd t;unti~gpoinf;~are At; the end of each se~wrch,the graphics display the poterrtid, disp1~1~red. all eigenvdues found since you lwt left the main menu (indicated on the g a p h by a line at; the appropriate level betweea the l&-most m& right-most turning points), and the current eigenfunction. A maximum of KAXUV.= 50 eigenvdues can be stored; if yau seach for mare levels, the earliest eigenvdues will be averwritten. c~c~cccccccccecceccec~ccccc~~ccccccc~cccc~e~~ce~c~ccc~ccccc~cc P R Q G W EXNPL3 C
C G C
E x m p l e 3: Bound states in a one-dimensional potential COmUTATIOEAL PNUSSCS (FORTMH VERSIQIJ)
by Steven E. Roonin and Dawn C. Meredith Copyright 1989, Addison-Wesley Publishing Company
CCCCCCGCCCCCCCCC~~CCCCCCCCf:CCC~C(31CCCCCCCCCCCCCCCCC(31CCCGCCCCCCCCCCCCC~CC~
5
CALL INXT CONTINUE CALL P A ~ M CALL BTtGf-ION
!display haades screen, setup parameters tmain loop; execute once for each sat of param !get input parameters !salve tim-independent Schroedinger equation
GQTO 5
EYD CCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCCCC SUBROUTINE MCBOhl C solves the time-independent Bchroedinger ewation for I-dimensional C potential; allows for m r e than one elganvalus search
~ccceCcccce~Ccc~~Cccccccccccccceccccccccc~ccc~ceccccc~~ccccccC~cccc C Glabal variables:
INCLUDE '10.ALL2 INCLUDE ' P m M . E 3 * e Lacal variables: mAL ENERGY ( m X m V ) INTEGER LEFTTP ( W L E V ) ,RGXTTP ( INmGER NFOUND PSI (mXXIPIT) INTEGER ITER INTEGER NOIZaS RE& E XMTEGER LTP, RTP WAZ DE, DESAm INTEGER NSTP INTEGER SCaEN INTEGER PWER INTEGER FILE C Functions: WAL GETFLT INTEGER mSMO DATA SCREEN,PMAPER,FILE/1,2,3/
!array of eigenvalues V) t a r r a g of t u r n i n g p o i n t s . n u a s o f l e v e l s found !wave f u n c t i o n !continue finding l e v e l s ? Inumber o f nodes ! t r i a l efgenenergy !classical turning points ( l a t t i c e ) ! s t e p i n enerc%y s e a r c h I n u d e r of s t e p s taken i n search !send t o terminal !make a hardcopy ?send t o a f i l e !obtain r e a l input ! o b t a i n y e s o r no i n p u t
e~~~~c~~ccccccc~~cccccccccecccceccccc~eccccccccceceeccccecccccccccccc~cc C
output s u m a r y o f parameters SF (TTBM) CALL PMOUT f OUNTT ) I F ( m I L E ) CALL PWOUT (TONIT) I F (GFILE1 CALL PMOUT (GUNTTI
C
ITERmJ. NFOUND=O EmEBOTTM DE=DEBOT C 5
~
(
X
~
! i n i t i a l i z e ssarchfng variables !reasonable s t a r t i n g values
e
B
Q
.
%
j
T
~
tZool, ever axurrw TaweIa
C
EsGETFLT (E, ENIN, E m , # E n t e r e n e r w P1 !get s t a r t i n g v a l u e s DE=GETFLTIDE,DE#XN,BE~X,@Enter s t e p i n e n e r w search1) DESAVEmDE: !save f o r n e x t l e v e l
C I F (TTERM1 CALL CTITL (OUNITl !output. t i t l e a I F (TFILE) CALL CTSTL (TUNIT)
(E,PE,Lm,R%%, Barns,W=,
-t=
ESX) t saarcrh
for anarm
p r o w t f o r new E and DE i f t o o many s t e p s t a k e n i n s e a r c h I F (NSTP .Cj&, M S T P ) THEN mZTE (QVMST,* ) ' ' m I T E (OSJMIT,*) E i g e n s t a t e n o t y e t foundr I TERmVESN0 ( 2 , *Do you want t o t r y a g a i n w i t h new E o r DE?#I ELSE o r output eigenvalue informn~tian SF (TTEm) CALL ROUT (E, LTP ,RTO ,NQDES,OUNIT f I F (TFSLE) CALL EOUT {E, LTP, RTP ,NODES, TUMZT)
I F (GFILE) CALL EOUT (E, LW, RTP,NODES, GUNIT) save e n e r m and t u r n i n g p o i n t s I F (NFQUND .EQ. WXLEVf T m N NFQUNEI=O S t o r a g e c a p a c i t y f o r l e v e l s exceeded* RRXTE (QIZNIT,* 1 m I T E (OUNIT,*J Old i n f o r m a t i o n w i l l b e a v e r w r i t t e n "
END XF NFOUND=HFOUNDtl ENERI;V (NFOmD)=E LEFTTP (NFOUND)=LTP RGWTTP (NFOUND)=RTP I F (TTERM) CALL PAUSE(%o c o n t i n u e , . . * , l )
I F (TTEW) CALL CLEAR I F lGTERNf THEN
!graphics autput
CALL GRFOUT(SCREEN,ENERGY,LEFTTPIRGHTTP~NFOUND~PSZ) CALL CLEZAR END I F SE (GFTLE) CALL GWOUT (F1LE, ENERGY, LEFTTP, RGHTTP NFOUNDIPSX) SF (GWRDCP) CALL GmQUT (PAPER, ENERGY LEFTTP ,RGXTTF ,NFQVND, PSX 1
-+
cheek i f a n o t h e r l e v e l is t o be found WXTE (OUMXT,*) C " mZTE fOUNTT,*) " f C
END I F C
E=E+DESAW DEmDESA-
t r e a s o n a b l e s t a r t i n g v a l u e s f o r next l e v e l
c G 1 0 m5
zm m c RETURN END
~ccc~~C~ccccc~cccec.ccc~ccC:C:cccccccceccccccccccc~ccccc~c~cc~ccc~ccc SUBROUTINE SEARCH (E, DE, LTP, RTB, NQDES, NSTP PSI 1 C search f o r one e i g e n v a l u e b e g i n n i n g w i t h e n s r s E and step DE
cccccccccccccccccccccccccccccccccccceccccccccCcccccccccccccccccccccccccc C Global v a r i a b l e s : INCLUDE "%O.ALL6 INCLUDE ? P m M . E 3 ' G Passed v a r f a b l e s : INTEGER NODES WAL E INTEGER LTP ,RTP m L DE INTEGER NSTP REAL PSI (mXULT1
!nu-r
of nodas ( o u t p u t )
!t r i a l e i g e n e n e r g y ,
t r u e e i g e n e n e r g y (XL01 I c l a s s i e a l t u r n i n g p o i n t s flatt;fc@)(output) f step i n e n e r g y s e a r c h ( i n p u t ) !nu&er s f steps t a k e n i n s e a r c h ( o u t p u t ) !wave f u n c t i o n f o u t p u t )
C Local v a r i a b l e s : LOGICAL SECANT REU F,FOLD, PSTmT
EQLD INTEGER NCROSS LOGICAL FXRST XNmGER NLINES C Functions: REAL GETFLT
M&
!are w e doing s e c a n t search yet? !values of t h e mismatch ! l a s t value o f t h e e n e r w lelassleally forbidden r e g i o n s ! s i g n a l first seep in search ! n u d e s of f i n e s s e n t t o s c r e e n
!obtain real i n p u t
ccccccc~ccccccccc~ccccccccceececCf:cceccccee~ceeccccf:cccececccecccccC:cccc FZmZ=.=m. Bgmz=*FmE*
Ibirat (=.a28t o M
P=WW
!
for k h l a h w e l
vaXw to gat fa&@ loep
mzms=2 HSrn=O
C C C
3.0
s e a z d f o ~~i g e n e a a wune25 F 3.8 8-22 IJtmpa t&aa
dmeugh or toe
XF [[rnStPj .a*z a m ) . m D * (MSZP .L%* W S W ) l R9m=Bsm+2
%mm
C
m
FSFmT-F Bf Fame
.
X?#
TF ( ( B E m T " E W * .%R=.) .mD. (F Dm-F* (E-EOm) / {F-ETOLD)
Em
.m,
Fa=))
TmM
m
SF ( T T E W ) CBLL TXTOUT f OUNIT, E, D&, F,%ODESIEICROSSr MLINES 1 %F (TFEm) CALL TXTQUT (TUNIT, E, DE, F, NQDES, HCROSS,HLXNES]
end sear* f f DE i s sa2ler than. m-lne pmoision ZF ( (mS(DE) .L%!. D@=&) .&.RD. [=B (F) ,O%, TOW) l I"mI =TB (OmXT,20) Fa-9 ( f Q', 21X, p BeZta E i8 too a-52, seareb mst atop' ) EI=ZIOW/Z ? w a r m to search END IF
278
B, Progmnzs for tke Ezana_pfes 60iC8
BMD
l0
m
C
MTURN END
ccceccccccccccccccceeccccccccccceccceccccccccccccccccccccecccccccccccccc SUBROUTINE MUmRV fF,NODES,E,LTP,RTP,WCROSS,FIRST,PSI) C subroutine ta integrate time independent Schroedinger ewation C with energy=E cCcCCCCcCcccccCeccccCCcGccCeecccCCeCccccCCCCCcCCcCceeccccccccccccc~ccccc C Global variables: INCLUDE 'PhMM.E3' C Passed variables: !size of mismatch (output) REAL F INTEGER NODES ! n W e r o f nodes (output) RE& E !trial eigenvalus (input) !efassical turning points (output) INTEGER LTP ,RTP INmCER %CROSS !classically forbidden regions (output) LOGICAL FIRST !signal first step in search (output) RE= PSI (MXLAT) !wave funet%on f output) C Loeal varltlbles: !matching lattice point INTEGER I M T C H !useful constant REAL C INmGER EX, XX ! X indices K1,RIM1,KIP1 !terns in Numerov algorithm !norm of wave function MllL N O W REAL PMMTCH,PPMTCN ! P S I at match point LWICAL FLIP !do we need to flip sign of F51 ! m a value of wave function Real PSTmX
ccccccccecccccccccccccecccccccccccccccccccccecccc~~cccccc~cecccccc~ccCcc (B-P .fbQV, ,mm.] fm%a=0 I e i p a l r 8aaxab Effor Immkf C= (DX*DX/f21 *
fsvaluatr aon+tm%
G
C
fin& XmTCB onas psr e n a z a 1awe1 by fookiag for a n k q into clraaicalXy 1CorbSdhn reg%aa
1
mm&* (E-V(SX) ) ra ( X m T e a .@Q. 0)
C
Xx=l rn=IZ+f Inrscj valm a% K lnaeatsrar olrata f z m region .m. 01 X ~ Z C W = I X : otbrr pze&wa faiZ8 to find f m T C H , raC X=TCH=W1"S-10
m<*{E-V(XX))
m ( (~ic~&xzm .%T, a) . m ~ .
C
jltP
m
{ZZ .EQ.
mzs-lQ)x m T c H = n
kfXm=KX WTO 1
EHD XF G
PST (l)=O B S I (2).x9, P99999E-10 X T M t e * ($-V (3)) KTe* (E-Vf P f )
c
TU)
zew a l g o x i t h ; S=O; int;agratlrr u n t i l eatss a l a s @ , fz-. reggon 10 3Xm2, f =Tea3 1 E r a x e * (E-v (zxs.~) asx (xx+i) (asx (xx) * (2.-30. *Ex) -PSZ [XI(:-I~* ( 1 + m m f / ~ X + E X P ~ ) Em=Ef troZl value. of K*X: Kf &zEl i f 953 gzowo too l a r g e z e s a a l e a11 p r e v i o u ~p o i n t s X&? (=S (PSI (fXS.1)) OT (2.5E+10) ) T m M) 2Q ==2,=+1, PSX (a) .PLeSI (a) *S. 999999E-06
. .
cowxsm
Ern SE" COMPXm PrnCBmP ss ( z a z c a ) !rhe beundary e o a d f t i o n ~
PSX (WZIS)=O PSf (WTS-1) =9.999998&-10 A I P I e * ($-V (mTS) ) K X e * (E-V(=TB-I) )
!&nitiaZ IC*A vauerr
M) 30 ZXmWT8-1, =2CH+2, E w e * (&-V (=-l) )
-1
R s Z (XX-l)m (PS%(aX)* (2. -10 *KT) -EOX [3X+l) * (X+fCIPl)) / (1+IImZ) KfEl=Kf trolX v a l u e s o f R*K Kz=xfm i f POX grow8 t o o Zarge reecpZs %If pzeviouis p o i n t s ) GT, (1, OE+lO) ) T m M DQ 40 ===%S-2, m-1, -1 ESI (m)=PSZ (m)*S. 999999P1-Q6
I:.F ( M S (PS%(XX-Zj
.
caR%mm
Brn
XF
CONTXNW
EI:m&*(E-V (X=TCB-%) ) c k c i f o r l o g &+iv P P ~ G B -(asx (rmFeE) * ( 2 - 3 , ~ * a ~-PSI ) ( Z ~ T C H +*Z~IX + K X P Z1~f { ~ + ~ C I M T ~ HOW=PmCB/PSX (I=%-) DO S m=mTCE,'1SPfeS PSI ( 3 X f =PBX f XX) *HOW
f no=
PSI: right; t o PSf l e f t
comxm fnmcR=aPma*wQ~ I i n d nodms, e w n f n g p o i a t a , e n t r y I n t o eZasaIcally tie& regiona and &%te&na i f m e r a l l s i g n ansat h f l i w d DBTmL (XMTa, NODES, E L%Pt R=, NCROSS I Bmr"CBIFLXP I BfW T , PSZ1 1t.m and f l i p s i p i f neaaasary 86 7 I X m 1 , PJPZS
XE'
7
(=B (PSf ( X X ) )
.GT.
PS
%P tF&IP .gm* .%R-* 1 R CQrnINrn TF (mXE) EPM%CB=-PPMXH
C
levrluats mkcrhLng conation
C =TURN END CCCCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCCCC
SUBROUTLNE DET&IL ( I m T C W , NODES,E, LTPIRTP, NCROSS@PWTCH, FLIP,FXRST, PS5j C subroutine to ealclulates nodes, turning points, entrqr C into classically forbidden regions, and whether or not the C overall sign of P S I must be flipped to make F continuous function of E
+
CCCCC6CGCCCCCCCCC6CCCCCCCCCGCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCCC !C Global variables: INCLUDE C P N M . E 3 ' C Passed variables: INTEGER TmTCN !matching Jattiee point (input) INTEGER NODES !number of nodes (output) ReAL E !trial eigenvalue (input) INTEGER LTP, RTP !classical turning points foutputf IMTEGER NCROSS !classically forbidden regions (output) RE& PMMTCM !PSI at match point (input) LOGICAL FIRST lsignal first step in search (input) L m I C A Z FLIP !do we need to flip sign o f PSI (output) M U PSI (mXLAT1 twave function (input) C Local variables: LOGIC& LSAME !does PS5 left retain its sign? !X index INTEGER TX W& K,KmST Iwavenu&ers INSEGER WLOLD,NLFT ?left nodes !right nodes XNmGER NRQLB, TttRT m A L PSXR, PSIL !sign of PSI which must be constant CGCCCCCCCCCCGCCCCCCCGCCCCCCCGGCCCCCGCCCCCCCCCCCCCCCGGCCCCCCCCCCCCCCCCCCC C fixid r sf nods. on ra& r i b mQLD=mT !save old valuse Xirst mammmT NrnF=Q
lzero
0
m-0 XZO 8 ==2,5=2CE-l !leg& .%&cl KlP (PBX 4ZX) *PSI (XX-l) LP. 0 ) HWT=m?P+3 CQmZm ra (as1 ( I ~ W E - I*~P m c a .%F. of wmT=wge+n M3 50 ~ = K m T G B S 1 , ~ T i S I ?rSgb& aid+
.
8
10
r~ (esz (m)*PSI(EX-W .LT. c m z m
01
mg=mg+r
C
C C C
desk f o r a h w e in noi% ens aide of tkrrn wave tbaC &Act% m s t d n t a g n
Raa galned a node, afw htween irkalp@
now, f%noflg, &lsdn%i f the
mm=.F==.
.-D,
+
.
ram v&ms bor rkrp 9sxmPsrx (2 1 asn=psr (=vs-%) m (mxre) asxm-laaxr,
m
(PLxa)
asrw-ssxa
zind rigkkmot turning pia*
Rm=a m~Zs.tl
(Rm *m.0 ) TmH Xz=xx-% ZF 4 (E-V{a).a. Q) Rm=ZX mm 120
za
mlig
.
(nsxlt*nsr( 2 ) tr. o ) FGZP-. mm. .m. (PsrR*psr(wrs-11 .LT. Q. 1
)
F&a=*mm*
nseds to be f3ippad
282;
B, Progmms for the Eszamples C RETURN
END
cccccccccccccccecccccccceccccccccccceccccccccccccccccccccccccccc~ccccccc C
C C
C C C
SUBROUTINE POTMTL sets up array for current potential; all. potentials have a dnimum value o f -1 and max of 1; if you change the potential, also change XMSN and XPlAX in INIT, and estimate DEBOT and EBQTTM (one fifth of the expected spacing at the bottom of the well, and two DEBQT% below the expected ground state energy).
ccecccccccc~cecececccccccccccccceccceeccccccececcccccccccccccccccccccccc C Global variables: INCLUDE PMM,E3' C Local variables: INTEGER ILEFT,SISJID,IRIGBT RE=
VSGALE
IWmGER IX VMIN =&L GURW
!lattice values for width, left !scaling faetor for renorm of parab I l a h Z s lattice points ?minimum value of: potential !curvature for smoothing bump
ccccccccccccccccecccC:cccccccccccccccccccccccccceccccccce~cccccc~cccccccc C &sane 2lidt;s on X and DX
33' (POT .EQ.
EHB 33' C
H)/ (taees-1) C C
f
C C
10
getup If (=I- @eerdina%e)array DO 5 X (EX) .c (m-l)*W
cmmm
setup V (pcl.tea%id) =ray IB (P6E .BQ. S Q U m ) %=H BC! 10 TX=l,mllS V {IX)m-3. CoHrTWm
f ~ p a M~B%% a
1* 2* (3,1415926/(4* .BQ, 1) %=I XWP=ErnT { (mP%-~Xlfl) I S.,
SE" (B-
RIQHTmX (ZmGHF) -%=X
(ImF1C)
I
h well bottm
edge&
cm==-. o m / 4 (maaz-m~j / a 4 **2 top ~f
C
is
t o avoid &naenLimit;ier
V (ZZ)U-1,+ ~ X W Z (2,. *
(X(=)
R
fma%+WT1/2.) **g)
20
Brn IB C
E m 33' (POT .BO.
t g r r m %G f mr13
f
W 30 ZX=l,mTO v (XZ) m- (1* $*X (%X)*X
-.
(m) 1
4.
l 3
.EQ. X) ths parrbolic potential i r f 2 a t t a ~ l d m W Z M T (EmD/DX) ZR (HOD (=D,
2) .m. MQD (MP%#, 2) ) =-=P-l D)/Z+l
40
e Db 50 ZZ=l,mfS
so
cOB%xm
m m
C =g12
IE (801: .Ea. M m ) IfmM m=%, =TB
f Umrzd-amaa w e n t i r l
W 60
bQ
tenmrm apcaing a t we12 bott~lla (&re Ex. 2.8) G
Ern XIF C= C
G
-mated gua@rarfor we-& @Later a a z a mamzm @p&aimg; wkkh therm valwaa, it wiz1 L&* thzrr, ntqm ZOE P d0 riqn ~ ~ ~ - 1 . + 2 . J * B ~ F
C
=TURN END
cccccccccccccccccccccceccccccccccccccccccccccccecccecccccceccccccccceccc SUBROUTINE INIT C i n i t i a l i z e s c o n s t a n t s , d i s p l a y s header screen, C i n i t i a l i z e s a r r a y s for input parameters
ccccccccccee~cccec~ccccecceccccccccccecccccccc~ccccccccccccccccccccccc~c G Global variables:
INCLUDE 'IOIALLe INCLUDE ' MEMU. ALL'
284
B. Programs for the Ezamples
!program d e s c r i p t i o n DXmNSTQN DESCRP f 221
IHTEGER NBEAD,NTEXT.NGRF
!number of l i n e s f o r e a c h d e s c r i p t i o n
CCCCCCCCCCCCCCCGCCCCC:CCCCGCCCCGCCCCCCCCCC:CCCGCCGCCCGCCCCCGCCCCCCCCCCCCCC CA= SETUP !get environment p a s a m t e r s
e C
C C
display header screen DESCRP ( 11 p EX-LE 3 DESCRPt2f= 'B~ound s t a t e s An a one-dimensional p o t e n t i a l t NEmD-2 t e x t output description DESCW(3)- ' d u r i n g seagch: e n e r w , d e l t a energy, d i s c o n t i n u i t y , ' DESGRP(4)=6nadas, and e n t r a n c e i n t o c l a s s i c a l l y f o r b i d d e n r e g i o n s r DESCRP(S)= ' a f t e r s e a r c h : e n e r w , c l a s s i c a l t u r n i n g p o i n t s , " + //"umber o f nodes6 NTEXT=3
C g r a p h i c s output d e s c r i p t i o n DESCm(6f- "potential, e i g e n v a l u e s , and e i g e n f u n c t i o n s ' XdGW=l. setup constant values f o r t h e potentials f a l l p o t e n t i a l s havs VIJIINm-1, V W = 1 XNINl=-2. XWI-2, XMXM2=-2. XM2-2. X%IN3=12.* (SQRT[21)-1.)j**t.1666666) XM3=1.9 r e a s o n a b l e l i m i t s on energy and e n e r g y Increment
EMIN=-.99999 EM-lO0.
DEMIWm5.E-06 DEM=1, GALL WEEhDER f DESCRP ,NNmD, NTEXT, HGBF) CALL MEMU
! s a t u p c o n s t a n t p a r t o f haadar
NTWE (1I ) =TITLE WMPT
(14 ) = * POTENTIAL FUMCTION =MUt
NLOLSN (14)=2, MHZLIM (14)=1.
C %TYPEf 15)=MTSTLE W W T (15) -'1 ) Square-well p o t e n t i a l p MLOLIM (25)-0. NNILIM(~S)-O. C MTYPE (1G) =MTTTLE E W T (16) ='2) Patabof i c - w e l l p o t e n t i a l " MLOLIM (16)90. MWILIH (16f =Q.
G MTYPE (17)=MTITLE M P W T (171-'3 ) Lennard-Janes p o t e n t i a l *
MLOLTM (2.7)=Q. MWILIM(17f-l.
c MTYPE f 1 8 ) =HCWOXc W W T ( 1 B ) m 'Make menu c h a f c e and p r e s s R e t u r n r MTAG(18)='19 24 26' MLOLIM (18 1 =l. MMIL1M ( 18 1 =3. MTNTS ( 28 ) -3 W A L S (28) 4.3. C MTICP&62 9)=NOSKIP W m P T ( 1 9 ) = 'Do you want a bump i n t h e s q u a r e w e l l ? ' MTAG (2 9)= Square R e l l Bump: ' m m ~(19) s -35. MINTS (19)=O C NTIVPE (2 0 ) =FLOAT NPmPT(20)= ' E n t e r t h e l e f t hand e d g e o f bump (scaled u n i t s ) ' MTAG (20)m "eft hand edge o f bump ( s c a l e d u n i t s ) ' MLOLIM (20) -XMINI MHILIM (20) =XmX1 MREALS (20) m-. 1 C
MTYPE (21) -FLOAT M P W T ( 2 1 ) = ' E n t e r t h e r i g h t hand e d g e o f bump ( s c a l e d u n i t s ) ' MTAG(21)= @ R i g h thand e d g e of bump ( s c a l e d u n i t s ) " MLQLIM ( 2 1) =XMTNL NWILIM (211 = X m X 1
~s(zz)-.r
C
MTVPE (22) =FLOAT W W T ( 2 2 ) = ' E n t e r t h e h e i M t of t h e bump ( s e a l e d u n i t s ) " MTRG(22f = 'Weight o f t h e bump ( s e a l e d u n i t s ) @
W O L T M (22)=Q.
MHILTM (221 =20 MREALS (22) -1.
MTYPE (241=NOSKZP MPRMPT(24)= 'Do you want a flattened bottom i n pardwfic-well0 MTAG (24) = rParabolic Flattened area:' MFtEALS(24)=3S. MINTS (24) =0 mt'ypB (25) =FLOAT MPRMPli(25)= 'Enter length of! the flattened area (scaled units)' MTAG (25) = Length o f the frattened area (scaled units) HLOLXM (25 1-0 MHILXM (25) -XMAX2=-XMZN2 ImEaLs(25) =* 1
MmPB (38 =FM)AT WRMPP(38)= 'Enter the matching tolexancrec
'Matching tolsranca' WLoLIH (38) 15.E-06 MTAG (38) =
MHXLIM (38)=1.000 MREALs(38)=.00005
-
MTWE (39) -NUM WPRMPT(39) 'Enter number of l a t t i c e pointsf MTAG (39)- "Rumber of l a t t i c e pointsp MLOLfM(39) =SO WILXM (39) rzIIAxLAT MIWTS (39) =160
WXFE (40) =NUM MPRMPT(40)- 'Enter maximtan number of steps i n searcht MTAG(40)- f M a x i number ~ of searoh steps' MLOLIM (40 ) 110 MHILXM(4O) 1300 MINTS (401-50
W'PRNG (PIXITS (-75)) =
'exffqpl3. t x t '
LS (871 -90. C RETURN
END
c~~cccc~~~~~~~~~~~~cce~~ccccccccccccc~cccccccccccccccccc~
SUBROUTlNE n C g e t s parameters from screen e ends program an reguest c eJosas old files c m p s menu variables to program varlhles c apens new files C calculates all derivative parameters
ec~~~ce~~~~cc~~~ccec~c~~~e~~c~c~cc~c~cccc~ceE:cccec~c C Global variables: INCLUDE W N U M U , A L L e XMCLUDE ' 10.ALLr INCLUDE T W W . E 3 t
c Local variables: C
map &tween menu items and p a ~ a m f e r s INTEGER IGAMm,ITOm,INPTS,fPlrXSTP TNmGER IPOT,fSUW,I~FT,IHE,IGW,IRIGNT,TFMT,IE"WID
-
P A U E T E R (ITOER = 38 ) P m W T E R (INPTS 39 f P TER (XWXSTP = 40 }
C Functian: WGJCAL LWGVT !converts 1 and 0 to true and false CCCCCCCCCCCCCCCCCCCCCC~CCCC~~GCCCGCCC~C~C~~~~~~~~C C get input from terminal GAU C-R CALL ASK f l ,I S T O P )
ZIllm
cmm
C
stop program if requested
C
I F (MmALS(IE4AIN)
.EQ, STOP) CALL FXWPSH
c close f i f e s if necessary
C
IF (TNPIWE .HE.
MSmHG IMIMTS f ITNAME) )f CALL FLCLOS f TNAHE ,TUMITf IF 1 G N W NE MSmNG (MINTS ( TGWm) 1 1 + CALL FLCLOS (GMAm,GUMXT f
+
. .
c C
C
set new parameter values physical and numerical: G A W = M M A L S ( IG A m )
288
B. Programs f o r the Ezamples T O W = m A L S ( ITOLR) NPTS=MIWTS (LNPTS) WSTP=MIKTS (XMXSTP f
C C
potential parameters P O T f N W L S ( f POT) BUW=MIWTS (IBUMP) LEFT=MWALS (TZEFT ) RIGHT-mALS (IRIGXT) WEIGHT=MmALS f XHEssH) FLAT=HINTS (XELAT)
G
CALL PQTNTL
!setup p ~ t e ~ t i aalr r q
e C TTERH-LQGCVT (MINTS (ZTTERM) f TFXLE-LOGWT (MINTS (XTFILE j 1 TMMEoMSTRMG (MINTS l XTNAm) 1
G G
graphics output GTERM=LQGCVT (MINTS { ZGTERM] cnmcP=LacmrT(MINTS (IGWRDI1 GFmL,e=LwcvT ~ H X N T S(IGFTLE~1 GEm=MSTRNG (MINTS ( X G M A E 1 1
C C
openfiles I F [TFILE) CALL FWPEN (TNkm, TUMI T) I F (GFXLE) CALL FWPEM(GRAm,GUHXT)
!files may have been renamed MSTRNG (MINTS (XTNAW) t 5TFaA.m MSTRNG (MINTS [XGPsAm) 1 =ENAm G
RETURN EPJD
ecccccccCccccccccccecccccccccecccccccceccccccccecccccccccceccccccccccccc" SMROUTINE PRMOUT (NUNIT)
C outputs parameter sumary to the spcifiad unit
c~~~ce~ce~cccccccccceccccccccccccccccccccccccceceecccccccceccccccccc~cc C Global varfabfes: INCLUDE 'XO.ALLt INCLUDE 'PAmM.E3' C P a s s e d variables: INTEGER MUNLT RE&L VAR [ 4 1
!unit n u d e r f o r output !initial values of coosd and m o m n t a
ccccccccceccceececcccecccccccccccccceecccccccccccceccccecccccccecceecccc IF (MUNIT .&Q, OUNITI
C WRITE aITE KRXTE WRITE
(NUNTT, 2 1 (MUNST, -4)
(NUHIT,G) GAMME1 (MUNIT,8) TOLF
CALL eLEm
WRITE (NUHIT,12) NPTS C
IF
(POT .EQ. SQUmE) TWEN m Z T E (MUNIT,14) IF (Bum ,Ea. 2 ) WRITE (MUNIT,2 6) LEFT,RIGHT,EEIGHT ELSE ZF lPOT .EQ. P A W ) T m H mIT& (MUNIT,18) IF / P U T .EQ, 1) TnlXlITE (MUNIT,PO) -PWID,PWTD ELSE IF (POT .EQ. ZENRD) TWEN WRITE (MUHIT,22) END IF
G
m I T E fMUMIT,24)VXM?IIM,VXIIIYIIX,DX WRITE (MUNIT, 2 6) WRITE (NUNIT,2) C 2 4
FORMAT
('
FOWT
Ir atput from Exa-le qwation' )
i
t')
3: Time Zndependent Schroedingert8
FQ-T ("~enuna =*,,F9.3) FORMT (' Matching tolaran~e= ', IPE20.3) FORmT ( * Number of lattice points =\ 15) F a W T ("ware Well potentialr) FO~Tf~with~umpframr,,E"6.3,~o~,F6.3,toofheight=C,E'8.3) F O m T (' ParabaLZc potential') F O m T ( * with flat bottom from ',FB.J,' to ',F6,3) FORNGLT ( * Lennard-Jones potential'] FORWT f r Xmir\=',P6.3,~~ma=~,FB.3,* I>x==* ,lPE10,3) FORmT ( V ~ ~ e z g l eand a lengths are in scaled unitst)
6 8
12 14 26 18
20 22 24 26 C
WTUW EHD CCCCCC~CCCCCCCCCCC3GCCCCCGC~CCCCCGCCCCCCCGCCCCCCCCCCCCCCCCC~CCCCCCCCCGCCC
SWROUTINE GTXTLIMUNET) C wtites title for text output to xe~uesteddevice
cecceecccccccc~eccccccc~cccccccccccccccccccccccccccE:ccccccccccccccccc~cc C Passed variables: INTEGER MUNIT
!unit to which we are writing
cccccceccec~cccceececcccccccccceececccccccccececcecceccccccccccccccccccc (MUNIT,30) WRITE (NUNIT,35)
WRITE:
C 30
FOMT -c.
tlOX, 8E~ergqtt, l 4 X , 'Deft 16X, * F#,1Ox, t N ~ d a s,5xp r *Frbddnt1
FOmT
35 4"
(lax,
P
, 1 4 ~ ~, - - ~ , ~ ~ x , ' - I , J J IJ ) I ,
---I-
* , 5 ~ e.,,--r
1
C
RETURN END
~cec~ccc~cccccccccc~ccccceccccccccceeccccccccccccccccccccccccccccccccccc SUBRQUTIME TXTQUT (MUNIT,E,DE, F,MODES MCRQSS,NLINES1 C writes results for one level to rbe requested unit
290
B. Programs for the Ezamples ccccccccccceccccccceccccccccccccccccccceccccccccccc=ccccccccccccccccccccc C Global variables: INCLUDE *1SB.ALLe INCLUDE 'PWM.E3' C Input variables; INTEGER MUPjfT tunit to which we are writing !values of the dsmatch REAL F INTEGER NODES !nu&er of nodes MWL E !trial efgenenergy RE& DE !step in enerw search INTEGER NCROSS !classically forbidden regions CHmCTER*3 FQRBBN !have we integrated into forb regions INmGER NLINES !nuPnber of lines sent ta screen (I/O)
~ccccccccccccc~cccccccccI:e:cccccccC:cccccccccccccccccccec~ccecccccccec~ccc C
if sereen i s full, clear sGreen and retype headings IF ( (HQD (NLXNES,TWLXN-4) .Ea. 0) + .AND, (WEIT .EQ. OUNIT)) THEM CALL PAUSE(ftto continue l) CALL C-R CALL CTITL [QUNIT) NLINES-2 END XF
...*,
C
IF (NCRQSS .GT, 01 THEM F"QmDN='Yes* ELSE FORBDM-eNa END SF m 1 T E (MUNTT,20) E,DE,F,TJODES,FORBD# ULPNES=NLIN&S+I
c 20
F O m T
(8X,F10.7,7X,EPE20e3,7Xr1PEZOIJ,8Xrf2r8X,A3~
c =TURN END
ccccecccccccceccccccccccccccccccC:cccccccccc~cceecccecceccccccc~ccccccccc SUBROUTINE &OUT (E,LTP,RTP,NODESCMUNIT) C output information about eigenstate
ccccccccccccccccccccccccccccceccccecc~cccccccccccc C Global variables:
INCLUDE 'fID,ALLf INCLUDE 6PAm.E3' C Passed variables: INTEGER NUNTT SNTEGER NODES REAL E fNTEGER LTP,RTP m& XL-, XRTP
funit to which w e are writing fnuder of nodes !trial efgenenerw !cjlassi~alturning points (lattice) Iclassical turning points
ccccccccccccccccccCCeccccccccccccccccccecc~ccccccecccccc~ecccccccccccccccc XLTP=VXMTN+ (LTP-1)*DX XR3CP=aNIN+ (RTP-1)"DX m I T E (MUNTT,SOO) E, NODES
!turning paints
mITE (MUNIT, 53.0 ) XLTP, XRTP C 500
510
F Q m T f V 0 ' , 2 0 X , "igenvalue F,F10.3, V i t b ' , I 2 , ' nades.' 1 F Q W T (IGX,'and c l a s s i c a l t u r n i n g p o i n t s *,,F7.4,' and ',F7.4)
C
=TURN END
~c~e~~~c~~c~~c~~ecccceeec~ccccccecccccccI:cccccccccc~cccccc~~c~ SUBROUTINE GRFQuT(DEvIcE,E~RGY,ZEF~CTP,RGWTTP,NFQUMD,PSI) C o u t p u t s p o t e n t i a l and e i q e n v a l u s s ( p l o t l ) a n d e i g e n f u n c t i o n s ( p l o t 21
cec~cccccccccCccccccecccceccccceccccceccccccceecccccccee~eccccccccccccec C Global v a r i a b l e s INCLUDE 'IXO.ALLf
.
INCLUDE GRFDAT &Lf C Input variables: !which d e v i c e i s b e i n g used? INTEGER DEVICE ! a r r a y aE e i g e n v a l u s s mAL ENERGY ( D L E V ) IMTEGER LEFTTP f W L E V t ,RGWTTP (mXLEV) !a r r a y of t u r n i n g p o i n t s INTEGER NFOUESD !number o f l e v e l s found mAL PSI (MXMT) !wave f u n c t i o n C Local v a r i a b l e s !index of l a t t i c e INTEGER I X INmCER XLEVEZ !index o f e i g e n v a l u e l a r r a y s t o graph eigenvalue RE& XE (21,G W H E (2) CBmCTER* 9 CGAHM, CE ! G B X m , ENERGY a s a c h a r a c t e r s t r i n g ! l e n g t h af s t r i n g INmGER LEM RE& NOW, m P S % f n a r m and nrax v a l u e for PSI INTEGER SCmEIJ !send t o t e r m i n a l IBmGER PAPER !make a hardcopy ?send t o a f i f e INmGER FILE DATA SGREEN,PWPER,FILE/I, 2,31
cccc~ccc~ecc~c~~~cceccc~eccc~ccccE:ccecccccccc~cc~ceceecce~cc~cee !messages f o r t h e i n r p a t i e n t IF (DEVICE -ME. SCREEN) HRITE (OUNIT,Z00) C
10
NOm=O. BQ 10 IX=l, MPTS MORM=MORM+PSI ( f X I CONTINUE
**2
! n o r m a l i z e wave f u n c t i o n
NQW-58RT (NQRM*DX) WXPSI=O. DO 30 IX=l,NPTS
PSI (xx)=psrtrxt /NORM IF (ABS (PSI (IX)1 GT, mXPSI) mXPSI = WBS (PSI (IX) )
.
30
e
CONTINUE I F (DEVICE .NE. FILE) THEN NPLQT=2
!how many p l o t s ?
C1
G
p a r a m t e r s t h a t a r e t h e same f o r b o t h p l o t s XMINmVXMIN ! a x i s parameters
yo~qua3acl30rd i
,(s3yun payeos)
[&'XI
ZOqdlUS ??W
mH1MT T2V3 ssn~shuafifapue ~ o ~ ~ u a 3 o( 2d)?a[gw ~ r rmOdNT * O=TVAOX
" Z-=MfWt 513r01dT sen~enua6yapue ya~?ua?od : q a ~ d3srt3
m I T & (GUMIT, 801 W I T E f GUM1"P 85) m I T E (GUNIT,?QO) t X ( I X 1 ,V(XX),PSI (XX1,XX.-1,NPTS) END fF C C
end graphing session IF (DEVICE .NE. FILE) CALL GPAGEtDEVLGE) IF (DEVICE .EQ. SCMEN) CALL TMODE
!end graphing package ?switch to text made
C
100 80 85 70
F Q m T (/,-atience,
please; output going te a Tile,') ,93X,'PosStf onp,14XIC Potentialp, E3X, v function@1 ' --------' , ~-----...---~, 1 3 ~ C, f F O m T ( 3 (11X,IFE12.5) ) F O m T 4" 0 % F O m T (E3X,
--..---m
-
-m--"
c mTVRN END
ccccccecccccecccecccccccccceecccceccccccccccccccccCcccccccccccccCccccccc ccccccce~cccccccceccccccccccccccecccececccecceccccceccec"ecceecceccc~cccc C param.e3 C
RE=
T
INmGER W T S
XW"LTEGER MaXSTP
!degree of "antumness* ?tolerance in search !nu&er aE lattice paints ?m= nu&er of steps in search
e XNTEGER MXLWT
!maximum n u h r aE lattice points
TER ( W m T = f Q O O f C
XWTEGER s Q u A ~ , P ~ B , L E ~ ~ ~!potential RB types
PARAMETER (PAW-2 1 C
INTEGER POT f ukicb potential INmGER BW,FLAT !which features do we want BE= LEFT,RZGHT,WEfGRT,PWID !potential charaeteristrcs Vt M U T ) !potential array X (mXMTt ?space coordinate MAL V W fmgix value o f potential RE= EBOTTM,DEBOT !guesses far g , s . energy and spacing
G W&
ENZN,EW,OEMXN,DEWX
!limits on energy and energy increment
C
X M Z N 1 , X ~ f r D X 1!limits on each patential XMIN2,XMXZIDXZ m m XMXP(13,XmX3,DX3 REAL VXE/Xlf,WmXIBX C
INTEGER M X L E V P h m m T E R ( m L E V = 50 )
c ZOMGN / PPAMN / GAMMA
?maximum nu&er of levels
COMON / N P W M / TOLF, MPTS, m X S T P GOWON / POTPRH / POT, BUEIP, ELRT, LEFT, RXGM'PI WEXGWT, PWTD
G O W Q N / GOWST
/
C O H O N / PCALC
/
C
Algorithm Tbis program calculates the Born and eikonal scattering amplitudes and cross sections (Eqs. (4.21) and (4.29,30), respectively) for an electron incident on a square-well, Gaussias well, or Lenz-Jensen potendid, as de~cribedin the text. The angles at which the differential cross section are calculated are fixed by the number of quadratare points input (BLEO) and the value of BCut as defined in the text (beginning of subroutine nrtcaox). The diEerential cross section at each angle (subroutine DIFFCS) is calculated in both the Born and eikonal approximations by subroutines BoRR and EIKOBL, respectively, with the Bessel function Jo calculated by function BESSJO, and the potential defined in function v. The total eross section is then calculated by integrating the differential eross section over these ELBG forward and backward angles (DO loops 100 and 200 in subroutine nrc~ow). All integrations are done by the same order Gauss-Legendre quadrature for which the weights w d absdssae are established in subroutine 9 ~ 0 . Input The physical parameters are the type of potentid [Lenz-Jensen], the nuclear charge [4] (Lenz-Jensen only), or well depth [20] (square or Gaussian well only), and the energy of the incident partide (in eV) [20]. The only numerical parameter is the number of qudrature points [20]. The p r o g m &e&s that the number of quadratare points is one! af the fourteen dowed vdue!~:2,3,4,5,6,8,10, 12,16,20,24,32,40, or 48. Output Far eaeft of the 1*WILEG sc&tering angles, the text output displays the scattering angle (in degrees), the momentum transfer (in inverse Angstroms), and both the Born and eikonat differential crms sections (in square Angstroms). When all of the differential cross sections have been cdedated, the p r o g r q -prints out the total cross section in the Born and eikond approximations, as well as the total cross section from the optical theorern. The graphics then displays the dierentid cros8 section as a function. of a g e fox both the Born iztnd eikond approgmat;ions. cccccccccccce~ecceccccecccecC:cc~cccccccccccccecccc~ccccccccccccccccccccc PROGMM EXWL4 C
C C C
E x m p l e 4: Barn and Elkanal Appraximatians to Quantum Scattering COMPUTATXONU PHYSICS taoalfww v e ~ s x o ~ j by Staven E. Koanin and Dawn C, Heredith Copyright 1989, Addison-Wesley Publishing Company
ccccccccccecccecccecccccccecccecccccecccccccccccccccccc~cccccccccccccccc CALL INIT
5
CONTINUE CALL P W M
Idisplay header screen, setup parameters ?main loop/ execute once for each s e t of param !get input from screen
CALL ARCHON GQTQ 5
!calmlate cross sections
END
cccccccccccccccccccccccccccccccC:ceccccccccccccccccccccccecccccccccccecec SUBROUTINE ARCWON C c a l c u l a t e s t h e Born,
e i k o n a l , and o p t i c a l theorem t o t a l c r a s s s e c t f o n s
ccceccccec~ccccccccccccccecccccccecccccccccccc~ccccccccccccccccccccccccc C Global v a r i a b l e s :
INCLUDE ' IIa.ALLt C Local v a r i a b l e s :
W& REAL MAL mAL
=L
SSNWW TWTCUT, COSCUT SIGBT,SIGBTF,SIGBTB SIGET,SIG)&TF,SIGElCB SIGQPT,IMEEO
!sin theta__cut/2 !theta-cut/2, cos o f t h e same !Born c r o s s s e c t i o n s !eikonal c r o s s s e c t i o n s l o p t i c a l cross sect, imag part of f ( 0 ) !integration variable t i n d a x wad p a i n t s , a n g l e in-er of f i n e s printed t o t e m i n a l !send t o t e r m i n a l !make a hardcopy !send t o a f i l e
REAL COSTE f NmGER I m G , LANG INTEGER MLINEG INTEGER SCREEN IMTEGER PMER INTEGER FILE DATA SGmEN,PAPER,FTLE/1,2,#
cccccccccecceccCccccccccccccccceecccccecccccccccccccccc~cccccccccccccccc C
o u t p u t s u m a r y of p a r a m e t e r s If (TTERM) C&LL BWOUT (OUNIT, NLINES) SF ( T F I m ) CALL EmOUT (TUNIT,NLXNES) I F (EFZLE) CALL PmQUT (GUNLT, NLINES)
I=
C
aglar a t w h i d @1@at=2*pit a &v&& fnestgsrl, fnto
C
C
C C C
in%agratsrfxem thstka=O Lo thata*hata-aak Co fixrd farwaz& mg2ca croira irscltiaa
(rusj+a j* ( z - c o s e v ~/2 ~ 0
wmzma 100
-L BXmCS (COSTICl, f LEG, IABO,SIaZI, S f GB%,P m O , BLZmS> CQrnXMW SX-TFmPZ * (X-C@SCUT) *STaT SIa%F=PI*(l-CGSCW) * S X a T
C
sxmz=o SxaEm0
C
e C
inr;sqracs f ~ o mthatr*hd&-mt eo tbeC&q% eo find b&&wazd aqXa areas @w%&@n M, 200 X==%,
WmKmO 200
cmzam
SImm=EP*(C:06CU~+Z)*sxmz STW-PI* f COSGUWl) * @ Z a p
c C
ba&wrzd und fomrxd @catdaringcrroor 8rokion@ sX~~sKamt.sxCffi)TB Sfml)=hlaam+SZam
SKWEF=Q*PI/KfXbdBEO
c C
output r e s u l t s I F ( T T E M ) CALL TOTOUT (OUNIT,TNTCUT,SIGBT,SZGET, SIGOPTI I F (TPILE) CALL TOTOUT [TUNIT, TNTCUT, SIGBT,SZGET,SIGOPTI
C
IF (TTERM) CALL PAUSE( * t o c o n t i n u e , IF (TTERE"I1 CALL CmAR
..
l ,
l)
G C
graphics output IF lCTERMf CALL GWOUT (SCREEN) IF (GFILE) CALL G m 0 0 T (FT=) IF (GNRDCP) CALL GRFOUT (PAPER)
C =TURN END
cccccccceceCc~cccCcc~ccccccccccececc~cccccccccc-C:ccccccc~c~cccccccccccccc SUBROUTINE DIFFCS(COSTW,XLEG,~NG,SXGET,SJGBT,IMFEO,NL~~ES~ C c a l c u l a t e t h e d i f f e r e n t i a l c r o s s s e c t i o n a t a g i v e a n g l e (COSTHI C and i t s c o n t r i b u t i o n t o t h e t o t a l c r o s s s e c t i o n
c~cCcccccecc~cccccccccccccccccccccce:cccf:cccccceecccccccccccccccccc~cccc~ C Global V a r i a b l e s : INCLUDE *PAMMM,E4' INCLUDE 'fO.ALLP C Passed Variables
REAL SIGBT = A t SIGET REAL IMFEO REAL GOSTH IWTEGER ILEG, LANG IMTEMR NLINES C L o c a l Variables: N & L THETA,Q M A T , DEGREE ( 96) REAL SIGE 196)
!Born c r o s s s e c t i o n s ( o u t p u t ) !eikonal c r a s s s e c t i o n s (autput) ! imag part o f f [D) ( o u t p u t 1 !integration variable (input) !i n d e x quad p a i n t s , a n g l e t i n p u t 1 !number of l i n e s p r i n t e d t o t e r m i n a l (I/Of
! a n g l e , momentum t r a n s f e r !a n g l e !elkanal d i f f e r e n t i a l cross section RE& SIGB(96) !born d i f f e r e n t i a l c r o s s s e c t i o n COmOW/RESULT/DEGmE,SIGEISICB ! p a s s t o g r a p h i c s r o u t i n e o n l y
CGCCCG"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC:CCCCGCCCCCCCCGCCCCCCCCCCf:CCCCCC~C
%=T&dTM
XF
(SWF (1-C652S*GOSlCX) [COSTHI
(%m=.LP. 0
I Find LXza q g Z a
0) T ~ F & ~ ~ T A + P X
G
0-2*~*sm (~mra/n, Q)
1mwnLm fzans$er ad this -@,a
G B m (Q,W@, SIC;IB)
!ea2&ade
dUCf-c~lmnkiaZarosr sscf
C
IF (TTERM) !text output CALL TXTOUT (QUWIT, DEGREE (mNG1 Q,STGB (mNG1 ,SIGE {LANG] ,EJLINES) IF ITPILE) & CALL TXTOUT (TUNIT,DEGmE (mNG1t Q C SIGB (LANG)I 51GE (LWMG],NLXEES &
I
C RETURN
END
eececccccccccccccccccccccccccccccccccccccccecccccccccceceecccccccceceC:cc SUBROUTINE BORN (Q,LANG, STGB) C calculates the differential eross section in the Born approximation C for one value of the Inamenturn transfer (Q)
cecccceccceccceecccccccecccccecccccccecccecccccecceecccccccccccccccccccc C Global Variables: f MCLUDE " PAW. E$" C Passed Variables Q L INTEGER LANG W A L SIGB (96) C Local Variables: R REAL REAL
HBQRN INTEGER J
!momentum transfer finput) !index of the angle (input) !Born differential cross section tautputf !radial variable !scattering amplitude findex of quadrature points
C Function: RE& V
!potential CecccccccccceccceccccccecccccccccecccccceccccccccccccccC:ccccccccccccccc =Q==@ !zero a m BOM+SXN (Q*%) *V (R)*R*=@
?male $he v ~ A d 2 a (3) !Caussim c~;xad~r&urs
3.00
e
sra
=nam*mom
=TURN
END ~~~c~~~ce~~~cccc~~ccccccccccC=ccccccccccccccccceccccccccccceccccccc SUBROUTINE EIKONL (Q,mNG, S I m ,TlvlFEof C calculates differential eross section in the eiksnal approximation C for sns value of the momentum transfer Q
e~~~~cec~~~~cc~~~cecccccccI=eccccce:ccccccccecccecccccccccccccccec~ C Global Variables:
'PAMM. E4'
INaUDE
C InputlQutput V a r i a b l e s
mAL Q
!momentum t r a n s f e r ( i n p u t )
INTEGER LANG REAL SIGE(961 REAL ImEO C Local Variables: RE& CWI 496) mAZ B COWLEX PE mAL ZmX, ZZ REAL R REAL JO INTEEER M, J: R E U X COmLEX SQRTCMl G Functions: MAL BESSJO
! index of t h e angle (iny>ut)
!e%konal d i f f c r o s s s e c t i o n ( o u t p u t ) [output
!imag p a r t a f f (0)
? p r o f i l e function !impact parameter !scattering amfitude ! i n t e g r a t i o n v a r i a b l e f o r CWI !r a d i u s !&ssel f u n c t i o n !index f o r quadrature !argument of Bessel f u n c t i o n !square r o o t o f a n u s 1 f z e r o t h Bessef f u n c t i o n e v a l a t X
m&L V ! p a t e n t %a l ~cc~~~c~~eec~cecccccccccccccef:cccccccccceccceccc~ccccccccccccccccceccc~ SWm=(0.,1.1 0. )
-(Q.,
t aonrptane
!zero %be @oat;& amp&
C:
* (=G(J)+1)/2.0 C
33'
t irrt;aqxaka ever B
(m@ .EQ. 11
Ica2sulaks pzafiZe funation @ace
CRI (3)=O * O DO 200 M=1, -Q Z Z = g W * [=G
(M) +I)/ Z
. l ~ o a l avarf &Za fcralalata xadiur tQZaar~aIm mad
G (a)
f
f (Q)
C
Z**B 30==6550 rn=FE+B*J C 2.00 C
C m X m
ZF (W@ *EQ*2,) C
RETURN
END ccccccccccccccccecccccccccccccC:ccccC:cccccecccccccccccecccccccccecccccccc m A L FUllrCTXoPJ V (R)
300
B. Progranas for the Bsamples C calculates the potential a t fixed R
cccccccccccccccccccccceccceccccccccccccccccccccc~cccccc~cccccccc~~cccccc C Global variables: INCLUDE ' P B W . E I 8 C InputlOutput Variables: REAL R C Local Varfables W& RR
REAL U
!radius [Input)
!radius for Lenz-Jensen (.ge. R151 !temp variable for Lenz-Jensen
CCCC~CCC~CCCCCCCCCCCCC~GCCC~CCCG~CCCGCCCCC~CCf~~~CCCCCCCCCCCCCCCCCCCCCC
IB" (POT .ZQ, S Q U m ) TmH
Is-axe
well
v=-vzne C
E&=
3 3 (POT SQ. aVSS) V=-==@*(-2W*R)
fWmseipn weXL
C
fmr-3ansen
EL=
!=%off r a u r at, loaakion of JS aheX1 TP (R .%S, IXJAf) ===S W 4 . Jli97*Z5*SWT (m) V=- ( (Z*E2) /nf *m(-U) * {l+UEf.I.WIll*( .3344+W* ( .04&5+. 002647*8) ) ) C
=TURN
END
cccccccceccceCcee~eececcccceeccccccccccecccccceccceccccccceccccccccccccc FUNCTION BESSJO ( X ] C ealalates the zerath order Bessel functian at X
cceecceccccc~cccccccceccceccccccccccccccccccc~eccecccccccc~eccccccceccE:c C Global Variables: C Input Variables:
mm
X
C Loeal Variables REAL V,Y2,TEWeTENP2
!argument of J-O !temporary variables to save values
c~cc~ce~ccccc~ccccIcecec~eccccccccecccccc~c~cceccccccccccccccIccccccccc~c V=X/3 * Y2=Y*Y C
IF ( A B S f X ) .LE. 3 . ) TWEN TE;W=-,0039444tI00021*Y2 TEMP=.O4444?9+Y2*TW Tern=-. 3 1 63866+V2*TEEIP
TEMP=1,2656208+Y2*TElvae TEW=-ZS2499997+V2*TEKP BESSJO=I,+VZ*mMg
ELSE U-1. /V
TEPaP=-7.2805E-04+1.44?6E-O4*V TEW=1.3?237E-O3+TEMP*V
TEW--9.512E-OS+TENP"V
TEMP=-,0055274+TEMP*Y TEMP=-7.7E-O7+TEMP*U TEMP=.79788456+TEMP*V TEKP2=-2.9333E-04+1.3558E-O4*Y TEW2=-5.4125E-04+TEWP2*Zr' TEtJu?2=2.6257JE-Q3+TEW2*V TEMP2=-3.9$4E-QS+TEEin?2*Y TEm2=-4,l66397E-02+TEpllP2*Y
TEMP2-X-.78539816+TEMP2*V
~~ss~a-rawxcas ITEMPZI/SQRT (XI ENDIF C
=TURN END GCCCCGCCCCCCCCGCCCGCCCCGCCCCCCCCCCCCGCCCGCCCCCCCCCCCCGCCCCCCCCCCCC~CCCCG
smRovTrHe QuAotNLBae) c subroutine to establish Gauss-Legendrs abscissae and weights CCCGGCGCCCCCCCCCCCCCCCCCCCCCGCCGCGCCCCCCCCCCCCCGCCCCCCCCCCCCCCCCCCGCCCCC
C Global variables: INCLUDE ' P A W , E 4 * G Passed Variables LOGICAL PIILBAD G Local Variables: INTEGER fLEG
!allowed value of nleg?(output) ?index fox abscissae and weights
ccccccccccccccccccccc~ceeecccceccccccccccc~~cccccc~ccccccccccc~cc~cccccc NLBD=.FALSE. C
THEM XLEG (l}=,577350269189626 MLEG(1)=l. ELSE IF fNLEG.EQ. 3) THEN XLEG 41)1,774596669241483 WLEG (l) =, 555555555555556 XLEG {2)=O, WLEG (2)=* 888888888888889 ELSE IF (NLEG,EQ,I] THEN XLEG (l)=. 861236311594053 @LEG (1)m. 347854845137454 XLEG (2)=.339981043584856 WLEG ( 2 ) -,65214555486254g ELSE IF (NLEG-EQ.5 ) TmN XLEG (l)=. 906179845938664 @LEGE1)=,236926885056289 I F (NLEE.EQ.2)
!nleg-2
!NLEGmS
!NLEG=4
f NLEG=$
XLEG12)=.538469320105683 M U G (21=. 478628670499366 XLEG ( 3 ) =0, WLEC ( 3 ) ~568888888888889 .
ELSE IF (NLEG.EQ,6) THEN XLEG (If932469514203152 WLEG (I)=.17132449237917 XLEG (2) 661209386466266 WLEG ( 2 )=.3607&1573048139
-.
? MLEGa6
302
B. Programs for dl8e Ezamplea XLEG (3)=.238619186083297 &LEG (3)=;. 467713934572691 ELSE I F (NLEG,EQ, 8) THEM
XLEG (1)=. 960289856497536 hlLEG(1)=.10122853629Q376 XLEG (2)=, 796666477413627 WLEG (211.222383034453374 XLEG (3)m.525532409916399 WLEG (31m,313706645877887 XLEG 14)-,18343464249565 WLEG (4)=. 362683783378362 ELSE IF (NmG.EQ.10) THEN XLEG ( X ) = , 973906528517172 WLEG 111 =.066671344308688 XLEG (2) =.865063356688985 RLEG (211.149451349150581 XLEG (3)=, 679409568299024 @LEG(3)=. 219086362515982 XLEG (4)=, 433395394129247 1LEC (41m.269266719309996 XLEG (5)=.148874338981631 @LEG(5)=. 295524224711793 ELSE IF (MLEG.EQ.12) THEM XLEG (1)m. 981560634246719 WLEG(1)=,047275336386512 XLEG (2)=.904117256370475 WLEG 12)=.l06938325995318 XLEG (3)=, 769902674194305 WLEG (3) =,l60078328543346 XLEG (4)=. 587317954286617 RLEG (41 =. 203167426723066 XLEG (5)=, 36783149899858 WLEG (5)=,233492536518355 XLEG f 61m, l25233408511469 WLEG f 6)=.249147045813403 ELSE IF (NLEG.EQ.16f THEN XLEG (l)=. 98940093499165 WLEG (l)=. 027152459411754 XLEG (2)=. 94457502307J233 @LEG (2) 062253523938648 XLEG (3)=.865631202387832 WLEG (3)=. 0951585126&2493 XLEG(4]=.75540440835JQa3 WLEG f 4)=.l24628971255534 XLEG (5)-. 617876244402644 @LEG (5)=. 149595988816577 XLEE (6)=. 458016777657227 KLEG (6)-,169156519395003 XLEG (7)=.281603550779259 @LEG(71=.l82603435044924 XLEG (8)=. 0950125Q9837637 WLEG (8)=. 189450630455069
==.
!NLEG=8
!NLEG=lO
?NLEG=12
!NLEG=16
ELSE XP (%LEG-EQ.20) TUEM XLEG [l)=. 993128599185094 !NLEG=20 WmG(1j =. QL76140072.39152 X U G ( 2 )=, 963971927277913 @LEG (2) 090601429800386 XLEG (3)=. 912234428251325 WLEG (3) 06267204833W XLEG (9)=. 839116971822218 WLEG(4) =, 083276741576704 XLEG (5)==, 76633590646015 1LEG (5)==, 10193021981724 X m 6 16)=. 636053680726515 WLEG {6) 2181945329CiI518 XLEG f 7)==. 510867001950827 WLEC ( 7 ) =,131688638449176 X m G (8)=,37370608873.5419 WLEG (8) 142096109318382 XLEG (9)=,227785851141645 WLEG (g)=. 1491729864726.03 XLEG(lO]=. 076526521133497 WLEG(20)=,152753387130725 ELSE IF (NLEG.EQ. 241 TNEN XLEG (l)=,995187219997Q21 WLEG (1)0.012341229799987 !NLEG=24 X m G (2)=, 874728555971309 WLEG (2)=.Q28531388628933 XLEG ( 3 )=. 938214552002732 W m G (3) =. 014277438817419 XLEG (4)P. 886415527004401 %LEG (4) = - 059298584415436 XLEG f f 1 =. 820001985973902 RLBG ( 5 )-*07334648141108 XLEG (6)m. 740124591578554 a E G (6)m. 086198161531953 X m C 172=, S48093651936975 WLEG (7)=,097618652104113 XLEG t81--545421471388839 WLEG f 8)=. 107449270215965 XLEG (9)=. 433793507626045 WLEG (9)~~115505668053725 X a G (10)= - 315042679696163 W m G 110) ==. 121S704725327803 XLEG (11)-.l91118857473614 MLEG (11)=.l25837456346828 XLEG (12)=,064056892862605 W U G (12)=.227938195346752 ELSE XF (NLEG.EQ.32) THEM XWG(1) =.991263861849482 HLEG ( 3 ) =. 00701861000947 !NLEG-32 X m G (2)=. 985611SlSS45268 WLEG (21=.016274394730905 XLEG ( 3 ) 964762255387506
-.
-.
--.
-.
304
B. Progmrnt~for the Esamples WLEG (3)=, Q2539206530W XLEGl41 =. 934806075937739 WLEG (41=. Q34273862913021 XLEG 451=. 896321155766Q52 lLEG (5) 042835898Q2222& XLEG [6)=. 849367623732569 WLEC (6)=,050998059262376 XLEG (7)P.794483795967942 WLEG 17)=.058684093478535 XLEG (8) =,732182118740289 WLEG (8)=. 065822222776362 XMG (9) 663044266930215 WLEG (9)=. 072345794108848 XLEG (10)=.587725757240762 WLEG (10)-. 07819389578707 XLEG (11)=. 506899908932229 W U G fllf -.083311924226946 XLEG412)=.421353276130635 RLEG u.2) as76szos3004403 XLEG (13) 331868602282127 WLEGf13)=.091173878699763 XLEGf141=.239287352252337 RLEG(24)=,093&44399080804 XLEG f15)=.144471963.582796 WLEG (15)=.09563872o079274 XLEG (261m.048307665687738 WLEG (16)P.09654008853.4727 EL% IF (NLEG,EQ,$O) THEN XLEG (l)m , 99823770971Q559 WLEG(1)=,004525277098533 XLEG (2)=. 990726238699457 =G (2) 010498284531152 XLEG (3)=. 97725994998J734 @LEG f 3)=. 0164210583811307 XLEG (4)=. 957916819213791 HmG (411.022245849194165 XLEG (5)=, 932812808278676
-.
-.
-. -.
-.
WLEG{5)=.027937006980023 X U G (6)=. 902098806968874 M m G (6)=,033460195282547 XLEG (7) 865959503212259 @LEG (7)=. Q38782167974472 XLEG (8)m. 82461223083331L R m G (8)=, 043870908185673 X m G t 9) 778305651426519 WLEG ( 9 ) =. 048695807635072 XLEG 13.0) =, 727318255189927 WLEG (10)1,053227846983936 XLZG (11)=.671956684614L79 WLEG (2.1)=. 057439769099393 XLEG (121=. 61255388966798 WLEG f12)==. 061306242492928
-.
-.
!NLEG=40
P l-i E9 W m Cu l-i d
19 QI
P
U (-1 ;)
r-4
0 0 P- m 0 U) a3 rl tn m r- 0
cn Cy
C4
U
rl Q
*
ft
Q)
e
A
=;t
CO
CI CI
3S X
It 0
'Q"
a2
2 z Q"
m CR M
r-
m CJI P 'Q" r-
N
m
r4 rl
0, U
LI?,
4 . '
5
g:
W
m
m
ID
ID
*
1 l
L
Q
QI
m
'Q"
rl U)
CO mm
U)
(r,
n
r- rS) m e- U)
U;)
P W 41
0
m m
€3 Q\
n Xy (0 r-
Q)
m
P
r-
wr) C)
CD
6
m
Q"
m
n m
CV
Q"
m
Q\ rl)
a
m
PC U3
N m rJ Q\
P m
a
Ga
r'i r-i
E9 0
m CV m
1
U) rr]
C
U
X
5
r"-
3
C9
il If
r;j G
CD W
I)
C
!2 5
W 'Q"
c.
m
0 0
-
(0 CV
r-
U;)
N
W
r-
m
m N a2 'Q"
ar a
0 Pr- (V Q m RI U7 c3 N Rl P 8" Ln P CD
tl
C*t P Q c3
(If
6 X
z 52
ttr
W 2 3X 3:4
W
C a#
U
k
0
a
4
B2
-4
A
2
C:
0
m
0 k .A
LI 'Bf. U. tO M C G
(11
C, U
3 C
"cl
9)
7J 3
m
C m
C,
.4
e
-4 0 & @ E 0
3 k @
g,
a#
U -1 -4 M @c, B l C G
a &a
II W
CI
U
4J d;l
X v, Gl W
+
O & -c, @U"..
Cl -4'4 S -a
a ~ t o
1
cr
4
a#
m
0
C
a
E a,
3
V)
'j.
U7
3* rJ
8
U CV) CO
N Q\ €U rl 9" rl r-l
0 U)
0 II
.-. d
2 €5
3
5
4.j
4 41
U
-Pf
c
//%total NTEXT-2
cross sectionp
grilphics o u t p u t d e s c r i p t i o n DESCRP ( 6 )= # d i f f e r e n t i a l Gross s e c t i o n vs. t h e t a f NCNPH=Il C A U HEADER (DESCm, NNmEl, NTEXT, NGMPM 1
set c o n s t a n t v a l u e s PX-3.1415926 SQmLFmSORT ( 0. S ) E2=14 * 409 =2*0 HBmM=?. 6359
Ihbar**2/mass e l e c t r o n
CALL MENU
I s e t u g c o n s t a n t p a r t o f =nu
!electron charge, s w a r e d
MT1IPE 413)=%TITLE M P W T ( 1 3 ) = ' P o t e n t i a l F u n c t i o n option^:^ MLOLIM (13) m2 WHILIH f l 31 11 MTQE ( f 4 1 -MTTTLE N P W T ( 1 9 ) = * 1 3 ) Lenz-Jensen P o t e n t i a l : e l e c t r o n HLQLIM ( 1 4 1 10 MNXLf M ( 1 4 ) 5 0
MTYPE 4 15) =MTITLE m M T ( 1 5 ) m e 2 f Square W e l l t MLOLTM (IS =Q MNILIM (151 =Q
WTYPE (18 ) =NUM M P W T ( l 8 ) = * E n t e r charge of t h e atomic n u c l s u s ' MTAGfl8fm 6 Z f NLDLZN (18)=l MHILIM (18) -108 MIWTS (18)m 4
&
n e u t r a l atom'
308
B. Programs for the Bgamples C PdlTPE (19)=SKIP mmLS (19 ) =21, C
MTVPE ( 201 =FLQAT M t " M T (20)='Enter
Vzero (@V) # Vzero (@V)p mQLINt20)=0,0 MNXLTM f 20)=5000. LS (20)-20.0 MTAG (20)= p
e MTYPE (211 =FLOAT
(21)=?Enter Energy (aV)* MTAG (21f l*Energy (eV) MLQLIM(23)-0.0 IM121)=5,0E+06 es(2~1=2a.o C
MT'YBE (22) =SKIP mmLS (22) 7135 C
M W E ( 38) =MUM WRNPT ( 3 8 ) -* Munrber o f wadratare p i n t s * NTAG ( 3 8 ) nu-r of wadrature paintsC nLaLxn t 3 81 =a MHSLIM (38)5.48 MINTS f 3 8 ) 120 C
MTYPE ( 391 =SKIP LS (39) -60
c MSSRNG (MINTS(75) 1 =
exmpl4, t x t *
C
("I=SKIP )
s (761-80. C
MSTRHG(MTNTS(86)f = '@exmpl4,grft C
E (87) =SKIP LS (87)-90.
c RETUW
END
eccc~ccCcececceccccccI:cccccecceeceecc~ccccC:ccccccccceeccccccececcccecccc SUBROUTINE P m N gets parameters from screen ends program an request c l o s e s old files maps =nu variables to program variables C opens new files C calculates all derivative paramters G C C C
ccccccccccccccecc~cccccccccceccccccccceccecccceecceecccC:cccccE:cecccccccc
c Global variables: ZNCLODE 'MENU.ALL"
INCLUDE ' I0. ALL" INCLUDE 'PARAM. E4C C Local Variables: LOGICAL NLBAD !allowed value of nleg? C map between menu items and parameters INTEGER IPQT,IZ,IVZERO,IE,INLEG P-METER (XPOT 1'7 ) PAMETER(IZ =l@) P m m T E R (TVZERO 20 1 FAmMETER (ZE 21 1 PAmNETER (INLEG = 38 1 C Functions: ZNTEGER GETINT ?gets integer value from screen !converts l and O to true and false ZWSCAL,M G C V T
-
~c~c~cccC~cccceccccccc~ee~ecc~ccceceececcccccccc~cccc~e~ccccccccCcccccc G
get input from terminal CALL CLEAR CALL ASK (1,ISTOP
c C
stop program if requested SF (MmALS ( T a I N ) .EQ. STOP) GALL FINISH
C
C
C C
close Eilas %f necessary SF (TN&ME NE, MSTRNG (MINTS(TTNAXE)) ) + CALL FLGLOS ( T H m , TUMIT1 SF f G H M E NE. MSTRNG {MINTS(IGNAME))) + CALL FLCLOS (GMAHE, GUNTT)
. .
physical and numerical parameters POT=MXNTS(SPOT) ZmMLNTS ( IZ) VBERO=WALS 4 XVZERQ) EsMREALS (X E1 NLEGmNfNTS I INLEG)
e C
<derived constants R=SQRT (2*E/NMM) IF (POT .E@, LENZ) THEN RCUT=l. Z6=Z**. 156667 RIS=.S29/Z ELSE RCUT=2. END IF
C f i n d weights and &scissae for Gauss-Legendre intagration C&LL QUAD ( NmAD 1 100 IF (IdmAD) THEM WRITE (OUNIT,*) Allowed values for quadrature points are + '2 3 4 5 6 8 10 12 16 20 29 32 40 48'
C
e e
31O
B, Pragmnas far the Esamples NLEC=GETINT (20,2,48,' E n t e r new n u d e x o f wadrature points' 1 MINTS ( INLEG) -NLEG CALL &U&D (NLBm) GOT0 100 END fJ? CALL C M m
G C
C C
C C
text output T T W - L o G C v T (MINTS ( I T T E M ] ) TFILE=LOGCVT (MrWTs (XTFILEI 1 THmE-MSTRNG IMXNTS (XTNANE} graphics output GTm-LQGCVT (MINTS (XGTERNf 1 GBmCP-LOGCVT (MINTS 4 IGHRD} f CPXLE=LQGCVT ( N I NTS (XGFXLE) f GHm=HSTRNG (MINTS (ICN&m) 1
openfiles f F (TFILE) CALL FLOPEN ( T N m , TUNIT)
I F (GFIm) CALL FmPEN(GNWE,GUNIT)
! f i l e s may have been renamed
nsmNG (MINTS
~ Z T H M ~j = m MSmNG (HINTS (XGMAm) f =GM-
m
C
=TURN
END
cccccccccccCc~ccccc~c~eeccccccececcccccccccccccceccccecccc~ecccccccccccc SUBROUTINE PRMQUT(MUNIT,MLXNES)
C outputs parametera to NUNIT
~eccccccccccccCccecceccecccccccccececcccceccccceccccccccccccccccccecccec C G l o b a l variables: INCLUDE ' 10-ALL'
C Passed variables: XNTEGZR MUNIT IMTEGBR MLIMES
!unit numf>ar f o x output (Input) f n u d e r of lines written so far ( I I Q I
cccecccccccccccccc~cccccccccccceccccccecc~cccccccccc~~~~ccccccccc~ccccc I F (MUNIT .EQ. OtRSIT) CALL C L E M C
m3TE HRITE W T E WRITE
(MUNIT, 2) (MUNXT,rl) (MUHIT, 61 E (MUNXT, 8r NLEG
c SF (POT .EQ. LEMZ) THEN WRITE (WFIMIT,10) 2 E U E I F O?QT ,Ea. SQUARE) THEN BRSTE (NUNIT, 1 2 ) VZERO ELSE I F (POT .EQ. GAUSS) THEN m I T E (MUNIT, 1 4 ) VZERO END IF
WRITE [MUNIT, 1 5 ) C
d i f f e r e n t header f a r text and g r a p h i c s f i l e s I F (MUNIT .EQ. G W I T ) THEN WRITE (MUMIT, 2) ELSE m I T E (NUBSIT, 2) m I T E (MUNIT, 3.6) WRITE (MUNXT, 3-71 BRTTE (lollTMST,lElf END XF
C
c NXIINESml O C
2 4 f
6 8 l0
52 14 15
IS 17 18
FORmT f ' ' ) F O W T ( ? O u t p u t f r o m e x a m l e 4: B o r n a n d e i k o n a l ' ' a p p r o x i n t i i t i o n s t o quantum s c a t t e r i n g E l FORmT f "nexgy (@V) m ' , 11PE10. 3) FOWT Numbo?r af q u a d r a t u r e p a i n t s ;= ' , X21 FORmT f q e n z J e n s e n p o t e n t i a l w i t h 2 -. 5 ,113) FQRMAT ( q q u a r e w e l l p o t e n t i a l wbeh V z e r a = ' 12PEl@,3) FORMT f r G a u s s i a n p o t e n t i a l w i t h Vzero = ? 1PE10.3) FORMT ( @ T h e t a is i n degreesf1 F6Rm5 (IXX, "Theta' ,l3X, " I , 14XI @Ba;tnf,1 4 X P# E i k a n a l t 1 FORmT flQX, d e g r e e s r , llX, #A*-l@I 12X, * A * * 2 * , 1 4 X AX*2 * ,llX, f , 1 2 ~ 8, ----E, 1 4 ~ ~---..--t , FORESAT (10X, ---S---
@
----
1 1
C =TURN END
cccccccccccccccc~cccccecccccceeccccccccccccccccceeccccceccccccccccccc~cc SUBROUTXNE TXTOUT (MUNIT, DEGREE, Q, SIGB, SXGE, NLI NE51 at each angle
C writes o u t d l f f a r e n C i a l G r o s s s e c t i o n
cceccccccc~~cccccccccceccccccccI=ecccececccccceccccc~cccc~cecccccccc~cc~c C Global vaxiables: ZNCLUDE ' I Q , ALLe INCLUDE *PAMMN,EI6 C Snput v a r i a b l e s :
SITEGER MUNIT l o u t p u t u n i t s p c i Eiar INTEGER NLINES !nu&er of l i n e s p r i n t e d t o s c r e e n ( I / O ) ! a n g l e a n d mamentum t r a n s f e r RML DEGREE, Q WAI, SITGB,SXGE !Born and s i k o n a l dfff c r o s s s e c t i o n CCCCC~CeCCCCC~CCCeG~CCCCCCCCCCCGCCGCeCCCGCCCGC~CCCCGCCeC~CCCCCCCC~CCC~CC C i f s c r e e n i s f u l l , clear a n d t y p e h e a d i n g s a g a i n f F ( (MOD (NLINES, TRNLIN-51 EQ 0) + .AMD. (NUNIT .EQ. DUNZT)) THEN CALL PABSE(%ta c o n t i n u e , .,\l) CALL CLEAR KRITE (ElfUMST, I61 RRTTE (MUNIT, l ? ) mXTE (MUWIT, 181 l R I T E (MUNJT,ZJ hlLINES=NLINES+3
. .
END I F C
m I T E (HUNIT, 20) DEGREE, Q, SIGB, SIC23
c C
keep t r a c k o f p r i n t e d l i n e s only f o r terminal output I F (NUNIT .E@. QUNIT) N&IMES=MZTNES+l
c 20 2
16 17 18
F O ~ T ( 9 X , F 7 . 2 , 9 X I F 7 , 2 , 9X,1PE10.319X,1nEZQ.31 F O m T ("1 F O M T W X , ' T h e t a t , ,l%@,Q 8 ,14Xp B o r n f , l4X, # E i k o n a l f 1 F O W T ( l Q X , 'degreesp,l l X , *Ak-1' ,12XI pA**2t, 1 4 , A**2 F O m T (IDX, * p ,I ~ X ,p l&,p - - - - I I1 4 ~p ,
."---\
-------
c
----m--
@
)
1
RETURN END
cccccccccccccccccccccccccccccccccccccecceccccccccccccccccccccccccccccccc SUBROUTINE TOTOUT (MUNIT, THTCUT, SXGBT, SICET, SZGOPT) C w r i t e s o u t t o t a l c r o s s s e c t i o n t a MUNXT
ccccccccccccecccceeccccccccccccccecccccccccccccccccccccceccccccccccccc~c G Global variables: f NCLUDE "PO. ALLC INCLUDE 'P&MM.E4" G Input v a r i a b l e s : INTEGER MUNIT TWTCUT REAL SIGBT,SSGET,SIGOPT
! o u t p u t u n i t specifier ! t h e t a cut, ! t o t a l cross s e c t i o n w i t h d i f f m e t h o d s
ccccceccccccecccecccccccccccececccccccccccecccccccccce~cceeccccccccccccc m I T E (PIUNIT,*) " mITE YVXITE WRXTE WRITE
IMUNf T, 10) (MUMIT, 2 0 ) (MUNIT, 30) (MUNST, 4 0 )
TWTCUT*1SO/PT SLGBT SXGET SIGBPT
C
10 20 30 40
theta cut I , F7.2, degreesf 1 B o r n sigm t o t a l ,,1PE10,3, ' A n g ~ t r o m s * * 21~ (' E l k o n a l s i g m a t o t a l =',lPE10.3,Vnggstroms**2') (' O p t i c a l t h e o r e m s i g m a t o t a l =%,IPE30.3,' Angstrom~**2~)
FO-T (' F O M T (* FO-T
PO-T
C
RETUEZlV END
cccccceccceecccCccccccecccccccccccccecccccccccccccccccccececcccccccc~ccc SUBROUTINE GRFOUT(DEVICE) C g r a p h s d i f f e r e n t i a l Gross s e c t i a n v s .
a n g l e on a s a d - l o g
scale
cccccccceccccceccecccccccccccccccccccccccccccecc~cccceccccccccccce~ccccc C Global variables IWCLUDE ' 10. ALL"
.
INCLUDE 'GWDAT ALL" C Input variables: INTEGER DEVICE C Local v a r i a b l e s SMg'EGER ILEG
! w h i c h d e v i e e is b e i n g used? !indexes angle
INTEGER EXPMW,EXPMIN !min and max exp f o r d i f f cross s e c t i o n tE a s a character s t r i n g CHaRACTER*9 CE REAL DEGREE ( 9 6 ) !angle REAL SIGE(96) !eikonal d i f f e r e n t i a l cross s e c t i o n REAL SfGB(96) !Born d i f f e r e n t i a l cross s e c t i o n ! s t r i n g length INTEGER LEN INTEGER SCREEN !send t o terminal INTEGER PAPER !make a hardcopy INTEGER FILE !send to a f i l e COMMON/RESULT/DEGREE,SIGESIGB DATA SCREEN, PAPER,FILE/I, 2,3/ CCCCCCCCCCC(=CCCCCCCCCCCCcCCCCCCCCccccccc~cmcccccccccc~ccccccccccccccmc C messages for the impatient IF (DEVICE .NE. SCREEN) WRITE (OUNIT,100) C
C
c a l c u l a t e paramtars f o r graphing IF (DEVICE .NE. FLm) THEN NPLOT-1 IPLoT=1
!how many p l o t s ?
C YE(asx*O.
! f i n d l i m i t s on data points
YMINPSIGB (I) DO 20 f U G = l , P * N L E C IF (SIGB(ILEG) .GT. YMAX) YMAX=SIGB tILW;) IF (SIGE(ILEG) .GT. YPYIX) YMAX=SIGE (ILEGJ XF (SIGB(ILEG) -LT. YMIN] YMIN=SIGB (ILEG) IF (SIGE(ILEG) .LT. YMINf YMINmSIGE (ILEGj CONTINUE f i n d i n t e g e r limits an exponent EXPMAX-INT (LOG10(YMAX) 1 IF (YMAX .GT. I.) EXPMAX =EXPMaXtl EXPMXN-IMT (~ocio (mIw IF (YMIN .LT, 1. ) EXPMINmEXPMIN-1 YMAX=lO.**EXPMAX YMIN=10.**EXPHIN
ILINE-1 ! l i n e and symbol s t y l e s ISYM=4 IFREQIl NXTICKaS NYTICK=EXPMAX-EXPMIW IF (IJYTXCX .GT, 8) THEN !keep number o f t i c k a small IF (MOD (MYTICK, 2 ) WEB. 0) THEN NYTICK=NYTICK/P ELSE
NYTICRm8 END S F END XF GALL GONVRT (E, CE ,LEN ) ! t i t l e s a n d labels IMF0 = ' B a r n ( X ) a n d E i k o n a l ( O 1 A p p r o x i m a t i o n s t LmEL(2)= ?Angle (Degrees) * IF [POT .EQ. LENZ) TWEN TITLE L e n z - J e n s e n P o t e n t i a l , E n e r g y (e!-vf=V//CE LWEL12)= @ D i f f e r e n t i a l C r o s s S e c t i o n (Angstroms**2) ELSE I F (POT .EQ. SQUARE) T m N TITLE = * S v a r e W e 1 l P o t e n t i a l , E n e r g y ( W ) / I C E -EL (21.. ' D i f f e r e n t i a l C r o s s S e c t i o n (Angstroms**2) ELSE I F (POT .EQ. GAUSS) THEN TITLE y G ~ u s s i a nP o t e n t i a l , Enerc3y (sV)=V/GE MBEL12)= r D l f f e r e n t i a l C r o s s S e c t i o n [Angstroms**2If END I F
GTDEV (DEVICE) SF (DEVICE .EQ, SCREEN) CALL G W D E CALL LGLWAX END I F
!device nomination ! c h a n g e t o g r a p h i c s mode !draw a x e s
C
outputresults
C
XF (DEVICE .EQ, FILE) TWEN WRITE (GUNIT,16) m I T E (GUNIT, 18) WRITE (GUNI T, 70) ( D E G M E(IL;EG), SIGB (ImG),SIGE (XLEG) , ILEG=f,2*NLEG)
"r
ELSE GALL XUPLOT (DEGME, SSGB) ISVM=1 CALL XUPLOT BEGmE, SIGE) END I F
C G
!plot born !plot eikonal
end gtaghing session I F (DEVICE .NE, FILE) CALL GPAGE(BEVIGE) I F (DEVICE .EQ. SCmEE) CALL TMQDE
!and g r a p h i c s package ! s w i t c h t o t e x t mode
C
16 18 70
100 G
F O m T (10X,"Theta', 13X, * B o r n f I 24X, Eikonal") F O M T (10X, ' -----',lax, 14x, e * F O m T (9X,F7,2, 934, 1PE10.3# 9X, lPELCI.31 F O m T (I,' P a t i e n c e , p l e a s e ; o u t p u t g o i n g t o a f i l e . " 1 @
-------
mTURX END
ccccceccCcccccccccc~ccccccecccccccceccC:cecccecccccccccccccccceeccccccccc cc~cecccccccec~ecccccccccccE:eef:cccccccccceccececcccccccccccccc~ccccccccc C paramme$
XNmGER Z REAL E REAL VZERO
!charge a f nucleus !energy o f p a r t i c l e !depth o f p o t e n t i a l
SMTEGEA NLEG fEamGER POT IMTEGER UNZ,SQUm,G&USS
!nuber of q u a d r a t u r e points !which potential !types sf potentials
C
P B m M T E R (LENZ=1) P B W E T E R 688Um=21 PAmMETER [GAUSS-3 f
c RE& E2 RE& H B W RML R m
SQH&LF,BI
! s q u a r e of c h a r g e on electron ! P l a n c k e s coanstant !-ximum r a d i u s of potential !constant S
C REAL K MAL Z& RE= RlS
W L RCUT R= W m G XLEG
I wave
R
U
~
T
!sixth root aE Z !radius of Is shell Ispatial extent o f patential !Gauss-Legendre weights and abscissae
C
COWON/PPAmM/Z,E,VZERO,NLEG GOMOM/NPAMM/POT CQmON/CONSTS/E2,WARM, = X , SQmLF,PI 68mON/PCAlCC/Z6,K,RCUT,WLEG (481 eXUG{48f ,RI$
AIgarithm This prosam fits ekctron-nudeus elastic sattering crass section8 to dete ne the nuclear &age density ucsing the method described in the text. Once the target nucleus is chogen, the experirnerttd data is read in (from file CA. DAT, HI.BAT, or PB .DAT),and the recoil and Goalomb corrections are made (subroutine RDATA). Before iterations be&n, the prosam cdcdates the quantities that do not depend on the Faurier (Eq. 5.63), part of the profile function X, ( b ) expansion coeEdents: (Eq. 5.66b), and a factor in the integrand for fin.., (subroutine TABLES). M1 ixrtegrds are done by 20-point Gauss-Legendre quads&urt?l. The init i d dmsi.(;;y is t;aken to be the Fermi function, and the initial Fonrier coeBeients are obtained from a discrete Fourjer trmsform of that function properly normalized to the total charge of the nudeus (subroutine FERMI). For each iteration (DQloop 100 in subroutine ARCHOH), the improved expansion coefficients are found (subroutine w~nmz)by constructing the matrix A and vector B defined by Eq. (5.491,inverting the matrix (subroutine nn~xw),and solving Eq. (5.51). Note that since Eq. (5.4713) is homogeneous, it can be suitably scded to the s m e order of mawitude as the rest of the rows of A. At each iteration, the profie function, scattering amplitude, theoretical cross section, x ~ density, , and uncertainties in the density are calculated (subroutine FIT).
Input The only phyeical parameter is the nudeus [Ca40]. Once the nud e w data has been r e d in, the progam displcays the beam energy, m&mum momentum transfer, and estimated nudear radius. (All energies are in MeV, all lengths in fermi, and all cross-sections in mbarns/ster You are then prompted for the value of the m&mum radius R [l. fermis], the total number of basis functions to use [Q&u*RMX/~] (see discussion in text after Eq. 5.59), and the number to start with. The mmimum number of sines is fixed by CnAX= 15. After each iteration (except the "zeroth") you are given the chance to increase the number of sines (if the current basis is smdler than the total requested), to continue iterating (if the current basis is the total requested), or to end iterations. Output After each iteration (including the Uzeroth"iteration when the Fourier coefficients are determined only by the Fermi function), the text output displays the iteration number, X2, degrees of freedom, number of sines used, total charge, maximum momentum transfer for this basis, expansion coefidents, and their uncertainty. The graphics then displays both the experimental cross section (with error bars) and the theoretical fit on a semi-log plot. The density and its uncertainty as a function of radius are also plotted. The number of radii at which the density is
edcdated is fixed by HGW= 100. Note that graphic8 $oes to hardcqy or ab file only dter the final iteration, but goes to the semen dter each iteration. cccc~ecccccccccccccceccccccccecceF:cececc~ccccccccccccccccecCcccccccceecc P R W W EXMPLS E x m p l e 5: Determining Pd-uelear Charge Density C GOWUTATIONAL PHYSICS (FORTmN VERSION) C by Steven E. Koonin and Dawn C. Mereditk C Copyright 2989, Addison-Hesley P u b l i s h i n g Company C
ccccccce~cc~cccccce~cccccccccccccccccceccc~ccccceccccccc~ccccccccccccccc 5
GALL SNXT CONTIEIUE CALL P CALL mCHOH GOT0 5 END
! d i s p l a y header screen, s e t u p p a r a m t e r s !main Joopl execute once f e r each set of param ? g e t i n p u t from s c r e e n ! c a l c u l a t e n u c l e a r charge d e n s i t y
cccceeccccecceccece~cceccccccccecccccceccccccccccccccccc~ccccccccecccccc SmROUTINE ARCROM C c a l c u l a t e s n u c l e a r charge d e n s i t y from b e s t f i t t o e l e c t r o n s c a t t e r i n g C data; t h e d e n s i t y i s expanded i n a f i n i t e F o u r f e s s e r i e s CCCCCCCCCCCeCCCCCCCil:GGGCCCCCCCCCCCCCCCCCCCCC~
C Global v a r i a b l e s : IHCLUDE 'PAWM. E5' INCLUDE 'IO,ALLf C Local v a r i a b l e s : ZNmGER ITER INTEGER INCRS, CONT IWTEGER NSIEJE M& GZERO (CMAX) m L SIGT (DATmX) COWLEX FTOTAL ( D A T M X J QBASIS DOUBLE PRECXSXON A (CmX+1, CmX+1) mAL GRf (NLEG) WAL RHO (NGRFI DRWO (NGRF) INTEGER SCREEN XNmEER PAPER IPJmEER FXLE C Function: INmGER GETIHT,YESNO DATA SCWEN, PAPER,FIILE;/l, 2,3 /
!number of i t e r a t i o n s ! i n c r e a s e n s i n e l continue i t e r ? !nu-r OE c o e f f i c f e n t s !Fourier coefficients ! t o t a l cross section !total scattering amlituds ! m x num mmentum t r a n s f e r !matrix f o r i n v e r t i n g !profile finetions !d e n s i f y f o r graphing ! e r r o r in d e n s i t y !send t o terminal !make a hardcopy !send t o a f i l e
!get i n p u t from s c r e e n
cccccccccccccccccccccccceccccccceccececccccccccccccccccccccccccccccccccc C C
C
read i n n u c l e a r d a t a and e a l c u l a t a d e r i v a t i v e parameters CALL NBATA set up a r r a y s t h a t do not depend on Cncs CALL TmLES ( A I prompt f a r v a l u e of N t o begin with NSTNE=GETINT (NBASZS). l, EdBASIS, + ' E n t e r number o f s i n e f u n c t i o n s t o begin w i t h p )
318
B, Programs for .the EzampZes CALL C==
C o u t p u t s u m a r y o f paramters I F (TTERM) CALL PMOUT (OUNIT) If (TFSLE) CALL PmOUT (TUNIT) fF {GFf LE) CALL PWOUT (GUNIT)
C
G C
G
o b t a i n i n i t i a l C n *S f r o m F e r m i d i s t r i b u t i o n X TER=O
!lazqest Q - 8 c r f M by basis CALL FERMI (NSINE,CZERO) c a l c u l a t e i n i t i a l f i t and d i s p l a y CALL F I T (NSXHE, CZERO, ITER,SIGT, FTOTAL, QBASIS, CWItA, RHO, DRHO]
C
100
llaop wer itarigtionlsp
COlli[lCXm
XTER=ITER+I
f i n d changes i n C Z & R O b t o o n i m i z e the e r r o r CALL MXNIMZ (CZERO, WSLNE, SIGT, FTOTAL, QBASXS, CH3 I A) c a l c u l a t e w a l i t y o f f i t , errors; d i s p l a y r e s u l t s CALL FIT (WSINE, (=ZERO: ITER, SXGT, FTQTAL, QBASIS, CMT, A, RBQ, DRHO)
C
C C
v a r i o u s o p t i o n s for c o n t i n u i n g I F (NSLWE .LT. NBASXS) THEN
G
+
TNCRSYESNQ(O,'Do y o u want t o i n c r e m n t n u & e r I F (INCRS .EQI I f THEN ISSNE=NSXMEfl CZERO (NSLNE) =O. CONT..%
o f s i n e s b y one?')
Ilazqe@t Q ascribed ELSE CONT=YESNO(I,'Do
ltsasia
you want t o c o n t i n u e i t e r a t i n g ? ' )
END IF ELSE CONT=YESUO(I,@Do you w a n t t o c o n t i n u e i t e r a t i n g ? f ) END I F C
IF (CQRT .EQ. I) W T Q I00 C C
w r i t e sut only t h e f i n a l v e r s i o n t o a f i l e I F (GWRDCPf CALL GRFOUTfPAPER,RWO,SZGTCNS1:;FilEIDfi:BO] S F (GFILE) CALL GWOVT (FILE, RHO, STGT, WSX NE: DRWOI
G
RETURN END
ccc~c~~~~~cc~~c~c~c~~c~e~cecc~ccccccc~ceccceccceccceceeecccccc SWROUTINE NDATA C read i n n u c l e a r data G d e f i n e v a r i a b l e s t h a t are n u c l e u s - d e p e n d e n t C t a k e recall o u t of data; c a l c u l a t e e f f e c t i v e momentum t r a n s f e r C p r o m p t f o r NBASfS and R M X
~c~~cc~c~~~ce~cc~~c~~c~ecccc~:~ccc~~~c~~cccccccc
C Global v a r i a b l e s :
INCLUDE ' P A M . E S t INCLUDR I O ALL1 C Lacal v a r i a b l e s : I N m G E R I,I R QW, RECOIL m L NTARGT INTEGER NZERO @
.
!index of i n p u t d a t a , r a d i u s ! v a r i a b l e s t o a d j u s t input d a t a !mass of t h e t a r g e t i n MeV ?suggestion f o r NBASIS
C Function: INTEGER GETINT !get i n t a g e r i n p u t from terminal GETFLT !get real i n w t from t e r h n a l CCCCCCCCCCGCCCCCGC~CGCCGCCCC:CCCCCCCCCCCCCC:CCCCCCCCCCCCCCCCCCGE:CCGCCCCGC:C C open d a t a P i l e s IF (NUCL .EQ, CA) THEN OPEN (UldITmDUNIT, FXLE='Cha DATt, STATUS=* OLD' 1 ELSE I F (NUCL .EQ, NZ 1 THEN OPEN (VNX T-DUNI T, FILE-' M 1 DAT* I STATUS='0LDf 1 ELSE I F (NUCL .EQ. PB) THEN OPEN (UNIT-DUNIT, F I L E = @PB. DATe ,STATUS=' OLDf 1 END IF 1:
c C
5
readindatadescription READ (DUMIT, 5 I TARGET W A D (BIINZT, * ) ZTARGT, ATARGn EBEAM, NPTS F O m T (2X,AlQ)
c MZ=T.s94 0*&TMGT m=zFmG111*mm
C C
26
read i n c r o s s sections; c l o s e f i l e RE31CI {DUNIT, 20) (THETA ( I ) , S f C E ( I f ,BSI68( I ) , C TWETA(I+1),SSEE(I+X) , D S I G E ( I + l ) , I = 1 , N P T S 6 2 j F O M T (2 (IX,F7,3,1X,E10.3, 1 X , E 1 0 1 3 ) 1 CLOSE (UMIT=DUNIT)
c G
C
C C
prcsllifinv ad3usttarsne~t o Lhe &aka ker~plthe
arrox small
.
IB ( D S I a (I) CT , SX- ( X ) ) D8IGE ( I )= , aagla i n radians (X) (X 3 * P X / so. ~ oocrection to ~troarcltntmtransfer
(X)
sr# ( z a m [X) /zm) W E (I)=Q-%%
C
nf [QErn{Zj *G%' take eat zecoiT mCoXW2 +2. *=-*SIN
{It ( T m T A (X)
/ 2)* * 2 / m m G T
320
B. XL"rq~"rams for
t i e Ezamples
s r a 4x2=arm(X) *=cox& osxa (X = ~ s x lar *mcarIi 30 C C
COWXm
prompt f o r i n p u t o f R M and NBASXS W I T E (QUNIT,40) TARGET m X T E IQUNST, SO) EBEM
WRITE (OUNXT,GO] -X WRTm (OUNIT,70 f RZERO WRITE (QUNIII,*)
"
C
Rm=GETFLT(RZERQ+4,,1.,251,
+
E n t e r t h e boundasy r a d i u s t o u s e ( i n f e r m i s I t j NZEFPO-XMTfQmX*RW/PI) W I T E (OUF\ff T, 80) NZERO NBASIS=GETXNT (NZERO,l , 1 5 , * E n t e r NBASXS81
c f i l l a r r a y R G W t h a t i s used f o r charge d e n s i t y w i t h r a d i a l v a l u e s I)RGW=RmINGRF DO 90 XR=I, NGRF RGRF f 1R) =XRXDRGRF CONTINUE
C
90 C 40 50
F O m T ( # For t h e t a r g e t \ , A f O ) F Q m T (' ttrh d a t a a r e a t a beam energy of 5 F 7 . 3 , '
60
F Q m T ( @ the maximm momentum t r a n s f e r covered i s
70 80
+
MeV" ' @
F7.3, fm**-1' 1 F Q W T ( ' t t h nuclear radius i s aboutrtF7.3,' fm@j F O m T ( @ t o keep QW2e35 t h a n Qexgsrimental, RAJBZISXS" + must h l a s s t h a n " , X 2 1 @
C RETURN END CCCCCCCCCCCCCCGCCCCGCCCCCCCCCCCGCCCGCCCCCeCCCCCCCCCCCGCCCCCCCCCCCGCCCCCC SUIlRoVTINE T m L E S (A) C c a l ~ u l a t e sCBI(&), sets u p t a b l e o f B*J-QfQR), c a l c u l a t e s FOUTER C and z e r o e s the m a t r i x A C (none of t h e s e v a r i a b l e s depend on Cn's, and t h e r e f o r e need C ta be dane o n l y once per c a l c u l a t i o n ) CCGCCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCC C Global v a r i a b l e s : INCLUDE "PAW.E5' XNCLUDE 'IIO.ALLr C output variables: DOUBLE PmCESEON A ( C m X + l , C m X + l ) ! m a t r i x f o r i n v e r t i n g C Local v a r i a b l e s : lWxd IF3 !impact p a r a m e t e r l m X INTEGER N, ILEE, JLEG, I, J !i n d i c e s REAL 2 , X , Y !integration variables !sum f o r i n t e g r a t i o n =&L SUM REAL PWX, BESS JO, BESSJ1 !r e a l f u n c t i o n s RE= J O ,Jl fternp v a l u e s f o r P o u t e r
COmLEX MO
!arguments o f the Lame1 function
COWLEX FACTOR COWLEX LOMMEL COeLEX TEMP1, TEW2
! c o w o n factor in POUTER 1 function * X** (3-MU) storage Ear L o m e l E u n c t i ~ n
m&
ccccceccccccccccccccecceccccceeccccceecccccccecccccccccccccccccccccccccc fwedioa f o r CWXN
C
+@mF ( l . -Y**2)) l Y ) -SmT (P
( (l. C
C C
( (m-l)**2-W**2)
zsro the =trfx
-Y**21
.- ((W-l.)**2-@0"c*2)/X**2 +
(X,W,NU)=f
+
P
* ( (m-3.)**22EIO**Z1 /X:**4
A
DO 2 I=%, 3. DO 1 if=%, C=+% 1. 2
&(I, J)=O. CQHTINm CQMEXrn
C
C
CEm
L.
part: of p r ~ f i l ef w a t i o n ia&@psa&ato f Cm's ) ' Caloulaking cki (n) , ,"
.
Ir2.1 33% a m a c a l ~ dby
81(l+X=G (IU6)) 12.
SW=@. D43 5 m011.3rRmG Z=B+ (l,-B)12. * ( 2 . +=G s m = S W m @(-G]
S 10 20
4-C))
*2*Srrsl (H*PZ*Z) * B E { & / E )
?Bq. 5.6635 t Gaassiw wad
Ca%XHa CmrJ (XmG, N) m - 4 * P X * W m * CQHTXNW
CQmHHa
C C
garctr, of E-gmcrs fntecgrand iadep@&ant of Cmc& (OmIT,*2 ' C~alaalat;?lng Eksmrael gmationi~* B fla 60 SmQ=X, N m G E= (%+-G (ImC) ) 12. I a Z l B" am S C P X B ~ t l Q . 3.62
50
COR1"Zm COmXBFUE.
60
C C
...*
calculaka E-oatax (whfah only aaea a point em*) (OWIT,*l Crlculating mkar ecatdaring -lie*..,@ (OWIZl,*f ' F&aQ--2*SQRM*a
DO 80 X=%, MPES x*mF. (I)*
30=mssao( X ) ( X , FaCTOR, -1. )
322
B. Programs for the Ezamgles *n (X) **2)
80
c =TURN
END
ccccccccccccccccccccceecccccccccc~cceccccccccccccccccccccccccccccccc~ccc SUBROUTINE FERE(IX(NSTNE,CZERQ) C c a l c u l a t e i n i t i a l CZERO by f i n d i n g F o u r i e r c o e f f i c i e n t s G f o r t h e Fermi F u n c t i o n
cCecCcccCCC@ccCCcCcCCCcCcCccCCeCCCCccccccccccccc~ccc~ccccGccc~ccccCccccc C Global v a r i a b l e s : C
INCLUDE ' P A W . E S C Input v a r i a b l e s :
!number o f c o e f f i c i e n t s
INTEGER NSINE C output v a r i a b l e s R a L CZERO (CIUIAX) C Local v a r i a b l e s : INTEGER ILEG, N REAL M D T U S , R REAL FERMIF, m W O REAL SUN RmL TWXCX DATA THICK / 2.4 /
IFourier e a e f f i c i e n t s t indices
!radial step,radlus !Fermi F u n c t i o n !sum f a r n o r m a l i z a t i o n l t h i e k n e s s a f Fermi f u n c t i o n
cceccccccccccccccccecccecccccC:ccccccccccccccccc~cccccccccccccccccccccccc C
!zeze
BO 30 B=%,RSfm
czmo (M)=0.
30
C a T I m
C
fP~mrAmrtzanrigea of Eq. 5.37 40 50 C
caNZ"fMm C a T X m
C 70 M=%,WSICESE
70
Xi? (MOD(E,2) ra (MOD(B, 2) CartIm
.$0. 2.2 Sm=SW+CIZ;ERO(M)/M .PZQ. 0) sw=m-ezmG(E) /H
BQ 80 M=%,mSJS ceno (H)ezma (H)*SW 80
CWTXm
C
=TURN
Em c
~
~
c
~
C
~
~
C
~
~
C
~
~
C
C
C
G
G
C
C
C
~
~
C
SUBROUTINE FIT (MSXNE,GZERO,ITER,SSGT, F"f8TALCQBASIS, CWI,A., RHQ, DRWO) C calculates s i v a (given CZERO), chi squared, tba charge density, C and error in charge density; displays the results
cc~~~ceccc~~~cece~cccececcccc~ccccccccc~cceccccccccccecceccccC:eecc~cc~c G Global variables: INCLUDE 'P&MM,E5' INCLUDE ' IQ,ALL" C Input variables: W&L GZERQ { c ~ x ) INTEGER NSSNE INTEGER ITER C Output variables: RE&L SXGT f DATMaXf COWLEX FTOTAL ( D A T N X )
REAL Q E A S I ~ REAL RHO (NGRFI M& DRWO (NGRFI DOUBLE PRECISSON ACCmX+5,CMX+S) C Local variables: R B U CH1 (NLEG) CQWLEX FINNER INTEGER ILK,IQ,M, IR,M CNISQ INTEGER NDOP RE& SIMES (CPECAX J W a SUM,FAC
RE&L Z INTEGER f CREEN INTEGER PAPER SNTEGER FILE DATA SCREEN,PAPER,FImlf,2,31
!Fourier coefficients !number of coefficients !nu&er of iterations !total cross section !total scattering amplitude !max num momentum transfer t~hargedensity lerror in density !matrix foz inverting !g r o f ile Eun~ti ~ n s
!inner scattering amplitude !indices !goodness of fit !degrees of freedom in fit Itable of sines ltentp varialr>le for DRWO !total nuclear charge !send to terminal !make a hardcapy !send ta a file
GCCCCCCCG~CCGGCCC~~~CCCCCeCCCCCCC~CCCCCG~CCCCCCGCCCCCCCCCC~CCC~CCCCGCCCC oalmlatca Lotal pzofJils gmoLion ae ea& b (W.5.66;ar)
C
DQ 20
IrnWl, HrnQ
c s x ( Z m G ) =-ZA*WG
( {%+=G f 2-1 ) 12) DO 10 N=l,Nsm C m f X-) -X (XmG) +CEma(NI* G E M (X=,
10 20 C G
M)
CQrnZrn COrnXHW
alouXata &it a i m , abfacyuare
cmsq=o
rnOF=Q G
DO SO f Q m 1 , m T S TZoop mar data poinee oaXcu%akat h fnner and t o f a 2 om%+arfng~ Z i t u d e
PX
0. !Zq. 5.62 * S W T r n * C B (ZrnG)) -1* )
40
324
B. Programs for ihe E~amples 8iaatt;arSng -3Jltuda
C
F T W U(IQ).+ (F
C
w & t h -mattransger corr {E%. 5.60) ( X Q ~121 **2*vca,*i*a*ms (sr?0"11m ~ X Q ) **2 X% (-H (ZQ) "LE. m S 1 8 ) F= mxswcarsg+( ( s r a ( x ~-src;z ) (XQ) fclsrnm (IQ)1**2 !IQ, 5 - 4 2 NDQF=HDOY+3 END 1IT C m Z m ~ @ = ~ ~ ~ ~ - @ s ~f &-me@ ~ @P f m d a @ip i n *rmes/sr,
C
s x a (rg) ~ =xo*cos
50 C
G
o a Z d 8 l t s the disanaify. and its arroz
Z=0. DO 70 I m 3 , N m REIs (m)=O
.
D=@
(lx) -0
l trro s m r
*
60 ~ 2 , X S S Z ~
sxms (a) =sm{rs+~rmm (I) * WO (fR) ==Q (XR)
tarn 7; h n a i t p r d % m ~
8-0. BQ
$0 M=X,ZJ F=-2 * XF {M B] FAC=Z* SW=SWHAC*A(W, M) * S X m (M)
gAnd
QZZ
i n dclnmr
awe= B4
f Pq. 5.53,
GOZJFIET~
80
D m O (m) =DmQ(IR)+SW*SZm {M)
f Eq
5.55,
eullt
ever
CQEOXm
60
D-o
(m) =SW%p
RE347 (m)==Q
6 ( D ~(m) O ))
(m)/=M (m)
(IR)l take o\;li: racxriula Exam W@ ?inkeg dens ;Per= CcrZ, charge Iaam =Q i s juat &nai.t;y
C
+
+
IF (TTEW) CALL TXTOUT (OUNIT,ITER,CNISQfNBQP, MSXNE, QBASIS*CZERQ,
Zj
XF ( W I L E ) CALL TXTOVT(TUNZT,ITERtCHISQeNDOFIISI:ME~QBAfTSICZEROtA~ZI XF (GTERM) THEN CALL GWOUT f SCREEN,RHO, S%GTfIdSZNE, DRHO)
CALL CLEAR END 3F G
REWURN END
ecccccccecGceecccccccecccccccecccecccce:cececcccccccececccccecccli:cecccce.c SUBROUTINE MINIM8 [CZEROcNSXNE, SXGT, FTOTAL,QBASI5, CH1 e f i n d s t h e corrections t o CZEFIO to minimize t h e f i t
AI
ceccccccccccccccccccecccccccccccccccccccc C Glabal variables;
C Znput variables: m& CZrSROfCm) INTEGER NSIHE WAL SZGT(DATW) RE& CH1 (NLEG)
lFourier caefficients IZ/o) I n u d e r of ~ o e ficiants f !total cross section f profile functions !total scattering amplitude !max num momentum transfer !m t r i x for inverting (IIO)
CQWLEX FTQTAL(D&TE(IAX)
M h L QEaSIS
DOUBLE PRECISEON A (CMAX+1, C m X + 1 ) C Lacal variables: REAL BWC (6mX.tl) INTEGER NDIM ~ O W L ED~F D ~ REAL W ( C M X l INTEGER IQ,N, ILEG, M M A L SUM
!lhs of linear equation I dimension of matrix l d f f f of F w . r , t . czeR0 fdiff of SIGT w , r , t . CZERB l indices !temp value for matrix mulplet;
ccccccc~ccccccccec~ccccccceccccececccc~cccece(scccccccccc~ccccccecccccce~ Calculating and f nvaxt ing 8.
WRSTE (OUNIT,*)
mm=@Szm+T
..
C
zsm the vacear B and mtrix, A.
C
m
E0 B = 1 , I S X m
m c (El =o
IDQ 20 *1,1
&(H, M)=@, caM%mm
20
30 C
COmXm
C
calmlate Lhe m t r g x A and vactor 8 DO 70 XWl,NPTS X@ (WEE (Xg) .LT, Q-ZS) 110 40 l=l, NSXMF?: DEDCm0
DO 30 f =@l,
IIm
i & s a v e ofP Q' is net &ao ky barriis I F A r i s t g&ndW ts
MW@
BC+
+ 30
+
%?a (rQ) /2)**2
!Eq, S. 67a
cw91xm DO 60 W = & , N S m
Icaculaka matrix A 882%. 5.48 {M]j b S 5 a f %Q)**2) !an& vatckor B(Zq 5.48) (sx~g (XQ) -sscr (IQ) W (E) /xlzsza (rq)**2
DO $0 W2,W A (M,M) a (B, M) +BB= (W (H]*W 50 60
70 C C
CQHZ B ~ (NI C- m e CaMICXMm Ern XF
fw) +
CQRTXNm
inc%ude &Z/dCn %em@, DO 1 0 0 M=2, NSfm
ruld
f l & 2 or& A ue;ilirlf
!l&
3,49a, 4,58
326
B.. P;rogrenzs for $he Ezanzplea XF fMQD(N,P) .Ea. P) A(E1,MDm)=-&(Tt2)/N !seale XF (MOD(N,P) .EQ. 0) AfR,NDm)=&(1,31)1'M A (MDXN,H)=A (M,HDXM) DO 90 M=l,tS f f A l . 1 @U% l = & x b ue;inq
A(2,Z)
A(M,E)e(W,M)
30 100
COMZXCaTTm iR (NSXm+X,HSTmSP)=0.
C
mZm (R,HDXN) C
DQ 120 H=a,lifSIm
.
S-0
rlnve*
the m k r l x
I e t i p Z y &**-X * B t o soJlva loormc;%ions to Cawe
;fa*:
310 mZ,NSXm s-svM+A (g,M) *=C {M) COlroTTBW C%BRO (W)=CZERO (N)+SW C@H%ZHrn M)
110 120 C
=TURN
END cccccccceccccceccccecccececceecccccccecccccecceccccccccccccccccceccccccc SUBROUTPNE mT%W(A, NDXH) C i n v e r t s t h e m a t r i x A of dimension NBIN u s i n g Gauss-Jordan e l i m i n a t i o n ; C A. i s replaced by Its i n v e r s e
ccccccccc~ccccccccccecccccccceccc~cc~cc~ccccccccccccececcccccccccccccccc G Global v a r i a b l e s :
INCLUDE 'IC).ALLP INCLUDE P m M . ES" C Input/output variables: DOUBLE PRECISION A ( C W + I , C m + I ) ! m a t r i x f o r i n v e r t i n g INTEGER NDXM !dimension of m a t r i x C Local v a r i a b l e s : DOUBLE P m c I s l a M P ( C m X + 1 ) , Q (emX+l) !temparary storage LQGICAL ZERQED (CmX+l) !keeps t r a c k a f who" z e r o e d ? Indices INTEGER I, J, K TNTE(;ER KBXG !index o f tow b e i n g z e r o e d !largest diag e l e m n t i n A DOUBLE PRECISION PIVOT ! l a r g a s t dfag e l e m of non zeroed rows REAL BIG
ceccccccecccccecCeccccccccceccccccccccc~cccccccccccccccccccccccccccccccc raws are ztbxsed? none so DO 10 Xm1,NDXM EEROED {X) = F m E
C
whicrh
10 C C
CQrnrnW
.
l o w over a l l rows W 100 f=%,mlM
mXdloP.O BX-0 BQ 20 G=Z,HDfM
l sssrrclh f o r l a q a s t &a9 al fin rows noL yet rsread
I, IOT, z m E a ( 3 )) rmH IF (ms(a{J,a) ) .cr.
sxc)
store &ha largest diagonaz eSenten% XI? (I .EQ, 1) PXVO"P=A(KBIG,m f G )
i f a21 dAag~nielsare rtexc, than the (=X0 .EQ. 0 ) rmP3 (OmT,*) * Matrix f s s i a ~ 3 a r '
ie slaplar
33'
XF mtrix i c a S12 oondiLionsd if s f z s of I H I ~ ~ ~ RvarAaa L I B qzeatly I1 (-S (A (-IQ, m I C ) /PIVOT) .LT!. 3.E-14) fREP3 m f 2 E (OmXT, *) Matrix iai ill caa&tionerdt
E m LP bagin ze3rofag row m X G zERoEa (mxoi mm. g (=X@) =l/& (mXG, B X G ) P fmxe)=X. I (ESXQ,=LE) =Q, ate above the diagonal IE (-X@ *az* %j fX) 30 3m2,mXQ-X P (a) =A (G,m X C ) S =A ts,mrc)*a tmzo) IF ( ,M W . ZEROEB (3)) Q ( 3 )=-Q 147) R (3,mIG) =a.
(a
CONTZHW
ZEZD IP efemnts t o the right of the diagomx 33' (=X@ .L%. mXM) TNEN D8 40 G=~fG+l,IDIM P (G)=& (mTO,JZ Q ( 3 )=-A (rnXC,3 )*Q (rn1G) IF (ZEROED 4 a) ) P C 2)=-P [3)
m
A(ICElfG,3)=0, CQHTXMrn XE
328
B. Programs for the Ezanzples 100 C C
CWXMfJ&
DO 110 ib2, m X M BQ 120 E=%,+l fir (3,K1 =A (K,J) 120 110
CrnTZRW
comxm
C
RETURN END cccccccccccccccccccccceeccccccccccceccceccccccecccccccccccccccccccccc~cc SUBROUTINE INST C initializes constants, displays header screen, C initializes arrays for input parameters
ccCcCcccecccccccccccceccccccce:cececccccceI:cccceccccc~cccccccccccccccccec G Global variables:
INCLUDE 'ITO.ALLP INCLUDE "MENU, ALL" INCLUDE 'PAW,ESC C Local parameters: CHWCTER*BO BESCRP ?program description DrmNsIaw DESCRP ( Z O ) ZNTEGER NHEAD,NTEXT,NGMPW !n&er of lines for each description ecCcccccccCccccccccccccccccccccceccceccccccccccccc~ccccccccccccccccccccc C get environment parameters CALL SETUP e C display header screen DESCRP (11 "EhMPLE 5 ' DESCRP ( 2 ) Determining Nuclear Charge Densitiesf NWMGlm2 c C text output description DESCRP ( 3 ) = 'Density parameters and quality of fite NTEXT=l C
C
graphics output descriptian DESCRP(4)- fCCarqe density and scattering cross section6 NGMPWm1
C
CALL HEADER (DESCRP,NHEAD,IdTEXT,NGMFH 1 C
C
calculate constants PI=4*AThN (1.0) ALPWA=l.jl37.036 WBmC-197.329
C
get data for Gauss-Legendre integration CALL GAUSS
SQRTM1=(0., 1,)
C C
setup menu arrays, beginning with constant part
B.5 Example 5 I
CALL MENU
C MPRMPT (415' 2) (not used)*
C
MTYPE (13)mNTITLE HPRMPT (13)=*Chaice of nucfei :' MLOLXMtS3)=2 MHSLIM (13) =l C
MTYPE ( 14 1 =MTITLE PIIPRMPT (I4)='1) Calcium 40
MLOLIM(14) -0 MHXLIM(14)aO C
MTYPE (15)=MTITLE MPRMPT(15)='2) Nickel 58 NLOLIM (15)-0 MXILIM (15)-0
'
C MTYPE ( I6 ) =#TITLE MPI?HL?T(16)1'31 Lead 208 MLOLIM (16 ) PO MHILIM ( 1 6)=1
'
C
HTYPE (17)=MCHOIC MPRMPT (17)='Enter
your choicer MTAGfl7)='18 18 18' MLOLIM (17) -1 MHILIM ( 171 -3 MINTS (17)=1 MREALS tl7)=1.
C MTYPE (181 =SKIP MREALS f 18)*35 C
MTYPE (36)=SKIP MREALS (36)=60. C
MSTRNG (MINTS(75) 1 * * sxmpf5. txtr
C MmPE ( 76)=SKIP
MRERLS (76)-80. C
MSTRWG [MINTS(86) ) 1 texmp15.grf C
MTYPE (87 ) =SKIP MREALS (87)=90. RETURN END CCCCCCCCcCCCccCCCCCCCCCCCCCcCCCCCCCCCCCccccccccc~cccc~cccccccccccccc~c SUBROUTINE PARAM C gets parameters from screen
329
330
B. Programs far tFse Ezamples C e n d s p r o g r a m on r e q u e s t C c l o s e s old f i l e s C naps menu v a r i a b l e s t o p r o g r a m v a r i a b l e s C o w n s new f i l e s C c a l c u l a t e s a l l d e r i v a t i v e paramtezs C performs checks a n garmters
ccece~ccccccecccccccccccecceceeeccccccccccecccccccccccecccP:cccccec~ccccf: C Global v a r i a b l e s : XNCLUDE *mNU.ALLf SNCLUDE ' IQ. ALLf INCLUDE 'PAMN.ESr C Local variables: INTBGER INUCL PAMNETER (IMUGL = 1 7 ) C Function: LWICAL LOGCVT
!map menu a r r a y s to p a r a m e t e r s
!converts 1 t o true, o t h e r s to f a l s e
ccccccccccCccccCcccccece~cc~ceccccecccccececcececceccccceecCcccccccccccc C
get i n p u t Eram t e m i n a l GALL CLEM C A U ASK (I,ISTOP)
C C
s t o p program i f r e q u e s t e d I F I m A L S ( I m I M ) .EQ, STOP) CALL FINISH
c clase f i l e s i f n e c e s s a r y %F ( T N W NE. MSTRNG (MINTS (ITHME) 1 )
C
l
+
CALL FECLOS (TNWEI TUMIT) I F (GNAW ,NE. MSTRHG (MINTS ( T G W E ) ) ) c FLCLQS (GNAME,GUNIT)
e C C C C
set new p a r a m e t e r v a l u e s p h y s i c a l and n u n t e r i e a l NUGL=E/ISNTSITNUCL)
text output T r e m = L o c c v T (MINTS (ITTERM)1 T F I m = L E W T (MINTS ( I T F f W l j TNU-MSTRNG (MINTS ( ITNAm} 1
e C
C C
grirphies o u t p u t GTEM=LQGCVT (MINTS f IGTEW) ) GHNCP=mGCVT (MINTS ( XGBRt)] 1 GFILE=LOGC~T{MrNTs (SGFXWI 1 GNmmMSTRNG (HINTS ( I G W m ) ) openfiles XF (TFILE) CALL FmPEN (TN-, TUWX T) IF (GFILE) CBLL FmPEN (GM=, GUMIT) ! f i l e s may h a v e b e e n r e n a m d MSTRHG [MINTS ( Z T W W ] ) =TNAXulE MsrRBG (MINTS ( r c N m ) f =GM=
RETURN END
~c~~eeee~c~~~ceee~~cccccccccccccccccccccecccccccccccceecccc~cccccccccccc SUBRQUTINE WUSS C establish Gauss-Legendre weights and abscissae for 20 paints
cc~e~c~c~~ceec~e~e~~cccccccccccccecceecccccccccccccccccccccccccccccc~ccc C Global variables:
INCLUDE 'PPAMM.ESt C Laeal variables:
INTEGER ILEG
!index for weights and abs~iasae
ccec~~c~~~~~c~~c~~ecccccccecccecccccceccc~ccccccccccccccccccc~ecccccc XLEG (l)=. 99312859918W WLEG (1)=. 017614007139152 XLEG (2) 963971W7277913 WLEG (2)=. 040601429800386 XLEG (3)c. 912234428251325 Km6 ( 3 )=,062672048334108 XLEG (4)=. 839116971822218 MLEG ( 4 ) =. 083276741576704 XLEG f5]=. 74633190646015 @LEG (S)=.l019301198L724 XLEG ( 6 ) =. 636053680726515 WLEG ( C ) 118194532961518 XLEG [71-. 510867001950827 W=G(71-.131688638449f76 XLEG ( S ) =,373?06088715419 WLEG (8) 14209610931.8382 XLEG (9) 227785851141645 ~ L E G C=.1ss17298s4726a3 ~) XLEG(10)=, 076526521133497 66LEG(l0)=,152753387130725
=.
-. -. -.
C
10
DO 10 ILEG=l,NLEG/2 !weights and abscissae are even and add XLEG (21-XLEG)=-XLEG (1LEG) WLEG(21-XLEG)=WLEG (rLEc) CONTfNVE
C RETURN
END
cccCcccccccecccccceccceccccccecccececccccccccccccecccceccccccccccccccccc R a L FUNCTION BESSJO(X) C calculates zerotk order Bessel function at X
ccc~ecccccccceccccccccccccccccccccecccceccccccccccccccc~cccccccccccccccc C Passed variables: =L X C LacaL variables: REAL TEMP,TEMP2,Y2,Y
ccccccc~ccc~cccc~~cccccccccecccccccecccccccccccccccecccccccccce~cccccccc ?I-X/3
.
IF(ABS(X1 .LT. 3 . 0 ) THEN Y2=Y*U TEMP=-.0039444+,00021*Y2
332
B, Progmms for the E~amples TEPgp=,0444479+Y2*TEW TEMP=-.3163866+Y2*TapIe TEMPsle2656208+Y2*TEMP TEMP=-2,2499997+Y2*TEMP BESSJO=l+Y2*TENP ELSE
Y=l /Y TENP=-7.2805E-04+1.4476E-O4*Y TEMP=1-37237E-Q3+TEPilP*k"
TEMPs-9,512E-05+TENP"Y TEMP=-.OQ55274+TEMP*Y TENPs-7.7E-O7+TEMP*V TBMP=.79788456+TEW*Y TEMP2=-2,9333E-04+1.3558E-O4*Y TEm2=-S14125E-04+TEMP;Z*U
TEMP2=2.62573E-O3+TEMP2*V TENP2=-3,954E-O5+TEW2*Y TEW2--4.166397E-O2+TEMP2*Y TEPa?2=X-.78539816+TEEilP2*Y
BESSJ0=TEMP*CoS (TEME"2)/SQRT ( X } END IF =TURN END
cccceccccccccccccceecccccccccccccccccccccccccccceccC:ceeeeccccccccc~eccC:~
W L FUNCTION BESSJl (X) G calculates first order Bessel function at X CCCeCGCCCCCC~C~CC~CCCC~CCGCCCCCCCeCCCC~~CC~CCC~CCCCCCCGCCCCCCCCCCCCCCC C Passed variables:
ReAL X C Local variables: REAL TEMP,TEW2,Y2,Y
~cccceccccccccccCecccccccceeccccccccc~cccccccccecccc~cccceccceccccccCccc V=X/J*
xetAss(x1
.LT, 3-01 THEN Y2=Y*k" TE~=-3.1761E-04+11109E-05*Y2 TEW-4,43319E-O3+V2*TEMP TEm=-3.$54289E-Q2+V2*TEW TEMP=.21093573+Y2*TEMP TEMP=-.56249985+Y2*TEMP BESSJl=X*(.5+V2*TEWW
ELSE
Y=1 IY TEMP*l.lJ653E-03-2.0033E-O4*Y TEW=-2.49511E-OJ+TEMP*Y TEMP=1,7105E-04+TEP?[PXY TEMP*1.659667E-Qi!+TEMP*Y TEm-2,56E-06+TEW*Y TEMP=.79788456+TEHO"Y TENP2r7.9824E-04-2.9166E-W TEMP2=7.4348E-O$+TEMP2*k" TEMp2=-6.37879R-O3+TEMP2*V
~EMP2=.0000565+TENP2"Y ~EH2=.12499612+TEMP2*V
TEa2-X-2.35619449tTEm2*Y BESSJ~=TEMP*C~S (TEW2) /SQRT ( X I END I F
RETrnM END
cc~~cc~cec~c~c~eceec~ccc~~ccc~ecc~cc~c~e~ccecc~ccccecccC:cccce~e
s u ~ ~ o u ~BRMOUT x m (MUNIT) C outputs parameter s u m a r y t o t h e s p e c i f i e d u n i t ~cc~c~cc~ceccecccccc~~~~cc~~eccccecccccccecccccccccccC:ecc~ccccccccc~ C Global variables: INCLUDE 'IIO*ALLf INCLUDE 'PPAMM. ES' C Passed variables: INTEGER MONIT
! u n i t nu&er
Ear o u t p u t
~e~~~~~~c~~~c~e~~~~c~~c~:c~cc~cccccecceccc~c~ccccc~eee I F (MUMIT .EQ. QUHIT] CAZL CLEAR G
m I T E (MUNXT,2) m X T E fMUNIT,4) WRITE (MUNIT,C) TmGET WRITE (MUNIT, S ) EBmH WRITE (MUNXT,10) W X WITE (WNfT,12) NBASIS &RITE (WUNIT, 11) -X m I T E (MffM?eSP116)IJBEISISkPL/RWX WITE (MUHIT, 2)
C 2 4 6 8
10 12
14 16
F o m T ("1 F O m T t r Output from example S : N u c l e a r Charge D e n s i t i e s p ) F Q M T (' F o r t h e C a r g a t ' , A 1 0 1 F O m T t f t h e data a r e a t a beam e n e r w o f ',F7.,3,' MeVC) F O M T (Vth eradial c u t o f f f o r t h e c h a r g e d e n s i t y = r , F 7 . J , p f m f ) F O m T f 1 t h e nu-r a f sines used=\ 1 2 ) F O m T ("the maximum e x p r i m e n t a l momntum t r a n s f e r = ' 5 ,F7.3, "m**-le 1 F 0 m T f ' t h e maxirnum n u m e r i c a l momentum tran~fer=~,F'1,J,~frn**-l~)
c mTUw
EED
c~ccccccccccccccccecccccccccccccccccccececececcccccccccccccccccc~cccccec SUBROUTINE TXTOUT (MUNIT, ITER, CWXSQ, hfDQFIISIEJE, QBASXSI QZERO~A,Zl C o u t p u t s the c h a r g e d e n s i t y p a r a m t e r s and goodness o f f i t t o MUNIT
ceccc~cccccCecceccceccceccccccccccceececccceccccccccccccccccccccccc~cccc C Global variables: INCLUDE * Ila.ALLe INCLUDE 'PAMM.ESe C Input variables: INTEGER MUNXT a A L GZERO [CMAX) INTEGER NSINE
lunit t o w r i t e t o t P o u r i e r coefficients tnunloer aE c o e f f i c i e n t s
334
B, Pmgrams f ~ the r Ezamples XNTEGER ITER mRZ, CNTSQ
INTEGER NDOF DOUBLE: PRECISION A(CWX+l,CW+1) m& QBASIS RE& Z C Local v a r i a b l e s : INTEGER N R E U SIGM
!nu&er o f i t e r a t i o n s !goodness o f f 4 t f d e g r e e s o f freedom i n f i t ! m a t r i x we're i n v e r t i n g tmax num momentum t r a n s f e r l t o t a l charge !index o f GZERD ! e r r o r o f CZERO
cceCceCcccecccc~cccc~cccccccccccccccccccccccccecccc~ccccccccc~:ccc~ceccc~ WRITE (MUNIT, *) * @
m 1 T E t#UNIT,*f WITE WRITE WRITE WRITE mfTE WRITE
' *
(MUNIT, 1 0 ) ITER (NUNIT, 1 5 ) CHISQ, NDDF (MWXT, 20) NSZME, Z (MUNST,25) WASIS (MUNIT,*) ' " fMUNZT,30)
C
50
DO 50 N-1,MSZME SIGPIGA=O. I F 1A(N,Nf .GT. 0) SIGM=SQRT(A(N,W)) WaITE (MUNIT, 40) N, CZERO (M),S I G m GQNTIPJUE
C
I F (NUNIT .EQ. OUNXT) GALL PAUSE[@toc o n t l n u e . , . @ , , l )
c 10 15 20 25
30 40
5 14) Z = t , l P E 1 5 , 8 , ~ o r ~ , f 4 , td e g r e a s o f f r e e d o m f ) af s i n e s = * , I 2 , t o t a l c h a r g e =',F10.4) F O m T ( ~ ~ a x i m umomentum m t r a n s f e r f o r t h i s basis = .',1PE95.8, 4' fm**-1') F Q m T ("he expansion c o e f f i c i e n t s of t h e charge d e n s i t y + 'and t h e i r errors are:?) F O W T ((' C(',,X2," *,1,lf?E15.8,Q"lPE15.8) F O m T (* Iteration
(' C h i * * F O W T ( * NuPhber
FOmT
e =TURN
END
ccccccccccccccccccceecccccccceecccceeccccccccccccccccc~ccccccccccccccccc SUBROUTINE GRFQDT(DEVICE, RHO, SIGT, NSINE, DRHQI G o u t p u t s d i f f e r e n t i a l c r o s s s e c t i o n v s . momentum t r a n s f e r
C and n u c l e a r c h a r g e d e n s i t y ( w i t h e r r a r b a r s ) v s . r a d i u s
cccccc~c~ccccccCcccccceecceccccccccceccceccececccc~ccccccccccccccccccccc C Global v a r i a b l e s
INCLUDE IO.ALLP INCLUDE "ARBM, E5" INCLUDE %=BAT. ALL" C Input variables: INTEGER DEVICE REAL SIGT ( D A T M ) RE= RNQ (NGRF) REAL DRNO (NGRF)
!which d e v i c e i s b e i n g u s e d ? !total cross section !density f o r g r a p h i n g terror i n density
INTEGER NSINE !nu&er o f aines C Local variables ! i n d e x e s data, d e n s i t y XMTEGER IDATA, XR !min a n d rnax exg f o r cliff cross s e c t i o n XMTEGER EXPMAX,EXP#XPT CHMCTER"9 GEBEm !EBEAM as a c h a r a c t e r s t r i n g ZNTEGER LEPJGTN ! l e n g t h a£ c h a r a c t e r s t r i n g s CH-CTER* 9 G S I NE ! n u h e r o f s i n e s as a s t r i n g TWmGER SINLEN Iarrays fox error b a r s RE& X (2),Y (21 !send t o terminal XNmGER SCREEN INTEGER PAPER !make a h a r d c o p y INTEGER F I L E lsend t o a f i f e , DATA S C ~ E N , P A P E R , F I L E / ~ 2,3/
cc~cccc~~cccc~cc~ccccceccc~c~ccccc~ec~cccececcccc~cccccec~c~cc~cccc C
nessagesfortheimpatient Tl? (DEVXCE .NE, SCREEN) RRITE (oUNIT,100)
e C
calculate parameters f o r g r a p h i n g the crass s e c t i o n s I F (DEVICE .HE. FTZE) TMEN !how many p l o t s ? NPLOT=l IPLBT=1
C
YE"IZIX=O. fflnd l i m i t s on data p a i n t s UNINmSIGT IT l DO 20 1D;ATA-1,NPTS I F (SIGT (IDATA) GT Y W X ) YNAX=STGT (IDBTA) I F (SZGE (SDATA) GT. Y W X ) YmX=SXGE IIDATAI I F (SIGT (IDA1;"A) LT. YMZN) YMIH=SIGT (IDATA) I F (SSGE (IDATAJ ,LT, UMIN} YMIN-SIGE (IDATAI CONTXWUE f i n d i n t e g e r l i m i t s on e x p o n e n t ~ E x a m x = r N T ( L O G I(YMW I F ( Y W .GT. 1. ) EXPmX =EXPPFLAX+I EXPMXNmINT ( L W 1 0 f"xlMXN1 f XF (YMIW .LT. 1 . ) EXPMIN=EXPMIM-2 VM=la.**&XPmX YNTN=10.**EXPMIM
. . .
.
XLINE=I
!Line a n d sy&ol
styles
SSVM=1 IFREQ=f. NXTICK=5 NYTICR=EXPmX-EXPMIN I F (NYTICK .GT, 8 ) TEEN ?keep nunrber a f t i e k s s m a l l I F (MOD(MYT%CK,Z) .EQ. 0) TMEN
336
B. Prqclranas for the EzumpZe~ WVTICK=NYTIGR/2 ELSE NYTICIC=B EMD I F END 3 F
CALL C O m T (EBEAM, CEBEAM, LENGTH) IMF0 = C C a l c u l a t e d ( X ) a n d E x p r l m @ n t a l ( O ) W E L ( 1 ) = ' B e f f t 3 c t S v e (h**-l)"
+
! t i t l e s and l a b e l s
-EL (21 = # D i f f e r e n t iaf C r o s s S e c t i o n I M a r n e s l a r ) TITLE ' E Z e c k r o n S c a t t e r i n g o n '///T=GET / / ' a t '//CEEEAM(I:BNGTWj//' MeVt
"
c CALL GTDEV (DEVICE) I F ( D m I C E .Ea. SCREEN) CALL GMODE C&L WLNAX END I F
!device n o m i n a t i o n ! c h a n g e t o graphics mda ! d r a w axes
C G
8Q
C C
c u t p u t crass s e c t i o n s v s , angle T P (DEVICE .EQ. FZLE) THEN WRITE (GUNTT, POO) m I T E (GUNZT,PIQ) m 9 T E (GUMIT, 220) (QEFF (XDAZIA) ,S I G T (IDAT&) ,IDATA-I, EilPTSf ELSE !piat exgerimntal data CALL XUPLOT (QEFF ,SXGE1 NPDINTm2 apREag.o f w i t h e r r o r bars DO 80 ICtATA=l,N&TS X ( 1) =QEFF (SDATA 1 X f 2)=QEFF (IDATA) Y (XI=SXGEfxaATA) +DSICE ~IBATAI Y (21=SXGE trDATA) -DSIGE ~IDATAI CALL XYPLClT f X , V) CONTJMUE NPOINT=NPTS IPREQ=1 TSVMmII !plot c a l c u l a t e d s i g m a CALL x v p L o a (QEFF, SLGT CALL GPAGE: (DEVICE) END I F c a l c u l a t e p a r a m e t e r s f o r charge d e n s i t y I F (DEVICE . W . F I L E ) THEN Ym=B. ! f i n d l i m i t s o n data p o i n t s YNTN=O DQ 120 I R = I , N G W I F (RHO(IR1 .GT. =X) Ym=MO(IR) CON"rNUE
.
120
.
XMTN=O XMAX-mx
Y OVAL=XMIPd XOVAL=YMIN
!fine and s y d o l styles
CALL XCNVRT(NSINE,CSIME,SINLEMl
?titles and labels
IPaFO="
(I) 'Radius (fermis)' =EEL (2) *Nuclear c h a r g e density [ f e r m i x * - 3 ) " TITLE = TARGET//* using /IICSXNE (I:SINLEN) /I' sine functions"
L-EL
i..
CALL LNZNAX END IF output charge density and its error IF (DEVXGE .EQ. FXLE) THEM
mrre
(GONIT,*) m WRITE (GUNIT, 3QO) WRITE (GVNTT, 310) mITE {GONIT, 320) (RGRFfIR),RHO (IRf,DRNO {SRI,XR=l, NERF)
ELSE GSILL XYELOT (RCW, RHO) NEOXNT=P
!charge density
rpma=o !with error bars
D8 180 XRm1,NI;RF X (1)-RGRF (ZR) X (2)=X (1) Y (1) =RHO ( I R ) -DRWO ( I R ) Y (2)=Y(ll+2*DRRQ(IRt CALL XYOLOT ( X , Y) GONTZNUE END I F
end graphing session XP (DEVICE .NE. FILE) CALL GPAGE(DEVICE1 r~ ( D ~ I C E.EB, SCWEHI CALL TMODE
f e n d graphics package !switch to text mode
F O m T (/, Vatienee, please; output going to a file.6) F O W T (1O X , "@E% (l/fermff ' ,SX, Sigma (m&rnes/srl@1 H O m T ( I Q X , --------------f CJX, t ------------------' ! @
F O m T (2(1O X I IPE15.8 f 1 F O W T (32X, [(fermi) @ X , T G h q e density (fm**-3)',f0X, "Error") (12X, ,8X,6-----------------------fi,10]i:C'-----8 1 Fa-T (3f9X,2PEI5.8) ) f
RETURN END
---------"
338
B. F"~.ograms for $he Bzanzpfes
C pnram.pfj
C
mkL PI COWLEX SQRTM1 RE& ALPm REAL HBAaC INTEGER NLEG PAWMETER f NLEG-20 1 REAL WLEG (NLEGZ ,XLEG (MZEG
!3.14159 f a w a r e r o o t a f minus 1 !f i n e s t r u c t u r e c o n s t a n t
fhbar t i m e s c (MeV-fermi) !number af p o i n t s f o r EL i n t e g ? w e i g h t s and a b s c i s s a e
C INTEGER CA,NT,PB P A M E T E R (CA=1J P h W E T E R (WTm2f
!flags f o r each nucleus
RE= RmX INTEGER NUCL INTEGER NBASIS
! r a d i u s a t which d e n s i t y =Q ?nucleus of choice !nu&er of s i n waves t o i n c l u d e
INTEGER D A T M X PAWWETER (DATMAX-1001 INTEGER HGRF PAMNETER (NGRE"=Z 0 1
!maximum number o f d a t a p o i n t s
C
C"
?number o f p o i n t s f o r g r a p b i n g
C
REAL THETA (DATMX) ,SIGE (DATMX), DSIGE (DATNAX] f e x p e r 1 . m e n a d a t a RE= QEPF ( DATmX) REAJI ZTARGT,ATARGT !charge, n u d e r of n u c l e a n s INTEGER NPTS !numker o f d a t a p o i n t s !beam e n e r g y and w a v e n u e e r m& EBEAN, KBEAPil mAL BA !charge * f i n e s t r u c t const RE& QMX !maximum momentum t r a n s f e r mAL RZERO !medal radius f o r n u c l e u s C W m C T E R * 1 0 TARGET mI, VG1 ! c o r r e c t i o n t a momentum t r a n s f e r REAL D R G E ,RGRF ( N G W ) ! r a d i a l values f o r graphing G
INTEGER CMX PAMMETER (CmX-IS) REAL CHIN (MLEG,CmX) %AL JTABLEfNLEG,DATmX) CQWLEX POUTER 1DATmX)
!maximum number o f Gnc s !c h i ( n ) a r r a y IBessel functions * b ! o u t e r p a r t o f s c a t t amplitude
C ~O~ON~CQMST/PI~A~HA,WBAR~,~JLEG,XLEG,SQRTM~ CQmON/PPM/MX,NUCL,NB&SIS C~~QN/PCALG/ZT~GT,ATARGT,NPTS,EBEAM,KBEAN,ZA,QM1ZX6RZERO,VC~ COE"340N/NUCDAT/THETA,SIGE,DS5GEIC2EFF COM0N/T~LE/CRIN,JTABLE~FOUTER COmON/GRF/DRGRF,RGRF COrnON/CWRC/TARGET
B.6 Example G Algorithm This program solves Laplace's equation in two dimensions on a uniform rectangular lattice by Gauss-Seidel iteration. The p r o e m currently dotvs the input d Dirichlet boundary conditions ody. Wowever, the mray smca can be used to indicate other types of boundary conditions (i.e., periodic and Neumann). Once all parameters are input, the relaxation iterations proceed with Eq. (6.17) being solved successively at each lattice point (subroutine RELAX). If requested, these relaxation sweeps will be mstricted to a sublatlice. The total e m r g per wea is d s a calculated Note . that the lattice @pacingin both a: and y is set equal to one. in R ~ U Every ~ F R E $iteration, %~ you are given option to continue it;era$ing or to return to the m;zin menu. Input The input procedure is a bit difirent for this program, as well as fm PrOject 6. R r tl-iese two codes, yau may find that during the iteration procedure you want do keep the Add vdues and d l parameters, except one or two, the same. Far exmple, you may wish to dter just the relax&ion parameter, change a boundary condition, or change the ffequeney at wEeh the field is displayed, Such a procedure is straighhrwmd, but only as long as tbe la;t;tice dirnendons remain the asme. Therefore, the menu is braken into two pieces: the first level obta;ins the lattice dimensions; the second level (or rnajn menu) obtains alf. other parameters. As bng as you, do not enter the first level menu, all prametem and field vml~resare ~nchangdunkess you s;neeificakly request atheruthe. The first level prompts you for the lattice parameters IX [20] and AY [20]. The maximum lattice sizes are fixed by two considerations: first, the parameters NXWAX= 79 and NYNAX= 79 which determine the array sizes; second, the size of your terminal as defined by T B E V and ~ TMLIR in subroutine SETUP*This last restriction is imposed so that the fidds can be displayed on the screen, using characters to indicate field strength (subroutine DISPLY). If you will be using a graphics package, you can remove the t e r d n d size restrictions an WX and hlY in subroutine LAmIC, If it is not your first time through this menu, you will also be given the option of ending program executioll [no], and (if that answer is no) resetting input parameters to their default vdaes. Note th& aU pmameters th& depend on lattice dimensions (Le., the field vdaes, interior boundary conditions, and sublattice parm~eters)are automaticdly reset evary time you enLer this first level menu. The main menu allows for input of all remaining e the field on, the parameters. The pltysicaf. parameters are the v d ~ of upper [O.], lower [25.],left [25.],and right [O.] boundaries, which are fixed
for DiricMet boundary con&tions. The limits on field vdues are given by FBZI= 0 a d mAX= 25, and are imposed 80 that the scde for character display of the field can be fixed (sw Output belovv), You can dso fix Dirichlet boundary conditions on the interim of the lattice. Two geometries are allowed (subroutine B ~ R P ) :rectangles defined by the lower left and upper right corners; and "45 depeen Hnes defined by one corner, the quadrant, and the length (i.e., quadrant one produces a line at 45', quadrant two at I S a , three a& 225', and four at $Is0, all with respect to the positive z-axis). Note that z and y locations are input as integers to indicate the mrresponding lattice point, A n z ~ m u mof BCMAX= 10 interior boundary conditions are permitted. The menu also dims for the display (subroutine DSPLBC or GRFBC) and review (subroutine RWIEU) of inteI.ior boundary conditions. W I E W 4 o w s for deletion of interior boundary con&tions or dteration of their h e d field d u e s , The numerical parametem are the relaxation parameter [l.],the option to relax a sublattice [no] spedfied by the lower left and upper right cornas, and the initial fidd vdue. Initid field vdueg at nm-boundary points can: 1) be read in from a file [exmpl6.in] created earEer by this program; 2) be set to a specified vdue [12.5]; or 3) remain unchanged. Option 2 is the dr;faalt if the calculation ie just beginning; .otherwise, option 3 is the default;, The two graphieg parametas are the mmber of contours for plotting [l01 (used only if you have a graphics package), and the frequency at which the field is displayed [IQ]. This is also the frequency at w&ch you me aked if you, would Eke to continue iterations. The r n ~ m u x nnumber of cantoars is fixed by U ~ V = 20. Oue put After each rdaxatim sweep, the text output displays the iteration number (iteration count is zeroed on return from the main menu), energy, change in enerw from the last iteration, md the maximum change in the fidd. Every ~~mq%t;b iteration, the prosam will display the field, Note that the field will be displayed as contours (if you have requested graphics sent to the screen, see subroutine GRFWT)or as characters (if you hatre requested text to the screen, see subroutine DISPLY). In the character display, sm& letters in&Icate boundary points and capitaf letters indicate non-boundary points. Currently the progam sets the maximam. field d u e to 25 m d the minimum. to 0,so that the letter A cmrespands to a field vdue of O and the letter Z ta a gel&vdue of 25. k r the contour plotg, the boundary points are indicated by dashed Bnes; the appearance ol" the contour lines will depend on your graphics package, Because display of the field can slovir down cdcdations considerably, yon may want to set BREQ to a large number.
Ag&rs, to avoid volurnirroues output, the field is not written out to a file or sent to a h a r d w j ~devjce ~ each. time it i s digplayed on the screen. Instead, when you request to stop iterations, p u PrifZ be wked if you waat the fidd valnes to be written to the requested output devices. Nate that the field may be written out in three ways: as character data (if text is requested to a file), as numerical data (if graphics is requested a file), or as a contour plot (if graphics i s requested to a hardcopy device).
cc~cce~cecCcccecccccccc~ccccccccccccccccccc~cccccccccccccccecc~ccccccccc C C C
P R E W EXWLC E x a p l e 6: S o l v i n g L a p l a c e ' s e ~ a t i o ni n two dimensions COE3PUTATPOMAL PHYSICS (SORTmN WRSION) by S t e v e n E , Koonin and Dawn C. M e r e d i t b C o p y r i g h t 1989, Addison-Wesley P u b l i s h i n g Company
C CCCCCCCCCCCCCCCCCGCCCCGCCCCCc"CCCCCCCCCCCCGCCCCGCCCCCCCCCCCCCCCGCCCCCCCCC
5
CAU INXT CONTINUE CALL mTTXC CALL ARCWON GOTO 5
!display header screen, s e t u p parameters !main l o o p / e x e c u t e once f o r e a c h set o f param !get l a t t i c e s i z e , a l l o w f o r e n d i n g ! g e t d e t a i f e d bound cond and r e l a x l a t t i c e
EWD
ceccc~cc~ccccCeccccecccccccecccccccccccccccccccccccccccc~ccccc~ccccccc~c SUBROUTINE ARCMQN C s u b r o u t i n e t o g e t p a r a m t e r s , r e l a x t h e l a t t i c e , and o u t p u t r e s u l t s CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCCGCCCCC~CC(3CGCC~CCCGGCCCCCCCCCCCCCCC~C
C Global v a r i a b l e s : INCLUDE 'PhMM. ECr INCLUDE 10. ALL' C! Local v a r i a b l e s : RE= P ( N X ~ X NYW , 1 RML PGW (NXMAX, MYMAXI INTEGER X M X H , X m X , Y M I N , Y m RE= D E L W , Q L D W =&L ENERGY, DELE XNTEGER NfTER LOGXCBL TTER LOGXGAL PRM LOGICAL END INTEEER I X , I Y INTEGER CHOXCE XNTEGER NLINES XMTEGER SCREEN XNmGER PAPER INTEGER FILE C Functions: REAJ, GETFLT XNTEGER GETXNT, VESRQ LQGZCAL LOCCVT
! f i e l d values ! f i e l d v a l u e s f o r grap.b%ng !corners of relaxing l a t t i c e !keep tzaek of changes i n P ! c u r r e n t and d e l t a e n e r g y !nu&r of i t e r a t i o n s !continue i t e r a t i n g ? !print out p a r a m t e r s l !end t h i s run? ? l a t t i c e indices !write o u t f i e l d now? Inu-r of l i n e s sent t o t e m i n a l !send t o t e r n t i n a l !make a hardcopy Isend t o a f i l e t u s e r input funetion ! u s e r i n p u t functions !convert 0,f t o f a l s e , t r u e
342
B. Progrgms for the Esanzples DATA SCmEN, PWER,FXLE/I, 2,3/
ceeccccccccceccccccccecccccec~cccccccccccccceccccccccccccec~cccccccccccc
5
END=.FIILSE, DO 5 IX=1, WX 06 5 XY-3,NY P (IX, XU) =O CON"PNUE
! i n i t i a l values
CONTINUE CALL P W H (P, END 1 I F (END) =TURN
?allow f o r m a y suns w i t h same l a t t i c e !get new parameters ! s t a r t f r e s h o r end altogether
C
200
e XP (SUBLAT) THEN iset l i m i t s for refaxatian
XMINcNXLL VMXE=NVLL YM-NYUR
ELSE XMIN=1 YMIN=I
xmmm YmX-NY END I F
e I F (TFZLE) CALL PRMQUT [ TvrJIT, WLLNES]
PM=. TRUE NITER=@
C 99
I F ( (TTERM) .AND, NZTER=NXT&R+l
!*in iCeraelonlr ( P m )1 CALL PWOUT (OVNIT, NLXNES)
e
f ~ a a ml a k k i e e
, SF (NITER .Earn l) TREN DP;LE.=O QLI)NAX=O END I F
rQm-1
!no changes i f t h i s i s t h e f i r s t time
SF. (TFIm) CALL TXTOUT (TUNIT, NITER, ENERGY, EfBLE, D E W X , IICIIEJES) XF (TTERM) CALL TXTOUT [OUNIT, Nf TER, ENERGY, DELEI DELMAXIN L I W S 1 I TER.=. FALSE. PRM=,TRUE, XF (MOD(NITER,MFWQI ,NE, 0) THEN ITER=,TRW. !continue i t e r a t i n g without asking PRM=,PALSE, !don't p r i n t o u t header ELSE !display f i e l d s e v e r y NFmQ i t e r a t i o n I F (GTEM) TWEN CALL PAUSE(rtto see the f L e l d 1) CALL CmZLR CALL G W O U T [SCREEN,P, PGRF, NX, MY, ENEWV) ELSE ZF fTTERM] TWEN
...',
see the f i e l d CALL CLEAR CALL DTSPLY (P,OUNIT) CALL PAVSfS('to
..."1)
END ZF IF (SUBWT) THEN !end provide o p t i o n s f a r c a n t i n u i n g S U ~ L A T = L O E C V T ( Y E S N O ~ ~ .r e,l a~xCi n~g~ s~u~b~l a~t ~t i c e ? ' f f IF ( SUBL&T) I %'ER=. TRUE ELSE I T E R = Z Q G C V T ( Y E S M D ( ~ ~ ~ C O ~ ~r e:lIaRxUi n~ g l a t t i c e ? ' ) ) END IF END IF
-
C
m
( x ~ R )E WTQ 99
~ N
foonkinua itsratfng
C
ELSE C
prompt f o r w r i t i n g out o f f i e l d v a l u e s IF ( (GFILE) .OR. (GWRDCP) .OR, (TFILE)) THEN C M O ~ C E = Y E S N O ( ~ ,you W ~ ~want t o write out f i e l d now?@> IF (CHOICE .EQ. f f THEN IF (GFILE) CALL WRTOUT (P) ! w r i t e out f i e l d i f r e q u e s t e d I F (GMRDCP) CALL GWOUT (PMERcP,PGRF, NX, NU, ENERGY) IF {TPILEI CALL DISPLV (P,TUNIT)
END IF END IF GOTO 200
! d i s p l a y menu
END I F
c END
cccccccccceccccccccccccccccccccccecccceccccccccccecccccccccccccccccccccc SUBROUTINE RE-X
(P, XMLN, X M X , VNIN, Y M X , ENERGY I DELE:, D E M X , OLDMX)
C relaxes the l a t t i c e (specified
by XMIN, e t c f , c a l c u l a t e s t h e new
C energy (ENERGY) and maximum change i n t h e f i e l d (DELWf
ccCccccccccccccccccccececccecccccccccccccccccccccccccccccccccccccecccccc C Global v a r i a b l e s :
INCLUDE 'PAMM.EGf INCLUDE -0,ALL' C Ingut/output v a r i a b l e s : REAL P (NXMAX,N U M M 1
INTEGER XMIM,XMAX,YMIM,VMX mAL D E L W , O L D M M R E U EEM&RGY,DELE
? field v a l uas
(I/O)
! c o r n e r s of r e l a x i n g f a t t i c e ( i n p u t f !keep t r a c k of ehange i n P ( o u t p u t ) ! c u r r e n t and d e l t a energy { o u t p u t )
C Local variables:
INmGER IX, I Y REAL A,B,C,D
m A L PNEW,POLD,DELP M A Z OLDE
! l a t t i c e indices !values of P a t neighboring p o i n t s !temp v a l u e o f P a t c u r r e n t p o i n t !old energy
cccCccccccccc~cccccccC:ceceeeeccccecccccecccccccccccccccccccecccceccccccc troll vaZaas tinftfaliza vdaea
s=w=a
*
344
B. Pr~granasf o r the Bganb;ples C
aa
200 X DO 10
&m0. B=O C=Q
e
.
B=O , XF (XX .ET. EX) A=P (IX+Z,TT) IF (EX: .GP. 1) mP(ZX-l,m) IF (IT LT * m) C=P (lx, n+1) IP (XY .CF. 1) D=F(SX,a-l)
.
POW=E (IX,3?I) ZF
{ B m C m {ZX, ZX)
.EQ.
MQM)
I field wa2-s at aefgWarAng I l a k t f c r s poknkes
PmH
/c* (A+WC+D)
!relax
B (EX, TV)=EmW n {Earn *m*0 . ) B E a a s ( (PQW-Prn) IPOLD)
EL= DHm=mS(PmW)
EHD
XF
LP ELSE Em=Pam
m C
fdanfe relax DIR-2
b e d con&
fF
IF (IX .or, r) (3Y .elf. 5)
m
f ~ m**2 -~) ( P m - D )**P
C
100 200
COHTXm COmXm
G
MTUREI END
ccceccccecccccccecccccccccccccecccceccccc~cccccc~ccccccccccccccccccccccc SUBROUTINE fNIT C initializes constants, displays haader screen, C initializes menu arrays for input parameters
cccccccccececceeeeeeL:cccccceccccccecccccecccccccccccecccccccccccccccce~c C
Global variables: INCLUDE 'IX0,ALL8 INCLUDE MENU. ALL' INCLUDE PAMM E G' @
.
!program description
DfmMSION BESCRP (201 INTEGER MREAD,NTmT,NGMPH
!number of lines far each descriptian
ccecccececccccec~ccccccecccccecccccccceccc~ccccccccccc~L:cccccccccccccccc C
get envir~nmentparameters
GALL SETUP
d i s p l a y header screen DESCRP (1) = 'EXAMPLE 6 DESCW(2)= ' S o l v i n g LaglaceH"s E w a t i o n i n Two Dimensions' MME&D=2 t e x t output description DESCRP ( 3 )= ' i t e r a t i o n , energy, change i n energy, DESCRP (41 = ' and t h e maximum change i n f i e l d ' NTEXTa2
'
graphics output description DESCW (5)= f i e l d v a l u e s ' NGWH-1
FIRST=, TRUE,
!is t h i s t h e f i r s t t i m e t h r o u g h t h e menu?
set u p c o n s t a n t p a r t of menu CA% muu item 9 h a s a d i f f e r e n t u s e i n this program MTYPE (9)=NTTTL& MBMPT (9)= V ) Change l a t t i c e s i z e o r e n d a l t o g e t h e r ' MLOLIM ( 9)=Q NWILXM (9)-1 MTYPE (2 3f =FLOAT N P W T (13) = ' E n t e r f i x e d value 05 t h e f i e l d f o r UPPER boundaryt MFAG(13)= ' F i e l d on UPPER boundary6 MLOLIM (13)=FMXW MHXLIM (13) = F m X LS (13)=FMfN MTVPE ( 1I 1 =FLOAT M P m T ( 1 4 ) = ' E n t e r f i x e d v a l u e of t h e f i e l d f o r MTAG(14)= ' F i e l d on WWR boundaryr MLOLIN (14)-PHI@ MNILXM (l4 ) =FMAX m A L S ( 1 4 3 =FEiLAX
MTmE ( 1S 1 -FLOAT M P W T ( 1 S ) - ' E n t e r f i x e d v a l u e OE t h e f i e l d f o r LEFT boundary' NTAF (15)= ' F i e l d on LEFT b o u n d a q r NLOLIM (15)-FMIN MHILIM [IS)=FMAX W A L S (5 5 1 - F M X
-
MTmE 11 61 -FMAT W W T (16) * E n t e r f i x e d v a l u e of t h e f i e l d f o r RIGHT boundaryf MTAG (16) = ' F i e l d on RXGNT boundaryf
MTYPE (17 f =NOSKIP m W F T (171=
+ 9 o you wish t o e n t e r l r e v i e w / d i s p l a y i n t e r i o r bound cond?" NTAG~S7)-"Enterlreview/dI,sp~ay i n t e r i o r boundary c o n d i t i o n s 8 MINTS (17)=0 mmLS (17 ) =35
T h i s s e c t i o n of t h e menu (from 25-33) i s called from BNDRP MTYPE (25)-MTITm MPWT(Z5f-"Interior MLOLTM (25 f m 2 mTLSM ( 2 5 )=1
Boundary Conditions Menu*
MTVPE f 26)=MTITLE W W T (26) 11) i n p u t r e c t a n ~ l a rbaundary eondft i o n s ' MLOLTM (26)-0 MHILIM (26) -0
MTUPE (271=MTITLE -'2) i n p u t 4 5 d e g r e e l i n e boundary condi t i o n s " MLQLIM (27)-0 MHILSN (27 ) =Q M P W T 127)
MTVPE f 281 =MTTTLE WREIIPT ( 2 8 ) m-3) review boundary c o n d i t i o n s ML0LIM (28) =Q Mf-fILXM(28f =Q
MTUPE 129) -MTXTM MPWT129)="4) mQLTN (291 m 0 MWXLIM (291-0
d i s p l a y boundary c o n d i t i o n s
NTVPE f 30 1 =NTTTLE plIpWTt30)="5) r e t u r n t o main menu" MLOLXM ( 30) =0 MWTLIN (30) =0 M T E E (311 =MCROIC NPWT (31)= 9 n t e r Choice" MTAG ( 3 1 ) = p 3 J 232 32 32 32 32' MLOLIM (33.1=l MHILIN f 311 =S MINTS (311 =S WmLS (31)=-S
"
MTUPE f 3 B 1 =FLOAT MPMPT(38)- ' E n t e r r e l a x a t i o n p a r a m e t e r " MTAG (38) = 'Re1a x a t f a n parameter' MLOLIM (38) =0, HWILIM 111(38)=2. mEBLS (38) =l.
MTVPE f 3 P f =NOSRIP mWT(39)='Do you want t a s p e c i f y a s u b l a t t i c e t o r e l a x f i r s t ? # M T E ( 3 9 ) - 9 e Z a x a s u b l a t t i c e first?' MINTS f 39) =0 MREAZS (39) 4 4 .
MTVPE ( 4 0 ) =NUM N P M P T ( 4 O ) = 9 n t e r l a w e r l e f t X v a l u e for s u b l a t t i c e ' NThG(bO)=%~owr l e f t X s u b l a t t i c e v a l u e 8 MLOLfM (40) =l E31.IILlN( 4 O ) =NXHAX HlMTS t4Of =l MTWE (41)=NUN @ W T ( 4 1 ) = @ E n t a rlower l e f t Y v a l u e f o r s u b l a t t i c e # NTAG f 4 1 ) Lower l e f t V s u b l a t t i ~ ev a l u e p
MZQLXM(41)=1 MNILTM ( 4 l ) =NUHAX EIHT5 (41 1 m1 MTYPE ( 4 2 ) =NUM W M F T 142) E n t e r upper r i g h t X v a l u e f o r s u b l a t t i c e ' MTAGf42J='Upper r i g h t X s u b l a t t i c e v a l u e t MLOLTN (42)=l HIWILIM ( 42 1 = N X m X MINTS (42)=1
MTVFE ( 4 3 ) =NUM IrlPmT(43)='Enter upper r i g h t Y value f o x s u b l a t t i c e " MTAG(43)=?Upper r i g h t Y s u b l a t t l c e v a l u e " MLOLZM ( 4 3 ) =l MWILLN (43 =KXMAX WTHTS f 4 3 f =l NTYPE f 4 4 f EMTITLE WMPT 144) =' f n l t i a l F i e l d Value Menut MLOLIM ( 4 4 1 1.1 MNILfM[44)=1 MTYnE ( 4 5 f -HT1 TLE HPmT(45)=") Read i n i n i t i a l v a l u e s from a f i l e ' MLOLIM ( 4 5 f =Q MNTL1W (45)=O
MTYPE ( 4 6 ) =NTITLE
348
B, Pr~gr~rns for the Ezamples M P W T t 4 6 ) = f 2 ) Set f i e l d a t all l a e t f c e p o i n t s to one valuee NLQLIM 146 ) =0 MWILIM f 46 ) =O N T P E 4 47)-MTITm m M P T (47)-'3 ) h a v e fi e l d v a l u e s unchanged1 NMLTW ( 4 7 ) =0 MHXLXM ( 4 7 1 ~ 0
NTYPE ( 48) =MCM P m T 148) = q n n t e r Ghcica"
NTAG (48)='449 51 5 Z r NLOLTN ( 4 8 f -1
NMTLTN (48) -3 MINTS (48)m2
MTVPE (49)=CWSTR a W T (491 = ' E n n t r name af d a t a file* MTAGf49)- * F i l e with i n i t i a l values far t h e f i e l d ' MNXLIM (49) -12, MZMTS (49)1 3 . MSTRMG IMTNTS (49)) %exmpl S, i n r WTYPE f 50f -SKIP tS ( S O ) ..SO *
NTYPE (51) =FLGCAT W W T ( S 1 ) = ' E n t e r i n i t i a l v a l u e f o r the f i e l d '
MTAG (51)= q n i t i a l Field Value' MLOLJN (51)=FM1N WMILIM (S1) mFM2PX LS (511 = (FmX-FMXE)/2
MSmNG (MINTS (86)) = 'exmpl6. g r f MTVPE { 87 ) =NUM W W T 1 8 7 f = 'Enter
the display f r s w e n c y f o r t h e fieldr MTAG187)- ' F i e l d display frequencyt NLQLIM(87)a 1. MBTLXH(87f- 100. MINTS (87)= 10
-
M P W T (88)
?Enter n u a e r of contour l e v e l s ' MTAG (881 = * Hu&er o f c o n t o u r l e v e l s @ MLOLIM(88)= 1. MKILTM (88) M L E V MINTS (88)= IQ
c PITYPE (89)=SKIP maLS (89)=90. C
MTURN END
~ece~e~c~~~c~~~ee~~~cecccceeccccccccecccecccceccccccecc~cccccceccc SUBROUTINE UTTIC
e g e t s l a t t i c e i i z e from s c r e e n and c a l c u l a t e s best way t o d i s p l a y t h e C f i e l d a s a s ~ i ci h a r a c t e r s b a s e d on l a t t i c e s i z e and t e r m i n a l s i z e ; C resets a l l boundary c o n d i t i o n s and d e f a u l t menu v a l u e s
ccc~~~~c~cc~cccce~cecccccccccccccc~ecccccccccccceccccccccc~ccccccccccccc C Global variables: INCLUDE ' P A W . EC' INCLUDE "IOIALLs INCLUDE 'MENU, ALL' INCLUDE 'mP,E6* C Local v a r i a b l e s : INTEGER END XNTZGBR I X , I V , IBC TMmGER MXHI,NYHI,NXLO,NPLO INmGER NXDEF,NYBEF LOGICAL MSET C Functions: XNmGER YESMQ, GETGNT WGIGAI, LOGCVT
!end program ! l a t t i c e i n d i c e s , BC i n d e x ? l i m i t s sn l a t t i c e size !default l a t t i c e s i z e s f r a a e t parameters? !user input functfans !change f , O t o t r u e and f a l s e
cccccccccccccccccccccccccccccccecccccceccc~ccccecceccccccccccCeccccccccc C
C
G C
a l l o w user t o e n d t h e program CALL C L E a I F (.NOT. FIRST] THEN EMD=YESNQ(O,? Do you want t o e n d t h e program?@) IF (END .ea. 11 CALL FGNXSW ELSE the l a t t i c e s i z e i s d e t e r m i n e d by a r r a y s i z e and t e r m i n a l s i z e ; i f you're u s i n g g r v h i c s , t e r m i n a l s i z e won" t a t t e r , set NXNI=%XfrYIX and NYHX-HYM NXHX=MIN (TRWXD-2, WXWX) NYHSmMIM (TMLIN-3, M Y W ) NXDEFmMZN {MXHI, 20) NVDEF-MIN (WVMI,201 NXLQ=HXM (S, NXDEF) NYLQ-MIN (S, NVDEF) END I F
C G
cpt l a t t i c e g a r a m t e r s from t h e t e r m i n a l NX=GET3NT(HXDEF,NXL0,TJXNI,r E n t e r number o f X l a t t i c e p o i n t s r ) MY=GETINTINVDEF,NVLQ,NYWIIP E n t e r number o f Y l a t t l c e p a i n t s r )
350
B. Programs far the Ezamples
calculate parameters fcs best looking display IF (2*MX .LE, T R M I D ) THEN XSfCIP=.TRm. !skip spaces in x XCNTR=(TRWID-2*WX)/2 Ikow t o center display f LSE
%SKIP=. FALSE, XCNTRm f rnMZD-NX) 1 2 END I F IF (XGNTR .LT* 3.1 XCWTRmI I F (2*NU .LEe T m L I N - 3 ) TWEN YSRIB=.TRUE. YCMTR=(TMLTN-2*NVf/2-2 ELSE YSKIP=.FALSE. YGNTRm (TWLIN-NY) 12-2 END I F IF fVCNTR .LT. O) YCNTRmO
!skip lines In y !how to canter display
set all bound ccnd parameters to zero NW.@
DB 26 IBC=I,BCmX XLL (IBC f =O VLL (IIBG) =B XUR (IBC)=O YUR IIBCI =O BCGEOH (TBC ) =6 BCVWL ( IBC 1 =O CONTIPJUE
ao zo, rxml,~xmx DO 30 TY=I,NYmX BNDCND ( JX ,IY l =Q CONTINUE CONTINUE
set up- limits on sublattice MHIZIM 4 INXLL) =NX HEELIN (SNYLL)=MY NHILIN IINXUR)=NX MNILIM ( I N Y W ) =NV
allow for resetting of defaults IF (FIRST) TWEN FIRST=.FUSE, ELSE MSET-LOGCVT (YESNO (0,p Da you want t o reset default values?' 1 1 IF (-SET) THEN !upper bound. eond. mMLS ( 1 3 ) = m T N !lower bound. eond. W A L S ( 14) = F W X
NmALS (15)-FMX ! L e f t bound. eond. MREALS (S6 ) =FMIN !r i g h t bound. eand. !amega MREZLLS (38)=l, MINTS (391 !sublattice? flower l e f t x s u b l a t t i c e MINTS f 40)=l !upper r i g h t x s u b l a t t i c e MINTS ( 4 1 f =l MINTS ( 4 2 ) =1 !lower l e f t y s u b l a t t i c e !upper r i g h t y s u b l a t t i e e MINTS ( 4 3 ) =l MINTS ( 4 8 ) = Z !PTYPE MREALS ( 4 8 1 -2 MSTRNG [MINTS f 49) 1 'exmpl G. i n r W A L S (51) (FmX-FMIN)/2 !I n i t i a l P v a l u e MIMTS (73) -TXTTRM MSTRNG (MINTS (75) 1 "exmpl 6,txtt MINTS ( 7 4 ) =TXTFIL MINTS ( 8 3 ) -GWTRM MINTS (84 ) =GWWRB MINTS ( 851 -GRFFXL MSTRNG(HfNTS(86)) = 'exmpl G.grEp MfNTS(87)- 10 !g r a p h i n 9 f r e q u e n c y !nu&r of c a n t o u r l i n e s MINTS (88)- 10 END I F
-
-
END IF
e RETURN END
cccccccccccccccCccccccccccccccceceeeccecccccceccccccccccccccccccccccc~cc SUBROUTINE PARAM (P, END ) C gets p a r a m e t e r s from s c r e e n C e n d s program on r e q u e s t C closes ald f i l e s C maps menu v a r i a b l e s t o program v a r i a b l e s
C C C C C
a p s n s new f i l e s c a l c u l a t e s a l l d e r i v a t i v e parameters p e r f o r m s c h e c k s an s u b l a t t i c e p a r a m e t e r s set t h e f i e l d t o i t s i n i t i a l v a l u e s (P) a n d c o n t r o l s e n d i n g o f program (END)
cecceecccec~cc~ccccccccccccC:cccc~ccccccC:ceccceccceec[:ecccccccccccccccccc C Global variables:
INCLUDE %MENU. ALLt INCLUDE IIO,ALLf INCLUDE VAMN. E6' INaUDE W P E 6" C In~>~lt/outpv u at r i a b l e s : WAL P { N X M , N Y W ) LOGICAL END C Local v a r i a b l e s : INTEGER TYPE, GEOM INmGER I X , I Y C Functions: LOGSGAL LOGCVT INTEGER GETlNT
.
! fi e l d v a l u e s
lend program? ! t y p e a n d gesm of bound cond ! l a t t i c e Indices ! c o n v e r t s 1 and O t o true and f a l s e ! g e t i n t e g e r from s c r e e n
eccecccccccccCcceccccccccccccccceccccecccccccccccccccCcccccccccccccccccc G 10
e
get input from terminal CONTINUE MINTS (INTERR)=O f reset value get all parameters except interior bound cond CALL CLEAR CALL ASK(3,ISTOP)
C C
c C
C
C C
G C
G C
start fresh or end altogether, if so requested IF (MmALS IImIN) e E Q * STOP) THEN END=.TRUE. RETURN END IF set basic boundary conditions before doing interior bc UPPER=mEBLS( fUPPER) LomR==ALS (IL m R 1
RIGHT-mEALS (IRIGHT) GEQMmmCTGL TYPEmDRCWLT CALL SETBCfP,GEOM,TUPE,UPPER,~,NXINVINY~ CALL SETB@(P,GEOM,TYPE,LOIER,lIMXI~,If CALL sETBC(P,GEOM,TVPE~~FT,~,I,~,NY~ CALL SETBC (P,GEQM,TYPE,RfGET,M, NX,1,MY) need to know if graphics are available GTEM=LoGCVT (MINTS( XGTEWI j allow far input of interior boundary conditions IF (HINTS(INTEm) .Ea. 1) CALL BNDRV (P) IF (MINTS(INTERR) .EQ. 1) GOTO 10 close files if necessary IF ( T N m .NE. MSTRMG [MINTS(ITNAME) 1 + CALL FLGLOS (TNANE,TUNIT)
physical and numerical paramters OMEGAmWALS ( XOmC1A) S~UT=LOGCVT(MrNTsgzsvs)f NXLL-MINTS (IMXLL) NYLLmMINTS (INVLL) MXm-MINTS (SNXUR) NYUR=MIMTS (INYUR1 PTYPE=&BS (MREALS 4 ZPTUBEI PFILE=MSTRBG (MINTS(IPFILE)) PINITmmALS f IPINIT)
e
e
c
text output TTERM=LQGCVT1MfNTS(ITTERM)f TFILE=LOGCVT(MIMTS(XTFILEfj TNm-MSTRNG (MINTS(ITMAMEf
graphics output GHRDCP-LoGCVT (HINTS (IGWRD11
GFILE-LoGCVT(MINTS(fGFILEf1 GNMEmMSTRNG (MINTS (IGHAME 1 1 NFBEQ-MINTS INFREQ) NLEVzMINTS ( XMLEV) open f i l e s I F (TFILE) CALL FLOE)EM(TE;IAME,TUNITl ! f i l e s may h a v e b e e n renamed MSTRNG (MSWTS (ITHA=] 1 =TNME check s u b l a t t i c e parameters I F f fNXLL .GT. NXUR} .OR, (NYLL .GT. NYUR)) THEW m I T E (OUNIT, 40) CALL ASK ( ENXLL, TNYURI NXLLmMINTS (INXLL) NYLL-MINTS f INYLLf UXUR=MINTS (XNXUR1 NVUR=NINTS (SNYUR) GOTO 39 END I F F O m T (' S u b l a t t i c e p a r a m e t e r s must have u p p e r r i g h t v a l u e s + "greater t h a n l o w e r l e f t ' } GALL CLEAR
set P t o i t s i n i t i a l value I F (PTYPE .EQ. 1) CALL MADSN (Pf s o m t i m e s i n READIN BTYPE is c h a n g e d IF (PTYPE .EQ. 2) THEN DQ 60 XX-I, NX DO 70 IY=l,HV I F (BMBCND (IX,I Y ) CONTINUE
p
f read d a t a i n
!set a l l non bound cond p o i n t s t o BSNIT .EQ. 6 ) P ( I X , I V ) ..PINIT
CONTINUE ELSE I F (PTYPE .EQ. 3 ) THEN CONTINUE END SF
? k e e p P the same
L
C C
reset PTYPE menu p a r a m e t e r s s o t h a t P r e m a i n s u n c h a n g e d d u r i n g runs unless t h e u s e r e x p l i c i t l y requests otherwise NSMTS (IPTYPE) = S MRmLS (IPTVPE) 13
e RETURN
END
cccc~ccecCCccccccecccccccC:ccccccccccccceccccccC:cccccecccccceccccccecC:ccc svBRovTnME BNDRY (P C o b t a i n s i n t e r i o r boundary c o n d i t i o n s from u s e r (P)
ccccccccCCcccccccccccccceccccceccccccccccc~c~ccccccccccccccecccccccccccc C Global variables: INCLUDE VPAMM.EG1
354
B, Progmms for the Egamptes INCLUDE I W . E 6 @ INCLUDE WENU. ALL' INCLUDE ' 10.ALLC C Ingutloutput variables: m& P ( N X W , N V W ) c Local variables: INTEGER TYPE INTEGER XLBXST,XWIST INTEGER VUDIST, YLDIST INmGER UPLIM C Funetfons: ZNmGER GETZNT I Z E U GETFZZ"
!field values
!type of b a u n d c o n d ! d i s t a f d i a g t o l e f t and r i g h t b c ! d i s t o f d i a g t a u p p e r a n d lower b e ! u p p e r l i m i t t o diag l e n g t h !get i n t e g e r from s c r e e n E g e t f L o a t f r o m screen
ceCcecce~c~cc~eec~cceccecccccccccccccceeccecccceccccccccccce:ccccecccccc~ ! c u z r e n t l y o n l y d i r i e h l e t bc i m p l e m e n t e d
TUPBcDRGWLT C
1
CALL GLEm
! d i s p l a y bound c o n d menu
CALL ASK ( IBCWU, ICBNDRY l G C
get d e t a i l e d g e o m e t r i c a l i n f a r m t i o n f a r r a c t a n w l a r b.c. IF (M-LS IBNDRY ) EQ. -1) THEN XF f m C .LT. W W ) THEN !u&ate nulnber aE b-e. NBC=NBC+ I BcCEOM (NBC) =mCTGL !set g e o m t r y E n t e r l o w e r l e f t X v a l u e pj XLL [ N E )= GETINT IZ,2, NX-I, YLL (=C) = GETIMT (2,2,NU-1, E n t e r l o w e r l e f t U valuer 1 XUR INBC 1 = GETINT (XLZ (NBC),XLL(NBC1 eEX-lC E n t e r u p p e r r i g h t X v a l u e * 1 YUR f WBC ) = GETINT (YLL (NBC), YLL (NBC1 W-1, g E n t e r upper r i g h t Y v a l u e ' B ~ v A L ( N B c ) ~ E T P L T I P N J N ~ F M ~ M ~EFn Mt eXr~ f*i e l d v a l u e CALL SETBC (F, BCGEOM (NBC) ,TYPE, BCVG (NBC j C XLL { B C )I XUR ( m C ) YLL (NBC) ,VUR (%BC)1 ELSE 1 t o o many bea. S WRITE (OUWIT, 3 0 ) !display warning m s s a g e a I T E (OUNIT,4@) GALL EIAUSEftto continue...',%) END I F
.
@
@
+ 4"
4"
G C
@
get d e t a i l e d geometrical i n f o m t i o n f a r d i a g o n a l b.c, LS fIBNDRYf .EQ* -21 THEN IF fNBC .LT. E M X ) THW NBC=NBC+"l !update n u d e r o f b . ~ . ~ s BCGEOM (NBC)=DXAGNL !sat g e o m t r y XLL (NBC) GETXNT ( 2 , 2 , NX-2, ' E n t e r f i r s t X value ') VLL (NBG) = GETINT ( 2 , 2 , MY-lc "nter f i r s t Y value '1 XUR(NBG) = GETINT ( 3 , l, 4, ' E n t e r q u a d r a n t : 1, 2, 3, o r 4' ) make s u r e t h a t d i a g o n a l s t a y s w i t h i n t h e l a t t i c e XRDZST=HX-l-XLL(HBC) XLBISTmXLL (NBC) -2 YUDTSTmMV-l-YLL(NBC) YLDIST=VLL (NBC) -2
-
+
XP (XUR(NBG) .EQ. 1 ) TWEN UPLIM=MIN (XRDIST, YUDIST) ELSE I F fXUR(NBGJ .EQ. 2) THEN UPLlM=MIM (XLDIST, YUDXST} ELSE I F (XUR (NBC) .EQ. 31 TWEN UPLXM-MIN (XLDf ST, YLDIST) ELSE fF (XVR (NBCf .&Q. 4 ) THEN UPLIM=MTU (XRDZST, YL-) END I F YUR (MBC) = GETINT (UPLXM, 0,UPLTM, C E n t e r l e n g t h o f 45 d e g r e e l i n e (max i s d e f a u l t ) * ) B ~ A (BBC) L =GETFLT (EMTEJ,FMINI F m X , * E n t e r f i e l d v a l u e f CALL SETBC f P, BCGEOM f NBC ) ,mPE, BWAL (NBC1 ,XLL {NBCj I XUR YLL (NBC),VUR (NBC) ELSE ?too m n y b . c ~ * ~ s WRITE (QUWIT, 30) ! d i s p l a y w a r n i n g message WRITE (OUNIT,4Q) CALL PAUSE('t0 ~ o n t i n u e . * . ~ , l ) @
-k
C ERE) I F C
. .
ELSE I F (MREALS (IBNDRY) EQ -3 1 THEN I F (MBC .EQ. 0) THEN m 1 T E (OUNISP, 2) CALL PAUSE('to c o n t i n u e . . . * , , l ) ELSE GALL REVIEW (P 1 END I F
!r e v i e w bc
ELSE I F (MREALS(IBNDRY1 .EQ, -41 TWEN I F fNBC .&Q. 0 ) TWEN WRZTE (OUNfT, 2) CALL PAUSEl'ta c o n t i n u e . . . " , l ) ELSE
!display b c
!nothing t o r e v i e w
G
TF (GTEWJ THEN CALL GRFBC
ELSE CALL DSPLBC (P END I F END I F
!nothing t o display
!graphics
?ns g r a p h i c s
C ELSE I F (MRERLStIBNDRU) .EQ, - 5 ) TWEN RETURN END I F
! g a b a c k to Main menu
C
GOTO 1 C JO
90 2
POmT (
+ FOmT +
Y o u have e n t e r e d t h e m a x i m m nu&er
' conditions allowedf) ' You c a n a d d more o n l y
o f baundaxy"
i f you d e l e t e o t h e r s f i r s t e u s i n g t h e REVIEW o p t i a o l ) F O m T ( @N o i n t e r i o r b o u n d a r y c a n d i t i o n s h a v e b e e n e n t e r e d r ) (
358
B. Programs for the E g ~ m p k f i c END
cccceccccCccccc~ceecccccecccccccccccccc~cececece~eeceeccce~ccc~ccccccccc SUBROUTSHE S E m C (P, GEQM' TYPE, PVALW, XII 242, Y l , V21 C g i v e n a n i n t e r i o r boundary c o n d i t i o n whose geometry i s g i v e n by GEOM, G X I , X2, U1, Y2; set P array e l e m e n t s t o PVUUE and set BMCCND t o TYPE
CCccceccc~ceccc~eccccececcccceeccecccccccccccccccceccceccccccccCcccccccc G Global v a r i a b l e s :
INCLUDE
PAmM. E 6f
C Input variables:
P (NXNa,X,# Y M f INmGER GEQN INTeGER TYPE PVALUE INmGER X1,X2,Yl ,V2 C Local v a r i a b l e s : TNTEGER XX, I Y , I XNTEGER XSLaPB,YSLQPE =AI,
!f i e l d v a l u e s t I l 0 )
!geometry t y p e o f bound cond ! t y p e o f bound cond ! v a l u e o f P on baund !sgmcf fy l o e a t i o n of bound ~ o n d ! l a t t i c e indices ! s l o p e s for d i a g o n a l b c
ceccccccccccccccecccccccccc~ccf:cecccccccccccccceceeccccccccccccceccccccc
20
SF [GEON *EQ. RBCTGL) THEN no ro 1x=xl,x2 P I I X , V 1 1 =PVALOE P ( IX ,U2 ) =PVALUE BNDCND ( I X , P1 1 = m P E BNDCNB (IX, V2 1 =TYPE CONTINUE 00 20 SY=Yl,VZ P (XI, IY) =PVALUE P 4x2, I Y f =OVALU& BHOCND (X1,Ifl) -TYPE BNDCND (X2, IY) -TYPE CONTINUE
flower s i d e f u m e r side
!left s i d e I right s i d e
c f o r d i a g o n a l , V2 is l e n g t h and X2 is a n g l e ELSE IF fCEOM *Ea. DIAGML) THEN I F ((X2 .EQ, 1) .OR, ( X 2 .EQ, 21) YSLOPE=1 EF ( ( X 2 *EQ. 3) .OR, fX2 .EQ, 4)) YSLOPEm-1 I F ((X2 .EQ. l! .OR. (X2 .EQ. 411 XSLOPE-1 I F ( (X2 EQ. 2) OR. (X2 .Ea. 3) 1 XSLOPEm-1 DO 30 I=O,Y2 /Y=yl+I*?ISLOPE IX=Xl +X *XSLOPE P (IX, f Y Z =PVALUE c d i s p l a y boundary c o n d i t i o n s (P} a s s m a l l letters C all nan-bound c o n d i t i o n s are d i s p l a y e d a s ' - # , regardless of value C s o u s e r may c l e a r l y see boundary c o n a t i o n s ; always w r i t t e n t o QUNLT BNDCMD (IX, I Y 1 -TYPE 30 CONTIMUE END I F C
.
c =TURN END
.
ccccccccecccecccecccccccccccceeccccccccccccccccccccccccccccccccccccccccc SUBROUTINE DSPLBC (P) C display boundary c o n d i t i o n s (PI a s s m a l l l e t t e r s C a l l non-bound conddtdons are d i s p l a y e d as r e g a r d l e s s of v a f u a C ss u s e r may c l e a r l y see boundary c a n d i t f o n s ; always w r i t t e n t o OUNIT ' m - " ,
c~c~eeccccccccecccecceccccc~~cecccccccccecccccccC:cccccccceccccecccccccec C Global v a r i a b l e s : INCLUDE ' PARAM. E 6' INCLUDE ' I Q . ALLs C Znput v a r i a b l e s : !f i e l d v a l u e s REAL P [NXmX, W U W C Local v a r i a b l e s : llattfee indices INTEGER XX, IV INTEGER PTEMP ! f i e l d a t c u r r e n t lattice site C a'&RX1F JELD (NXMAX) ! f i e l d a s c h a r a c t e r data C TER"80 BLEK !blanks for c a n t e r i n g In X CHWCTER* P ASRI S, NEC;ASK O :25 ) ! c h a r a e d a t a for d i s p l a y BA= BLNK / "'I DATA &SKXI/'-* / DATA N E [ ; A S X / f a a ' , f b ~ , ' e t , ' d r , ~ e ~ , F Z t , ~ ~ ~ , ' ,h6~kEte, eil@e,, l sm j f8 , 4 rnrlr~',"p","',"r ,'aF ,'t',~u~,'~~,~w~,~x',*yf* z @ / f
ceccccececcccccceceeccc~cececcccccececcccccccccccccecccccceccccccccccccc CLEAR DQ 20 IY-l, YCNTR WRITE (OUNIT,*f CA=
20
!canter output
CONTINUE
c
50
10 15 100
DO 100 IV=NY,1,-1 DD 50 IXm1,NX I F (BMDGND(IX,IY) .EQ, 0) THEN !set non-b,c. t o ' - P FIELD ( Z X I =&SKI1 ELSE PTEMPsNINT (P ( I X , TY) 1 !change b.c, d o a s c i i v a l u e s I F (PTE1VIB .GT, F M X ) PTEMPmFWX IF (PTEMP .LT. FNIN) PTEmmFMIN FIELD (SX) =NEGASK (PTEMP1 END I F CONTZNUE I F (XSKXP) THEM m Z T E (OUNIT, I O BLMK (1:XCNTR) ,IFIELD f TX) ,IXm1, NX) ELSE WRITE (OUNIT, 35) BLMK 4 1 :XCNTRf ,{FIELD( T X ) ,IX=b, M X f END SF TF (YSKIP) WRITPZ (OUNIT,") ' F O m T ( I X , A, 100 (AI,1X) f F O R m T ( l X , A , TOO (Alf 1 CQISTINUE CALL PAUSE(' t o ga back t o menu..,@ , l )
c WTURN END
cccccccccecceccecccccccccccceccccecccccccccecccccccccceccccecccccccccccc
358
B, Programs far tbe Ezamples SUBROUTINE GRFBC C d i s p l a y boundary c o n d i t i o n s
a s d a s h e d l i n e s s o u s e r may i n s p e c t
C boundary c o n d i t i o n s ; a l w a y s w r i t t e n t o OUNIT u s i n g g r a p h i c s package
c~c~cc~ce~~cCe~~cccccccccccccecceeee~ceccc~eec~c~cc~~cec~~ C Global v a r i a b l e s :
SMCLUDE ' I0.ALL8 INCLUDE V&-, E6" XNCLUDE " W D B A . ALL6 C Local v a r i a b l e s : REAL BCX (5),BGV (S) INTEGER X, IX, I Y INTEGER IBC RE& XSLOFE, VSLOPE INTEGER SCREEN INTEGER PAPER INTEGER FILE DATA SCmEN,FAPER,FILE/1, 2 @31
I
! c o r n e r s of b o u n d a q c a n d i t i o n s ! l e v e l index, lattice i n d i c e s ! i n d e x on b o u n d a r y c o n d i t i o n s ! s l o p e o f d i a g o n a l BC ! s e n d t o terminal !make a h a r d c o p y !sand t o a f i l e
cecceecec~ec~~cc~cccccccc~cccceccccecccccccceccc~ccccececcccccccc~ecccc NPU)T=l TPLOT-1.
!how many p l o t s
C ILINPJE=Z Yrn=MY YMINml. XMf N-1,
?axes data
XM=PJX
YOVAL-XMIN XOVm=Y HIM NXT1CTC=5 MY TI@K=5 C MEL(lj='HX@ =EL (2)=wNksr TITLE=%~oudary c o n d i t i o n s t
!deseriptiona
CALL CTDEV (SCREEN) @A& GlrlODE CA= LNLNAX
!device nomination ! c h a n g e t o g r a p h i c s mode t draw a x e s
G
e C
d i s p l a y i n t e r i o r boundary c o n d i t i o n s as dashed f i n e s !loop over b,c. DO 200 IBCm1,NBC TP (BCGEQM(IBC1 .EQ. BLAGNL) THEN NPOINTm2 I F ((XUR(IBC1 .EQ, 1 ) .OR, (XUR(IBC) .EQ. 2 ) ) YSLOPE=I I F ((XUR(IBC) .Ea. 3 ) .QR. (XUR(TBCl .EQ. 41 1 y S ~ 0 ~ ~ m - l IF ((XUR(EBC1 .EQ, 1) .OR. (XUR(1BC) .EQ, 4) 1 XSLOPE=~ 1F ( ( X U R ( I N ) .EQ, 2) .OR. (XUR(1BG) .EQ. 31 1 XSLOPE=-1 EICX (1)=XLL (IBCI sex (2)=XLL ( x a c t +~SLOPE*VURIIBCI BCV ( 1 ) =ULL (IBG) seu (2)-VLL f IBC) +YSLOPE*YUR (1:BCl ELSE I F (BCGBOHfIBCf .EQ, WCTGL) THEN
200
NPOINT=5 BCX (1)=XLL (IBC) BCX ( 2 ) =BCX (11 BCX (3)=XUR (IBG) BCX ( 4 ) =BCX ( 3 ) BCV (1)=YLL (IBC) BCY (2)=YUR IIBC) BCV (3)=BCV 421 BCY ( 4 ) =acu (1) BCX (5)=BC% (1) BCV ( S ) =BCV (1) END I F GALL XYPLOT (BCX, BCY) CONTIMUB
fpfat boundaries
C C
end graphing session CALL GPAGE(SGREEN1 CALL TMODE
!end graphics package !switch to text mode
C RETURN END
~c~~~~~~~e~~~ccccceceeccecccccccI:ccccccceccc~cccccccc~cccccce~cc SUBROUTINE =VIEW (P ) G routine to allow user to review interior boundary conditions; C they can 1) leave as is , 2) delete, 3) altar field value
c~ccceccccCccceeccccccccccccccccecccccccceccce~ccceccccccccecceeeccccec~ C Global variables: TNCLUDE INCLUDE
'PZIMN. E C
10.ALLt
C Inputloutgut variables: REAL P (NXNAX, N V m X )
C Local variables: INTEGER IBC, JBC INTEGER WGICAL INTEGER INTEGER
RE&
GETINT, CHOICE: DELETE ( B C m X ) NDEL TYPE
m"I1FLT
! field
values
!index on bound eond user choice !delete this bound eond? !nu&er deleted !type of boundary condition !get float from user ?gat
ccccecceccccccecccccccccccccecceccceccec~ccccccce~ecccGceccccccccccccccc NDEL-Q
e Do C C
1 0 0 IBC=l,NBC" DELETE ( IBC) = FALSE.
.
!initialize
write out description af this bound con4 WRITE (OUNTT,S) IBC TF (BCGEON(XBC1 .Ea. DIAGNL) THEN WRITE (OUNST,10) X L L ~ X B C,YLL I (SW) , x m t x B e j I ~ ELSE XF (BCGEQM (IBG) .Ea. RECTGL) T m N m I T E (OUNIT,15) XLLfIBC) ,YLL(IBC) ,XUR(IBC) ,VUR (IBC) END I F WRITE (OUMIT, 2 0 f &CVAL(IBC)
~
~
360
B. Pmgmms for the Ezamples
+
CWOZCE=GETINT (1,1,3, 'Do y o u w a n t t o l l k e e p it 2 ) d e l e t e i t 3) c h a n g e f i e l d v a l u e ? F )
!do n o t h i n g I F (CHOICE .EQ. 1 ) THEN CONTINUE ELSE ZF (CHOICE .EQ. 2) THEN !delete i t NDEL=NDEL+Z DELETE ( SBC ) = TRUE, TYPE= WON !releases b.=. C U L SETBC (P, BCCEQH ( f BC) ,TYPE, BCVAL (IBCf ,XLL (XBC) ,XUR f IBC) , + YLL ( r a e ) ,YUR t s ~ ctt ELSE I F (CHOICE .Ea. 3 ) THEN !get new f i e l d v a l u e BCVAL [IBC) = m T F L T (FMTNPFN3:N?FWX, E n t e r f i e l d v a l u e ' ) END I F CONTXMUE
.
@
get. rid of spaces l e f t i n b o u n d cond set when o n e o r m o r e i s deleted XF (NDEL .NE. O) THEN IK=O IJBG l a b l s o l d set o f b o u n d c o n d l I B C labels new set of b o u n d c o n d no 200 J B C = ~ , ~ ~ B C SF 4 DELETE (=C ) ) THEN GOMT f HUE ELSE: IBC=IBC+1 ! n e x t empty place XLL ( f B@) =XLL f JBCf !m v e up p a r a m e t e r v a l u e s t a t m x t empty piace VLL (SBC) PVLL (JBC) x v {~r s e j = x v (~J B ~ ) YUR (EBC) =YUR (JBC) BCGEOM ( IBCf =BCGEOM (SIBC) BCVAL 4 TBCf =BCVAL ( m C ) mI)I F CONTINUE !uMate n u & e r o f b.c.@s NBC=NBC-NDEL END XF
DO 300 IBC=Z,NBC reset b o u n d a r y c a n d f t l o n s i n case some of deleted b o u n d c o n d w r a t a over o t h e r s a l s o a d j u s t s t h a s e f a r which t h e field v a l u e was c h a n g e d TYPE-DRCNLT CALL SETBC (P, BCGEOH (IBC) TYPE, BCVAL (XISC) ,XLL (IBC) ,XUR + YLL (XBC),VOW (IBCI CONTINUE: RETURN ( @ B o u n d a ~C o n d i t i o n # u & e r 6,12) P O M T ( * D i a g o n a l w i t h f i r s t e 0 o r d i n a t e s = ( \ I 2 ~ ,~? , 1 2 , + 1 , quadrant =' , I 2 , ', a n d 1 e n g t h m f 1 2 ) F O m T ( * R e c t a n g l e w i t h l o w e r l e f t a t [' ,I2,' ,',1 2 , + * ) a n d umer r i g h t a t ( p , Z 2 8 @ , t * S 2 t f ) ' j F Q m T C * T h e f i e l d i s fixed a t ',,ZPIE;l2.5)
FO-T
c END
~~~ccc~~~c~cc~cc~ceccccceccccccecccccceccccccc~cc~ccccccece~ccccccccccc SUBRoUTIHE READIN (P ) C r e a d i n f i e l d v a l u e s and boundary c o n d i t i o n s ; C r e a d s i n o n l y files w r i t t e n by s u b r o u t i n e IrORTOUT, and f i l e s w r i t t e n C w i t h same l a t t i c e s i z e
c~~~~cc~~e~~~~~~ccc~cccccccccc~ccccceccceccc~ceecccI:~ccccccccc C Global variables:
INCLUDE '1OlALir" INCLUDE @PA=M. E6' IPICLUDE '=NU. ALLf f NCLUDE "P. E 6" C Output v a r i a b l e s : RE& P (NXmX, M \ I ' S ( M c Local v a r i a b l e s : INTEGER IX,IV CTER*aO JUNK A L SUCESS INTEGER CHOICE INTeGER MX, MY, MOaGA C Funetion: INTEGER YESNO GHMCTERX40 CHARAC
l f i e l d values ! l a t t i c e indices ! f i r s t l i n e i f af no i n t e r e s t ! d i d w e f i n d a f i l e t o open? Iuaer answer ! p a r a m e t e r s from PFILE ! g e t yezsno i n p u t from u s e r !returns character input
ccccceeccccccccccceccccccccCcceccccccceccccccceccccccccccccccccccccccccc C U z l FZOPUZ (&FILE,DtfNZT, SUCESSf MSTRNG (MINTS ( I P P X ~f )=&FILE
10
!open t h e f i l e f o r i n p u t
!file may have been r e n a m d
I :
I F (,NOT. SUCESS] THEN CALL =ASK mTURI ELSE
!prompt a g a i n f a r inft P !if no f i l e was found
C
READ (DUNIT,S) JUMK FORWT (A)
5
? s k i p aver t i t l e
C C
15 C
l a t t i c e s i z e s must match; If t h e y d o n e t , a l l o w f o r o t h e r o p t i o n s mAD (DUNIT,*) K,MU,MOMEGA I F ( ( W .NE, NX) .OR. (MY .NE. M Y ) ) THEM CALL FLCLOS (PFILE, DUNIT) ! c l o s e it up m 3 T E (OUNIT, 15) NX,MV PORMT (' I n p u t f i l e h a s d o e s n o t have t h e c o r r e c t t ' l a t t i ce sf ze, I t i s 5 12, C by * ,I 2 f C H O I C E = Y E S N O ( ~ , ~ yyou D want t o try a n o t h e r f i l e T c ) I F (CHOICE .Ea. 0) THEM CALL WASK !pronrpt a g a i n f o r i n i t P RETUREa ELSE c (FFILE, 12, ' E n t e r a n o t h e r filename' 1 MSTRNG (MrMTs (IeFILEI f =eFILe GOTO 10 ! t r y t o open t h i s a n e END XF
END I F
c C C
100 3.10
i f we've g a t t e n t h i s f a r , we've o p e n e d a f i f e w i t h d a t a from a l a t t i c e o f t h e same size; f i n a l l y r e a d i n f i e l d DO 1QO IX=l,NX READ (DUNIT, l l O f (P (IX, 1"k") ,IU=1, WU) CONTINUE FORrJlAT ( 5 (2X, 1PE14.7) CALL FLCWS (PPILE, DUNIT) ?close f i l e END I F
C MTURtJ END
cccccce~cccccccceecccccceccccccccccccccccccccccccccccccccccc~ccecccccccc SUBROUTINE REASK C prompt again for i n i t i a l P c o n f i g u r a t i o n ; C c a l l a d o n l y i f r e a d i n g i n from a f i l e i s r e q u e s t e d and f a i l e d CCCCCCCCCCCGGCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCCCC:CCCCCCCCGCGC
C Glabal variables:
INCLUDE ' MEMU. ALL'
INCLUDE 'WP.E6" INCLUDE ' P W M , E G f CCCCCCCCCCCGCCCGGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCC C r e d i s p l a y i n i t i a l F i e l d V a l u e Menu, b u t d i s a l l o w c h o i c e 1 W W T (45) =@l) ( n a t a l l o w e d ) MLOLIM (481 12 MINTS [481=3 EIRaLS (481 -3
CALL ASK(44,52)
c PTWE-mS (MREALS tXPTYPE) 1 PINIT=MMALS (IPIMIT)
!set p a r a m e t e r c h o i e a s
C
MPMT(451-'lI) MLOLXM 4 4 8 1 =l
Read i n i n i t i a l v a l u e s from a f l l e Y r s s e t menu
C
RETURN END
c~cccc~ccc~ccccCcccccceeccccccccccecccccecccccccccccCccccccccccccccccccc SUBROUTINE PRNOUT(MUNIT,NLINES) C w r i t e o u t p a r a m e t e r s u m a r y t o MUNIT
~cccccccccccccccccccccccccccccccccccccceeccccccccccccccccccccccccc~ccccc C Global variables:
INCLUDE TTO.ALLt INCLUDE ' PPAMM.E6' C Input variables: XNTEGER MUNIT INTEGER NLINES
! f o r t r a n u n i t nunber ?number o f l i n e s s e n t t o t e r m i n a l
ccceccccc~ccccccCccccceccccccccccccecececccceccccccccccccccccccecccccecc I F (MUNIT .EQ, OUMIT) CALL CLEM C
m I T E (MUNIT, 5 )
I F (MUNIT .EQ, GUNIT) THEN WRITE (MUNIT, *J HX, WY, O M E m ELSE a I T E (MUNIT, 1 0 ) WX, MY, Om(;A WRITE (MUMIT, 1 2 ) UPPER, LOmR, LEFT, RIGHT I F (SUBUT) WRITE (MUNIT, 15) NXLL, MVLL, NXUR, WRfTE (MUNIT,*I ' ' m f T E (MUNIT, 3 0 ) WRITE (MUNXT,4Q) EMD TF WLINESm4 SF (SUBUIT) MLINES=NLIMES+l
NYm
C
S
lO l2 15 30 40 C
F O m T f O u t p u t f r o m e x a m p l e 6: S o l u t i o n s t o L a p l a e e t 's E q u a t i o n f + * i n t w o d i m e n s i o n s 41 F O m T (tNX=f,13,5X,'NV=t,,SJ,SX,* Om@ga=',IF6,3) F O m T (' f i e l d v a f u e s o n u p p e r , l o w e r , l e f t , a n d right are ' , + 4 (2X,F5.2) 1 F O m T ( # S u b l a t t i c e d e f i n e d by (' ,13, ,l , I 3 , ' I a n d t f , 413,"f"rf3f')') F Q m T (@X," ~ t e r ' , llX, 'Energy' 13X, * D e l t a E * , 12X, 'max D e l t a F' b F Q M T (8X,*----',1lX,'---m--' , 1 3 ~ @, @ , 1 2 ~ t , --...-------- 8 1 ----m--
RETURR END
ccccecc~cee~ccccccccecccccececcccccccccecccccccecccecececccccccccc~ccccc SUBROUTIME TXTOUT(MUNIT,NITER,EN~GUIDELE,DEL~,MLINES] C o u t p u t t e x t r e s u l t s t a MUMIT
ccccceccccccccccccceccececccccccceccccccccccccccceccccC:ccecccccccccccccc C Global variables: INCLUDE XXO.ALLf G Znput v a r i a b l e s : INTEGER NITER RE& DELmX, QLI)m m& ENERGY, DELE INTEGER MUNIT IMTEGER NEZNES
?nu&er o f i t e r a t i o n s !keep t r a e k o f changes i n P !current and d e l t a enstgy ! f o r t r a n u n i t nu&er !nu&er o f l i n e s sent t o t e r m i n a l ( I I 0 )
ccceecececccccceccccceccccccccccccccccccccccccccccccccceccccccccc C
I f s c r e e n is f u l l , clear s c r e e n a n d r e t y p e h e a d i n g s I F ( (MOD(WLIHES, TBMLXM-5) .EQ. O f + .AND. (NUWST .EQ. OUNIT)) THEN CALL PAUSE('to c o n t i n u e . . . @ , l ) CALL CLE&R hlRITE (MUNIT, 30) liaBP"1" ((MUNZT, 40) END PF I F (NUNST .EQ. OUNIT) NLINES=ULINES+f
C 50 30
40
~ T T E(MUNIT, 5 0 ) NITER, ENERGY, BELE, a e L m x F Q m T (8X,I4,3(8X,lPE12.5)) F Q m T (@X, I t e r f ,I l X , ' E n e r g y i , 13X, ' D e l t a E t , 12X, "max D e l t a P') F O m T (@X,'----' ,11~, L---mp -------@,12~,"-- ----------... r 1
564
13. Programs for the Es~mpfeg e =TURN EMD
cccccccccccccccceceeecccI:cccccCeccccccceccccecceccceccccececcccccccccccc SUBROUTINE DSSPLY(P,MONIT) G d i s p l a y f i e l d (P) a s a s c f l c h a r a c t e r s : bound cond a r e s m a l l letters, C non baund cand a r e i n c a p i t a l s ; o u t p u t s e n t t o MUMIT
~cee~~ec~~e~~~e~~~e~c~cc~c~ccc~cce~~eccc~~c G Global variables: INCLUDE C P m M , E 6" INCLUDE 'IIO.ALLC C Input variables: REAL P ( H X m X , N V W ) INTEGER MUNIT G Local v a r i a b l e s ; INTEGER IX, IY INmGER PTEWP
"
I f i e l d vaZues ! u n i t weCrew r i t i n g t o !lattice indices ! f i e l d at c u r r e n t l a t t i c e s i t e ! f i e l d as c h a r a c t e r data !blanks for e e n t e r f n g i n X WEGASK (0:25) 1 c h a r a c data f o r display
DAT& BLNK / / DATA A S K I I / ~ A @ , , " B \ * C ,'D~C'EC,'F',CG~,~H~,rI*~pJ',pKf,'LC,'M', '
~H',~~','p',~q~,rptr~*S'I'T~,*U~"V~*~liJC,'x',~Y'*r~'/
4-
DATA N E 6 9 S I C / ~ f , r b * ~ 6 " c ~ ~ d ~ , ~ f ' , ~ f * ,J*,pk~,fle,'m*, *~CICb~p~i8,~ + r n f , r o f, ~ ' p * , p ' q ~ , ~ r e I ~ s C , *, rUt~; ,f * ~ ~ , ~ W ~ , * X ~ , ~ ~ ' , * Z ' /
cccccccccccceecccccccccccccccccecccccccceccccecccccccececccccccceccccccc
20
I F (MUNIT .EQ. OURIT) THEN D 6 20 IV=I,VCNTR !center output WRITE (OZJNIT, * f ' ' CONTINUE ELSE m I T E (MUNIT,*) 'E'Fild v a l u e s arc?:' END I F
e DO f O O X V = N V , l , - 1 DO 50 IX=I,NX PTENPmWINT (P (IX, 1x1) !convert f i e l d value t o a s c i i I F (PTEMP .GT, F m X ) PTEMf"=FmX !keep t h i n g s i n bounds I F (PTENP .LT, FNIN) PTEIUaemFMfN I F (BMBCND ( I X , IU) EQ. O) FIELD [IX) =ASK11 (PTEMP) IF (BNDCND (IX, IV I NE. 01 FIELD (1x1 =NEGASK I P T e w j
. .
50 C:
CONTINUE w r i t e a u t a l i n e a t a t i n i f 3 f n o c s n t e r i n g done f o r TUNIT) IF (MUEIZT .EQ, TUNITf THEW W I T E (TUWTT, 16) (FIELD (1x1,I X = 1 , NX) ELSE I F (XSKIP) T m N WRITE (OUEIIT, IQ) BLNR f l :XCNTR) ELSE WRITE (OUNST, IS) BLNK (1:XCPJTR) END I F 1F (YSRIP) m I T E (QUNIT,*) '
,(FIELD (EX) ,IX=l, NX) ,(FIELD (IX) ,I X = l ,
NXf
10
15 16 100 C
END IF FORmT (1X,A,100 (AI,1X)) FORmT (1X,A,100 ( A I ) 1 FORmT (1X,100 (AIf 1 CONTINUE RETURN END
CCCCCCCCCCCC~CCCCCCCCCGCCCCCGCGCCGCCCCCCCCCCCCGCCCGCCCCCCCCCCCCCGGCCGCCC
SUBROUTSHE GRFOUT(DEVICEpPrPGRFIrJIXIWtE) C display contours o f the field P C the field valuas must be in an array that is exactly NX by NY; this ean be aecamglished with implicit dimensioning which rewires that PGRF and its dimnsians be passed to this routine ccccccc~c~cccC~cc~cccCccccccccccccccccccccccccceeccccceecccccc~cccccccc~ C Global variables: XNCLUDE * 10,ALLf INCLUDE rFAW.E6' INCLUDE 'GWDAT,ALLt C Input variables: INTEGER DEVICE tuhich device R&RL P (NXmX,N Y W I ffield values !NX and NU in d i s ~ i s e INTEGER MX,MY a E ; U PGRF(MX,MV) !field values for gxaphing REAL E ?energy G Local variables: !corners of boundary conditions REAL 8CX (5),BCY (51 INTEGER I,IXr XY !level index, lattice indices !largest and smllest field value REAL P m X ,PMSU !index on boundary conditions INmGER FBG =AL. XSLOPE, YSLOPE !slope of diagonal BC !data &S chaxaeters GTER*9 CMIN,CMX,CE !string lengths INTEGER LMIN ,LMAX, ELEN INTEGER SCMEN !send to terminal !make a hardcopy INTEGER PAPER !send to a file INmGER FILE DATA SCREEN,PAPER,FILE/lI 2 3 1 c~~cc~l~c~~~c~c~eccccec~cccccecccccecccccceccccecccccccccc~~ccc~cccc PW=O !set scale PMXN-P (1,I) DO 10 XXmf,MX DO 20 IVm1,MY IF (P(IX,IY) .GT. P m X ) PW=P(IX,IY) IF (P (XXIIY) .LT. PMTN) PMIN=P (IX,IY) !load field into P G W PGRF (XX,T Y ) =l? (IX,IV) 20 CONTINUE C
G
10
COE3"PSNlfE
G C
messages f o r the i~patlent IF (DEVICE .NE. SCmEH) m I T E (OUNIT,100)
C C
calculate parameters far grapking
NPW'I"=Z
!how many p l o t s
XPMT=l C ?bxtzcs data
Y m = m VHIN=1, XMIN-I
.
xm=m YOVAL=XMIW XQVAZ-VMZN =TICK-S HY Z15CK=5
c =EL(l)=@WXt !descriptions UBEL f2)=1NY@ , nm caLL c o ~ v (PMIN, a ~ e ~ x wL CALL CONVRT (PW, emx,LW) CALL CQKWT (E,CE,ELEN) IIGMXN (I:ZMLN) / / V m a x = ' / l INFQ="Prnln i CMX(I:LM) I/@ E=r//CE(l:ELE%) TZTLE=eSolutSons ta Laplacee*"sEquation' G
CALL GTDEV (DEVICE) IF (DEVICE .BB. SCREEM} CaLL GNODE GALL LNLMAX
fdeviw nodnation !change to graphics mode !draw axes
C
C
display interior boundary conditions as dashed lines DO 200 IBC=1,NBC !loop over h.e. IF (BCGEOM(IBCf .EQ. DIAGNLf THEE
RPOINT=2 IF ( (XUR (SBG) .EQ. 1) .OR. (XUR IIBG) XF ((XURtIBC) .Ea. 3 ) .OR, (XUR(IBG1 IF ((XUR(IBG) .EQ. 1) .OR. (XUR(XBC) XP f (XURfZBCf.E@, 2 ) .OR. [X@R(XBC) scx(1 =XLL(see) BCX (2)=XLL(IBCftXSLOPErCYUR (XBG) BCY t l ) =YLL(rset BCU 42 1 =YLL (IBC)tYSLQPEXYUR[ZBC) ELSE IF fBCGEOM{fBC) .EQ, WCTGL) THEN NPOf NT=5
.EQ. 2 ) Z YSLOPE=1 .Ea. 4)) VSLOPE=-P .EQ. 4)) XSLOPE-1 .EQ. 3 ) ) XSLOPE=-I
sex (11 =XLL(zsc) acx (2)=sex (11 BCX (3)=XUR{IBC) BCX ( 4 ) =BCX ( 3 ) BCY (1)=VLL(IBG) BCY (2)=YUR (XBCT) BCV f 31 =BGY (2) BCY (4)-BCY (I) sex (5)= ~ c (11 x SCU ( S ) =BCU (l) END IF ILINE=2 CALL XYPXIBT(BCX,BCY)
!plot boundaries
200
CONTINUE
C
ILIPJE=I CALL CONTOR(PGRF,MX,MY,PMIN,P~XINLEV) C C
end graphing session I F (DEVICE .NE, FILE) CALL GPAGEfDEVICEf I F (DEVICE .EQ. SCMEN) CALL TMODE
C
100
F O m T (/,
Patience, please;
lend g r a p h i c s p a c k a g e ! s w i t c h t o t e x t mode
autput going t o a f i l e "'1
C
RETURN END
cccccCccccecccecccc3ceecccccccccccceccccccccccccccccccccccccccccccccccccc SUlEIRoUTIME WRTOUT f P ) C w r i t e o u t f i e l d (P1 a n d b o u n d a r y e a n d i t i o n s t o GUNZT f o r r e a d i n g b a c k C i n as i n i t i a l c o n d i t i o n s a r f o r g r a p h i n g with a n external p a c k a g e
ccCeccccccccCcccceccccccccceccccccccceeccccccceccccccccccccccccccccccccc C Global variables: f NCLUDE 10,ALL" INCLUDE MENU. ALL" INCLUDE * PAMM. EG' C Input variakles: MAL e (NXWX,NYWI G Local variables: INTEGER IX, XY INSPISGER MLINES
!f i e l d
values
!f a t t i c e i n d i c e s ! l i n e s w r i t t e n fn PMOUT
cccccceccccccccccccccccc~ccccccccccccccccceecccccccccc"ccccccc~cccccccccc CALL FLOPEIN (GNWME, EUHIT) NSTRMC (HINTS(reNAm1I =GNAW CALL PRNOUT ( G U N I T , NLSNES 1
fopn file !write o u t header
c 3.00
10
DO 1 0 0 X X - El X, WRITE (GUN3TI10) (P(IX,IY),IY=1,NU) CONTINUE F O M T (5[2X,ZPEl4.7) )
!write a u t f i e l d
C DO 200 IX=I,NX
200 2Cl
! w r i t e o u t bound c o n d WRITE (GUNIT, 20) (BNDCND @X, IY) ,TV=L, NY) CONTINUE F Q W T (IDflX,TZ)f ! c l o s e i t up CALL FLCLOS f GNAWE,GUNITf
C
=TURN END
cccccccc~ccccc~cccccccccccccccccccF:ccccccccccccecccccc~ccc~ccccccccccccc c~cccccccccccceeccccccccccccccccceeccccccccccccccceccccceccccccccceccece C param.eC, C INTEGER NXW,NYNZV(; TER (NXmX-7 9, N V m = 7 9) REIUL FMIN, FE?IAX
!maximum l a t t i c e s i z e !maximum v a l u e s of t h e f i e l d
368
B. Plrograms for the E~asrtples
.,
P W M E T E R (FMIN-O FE(IlLXm25 ,) INTEGER 3 C M !maximum nuniber o f bound cand P A M a T E R fB C W - 1 0 ) IWTEGER MCTGL, DIAGNL !shapes of bound cond P W m T E R (mCTGL=I,DIAGNLm2 ) IMTEMR DRCNLT,NON !type a f bound eond P-METER (DRCBLTm1, NON10 ) INTEGER mXLEV !maximum nu&er of c o n t o u r l e v e l s
G
LETGAL F I R S T
1 f i r s t time through menu?
INTEGER NX, Nll REAL UPPER,LQWER,LEFT,RIGNT RE= OMEGA INTEGER PTYPE CHWCTER*IZ PFILE RE% P I N I T LmZCAL S U B U T XNmGER NXLL, NYLL, m U R , NVUR
!lattice size ! f i e l d v a l u e s on l a t t i c e edge ! r e l a x a t i o n parameter !choice for i n i t i a l f i e l d ! f i l e t a input i n i t data ! i n i t i a l guess !relax sublattice f i r s t ? ?sublattice prameters
INTEGER NFREQ INTEGER NLEV
!frequency of d i s p l a y !nuWer of c o n t o u r l e v e l s
c e
INTEGER BCGEOM (BCWX 1 a W L BCVAL (BC=) INTEGER BWDCND ( M m X , M Y M X )
!numbe?r of bound eund (BCM l e o a r d i n a t e s f o r bound cond I g e o m e t q of bound cond !value o f bound cand ! f l a g t o indicate bound cond
L W I C A L XSKIP,YSRIP INTEGER XCNTR,YCNTR
! s k i p s p a c e s or l i n e s i n d i s p l a y !how t o c e n t e r display
INTEGER BBC XLL (BCWI
,YLL ~BCW) ,XUR ( B C ~ X ,)YW
G
c COWON / F m G
/ FZRST / NX, MY, UPPER, WmR, LEFT, RIGHT / O~GA,PINITISUB~T,NXLL,NYLL,NXUReN?IURtEZTYPE / NBC, XLL, VLL, XUR, VUR, BCEEOM, BCVAL, BNDGND / NLEV,WFREQ,XSKIPrVSKIPtXCNTReYCNTR COWOR / ASCIZ / PFILE
~~~c~c~cccccc~ce~ecececeeccccccccceccccccccc~cecccccccccccccccccC~c cecccccccccr=cecccccccccccccccccccccccecccccceccccccccccccccccccccccccccc C map.e(i INTEGER IUPPER,fLWR,fLEFT,IRIGHTtIOMEGAfIBC~UfXBEaDRU INTEGER f SUB, INXtE, INYLL, ENXUR, I W U R CXPT'VPE* IPFXLE, ZPIHXT INTEGER X N F ~ Q , I N ~ V , Z N T E ; ~ 13 ) P A M E T E R (IUPPER PAmmTER (ILOMER = 2 4 1 PAMmTER ( T U F T E 15 1 O A m E T E R (IRIGWT = 1 6 f P W W T E R (INTERR 17 1 TER (XBCMNU 1 25 1 P m M E T E R (XBNDRY = 31 1
-
-
(IONEGA TER (TSUB TER (INXLL TER (TNYLL = P a H T E R (SNXUR = TER (INVUR = TER {IPTYPE O A M W T E R f IPFILE p P-mTEW,
P m m T E R (TPINIT
-
38 ) 39 f $0 )
41 42
) )
43 1
48 1 49 ) 51 )
TER (INmV = 88 )
B.7 Example 7 Algorit hrn This program solves the time-dependent Schroedinger equai tion for a particle moving in a one dimensional box (i.e., the potential is infinite at the edges of the lattice: z = -1 and I = f l),allowing for various potential obstades in the bottom of the box. After the potential and initial wavepacket shape have been defined, the time evolution proceeds (loop 15 in subroutine IRCHOA). Here, the basic task is to find the new wave function at each time step by solving Eqs. (7.31,7.33) in subroutine EVOLVEusing the matrix inversion scheme (7.12-7.16). For this purpose the cx and y coefficients are computed once for each value of oT before the time evolution begins (subroutine TRDIILC). At each iteration the energy and normalization are computed in subroutines EEERCY and EoRmZ, respectively. Every BSTEP'~h iteration you have the option to continue iteratiom, change DT or NSTEP, or return to the main menu. One important physical parameter is the wavenumber ko which describes the osdl&ioas of the initial wavepacket. For an iGdial Gausgian
This number fixes the energy and the momentum of the particle. (The energy and momentum of a f r e e Gaussian packet are 3/(402) and h@,where ti = 2m = 1. For wide Gaussians p d e t s , the dominates the energy.) KO is not entered directly, but is fixed by entering the number of cycles on the lattice, where number of cycles on the lattice equals Cl;a xlmgth of latticef an. The m ~ m a m number of cyeles dowed on the lattice is Rpm/&,This restriction ensures that one cycle is described by at least 4 l&tice points, and therefore the ssdlating past of the wavepaclret cm be described on the lattice. From the discussion above, it is clew that the ;ylpropdate scale for both the energy of the particle and the height of the potential is given by kg. In addition, the size of the time step is conveniently scaled by kc2. To see this, note that the error term scales as For accurate time evolution we must have (taking H W k;) At < 1/k;, or in scded units At < 3 ,
lei +
Input The physical parameters indude the potential [square well] and the initial wavepacket shape [Gaussian]. Various analytical forms for the potential are possible (square-well, Gaussian barrier, potential step, or parabolic well), as defined in subroutine POTIITL. You must also specify the potential's center [.S], half-width at one-twentieth of the maximum 1.081, m d height (in units of ~ 0 + + 2 )[.3], as well as the I value [.S]that
divides left and right (used to estimate transmission coefficients). The two analytic choices for the initid wavepacket are a Gaussim or Lorentzian (subroutine I ~ P H I ) .The parameters that define the packets are the center [-.5],width [.25], and number of cycles on the lattice (10.1 ( = K o / ~ ) . The only numerical parameter entered in the main menu is the number of lattice points [200]. The maximum number of lattice points is fixed by HAXLAT= 1000. The other numericd parameters are the scaled time step [.2], and the number of time steps until you can end the iterations [M];these are entered after you leave the main menu. The one graphics parameter is EFREQ (also entered after the main menu). This determines the frequency at which "movie" frames are displayed (see Output below). Output At each time step the text output displays the unscded time; the energy (in units of KO*.~); left, right, and total probabilities; and left, right, and total (s). The graphics routine plots both 42(z)and V ( % )on and WIH. the same set of axis. The scale for V ( % goes ) between is the same for the entire run (subroutine GRFOIIT). The scale for This has the disadvantage that the scale could occasionally be too smdl to display the entire wave function, but a fixed scale makes apparent relative amplitudes of +2(z) at different times. If both text and grqbics we rcjqucrsted to the terminal, the plot of +2(z)agd V ( %will ) be displayed only every rsmp'th time step. If only graphics is requested to the screen, you will obtain output Lhat resembles movies: every W F R E P ' time ~ ~ step, 4 2 ( ~will ) be plotted, with four plots on one page to allow comparison of +2(s)at different times. The program ensures that lrsTEP is an integer multiple of 4rEFRBq (subroutine ARCHOB). Graphics output to a, file or a hardcopy device is done every w ~ m ~ ' t h iteration. For the hardcopy device anly one plot, not four, is printed pm cccccccccccccCccccCccccccccccccc~ccccceccccccceccccecccceccccccccccccccc G C C
PROCMM EXMPL7 E x w l e 7: The time-dependent S c h r o e d i n g e r E q u a t i o n C0NPUZ"ATIONAL PHYSICS (FORTmN a R S I O N ) by S t e v e n E. Koonin and Dawn C. Mereditb
C
C o p y r i g h t 1989, Addison-Wesley P u b l i s h i n g Company
cccccccCcccccccccccceccccccccccceccceccccccccccccccccccccccccccccccccccc 5
CALL I N I T CONTINUE CALL PAMM CALL, ARCHOH GOT0 5
!dispLay header s c r e e n , s e t u p parameters !main leap/ execute one@ for e a c h set of param !get i n p u t fram s e r a e n l c a l e u l a t e t i m e e v o l u t i o n a f a wavepacket
END
cccccccceccccccccccccccecccccccccccccccccccccccccccccccccccccccccccccccc
312
B. Prqgrams for .the EzampZes SUBROUTINE ARCHON t i m e e v o l u t i o n of a one-dintensional wavepacket C a c c o r d i n g t o t h e time-dependent Scbroedinger e q u a t i o n C calculates the
eccceecccccccccccccceccc~ceecccccccccccccecccececcc~eeeeccccccc~cccccccc C Global v a r i a b l e s :
C Local v a r i a b l e s : COWLEX PHX ( 0 :M f r A T 1 m& PHI2 { Q : M U T ) RE& TIrn RE& TPRQBIFS'RQB,IPPROS REAL LX, RX ,TX
m=
E
RE&
!wavepacket !wavepackat squared !time !normalization of t h e wavepacket ?average p o s i t i o n !energy !time s t e p !time index !s c a f e d t i m s t e p !min,max r e a s o n a b l e s i z e f o r DTSCAE !n&er of l i n e s p r i n t e d t o t e r d n a l !send t o tecminal !make a hardcopy !send t o a f i l e !nu&er of t i m e s t e p s t o t a k e !options f o r c o n t i n u i n g !which frame of t h e movie i s i t ? !graphing f r e w e n c y (movies only) ! t e v v a r i a b l e s for movies
DT XNTEGER XT DTSCAL R W DTNZM,DTMAX IMTEGER BLTMES INTEGER SCMEN IMTEGER PWER XNmGER F I U INTEGER NSTEP LOGICAL MORE,NE%BT XNmGER Pmm INmGEEP NmEQ M A L DIFF C Functions: !get f l o a t i n g p a i n t n u h r from s c r e e n =L GETFLT f g e t yes/na answer from s c r e e n INTEGER YESNO LOGICAL LOGCVT l change from 1 , 0 t o t r u e and f a l s e !gee I n t e g e r d a t a from s c r e e n INTEGER GETLNT DAIIA SCWEM,PAPER,FlLE/1r2t3/
I F (TFSLE) CALL PRMOUT (SUNIT, NLINES) I F (GPZLE) CALL PmOUT (GUNIT, NLINES)
e 31rrPHX (PBX, PBX2 ) TIm-0.
!satup i d k i a l B= ! i n i t i a l i z e time
NSTEP=40 WFmQ=lO DTSCAL- .2 DTmX=lQO. BTNIN=DX**2*KO**2/%
? d e f nun o f t i m e ? steps u n t i l next prornpt !def grapbing f r e q fmavies o n l y ) !def s c a l e d t i m s t e p tnax s c a l e d time s t e p !minimum s c a l e d t i m e s t e p
arzq
C
C
10
CONTINUE !loop over d i f f e r e n t DT a n d l o r WSTEP DTSCAL-GETPLT (DTSCAL, - r ) T W I DTMm, + , E n t e r time s t e p { u n i t s of KO**-21'1 IF (ABS (DTSCALJ LT, DTMZN f
.
!donft let it get too small ! p h y s i c a l time NSTEP=GETIWT(NSTEP,1,1O0OtfEnter numBar of t i m seepsr}
DTSCAL=SIGN(DTMIH,DTSCALf DT=DTSCAL/KO**2
NLINES=WLIMES+4 IF (NWIES) THEN mJFREQ=GETIMT(MFREQ,P,1000,*Enter graphing f r e q e n c y ? !make sure t h a t t o t a l nurn of frames is divisible by 4 DIFF=NOD(NSTEB" 4*NFmQj TF (BIFF .NE. Q) NSTEP=NSTEP+Q*NFMQ-DIFF END IF
.
(DT) l ca1~28if;e IF (TFTLE) CALL TITLES (TUNXT,NLIMES,DT)
far thia D2
!loop over sets of WSTEP time steps CONTINUE: XP (TTERN) eau, TITLES c o u ~ xWLIWESI ~, DTI
It* ervalutf an DO 20 ImZ,]LBSWP TTH3eMm+B91 -L mOLm (PBX,PET2,Dlt ) !tee a t S m @tap a& H Q m Z (BE2,WRQB, m O B , ZERQB, U, m, m) t cralc a o m !oala enerrw (PBX,BETP,E)
IF ((MOVXES) .AND. (NOD(IT,NFREQ) .Ea. O) 1 THEN FmE-MOD (ITtWREQ, 41 IF fF .EQ, 1) T m N CALL GRFQUT (SCREEMrPWI2,TIME,TPROBITXrEI ELSE C a L GWSEC (SCREEN,PN12,T I W ,TPROB,TXI F END XF END IF IF (TTERM) CALL TXTOUT [OUMIT,E,T T m , LPROI3,WROB,TPRQB,LX,RXrTX,HLIWES] IF (WILE) CALL TXTOUT (TUMIT,E,TIME,LPROB. RPROB,TPRQBCLX,RXe TX,HLINESl CONTXm
graphics autpue
IF (MOVIES) THEN CALL TMQDE ELSE ZP (GTEM) THEN
tawitch back to t e x t made
print aut graphics now i f t e x t was being sent t a screen ,' ,l) CALL PAUSE ( * t o see t h e wave packet CALL GRFOUT (SCREEN,PRTZ, TIME:,TPROB,TX,Et
..
END IF IF {GFSLE) CALL GRF6UT (FILE,PHI2,TIMEr TPROB,FX, P,) IF (GRRDCP) CALL GRFOUT (PAPER,PN12,TINE*TPROB,TX, 8) MORE-LOGCVT (YESNO (l., Continue iterating?' f 1 IF (MO=) THEN NLINES-Q
3"1
4. Programs f o r the Ezanzples I F (TTERM) CA&& C L E m GOTO 15 END I F C
MEEDT=LQGCVT(YESNO(TpfChanget i m e s t e p and c o n t i n u e ? ' ) ) I F (NESDT) THEW
NLLNESmO I F (TTERM) CALL C L m R GOTO f 0 END IF
c RETURN END
ccccccccccceccceccccececccecceccccccccccccccc~cccccccc~ccccceccccccccccc SUBROUTINE EVOLVE (PHI, PNI2, DT) C t a k e one t i m e s t e p using t h e i m p l i c i t a l g o r i t h m C (Eq. 7.30-7.33 and 7.11-7.161
ccccccccecCccccccCcccccccccccccccccccccccc~cccccecccccccececcccccccceccc C Global v a r i a b l e s : INCLUDE P A W . E?' C Inputloutput variables: @
COWLEX PHI (O:mXLAT) REAL PHI;? ( O : m U T ) RE= I3T C Local v a r i a b l e s : COWLEX COMST COMPLEX CHS COWLEX BETA 4 O :m L A T ) IMTEGER I X
!wavepacket ( I f 0 ) !wavepacket swared (I/O)
!time s t e p ( i n p u t ) !term i n ! p a r t of !term i n !Tattics
matrix inversion wave f u n c t i o n matrix inversion index
cccccccccc~ccccc~cccccccccecccccC:eccccccccccccccccccceccccccccccccccC:cee CQH8"rorr8*SWTM%*DX*DX/PI?C
mmfmlCS-J,) =O
.
f i e t i a l ean&t$ons far =FA DO 10 XXmWTS-2,0, -3 Ibaward recurslion for BEFA (lX+l)* (=E& (XX+lj-COEST*X?HX(IX+X) 1
50 C
COWX-
!bma&ny aonditions lfomard rao-ur~9enfez CHX and PBX CEX X ! C m a& thio l a t t i o s poinf aax (1x1 = C E Z - P ~(ZX) !FBI a t new LA!BHX2 at new t i m a ~ n s (zx) 2 =-B {PE (xx) } **2
CHT=(O., 0 . ) DO 20
20 C
TB-3. 1 C
cammm RETURN
ERD cc~ccce~~cccccc~~ccccccccccccccccecccccccccccccccccccccccccecc~cccccccc SUBROUTINE TRDIAG (DT) C c a l c u l a t e GAMm f o r t h e i n v e r s i o n of t h e t r i d i a g o n a l m a t r i x C (Eq* 7.30-7.33 and 7.11-7,161
Ccccccceccc~cccecccccececcccccccccccccccccccccccccccccc~ececcecccce[:cccc C Global v a r i a b l e s : XNCLUDE 'PAmM,E7'
C Xnput variables: M U DT C Local variables: INTEGER I X COWLEX WZERO,CQNSTl M A L CONST2
!time step !lattice index !terms in mtrix inversion !useful constant
cccccccccceccccccccccecccccceccccccccccccccccceccccccccccccccccccccccccc CWSTl--2.+2*SQRTm*DX**2/I)T CQHS2"2-+m]DX*DX*KCk*RO {=%S) =Q. DO 20 IXmWTS-1,0, -1 umMowsrz-c0~~~2 (1x1 *v 20
lSnikia2 ooa&it&ons for
comxm
C
RETURN END
ccccccceccccCcccccccccecccccceccccccecccccccccccccccccccccc~cccccccccccc SUBROUTINE NOWLZ (PHI2, LPROB,WROB, TPRQB,LX, RX, TXf C given PHIZ, finds left, right, and total probability of the wavepacker C as well as the average X value (left, right, and total}
ccccc~ceccccccccccccccccccccccccceccccceccec~eccccccceccccccc~cccccC:cccc c Global varfbfes: INCLUDE: "&RAM. E?' C Input variable: R= PHI2 ( 0 : M X M T ) C Output variables: RE& ZPROB, RPEOB,TBROB -L m,RX,TX G Local variables: INTEGER IX
!wavepacket squared !left,
right, and total prebabilfty ! l e f t , right, end total average position
t lattice index
cccccccccccc~ceccecccccc~cccccccccccccccccccccccccccccecc~cccc~ccceccccc 0
Lx=@*
.
f zezo a
PQ 10 XX=Z,ZMID-l
lin%egxata with -l;rapaxoiderlrule
m R Q m W R O B fPBX2 (IX) ===+X (IX)*PBX2 (IX)
3.0
cmxm
m W m m R O B + B S X 2 (XMZD)/ Z ~ = ~ + ~ D + P(XMTD) w x P12
I d w e pink i s shared bartween r leg% &U&&~ i g b %
C
2 (IMID)12 nr;?(rms)12
td d a e ~ P n k oonlx&ba%ion
tin&sqzatsl w i k h t.rapzo&dirl rule mRQB=WROE+EHI 2 (XX) ===+X (XX)*Pm2(XX) 20 G
GOSZXrn
EPmB=WROB+mEOB
.
R Q. ) R tmRoB .m * 0 . ) m=m/wRQB TX=a*WROB+U*WROB
Iteta2 pzabpbi2At:y t no Ikotal
a>5 s a neighteail a
m
376
B, Pmlgram~for the EgampZes C
RETURN END CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCGCCCC SUBROUTINE ENERC;U(PWI,PWI2,E) G c a l c u l a t e t b a s e a l e d energy E ( u n i t s of KQ**2) given PWI and PHI2
cecccccccccccccccccccccccccccccccccccI:ccccccccccceccccccccccccccc~cccccc C Global v a r i a b l e s : INCLUDE 'P A m , E ? ' C Input/Qutput v a r i a b l e s : COWLEX PWS (0: W U T l PE12 (0:MAXUT) mA3, E C Local v a r i a b l e s : INTEGER IX m= PE] CQWmX RE
t wavepacket ( i n p u t 1 !wavepacket squared ( I n p u t )
? t o t a l scaled e n e r w (output) ! l a t t i c e index !potential e n e r w ? k i n e t i c energy
~cccc~cccccc~ccc~~~ccccccececceccccccccccc~cccccecececccccccccc~ccc~ BE=Q
m*.
.
lid;tCialine lintblqra%ausing t;rapzaiW m l s
BO I Q ZX=l,NPTB-1
PEmPE+V (XI) 3rpE3 (TX) m=m+CQH3(;f (F= (XX) ) * (FIJI (m-3.)-2*P85 (ZX) +PBX (=+l)
X0
cornmm
rn-rn[DX**2/PtO+*2
Isrurzm ooala
1RQ**2
=TURN END
ccc~e~~~cccc~~cececcceecccccccccccccccccccccccccccccccc~ececcccccccccc SUBROUTIRE XXVTPNI(PWf,PXI2) PHI a r r a y from i n p u t parameters
C creates i n i t i a l
ccc~C~ccCc~~CcCcccc(=CcCGGeGCCcCCCCcCccccccccccC~c~cc~cCccccccCcCccCcc C Global v a r i a b l e s :
INCLUDE VPAW.E?' C Output v a r i a b l e s ; COWLEX PWX ( O : W L A T l PHI2 f 0:MaXLAT)
m=
C Local v a r i a b l e s : IMTEGER I X m& NOW,LPROB,RPRBB,SQItTM M& LX,RX, TX
!wavepacket !wavepacket s w a r s d I l a t t i c e index !normalization sf t h e navepacket !average p o s i t i o n
ccccccccccccccccccccccccccccccccccccceccccccccccccccccccccccccccccceccec f WrenitxiDO 10 XX=X,NBTS-3.
(smw*no*x
(m) ) / (sx-**z+
COHrzm
3.0 C
B-
.m,
XI?' (E&-T aUSS) T m W 20 n=%,wStS-l
!6iruoei-
(X(=)
-w0)**2)
20
CQHTXNUE IF
=D C
!potential io infiniLa at ends of Laktfca f ao PIXX 18 xaro there
P H I (0)=Q. fPES(=PIS) -0 , C:
m,
IamZ (PBX2 , =ROB, WRQB,%Wpa, m] SWW=SWT (Horn)
RQ
PO 30 IX=O,WTS 30
P a s (xx) =PHX (2x1 /SQRTB PHI2 4 PX) =PHI2 f X X ) /HOW COmXEW
C RETURN
END
ccccccccccccccecccceccccccccccccccccccccccececcecccccccccccccccccccccccc SUBROUTINE POTNTL C fills the potential array
ccceecccccccccccccccececcccccccccccccccccccccccccccecccccccccccccccccccc variables: IHGLUDE ' PAmM, ET" C Local variables: INTEGER TX C Global
f lattice index
cccccccccccccccccccceccccccccccccccccccccccccccccccccccccccccccccccE:cccc laiszax off X va2aea
S
N+IX*I)X C
IF
(pm .age sag-) D0 10 a = O , N P T S
Taa
ns t t x t r x ) .a.t x o - ~ t ) .m.
(x(zx)
v trxj -vo
.LIE. (xo+k))fP
ELSB
X0
v (XX)-0. E m IF CaBTfBUe
C C
20
i a fixed. so that V ( X O + & ) IF (POT .W.a V s S ) TmH PO XX=O,mTS
SS
IDV [xO-A)=w
tOauar~fan
V (IX)=VO*Ea (-AaVSS* (X (1x1 -X01 **Z/A**21 CQM"L"rn
C I)(3
30 XX=OINPTS
v {ZX)=W* 30 C C C
( X (rx) -xo) **2/~.**2)
CONTIHa
R S m Star Xixscl so that: V/XOS.A).rl.-BS*VO and V (XO-A) = m S V O ( m e PIIF) E m IE (POT .%Q. STEP) T a B tgmokb r t q fanetion oa do sx=o,llinzr~
~
I
378
B, Programs for Ike Ezamples
v (XX)=vo/2* (2/PX*&Trn (AS=*
coa%lm
40
rnD
[X (1x1-XO) /A) +X " 1
33'
G (01 40)
DO 90 XX=l,IWPTP xle (FT(1X) .Gin!. XF VfXX]
50
(=l
.&!l!.
C@mlW
TF C RETURN
END
c~cccccccccccceccccccccccceccccccccceccccccecccccc~eccccccccc~cc~ccc~ccc SUBROUTINE I N I T C i n i t i a l i z e s c o n s t a n t s , d i s p l a y s header screen, C i n i t i a l i z e s menu a r r a y s f o r i n p u t paranteters
~ccccccccccccCccccccececcccccccccccccccccccccccccccccccecccccc~cC:ccccc~c C Global v a r i a b l e s :
SNCLUDE "0. ALL' INCLUDE 'MENUSALL' INCLUDE V m M . E?; C Local p r a m e t e r s : CW=CTERk80 DE5CW DxmHsroH DESCW (201 INTEGER NHEAD,NTEXT,NGWN REAL EPS
!progran d e s c r i p t i o n
!n*er of l i n e s f o r each d e s c r i p t i o n !small nu&er t o set width o f p o t n t l s
CCCCCC6CCGGCCCCCf=@CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC~CCCCCCCCCCCCC
C
gee environment parameters CALL SETUP
c C
C G
d i s p l a y header s c r e e n DESGW ( 1 1 "EXWPLE 7' DESCWf2)m * S o l u t i o n of time-depndent Sehroedinger Equation" DESCRP(3)r - @ f o ra wavepacket i n a one-dimensional p o t e n t i a l i NHmDm3 t e x t output d e s c r i p t i o n DESCRP (4)= "time, energy, p r o b a b i l i t y , and €X>@
NTEXTml
c C
g r a p h i c s output d e s c r i p t i o n
DESGRP(5)- ' p o t e n t i a l and Iwavepackett**2 v s , N G W W-1
c CALL HERDER (DESCE, MWEAD, NTEXT p NGMPNI C
C
C
define constants PT=4,0*ATAN(I. 0) SQRTNI- (O,1)
I s w a r e r o o t of -1
X"
change prompts below i f you change VXMIN a n d / o r VX-X, for XD, %a, a n d GVGLEmKQ*(VXMAX-VXMXN] /2/PX VXHINm-1, ! p h y s i c a l l i m i t s on l a t t i c e VXPIAX=l.. l f i n d c o n s t a n t s s o t h a t a t X-XO+A
EPS=I. / 2 0 ,
! o r XmXO-A, V(X)-EPS*VO ASTEPmTAN { P I * ( l ,/ 2 . -EPSlj ! (doesn*t a p p l y t o p a r a b o l a ) AGAUSS=&~G(l,/EO%
s e t u p -nu CALL MENU
arrays, beginning with constant p a r t
NTWE (13)=TITLE M P W T ( 1 3 )='POTENTIAL FUNGTSON MEHU" MLOLIM (13)4 2 , MNXLIM (131 =l.
MTSE (11)=MTTTLE M P W T (2.4)+'l) Square-well: V=VO f o r XO-A < X < XO+A@ NLOLIM (141-0. NHILINfl4f -0,
M T E E (151 -MTITLE M P W T (3.5) = Gaussian: V (X) =VO* (EXP- (ACAUSS* 4 ( X - X 0 1 / A I **2}j ' +"2)
MLQLIM (15)=0. MWILIM (15) -0. MTVPE (3.6) -MTITLE 1?4PMPTf16]= +"J) P a r a b o l i c : V ( X f =VO* (X-XO) **2/A*"2" MWLfM (16)-0. MWXLEM (1C) -0.
MTVPE f l 7 1 =MTITLE W M P T (171
+' 44) Smooth s t e p : MLOLTM (17)PO.
V I X ) =V0*
(2/PI*ATN(ASTEE* (X-X01 [A) + I ) / 2 f
mXLIM(173=l. MTYPE ( I 8 1 =MGWOIG WR?ilPT(18)=@Makea menu c h o i c e and p r e s s r e t u r n ' NTAGf28)=f I 9 l 9 1 9 19' MLOLIM (18) =l. WHXLIMfl8)=4,
(la)=l
MR~L5(18)-I, NTVPE (191 =FLOAT M P W T ( l 9 f = ' E n t e r XO ( c e n t e r o f p o t e n t i a l MTAG ( 1 9 ) = ' @ e n t e r of p o t e n t i a l (X01 "
-1 < X 0 < 1
*
380
B. Programs for $he Egamples
MTYPE (201 =FLOAT W m T (20)-"nter A (half width sf one-twentieth max) MTAG (201 Half-width of potential (A) MLQLXM (20 t =so* (wmx-VXMTNI I ~ X ~ T MHXLIM(20) = (VXW-VXNIN}*ha, MRMLS (20)= (VXmX-=MINI /25,
@
MTYPE ( 2 1) -FLOAT MPRMPT(Zll=eEnter V0 (height of potential in units of RO**2)' NTAG (21)r f Height af potential VQ funits of KO**2) MzoLxn (21I =-loo, MHLLTM t21)=100. M T W E (22 ) =FLOAT m m P T (22)=
+
'Enter XMTB which separates right from left (-S C XMZD C 1)' value' MLOLXM (22) =mMLN MHILXM (22f =V" LS (22f =WMXN+J* (V
HTAG (22)-'middle X
NTYPE (23)=TITLE W R M P T (23J =' Wh-PACRES MLOLXM C23 1 92. NWTLIM (231-1.
ml(fU*
MTYPE (251 =MTITLE W M T (251= +* 22) Gaussian: PHI ( X f =EXP (I*KO*XJ*EXP t- (X-WO)**2I2/STGM**2Ie MLQLXM (251-0. MHTLIX (251 -1, NTUPE (26)=MCWOIC NPmT(ZC)='Nake a menu choice and press returne M T W (26) 2'7 2 7 @ NLOLIM (26)-h. MHTLIM (261 =2. MINTS (26) -2 MREALS (261-2. 1 '
MTYPE (27)=FLOAT
HPRMPT(27f = ' E n t e r WO ( c e n t e r o f p a c k e t -1 < WO < 1 ) ' MTAG ( 2 7 ) PVeentr of packet (WO} ' HLQLIM (27) =VXMTN MWILIM 2 '2 ) =VXMAX mEALS (27)=VXf?lfN+ (CrXlr9AX-VXMIN) /3
C MTmE (281 =FLOAT M P M P T (28)='Enter SXGMA ( w i d t h of packet) MTAG (28) mrNidth of packet (SZGM) ' MLQLIPI ( 2 8 ) = l 0 * (VXfiLAX-VXMIMI /MIXmT MHXLXM (2s =lo* ( V X ~ - V X M S N I M W L S (28)=. 125* (vXMAX-VXMINZ C
MTYPE f 29)=FLOAT MPWPT(29)ofEnter number sE c y c l e s on l a t t i c e MTBG t29) ='Number of c y c l e s = KO/PIr MLOLIM f 2 9)=-REAL (P4AXLAT) / 4, MHILIM(29)m REAZ(MAXLAT1 f 4 . r n E & L S ( 2 9 ) = 10.
KOIPI
'
C
MTYPE { 3 0 1 =SKIP mEWLS (30) =35. C
MT'YPE ( 3 8 1 =HUM MPWPT (38) = ' E n t e r nuarber o f l a t t i c e p o i n t s r
MTAG(38)- 'Humber o f l a t t i c e p a i n t s t MLOLIM(38)420. MNILIM (381 =mXLAT HINTS (38) =200 C MTVPE C391 =SKIP m m L s ( 3 9 )=so. C
NSTRMG (MfNTS ( 7 5 ) 1 =
@
eexmpl7, t x t '
C
NTVPE ( 7 C) -SKIP C
MSTRHG(MINTS(86))= %exmp17.grff C
MTVPE (871 =SKIP
MREALS ( 8 7 ) -90, 62
RETURN END
cc~~eccccccceccccccI:ccccceeeeccccccccccccccccccCccccCc~ccccccccccccccccc C
C €!
C C
SUBROUTXNE PARAM g e t s p a r a m e t e r s from screen e n d s program on r e q u e s t closes old f i l e s maps menu v a r i a b l e s t o program v a r i a b l e s opens new f i l e s
381:
B. P~.sgramsfor .the Exgmples C caleuZates all derivative parameters C performs checks on parmeters
cccccecccccCccccccceeecccccccccccecccccccccccccccecccccccccecccccccccecc C Global variables: INCLUDE =MU. ALL' @
INCLUDX.: *IIO,ALLf INCLUDE VPABAM.E7f
C Local variables: 611CmS !nu&er of cycles an lattice !maximm nuder o f cycles for given HPTS mAL m C U e map between menu items and paramters INTEGER ZPOT, IXO,lA, IVO, TXMID, EPACK,XSfGMAI IWQIICYCLEt XNPTS
=L C
PAWNETER (IPOT TER ( I X Q
P-METER
(IA P A W E T E R (XVO
181 = 19) = 20) = 21)
--
P m M E T E R (IXNTD TER (XPACK TER (IMO = ( I S I G M .= P A M m T E R (TCVCLE P-METER (INPTS =
-
221 26)
27) 28)
29) 38)
C Functions: LOGICAL L m C V T m A L GETFLT
!converts 1 and O to true and false !get floating point nu&er from screen
ececccccccecccccc~ccccC:cccccccecccccccccccccccccc~ecccccc~c~cccccccc~c~cc C
get i n p u t from terminal CALL CLEAR CALL ASK f l, ISTOP 1
C
C
stop program if requested f F (=&L$ (ImIN) .Ea. STOP) (=ALLFJNXSH
C G
close files if necessary I F (TB= .NE. M S a N G (MINTS (ITNAME) )) t CALL FLCLOS [TNhME,TUNIT1 IF ( G R M NE. MSTRNG (MINTS ( IGgME) I I C A U FLGLOS (GNAME,GUNIT 1 t
.
C C
C
set new parameter values physical and numerical POT-MINTS ( I P O T ) xa=cMREaLs (rxoI VG-MREALS ( I V Q ) XMTD-mALS ( IXMf D 1 PACKETmWINTS (ZPACK) SIGmmMREALS ( I S Z G M )
wommats irwo) GYCLES=NREALS(ZCYCLE) NPTS=WIMTS ( I N P T S )
c
t e x t output TTERNmLOGCVT (MXNTS (ITTERM) )
TFIM=L~GC~T~MIMT~(~TFI:LEII TNME-MSTRNG(NINTS(ITTJAtriEl} C C
graphics output GTERM=LGGCVT(MINTS(TGTERMll GHRD~P-L~G~VT(MXNT~(IGHRDI) c F x m = L o c c v T (MINTS 4 IGFILE) 1 GN~E=MSTRNG(MINTSlXGNAKE~ 1
c C
openfiles I F fTFILEf CALL FWPEN (TNAME, TUNIT) XP ( E F P M ) CALL FWPEN (GNAME, EUNI T) ! f i l e s may have been renamed MSTRNG (MINTS (ITN=) 1 =THAW MSTRHG (MINTS ( I G H A m l l =GFJAME
c C
d e r i v a t i v e parameters MOVIES=.FALSE, SF ((GTERM) .&RD. (.NOT, DX= (~XMAX-WMIW 1 /NPTS
TTERMII MOVTES=,TRUE. !s p a t i a l s t e p
IMXD-HINT~(XM~D-~XMIN~/DXI XNID=mIN+INXBxDX LS (IXMID) =XMID C C
! n e a r e s t l a t t i c e index t o XNXD ! f o r c e XMID t o be a l a t t i c e p o i n t lehange d e f a u l t a c c o r d i n g l y
c h e ~ kCYCLES w i t h r e s p e c t t o l a t t i c e s i z e MRXCYC=WAL(NPTS f /4. I m x nuntber of c y c l e s f o r NETS IF (CYCLES .GT. mxeue) Twaw m Z T E (OUNIT,*) @Wumlt>erof c y c l e s i s t o o l a r g e f o r NIPTSf -I.
CYCLES=GETFLT(~CVC/1O0,-MAXCYC,MXCVC, "nnte ru&er of c y c l e s KO/PItI
MmALS(ICVCLE)=CVCLES END I F ROmCYCLES* 2*PI/ (VM&X-VXMIN} CALL CWAR
c CALL POTNTL XF ((GTERM) .OR.
!s e t u p p o t e n t i a l a r r a y IGHRDCPI) CALL GRFINT ! i n i t i a l i z e q r a p b i n g param
c MTURN END
cccccccccccccccccceeccccccccccccceccceccccccccccccceccc~cccecccccccccccc SWROUTINE PRMOUT (MUNIT, NLTNES) C o u t p u t s parameter s u m a r y t o MUNIT
c~ccceccccccccccc~e~cccccccc~eccccccccccccccccccccccccc"ccccccccccccccccc C Global v a r i a b l e s : INCLUDE TO, ALL" SNCLUDE C PAMM E7 ' C Passed v a r i a b l e s : fNTEGER NUHIT INTEGER NLTMES
.
! u n i t nu&er for o u t p u t ( i n p u t ) ! m u d e r of l i n e s w r i t t e n s a Ear ( o u t p u t )
384
B. Pragrams for the EsckmpEes cccccee~ccccccecceccccceeccccceccececcccccccccccccccccccccceC:cccceecccee IF (MUNIT .E@, QUNITl GALL CLEm C
m T T E (MUNIT,2) m I T E (MUNLT,4) WRITE (MUNST,24) X&TIZ,NPTS, DX kJRTTE (NUNIT,2) SF (POT ,EQ. S B U m ) THEN HRITE (MOMXT,G) ELSE IF (POT .Ea. GAUSS) THEN WRITE (MUNIT,8) ELSE IF (POT .EQ, P A W ) THEN WaZTE (WNfT,lOf ELse aF (par .EQ, STEP) THEN m S T E (NUNIT,12) END TP @RITE (MUNIT,14) XOIAIVO WRITE (MUHIT,2) IF (PACKET .ea. LQRHTZI THEN lriIRITE (MUNIT,16) ELSE IF (PACKET .EQ, C;AUSS) T W N MlRITE (MUNIT,182 END IF mETE (MUNIT,201 WO,S I G m m I T E (HUMXT,22) KO,KO**2 WRITE fMUNX1,2)
e EIEINES-11
e 2
FOWZt
4
FomT
('
C
1
(I Output from example 7: Time-dependents Schroedinger Equationr> F Q W T t t Square-barrierlwell: V=VO f o r XO-A < X XO+Afj FOWT + Gaussian barrrierlwell : V (X) =VOX ( B P -(AGAUSS*I (X-XQ} /AI **21 I 1 F O W T (' Parabolic we1L: V ( X ) =VO* (X-X0)**2/&**zr 1 F O m T ( q m a o k h step: V (X) =+(I*(Z/PI*ATN (ASTEP*( X - X 0 1 /A} +l)/2* 1 FQWT('XXO=\1PE12.5,5X,'kAf,lPE12,5,5X, C V0 (units KOX*2) = f,1PE12.5) FORMAT (' Larentzian wavepacket: * , + * PHI (X) =EXP (x*K~*x] / (SIC;M**~+(X-WO)**a 1 FORmT ( * Gaussian wavepacket: I , + 'PHI (X) =EXP (I*KO*X)*Emf- [X-MO) **2/2/SIGm**2)' ) FORWT OW"( = ' ,lPE12.5,5X, SIGMA = ",IPE12.5) FORPllAT (' KO * ,lPEIZ,5,5X,F KO**2 (energy scale) = f ,fPE12 .S) FQ~T('XXNPDDUe9r1PE12rStSX,@NPTSPf,15r5Xe C space step = ',1PE12.5) FORMT (18~,%ener~\r9~,~p~:ababi2.ity~,19X,'~x>~l FORE'lZlT (?X,'time*,?X, C KO**2 ' ,5 X 9 F left.@, 3X, ' rightp,3 X C I total8,l i X I + "eftf *4X, "rightf, 4X, "total") PO-T (?X, L=--\ ? X , "-----I, 5x, ----I, 3 x , ,sx, , GXt + r ,q~, l& F, ---& f C
6
8
f0 12 14 16 18
20 22 24 26 28 30
-
f
----@,
----W'
----W-'
c =TURN END
~ccc~~~~cce~~~e~ccc~~~e~~~~c~e~c~cc~~e~cc~ec~e~c SUBROUTINE TITLEs(MuNIT,WLTNES,DT) C w r i t e o u t t i m step a n d column t i t l e s t o MUNXT
ccc~cc~cc~cccc~~ce~~ce~ce~cccccccccccccccecccccccccccccecccccccecccceccc C Global variables: INCLUDE "0. ALL" C Passed variables: INTEGER MUNIT INTEGER NLIMES , RML DZ"
!unit n u d e r f o r output (input) ! n u b e r o f l i n e s w r i t t e n s a Ear (output) ? t i m e step ( i n p u t )
c~ccc~~~~~~c~~cec~~~cccccccccccceccecccccecccc~ccceccccc~cccc1ccccc WII;ITE WRXTE WITE MR5Z"E mSTE
' (MUNIT,*) (WUNTT,20f BT (MUNIT, 26) (MUMIT, 28) (MUNIT, 30)
c IP (NUNIT .EQ. OUNITf NLINES=NLINES+5
c 20 26 28 30
t i m e s t e p = \ IPEl5.8f (18XI*energy',,3X,fp~obabf3.Zt:yf,19X,*~~~'~ FORmT (?X, ' t i m e " ?X, 'K0**2 rSX, " e f t * F ,JX, r i g h t ' , 3X, @ t o t a l * 6X, , g l e f t r ,4X, * r i g h t t , 4X, ? e o t a , l t 1 PO-T (TX,# ?X, - - - - - - I , fix, ---I@, 3X, -----P, 3x, * # r, , ...r 4 ~ "--.,.--C , 4 ~ 6, t PORmT
fp
FOWT
+
----S-@
+ e
rnTURN END CCCCCCCCCCCCCCCCGGCCCCCGCCCCCCCCCCCt:CCCCCeCCCC:CCCCCCCCCCC"CCCCCCCCCCCCC~C SUBROUTINE TXTOUT ( M U N I T, E, T I W , LPROBIRPR6Bt TPROB, LX,, TX, MLXNES} C w r i t e s r e s u l t s f a r o n e s t a t e t o MUNIT
ccccccccccccc~cc~cc~ccC:ccecccc~ccccccececcccccccecccccccececcceccccccccc C Global variables: INCLUDE "IO.ALL1 C Input variables: INTEGER NUNTT REAL TXNE Z"PROB,LPRQB,RPROB REAL LX,RX,TX REAL E INmGER NLTNES
!o u t p u t unit s p e c l EIer !t;im ! n o r m a l i z & t i o n of t h e w a v e p a c k e t !average p o s i t i o n
!energy ! n u n b e r of l i n e s p r i n t e d s o far II/O)
CeecccccccccccccCceccccccccceccccccccccccccccccccccccccccccccccccccccccc C
i f s c r e e n i s f u l l , clear s c r e e n and refype h e a d i n g s ( (MOD(MLTNES, TRHLIN-4) .EQ, 0) + .AND. (MUNIT .EQ. OUNIT) ) THEN to tc o n t i n u e . \ ,l1 CALL PAUSE:4 @ GALL CLEAR @RITE (MUNTT, 26) m I T E (MVNI&,28)
IF
..
386
B. Programs for the Bgamples m I T E (MUMIT,SO) MLINES=NLfNES+3 END IF G
m I T E (MUNXT,40) TIME, E, LPROB,WROB, TPRQB, = , W , TX kaap track o f printed lines only Tor terminal output IF (MUMIT .EQ. OUNIT) NLINES-NLINES+1
C
G 26
28 30
40
+
F O m T (ISX,reana~"lSX,@pr~babilityfC19X17~<~~~) F O R m T f 2 X , t i m e 7X, KRO**2 ',S X , * leftc,3X, ' rightp,3X, tc)taItI 6X,
tllaftf~ 4 X , r r i g h t ~ r 4 X t @ t1~ t ~ 1 f F Q R m T (?X, ' ? X , ------t, 5)E, 8 - - - - I I 3 X t f -----F .c l ,4X,f-----t,4X,t-----f 1 F O M T (4X,1PE10.3,4X,0PF6,3,4XIF5.3,2~3X,]F5.3~, + 4X,F6.3,2 {3X,F6.3) ) ----m\
,3X,
1
m,
c WIfURH END
cCccccccccc~eccccccccccccceceeeccccccceecee~cccccccccecceccccecccccecccc SUBROUTINE G W I N T C initialize a12 graphing variables which are the same far ane sun
ccccccceccccccecccecccceC:ceccccccccccccecccccceccc~ccecccccccccccccccccc C Global variables INCLUDE @PAmIVI.E7" INCLUDE GRFDAT .ALLe
ccccccecceeccecececcccccccccc~eeecccccC:ccccccccececceccccccccccccccccccc !find limits on data pafnts
Y W - V W W 1N=WfN X OVUmVNXN
XMIN=WWTN XW=rnrn
UI)VAL=VXE"IJN
e WPOINT=NPTS+l G
xsm=~
!sy&ols
and ticks
IFmB=O NXTICK-5 MYTICKm5 ILINE=I.
c ME1EL (I) =' scaled X* MBEL (2)="otential,
?titles and labels PMI2*
e =TURN END
~~ecee~~~cecc~cccccccc~c~eecc~ec~cccccccccccececcecccc~cccce~~~ SUBROUTINE GRFOUT (DEVICE,PHJ2,T 1 m ITPRQB, IIX, E) G outputs wavepaeket and potential to DEVfCE
c~~e~c~e~~~c~e~c~~ecccc~~cccc~c~~~c~cccccccccce~ccceccccc C
Global variables INCLUDE pIO.ALL"
.
INCLUDE C PAMM E7 ' INCLUDE * CWDAT ALLt e Input v a r i a b l e s : !which d e v i c e i s b e i n g used? INTEGER DEVICE ~ A PHI^ L ( O : ~ X ~ T I !wavepacket s q a r e d TINE !time ! n o m a f i z a t i o n of t h e wavepacket W f i TPROB REAL TX !average p o s i t i o n REAL E !e n e r w G Local v a r i a b l e s ! s c a l e d wavepacket s w a r e d REAL PNTGRF(O:mXUT) ! s c a l i n g f a c t o r f o r PHI2 RE& VSCALE INTEGER XX ! l a t t i c e index CH-CTER " 9 CE, CSIG !Energy, SIGM a s c h a r a c t e r d a t a CMmCTER*9 CPROB,CTX,CTINE ! d a t a a s c h a r a c t e r s INTEGER PLEN,TXLEN,TLEN,ELEM,SUN ! l e n g t h sf s t r i n g s !true l e n g t h o f c h a r a c t e r d a t a ZMTeGER LENTRO SMTEGER SCREEN !send t o t e r m i n a l !mka a hardcopy INTEGER PAPER !send t o a file INTEGER FILE DATA SGREEM,PAPER,PILE/1,2,3/
.
cCccCccc~ceeecccc~cccccccccC:cc~ccccecceccceecceeecccccccccceeceeccccccce G
m e s s a g e s f o r the i m p a t i e n t I F (DEVICE .NE. SCREEN) WRITE (QUNST, 100)
C
c a l c u l a t e parameters far graphing I F (DEVICE .NE. FILE) TWEN
c2
C
I F (.NOT. MOVIES) TWEN NPLOT=1 ELSE NPLOT=4 END fE IP~T=X
lhow m n y p l o t s ? !f o r m o v i e s , t h e r e are ! 4 p l o t s p e r page
+
CALL GOWRT (TPROB, CPROB, P L W l create l e g e n d CALL CONVRT (TX, CTX ,TXLEM 1 CALL CONVRT fTINE,CTINE,TLEEJj IWFO-' t=V/CTTME (1;TLENI I"/ p norm-' l / GPROB(l rPLEN) //V<X>='//@TX(l:TXLEN)
4-
CALL CQNVRT(E, c ~ELEM) , ! d e s c r i p t i o n o f data GALL COMVRT (SICMA, CSIG, SLEM) XP (PACKET .EQ, LORNTZf TEEN TTTZE='Lorentzian p a c k e t , ' ELSE I F (PACKET .EQ. GAUSS) THEN TITLE=fGau%sfan p a c k e t , " END I F TITLE=TZTLE (l:LENTRU (TZTLE] b / / I w i d t h = ' //CSIG f l :SLEN) / / I , E = I //CB (I:ELEN)
C
e GALL GTBIEV (DEVICE)
!device nomf n a t i o n
IF (DEVICE .EQ, GALL LNLNAX
S a E E M ) CALL GMODE
!change to graphics mode !draw axes
END IF
c C C C
The largest PHI24XX) can ever become is 1 (all probability at one lattice point). The following scale assumes that the maximum value is 1OINPTS (grob equally shared by ane-tenth a f tbe points] VSCALE=(VIVYIX-VMXN~*NPTS/lO. fseafe PM12 sa that it fits on Vscale DO 10 TX=O,NPTS PHIGRF (SXI = w r ~ + ~ ~~SsX*z )v s c a L E IF (PHIGW (XX) GT. V=) PHZGRF ( I X ) - V W I clip high values
10
CONTINUE
.
e C
output results XP (DEVICE .EQ, F I L E ) THEN
@RITE (EONXT,GO) TINE m S T E (GUNZT,70) f X (XX) ,V ( 1 x 1 ,PHI2 ( I X ) ,IX=l,HPTS) ELSE CALL XUPLOT (X,V) CALL XYPLOT (X, PWIGRF) END I F
e C
end graphincg session XE" ('NQT. MOVIES) THEW IF (DEVICE .HE, FILE) CALL GPAGE(DE;VIGE) S F (DEVICE .EQ, SCMEN) CALL TMODE END XF
tend graphics paekat~e !switch to text node
C
SO 70 100 C
F O W T f ' X,V, PMS2 at time = * 6,1PE/5-8) F O m T (3 (5X,E15.8)1 F Q M T (/, Vatience, please; output going to a file,' 1 =TURN END
~cccc~~ccc~cCcccecceceecccccccccccccceccccccceccccccccccccccecccccccccce SUBROUTIM GRFSEC (DEVICE, PHI2,T I m , T X , C outputs wavegaeket and potential for msvlas, frames 2-4
e~~c~~~~~c~~~c~ccccc~eccccceccc~c~ccecc~c~ceccccc~cccc~ C Global variables INCLUDE @ITQ,AZLt ZNCLUDE 'P m M , E 7 ' INCLUDE ' GWDAT &LF
.
C Input variables: XNTEEER DEVICE REAL PHI2 (0:MAXLAT) WAT T X a M f i TPROB M U TX
INllEGER F M =
e Local variables REAL PWIGRF (O:kIAXMT) REAL VSCALE
?which device Ss being used7 fuavepaeket squared !time !narnalization of tka wavepacket !average position Iwbieh frame of the movie is it? ? sealed wavepacket squared
tscalinq f a c t o r for PHI2
INTEGER IX !lattice index CTERI9 CPRQB,CTX,CTIME I d a t a as c h a r a c t e r s XNTEGER PLEM,TXMN,TLEN ! l e n g t h of s t r i n g s INTEGER SCREEN fsend t o t e m i n a l INTEC;ER PAPER !make a h a r d c o p y !send t o a f i l e INTEGER FILE DATA SCREEW,PAPER,FILE/1,2,3/
ce~cecc~ccc~eccccc~cccccccce:ceccccecccccccccccccr:ceccccccccccccccccccccc XPLOT=FmME I F [IPLOT .EQ. 0) IPLaT14
!associate p l o t s w i t h frames
C CALL CQNmT (TPROB, CPROB, PLEklj Iereate l e g e n d CA& COPIIVRT (TX, CTX, TXLEN) CAm GONVRT (TINE, CTINE, TLEN) n o r m */ l / INFO=* t=*//CTIME ~I:TLE:N]/ / I + CPRQB(1:PLEN)/If <X>='//CTX(I:TXLEN) CALL LNLNAX !draw a x e s
e VSCUE=(VPILaX-WIN)*NPTS/lO. Do 10 IX=O,NPTS
IQ
!scale PHI2 sa t h a t it f i t s on Vseale
PHXGW(1x1 =VMIN+PWI~ 1x1 *VSGALE I F (PHIGRF ( I X ) .GT. V M X f PWIGRF ( I X ) = V m X CONTINUE
G CALL XVPLOT (X,V) CALL XYPLOT (X, PHIGW)
fplot data
C
XP (XPLOT .Eg. 4 ) CALL GPAGE(DEVXGE1
!clear t h i s g r a p h i c s page
C
RETURW END
cccccccccccccccCcccececcccecccceccccccccccccccccccccccccc~cccccccccccccc ccceceeccccCccccee~ccccceccccccccceec~cceecccccccecccccccccccccccc~cccc~ C param.ot7
c RE&
PI MAL VXMXN,mmX COPIIPLEX SQRTIJ11 REAL ASTEP,AGAUSS IWTEGER POT =&L X0
RE=
A =U V0
INPEGER PACKET REAL S I G m m A L WO
R E U KO M& XMXD INTEGER IMID DX SNTEGER NPTS RE& =X,VMIM
!pi=3.15159..,., !physical l i m i t s on lattice ! s q u a r e r o o t o f -2 !factors i n the potentials ?which p o t e n t i a l !center of potential !width o f p o t e n t i a l !height o f p o t e n t i a l !which w a v e p a c k e t fpackat width !packet i n i t i a l p o s i t i o n ! p a c k e t wavenumber ! d i v i s i o n b e t w e e n l e f t a n d right !index o f d i v i s i o n !s p a t i a1 s t e p !number of l a t t i c e p o i n t s ! l i m i t s o n value of p o t e n t i a l
390
B, Pr~gramsfor the Egamples LOGICAL MOVIES
!when only graphics to screen is requested
e IWTEGER W L A T !maximum number of fattie@ points PAMmTER (mXLAT=100Q J M& X ( O : m X m T ) !array of X values
mfi
V(O:MAXLAT) tarray of potential values COWLEX GaM(O:MAXLAT) !terms in matrix inversion
C
INTEGER SQUmE,C;AUSS,PAMB,STEP Ityphs o f potentials INTEGER LORNTZ !types of packets PW1VIETER fSQPIARE=I,GAUSS=2,PARBB=3,S~P=4,LORNTZ=fl C
COMMON 6OMOH COWON COMOhl
/ COMST / PI,VXMIN,VXM,SQRTNIIASTEP,AWUSS / P P W M / POT,XO,A,VO,PACKET,STGEIA,WOIMXD / N P W N / WPTS
I PCALC / DX,X,V,(;IL~,IMXD,WX~VMIN~MOVIES,KO
B.8 Example 8 Algorithm This program simulates the two-dimension& Ising model using the algorithm of Metropolis et al. Before calculations begin, the acceptance ratio r is calculated for the 10 different cases (subroutine PARAR), and the initial configuration is chosen at random (DO loop 5 in subroutine nrrclroa). After the thermalization sweeps are performed (loop 10), data taking for the groups begins (loop 20). The two basic subroutines are PIETROP, which performs a Metropolis sweep of the lattice, and sm, which calculates the energy and magnetization for the configuration of th During the data taking, both group and the lattice every 1 1 ~ ~ w 'sweep. total sums for the energy and magnetization are accumulated (subroutine AWRAC) so that effects of sweep-to-sweep correlations can be monitored, as discussed immediately above Exercise 8.6. After the requested number of groups have been calculated, you are prompted for the number of additional groups to be done [IO.]. Input The physical parameters are the magnetic field [O.] and interaction strength [.$], both in units of kT. The numerical parameters are the number of lattice points in 1 [20] and y [20], the random number seed [54767], the number of thermalization sweeps [20], the sampling frequency [5], the group size [10], and the number of groups [10]. The maximum n m b e r of s points is fixed by HllXX= 79; and y psints, by MAXY= 20. These ts a-re to ensure that the charxter display of the con6guration will fit on thc; typical scrmn whi& is 24 lines long and 80 chrxsacters ryide. If yaw t e r d n d is not 24 X W, or if ;you won't be displaying the csn6mra;tion, you c m adjrrst these parmeterss The text output paxrameter &ows you to chose the shod version sf the output for which the smple sums are not displayed. Please see the note in C.7 concerning the random number seed and compiler storage of iaegers.
Output Every ~m~g'tlr sweep, the text output displays the g o u p index, sample index, p o u p size, abcceptasce ratio, energy, and magnetization. (All thermodynamic quantities are per spin.) If the short output is requested, this output is not printed. Every EFREQ*#SXZE'~~ sweep (when a group is completed), the text output displays the group index, the group averages for energy, magmtization, ausceptiWity, and speei3ic heat, as W& aa the u~cert;aintyin enerm and magnetization. Also, at this time the grand averages (including all groups cdcdated so far) are displayed with two uacertajlnties for energy and magnetization, m discussed in the text e
E ycru requegt g a p f i m to tohe screen or file, eveq IF RE^'^^ gweep the congguration is displayed or pinted u ~ i n gcharacters: spin up i s indicated by m X, and spin down is indic&ed by ib bIaak. No more sopkistica2;ed g q h i c s autput i s available since i%caufd tell you no more than this. ccccc~ccCccccccccccccecccccccccccccccccccccccccccccccccc~ccccceccceccccc BRQC;MN EXWL8 Example 8; Monte Carlo simulation o f the two-dimensional Ssing lulodel COWUTATIOMAL PHYSICS (FORTmN mRSION) C by Steven E. Koonin and Dawn C, Meredith C Copyright 1989, Addison-Wesley Publishing Conrpany
C C
cccCcccecccccccCcecccccccccccccccccceeccececcccceecccecccccccecccccccccc 5
CALL IWIP CONTINUE CALL P a M CALL ARCWON GOTO 5
!display header screen, setup parameters !main loop/ execute once for each sat of garam !get input from screen !calculate t b e thermodynamic -antities
END CCCCCGCCCCCCCCCCCCCCGCCCCCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCGCCCCC
SUBROUTINE ARCHOW C calculates the thermodynamic quantities: enerrgy, magnetization C susceptibility, and specific heat at constant field and interaction C strength
cc~cccccc~ceccccceccccccccccccccceccccccececccccccccccecccccccccccccccCc C Global variables: INCLUDE 'PARIIM, E8' INCLUDE 'IXO.A&L* C Local variables: !spin configuration INTEGER S P I N ( W X , M Y ) C all of the thermdynamic quant have 2 indices C (not all array elements are used, e.g. CWI fsweep,value)1 C first indax is the level: sweep, group, or total G second index is the value: quantity, quant**2@ or sigma**2 mG(3,3) !magnetization !energy ENERGY f 3,31 I specific heat RE& CB(3,3) M A L CHI (3,31 !susceptibility TNTEGER f T H E W !thermalfzation index INTEGER fTER !iteration index REAL ACCBT !acceptance ratio INTEGER IX, SY !hoxiz and vert indiees D of lines printad to terminal IWTEGER NLIMES II?JmGERMORE, Imp !how many more groups, group index INTEGER ISmEP !sweep index XNTEGER SmEP,CRQUP,TOTAL !which level of calculation ' INTEGER VALUE,SQUARE,STGSQ ?which wantity C Functions: REAL GETFLT !get floating point nu-r from screen INTEGER YESNO !get yeslno answer from screen Ichanc~csfrom 2 . 0 to true and false LOGICAL LOGCVT !get integer data from screen 1NmEER GETINT
!generates a randam number W& =%NOS DATA S W E P , C R O U P , T ~ T A L / ~ , ~ ~ ~ / DATA VAGUE, S Q V m t SIGSQf 1 t 2,3f
~c~~~~~~c~~~~~c~~~cc~ecc~ccce~ecc~:cc~~~~cc~ccc~ C
o u t w t sumary of parameters TF ( T T E M ) CALL PMOUT (QUWXT, NLINESf XP (TFLLE) GALL PRNOUT (TUNXT, NLINES SF (GFILE) CALL PRMOUT (CUNTT, NLIMES)
e
lr&om
DO fi XX=Z,m
initial, tspb caofAf;lura%ian
m3 6 xx=z,NV
IF
(D-D) XI?) =l
.G!E.
.S) T a w
$
E m SPTM (XX, m)=-a
3.
l.0
comxm
IF (TTEM) CALL PAUSE ( 't a k q l n s u m i n g
...' ,l)
C
CALL ZERO(TQTAL,~G,ENERG?IIGHZtCB] !zero total averages MOM=NGROUP C
15
CONTINUZ DO 20 XGmmNGRBUP-MOW+l,NGRoUP
CALL ZERQ(GROUP,MG,ENERCV,CMI,CBJ
!allow for mare groups !loop over groups !zero graup averages
c
+
XP ( ( T T E W ) .ANB. (.NOT. GTERM) .AND. (,NOT. TERSE)) CALL TITWS(OUNZT,NLTNES) I F ( ( T F I L E ) -ANB. ( "NOT. TERSE)1 CALL T I T a S (TUNZT, NLINES)
G
DO
!-a
r #wezap of the lakLXca
C
CX,W.J Z m o (=ET?, WU2, S W (SE)Strl,- , E a r n )
Iinclu&e i n avrragea !which s w e q i s it ,CRX, m) rzera meep d o t a e ? eweerp total,rdld t o grow
IF (GTEWl THEM
!display data
G G U L BTSPLY (OUNIT,SPIN, MAG,
ENERGY,ACCPT,XGW,ISIEEPf ELSE SF 1 ( T T E m ) CaL
.AND,
( .NOT,
TERSE) ) THEN
394
B, Prognrnas for the Eza~npilet~
+
SWOOUT [OUNXT, b%G, ENERGY, ACCPT, IGRP, ISWEEP, NLXNES) END I F I F ((TFILE) .AND. (.NOT. TERSE)) CALL SWPOUT (TUNIT, =G, ENERGY, ACCPT*IGRPt I S m E P , N L S I I F ( ( G F I W ) .OR, (GHRDCP)) CALL DTSPLY (GUNIT, SPIN, WG, ENERGYI ACCPI", IGRP, ISWE:EP)
+
+ F:
END I F
30
20 e
CONTINUE NORE=C;ETINT (10,0,1000, 'How many more g r o u p s ? ' ) SF (PliORE .GT. 0) THEN NGRQUP=NGROUP+MORE NLXNESmO SF ( (TTERMj .AND, ( ,NOT, TERSE) ) CALL CLEm GQTQ
15
END I F
c RETURN END
cccccccccccccccccccccccccceccccceccccccccI:cccecccecccccccccccccccccccccc SUBROUT1WE METROP (SPIN, ACCPT) C make one sweep of t k e l a t t i c e u s i n g t h e M e t r o p o l i s a l g o r i t h m
C to g e n e r a t e a new c o n f i g u r a t i o n
ccF:cCcccccccccCccccccccccccccccccccccccccccccceccccceccccccccecccecccccc C Global variables: INCLUDE ' P M M . E 8 ' C fnput/Output variables: INTEGER SPIN ( m X X , mXY) REAL ACCPT C Local v a r i a b l e s : XNmGER XX, SV INTEGER IXMX,IXP1,XYM1,IYP1 INWEER NNSUM C Function: M& MNNOS
!spin c o n f i p r a t l a n fIlO) !aeccgtance r a t i o (ouCput) ! h o r i z and v e r t i n d i e e s !indices of nearest neigbbors !sum o f n e a r e a t ne2ghbors ! g e n e r a t e s a random R U ~ T
cccc~ccc~cce~~c~ccccceccc~cceecccccceccc~ccccccccccc~ceeccccccccccccccc 8~a~G 1QwemQII t r8t%b
X-%=@.
BC1 10 ZZ=1,= X=1==+1 zx .SQ.
lax) m%=%
C
DO 20 rx=z,m f m1=n+1
m? {m 'EQ' f rn=SY-l
m1 znz=x
38 (3V .&Q. 1) f m = W
Im@rrrrt: .C.
WSM=SPXB (m,IVIE"1)+ W I N ( Z X , I m l )+SPIlSI [Jm1,IP)+SEX84
(D=@)
.LT.
SEX%(XX,ZX) m-SPJN
ACmT*CmT+1
(m,Il']
(mSUN,SPIN (fX, m))) T m !f l i p t;ha apfn !mdate aampe ceant:
Ism XE"
c 2Q 10
C w x m caH2mm &CmT=ECPT/NSE"XB
C
=TURN END
ccccccccccccccccccccecccccccccccccccccccccC:eccecccccccccccccccccecccc~cc SUBROUTINE SUW(SPIN,mC,RmRGY) C calculate magnetizatian and energy for t h i s sweep C add these values to the group averages
ccCccccccceccccccccecccccceccccceccccccccccccccccccccccceccccccccccccccc C Global variables: @
G
e C C
C
INCZIUDE T A W . E8 ' Inputloutput variables: INmGER S P I N ( m X , W V ) !spin configuration (input) all of the thermodynamic quant have 2 indices (not a1l array elements are used, e.g. CWI (sweq,value)1 first index is the level: sweep, group, ox total second index is the quantity: value, sware, or sigma**2 ltEG mG(3,3) !magnetization (IIO) mAL ENERGY ( 3 , 3 ) !energy (I/Cl) Local variables: INTEGER PAIRS !interaction sum INTEGER SmEP,GROUP,TOTAL !which level of calculation INTEGER VALUE,SOUAW,SIGSQ Iwhich quantity !horiz and vart indices INTEGER XX, IY INmGER IXM1,IYMl fneighbor indices DATA SWEEP,CROUP,TQTAL/1,2,31 DATA VALUE,SQUME, SZGSQ/1,2,3/
cccccceeccCCccccccccccceccccccccccccccceccecccccccccccccccccccccccccccc~ 1.0 !zero paSr a m ry=z,m Xrn1=XY-2
DC7 20 xx=r,m X===-% 33' ( X X .EQ. 1)
!aefgmor to khe left; Ipri@&cb.c.
C
C C
C 20
10
this -&bed of s pairs demo not; oean& &W%~ a z m = ~ ~ x m + s P(Ex, r wx r ) * ( S B(~m ,xm)+s~m (X=, =)1 mmmtization is the Sc i tlw wino (Eq, 8.23.a) W ( S ~ L " , W W ] = W ( S ~ E P , W ~ ) + S P I Na) (~, CaHIPXm
CQRTXBW
396
B. Programs for the E~ramples C
1
!Eq 8 . 1 8
C G
G
=TURN
END
cc~~le~~c~cccc~~cc~~eccec~cccce~~cccccccccececcccccccccccc~cecccc SUBROUTINE AVE~G~MP*G,ENERGY,CNI,CB,IGROUP~ C find group averages from graug sums and add these to total averages; e calculate uncertainties and display results
c~~~cccccccccccccceccccccccccccecccceccece~ccccC:ccccccc~cccccccccccccc~
e Global variables:
INCLUDE "&MM. E8' INCLUDE IO,ALL' C Input/Wtput variables: C all af the thermodynamic quant have 2 Indices C (not a l l array elements are used, @.g. CNIfsweap,value)) C first index i s the level: sweep, group, or total C second index is the value: qantity, guant**2, or signra**2 REAL m G ( S , 3 1 !magnetization !energy R m L ENERGY ( 3,3) ! s ~ e i f i cheat REAL CB(3,3) CWT (3,3) !susceptibility INTEGER IGROUP ? group index (input1 C Local variables: RE- M, MSIG1, MSIGZ ?magnetizationand uncertainties RE& E,ESTGl,ESIG2 Ienergy and uncertainties REAL SUS,SUSSIG f susceptibility and uncertainty Ispcific heat and uncertainty REAL C,CSTG !index the wantity INTEGER IQUAMT INTEGER SWEEP,GROVP,TOTAL !which level o f calculation INTEGER VALUE,SQUAW,SIGSQ !which quantity DATA SbJEEP, GROUP, TOTAL/l,2,31 DATA VALUE,SQUAm,S f GSQ/S, 2,3/ ~ecccccec~cc~ccceccccecce~eccccccceccccceccccccC:c~c~ceccc~ccccccecccccc C aal-lats gzoup averamr m d m=rtalnkiarr f r o m group a m a
,XQVMT) /%SIZE 10 ) **2
CB f a O W , Vam)=BmWY {a@=, SQU-} - B m R a [mow,V U m 1**2 E m = f a O W , SXGSQ) =C33 ( a O W ,VUGE} INSIZE
(m@=,s x a s q ) CBI ( CB ( a O W , SQU-) C C
.LT.
0 , ) E ~ R G (Za o m , SZCSO~=O
.
V U m ) **2
=Cl3 (=Q=,
a& gxew avaraprs lea total s m o DO 20 1 ,SZGSQ m (TOT=, I Q W T ) =m@ (ZWU, XQUMT) Ern&= ( T 0 2 U ' X Q g m ] - m m ( r n T U , X (TOE=, XQVmZI) +CBX (9?0Tm, XQBmZ) =a
(=am, XQQM5")
cm
20 C
C
find toleal a v a r w o u s i q &eta%
(TOT=, m m )fxmm MSZGZ= ( m(TOT=, ~ S Q U ~ /XWW-N**2) ) /IaOm/HSTZIZ TB" ( W I G % ,W.0 ) WXGX=O,
c
, m m )/xmm BsrGi=.s@T ( ; e s x ~ z) (Tap=,
s x G s Q ) ) lzaQm
e
sossx- (mr( T ~ T U , s ~ o mt xl= o m - ~ u s * * 2 j m ( s w s s x o .LT. 0 . ) sussre-o.
IZ~OUI!
S V S S l * S ~ T (SUSSXO)
e
aow-c**2]/zmam flP" (CSXQ .LT. 0. ) CST(;la20, CSX-SWT (esxc)
c C
write o u t s u XF (TTEM) CALL TXTQUT(mG,&NERGY,CB,CHI,E,ES,5:G1,ESIG2,
+
M, MSXG1, HSTG2, SUS, SUSSIG, C, C S I G, TGROUP, OUNXT) I F ( T P I L E ) CALL TXSOUT ( N G ,ENERGY, CB, C B I , EI E 5 1G I , ESTG2, + M,NSIG1, MSXG2, SUS, SUSSXG, C, CSXG, TGROUP, TUHXT) C
RETURN END
cccccccccccccccccccccccccccecccccccccccccccccccccccccccccccccccccccccccc SUBROUTINE ZERO ( ILEVEL, E?IAG, ENERGY, CBI, CB) G zero sums Ear SLEVEL thermodynamic values
ccceCcccccccccceccc~cccccccccccccccccccccccccccccccccccccecccccecccccccc C Xnput/Output v a r i a b l e s ; INTEGER X L E m L !which level t o zero (input} G all of t h e thermodynamic w a n t have 2 i n d i c e s G (not a l l array elements a r e used, e.g. C H X l s w e e p , v a l u e ) f C f i r s t index i s t h e l e v e l : sweep, group, or t a t a l
398
B. Programs for the Ezamples second index is the value: quantity, quante*2, or sigma**2 MA6 (3,3) !magnetization (output) =L ENERGY (3,3) !energy {output) REAL CB63,3) ! spcific heat (output) REAL CHS ( 3 , 3 ) !susceptibility (output) C Local variable: INTEGER IQUANT !which quantity cccccccccccccccccceccccccccecccccccccccccccccccccecccccccccccccc~(1:cC:cccc DO 10 IQUAMT=1,3 MAG ( ILEVEL,IQUAPJT)=a. ENERGY ( I L E m L , 1QUANT)PQ. CNI (ILEVEL,f QUANT) =Q. CB (ZLEVEL,IQUANT) =Q. 3.0 CONTINUE RETURN END C
ccccccceceCccccccecccccccccccceccccccccccccecccccccccecccccccccccccccc~c SUBROUTZME INIT initializes constants, displays header screen, G initializes menu arrays for input parameters
(1:
cccccce"cccccccccccccecccccccceccccccccecccccccccccececcccccccccc~ccccccc C Global variables: INCLUDE "IO,ALLt INCLUDE ' MENU. ALLt
!program description DTmNSION DESCRP (2aI
INTEGER NWEAD,NTEXT,NGRBPN
Inuntber of lines for each descript;ian
cccccccccecccccccccccccccccececcccccecccccccccc~ccccccccccccccccccccccc~ C
get environment parameters CALL SETUP
C C
C C
display header screen DESCRP 4 1 1 = 'EXAMPLE 8" DESCW(2)= 'Monte Carlo simulation of the 2-43 Isin$ Model* DESCRP (3) 'using the Metropolis algorithm" NUmD=J text output description DESCW (4) = ' acceptance rate, energy, magnetization, specific heat ' DESCRP ( 5 )= ' and susceptibifity (all are values per spin)' NTEXT-2
c C
graphics output description DESCRP f G)= * spin configuration (blank=-l; X-+l) MGMPW=1
C
CALL WEADER~DESCW,NWEAD,WTEXT,NGRAE"H~
c C
setup menu arrays, beginning with canstant part CALL MERU
"
MTYPE ( 1 31 -FLOAT M P a T f l 3 ) - ' E n t e r v a l u e f a r m g n e t i ~f i e l d ( u n i t s o f kTI1 MTAG (13)=;%agnetic f i e l d f u n i t s of kT) " MLOLIN(f3)--20e MHILPM (131 ~ 2 0 . MEALS (23) -0.
MTYPE ( 14 ) =FLOAT MFMPTf14)=eEnter v a l u e f a r i n t e r a c t i o n s t r e n g t h ( u n i t s of kT)@ MTAG (3.4) = q l n e r a e t i o n s t r e n g t h f u n i t s of kTf ' MLOLIM (14) P-20 MWTLIM(14)-20. mm~s(14)=.3 MTYPE 115 ) =SKIP LS (15) ~ 3 5 .
MTYPE ( 38f =NUM e W T ( 3 & ) = " E n t e r number o f X l a t t i c e p o i n t s F MTAG(38f- ' H u d e r of X l a t t i c e p o i n t s t NLOLXN ( 38 1 =2, MWILf W (38) = m X MINTS 1381-20 HTYPe ( 3 9I =NUM NPMPTf39)m ' E n t e r n-er of Y l a t t i c e p a i n t s p MTAG (391= ' R u d e r o f Y l a t t i c e p o i n t s ' MLOLXM (39)-2. MBILIM 43 9f - m X Y MINTS (391 m20
M m E (40)=NUM MPWPT(401= * I n t e g e r random nrrmber s e e d f o r i n i t f l u c t u a t i o n s " #TAG (40) "Random number s e e d r HLOLXM (40) =IOQO. MWfLIM(40) m99989, MINTS ( 4 0 ) =S4767 NTYPE f 4 1 1 =NUM MPWPT(4T)m " N u d r o f t h e r m a l i z a t l o n sweeps' MTAG (41) ' Thernralizatlon sweepsf NLOLIM 14 3. ) =Q MHILIM f 41) *l000 MINTS (42 1 -20
-
MTSE ( 4 2 1 -MUM MPWT (42) ' E n t e r s a w l i n g frequency ( t o w a Z d c o r ~ e l a " c o n s 1 ' MTAG (42)= ' Sampling f requencyt MLOLIM (42 ) =l HHILLM f 42)=l00 MINTS (421-5
400
B. P~ogmmsfor ithe Ezan~ples C
MTmE ( 43 1 =NUM WRMPT f 43) 'Number of samples in a groupf
MTAG(43)= 'Group size' MLOLSM (431=l MXLIN ~ 3 =loo0 1 MINTS (43)m10 C
MTYPE ( 4 4 f =NUM W M P T f 4 4 ) - 'Enter nuder of groupsv
MTAG (44) W u h e r of groupst MLOLSN t 44f -1 MHXLIPI f 44)m1000 MINTS (44)=l0
c MTWE ( I S ) =SKIP W m L S (45) 060.
C E15TRMGfMTNTS (751 l =
'exmplff.txt8
e MTmE ( 7 6) =BOOmM m ? W T ( 7 6 ) = t D o you want tbe short version of the output?" MTAG (761 m f Short version of output* NLNTS (76)-0 C
MTmE ( 77 f =SKIP
LS 677)=80,
c MSmKG (MINTS186f 1 = 'exmpl8 .grf C
MTWE ( 8 71 =SKIP LS (87) t.190.
c
mTURI
END ~CCCCGCCCC~CCC~CC ~ ~ ~ C C C C C C C ~ C C ~ C ~ C ~ C C C C ~ ~ ~ ~ ~ C ~ ~ SWROUTINE P C gets parameters from screen C ends program on request C closes old files C maps menu variables to program variables C opens new f i l e s C calculates all derivative paramters C performs checks on parameters
cccCccecccceccccccccccccccccccC=cccecccceccccccccceccccecceccceeccceccccc C Global variables: ALLp INCLUDE "NU. INCLUDE *ITO.ALLf C Local variables: IMImGER IF !possible values for sum o f neighb. spins C map btween =nu indices and paramters
INTEGER I B , TJ, INX, XNY, f DSEED, I N T m , TNFREQ? fNSIZE# XNGRE", ITERSE =I31 TER(IB TER (TJ = 14)
-
TER (IDSEED 40) TEE4 (IWTWRM = 4 1 ) PAmMETER (INFREQ = 42) P m m T E R (INSIZE = 43) TER (INGRF = 4 4 1 TER (ITERSE 76) C Functions: LOGICAL LQGCVT
-
! c o n v e r t s 2 and O t o true and f a l s e
cccccccccccccccceccccccececccccccecceecccccccccccccccC:cecccccccccccccccc get i n p u t from temf n a l C&& C L m R CALL ASK (I,ISTOP
stop program if r e q u e s t e d TP f m A L S (XNEllIM) .EQ, STOP) CALL FXNXSW
e l o s e f i l e s i f necessary I F (TB= NE, MSmNG (MXMTS ( I m m ) 1 + CALL PLCLQS ( T H W , TUMIT) .WEe MSmNG (MINTS (IGWME) ) ) f P (GM-
.
+
C&LL FWLOS (W-, GUNIT)
set new parameter v a l u e s physical and numerical J==ALS ( f 31 NXmMIWTS (INX) Pa?l=MINTS (XWV) D S ~ D - D B L E(MINTS ( I D s a E m NTHEWPlr=MXHTS (INTHW) NFmQ-MINTS ( INFmO) NSIZE=MXUTS (INSSZE) NGROUP=MINTS (INGM f
t e x t output TTERM-LOCCVT (MINTS (ITTERN) f
TFILE=taGCVT(WXNTStj:TFIUjj T N ~ - H S T R N G(nrNTs (ITHW) 1 TERSE-LOGCVT (MINTS (ITERSE f 1 graphics o u t p u t GTERM-LOGCVT (M1WTS ( fGTERH1 1 c H m c e = w c C v T f n r N a s ( I G ~ D 1J
WILE-LWWT(MXNTS(IGF3LEI) GNM=MSTRXJG (MINTS (ZGNmE) )
open f 2163s
IF (TFILE) CALL FLOPEN (TNWI"IE,TWIT) XF (GFILE) CALL FIXIPEN (EH-, GUNIT) !files may have been renamed MSTRNG (MINTS(ITNAm)) = T H W HSTRMG (newrs ( I G N ~ =I G N A ~
c CALL C L M R C C
~alculatederivative parameters NSPIN=NX*#Y PO 50 Z F * ~ - 4 , 4 ~ 2 tr~lt.teef pzebi.; net: alf mzro (m, -%)=m (2" (J*ZI+BII m z ~ ~ ( s~ x~**/ ~l T~I a ~ n , - % l
ZQ
c G
calculate parameters Esr best looking text display IF (2*NX .LE. TRmXB) THEN Iskip spaces in x XSKIBm,TRUE. XCNTR={TRWIB-2*NX)/2 thaw to center display ELSE XSKIPm. FALSE, XCNTR= (TWID-NX)/2 END TF IF fXCNTR .LT, 1) XCMTR=I IF (2*NY .LE. TRMLIN-5) THEN YSKTP=,TRUE. YCNTR=ITRHLIN-2*NV)/2-3 ELSE YSKXP=,FALSE, VCNTRm f TmtIN-NV)/2-3 END IF IF (YCNTR .LT, O f YCNTRmO
!skip lines in y !how ta centsr display
C RE;TURN END
cccccccccccceccc~ccccecccccccecccccecccccccccccccccccccccccccccccc~ccccc SUBROUTINE PRMOUT(NUNIT,NLINES) C write out parameter sumary to MUNXT
cccec~~~ccccc~cccecccccccccccftcccccccccecccccccccccccccccceccccccccccccc Global variables: INCLUDE @I0.ALL8 INCLUDE 'PAMM. E&' C Xnput variables: XNmGER NUNIT !fortran unit n u a e r INmGER NLTNES !nu&er of Lines sent to terminal CCCCCCCCGC~CCCCCCCCCCCCGCCCCCCCCCC~CCCCCCGCCGCCCCCCC~C~CCCCCCCCCCCCCCCCC IF fMUNf T .EQ, OUNIT) CALL CLEAR C WRITE (MUNIT,51 WRITE (NUNIT,61 WRITE (NUNXT,7 ) B WRITE (NUNIT,8) J
C
MTRITE (HUNZT,101 NX,NY WRITE (NUNIT, 1 5 ) NTBBRM WRf TE (MUNIT, 20) WMQ, NSTZE MRXTE (MUNST,* ) " NLTINESm8
c 5 6
F O M T f"utr;lut fromexample 8 z C ) F O M T f t Monte Carlo S i m l a t f o n of t h e t 2--D I s i n g Model u s i n g t h e Metropolis A l g o r i t h m r ) FOmT [ @ M a g n e t i ~ f i e l d f u n i t s o f k T ) = ' , 1 P E ~ 2 , 5 ) F O m Y ( @ Intezraction s t r e n g t h ( u n i t s of k T f =\lE"E12.5) F O m T [' NIX=',f3,5Xrf NY ='#X31 F O M T ( l nn&er aE t h e r m a l i z a t i o n sweeps =',S41 P O W T ( f s v e e p f r e q u e n c y = "H,' g r o ~ p s i z e = ~ , f i 4 )
+
7
8 l0 15 20 C
WTURH
END CCCCCCCCCCCCGGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
SUBROUTINE DISPLY (HUNTT, SF IM, N G , ENERGY, ACCPT, ImOUP TISWEP 1 C d i s p l a y s p i n c o n f i g u r a t i o n (spin=-l i s a blank, spin51 i s an X I C and write o u t d a t a f a r t h i s sweep
cc~cccccc~~cce~ccccccccccccceccccccecc~eccecC:ccccc"cc~ccc~cccccccc~c~cccc e Global v a r i a b l e s : C
C C" C
C
C
SNCLUDE fFAmH.E8Q INCLUDE "IQ.ALLf Input variables: !s p i n c o n f i g u r a t i o n INTEGER SPIN ( W X , W Y ) a l l of the thermdynamic w a n t have 2 f n d i e e s (not a l l a r r a y elements a r e used, e.g. CHX (sweep, v a l u e ) 1 f i r s t fadsx i s the l e v e l : sweep, greup, o r t o t a l seeand i n d e x i s the value: c y ~ a n t i t y , quant**2, ar sigma**2 m&Lm G ( 3 , 3 f !magnetization !e n e r w RE= EHERGY (3,3 f ACGPT !ameptance r a t i o INTEGER NUNIT ! u n i t wet re w r i t i n g t o !sweep and group index INTEGER ISmEP, TGROUP Local v a r i a b l e s : INmGER S&TEEP,GROUP,TOTU !which l e v e l of c a l c u l a t i a n XNmGER VALUE,SQUAm,STGSQ !which q u a n t i t y ! l a t t i c e indices TNTEGER I X , IV C M m C T E R * 1 CSPIN(mXX1 !spin a s c h a r a c t e r d a t a !blanks f o r eezntering i n X s s l ~ haLxE I DATA SmEP,GROUP,TOTALf1,2,3/ DATA VALUE,SQUmcSIGSQ/1,2,3/ Q
CCCCCCCCCCCC~C~CCG~CCCGCCC~CCCCGCCCCCCGCCCCCCCCCCCCCCCCCCCCCC~CCCCCCCC~C
20
I P (MUWIT .EQ. OUMIT] THEN CLEAR DO 2 0 I V = ~ , YGNTR m I T E (OUNIT, * ) ' ' CONTINUE
END SE"
!center output
404
B, Programs far the Zz~mples WITE (MUNIT, 11) IGROUP, ISmEP,NSXZE,ACCPT, ENERGY ( SmEP, VALUE) INSPIN, MAI; [SWEEP, VALUE 1 /NSP I N F O m T f r group \ I 3 , ' , s ~ e e p ' , I 3 , Q u t o f ',53,5X, + aaccpt , l f 5 . 3 , t Energy = #,F7.3,' Nag = ' , , F 6 . 3 )
-8-
f l C
10 15 16 100
!change +-1 t o X and b l a n k DO 100 IU-MY, 1, -1 DO 50 IX=Z,NX I F (SPLN(IX,IV) .Ea. 1) THEW CSPIN (IX) =' X @ ELSE GSPIN f IXl=" END I F CONTINUE w r i t e o u t a l i n e a t a t i m e (no c e n t e r i n g done f a r TUMIT) EF (MUMIT .EQ. TUNIT) THEN WRITE (TUNf T, 1 6 ) (CSPIN (IX),I X = 1 , MX} ELSE I F (XSKIP) T B N mXTE (MUHIT, 1 0 ) BLNK (l:XCHTR), (GSPXN (XX) ,IX-1, NX) ELSE m J T E (HUMI"IC15) BLMK(I:XCMTR), fCSPXt3fIX),TX=l,MXf END I F I F (VSKIP) WRITE (MUNIT, * f ' ' END J F F O M T (1X,A, I O O (AI, 1x1) FORMAT (Ix,a, 100 (AI) 1 F B R M T (1X,100(All) CONTINUE I F (MUNIT EQ. QUN1T) CALL PAUSE ( * t to c a n t i n u e ',Q)
.
..
G
RETURN END
cccccccceccccccccccccccc~ceccccceccccccecccccecccecccc~ccccccc~ccc=cc~ccc SUBROUTINE SWPOUT(MUNIT,~G,E1"9ERGYt&CCPT,IGROUP,ZS1EEP,HLXNES) C and w r i t e o u t d a t a f o r t h i s sweep
cccccceccccccccccceccccccccececceeeccccecccccceecccccccccccccccccccc~~cc C Global v a r i a b l e s : INCLUDE f P M M , E 8 1 INCLUDE 'XTO.ALLt G Input variables: C all af t h e thermadynamic w a n t have 2 i n d i c e s C ( n o t a l l a r r a y e l e m e n t s are used, @.g. CH1 (sweep,valua) ) G f i r s t index i s t h e l e v e l : sweep, group, o r t o t a l C second i n d e x i s t h e v a l u e : q u a n t i t y , w a n t * * 2 , or sigma**2 RE& M G { 3 , 3 f !magnetization WBL ENERGY f 3 , 3 f !e n e r w mm ACCPT Eaeceptance r a t i o INTEGER MUNIT I u n i t wef re w r i t i n g t o ZNmGER ISMEEP,TGROUP !sweep a n d group i n d e x ZNmGER NLINES ! k i n e s w r i t t e n t o t e r m i n a l (X/Q) C Local v a r i a b l e s : XWTEGER SmEP,GROUP,TOTAL [which l e v e l o f c a l c u l a t i o n
INTEGER V&LUE,SBUAm,SIGSQ !which quantity DATA S m E Pc GROUP, TOTAL/1,2,3 / DATA V&LUEt SQUARE,SXGSQ/l.#2?3/
cccccccccccecCccccccccceccccccccccccccceccccccccccC:ccccccccccccceecccccc W I T E (MUNIT,11) IGROUP,ISWEP,NSIZE,A m , ENERGY (SmEP,VALUE) /NSPXN,m G {SWEEP VALUE)/NSPIH FO-T (7Xe13,7X,13,' / " €13,"1X,FSS3,7X,F9.31 IF (NUNXT .EQ. OUNITf NLINES=NLZNES+l RETURN END
+ 11
ccccccccccccccccccccccccccecccecccccceeccccccccccccccccccccccccccccccccc SUBROUTINE TXTOUT(MAG,ENERGY,CB,CWf,E, ESIGl,ESZG2, + M,MSTG1,MS162,SUS,SUSSXG,G, CSIG?IGROUP,MUNfT}
e write out averages and uncertainties to MUNIT CCGCGCCCGCCCCCCCCCCCCCGCCCCCCGCCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCCCCC~CCCCCC
C Global variables: INCLUDE t P A M * E 8 " INCLUDE 'IOIALrL6 C Input variables: C all of the thermodynamic want have 2 indieas C (not all array elements are used, e.g. CMl(sweep,value)) C first index is the level: sweep, group, or total C second index is the value: cfuantity, cyuant**Z, or si9ax*2 Mm mG(3,3) !magneCizatian f energll R m L ENERGY 4 3,3) ! specific heat CB 43,33 CB1 (3,3) !susceptibility TNmGER IGROUP !group index M,NSIGI,MSIG2 !magnetization and uncertainties E,ESIGZ,ESIGZ !energy and uncertainties !su~ceptibilityand uncertainty SUS,SUSSXG mm CrCSTG !specific heat and uncertainty INTEGER MUNZT !which unit nu&er C Local variables: INWGER SWEEP,GROUP,TOTAL ?which level of calculation INTEGBR VALUE,SQUm,SIGS& Ewhich quantity DATA SWEEP,GROUP TOTAL/ l,2,3/ X>ATA V U U E , SQUmE,SIGSQ/I,2 , 3 /
ccccccccccc~ceccccccccccccccecccccccccc~cccc~ccccccccccccccccceccccccccc MRlTE: mITB mITE mITE +
(MUN1T, 3 0) IGROUB,NGROUP (MUNIT,32) (WUNfT,33) (HUN1T, 35)
EHERGU(CROUP,VALUE~/MSP1NISQRT(ENEWGY(GROUP~SIGSQ~]/HSPXE,
+ m G (GROUP,VALUE)/NSPIN,SQRT (=G (GROUP,SIGSQ)). /MSPIN, + CWX(GROUP,VALUE)/NSPXMeCBIGROUPvVALUE~/PJSPIN fhlRITE (IUXINIT,r10) E/NSPIN,ESIGI/MSPIHtESXG2/AISPIN,
+
H/NSPIN,MSIGI/NSPIN,MSZE2/WSPfNli
+ SUS/NSPIN,SUSSIG/NSPIN,C/N5PIPJ~GSIG/MSP1N WRITE (MUNIT,*) " fF [(MUNIT .Ea. OUNIT) .AND. (.MOT. TERSE)) -4CALL PAUSE t f to continue. , 5 ).l
.
C 30 32
33
35 40
F Q m T ( q r o u p ',I3,' (out of: ',I4,') averagesr) F O m T ( I q X , 'Energy1, 13X, *Magnetizationt, 5 X , ' S u s c e p t i b i I & t y y , .IZX, " p e e i f i c Weat') F O M T (l4X, L-----*, 1 3 ~ , ---...---- t 15~,f-------------..." C 2X, * 6 1 F O m T (' group ' " 2(1X,F7.3, ,F5,3,6X), -5 2 (2X,F6,3,7X) ) F O m T I t ttotl * ,2(1X,f"7.3, +-* ,F5.3, V / "PF5.3), i 2 ( I X , F6.3, ,F6,3)) --m--
----------""--
*+mf
"m-'
G RETURN END
ccccccccccccccccccccccccccccccccccccccccccccccceeccccccccccccc~ccccccccc SUBRQUTINE TITLES (MUNIT, NLINES) C
write out t e x t d a t a t i t l e s
cccccccccccecccccccccccecccecceccccccccecccccccccccccccccccccccccccccccc C Global v a r i a b l e s : INCLUDE, XIO ,ALL* C InputlOutpt variables: INTEGER MUNIT XNmC;ER NLINES
!o u t p u t u n i t f i n p u t 1
!nu&er
of l i n e s w r i t t e n (5/0)
cccecccccccc~ceeccccccccceeccccceceeccccccceccccccccecc~cccceccccccccccc I F (NUNZT .EQ. OuNIT) CALL CLEAR C
10
11
WRITE (NUNfT,IO) NRITE (MUWXT,11) F O M T (bX, 'Group*, 3 X , 9 w e e p I Q u t o f f , 5X, ' A ~ e p t ' , 9X, "nergyp + 6XffM)rlagnetization'f FQmT 3X, ------------p 5X6 gx, .I. 6X,f,..------------t 1
(a,
~
~
-
-
-
f
,
f
----m-#
c I F (MUMIT .EQ, QUNIT) MLINES=NLJWES+2
c =TURN END
CCC~CCCC~~CGCCCC~GCGCCGCCCCCCCCCCCCCCCCCCCGCCCC~GCCC"CGCCCCCCCCCCC~~CCCGC
ccc~cccce~~~ccccccc~cccc~ccccccecccccc~cceccccccc~cccecccccccc~ccccc C param.@@
e =U B
!magnetic f i e f d s t r e n g t h -!interaction strength ! h a r i z and v e r t n u a e r of l a t t i c e p o i n t s XNTEGER NX, NU DOUBLE BRECXSION DSEED !random n u d r seed INTEGER NTXERM !nu&er of t h e r m a l i z a t i o n sweeps ? f r & gof sweeps do avoid correlations INTEGER MFREQ INmCER NSXZE !s i z e of groups IMTEGER NGRQUP !number of groups !data f o r e e n t e r i n g d i s p l a y INTEGER XCNTR,YCNTR LOGICAL XSKIP,YSKIP ?data for centering display M L R1?ITXQ(-4;B,-l:f) !a,ceepCan~er a t i o m a t r i x INTEGER WSPIN ! t o t a l nu&er of s p i n s
m&
J
LOGIC&
TERSE
!terse outpat
IUmGER
mm,M X Y
!maximm horiz and vert dimens5ons !these are set assuming that you !have no graphics and the length sf !your terminalm24
e PAWETER (WX-791 TER ( W U = 2 0 ) G
COMQN / P P A m / B, J / NX, NY, BSEED, NTmRM, NFReQ, fVSIZEINGROUP COMON / GOAMM / XCNTR,VCWTR,XSKfP,VSXIP,TERSE COWON / P C U C / RATIQ,NSPIN
This page intentionally left blank
Appendix C
Programs for
C.1 Project 1 Algorit hrn This program calculates, for a given energy, the deflection function for scattering from the Lennard-Jones potential at NB impact parameters covering the range from enrl to ennx. The basic task is to evaluate Eq. (1.8) for each impact parameter requested (DO loop 25 in subroutine n~ceoa).This is done in subroutine TaeTn, where first a simple seareh is used to locate N T N , the t u r ~ n gpoint. Then the integrds are evafuated by the rectangle rule, with a cfiange of variables to regul&e the singulmities, Ysu may dter the potentid by cfla@ng m ( ~at)the beginning of subroutine THETA. If you; do, don't forget to find the new vdue for RMAX such that V(r,,,) M 5 x 1 0 - ~ & . Input The physical parameters are the Energy [1.0], the minimum and maximum impact parameters [.1,2.4], and the number of impact parameters for which the guadrature is performed [20]. The maximum number of inzpaet parameters is fixed by the FORTRAN parameter WX= 100. Energy is in units of 6,lengths are in units of a. The program chedts that BMIN cr BMAX < M A X in subroutine PCaEcK. The numerical p a r m e ters include the tolerance for the search on the turning point [.0001], the radius beyond which the potential is negligible [2.5], and the number of quadrat- points [40]. Output Far each impact parmeter the text output disjplays the impact parameter, B; the radius of dogest a.pproa&, MII; a9d the scaltering angle in d e g r ~ sANGLE. ; ~ After all values of UGLE have been cdculated, the deflection (scattering) an@eis maphed asr a function of imprtet pasmeter,
cccccceccccccccccccccccccccccccccccccccccccccecccccececcceccccccc~cccccc C C C
C
PROGmM P R 0 9 1 P r o j e c t l: S c a t t e r i n g by a c e n t r a l 6-12 p o t e n t i a l COmUTATIDHkL PHYSICS (FORTWN VERSIOW) by Steven E. Raonin and Dawn C, M e r e d i t b Copyright 1989, Addison-lesley P u b l i s h i n g C o w a n y
ccecccccccccccccccccceccc~~cccccccc~cccce~cccccccccccccccccccccccccc~ccc 5
CALL IEJIT CONTINUE CALL PAMM CALL ARCWON GOT8 fi
!display header screen, setup parameters !main loop; e x e c u t e o n c e f o r e a c h set aE pasam ! g e t input p a r a m e t e r s !calculate s c a t t e r i n g angles
END
ccccccccceceecccccccccecccccccecccc"cececececcccccccceccccccccccccccccccc SUBROUTINE mCNON C c a l c u l a t e s c a t t e r i n g a n g l e s a s a f u n c t i o n o f t h e impact p a r a m e t e r
cccccccceccccce~eecceccccccccccccccccccccCiccccececcccccccccceccccccccecc C Glabal variables INCLUDE 'PARAM.PI6 INCLUDE ' I Z O . ALL' e Local variables:
REAL RMZN ! r a d i u s o f c l o s e s t approach !final scattering angle RE= ANGLE (0:W) REAL SNPACT(O:MAX) !emact p a r a m e t e r ! v a l u e s cf t h e two i n t e g r a l s REAL INT1, INT2 ! i n d e x o f inrpact param INTEGER I B INTEGER NLINES ?nu&er of l i n e s printed so f a r ?send t o terminal INTEGER SCMEN INmGER PAPER !make a hardcopy INTEGER FILE !send t o a f i l e DEITA SCMEN, PMER, FILE/%#2 I 3 I
cccCcccccccec~~cccccccccccccccccccccecccc~cccccccccceeecccccccccccccccc~ C
output s u m a r y of parameters XP (TTERM) GALL PRMQUT (QUNIT, NLZNES) fF (TFILE) GALL PMOUT (TUNZTeNLINES) I F (GFILE) CALL PMQUT IGUNXT, NLINES)
c
I l o q w a t % q a a t garm
DO 25 PB=O, (=-l)
c (m*DB) ! (fa) ,zwxz ,m 2 ,m w ) r
t value o f B aka FmT& for each B mGm (m)= (Z*ZWACT (m)* (XET"P4m2) *TB@) /BX f czonvee ta T (PB)==M;(.
(-XI
C
e
t e x t output IF (TTERM) CALL TXTOUT (OUNIT,NLIE~ES~ IWACT RNIE~ANGLE 1 I F (TBILE) CALL TXTOUT [TUNITINLIMES,IMPACT (XBf RMIN,PiNGLE { I B l )
e 25 CmlrIm
c I F ITTERM) CALL PAUSEffto c o n t i n u e . . XP (TTERW1 CALL Cmm C
.',l)
C.1 Project 1 SF IGTERM) CALL GWOUT(SCRE&N,AMGW,IWACTf I F (GFILE) CALL GWQUT (FILEI AMGm I IMPACT) I F (GMRDCPf CALL GRFOUT (PAPER, MGm, IRACT)
415,
!graphics o u t p t
c RETURN END
~cccc~cCcee~~ccccccccccccccccceccc~cccccceccccccceccccccccccccceccccc~cc C C
C
SUBROUTINE THETA (B,TNT1,INT2, MIN) s e a r c h e s t o f i n d RMXN ( c l o s e s t approach) integrates FNT1 from El t o R m X t o find INTl i n t e g r a t e s FN12 from RMTM t o -X t o f i n d INT2
ce~~cc~~c~ce~cccccc~~ccccccccccC:cccccccececcc~cccccccccccccccccceccccccc C Global
variables:
INCLUDE ' PPBMM. P1 " e IngutfWtput variables: W L B R E U XNT1, INT2 RE= RMZN C Local v a r i a b l e s : BE& R REAL BR RE= U M A L UMAX
RE&
H M U SUM INTEGER I U REAL FNV M U PNII,FMI2
l i ~ a c pt a r a m t e r ( f n p t f !values far t h e two i n t e g r a l s (crutput) ? r a d i u s of c l o s e s approach (output) !c u r r e n t radf u s !c u r r e n t s e a r c h step s i z e !U=SQRT (R-8) o r S a T ( R - M I N I !@-=SORT (R=-B) or SQRT 1 R W - R M E M )
!radial s t e p for wadrature !sum f o r w a d r a t a r e !index on U tscattering potential {function) ! f i r s t and second i n t e g r a n d s ( f u n c t i o n )
c e c c e c c e e c c ~ c e c c e c c c c c c e e C c c C c c e e G c c c C C
&fine Zaac%ions m (R1 1 4* (R** (-%a) -]R** ( - 6 ) ) TIR**~/SWZ(1- (sm)**2) mzz (B,R) B'Mf 2 (B, R, E) l fR**2/SWZ (1- (LS/R) **S-W fR) /E)
-
C
!$nwmd m a d for turning point
1
DR XF
ap-
0.2
1%
M&=&
) ) .&P.O*O)
ia w h r e fi.e.,
ir iaffdta the W d n a t o ~ O
m m GO 1CO 5
Ern C
! f i r s t i n t q r a l kg- recdaaqle raXa IaMge vrr2&1% do G=B=E(R-B) !to mmve ainplariky at; R@
Sm=O
M)
l0 IfJ=l,WTS V=E* (f U-@. 5 ) R=@* *2+B S ~ S W + @ +(B, ~ IR)l
fahaage ba&
te R
eval i n t q z m d
10 C a M T x m XlI"I=2*W*Srn
G
!@e@oa& inte9z.l by roetangas rule tebmgm of vari&&r t o !CQ rrmmove r i a p l a r i t y at R = m M
6-0
DO 22 XUm1,NnTS mm* (XU-0.5) R=U**2+WXM SW=SW+U*m12(8,R,E) 22 COmSm kl%2=2+P*SW
tahango b a d to R t o oval, Snt;sg%ad
c RETURN END GCCCCCCGCCCCCCCCGCCCCCCCC~CCCCCCCCC~CCCCCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCCC
SUBRQUTINE T N l T C initializes constants, displays header screen, C initializes arrays for input parameters
cc~cccceccCccccccccccccecceccccccccc~ccccccccc~~cccc~cccccccccccccccccc~ C Global variables:
.
INCLUDE ' I0 ALLF INCLUDE ' MENU. ALL' INCLUDE 'PAmM.OIt C Local parameters: CHWCTER*BO DESCRP DINENSION DESCRP (22) INTEGER NHEAD,NTEXT,NGRF
!program description f n u w r o f lines f o r each description
cccceccc~~~cccce~ccccccccccccccccccceccccccc~ceccc~ccccccccecccc~cccccc CALL SETUP
!get environment parameters
G
!display header screen PROJECT 1' DESCRP (E ) DESGRP(2)= #Scattering by a 6-12 potential' NNEAD=2
e C!
text output description F Iwact, parameter, radius of closest approach, DESCRP (B)= and the angfe af dafleetlan" DESCBP 131 =
"
WTEXZ"s2
C C
graphics output description DESCRP f 5)= #ddelectfon function* + //Vseattsring angle v s , impact parameter)' PJGRF=1
G
CALL WEADER(DESCRP,NHEAD,NTEXT,NaFI
c C
calculate constants PI=B*ATAN (1.0)
C
CALL MENU
!setup constant part of menu
NTWE ( 1 3 ) =FLOAT M P W T (13)= ' E n t e r i n c i d e n t enerc?ry E ( s c a l e d u n i t s ) NTAE (13) q n c f d e n t e n e r g y ( s c a l e d u n i t s ) ' MLOLIN (13) 01
- -.
MHILIM (13)=1000, mmLS (13)-1.0
NTYPE ( 1 4) =FLOAT MPFUrlPT(14)= ' E n t e r t h e minimum impact p a r a m e t e r ( s e a l e d units)* %TAG(14) %Minimum impact p a r a m e t e r Bmin ( s e a l e d units) '
- ;=.
MLOLTM (3.4) 0 MWILIM(14)-2.5 M m L S (14)-0.1
NTYPE (1S) =FLOAT M P m T ( 1 5 ) = I E n t e r t h e maximum impact p a r a m e t e r ( s c a l e d u n i t s I r MTAG (15)= Maximum impact p a r a m e t e r Bmax ( s c a l e d u n i t s ) MLOLXN(lSI=.O NWSLIM(15)=7. mEZILS 4151-2.4 @
MTWE f f 6)=NUN M P W T { S G ) = ' E n t e r nu-r a f values Ear impact p a r a m e t e r " MTAG (161 = "umber o f v a f u e s f o r impact p a r a m e t e r * MLOLIM (3.6) =l, MHILf M t 1 6 ) =MAX MINTS (16) -20
MTVPE ( 38 ) =FLOAT MPRMPT ( 3 8 ) 1 ' E n t e r t a l e r a n c e f o r t u r n i n g p a i n t s e a r c h " MTAG (38) = T u r n i n g p o i n t s e a r c h tof e r a n c e F MLOLSM ( 3 8 ) 00a005 ~ ~ NHTLTNf38)=. 1 maL5 (38) =. 0001 NTUPE ( 3 9f =FLOAT MPmPT ( 3 9 ) = * E n t e r r a d i u s a t which V ( r )<<E ( s c a l e d u n i t s ) NTAG (39) = 'Maximum r a d i u s R M X ( s c a l e d u n i t s ) " MLOLXM139) =Q.
M'NILIM(J9f=IO. O LS (391-2.5 NTUPE ( 4 0 ) =NUM M P M T (40) @ E n t e rnu&er o f q u a d r a t u r e p o i n t s r MTAG (401 Wu&er of q a d r a t u r e pof n t s p MLQLIM(40) =20.
-
MNXLIN(9Of-300. MINTS (40)=40
414
G.Pmgmms for .the Projects C NTVPE (41)=SKIP MRmLS (41)=60. C
MSTRNG(MINTS(75) ) = r p r o j l . t x t ' C MTWE ( 7 6 1 -SKIP m m L S (76) 4 3 0 .
c MSTRNG (MINTS (86)) =
c
'p r o j l .g r f *
MTYPE ( B7 1 =SKIP C RETURN END
ccceCc~cccccceccccccceeeccc~ccccccccccccceecccccceccccccccececcccI:cccccc SUBROUTINE P-M C g e t s parameters from screen
C e n d s program on r e q u e s t G closes old f i l e s C maps menu v a r i a b l e s t o program v a r i a b l e s C opens new f i l e s C c a l c u l a t e s a l l d e r i v a t i v e parameters
cCccccececcccceccccceccC:ccccccccccccccC:ccccccccccccccccccccccccccccccccc C Global v a r i a b l e s :
INCLUDE =PIENU ALL" INCLUDE "(2. ALL' INCLUDE ' P A m . P I 8 INCLUDE %P. " I
C
Function: LOGICAL LOGCVT
!c a n v e r t s 3 and
O t o true and f a l s e
c~cccccecceccccccccceccecccccccccccccccecceccccccccccccccccccccccccccccc C
g e t input from t e r m i n a l caLL CLEAR GALL ASK(1,ISTOP)
c C G C
c e
s t o p grogram i f r e w e s t a d I F (MREAtS f l M I N ) .EQ. STOP) CALL FINISH c l o s e f i l e s i f necessary ZF f TNAME NE. MSTRNG (MINTS (ITHAME) 1 1 + CALL FLCLOS (TMAME, TUNTTI I F (GNAME .NE. MSTRNG (MINTS (IGNAME))) + CALL FLCLOS (GNBME, GUNIT)
.
p h y s i c a l and n u m r i c a l parameters EmmEALS 4 I E ) BMINmMREALS (IBMIN) B W m N R E A L S (SBmX) NB-MINTS (INB) RW=MREALS 4 IRMAX
TOLR=mEALS (ITQLR) NPTS=MINTS (INPTS} C
e
t e x t output TTERMmLOGCVT (HINTS I T T E M I 1 TFILE=LoGCVT (MINTS (ZTFILEI Z TNm=MSTRNG (MINTS (ITHAW] 1
C C
graphics output GTERM-LNCVT {MINTS( I G T E M l f GHRDCP-LoGWT (MINTS (IGHRDI j
GFILE=LOGe\lTfMINTS(IEE"ILE)~ GNW-MsTRHG(MINTS(lGNAME~) f:
e
openfiles
XF fTFZLE) CALL PZaPEN(TNAm,TUNIT) I F (GFILEf GALL FZOPEN(GNAm,GUNIT) files may have been renamed
C
MSTRNG (MZWTS (ITHAW1 ) =TNAME MSTRNG [MXNTS(XcHArn) I = G M A ~
e CALL PCHECK DB- (BWX-BMIN) I (NB-11 CALL C L E m
?calculate step in B
C
RETURN END
CCCC~CCCCCCCCCCCCCCCCCCGCCCCCCCGCGCCCCCCCCCCCGGCGGCCCCCCCCCCCCCCCCCCCCCC SUBROUTIRE PCmCK
C to ensure that O
eccc~cccc~ccccc~ccCcccccccccccccecccccccccccccccccccccccccc~cccccccccccc Global variablas:
C
XNCLUBE ' m N U , ALL" INCLUDE 130.ALLt INCLUDE * P a M . P l r INCLUDE: @Mi%l?.PI" G
Function: !gets f l o a t i n g point n u m b e r
GETFLT
ccccC=cCccCccccec~ccccccccceeeceecccccec~ecccceccecccccccccecccccccf:ccccc IF ( B m X .LE. BMINf THEN m I T E (OUNIT, 10) B W , BMZN
40
m P T E (OUNIT, 20) H m L S fXEMXN1 -C;ETFLT (MREALS (IBMINf NLOLEM (IBNIN},MEIXLIM (IBMIM) , E n t e r BMIHp 1 m M L S 4 I B m l =GETFLIP ( m E A L S ( f B m X ) ,BMXN, MWTLIM ( SBmX 1
.I-
@
+
@Enter BNAX*) BM=PIREALS (ISiElAX) BMIN=mEALS ( IBMIN )
60 TO 40
END XF C
sa
IF
(=X
.LE, BM)
T
~
N
416
C. Pcrognsms for the Pr0jec.t-s m I T E (OUNIIX", 30) RPIIAX,BmX WRITE (OUNXT, 20) !prompt f o r new v a l u e s MREALS ( I B W X ) 6 E T F L T (MREPILS ( I B m X ) I SWTN, MN.XtI:M f IBfutAX) ,
"ntsr
-I-
B M X @1
BMAX=MREALS (TBMX) ) (HREAZS I R ~ X , ) XAXI NReALs t I R ~ -GETFLT
,
q n t e r RmXfj
-4-
RWXmMREBLS ( I m X f GQ TO 50 END I F
e 10
B m X ( = r e , F 6 . 3 , t 1 f," hi isass t h a n BNIN F6.3,r),t) F Q m U f " b u t i t should be3 t h e o t h e r way round; " F O m T (/,'
+
20 -I-
30
f
r e e n t e r parameter v a l u e s p 1 X=8,F6.3,e)r,p Is less t h a n B M
F O m T (/,"W
(==',
fmf
,,F6.3,r)f f
C
RETURN END
cccCccccecccccceeccccccccccceccceccceccccccccecceccceccceccceccceccccccc SUBROUTINE PRMOUT(MUNIT,NLIWESI
o u r p u t s parameter s u m a r y ta the s p e c i f i e d u n i t CCCGC~CCCCCCC~CCCGC~CCCCCCC~CC~CC6CCCGCCGCCGCCCCCC~CCCC~CCGCCCCC~GCCCC C Global v a r i a b l e s C
INCLUDE *SQ.BLZ' INCLUDE * P W M . P 1"
c Passed v a r i a b l e s ! u n i t n u w r f o r output f i n p u t ) !number of l i n e s w r i t t e n s o Ear ( o u t p u t )
INTEGER MUNIT INTEGER NZINES
eCc~ccccecc~cccc~c~ccecccce~ecceecC:ec~ccc~cccc~ccccceccccceccccccccc I F (MUHIT .EQI OUNIT) CALL CLEAR G
WRITE mITE mITE mXTE
mITE WRITE mITE WRITE C C
(MUNIT, 3.91
(MUHIT, 21 1 (MUNIT,27) (MUNl"lZ23) (MUNXT,25f (MtlNIT,29) (NUNIT, 30) (NUNIT, 1 S 1
E RmX,WTS TOLR BMIN,BMX,NB
d i f f e r e n t d a t a h e a d e r s for graphics and t e x t output I F (MUNIT .NE, GUNIT) THEN WRITE (NUNIT, 31) m S T E (MUMIT, 321 bJR32"E (MUNIT, 33) ELSE m I T E (MUNTT, 3-51 END I F
e WLIWES = 11
G 19 21
FOMT F O m T
+
23 25
FO-T FOMT
2 " 1 O W U 8
29 30 31 32 33 35
FOWT
+
Fa-T POmT FOMT
FOWT FONT
'1 Output from p r o j e c t l: ' S c a t t e r i n g by a c e n t r a l 6-12 p o t e n t i a l (' Rmax=', FE;, 3,SX, numbier o f q u a d r a k u r e p o i n t s =% 14) ( * Turning p o i n t t o l e r a n c e = ',E12-5) I n c i d e n t e n e r g y = 'PF8.31 (' BnIn = \F6,3,SX,'Bmx ' ,F6.3, SX, nuumber of B v a l u e s = ',I31 (' Lengths a r e i n s e a l e d u n i t s , a n g l e s i n d e g r e e s ' 1 (%$X,' Impact" 14X, C l ~ s e s t , ' 16X, @ s c a t t e r i n g 1a ' P a r a m e t e r * , l 3 X , t A p p ~ o a ~17X, h p 'Anglei 1 (13X, 5,13~,"------t 1 7 ~ , f2X,'I1mpact parameter',2X.'S~ettering Anglef) ('
('
"--------
@
---...-f
C
RETURhl END
eecceeccccccccccececccccccccccccccccccccccccccccccccccccccccc~cccccccccc SUBROUTINE TXTOUT(NUNTT,NLINES,BIWINIANGLE} C writes r e s u l t s f o r one i n p a c t p a r a m e t e r t o t h e r e q u e s t e d u n i t
ccccceccccccccecccccecccccccccccceccceecccccec~ccceccccccccccccccccccccc C Global v a r i a b l e s :
INCLUDE
XIO,ALLf
C Passed variables: INTEGER MUNXT
ioutput u n i t speciZler (input) !nu&er of l i n e s p r i n t e d s o f a r ( I / O ) limpact parameter (input) ! r a d i u s o f c l o s e s t approach ( i n p u t ) ! s c a t t e r i n g angle(input1
INTEGER NLINES REAL B REAL RMIM a& ANGLE
ccccccccccccccCcccccccccceeccccccccccccccceccccccccccccccccccccc~ccccccc C
I f screen i s f u l l , c l e a r screen and r e t g p headings PF 4 (MOD (HLINES, mMLIN-4) EQ. 0) + .AND. (MUNIT ,EQ. QUNfTfl THEN CALL PAUSE tt o c o t i n u e , @,,l) CALL CLEm MRITE (MUNIT, 31) FJRITE (MUNIT, 3 2 ) WRITE (MUMfT, 3 3 ) NLIMESSm3 END I F
. ..
C
VIfRITE (MUNIT, 35 f B, RMIM, AhlGLE C
C
keep t r a c k o f p r i n t e d l i n e s o n l y f o r t e r d n a l o u t p u t I F (MUNIT .EQ. OUNTT) NLXNES=NLINES+I
C
31 32 33 35 C
F O W T f %5X,qnpaact r , 1 4 X , C l o s e s t 8 , 16X, I S c a t t e r i n g r ) F O m T 113X, ' P a r a m e t e r t I 13X, #Approach117X, @Angle@ 1 P O m T (13X, ' ---------' ,13~,t-------"?X,"-1
FOMT =TURN
(15X,F6.3,15XtF6.3,
15XIF9.3f
END GCCCCCCCCCCCCCCGC@CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCI:CCCCCCCCCCCC
SUBROUTINE GRFOUT(D&VICE,AHGLE,fWAeT) C g r a p h s s c a t t e r i n g a n g l e vs, Impact p a r a m e t e r ~CCCCCCCCCCCCCCGCCGCCCCCCCCCCCCCCCC:@CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C Global v a r i a b l e s INCLUDE 'I0,ALLf
INCLUDE
'GRFDAT .ALLf
C Input variables:
INTEGER DEVICE R m L ANGLE (O:MZ1X) RE& IWACT f 0 :M X J C Local v a r i a b l e s INmGER ZB C N m C T E R * 9 CE ,CR INTEGER LEN, RLEN INTEGER SCREEN INTEGER PAPER INTEGER FILE
!which device i s being u s e d ? ! f i n a l s c a t t e r i n g angle !impact p a r a m e t e r !index an impact p a r a m e t e r !energy, R M X a s a c h a r a c t e r s t r i n g !length of s t r i n g !send t o t e r m i n a l !make a hardcopy !send t o a f i l e
DATA SCREEN,PAPER,FILE/1,2,3/ f"CCCCCCCCCCCCCCGCCCGCCCCGCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC~CCCCCCC
C
messages f o r t h e i m p a t i e n t I F (DEVICE .ME. SCREEN) m I T E (QUNIT,I@O)
C
G
calculate p a r a m t e r s f o r g r a p h i n g I F (DEVICE .NE. FILE) THEN
C
NPLOT=3 IPLOT=l
!how many p l o t s ?
YmXmO. YWIM-0. DO 20 IBmO, NB-1 IF (AKGLE (TB) IF (ANGLE( IB)
tfind l i m i t s on d a t a p o i n t s
c
. , YmX) (IB) .LT. YNINl VMTN=ANGZpe (XBl GT
UW=ANGU
CQNTIMUE XWIN=BMTIJ XM=BrnX
VOVAL=BMIM XOV&L=O.
! l i n e and sy&ol
CALL C O W T (E,CE ,ZEN I CALL COWRT (=X, CR, RLEN 1
styles
{ t i t l e s and l a b e l s
I N F O o ' m X = '//CR(l:RmWI TITLE = ' S c a t t e r i n g f r o m 5-12 p o t e n t i a l , Energy='//CE LABEL (1)a 'Tmpaet p a r a m e t e r ( s c a l e d u n i t s ) ' LAWL f 21 = 'S c a t t e r i n g a n g l e ( d e g r e e s 1 '
CALL GTDEV (DEVICE) I F [DEVICE .EQ. SCREEN) CALL GEvlODE CALL LHLNAX END I F C C
!device n o m i n a t i o n ! c h a n g e t o g r a p h i c s mode
!draw axes
output r e s u l t s I F (DEVICE .EQ. FILE] THEN WRXTE (GUNXT,70) (XNPACT(IB),ANGLE(LBf ,IB=1,PJ£3~
ELSE CALL XVP LOT ( IWBCT, ANGLE
END I F
c C
end graphing session I F (DEVICE .MX?. FILE) CALL GPAGE(DEVECE) XF (DEVICE .EQ. SaEEM) CALL TMODE
!close graphing package ! s w i t c h t o text mode
c 70 IQ0 C
F O M T ( 2 (5X, E 1 1 -31 1 P O W T (/, ' P a t f e n c e , please; o u t p u t g o i n g t o a f i l e . ' 1
RETURN END CCCCCCGCCCCCCCCCCCCCCCCCC~CCCCGCCCCCCGCCCCCGCCCCCCC~CCGCCCCGCGGI=CCCCGC~C
cec~ccecccccccccc~ccccccc~ccccccccccccccC:cecccceccccccec~cc~cccccccccecc C param.pl C REU PI REAL E m A L BNIN MAL B= REAL R W =&L TOLR INTEGER NB TNmGER NPTS RDT3 XNmGER =X
..,......
! pim3.14159 ! i n c i d e n t energy i n u n i t s o f V z e ~ o ! minimum i m p a c t p a r a m e t e r
! maximum I m p a c t p a r a m e t e r ! r a d i u s a t which V<<E I tolerance for turning point search ! n u d a r o f s t e p s i n £3 ! n u h e r of w a d r a t u r e p o i n t s I size of s t e p s i n B !max number o f B v a l u e s
e PAWmTER fmX=1001 C
COMaN COWON COMON COMON
/ / / /
CONST / PI PPAMM / E, BMIN, 8 m X HP&/ NB, R m X , TOLR,NPTS PCALC / DB
ececccccccc~ccccccCcC:cecccccccceccccccecccccc~~ccc~ccc~cccccccccccecccec cccc~cccccccccceccecc~cec~ccccccc~ccccccc~ccccccccccccccccccc~ccccc~cc~c C map.pl INTEGER I E , f BMIN, IBmX, INB, T R m , TNPTS*ITOLR e a m m T E R (re -13)
P A W E T E R (IBMXN 114) PAMMETER ( I B M X =l51 P W M e T E R (1NB =l&] PAMMETER (ITOLR 538) P m M E T E R (IRMAX =39) PAMMETER (ZNPTS m401
42.2 Project 2 Algorithm This program constructs a series of white dwarf models for a specified electron fraction m with central densities ranging in equal logarithmic steps between the values of RH@^ and RHQZ specified. For each model (DO loop 20 in subroutine ir~c~oar),the dimensionless equations (11.18) for the mass and density are integrated by the fourth order . empiricdy scaled radial Runge-Kutt a algorithm (subroutine R ~ G E ) An step DR is used for each model, and initid conditions for the integration are determined by a Taylor expansion of the differential equations about r = 0 (beginning of the same DO loop). Integration proceeds until the density has fallen below 103 gm emm3.In addition, the contributions to the internal and gravitational energies are calculated at each radial step (subroutine I~TCRT).The radial derivatives of the mass and density are defined in function routine DEIR~;;the derivative of pressure with respect to density is defined in function routine okann; and the integrand for tbe kinetic is defined in function routine EPSWO. Input The physical parameters include the electron fraction [l.],the central density for the first model [1.OE+05], the central density for the last model [I.OE+ll], and the number of models to calculate [4.] The progrms checks that the initid density is s m d e r than the final density, There are no mnterical paslzbnneters: the step size is a fixed function of the central density* Output; As each model is cdeulated, the radid step, central densit& number of stegs, totd rrtdius, total mus, kimtie enero, gravitatiartal enera, afld total tsnergy for the model are displayed, Densities are in per cubic centimeter, e n e r g is in ergs, &stances in ~f?ntimeters, and mass in grams. After all of the models are integrated, the graphics displays two plots, The first is the totd mws o-f the rnadefs vs. the central density; the second i s the density vs, radius for e x h model. CGCCCCCCCGcCCCCCeCCCCCCcCCeCcCcCCCCGcCeCcCCCCCc~CccCccc~ccCcGcccc~ccCccC
PROGMM PROJ2 Project 2: The structure of white dwarf s t a r s e c o n P v T A r r o H A L PHYSICS { F a R r R a H w~s~oru) C by Steven E, Koonin and Dawn C. Meredith G Copyright 1989, Addison-Wesley Publishing Company CCCCGGCCCCCeCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCGCCCCCCGCCGCCCCCCCCCCGCCCG GALL INIT !display header screen, setup parameters 5 COEITXZNUE !main loop; execute once for each set of param GALL PAMM !get input parameters CALL WRCNQNI !calculate density, mass and radius of stars C
422
C. Pmgrams for the Projects GOTO 5 END GCCCC~CGCCCC~CCCICCCC~CCCCCCCG~CCCCC:CGCCCCCCCC~CCCCG~CCC~~C~CC~~C~CC
SUBROUTINE ARCHON C calculate the ntasslr), densityfr) for a range of central densities
cccc~eee~cc~~cccccccccccec~e~cc~cccccccccccecccc~cecc~cccccec C Global variables: INCLUDE "0*WLL6 TNCLUDE 'PAMM.P2' C Lacal variables: W A L MSTOR (mXMBD) !mass of star REAL RADIUS (mXMOD) !radius of star m& STEP ( M M B D f ?step size REAL RMIU (WXMOD) !starting radius INTEGER NSTEP (MZImOD) lnunrbsr of radial steps -L REIOSTR tmXMOD, O:mXSTPl !&nsity (r) of star INTEGER SMODEL !index of current model INTEGER NLINES lnunber a f lines printed aut RE& tvlc RHO !current mass and density REaZ R ? current radius IZR !radial step RE= E G B V !gravitational energy o f star RE= EKZNT ?kinetic energy o f star W A L EXFOMT ! t e w o r a r y exponent REAL RROGEN !central density for this model !nu&er of radial steps IMTEGER IR INTEGER DEVICE ! current graphing device fsend to terminal INTEGER SCmEN !make a bardcopy XNTEGER PAPER INTEGER FILE Isend to a file C Functions: !dPressure/dDensity REAL GAMlulll DATA S C R E & N , P W P E R , E I ~ / 1 , ~ ~ececcccccc~eccCcccccecccecccccceececcecceccc~ecccececcc~ccccecc~c~c~cc C output sumary of parameters IF (TTEW) CALL PEtIVIQUT (OUNIT,HLINES) IF [TFTLE) CALL PFi?MOUT(TUNIT,NLLN&S) IF (GFTLE) CALL PMOUT (GUNIT,NLINES) C
33ioop over aaneral den&
BQ 20 I@ODEW%, W D Z 3 b
C C
C
oalmaatr oanttal hnsity !rppadng htoossem 4-B = FL / P( L mQaB= (=@%/MW) * f (Wa2/mQX)*+mQmjf mwa on log soale DEW ( (3.0*0,00?L/mmHj** (1.813.0) ) 1 3 . 0 R=BR/l0 (f MOD=) =R*R0/11).E+08 (XMODm)=BR%@ 12.0. E+O8
.
C C
I ra&aT, sdep Ibsgin ad finite radius l a d e i n g raausr ? s t q size
uas TayZot ezpaneion to abtain initial con&kfont~ lfnitial mar& M= (R**3. O) * (MWH13 0 )
.
i n i t i o 2 density ~~~~ER*(l-~Q~H*R**2.0/5.0/
C
( m D B L , 0 ) ==o*m00
G
graCsl aqluafienr and find energies, raairara, and radiulrl @F @tar XBFaT (M,=a, R, DR, E-V, mXWrP, XMODELIIR,mOS1:Rj
C C
!cave values f o r graph
MSTaR (IMODEL)=M*M0/1Q.1&+33 m X Q S(XMQDEL)m~*R0/10. E+08 N S m (IMODBZ)=XR C -C
I F (TTERPII) ! t e x t output CALL TXTOUT [OUNIT,NLINES~ R, H, DR, RMocEN,ERINT,EGmV,IRI
+
IF (TFILE) CALL TXTOUT(TUNIT,NLTUES,R,H,DR~RNOCEN,EKINT~ECRAV~IR~
C
20
CONTINUE
c IF f TTERMf CALL PAUSE ( @t o e o n t i n u e XP (TTERN) CALL CLEAR
... ,I C
)
C
e
graphics output
ZF (GTERZJI) CALL GWOUT f SCmEN,MSTOR, EVLDS US, STEP,RMXN, NSTEP ,RHOSTR) f F (C;f"PLEf CALL G E O V T (FILE,MSTOR, M D 1US, STEP,WIN, NSTEP,RHOSTR} IF [GRRDCP) CALL GRFOUT (PkPER,MSTOR, MDIUS,STEPCRNThT, WSTEP,RWOSTR)
C
RETURN END cecccccccCcCcceccceE:cccccccccccecccecccccccecccccccccecccccccccc~ccceCcc SUBROUTINE INTGRT (M,RHO, R, DR,EGMV, EKIHT,XP40DBLeTR,RHOSTR) C i n t e g r a t e s mass and d e n s i t y b e g i n n i n g with N a n d RHO a t r a d i u s R; C c a l c u l a t e s g r a v i t a t i o n a l and k i n e t i c e n e r g i e s
ccccceccccccccceccccecccccecccccccccc~cccccccccccccccccc C Global v a r i a b l e s :
INCLUDE TAmN.PZ" C Passed variables:
mAL RMOSTR (mXMOD,0:MWXSTPl ! d e n s i t y (rl o f s t a r t o u t p u t ) INTEGER IMODEL ! i n d e x of c u r r e n t model ( i n p u t ) REAL M, RHO ! c u r r e n t mass and d e n s i t y ( I l O f =At, R !c u r r e n t r a d i u s f T / O ) REAL DR !r a d i a l step ( I n p u t 1 REAL EGMV ! g r a v i t a t i o n a l e n e r g y of s t a r ( o u t p u t ) REAL ERlNT ! k i n e t i c e n e r g y of s t a r ( o u t p u t ) INTEGER ZR !current l a t t i c e point (output) C Function: REAL EfSRWO ifunction i n energy d e n s i t y
cccccce~~cc~ceccc~eccccecccccccccccccc~ec~ccccccccecec~cec~ccccccccccccc 0.0 !zero smrs 0.0
ER=@ ZzP ( (lR -LT. =S=)
XR=XR+l
.XBD.
( m 0 .GP. MQCUT) ) t u w e e raaal fn & a
!take a Rmge-Katta step !avoid 8-22 hn@iCi@a~ =OS= (XMODEL, XR) = M Q * m 0 0 !save vauea far gzaphirtg $WV=mmV+M-Q*R !cenkrmtlen +a enexw intag. ERXH~~ZH%+R**Z*~SW0{REIO**r(31./3.]) GOIN) 50 €%L% RWm {M,M O cR, DR) XF (m0.L%. M-WOCTJI
mm112")
Ern XE" L-Vm-EWV*DR*ZdO maF=mxMIC*m*EQ RETURN
Imsc&Z@de n e ~ g i e ~ ~
END
ccccccccccccccccccccccccccccccccc~ccccccccccccccccccccccccccccccccccc SUBROUTXNE RUMGE (M,RHO, R, DR) C take a Runge-Kutta step to integrate m s s and density
cccecccccccccc~c~ccccccccccccccccccceccccccccc~ccccccccccccccccccccccccc G Passed variables:
REAL M, RNQ
!currant mass and density (I/Q) tcusrent radius (input) !radial step f input)
W& R REAL I3R C
Local variables: RE& DMDR, DRHQDR m u KIM,KbRMO REAL K2M, R2RNO m A I , B JM, K3RBO REAL K483, K4RWQ
!radial derivatives of mass and dens lintexmediate increments of mss and I density
cccccccccccccccccccecccccccccecccccccecccccccccccccccccccccccccccccccccc DEW (M, MQ, R, D m R , DWQDR) !&=late M B mmDR*DmR KXW*DR*DmODR
C
i oaXdak%U " a
R=R+DR[2.0 M*. 5*ltSXM 0 ,R, DmR, DrnODR]
E2=05DR*WQDR
C !c a d a t e kSf s S* (K2M-XlHf S* ( I S m 0 - K T M O ) D- {M*m0, R* DmBe DrnQDR] R3MBR*DmR R3m+DR*Dm0DR
M=*.
=+MW.
C E=R+BR/2.0 M=WK3M-.5*82M
D-
!calculs&e k4' @
{M,RHO,R, D m R , DmODR)
ltS4mDR*DWR K4=Q=DR*DMODR
C C
~ n d dcnrAty at; new rcraius M=M-I(~M+(~M+~.~*~M+~.o*K~M+~~SQM]/~.O v;orZusra: sf! =ss
w - ~ Q - K ~ ~( K WX W W 2 . 0 * ~ ~ 0 + 2 . 0 * A 3 m O S K 4 ~/g. 0)
c MTURW END
cccccccccccccccccccccccccecccccccccccccccccccccccccccccccccccccccccccccc SrnROUTINE DERS (M,RHO, R, DNDR, DRMODRf C c a l c u l a t e t h e d e r i v a t i v e s of mass and d e n s i t y w i t h r e s p e c t t o r a d i u s
~c~~e~ccccc~cccccccccccccccecccccccccccccccccccccccccccccceccceccccccccc C Passed variables: =&L MIRE0 MU R m u DmR, DRHQDR C Functions m= GMW
!current mass and d e n s i t y ( i n p u t ) !c u r r e n t r a d i u s ( i n p u t ) ! r a d i a l d e r i v a t i v e s o f mass and d e n s ( o u t p u t )
!dPressure/dDenslty
cceccccccccccccccccccccccccccccecccccccccccccccccecccccccecccccccccccccc IF (RN0 .GT. 0.0) THEN !avoid d i v i s i o n by z e r o (m~**(r.ot3.a11) D ~ O D R = - M * ~ O (/ (R**2)* DWR= (R**2)*m0 END IF rnlllfRtJ END
cecccccccccccccccceccceccccccccccccccccccccccccccccccccccecccccccccccccc M&
FUHCTIOM G A m ( X )
C d e r i v a t i v e of p r e s s u r e w i t h r e s p e c t t a d e n s i t y
cccceccccccceccccceccccccccccccccccccccccccccccccccccccccccccccccccccccc G Passed variables: !cubed r o o t of d e n s i t y
*x/a. o l s a z (x*xcr 1 END
cccccccccccccccccccccceccccccccccceccecccecccccccccccccccccccccccccccccc RE& FUNCTION EPSRHO [X) C f u n c t i o n needsd i n t b a c a l c u l a t i o n of t h e energy
cccccccccceccccCcccccccccccccccccecccccccccccccccccccccccccccccccccccccc C Passed variables:
m= C
!cubed r o o t of d e n s i t y
X
Local v a r i a b l e s :
M A L PARTI,E"ART2 !terms i n t h e f u n c t i o n GCCCCCCCCCCCCCCCCCCCGCCGCCCCCCCGCCCCCCCC~CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC EmTZmX* (1.O+Z .0*X**2)*BmT (2. Q+X**2) P M T 2 = m (X+SrnT (%.O+X**2) ) ==WO. 3751 ( ~ ~ n - ~ m r 2 ) END
cccccccc~ccccecccccccccccccccccccccccccecccccecccccccccccccccccccccccccc SUBRQUTINE INIT C i n i t i a l i z e s constants, d i s p l a y s header screen,
C i n i t i a l i z e s a r r a y s f o r input parameters
c~ccc~cccccccccccc~ccccccccccccccccccccccccccecccccccccceccccccccccccccc C Global v a r i a b l e s : INCLUDE * 10. ALL'
fWCLUDE
INCLUDE
'MENU. ALL'
' PARAM,PZ"
C Local parameters:
426
C. Progrranzs for the Prajeets !program d e s c r i p t i o n DXmMSXON DESCRP ( 2 2 1 IMWGER NNEAD,NTEXT,NGRF
!nu&er
af l i n e s f o r e a c h d e s c r i p t i o n
cGcccccccccccecccececccccccccccccccccccccccecccccccc~cccccccccccccccccct !get e n v i r o n m n t p a r a m e t e r s
GALL SETUP
C
d i s p l a y header s c r e e n DESGIZP (11= 'OROS&CT 2' DESCRPf2)- cThe s t r u c t u r e o f white dwarf s t a r s " NHEAD=2
e C
text o u t p t description
DESCRP ( 3 ) = ?mass, radius, and energy o f e a c h s t a r " NTEXT-I
G C
C
C G
graphics output description DESCRP(4)- "tataf mass vs, f i n a l r a d i u s f o r a l l models' DESCRP ( 5 ) ' d e n s i t y vs. r a d i u s f o r e a c h made18 NGW=2
-
CALL HEADER (DESCW ,XJWEAD, PJTEXT ,NC;RE"I calculate constants MEORMn = 1./1836.
C C
s e t u p menu CALL MENU
! s e t u p c o n s t a n t part of menu
c WmPT(4)='2)
( n o t used)
c NTWE (13 f =FLOAT M e m T (131 = EnRte e l e c t r o n f r a c t i o n , YEC MTAG (13)= ' E l e c t r o n f r a ~ t i ~ nYE1 ,
MLQLIM(l3)-"001 MBILIN f13)=10, mBLS (13)=1. Q C
N T e E (14 ) =FLOAT W W T (14)= "nntsr c e n t r a l d e n s i t y (gm/cmA3) f o r t h e f i r s t model' MTAG f14)= ' X n i t i a l c e n t r a l d e n s i t y (gm/cmA3)*
NLOLTM ( 2 4 ) =1 .E5 MNILTM(L4)-1.E15 mmLS (14)=l.E5 C MTYPE (l5I =FLOAT
W M B T ( l 5 ) = "nter c e n t r a l d e n s i t y (gmlcmA3f f o r t h e l a s t modelf MTkG(IS)= 'PFiaal c e n t r a l d e n s i t y lgm/cnA3)" MLOLIM 115) -1 .E5 IVIWZLXM (2.5)=1.E15 (15)=l.Ell M-LS
e MTUPE ( 3.6) =NUM
M P W T (16)1 ' Enter t h e n u d e r of models t a c a l c u l a t e F quunzber a f mdeXs t o c a l c u l a t e " MLOLIM (161=l, MHILIM (161 -=MOD MINTS 416)4. MTZ(16)-
G M T S E (17 l =SKIP ~ E A L (171 S =35.
C MTYPE (36) =SKIP
m A L S (JG)=CSD. C
MSmNG(MINTS(75))- t p p r o j 2 . t ~ t " C
MTYPE (76) =SKIP mMLS (76)-80. C
MSTRMG tMTMTS(86)) = ? p r o j 2 . g r f t
e MTWE f 87) =SKIP NRmLS (871 =90. C
RETURN END
CccccccccccccccccccccccccccceecceececccccccccI:cccccccccccccccccccccccccc SOBROUTTHE P W M C g e t s p a r a m t e r s from s c r e e n C ends program on request
C closes old f i l e s C maps menu v a r i a b l e s t o program v a r i a b l e s C opens new f i l e s C! c a l c u l a t e s a l l d e r i v a t i v e parameters
ccccccccccccCcccccc~cccccccccccccccccccccccccccccceccceccecccccccccceccc C Global v a r i a b l e s :
INCLUDE 'm N O , ALLf IHaUDE ' XQ,ALL' INCLUDE * P A W . P 2 " IN~LUDE1 m ~ . ~ 2 t C Function:
? c o n v e r t s 1 and O t o t r u e and f a l s e
LOGICAL LOGCVT
cCcccccCICtCcccccccccceccecce~cecccccccccccccccccccccccccccccccccecccccccc C
g e t i n p u t from t e m i n a f CALL CLECALL ASK(1,fSTOPJ
c s t o p program i f requested
C
IF (NREALS[INAINI C C
.m.
STOP> CALL FINISH
c l o s e f i l e s I f necessary
+
IF ( T M M E .NE. NSTRNG (MINTS(ITNAMEW CALL FLCLOS (THAW, TUWIT) IF (GNRM .WE. MSTRNG [MINTS(TGNANE)) )
428
C, Progrrrnts for $he Pr~jects + C C G
CALL FLCLOS {GNAW, GUNIT)
set new parameter values physical and numerical: U E = W A L S ( IUE) RBOZ=NWALS ( IRNO1) R H 0 2 m M m L S f IRWQ2 ) NHODEL-MINTS (INMODL)
C
t e x t output
C
TTERM=LaGCVT(MXNTS(XTTERMj) TFILEmWGCVT (HINTS ( I T F I U 1 1 TNN-MSTRNG (MINTS (ITEaMEl f C C
graphics output GTERH=LOCCVT (MINTS [ZGTERM)) GHRDCPmLmCvT (MINTS(TGNRDI1 GFILE=L,~GCVT(MsNas (rC;Fxze) I GNME=MSTRNG (MINTS ( I G N m ) }
C C
open f i l e s I F ( T F I m ) CALL FWPEN (TNAm, TUNIT) IF (GFILB) c a L L F ~ P E ~N G N A G~ ~, T T ) f i f e s may have been renamed MSTRHG (MIWTS( I T H A M ) 1 =THAW MSTMC (MrWTs ( I G N ~= ~E ; N A ~
C
C
CALL PCWECK CALL C L M R
c c a l c u l a t e parameter dependent q u a n t i t i e s R0=?.72E+08*= laaZf1~c~f radiuo !@&in9 gltsrro MO*. 63E1+33*(=**2) ~W=97?)000./~ foealinq W r i t y E O m + m @ m * 9 * (M0/=+32) t scaling %Inex= ~~~=ZOtlO./WOO InearXy zero dmaiey
C
e mTUR'1\1 END
ccccccccceccc~cccccccccccccccccccccccccccceccccccccccccccccccccccccececc SUBROUTINE: PCHECK C
ensure t h a t RH02 < RN02
cc~~C~cCccccccccccceccecccccccc~eecccccceC:cccccccccccccecccccc~~ccccc~cc C Global paranteters: INCLUDE ' PPAMM. P2" INCLUDE ' =NU, ALLp INCLUDE ' IO.ALL* INCLUDE 'm ~~2.
cccccecccccccccccecccccceccccccccccccccccccccccccececccccccccccceccccecc 10
I F (RHO1 .GE. RH021 T m M m I T E (OUNIT,15) CALL ASK [ I R H o l , IRHQP 1
25
RWO1-lylREALS(IRWO1) RM62=MREALS (IRWQ2) GOTO 10 END IF FOmT + ("The initial density mst be smaller than the final densityCl RETURN END
cee~~c~cccccc~cccccccceccecccccccceccceccccccccccccecccccccccccccc~ccecc SUBROUTINE PRMOUT{WUNIT,NLINES] C outputs parameters to the specified unit
~ec~ce~eccccc~cccccccccc~cc~cecccC:ccccccececcccccceccccececcccecccecccce e Global variables IMCLUDE ' P m M . P 2 " INCLUDE C SO.ALLt C Passed variables INTEGER NUNIT INTEGER NLTNES
!unit nu&er for output (input1 !nu&er af lines written so far (X/O)
ccecccce~ccccccce~ccccceecccccccccccccceccc~cccccccccceccccccecccccccccc 1F (MUMIT .EQ. QUNIT) C&LL CLEAR
e m I T E (NUPJLT,PS)) m % T E (ErlUNST,21) WRITE (MUNIT,25) NMODEL m Z T E (MUPJIT,27) YE mITE (HUNIT,29) RRO1,RHO2 WRITE (MUNIT,1 9 ) C !headers for t e x t output only
fF (MUNIT .NE, GUNIT) THEN m I T E (MUNIT,31) WRITE (MUNIT,32) tVRXTE (MUNIT,33) END IF G
WLINES C 19 21
25 27 29 31
FOWT FOmT
+
FOmT FQMT FQmT
+
F O m T
+
FOWT
32
i
33 3-
=
9 ("1 ('
Output from project 2:
',
* The structure of white dwarf stars
')
MuntberoEm~d@1s=~,S3) (' Electron fraction YE= ',1PE9,3) ("Fist. central density=',lPE9.3, SX,VFinl central den~lty='~,lPE9.3) I3X,'Step" ,4X, 'Cent Den" I X , Mstepf,,3X, 8RadI~s8, SX,'Masst, 7X,'Kfn E\,CiX,'Grav E \ 7 X , ' T a t E') (*
(3X, "em 5X, m "
,4X, " r n / ~ m " - 3 ~ , 1X, @ ,
?X, 9X,
1QA51ergs
\,3XIr
',,4X,
@
cm
'1
',
F Q ~ T(3~,r----r,4~,*--------1,2~~r----- r , ,3~, L . . I SX," - - - F , 7X,@-----',6X,f * ' " 1 X , I ----' 1 -----m.
C
RETURN END
$30
C, Pmgrams for $fie Projects ccccccccccccceccccccccccccccf:ceccecc~ccccccccccccccceccceccccccceccccccc SUBROUTINE TXTOUT (MUNIT, NLXNEScR, M, DR, RROCEM, EKINT, EGMV8 I R ) C w r i t e s r e s u l t s f o r one model t o t h e r e q u e s t e d u n i t
cceeeecccccccccccccccccccccccccccccccccc~ccecccccccccccccccccccccccccccc C Global variables:
INCLUDE IO -ALLf INCLUDE * P P A M . PZ* C Input variables: INTEGER MUNIT XNmGBk! NLZNES REAL H, RHO R W RHOCEN
m=
Iunit t o which w e a r e w r i t i n g t n u a r of l i n e s p r i n t e d out ( 3 / 0 ) f e u r r a n t mass and d e n s i t y !central density t current radius !radial step ! g r a v i t a t i o n a l e n e r g y of s t a r ! k i n e t i c e n e r w of s t a r !nu&er o f r a d i a l steps
R I3R
RE& E G M V RE& ZKINT INmGER IR
e~~ccccccceeccecccccccccccccf:cccccccccccccccccccC:ccc~cecccccccccccc~eccc c ifs c r e e n f s f u l l , c l e a r s c r e e n and r e t y p e h e a d i n g s 3F ( (NOD (NLINES, TRMLIN-a
.EB.
01
.AHD. (MUNIT .EQ, OVNTTI THEN
i
CALL PAUSE(%o c o n t i n u a f ,,l) CALL CLEAR WRITE (MUMIT, 31 1 W I T E (MUNIT, 32) m 3 T E (MUNIT, 33) END I F
c C
write u n s c a l e d v a l u e s t o s c r e e n DRXRO1RMQCEN*RM00, 3% i R*RO,N*NO,EKINT,EGMV,EKINT+EGMV WRf TE (MUNTT, 35)
e keep track of p r i n t e d l i n e s o n l y f o r t e r m i n a l o u t p u t IF (NmIT .EQ. OUNIT) NLIMBS=MLZNES+1
C C
31
FQmT 1.
FQmT
32
1.
33 35
FQmT
+
FOWT
f 3 X , ~ S S t e p ~ , 4 X f T e e nDen~1X,~NNstepa,3X,~Rad4.usf, t SX, *Mass\ ?X, "in E t , SX, "rav E 1 l ? X , 'Tot Et ) (3X,C cm ?, ,4X,~gm/mh-3', IX, \3X,' cm ', 5Xtt gm gm, ?X, 9X, "QA% ergs ,4X, C *1 ,4X,' t *,IX,' I , 3 X , 1 ---...-.," t ( 3 X I '-----" sx, &-.,p "&, 1 6X, L...----@ ?X, L----ff (2 (1X,1PEBe2),2X,I4,3 (2XI1PE9.3) 2 (ZX, ZPElO-3)1
".-------
"
--m-.".
C
RETURN
END
~eceecc~~ccc~ccc~cccc~~cC~~~cc~~ccc~~ccccccccccccccccccccc~ccc~ SUBROUTINE GWOUTfDEVZCE,MSTOR,MDIUS,STEPIRMINfN5TEI",RHOSTR) 1) t o t a l mass v s . f i n a l r a d i u s of s t a r 2) d e n s i t y vs. r a d i u s
C o u t p u t s two p l o t s : C
ccceec~cCcccccccce~ccccccccecccccccccccccceecccecccccccccccccecccccccccc C Global v a r i a b l e s
SMCLUZZe 'X0.ALL8
INCLUDE 'PARAN, P2' INCLUDE 'GRFDAT .ALLp G Input variables: INTEGER DEVICE !which d e v i c e i s b e i n g u s e d ? REAL MSTOR (MaXMGDf !mass o f s t a r s RE& MDTUS ( W N O D ) !radius of s t a r s REAL STEP ( W M O D 1 !step size REAL RMIM (MAXMOB1 !starting radius INTEGER NSTEP(WXM0D) !nu&er o f r a d i a l s t e p s ! d e n s i t y ( r ) o f star REAL RHOSTR[MAXMQD,O:MSTP) e Local v a r i a b l e s ! r a d i u s a n d d e n s i t y for o n e model REAL R, DEN ! c u r r e n t model a n d r a d i u s INTEGER IM, I R DlmNSIOH R ( 0 :MAXSTP), DEN (0:msTp) ! r a d i u s and d e n s i t y CBWCTER* 9 GYE !electron fraction a s eharac s t r i n g !length of string INmEGER LEN INTEGER SCREEN !send t o t e r m i n a l INTEGER PAPER ?make a h a r d c o p y TNmGER FILE !send t o a f i f e DATA S C R E E N , P A P E R , F I L E / ~ , ~ /
~~~~~c~~~cc~ccc~cececcc"ccccccccececcccc~ecccccccccceccecccc~ccccccccc C
messages f o r t h e inrpatient I F (DEVICE .NE. S@W&N) M I T E (OUHIT.100)
G
C
C
d e f i n e p a r a m t e r s w h i c h are t h e same f o r b o t h g l a t s r r (aEvrcE .NE. FXLE) THEN NBLOT=2 !how many p l o t s ?
.
XNIN=Q VOVAL=O. G
IL1NE=1 ISYM=1 XFREQ=1 NXTICKm5 NV'P"ICK=5
! f i n e and sy&ol
styles
C
CALL C O m T (YE, CUE, ZEN) TITLE = ' W h i t e Dwarf S t a r s w i t h e l e c t r o n f r a c t i o n - @ / l / C Y E C
CALL GTDEV (DEVICE) I F (DEVICE .EQ. SCREEN) CALL GNODE END I F
!device nomination ! c h a n g e t o graphics node
C C
Do 20 IPLOT-1,NPLOT d e f i n e parameters w h i c h a r e d i f f e r e n t f o r each p l o t TF (DEVICE .NE, FILE) THEM I F (IFLOT .EQ. I f THEN YMIN-NSTOR [l) XOVAL-MSTDR (1)
xm=morvs (Il YMAX=HSTm (NMODEL)
432
C. Pmgmsnrs for the Projeds NPOINT=NMODEL LABEL (1)= "radius t 10**8 cm) ' L&BEL (2) = #mass (10**33 p) CALL LMLMAX ELSE XP(YLX=MBIUS ( 1) IImXmRX02 YMIN=RHOCUT*RHOO XOVU=RHOCUT*RWOQ IFWQ=O
LAB&L(I)= badfus f 1 0 * * 8 cm)" m E L ( 2 ) = "ensity tp*em** (-3)1 ' CALL LGLMAX END If END IF C C G
output results IF (IPLOT .EQ, 1) THEN total mass vs. final radius
IF (DWICE .EQ. FILE) I'MEFJ WRITE (EVNIT,80) WRITE [GUMIT, 70) (RADIUS(IN),MsTOR [IM),3:N=lIMMODEL~ ELSE GALL XVDLOT (RADIUS,NSTm) END IF G
ELSE C
30 20
denslty(r) vs. r for each model
DO 30 IM=1,NMQBEL NPOINT=NSTEP(IM)4-1 no 40 IR-Q,NPOINT-I R ( X R=RMIN ~ (IN)+rR*sTEP 4 1 ~ 1 nEH ( IR}=RHOSTR IM,INCQWTSNUE IF (DEVSCE .EQ. FILE) THEN WRITE (GUMIT,85) IM mXTE (GUNIT,701 (R I I R ) ,DEN (TR) ,IR=O,NPOINT) ELSE CALL XYPLOT (R, DEN) END IF CONTINUE END IF CONTINUE
C C
IPLOTmNPLOT end graphing session IF (DEVICE .NE. FILE) GALL GPAGE f DEVICE) eF (DEVICE .EQ. S W E N ) CALL TMODE
f end graphing package !switch to text made
C '70
80 85
F O m T (215X,E11e3)1 Fa-T ( I ,LOX,' radius', lOX,'mass' F O m T (/, Deensity vs. radius for model \ ,121
100
F O m T f/,@
Patience, please: output going to a file.@}
c MTURN END
~~ecc~~~cccccccccccccecccccccccccccccccccccc~ccccccccccccccccccccccccccc
~ C C C G C C ~ G ~ G ~ C C C C C C ~ ~ ~ C G ~ ~ C C ~ ~ C G C ~ ~ ~ C ~ ~ C ~ C ~ ~ ~ C C param.g2 C REAL M3eQRW !mass of electron over mass of pratan
m= YE =&L RHO1 M & L RA02 IWTEGER NMODEL REAL RO W A L MO WAS, RWOO
m A L E0 RE& RWOCUT INTEGER MAXSTP INTEGER M X M O D
!electron fraction !initial density ! final density fnudcr o f models to calculate !sealing radius !scaling mass !scaling density !scaling enerw Inearly zero density !array size for density !max number o f models
c P m M E T E R (WSTF=IQ00) P M m T E R (MAXMODa251
c G O m Q N / CQNST /MEORW C O m O N / PO&MM / VE,RXQI,RHOZ,NMODEL C Q M G N / PCALC / RO, WO, RWOD, EO ,RHOCUT
ccccccccccccccccecceeccecceccccccccccce:ccccceccececccecccccccceccccccccc cccecccecccecceccccccccccccccceccccceccecccecceccccceccccccccc~cC:ecccecc C
map,p2 TNTEGER IVE,ERHOL,fRWQ2,INMODr P A W E T E R (IUE =l31 P h W E T E R (SRN01 13.41 P m m T E R (SRN02 -3.5) P m M E T E R (INNQDL =I 6)
r Pr~jects 434 3. Programs f ~ %he
C.3 Project 3 Algorithm This grogram sdves the Bartree-Focb equations ia the R1ling appro~mationfor atomic systems tvith electrons in the Is, 29, and 2p shells. To be&n the iter&ive procedure? normdzed hydrogenie wave functions (subroutine BMRCR)and their energies (subroutine EIERGY) are calculated, the virid theorem is umd to det ne the variational parmetes ZSTAR,whieh is in tarn used to cafedate the aptimd scaled hydrogenie wa;ve functions and their energies. These wave functions serw as our init i d &e;uess". Then 'fOp each iteration requested the s i n e particle eigenvduc!equik tions (IE.28) are solved as inhomogeneous boundary value problems (subroutine saouw) using the single partide energies, electrostatic potential, and Fock terms cdculated from tht? pfevious wave functions. The homogeneous solutions are found using Numerov's method, and these solutions are then u s 4 to cafcalate the inhomogenmus aotutioxls usiag the Green's Eunction method. Care is t&en to ensure that the 28 orbital is arthogonal. to th& of the 1s. When the repest& iterations are completed, you can request more or allow the cdcdation to t e r ~ n a t e . Mu& of the computational eEod is in the cdedadion of the sinde particle energies (111.30) and totd energy (III.26,27) for each set of single partide wave functions (subroutine EBERGY). In subroutine SOVRCE the tot d electron dertsity is calculated as a weighted m r a g e of the current and previous densities, and the Fock terms (111.28 b,c) are evaluated using the trapezoid& rule for the integrals md the t h r e j symbds from subroutine SqmJ. The dectrostatic potentid due to the electrons is cdcdated in subroutine POIS~Ewhere the Numerov method is used to integrate Poissads equation (III.18), and the unwanted linear behavior is subtracted off. The remaining energy integrals are calculated in subroutine EWERCY using the trapezoidd rule. Input The physical parameters are the nuclear charge [G], and the occupations of the i s [2], 29 [2], and 2p [2] states. The numerical parameters are the ranlid step size (Angstroms) [.01], the outer radius (Angstroms) [2], and the initial number of iterations. The program checks that the totd number of radiaf, steps does not; excwd B I I X ~ P =2000; if it b e s , yau xe prompted for a larger fadid step.
Output After each iteration all of the single particle energies (Enetic, elearon-nudeus, electron-dectron, exchange, totd potentid, and total) are displayed for each occupied state, as well as the total for all states, Ml ener&es are in. electron v01tg. When iterations w e completed,
the graphics displays the partial and total electron densities as a function of r d i u s . cccccccCcccccccccccccccccccccccceccccccccccccccceccccecCcccccecccecccccc OROGmN P R O J 3
Wartraa-Pock solutions of s m l l atomic systems in the filling approximation COMPUTATICtNAL PHYSICS (FORTMN VERSZOM] C by Steven E. Moonin and Dawn C. Mereditk C Copyright 1989, Addisan-Wesley Publishing Company C C C
Project 3:
ceeccccccecccccccceccccccccccccccccccccccccc~ccceccccccccccccccccccccccc Idisplay header screen, setup parameters CONTINUE !main loop/ execute once for each set of param !get input from screen C"ALL P A M CALL ARCHOH !find the Hartree-Fock wave functions GOTO 5 EBB ccceccccccccccccccccccccecccccccccccccccccccccccccccccc~cccccccccccccccc SUBROUTINE ARCHOW C find the Nartree-Fock wave functions for the specified atom cccc~cccceccccccceccccccccccccccccccccccc.cccccc~cccecececcccceccc~c~cccc C Global variables: INCLUDE " 0 . ALL' INCLUDE * PARAM, P 3' C Local variables: !all energies o f all states REAL E (mXSTT+1,8f !Fock terms REAL FQGK 4 0 :M S m ,NXSTT 1 !density REAL RWO(0:MAXSTP) !radial wave function REAL PSTOR 4 O :mXSTP,MXSTT) REAL PHI:(0:NAXSTP) ! electran potent ial !single particle energy of state REAL ESP INTEGER XTER !iteration index !single particle state index INTEGER STATE m& Z S T m !optimal effective nuclear charge INWCER DEVICE !current grapking device INTEGER ISTOP,ISTART !current limits on iteration INTEGER MLINES Inu&er o f lines written te screen INTEGER SCREEN !send to terminal INTEGER PAPER !make a hardcopy INTEGER FILE !send ts a file C Functions XNEGER GETINT !integer screen input DATA SCREEN,PAPER,FILE/1,2,31 cccccccceccceecCecccccccccceececcecccccccccecccccccecccccccccccccccccccc C begin itazakiona wtlth a good p e a . EX=l. !no old denoitg t o d x witb new CALL I M X T
5
ZSTrnmZ
W D M R (%S%=, P S F m )
I
I find hydroqenlo wave funeelens
Z S T m using Virfaf theorcsm
(E(RBFATE+X,IWO'P]/ 42*E (NSPAPEileXKTQ2) 1 1 WltDWE (%SF=, PSTW) !find new hycfsogenSc wave f w c t i c n e
%SPm=-Z*
436
S. Programs for the Pvojects E m R m (B,B o a , EEC?, P a s , PSTOR)
1
and snrrzg%err-
C
!output s u m a r y I F (TTERM) CALL I F (TPILE) CALL I F (GFILE) CALL
o f parameters PmOUT (OUNIT, ZSTAR, N L I m S ] PRMOUT (TUNIT, ZSTAR, HLINESj PWOUT (GUNIT, ZSTAR, NLXHES)
C
! m i x old and new d e n s i t y Ear s t a b i l i t y !z e r o i t e r a t i o n c o u n t e r s
MIX==,5 I TEE= Q ISTARTSO Z STOP=O
c output i n i t i a l energies TF (TTERM) csLL TXTOUT (OUNIT, ITER, E, NLINES I I F ( T F T W ) CALL SXTOUT (TUNIS, ITER, EI NLIMESI
G
c 10
CQUTLNUE fSTAWT=ISTOP+l XSTQP=ISTOP+NTTER W)
!loop o v e r i t e r a t i o n s !update i t e r a t i o n counters
100 I m = Z S % m T , f STQP DO 50 ST&-1, f f p (NOCC(SF&=) .HIE. 0 ) ?.Loopever @a+ states tsin@e m ~ i a T a ,mnara ESE* (SZAZB, IPOT) IP ( U P .QT. O) ESP=-ZO !keep g r r t t i c i ~bunad part: wave 2uncrtion PHT) (STaTE,ESP,PSTGR,P-,
m CoBSImVI& colZaala%e saw eaergiss and output: (E,EQCK,=Q, PHI,BSTQR) I F (TTERM) CaLL TXTOUT (OUNIT, ITER, E, NLIEE51 I P (TFTLE) CALL TXTQUT (TUNIT, ITER, E, NLINES)
100
C8N3tXm
C C
a l l o w E a r more i t e r a t i o n s NITER-GETTNT f 0 , 0 , 2 0 , "Wsw many m a r e i t e r a t i o n s ? ' 1 TF (NITER .NE. 0 ) GOTO 10
C
I F (TTERM) CALL C U A R
C C
grrsphicsoutput I F (GTERM) CALL GWQUT (SCREEN, PSTOR, RHO, E 1 I F (GPXLE) CALL GWOUT (FILE, PSTOR,RHQ, E] I F f GXRDCP f CALL GWOUT (PAPER, PSTOR, RMO, E)
C
RETURN
END
cccccccecccccccccecccccccccccccccccccccccccccccccc~ccccccccccccccccccccc SUBROUTINE HYDRGN(ZSTWR,PSTORI C creates h y d t o g e n i c w a v e f u n c t i o n s PSTOR w i t h n u c l e a r c h a r g e = Z S T m
e~cccccccceccccCcCccceccccccccecccccceecccccceccecccccceccceTcccccccccccc C Glabal v a r i a b l e s :
C Input v a r i a b l e s : W a ZSTAR RE& PSTQR (0:M X S T P , W S T T I e Local v a r i a b l e s : INTEGER ER RE& RSTAR WEAL ERSTAR INTEGER STATE W& BOW
! e f f e c t i v e n u c l e a r charge ! r a d i a l wave f u n c t i o n !r a d i a l index !s c a l e d r a d i u s
!useful exponential ! s t a t e index !norm a f wave f u n c t i o n
~~c~~~ccc~lc~cccc~~c~c~ccc~:c~cecccccccccc~cc~cccccc~ccc~~ccc aes~azmU.of parks ef. hyd*.og.enAc nave functions C DO I rclaled
.
WEm/2 1
t umefuz
n%iaf
za ( N ~(2) C .m, 01 E S ~ C O (SR, E ~22 = R S ~ * W T ~ * XI!'
(SWC (2)
.m,
.
XE (BWC (3;) NIC. 20
O) 0)
PSTQR (XR,2) :.(2-=T=) . f R S m * m T m PSgQR (SIC, 3)= (MZm**2)*W%=
CaFXMm
G
e ZEi' (NWC (SPA=)
0)
TmB
MO-O DO 3Q X w O , W R
M@-%. I (sag [ H W * D R )1 DO 35. =m@,= Ps1Cm (332, smPE) =PsmR(m,SPATE] *HOW CQIPSIXI~
315
m
XB
C
mTURH
END CCCCCCGCCCCCCCCGCCCCCCeCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC~ SUBROUTINE ENERGY (E,POCK, RHO, PHI, PSTQRf C s u b r o u t i n e t o c a l c u l a t e t h e e n e r g i e s of a normalized C set of s i n g l e - p a r t i c l e wave f u n c t i o n s (PSTQR); C a l s o c a l c u l a t e s Fock terms, density, and e l e c t r o n p o t e n t i a l
eccccccccccCccCCcccccf:ccccC:ccccccccceccc~e~cccceccecccI:cccceecceccccf:c~c C Global v a r i a b l e s :
INCLUDE 'PARAM.P3' C Passed v a r i a b l e s : W& P S T O R ( O : W S T P , m X S T T ) ! r a d i a l wave f u n c t i o n ( i n p u t ) POCK ( 0 :mXSW, W S T T ) !Fock terms (cutput 1 mAL PM1 (Q:PIAXSTP) !electron potential (output) RE= RXQ O :m X S T P 1 !density (output) MAL E (WXSTT+3,8) ! a l l e n e r g i e s of a l l s t a t e s ( o u t p u t ) G Local v a r i a b l e s :
INTEGER STATE
! s t a t e index
438
3, Pr~gramsfar bhe Pmjeets !radial i n d e x
INTEGER IR INTEGER IE REAL R REAL LLZ
mm
!energy index !current radius
!square of angular momentum !values ta e a l c d(rho)/dr
I?M,OZ,PZZ
ccccccccc~cccccccc~cccccccccccceecccceececee~ccccccccecceccccccccccccccc !aaleulate Rook taan4 arnoity SOW= (PSPaR, F-, =Q) P O I S S ~(FEE, =a)
Icdc p t n C 1 dne to electlron ekargs
C
fzrru t o k s l maxg%am
DO 20 XE=XmR, I21o.T E (NS2&TE+f, IE) m0 20 C
eomxwf7E: DO 38 ST&m=%,NSam
rs
(EOCC~STA~B).m,0 )
C
W 10 SP=TmB,TTOT
!zero saaza Eor t h h state
E (SPATS, XL) =0 10 C
C a m f Elm LL%=MWW (S%&=)
* (VaQH (ST&rn) $1,)
PM=Q 130 48 X R = l , m
!integrate the enarw drtxzr~ftias
R==* BR BE=PSTQE(m,STATE) PZ2=PZ**2 ? kinrticr
loentri2uqal E (SPATE, XWH) =E (SZ&TE, m N ) -EZ2m !~L&@o--c~ E (STAgE, I-) =B (STAEE, I-) +PHI {IR} *F22 falea-else ) =%E (SE&=, E m ) +F= (ZR,S T a m ) *PZ !e x a b a p
?& t h fls a+a&a@o ~ o n t s i b u t f a nto %eta2 smszw DO 30 XE=mH, -X E (WsTAm+l, ZE) =E [W5Z1A~+ZIIZ) f E IE)*NOCC (SFA,trE)
CONPXNW
C
Ern
33'
C
!=%&ate
toLa2 mazgAes
0 (SF&=, I=$) =S [S==,
C C
~ totrf i& kinatio, ]~~)tmntiorl. and t a t r l ertexrgfso
a f sT&m, me%) =E (STArn,I m s )+E (SZPArn, fa w l E (STArn,m%=) =E (ST&ZZ, X m E )t E [S%&rn, =E) +E tsmm, = X ) E (S%&=, xzozl)=E (SF&=, mar1+E ( s z ~ ZTBT~ , c RETURN
END
C~ccccc~~ccccccc~cccccccc~cc~c~~c~cccc~cccc~~ccccccccccccccccccccccc SWROUTIME SOURCE (PSTOR, FOCR,RN01 C s u b r o u t i n e t o c o q u t e t h e d e n s i t y and t h e Fock t e r m s g i v e n PSTQR CCCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCCCCCCGCCCCCCCCCCGGCCCCCCCCCCCCCCCCCCC
C Global v a r i a b l e s : INCLUDE 'PAmM. P 3' C Passed variables:
RE=
PSTOR [O:MAXSTP, MXSTTI REAX; RWQ(O:mXSTPl =&L FOCK (O:WSTP,MAXSTTf C Local v a r i a b l e s : W% BE" REAL PAC INTEGER IR WAL R
! r a d i a l wave f u n e t i o n ( i n p u t ) !density fautputf !Fock terms ( o u t p u t f
l i n ~ r e n r s n t i n Fcck t e r m ! c o n s t a n t factor I n Fock t e r m ! r a d i a l index !current radius RUM !r**lat&da M A L RMM1 t re* f l a n b d a t L ) ! indexes s t a t e TWTEGER STATE IM'PEWR STATE2 !indexes second s t a t e in Fock t e r m RE& SUM !sum f o r Fock i n t e g r a l s TERM !teny>orary term f o r sum GER Lfi, L2 !angular momentum f o r two s t a t e s ! l i m i t s on sum of LltL2 INTEGER LSTART, LSTOP ! c u r r e n t v a l u e of ang mom sum INmCER M REAL TNREEJ l three j c a e f f i c i e n t CCCCCCC~CCGGCCCCCCCCGCCGCGCCCCGCCCCCCCCCCCCGCCCCCC~CCCCCCCCCCCCCCCCCCCCC DO 20 S1R..rT,m linaImb fractfan aL 03.4 dsnelty
{m}= 4% ' 20 C
* N O (ZR)
CQ1J"r
DO 30 SZ&ml,fQSmm X ( S ) 1
.
!loop we6 oompfsd 6tatolir
C
DO 4 0 m=X,lfnz M O (XR)-0
!eon%rfW%ion of tbis 6tat;e t o b n s i t y (XR]t m X * E a (S2&=) * (BSSCOR(XR,STAm) **2) P m (XI?.@BTAmf m0 I s;sra mCIC, CS=
5W=0
DC) 90
m m , 1,-3,
linwrrd InCaglzal for F o e
WXR*DR
s m (ZR,sTam) =
E m tzR* s
s-sm+mw
cmxm
90 C 50
!ad
low
ever 2-
EMD IE" 50
CONZIHa
fear3 reap mar rtaem2
EBB 3 3 tend toop over stake C RETURN
END
ccccccccccccceccccccccccceccecccccececcceeccccccecccccccccccccccccc~cccc SUBROUTINE POISSN[PWX,RBO) C subroutine to solve Poissan- sec_yuation f o r the direct potential C given the electron density RHO
cccccecceccccececcccccecececcccccccccccceccecccccccccceccL:cccceccccccccc C
Global variables:
INCLUDE rPAMM.P3' C Passed vaziables: REAL P N I ( O : M S T P )
!electron potential (output) !density (input)
REAL RHO ( O :mXSTP J C Local variables:
!useful constant !radial index !linear behaviar to subtract !radius !source terms !total charge
M U CON INWGER IR
W L M M& R
=L
SH,SP, 52 SUM
~ce~~e~ee~~~~~~~eeecc~~c~ec~~ec~c~cccccccec~ccccccc iqa&a%uru of! &arri%g t o p t : 1 l a i t f rl wag2or P m (11
Cl. M)
l.9
19
+c
l.,=
CWXNm
C
CON
Ilaftial
DR**2/12
V ~ W Bfor -@W&&
in%w
C
*ss 29 C
SZ=S CmTN'IJE
( P1 I l /R DO 39 3R=Z,N]6t R=I]a*DB B= (XRZ = P m (XR)/R-H 39 e
)
f r ~ k r r o 0 ;of 8
If n r u bbrvior
t i a e o r of! %/X for t
c m z m RETURN END
ecececceccccccccccccccccececcecccccecccecccecccceccccccccccccccccccccccc SUBROUTINE SNGWN f STATE,E,PSTOR,FOCKi) PWT 1 C subroutine to salve the singfa-particle wave function as an C inhsmogeneous boundary-value problem for a given state, energy E, C source term (POCK), and potential (PWZ)
CcCcccecccc~cecec~ccccecceccccccccecccccceeccccccccceeccccC:ccceeccccecce C Global variables: INCLUDE 'PWN,PJ* C Passed variables:
INTEGER STATE WAli, E
REAL FOCB (O:MBXSTP,mXSTT) REAL PHI (0:MAXSTP)
REAL PSTBR(O:MXSTP,mXSTIIf
!which singfe particZe state finput) !single particle enerw (input) !Pock terms (input) ?electran potential finput) !radial wave function foutputf
442
3. P~ograntsf:or the Pmjects C Lacal variables: REAL PSfIN(O:MSTP),PSIOUT(O:~XSWl !homogeneous salutions INmGER NRZ !midpoint for the lattice LL1 !angular momentum REAL DRHElPl !useful constant
m& K2M, K2Z,K2P
?local nave numbers !normalization REAL R !currant radius SUN !sum far integration REAL 91Em !tamp term in integration =At m O N !Wronskian at ~ d d l eof lattice INTEGER ZR !radial index CCCCCCGCCGG~CCCCCCGGCGCCCCCCCCCCCCCGCCCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC =At
c
NORM
U l M a O M (STAEE)* (==OM
t use
(SF&=) +2
12
PSXQgT (l)=l,@E-%Q DO 49 Xm2,m
aszau~(m-2)* (z+x~M)) / ( I + X K ~ P ~
4
AZB=K2Z
!roll va&ues
mXmK2P
49
eamxm
G
?fnke@zae~t ?Lnwad bemgamouri B O ~ R
R2PmranO
* (E-P= (m-2)+ (ZC PSXXt-4(m)=O ESXXE (=-l 1 OE-30 80 59 ==m-2,1, -1 S
(E-PHI(m)+ (2 (asrxg(IR+~) *
3.
mBe2B
ESZZI (ZR+2)* (3+X:2E>1 / (1+A2Mj ?roll ualuersc
K28=X%M S9
eamxm
C
ISronrtkian at a t f W e of msh
===l2
mo~= (Psrnsr( ~ P + I-PSIXI ) ( m - % )) 1 (~*DR] *PSZB~T (m) mm-a~- (nsxavrc( m + % )-psrarr%(m-%) f 1 (Z*BR)*PSZXI(m21 C
S=-@ DO 69
!oudwwd fnteqzal in Cmenps soln Wa
-nszouT (a) *PSW=SWTrn
(XR,STATE)I2
~srm (rR, s m ~=ESXII ~ j (XRI*SW*OIZ
s-sw+ 69
CQmmVE
C
tinwrzd inestgra% in Oraenb edla S W 0 DO 79 XR=rn,X,-11 (ZR,SmTE) / a -PSffN (XR) smsm+mm PsTOR (ZR,S-=] = (PsTm (XR,STA.ZEj+PSXQR {XR] *SUM*DR)/=OH
sm=sm+ 79 C
COrnfErn 23' (SF&=
fkew 1s and 2n
.Ea. 2 ) "rEOZN
o*hagmaI
SW=@ M)
89 ZR=I,MR SW=SW+PSTa
(m,1)*PSToR [m,2 )
COmXm
89
SW=SW*BR
DO 99 XR=X,rn !l? f ZR, € 2) % =PSTQR , (m,2)-SW*IeSTrn f IR,1)
99
EMD fzf C:
Horn* DO 118 X-1, HR BQM=B0m+PSP= 18
(m,SF&=) **%
CWTEm
EX? 28 ZR=Z,m
PSWR ( z ~smm) , 28
(ZR,
s ~ ~ *HOW mj
C
C
=TURN END
cccccc~cccccec~ccccccccccccccc~cecccccccccccce~ccceccccccccecccecccccccc SUBROUTINE SQR3J(L1,L2,M&,TWREEJ) C
subroutine to calculate square of the 3-3 coefficient a m a r i n g i n t h e exchange energy
ccccccccccccccc~c~cccc~ccccccccccccccccccccccccccceecccceccccccccccccccc G Global variables: INCLUDE VmM. P3' C Passed variables: INmEER Cl, L2, M mAX,
!angular momentum (input) !three -j coefficient (out&tutf
INTEGER ZmX, P
!intermediate t e r m for calc of 3 J ?useful co&fnatians a f ang mom
ITWREEJ C Lacal variabl es: Wdll, DELTA
c~~ccccecccccccececcccececccceccecccceccecccccceccccccceceec~ceceecccec~ Xm=LZ+X12+W+X
!uaefa11 oo&fnatfons
P= (LL+&2+U)f 2 G DE&Fk=E&CPm(XIX+L2--) *F&C%& (-L1+L2+W) DE&FA=DBLZ&*EACXm [XI%-L2+Uj/F=(X=)
!tm valaas
444
8. P~agranzsfor the Pwjects @AC-
(P)**?l
e RETURN
END
ccc~cccccccccceccccec~ccccce~ccccccccceecccccc~cceeccc~ccec~cccc~ccccc SUBRQUSINE IMIT C I n i t i a l i z e s constants, d i s p l a y s header screen, C i n i t i a l i z e s a r r a y s for input parameters ~~CCCCCC"CCCCCGCCCCeCCeCCccCGCcCGcecCCCCcCeGcecCCcCCCCCCCCCcCCcccCcCccCcC C Global v a r i a b l e s :
INCLUDE ' IQ .ALLr XNCLUBE * MENU. ALL" INCLUDE 'PAMM.P3" C Local p a r a m e t e r s :
{program d e s c r i p t i o n
C H W C T E R X 8 0 DESCRP
DIWNSXOmJ DESCRP (20) XNTEGER NWEAD,NFEXT,NGWH
!number o f l i n e s f o r e a c h d e s c r i p t i o n INTEGER I !index f o r f a c t o r i a l loop CCCCCCCCCCCCCCCGCCCCCCCCCCCCCCCCCCCeCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCCCCCCC CALL SETUP ! g e t (environment p a r a m e t e r s
e C
display header screen BESCRP(1)- "PRO;PEGT 3 I BESCRP (2) Hartree-Fock s o l u t i o n s of s m a l l a t o m i c s y s t e m s f DESCRP(3)- ' i n t h e f i l l i n g approximation'
-
NHCIEAB.-3
C
C
t e x t output description DESCW ( 4 ) -"kinetic, potenti a l + //V(eleetron-nucleus, e l e c t r a n - e l e c t r o n , * BESCRP(S)= t e e x c k a n ~and t o t a l ) and t o t a l . e n e r g f o r e a c h s t a t e " @
NTEXTs2 C
C
graphics output description DESCRP(6f= e e f e e t r o n p r o b a b i l i t y d e n s i t y f o r e a c h s t a t e f P3GmPW-1
G
GALL READER(DESCW,NWEAD,NTEXT,NGRAPW) C C
calculate constants ?atomic constants
HBmM-7.635 9 CMGE-14.409
!hbar*2/ (mssf
ABOWR=NBARM/CWARGE
!charge of t h e e l e c t r o n !Bohr r a d i u s
NSTFLTEmMXSTT
! d e s c r i p t i o n s of s t a t e s
C ANGMOM (11 -0 ANGMOM I 21 =C?
-
ANGMOH ( 31 1
IO(l)="IS
'
ID(2)m' 2S F I D ( 3 f=' 22P ' I D f 41 =' TOTAL" !f a c t o r i a l s FAGTRL f O 1 =l DO 10 I=1,10 FACTRL f P) =TXFACTRLf 1-11 CONTINUE
s e t u p menu a r r a y s CALL =NU
f setup canstant part of
menu
MTWE ( 1 31 =FmAT E/IPWT (13) = E n t e r n u c l e a r charge1 MTAG (13) f N u c l e a r c h a r g e ' MLOLZM 113) -1. MWfLIM(13)=20. mEALS f 13)=G. MTWE ( 141=NUM W W T (3.4) = @Enter nu&z o f e l e c t r o n s i n the 1s s l a t e p MTAG (14 ) = eOccupatlon oE Is s t a t e r MLOLIM(l4f-0. MMTLTM I141 =2. MINTS (14)mZ. MTYOE (15)=NUM MPWT115)- ' E n t e r n u d e r of e l e c t r o n s i n t h e 2s s t a t e f NTAG(1S)- W e c u p a t i o n of 2 s a t a t e t MLoLrn (lsj=a. NWILIM (15)- 2 . MINTS [ l 5 1 -2. MTMtE (3.G ) -NUM M P W T ( l 6 ) = I E n t e r n u d r o f e l e c t r o n s i n t h e 2g statef MTAG(16)- W c c u p a t i o n o f 2 p s t a t e r ML6LXM (161-0, HNILIM (3.6)= 6 , MINTS (161 -2.
MTUPE [ 381 -FLOAT W W T (381= ' E n t e r r a d i a l s t e p s i z e (Angstroms) "
MTAG (38) ' R a d i a l s t e p s i z e {Angstromsf ' NLOLIN(38) =,0001 MNILIM(38) =. 5 WEAL5 (38)=.01
446
3, Proglrams for tke Pro;iec$e 'Enter o u t e r r a d i u s o f the l d t t i c e (Angstroms) ' NTAG (39)= t o u t e r r a d i u s of l a t t i c e fftngstroms)" MLOLXM (39) -,01 NWILIM (391 -20.
mm11 (39)=
C
MTWE f 4 0 ) =NUM MPmPT ( 4 0 ) = E n t e r number of i t e r a t i o n s e NTAG (40)= %user of i t e r a t i o n s e MLOLIM (40)=l.
MHILIN(40f-50. MINTS (40)-4. c MTUPE ( 4I ) =SKIP NREALS (41) =GO
c MSTRNG (MINTSf 7 5 ) ) m "roj3.
txtt
C WTYPE ( 7 6)=SKIP M W L S (761 =80,
c MSmNG (MINTS (86)) = ' p r o j 3 . g r f 6
c M T F E (87)-SKf P #=L$ (87) -90, C
=TURN
&%D
ccccccccccccecec~~cccccceccccccccccccccccc~ccc~cccccccccccccccccccccccce SUBROUTINE PAMM C g e t s parameters from screen C ends program on r e q u e s t
C closes old f i f e s C maps m n u v a r i a b l e s t o pragram v a r i a b l e s G opens new f i l e s G c a l c u l a t e s a l l d e r i v a t i v e parameters
ccccccc~ceccec~~ceccecccccccccccccccccccccccccccccccccecccc~cccccc~ccccc C Global v a r i a b l e s :
XECLUDE =%U. ALL8 INCLUDE "0. ALLf XNCLUDE 'PAmN. P 3' INCLUDE W .P 3 ' G Local v a r i a b l e s : JNTEGER I
!index of c u r r e n t s t a t e
Function;
LOGICAL LOGCVT
! c o n v e r t s 1 to TRUE, o t h e r s ta FALSE
ccceccccccccceccecccccccceccceeccccccecccccecccccccccccecccccceccccccccc C
get i n p u t from t e r m i n a l CALL GLEm CALL ASIC(1, TSTOP)
C
C
s t o p grogram i f rewasted
I F (MRmLS f ImIM) .EQ.
STOP) CALL F I N I S H
C;
C
close files if necessary XP (TNAm GALL TF ( G N W i CALL
+
.NE. NSmMG (MINTS (TTHME) 1 ) FLGLOS (TNAME, TUNIT) .NE. MSTRHG (MINTS ( I G N M E I 1 FLCLQS (ENAm, GUNIT)
c G
e
set new parameter values physical and numerical Z=mEALS 1I Z ) NOCC (1)=MINTS (IONEI UOCC ( 2 )=MINTS (ITWO) NOCC ( J 1 =MINTS r TWWE t D R = W A L S ( 1BR)
G
C
textoutput TTEM=LoGCvT (MINTS (ITTERM) 1 TPXLE=LQGCVT (MINTS ( I T F f LE) 1 THME=HSTRNG (MINTS (ITN-))
C G
grapbfcs output GTEW=LoGCVT (MINTS (XGTERM1) s a w c P = L o c c v T CMTMTS(IGHRD)I c F x L E = k o c m r (MxNas ( XGFILEI GNW=HSTRNG [MINTS(JGHAm))
(3
C
openfiles
C
IP (GPIr.P.1 CALL F W P E N (Gl\aMEI GU1JIT) f i l e s may have been renamed MSTRNG (MINTS ( I T N M ) 1 -TEAME
I F (TFILE) CALL F W P E N ( T N m , T U N I T )
MsTRnc (MINTS (IGNM)
t=GE&~
c C
calcul. ZCmG
ative parameters; !nualaar &azge
DO 10 1=1,1~2~m WOCC (NST&m+1)= B X C 615SP&m+3) +NQGC (X) 10
COmXm
C CALL PCWECX. CALL CLEAR
!cheek input
e RETURN END
cccceeceececeec~eccef:ccccccecceccccecceccccccccccc~ccc~ccccCccecccc~cccc SWRQUTINE PCHECH
G ensure that the nu&er
a f radial steps is not greater than the
448
3. Programs for the Pmjects C size of the arrays
ccccccccccccceccceccccccecceccccccccceccccccccccccccccCcccccc~cccccccccc C Global parameters:
SNCLUDE ' P A M . P 3 ' INCLUDE 'mMU,ALLP INCLUDE 'TO,ALLj IMCLUDE P " .P3' C Functions: R= GETFLT
!gat f l o a t f r a m s c r e e n
ccccccccCc~ccccccceeeccccccccccccccccccccccccccccccecccccccccccecccccccc l 0
C 15
I F ( N I 4 .GTI
m X S T P ) THEN VRETE (OUNIT, I S ) REAL (NR), W S T P HWLIM fIDR) = m X / M X S T P t r e v i s e lower Ilrnit MWALS f SBRf =E"n;OLSM ( IBR) L S ( I D R ) = GETFLTfNREALS(TDR),NWLSM(IDRf, -E. MWILXN(TDR),%nter a larger s t e p f ) DR=MmALS ( IDR) NRmTNT (RMAX/DR) GOTO 1 0 END I F FOMT
( j
+
T o t a l n u m b e r o f radial steps f=r,1P.E9.2, * ) i s larger t h a n m a x s t p ( = t , i 5 , q r 1
G
RETURN END
ccccccCcccccccccecccccccccccccccccccce~ccccccccceccccceccecccccceecceec~ SUBROUTINE PRMOUT (MUMf f , ZSTAR, NLTNES) C outputs text. r e s u l t s t o t h e swcified u n i t
ccccccccceccccccccccccccccccccccccccccccceC:cccccccccccccccccC:ccccccccccc G Global variables INCLUDE C XOIIILL8
C Passed v a r i a b l e s IMTEGER MUNIT RE& ZST&R I N m G E R IS XNmGER NLSNES
! c u r r e n t unit n-er (input) !optimal charge (input) !f ndexes s t a t e s ( i n p u t ) !nu&sr of X i n a s w r i t t e n t o s c r e e n ( f / O )
cccccecc~eccccccccceGecccccCcccc~cccccccccC:ccccccccccceccccccccceccccec~ I F (MUNIT .EQ. OUNIT) CALL CLEAR
e MBSTE mITE RRITE mTTE mITE mITE
(E"IUMST,19) (MUNIT, 21) (NUNIT, 27) Z, ZSTAR (MUMIT, 231 R m , LIR (MUNIT,30) (NOCC(TS),IS=I,NSTATE) (MUWTT, 33)
C
I F (NUNIT WRITE In7RTTE WRITE
.EQ. GUNIT) THEN (MUNIT, 19) {MUNIT, 351 (MIINIT,$a)
t s w c f a l h e a d i n g for g r a p h i c s f i l e
WE3ITE (MUNIT,191 ELSE m I " P ((MuNIT, 191 END I F C
1?3LINE5=7 C
l9 21
POMT FOMT .c.
27
FoWT
23
FOmT
+ 30 33 35
FOMT FOmT F O m T i
FQmT
40
'4
'1
(Wwt from p r o j e c t
3:', Hartree-Fock s o l u t i o n s f a r small atomic systems' 1 IQuclear charge="rF5.3,5X, ' z s t i i r =' @,F6.3) I f Rrnax fAngstroms]=",F6.3,5XIf r a d i a l s t e p (Angstroms)=', IPEIZ. 51 (' Oecupatlon of t h e s t a t e s a r e : 5 3 (2X,I2) f fQLl, e n e r g i e s a r e I n e V ' f (4X, "radius ',4X, Is d e n s i t y ' , 5X, "2s d e n s i t y ' dlctnsity\r4XltttataI d e n s i t y * } (4X, 44XI ,$ X I f "--------m-'
ejx,
4-
I
----.,,----.'" 1
4X,
1
--.".----------'l
------m
e mTUW
END
~~c~~~ccccccc~cecccccecccccccccecccccccecccccccccccccceccccccccccccccccc SUBROUTINE TXTOUT(MUNIT,TTER,E,NZI:MES~
e writes enexgies f o r one i t s r a t i o n t o t h e r a m e s t e d u n i t cecceccccecceeccccecccccceccccccccccceccceccccccccc~ccecccccCccccccccccc C ELobal v a r i a b l e s :
INCLUDE 'IO.ALL6 INCLUDE 'P M M P3' G Passed variables:
.
E (MAXSTT+1,8) INTEGER MUNIT INTEGER ITER INTEGER NLf NES C Local v a r i a b l e s : INTEGER fS INTEGER DELIME
! a l l energies o f a l l s t a t e s (input) !c u r r e n t u n i t ( i n p u t ) ?current i t e r a t i o n (input) !nu&er o f l i n e s w r i t t e n t~ s c r e e n (flo) ! s t a t e index Inu&er o f l i n e s w r i t t e n per call
ccccecececec~ccecccccccccccccccccccccccecccceccceccccccccccccccccccccccc C
DELIME-J+NSTATE ! n u h e r of Lines w r i t t e n per c a l l c l e a r t h e s c r e e n a t a convenient p l a c e I F ((NLfNESfDELIm -GT. TmLXN-6) .&MD. fNUMLT .EQ. OUNZT)) TWEN GALL PAUSE ( ' t o c o n t i n u e , * ,l f CALL CLEAR N&XNES=O EWCI I F
..
C
WRITE (MUNIT, 20) ITER WRITE (MUMIT, 3 0 )
c
Da 50 IS=l,NSTATE+I I F (NOCC (IS) .NE. Q ) TWEN !occupied s t a t e s anfy WRITE IMUulT, 35) XD ( f S ) ,NOCC ( I S ) ,E (IS,XKTQT) ,E (LS, I a N ) ,
450
9. Programs for the Projects
+ 50
E (IS,X-E), E [IS,TVEXfI E (IS,IVTOTj# E(IS,ITQT] END IF CONTINUE
c 20 30 35
FOmT FOWT
+
FOmT
' ------- Iteration ,12, b.------? 1 (2X,c Statet,,2X, 'Huecf,4 X I Ktotr,?'X, 'Vene,? X , (Veer,?X9 Tex6,,GX,*Vtotf, ,GX,*Etutf 1 (2X,A5,3X, 12, >X,6 (lX,F993j1 (26X,
e IF [MUWZT .EQ. QUNIT} NLSNES=NLINES+DELINE
C RETURN END
cccccceccecccccccccccccC:cccc~ccceccccecccceccccccccccccccceccccc~cccc~cc SUBROUTINE GRFOUT(DEVICE,PSTOR,RWO,E) C graph the densities of each state and the total density
ccccC:cccccccccccccccecccecccccccecceeccccccccccceccccccccccccccccccccccc C Global variables INCLUDE 10,ALL" INCLUDE " W N . P 3 ' INCLUDE * GRFDRT.%L' G Input variables: IMTEGER DEVICE !which device is being used? REAL PSTOR (0:L"IAXSTP,W S T T ) !radial wave function !density RE= RHO ( O :MXSTP 1 RE& E (MAXSTT+l,8) !all energies of all states C Local variables REAL X, U !radius and density mAL R !radius for GVNXT !density far gunit REAL DEN INTEGER IS !array of occupied states INTEGER OGC !nu&er of occupied s t a t e s INTEGER IR lfnciexes radius !current state INTEGER STATE !Z,E,NOCC as a character strings CTER*9 CZ,CE,CQCC INTEGER ZLEW,ELEN,OLEN Ichars~terlength DImNSION XtO:E?taXSTP), V f O : m X S T P ) DImNSIoN IS (FylXSTTtI),DEN (WXSTT.f.1) INTEGER SCREEN !send to terminal INTEGER PAPER !make a hardcoay !send ta a file INTEGER FILE DATA SCREEN,PBPER,FILE/I,~,JI
~~~cc~~~~~~cc~c~cccccccccccccccccccc~cccccc~cceccceccccccecccc C messages for the impatient IF (DEVICE .NE. SCREEN) WRITE (OUNLT,1001 e C
how many occupied states are there, and which are they? ace=0 DO 60 STATE-S,NSTPATE IF (NOCCfSTATE) .NE. 0) THEN OcC=OCC+l IS (OCC) =STATE
60
END I F CQEJTINUE IF (OCG .GT. I f TWH OGC=OCC+ 1 IS (OCG) =WSTATE+I
!include total density ! i f more than one sp state
END IP
e C
define parameters which are the same far all plots n p ( a m r c E .NE. FILE) THEM NPLOTmQCC !how many plots?
C XNIM=0. XmX=RMX YOVAL=0,
!X
value is radius
YmX=O * DO 50 fR=l,NR TF (RNO(IR1 .GT,
!y
values are density
c YmX)VMX=RHQ(XR)
CONTINUE VMIM-0,
XOVAL=O, !line and symb~1styles
+
GALL COMVRT IZ, CZ, ZLENI !titles and labels CALL C O m T f E (OCC, 8 1 ,CE,ELEN) T I T M = eAtomic Bartree Fack, z=' //C8(l:ZLEWI / I
\ rota1 Enexw=V/eE M E L (11
"adius
(Angstroms)
C
CALL GTDEV (DEVICE) XF (DEVICE .&B. SCREEN) CALL GNODE END I F
!device nomination !change to graphics m d e
C C
IF {BEVZCE .NE. FILE} THEN for graphics pack, do one plot for each occupied state DO 20 fPLOT=1, NPLOT
C
STATE=IS (TPLQT) CALL GONVRT (E ( f PLOT, 8 1 ,CE, ELEM) CALL ICNVRT f NOCC (STATE f ,COCCI QLEkr1 INFO="nergy = ' /ICE (1:ELEM) I / %ooccpr' /l6066 U B E L ( 2 ) =ID (STATE] / / ' probability densityf GALL LNLNAX
452
13. Progsurnzs for .Ihe Pmjects
30
20 C C
110 120 C
SF (STATE .EQ* NSTATE+1) THEN Y (1R)=RHO (IR) ELSE U ( I R ) -NOCC f STATE)*PSTQR (IRISTATE}* * 2 END 3F COMTLMUE CALL XYPLOT f X , V ) CONTINUE ELSE f o r gzlnit, write one o n l y l i n e f o r each r a d i u s DO 120 IR=O,NR R=IRXDR DO 110 STATE-1,NSTATE+1 IF (STATE .EQ, NST&TE+1) THEN DEN (STATE)=RHO (IR) ELSE DEN (STATE)=NOCC (S31ATE)*PSTQR (XR,STATE)**2 END IF CQNTXNUE m I T E (GUNIT,70) R, (DEEJ(STATE),ST&TE*r;l,NSTATE+lf COEJTIMUE
END IF C G
end graphing s e s s i o n
IPWT-NPLOT !reset index XP (DEVICE .m. FILE) CALL GPAGE (DEVSCE) !end g r a p h i c s package IF (DEVICE .EQ, SaEEH) CALL TNODE ! s w i t c h t o t e x t mode C
70
100 C
F O m T f 5 f 4X,IPE12.3) ) F O m T (/, * P a t i e n c e , please:
o u t p u t going t o a Ef l e , * 1
mTURH END
cccccceccecccccccccceccecceccccccccccccccccccccccccccccccccCcccecccccccc ~~c~e~c~ec~~cece~c~:~~eeccc~~ccccc~~~cc~~c G param.p3
e M& NIX XNTEGER ESTATE R= CWARGE REAL mOWR XHTEGER FACTRL
XNmGER AMGHOM 6HM@TERX5 ID Z
INTEGER N6CC mAb, DR m L M
X
INTEGER HITER
! f r a c t i o n cf o l d density t o n i x i n ! t o t a l n u w s of s t a t e s i n t h e c a l c u l a t i o n !hbar**2/mas cf an e l e c t r o n !square of t k a e l e c t r o n charge tBohr r a d i u s ! a r r a y of f a c t o r i a l s l a n w l a r momntum of each s t a t e Istate i d e n t i f i c a t i o n lnuntbar af p r o t o n s i n nucleus !occupation o f each a t a t a fradiaf s t e p s i z e foutex r a d i u s o f f a t t i e e !nu&er of i t e r a t i o n s
REAL Z C W G !nuclear charge INTEGER NR !nu&er of radial steps INTEGER m S T T !maximm nu&er of states allowed INmGER fKEN,IcEN,ImN,IWE,IWX !index e n e r w typrts INTEGER %KTOT,IVTOS,ITOT !index enerw totals !maximum s i z e of data arrays IBTEGER NAXSTP G
C
DZWNSIO% FACTRL (0:30),ANGHOM (mStfT1,NOCC ( W S T T + lB SD 4 m S T T + l l
C C O M O N / CONST / MIX,NSTATE,WBW,CWMGE,RBQMR,FACTRL,ANGMOM / DR,mX,NITER
CQmON / N A m S /
ID
cccccecececcCcccccccccecceccccceccccccccecccceceeececceccccccceccccccccc ccccccccccccecceccccccccccccceccecccccceccccecceccccccccccecccccccccccc~ C map,p3 INTEGER IZ, IONE, ITWQ, ITHME, IOR, I m X , TRITER P m M E T E R (IZ =l3 ) P W M T E R f IONE m14 1 PAMMETER (ITWO -55 1 rnR (ITHREE,=l6 f
P m m T E R [IDR -38 ) TER (SRMX =39 f P A m m T E R (1lr;lZTBR 4 0 )
454
C. Pmgmrrss for $he Pmjeels
C.4 Project 4 Algorltfxm This progrm finds the partid wave scaltering solution for electrons incident on a square-well (radius 1.5 A), a Gaussian well, or the Lenz-Jensen potential (subroutine POTBTL). Note that all of the potentids vanish for r 2 r,,,. The scattering up2itude is calcul&ed from Eq. (IV.4), wit h the Legendre polynomials evaluated by forward recursion in subroutines LPIAIT and LECPOL. To find the phase shift (Eq. (IV.8)) for each partial wave requested from LSTART to LSTOP, the radial Schroedinger equation (IV.2) is integrated outward for both the free and scattering wave functions (subroutine rwwv); the required spherical Bessel functions are calculated in subroutine S~SSEL.Note that the starting value for the w m function at the second lattice point is determined f r m the approximation to the second derivative (1.7) at the first lattice point. Mrrltiple-of-X ambiwitie~in the phase shifts are resolved in subroutine FIIOEL by comparing the number sf nodes and antinodes in the free and scitttesed waves, Input The physical parameters are the potentid [Lenz-Jensen], the nudear charge [4](Lenz-Jensen only), or the well depth [SO.] (square or Gaussian well), and the incident energy [20.]. All energies are in eV, and dl lengths are in Angstroms. The numerical parametc;rs are the number of integration points to r ( ' ) [400],the number of extra integration points between a d [GO], and the number of angles at which to calculate the differential cross section [36]. The maximum number of integration points, extra integration points, and angles are fixed by R A X ~ - - 1000, MAXE== 100, and EZAXAIG= 100, mspectively. At the be@nning of the cdculatim, the p r o g m determines a =asonable vdue for LKAX bmed on the discussion in the book; this value is displayed and you are prompted for values for LSTW [O]and LSTOP [MAXI. The maximum pmtial wave sawed is k e d by MXL= 100.
Output, Z"he t a t output asplayn;, for each vdue of L =quested, the phase shift (in degrees) and the t o t d cross section for that partial wave (in square Angstroms). When all partial waves are calculated, the program displays the total cross section followed by the real and imaginary scattering amplitudes and differentid cross section at the requested number of angles (equally spaced from 0 t o 180 degrees). If you request graphics to the screen, the program will display the effective potential, free wave, and scattered wave vs. radius for each partid wave. (In order to avoid excessive output, an exception is made to the rule: the program does not send these graphs to the hardcopy device
or a Be.) Note that the energV scale on the graph goes from -2E to 423, where E is the inddent energy, and the wave functions are centered about E. The phase shift for the partial wave is displayed in the legend. If you request both text and graphics to the screen, the text output appears after the graphics output. At the end of the calculation, the graphics displays the differential cross section vs. angle on a semi-log scale (this graph can be sent to hardcopy and file on request). c~~cc~ec~ccccccc~~c~~ccccccccccecccecccccccccccccccccccccccccccccccccccc C C C
C
P R O G W PROJ4 PROJECT 4: P a r t i a l - w a v e s o l u t i o n af quantum s c a t t e r i n g COMPUTATIONAL PHYSICS (FORTmH aRSIOPJ) by S t e v e n E. Koonin and Dawn C. Mereditb CapyricJht 1989, A d d i s o n - l e s l e y P u b l b s b i n g Company
cccccce~cccc~cccccccccccccccccccccccccccccccccccc~ccccccccccccecccccccec 5
CALL INIT CONTINUE CALL PAW CALL ARCHON GQTO 5 ERB
!display header screen, s e t u p parameters tmain l o o p / e x e c u t e once Ear e a c h set o f param ! g e t i n w t from s c r e e n ? c a l c u l a t e t o t a l and d i f f e r e n t i a l c r o s s s e c t i o n
ccccecccccccc~cccccccccceccccccccecccccccccccceccccceccccccccccccCcccccc SUBROUTINE mCBOH C c a l c u l a t e s d i f f e r e n t i a l and t o t a l c r a s s s e c t i o n using
C partial-wave
expansion; s c a t t e r i n g i s %ram a c e n t r a l p a t e n t i a l
cccc~ccccccccecccccececccccceccccccccccccccccccccccccccececcccccccccecec C Glabal variables:
INCLUDE f P M M . P $ " INCLUDE 1 0 ALLt C Local variables: !which p a r t i a l wave INmGER L m& DELTA t 0 :=L) !phase s h i f t !phase s h i f t i n d e g r e e s RE& DELDEG ( O :MAXLf REAL SIGm(O:mXL),STGTOT !total cross section WAL DSIGm (O:MMNG) !differential cross section COmZEX FIO:NXAWGI ! s c a t t e r i n g amplitude RE= CB, SD ! s i n s and c o s i n e s IMTBGER ITHETA !Index t h e a n g l e !number of l i n e s w r i t t e n t o t e r m i n a l INTEGER NZTNES !current graphics device INTEGER DEVICE INTEGER SCREEN !send t a t e r m i n a l INTEGER PAPER !make a hardcopy INTEGER FILE !send t o a f i l e DATh SCREEN, PAPER, FILE/1,2,3/
.
ccccccccccccccccccccccccccccccccecceccccccccceccccccc~ccccccccc~ccc~c~~c C
o u t p u t s u m a r y of p a r a m e t e r s I F ( (TTERM) .AND. ( .NOT. ETEM) } CALL PRMOUT (OWXT, NLINES1 IF (TFILEI c a u P R J M ~ U(TvNrT, T NLIMES) I F (GFILE) CALL PWOUT [GUNIT, NLINES)
C
G
fAnd, the pharae ~lhiffeaby A ~ t q z a t I nkhai ~ ~ %--in@ SICT-O . W 100 MwFm2,mmB (L,BELT&) 80.0*DmFA (L) !PE s r m (L)=~*PXIKZ*( 2 * ~ 1 *S= 1 ~DELT~FL (L) **2 srommerolcoz+sx(S)
S-OCIingm
a%.
C If" (GmRM) T m N tsutput results for this L value CALL GmOUT (SGmEN, L, BELDEG (L) ,S I G m {L} 1 ELSE I F (TTERM) THEN CALL TXTQDT (OUNIT, %LZNE:SIL, DELDEG (L) ,S T G m (L)1
END IF 100
I F ( T F I a ) CALL TXTOUT fTUNIT,NLINES, L, DELDEG (L) C SXGlvra (L,) 1 COrnIrn
C C
output data f o x all L
IF
( (TTERMI .AND.
(GTERM) ) CALL DELOUT (DELBEG, SIGNA)
C G
cal&at;r &ggmzaaeia ororas aect;fon by DO 300 2TmT&=Q,mG
1%(Smn)=(o*,o.)
DO 240 W&SmP,LS5?0P so=sxH(DEL= (t) ) CD*QS
(D==
(L) )
s tzrmr~) =P(S-T~)
200
300 C
+
( z * x i c ~*SD*PI; ) (X,, S T ~ T B J c@BlcIm F ( r m a ) =P ( r m n j/a: (-8 (P" [XTmT&J) ) **g BSI(X%=TA) CQH9CXm
(CD' SDI
I F (TTERM) GALL P A D S E f 8 t o see total cross s e c t i o n s . ..',l) IF (TTEW) CALL C L E m
C I F (TTERM) CALL 53GOUT (BUNIT, F, DSIGMA, 5IC;TOT) I F (TFXLE) CALL S I W U T (TUNIT, F,DSXGmI SIGTQT]
C f F (TTERM) GALL PAUSE ( * t o continue.
I F (TTEM) C"ALL
Cmm
..' 1)
c C
graphics output I F (GTEW) CALL CWSIG (SCREEN, DSXGMA, STGTOTI IF (GFILE) Cam GWSIG (FILE, DSIGMA~SXGTOTI IF (GHRDCP) CALL ~ F S I G (PAPER, D S I G ~SIGTQTI ~
G
=TURN END
~~~~cc~~c~ccc~~~e~cc~cec~ccccccc~ccccc~cccccceeccccecccccc Subroutine NUMERV(L,DBLTA> C find the phase shifts DELTA for fixed L by integrating C the raddal wave a w a t f o n (for both the scattered and free wave)
C using the Numerov algorithm
ccc~cccecccccc~ccccccccecccccecce:cccccccccccc~ccccc~cccccc~~cccc~c~ccccc C Global variables: INCLUDE @ O W M . P 4 " C Tngutlmtput Variables: ?which partial wave (input1 INTlEGER L M& DELTA ( O :=XL) !phase shift (output) C Loeal Variables: ),PSSF(mm+MXE) !wave functions WE= P S T W ,PSFMAX Imxima of wave functions M m VEFP 1 W M S . M E1 !effective pot for fixed L RMX, COHST mAL W R E E ( W N + a X E ) !centrifugal potential REAL KZ,KIfoll,lKXP3 IWumerov coefficients far scatt wave M A L KIFIKIE41F,RIP1F !Mumrow coefficients for free wave tfactars to calculate phase shift REAL G,NUmR,DENQM RE& LZ !useful constant Ear centrifugal pot IPJmGER IR,MR !index for radius C O ~ G N / ~ S U L T / P S T 8 P % I F , P S T M . I P S F M A X I ~!pass F F results to GWOUT ~ C G C ~ C ~ C C ~ ~ C C ~ C~ ~~C~C ~ c c c ~ c c ~ ~ ~ ~ ~ c ~ e ~ c ~ ~ e ~ ~ ~ ~ c e c t usegujl comstae C
C
oaldata t
200
cmzZNU]&
e G C
h@m%w vdnms wa
for a m f%m&nq bokh srcrtLmred ancl f ~ e ewave &aaeione
PSZ ( l } =ZE-PS XIaeOZirSZ* (B (3) 1 as%$21= 42. -22, *mm)*PSI (21 K I e m S T * (E-=@ (2) )
iocrarttrzed wave iniCirZ aan&t&ons
PSm (a) =2E-2 1ISI~~~~SIP* P S (2) ~= ( 2 . m@wmsr"* {B
!free rave i e t i a 2 , canatiorrra
I 4 a r i v a k i v e to get a t a r d e d
C
-
) *pslCr ( l )
1
C
W 300 1 R = P r ~ 1 C S + ~ ~ - l
C: PSX (ZR+2} 1( (2-%0*KX) *as1 {XRZ I P (PSX ( I R + l ) G??,1E+25) 5(= W 4 0 0 M#.%=%, XR+l
.
QOO
~ s (m) r = ~ s(m) r *a.
EWIP R ~ = K I EZ=XZE2
C
ooooz
t r c a t t e r e d wave E - (%+mm) {XR-1) 1 I (f.+-X) werZ2ows *PSI
f gzewent;
l nave - ~a+mm~j *BB= (m-111I i lgzavan&ovarf l w r
m h F M W S " r *($-W=(TR+l)) PSXZ {rftti) = ( (z-ia*xm)*PSI:%I (m) Y IP {PBEP(=+S) .G%. 1E+1S) T m DO 500 ==1,1R+1 PS= {m]~ ~ (m) s *a. m oaool -XB
300
mW=mE
fmha
X
RIB=)
!roll vdaas
rnZ=EXl?1F C 300
C
CI G
oal&rtrr
m
blta
(8-
W. IfP.8)
G*&(l,L)-fi(2,L) DEmMe*EL [l,&l-m (2,L)
LI"XmEL(DZL3A {L),PST, PBZE, PSI=, P C
=TURN
awa
ccccceecceCccccceccccccccccccccccccccccccccccccc~ccccccccccccccccccccccc SUmOUTINE FSXDEL(DELZ"A,PSI,PSI:F,PSI~X,PSF~1 C r e s o l v e s the a d i ~ i t yin DELTA using info from t h e wave f u n c t i o n s C PSX and PSZF; f i n d s m a x i m i n wave f u n e t i o n s OSSMX, P S X F W
~ccc~ccCcc~cccccccceccccceccc~cccccccecccccccccf:ccccccccecc~eccccccccccc C Global v a r i a b l e s : C Passed Variables: MAL DELTA
? p h a s e s h i f t (I/O) PSX ( W N + m X E I ,PSIF (mXN+mm) !wave f a n c f i o n s ( i n p u t 1 M L PSIm,PSFW !mix o f wave f u n e t i o n s ( a u t p u t f C Local V a r i a b l e s : INTEGER BUW,NODES,BUWF,HODESF ! n u W r of nodes and a n t i n o d e s ! r a d i a l index INTEGER T !Is t h e phase s h i f t p o s i t i v e ? LOGICAL DP0S !how many f a c t o r s of p i t o add INTEGER N C Function: ! r e t u r n s s i g n of a r w m e n t &E=
f o r the .cattarad wave
.m.B
TB ( B a {P63{I))
+ 500 C
XR
( SGM (PBX (X+%) -PBXI
. s a (asz(X) -PBX v-%)
1
li3W=BW+5
COmXm ata,
B-FmO
nobs, a d psi
for the free wavm
NORE5l=0
a.o
P
5=2, WTS+mm-1
D
xs (sm(asmtz)1 .m. XF (m(ss= (X} ) .er .as
DESS+X
+ 204 C
Cmfl13m
DPOS=Dm%& .G%. 0 - 0
!is the phase shffe gooft%ve3
C
C C
s i p of phase sWZ"t;a s - nieh eonveation vlz,, an at;tz&&ive pkential has lpoaitivrl &Xta R= (%ODES+BW-HQDESZ-BmE") n;p (aTmca .m. . ~ a r . BEOSI TW= (El-31 /2 EL= XF ( .HOP. .W. DPOS) B= (%-l> / 2 EL= M=H/2 XBD XF
DELFA=BmZ&+B*iPX C
=TURN END
ccccccccCcccccecccccc~cccc~cccceccc~ccccccccecccccccccceccccC:ccccccccecc B& PUNCTlOXJ SGPJ (X) C returns the sign a f x
REAL X
cecccecccccccc~cccccccccccecccccccccccceececccecccccccccececcccccccccccc IF (X.EQ.0) THEN SGN-Q O ELSE IF (X.LT, 0) THEN $GM=-1.0 ELSE IF (X,GT,0) THEN SGN=l. Q
.
EEJDXF RETWH
END ccccccccccec~ccccceeececcccccccccccccccccccccccccccec~cccccccecec~cccccc SUBROUTINE POTMTL C fill the array V for choice of potential
cccccccc~ccccCccccccccccccceccccecccceecccccecccccccccccccccccccccccccec C Global variables: INCLUDE 'PPAMH.PIt C Loeal variables: INTEGER I R =&L U
!index for r a d l u s ttenrp value for Lenz-Jensen
CGCCCCCCCCGCCCCCCGCCCGCCCGCCCCCGCCCCCCCCCCCCCCGCCCCCCCCCCGCCCCCCGCJCCCCCC
C
&awe woiluea of the raaua DO 100 ==l,mTS R (IR)=ZR*DR
460
C".. Pmgmnas for the Projecla 100 C
comxm
=I
XE (POT SQ. =NZ) fUn&-aansen DO 2 0 0 XR=X, m2"s Um4.53 97*26*SWT (R (fR) ) V (%R)m- ( (Z*E2)/R (m)1*Em[-V>
+ 200
*
(1+V+V*V*(0.3344+~*~0.048~+QQ0Q2d17*tl~Z)
cmxm mm.
&%=Cm. C
IF (par( .EQ. s 00 300 -1,=111*3/4 360
400
~ ~ rrm~ m )
I @pm@ W~BZL
v (m)=-TB=@ CaHTZm DO 4OO T R = R 9 8 * 3 / 4 , m T S V(XR)=O,O CORTXm TF {rn%RO .m. 0 ) A%rnC%.FU8E* XF {W=@ .@!E. 0 ) &%%RC*.
C
500
ELBE EF (POP .E@. a Q S S ) SImB fGaalrrian we21 W 5 Q O XR=l,=l?S v (ER) = - v z E ~ * E(-R ~ (5af*R ~ X R1) CGE1Cxm I F p%mO .Wa Q) &ZmCm. x F w m a *@E' 01 &Prnrn=.
C:
mm
c C
606
far a11 ptmtia2s, V i s rcero atsidsrr PO COO l E W F S + Z , m T S + V (XR) 4. CamXNm
C
Rf?IPum END
eecccceCcceccce~cceecccececcccccccceccceccc~cecccccccccccccccccceccecccc C
SUBROUTINE LPfNfT calculates t h e Legendre Polynomials PO and PI
eeeccc~c~ccccccceeccceecc~eccccccceccccGtce~ceccccccecceccC:cccee~cccccccc f: GXabal Variabl C
Local Variables: INTEGER ZTWETA
!indexes t h e an2l.e CCC~GCCCC~CCCCCCCC~CGCCCCCCCCCCGC~CCCCCC~CC:CCCCCGCCCCCCCCC:CCCCCCCCCCGCCC m ZOO remT*o,-o %=%A (Z%m2"&) =ZT=ZA*EI/%M@ (ITmEA) PLfWTB*110 /m@ g r m l r r r ) e o s (rmrrh ( I Z ~ T A I P& (0, X W T A ) =l P& ( l , X-%&) 4 m Z k (ZTrnrn) XQO C m X m
C
RETURN EHD
~~~~~~~ec~~e~cc~~ccc~ccc~ccccceccccccccccecccccccecccccccccccccccccc SUBROUTINE mGPOL C calculates the Legandre Polynomials from LTABm to LSTOP C
using recursion relation
e~~~~~cccccccecccceccccccccceccc"ccccccccccccececceccccccccccccccC:ccccccc C Glabal variables:
C Local Variables: INmGER ITNETA, L
M&
f index angle and L
!cos[theta)
X
~~cccccc~c~c~c~ccceI:cccceccccccccccccccccccccccccccccceccceccceccccccf:c~ DO 160 I11mTb0,mG $
-
*&SW-1 1 (z*wi)*X*PL (xi, 200
r m a ~-L*PI( j G P ~X,
~
Tj I ~CL+Z) I
a00 C
RETURM
END
ccccccccc~~cccc~ccccccccccccccccccccccccccccccccccccececcccccccccccccccc SUBROUTINE SBSSEL C calculates the Spherical Besael functions at R M X and W T M + C for L values from O to LSTOP
cccccccccccccccccccccccccccceccccccccccceccccccccccccccccccccccccccccccc C Global variables: 'PAW,P4* INCLUDE C Local Variables:
=L MAL ENTEGER
J, JM1, JP1 NORM L, LUPPER
!temp values fox JL backwd reeursn !normalizing factor for JLrs findex of JL and Nt !indexes R W or R m + R X T a A Ifunction argument
ccccccccccccccccccecceccccc C
C C
100
Em XOOO X W l , l X v&lae# for W&&& XP f I R '134. 1) I k K *
t nmmhd
ebealtn XLf& by alabla korvrrd raaruion ( f R, Q ) =-COS ( X ) 1 X E&(TR,l)m-COS (X)/ (X*X) -SXH [X) /X W 100 -1,LSTQP-I. RL (ER, ( z * t ~*m s ~ (ERIxc} /X-HL L-21 CCINTIrn
C 6
obealn
u.taX>XafrJ&akw&xdrawrafon
LWBER=X+ZO.
letart at fc suoh that JL is naagb1
3215=0
9=9.999999983-21. ?azbitraq bginninq value DO 200 L=LWPER,1,-1 a= (2*ttl)*J/fC-a1 EE ( (L-S).m, &STOP) JL (ER,fc-1)=m !saw@ nsc~cS9dL va1uer ;JIPI=Z IroU valucallr gm-l
200
CONTTrn ? n o m l l z s u@ln(~analytic fern of $0 IOM=SII (X)J X / a (m,0 ) DO 300 wO,uraF a'(ZR,L)= H O W & {XR,L) COWTEN=
300 1.000 CONTPNUT?: C
MTURIJ
END
c~ceeccccecececccccccceccccccccececccecccccccccecccccccccccccccccccccccc SUBROUTINE INlT C i n i t i a l i z e s constants, d i s p l a y s header screen, C i n i t i a l i z e s a r r a y s f o r input parameters
cceeccce~~cececccccccccececececceeccccecccccccccccccccceccccccceccf:c~eec C Global v a r i a b l e s :
INCLUDE 'IO,BLL' INCLUDE p MENU ,ALL" INCLUDE cPWM.P4' C Loeal parameters: CHmCTER*80 DESCW BIWNSLON DESCRP (20) INTEGER NHEAD,NTEXT,NGWPH
?program d e s c r i p t i o n f n u d e r of l i n e s f o r each d e s c r i p t i o n
ecccceccccceccCccccceccccccccececcccccc~cccccccccccccccccccceccccccecccc CALL SETUP
! g e t environment parameters
f: C
d i s p l ay h e a d e r s c r e e n DESGRP (1) = "PROJECT 4 " DESCRPtZ)= fPgartial-weve s o l u t i o n to quantum s c a t t e r i n g " NHEADg2
c C
t e x t output description D E S C W 4 3 f m "phase s h i f t and t o t a l c r o s s s e c t i o n f o r e a c h L;f DESCRP ( 4 ) = ' d i f T e r e n t i a l c r o s s sect ion a t s e v e r a l a n g l e s t
P3"P"EXT-2 C
C
graphics cutput description DESCRP(5)-fVVeffe~tive,s c a t t e r e d wave, and f r e e wave v s . r a d i u s ; ' DESCRP (61 = ' d i f f e r e n t l a l c r o s s s e c t i o n v s , a n g l e ' NGmPW=2
C
CALL HEADER (DESCW ,NHEAD, NTEXT, ESGMPW) C
C
set c o n s t a n t v a l u e s PZ=4.0*ATAN (3.)
CALL MEHU
!setup constant part o f menu
MTYPE f l3) ='DVITITLE FIPR14PT(13)-Votentia5 Function Options:' MLOLIN ( 1 3f -2 WNIEZM (13)=l MTWE ( 14) -MTITte MPMFT(14)="1j Lenz-Jensen Potential: eleetxsn MLOLSM (141=Q MHXLSM [14)-0
&
MTYPE ( 2 5) =XTITm mmPI["(15) Spars Welle MLQLZM ( 15 1 m 0 MHSLSM (151-0 MT?IPE (16) =MTJTLE M P W T (3.61 =' 3) Gausslan Well' MLOLIM (261m0 MNfLIM 4 3.61-2
NTVPE (17 ) =MCHOIC M P W T (L71=qntsr Choicer MT&G(17)='18 20 206 MLOLZM (17)a1 MHXLIM f 3.7) m 3 MINTS (17)11 m A L S (17)=1. MT-E (181 -NUM M P W T (18)=*Enter charge NTAG f18)m' Z p
of the atonic nueleuae
MLOLLM f 18)-2 MXTLXMf18)=l08 NZNTS (181 -4 MTYPE (19 1-SKIP MmALS f 191 m2 1 MTWE f20 f =FLOAT N Z t W T (201 -'Enter depth of potential well MTAG (20)= ' V z e f o (eV) MLoL3N (20)m-5000. MHSLZN (20)=S000 MmALS(20)= 50.0 @
(@V)*
neutral atomf
464
C. Pm?gmms for the Pr~jects N B m T (21)='Enter Enslcs (eV)' MTAG (21)=%nergy (eV) MLOLIM (21) =OIQQO1 MMILIM 121)=za1000. MRrnLS (23.1 420.0 C
MTYPE 122 f =SKIP LS (22)-35 C
M W E (38)=NUM M P W T (38) ='Number of integration points to rlr
n u h r o f integration points to rlr MLOLlH (38) -100 MRSLXM (381 =mXN MINTS (381~400 MTAG (38)
G
MTVPE ( 3 9)=NUM @WT(39)=@Hu&er MTAG (39)=' nu&er MLOLIN (39)220 MWILfM ( 39) = W E MINTS (39)=SO
of integration points between rl a f extra integration points?
and r2'
c NTWE ( 4 0f =NUN
MPWTl4Of=*Numker of anglesf MTAG ( 4 0 ) m f numjber o f anglesv ~QLIP?r(40)=1 MfNTS 4401-36 G
NTUOE (41)=SKZP LS ( 4 2 ) -60 G
NSmNG (MINTS(35) ) G
-
'proj4. t x t *
( 7 S)=SKXP
S (76) -80C MSmHG (MINTS(86)) = "proj4,grf* C
MFVPE f 8 7 1 =SKIP M m L S (87)=90. C mTUR#
END
cccccCccccccccec~c~ceccececccccccccccceec~cceceC:eccccccccccceccccec~ecc~ C C C C C
SUISROUTIHE P-M gets parameters fxom screen ends program on request closes old files maps menu variables to program variables opens new files
C calculates a l l d e r i v a t i v e p a r a m e t e r s
CCcCccCcccceCcccccccccecccccccccccccccccccccccc~ccccccccc~ccf:ceccccecccc C Global Variables: ALL" INCLUDE "@U. INCLUDE: '10.ALL' INCLUDE 'PARAM,P4' G Local Variables: INWGER GETINT INTEGER LDEF G map b e t w e e n menu i t e m s a n d INTEGER IPOT, I Z , IVZERO, TER ETPOT = 17 TER [ I Z 18 P m H E m R (IVZERO = 20 TER ( I E -. 21 TER ( I N P T S = 38 P-WTER I I N X T M = 39 P m W T E R (INAN6 = 40 G Function: LM-;fCAL LOCCVT
!get i n t e g e r i n p u t f r o m t e r m i n a l ! d e f a u l t value far L s t o p parameters XE, INPTS, XMXTM, INANC
1
1 1 1 )
1 1 i c a n v e r t s 1 and Q t o tme a n d f a l s e
Ccccc~cc~cccCCccccccceecee~eeccccccCcccceccccc~cccccccecccc~ccc~cccceccc C
get i n p u t f r o m t e m f n a l CALL CLEAR. CALL ASK f S, ISTOP f
C
s t o p p r o g r a m i f requested I F ( W A L S ( I m I M ) .EQ, STOP) CALL F I N I S H
C
C
close f i l e s i f necessary
C
I F ( T H M .NE. MSmBG (MINTS (ITNAME) ) 1 CALL FLCLOS (THAm, TUWIT) TF (GMM& NE, MSZ"RNG(MINTS IIGH&ME) 1 } + CALL FLCLOS (CNAHE, G U N W
+
C C C
C C
.
set new paramter v a l u e s p h y s i c a l and n u m r i e a l POT=MINTS ( I P O T ) Z=MINTS (1Z1 V Z m Q = m A L S ( IVZERQ) E = m A L S II E) NPTS-MINTS ( I W T S ) N X m = M S N T S 4 INXTRZL) calculate d e r i v a t i v e p a r a m e t e r s : Z&=ZkC8. 266567 X(2=2*E/E4f3ARMt K-SWT (X21 LW=K*WX/2+4 DR=RWX/NL?TS Mm=IZR*HXTU
C
C&LL BQTNTL
!fill the potential array
prompt f o r r a n g e of p a r t i a l waves a f t e r d i s p l a y i n g LmX KRITE (OUNIT, 1 0 ) a t t h i s enert3y i s = ',I3) F O M T f r The v a l u e f o r =X m I T E (OUNIT,") " LSTmT=GETINT(O,O,mXL, E n t e r a v a l u e for L s t a r t ' ) ZDEF-mX (LSTART, L m X f LSTOP=GETINT(LDEF,L5TART,KIIXL,e E n t e r a v a l u e f o r L s t o p ' ] CALL CLEM c a l c u l a t e Legendre P o l y n o m i a l s i f n o t a l r e a d y done ! a n g l e s have changed I F (HANG .NE* MINTS 1INANG) 1 THEN [email protected]( IHmG) GALL LPINZT END I F need t o have Legendre p o l y n o m i a l s a l l t h e way t o LSTBP I F (LTmLE *LT* LSTQP) CALL LEGP5L c a l c u l a t e spherical bessef funetions CALL SBSSEL text: a u t p u t TTERMoLoGCvT (MINTS ( ITTEMj 1
TFILE=LoGCVT(MIMTS(STFILEjf TKMoMSTRMG (MINTS (ITP3ANEf 1
graphics o u t p u t
GTBW=LOGCVT (MINTS 4 IGTERMI ) GmCP-LOGCVT (MINTS f7:GWRD)1 GFXLE-L5GCVT(MINTS~IGFILE~) G M ~ = M S T R N(MINTS G ( r@HAME1 open f i l e s I F (TFILEf CALL FU1PEN (TMAm, T a l T f IF (GFILE~ cam F ~ P E (CH=, M GUNIT) ! f i l e s may have been renamed MsraUG (MINTS (ITN-) I =THW MSTRHG (MIHTS {XGrJAM) ) =GNAm C
=TURN
END CccccceccccccccccccccccccccceIzcecceeccccccccGccccecc~cccccccc~eccc~ccccc SUBROUTINE PRMOUT(XUNXT,NLINES) C o u t p u t s p a r a m e t e r s t o MUNIT, k e e p i n g t r a c k o f n u d e r o f l i n e s p r i n t e d
cCcCccccccCccttccccccccccccccccccccccececcecccccccccccccccccccccccccccc~ C Glabal v a r i a b l e s :
INCLUDE IQ. ALL' INCLUDE ' P A M . P 9 ' G Passed variables: INTEGER MUNIT INmGER NLINES
! u n i t nuniber fa f o u t p u t ( i n p u t ) !nu&er a f l i n e s w r i t t e n s o f a r (XI01
~ceccccc~cccccccc~ecccc~eeccececC:cccC:cccecc~eccccccccccccccc~cccccccccc
I F (MUNIT .EQ. OUNIT) CALL GLEaR
e WRTm mITE mZTE tJRXTE FJRf TE WRITE mTTE
[NUNIT, 2 ) (MUNIT, 4 ) (NUNIT,G) E (MUMXT, I)) L S T m C LSWP (NUNTT, 2 0 ) NPTS (MUNTT, 22 1 NXTM (MUNIT,24) M M G
c I F (POT .EQ. I;ENZ) THEN m J T E (MUNXT,lO) Z E m E I F (POT ,Ea. SQU&m) THEN HRfTE (NUWST,12) VZERO ELSE I F fPQT .EQ. GAUSS) TXEN mXTE (MUNIT,lrl) VZERO END SF
e d i f f e r e n t h e a d e r E a r t e x t and g r a p h i c s f i f e s I F (MUMXT .EQ. GUMIT) THEN W I T E (MUNTT, 2 ) ELSE m I T E (NUNIT,2) m I T E (MUHIT, 1 6 ) m I T E (MUNIT, 1 7 ) WRITE (MUHIT, 18) END I F
C
C NLTWES=l l
c 2 4
6 8 10 12 14
20 22 24 26 17 18 G
+
FORMT (' ' 1 PQRmT ( V u t p u t f r o m p r o j e c t 4: P a r t i a l - w a v e s o l u t i o n e "to quantum s c a t t e x i n g r 1 FORNBT f f E n e r g y (@V) =" lPE10.31 FORMT f ' L s t a r t = X I , % O X , * L stop 5 XI31 FORmT 4' Lenz Jensen p o t e n t i a l w i t h Z = ', 133) F Q m T ( * Swaar w e l l p o t e n t i a l with V z e r s = 1PE10.31 F O W T ( q a u s s i a n p o t e n t i a l w i t h V z e r o .; 1lPE10.3) F O M T 1" N u d e r of i n t e g r a t i o n p o i n t s = ', 1 4 ) FORMT ( * Humker o f p o i n t s b t w e e n r f a n d r 2 = ', 1 4 ) FORmT ( " u m b e r o f a n g l e s = ' , I 3 f FORMAT (15X, * L r ,l5X, ' D e l t a (Lf', 17XI * SfgmafLf 1 F O W T (15X, * ' ,1!5X, ' d e g r e e s * ,lSX, ' A ~ g s t r o m s f x Z ' 1 FORMAT (TSX, ' --' , 1 S X , ' ------A ,15x,~-----------e 1 @
,
MTURN END
ccccccccccccccccccccceccccccccccecr:cececccccecccccccccccccccceeecccccccc SUBROUTINE TXTOUT (MUNIT, NLINES, L, DELDECf S f G M ) C w r i t e s out phase s h i f t a n d t a t a l c r o s s s e c t i o n f o r each p a r t i a l wave G to NUNZT, k e e p i n g t r a c k of n u d e r of l i n e s p r i n t e d
ccccccceccececcccccccecccccccccccccccccccccccccccccccecccccccecccccccccc
468
C, Pmgmtms for the P r ~ j e e f s C Global variables: INCLUDE * XIQ.ALL' INCLUDE @PAWH.P4' Passed variablas: XNmGER MUNIT !output unit specifier (input1 INmGER NLINES !rider of lines printed to screen(l/Oj !partial wave nu&er (input) 1NTEC;ER L RE& DELDEG,5 I G m Iphase shift and cross section finput) CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCCGCC~CCCC~CCC~~CCCCC~CCC~CG C if screen is full, clear and t y p headings again IF ( (MOD(NLINES,TRMLXM-4f EQ. 0 ) + .WD, (MUNTT .EQ. QUMITf) THEN CALL PAUSE(*to eontinue,..f,lf CALL CLEAR IISRITE (MUNLT,iG) WRITE (MUNIT,1 7 f m I T E (MUNIT,18) WRITE fNUMXT,2) NLXNES=MLSMES+4 END IF e WRIm fMUNIT,20) L,DELDEG,SEGXYIA C keep track of printed lines only far terminal output IF (MUNIT EQ, OUNTTf NLINES=NLIPSES*I
.
.
e 20
2 16 17 18
F O m T f ISX,I3,13X,iPEfO13,13X, T"OrnT(") F O m T EfSX,'L*, 15X,'Delta (L) F O m T (l5X,' 5 15X,'degrees F Q m T (15X, ,15X, " - - - - - - - p ,
--"
1PE15 8 ) 1(
I?XI Sigma (Lf p 1 ,1SX, %~ngstrams**2~1 ISX, >
------------
e RETURN END
ccccccccccccccccccccccccccccccccccccccceccceccecccccccccccceccccccccccec SUBROUTINE DELOUT(DE&DEG, SIG-) C autputs delta and partial wave cross se~tiansta screen
ccccccecccccccccccccecececccecccccccccr=:ecccccccecccecceC:cC:cc~cccec~ccccc C Global variables:
IMCLUDE * IO.ALLr INCLUDE ' P m M . P I ' G Passed variables: REAL DELDEG ( O :m X L ) !phase shift in degrees (input1 W& SIE~(B:~XEl,SIGTO"XItatal cross section (Input) IPJTEGER L !partial wave index (Pnput) C Local variables: of lines written so far (I/O) XNIIEGER NLPNES !nu&er
cceccecccececccce~cecceccecccccccccccccccccccceeccccecccccececcccccceccc CALL PRMQUT (OUNIT,NLINES)
100
DO 100 L-LSTART,LSTOP CALL TXTOUS (QUhlIT,NLXMES,L,DBLDEG (L),SIGMA (L)1 CWTIEtfUE RETURN
C.4 Project 4
469
END
cccccccccccccCcecccccccecccccccccccecccccccccccceccccc~cccccccccccc~cccc SUBROUTINE SIGOUT(HUNIT,F,DSIGMrSSGTQT)
e writes o u t s c a t t e r i n g a n g l e , s c a t t e r i n g a m p l i t u d e , C d i f f e r e n t i a l c r o s s s e c t i o n a n d t o t a l c r o s s s e c t i o n t o MUNIT
ecccecccccccc~ccecccccccccccccccccccccccccceccccccccccccccccccccccc~cccc e
GlobaZ v a r i a b l e s : INCLUDE qIO.WLLf INCLUDE 'PAmM,P4' C Input variables: INTEGER MUNIT m& DSIGm(0:mmNG) COWLEX F 4 O :M X A N G 1 INTEGER TTNETA REBL SIGTOT C Local v a r i a b l e s : INTEGER N L T m S
!output u n i t s p e c i f i e r !differential aross section !scattering a q l i t u d e findex o f t h e t a !total cross section
lkeap t r a c k o f l i n e s p r i n t e d o u t
~~ccec~~cccccc~cceccccccccccccccccc~ccceccccccccc~eccccccccecccccecececc (NNTT, 2) (MUMIT, 2 1 {MUNfT, 4 f SIGTQT fMUNfTt2f (MUIJIT, 2) WRITE (MUNIT, 1 0 ) WRLTB {WEST, 11) mXTE (WMXT, 12)
WRITE mITE mLTE WFtITE WRITE
C
NLXSES=..EI C G
100
w r i t e o u t data, a l l o w i n g t i m e for u s e r t o e x e n i n e f u l l pages DO 1 0 0 ITHETA=O,mG WITE (MUNIT, 1 4 ) D E G W E (ITHETA) ,F (ITHETA), DSIGm (ITWETA) WLINES=HLINES+P SF ( (MOD (NLINES, TRMLXN-4) .Ea. 0) .AND. + (mNIT .EB. OUWIT) ) TEEN CALL PAUSE("o c o n t i n u e , . . \ l ) c&L CLEM EHD SF CONTINUE
c 2 4 20 11 12
14
FORmT FQRmT FQmT FQWT
-
'TOTAL CROSS SECTTON %1PE15,8,? Mgstzams**2') ,14X, AmlCtude (E,r. Xm) ,15X, 'd S i m / d T h e t a t } EBX, d e g r e e s t , 13X, Angst rc.trs**=! * , 2 5 Y , * %qgst~ims**2~ 1 (IQX, Theta*
@
(9X,t-------e,23X,G-------------"rf5,?-------------@
(7X,F8.2,6XS
('
,1PE1Se8, ',"19E15.8,
'1
CIX, 1PE15.8)
G
=TURN END
ccccccccccccccccceccccccceecccceccccccccceccecccccccccccccccecccC-ceccC:~c SUBROUTINE GWOUT (DEVf CE, L, DELDEG, SIGMI C o u t p u t s p o t e n t i a l a n d b o t h f r e e and s c a t t e r e d w a v e f u n c t i o n s f o r
one L:
470
C. Prr?gmmsfor the Projects C does n o t allow f o r hardeopy o r f i l e a u t p u t
G i n o r d e r t o a v o i d t h e c r e a t i o n o f voluminous f i l e s
ccececccccccccecececccccceccccccc~cc~c~cccccccccc~cccc~c~ccccccc C Global v a r i a b l e s
INCLUDE 'IQ,ALLf INCLUDE @PA=M.P$' INCLUDE ' GRFDAT, &L" C Input variables: INmGER DEVICE I w b i c h device i s b e i n g u s e d ? !p a r t i a l wave TNmGER L DELDEG SXGM !phase s h i f t and c r o s s s e c t i o n !wave f u n c t i o n s RE= PSI ( m X N i W E f , f SfF ( m N + W E j REAL P S I M X , P S F W !maxima o f wave f u n c t i o n s !effective pot for fixed L REAL VEFF ( W N + W E ) CQWONfRESULT/PSI,PSIF,PSfW,PSFMAXIVIEFF!pas r e s u l t s from Numerv C Loeal v a r i a b l e s INmGER I R ! i n d e x sE l a t t i c e REAL VGRF IMA)EE+WIN) !V s c a l e d for g r a p h i n g R23AL PSIG(MXE+MAXN),PSIFG(mEfWXtJf I r e s e a l e d wave f u n c t i o n s ! a r r a y for p l o t t i n g e n e r g y RE& ENERGY (2 1 ,m D I O S ( 2 ), CMWCTER*9 CL,CDEL,CSIG,CE ! c h a r a c t e r v e r s i o n o f d a t a INTEGER LE%,LCDEL, LCSIG ! l e n g t h of s t r i n g s INllEEEER SCREEN !send t o terminal !make a h a r d e a p y INmGER PAPER INTEGER FILE !send t o a f i l e DATA SCREEN, PAPER, F I L E / 1 , 2 , 3 / CCCCCCGCCCCCGCCCGCCCCGCCCGCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCCCC C messages f o r t h e i m p a t i e n t SF (BEVICE .NE. SCREEN) WRITE (OUNIT, 100)
c
C
aetvp graphing parameters IF (DEVTCE .NE. FILE) THEM NPLBT=1 IPLOT=1
C XMIN-O
.O
YOVAL=XMLN YNIM=-2*E UmX=+ 4 *E XOVAL=O
!how many p l o t s ?
!axis parameters !energy a x i s v a r i e s between !-2E and 4E
LABEL(I)= ' r a d i u s angstrom^)^ ! t i t l e s a n d l a b e l s UBEL ( 2 ) = 'VeEf feV), s c a t t e r e d wave ( s o l i d ) , I / ' a n d free ( a s o ) wave8 CALL CONVRT (E, CE, LEN ) I F (POT .EQ. LEMZ) THEN TXTLE = ' M n W - ~ e e n P a t e n t i a l , E n e r g y 4eV) ='/LICE ELSE I F {POT .EQ. SQUmE1 THEM TITLE = ' S w a r e W e l l P o t e n t i a l , E n e r g y 4eV)- I //CE @
+
ELSE I F (POT .EQ. GAUSS) THEN TITLE = ' G a u s s i a n Potential, Energy (eV)='//CE END I F
arrays for plotting energy
mar u s (I -0. RaDIuS ( 2 )= X M ENERGY ( 1) =E ENERGY [ 2 ) =E
plot Veffective between -2E and 4E DO 30 IR=1,NPTS+WXTM !normalize WFF VGRF (IRI=VEFF (XR) IF IVGRF (ER) GT Y W 1 VGRF ( I R 1 = Y m X I F (VGRF (XR) .LT, YHIN) VGRF 4 I R ) =YMIN
. .
CONTINUE
rescale wave functions so that it fits on the energy scale DO 10 IR=1,KPTS+MXTM P S I G (ZR) ==PSI(1R) * 3 * E / P S I W + E : P S I F G (IR)=PSXF ( I R ) *3*E/PSFmX+E CONTINUE
!line and s y h o l styles
CALL GTDEVfDEVICE) I F (DEVZCE .EQ. SCWEW) CALL GMODE
!device nomination !change to graphics mode
create the legend GALL XCWRT (L,CL, LEN) CALL CONVRT (DELDEG,CDEL, LCDELI CALL CONVRT ( S I G m , CSXG, LCS1Gf IMFO=W@lta(L="/CLt1:LEN) / / ' l = * //CDEL(l:LCDEL) / / * deg' / / //GL(I:LEHJ / I # 1 = v / c s r ct i : L c s r G l / j t ~ * * 2 ' CALL LNLHAX CALL XVFLOT (R, VGRF ) NPOZNTm2 CALL XYPLOT (MDIUS, ENERGY) NPOINT=NPTS+NXTRA CALL XYPLOT (R, P S I G )
!plot potential !plot energy
!plot wave function
XFREQ=4 XYPLOT (R, PSXFG) END I F
!plot free w a v e function
472
C. Pwgmms for the Projects C
C
end grapking session I F (DEVZCE .HE. FILE) CALL GPAGEtDEVICE) IF (DEVICE .EQ. S ~ E E N IC&LL T ~ D E
lend g r a p h i c s package ! s w i t c h t o t e x t mode
C
100 C
FOWT (/,Vatience,
please;
output going t o a
mTUEZU
END
cccccccccccceecccccec~ceccccceccceccececccc~cccccccccecccccccccccccccc~c SUBROUTINE GRFSIG (DWICE, BSIGmf SIGTOTf a n g l e f o r a l l p a r t i a l waves G on a s e m i - l o g scale C graphs d i f f e r e n t i a l c r o s s s e c t i o n vs.
cccccccccccceeccccceceecc~ecccccccecccccccccccccccccccccceccC:cccce~ccccc C Global v a r i a b l e s INCLUDE "IO.ALLc INeLtUDE ' P A M . P $ " INCLUDE 'GRFDAT ALL' C Input variables: INTEGER DEVICE !which d e v i c e i s b e i n g u s e d ? REAE SfGTOT !total cross section WAL DSIQm10 :MXAWG) !d i f f e r e n t f al c r o s s s e c t i o n G Loeal v a r i a b l e s INTEGER ITHET& !indexes a n g l e INTEGER E X B m X , E a M I I ? m i n and max c3xp f o r d f f f c r o s s s e c t i o n TER*g CE,CSIG I e n e r g y , s i g m as a c h a r a c t e r s t r i n g INTEGER LEN !string length INTEGER SCREEN !sand t o t e r m i n a l INmGER PmER !make a hardeopy INmEER FILE !send t o a f i l e DATA SCREEN, PAPER, F f L E / l I 2 t 3 I
.
e~~~c~ee~~~ce~c~~cccccccceccc~~cccccccccececcccccccccecceecccccce C
messages f o r t h e i m p a t i e n t IF (DEVICE .HE, SCREEN) WRITE (OUNIT,100)
C
G
c a l c u l a t e parameters f o r graphing I F (DEVICE .HE, PILE) THEN
c MPLOT=l ICPLBT=l
c
!how many p l o t s ?
! f i n $ l i m i t s an d a t a p a i n t s UMIN-DSIGMA (1) DQ 20 ITWETA=O,NAPJG fF ( D S T G M (XTMETA) .GT, YE*PAX) Ymx-DSIGm (ITHET&) IF (DSZGMA(ITHETA) .LT. W Z N f VMINmDSIGm (ITWETA) COHTIIUE ! f i n d i n t e g e r l i m i t s on e x p o n e n t ExPmx-rNT (LWIO ( u r n ) j I F ( V W .GT. 1,) E X P M -EmPIL11X+I ExPMIW-fHa (LOGLo (UMXM) I I F (VMIN ,LT. 1. ) EXPMIN=EXPMIM-1 YMAX=O.
XMIN-DEGrnE (Q) XmmDEGREE (N&NG YOVAL=XMIPJ XOVAL=YMIN
!line and s y d o l styles ILINE=I XSPM-4 IFm8=1 XJXTLCK=4 NYTICK-EXPmX-EXPMIN IF (NYTICK .CF. 8) THEN !keep nu-r of ticks small IF (frlOD(WTICK,2) .EQ. 0) TWEN NPTIGK=NUTXCK/2 ELSE
NVTICK-8 END IF END IF !titles and l a h l s CALL G O M T (E,CIE, LEM ) IF (POT .&Q, mMZ) THEN ' hnz-Jensen Potential, Energy (eV)=V/CE TITm ELSE TF (POT .EQ. SQUME) T m N TITLE = "ware Well Potential, Energy (eV)mr//CE ELSE IF (POT .EQ. (;AUSS) THEW TITLE = "aussian Potential, Energy [&)='/ICE END IF CALL CQWRT (SXGTOT,CSZG,LEN) I//CSIG INFO-'Total cross section in A**2 LABEL(lI1 "gle (dsgrse~)~ LABEL (21= 'D i f fsrentiaf Cross Section (Wngstroms**2)
-
CALL GTDEV (DEVICE) IF [DEVICE ,&QI SCmEN) (=ALL GMQDE CALL LELNM END XF
e C
output results IF (DEVICE .EQ. FILE) TWEN HRSTE (GUNIT,10) m I T E (GUNLT,11) WIZI"E1 EGUNlT,l21 WRITE (GUNST,l1) (D&GREE(ITNjeTA),DSIGMIIT~TAI,ITHETA=.O,NAPJGI ELSE CALL XmLOT (DEGREE,DSIGM) END TF
G
C
!device nomination !change to graphics made !draw axes
end graphing session
TF (DEVICE .NE. FILE) CALL GPAGEtDEVICE) !end g r a p h i c s package I F (DEVICE .EQ. SCMEH) CALL TNODE ! s w i t c h t o t e x t mde C 10
F Q m T (2PX, ' TThtaa", P O m T (2DX, "esgr@esf
14
21X, c d S i p a / d T b e t a 61 20X, 9 n g ~ t r o m s * * 21 ~ F O M T (20X, ' ,2QXIt-------.,...,----fl 1 F O m T (18X,1BE10.3,18X,lPE15.8]
100
FOWT f l , V a t i e n c e , please;
I1 12
I
----m--@
output going t o a f i l e . ? )
C
=TURN END
ccccccceccccccccccccccccccccccccccccccccccceececcecccccccccccccccccccccc cccccceccccccccccccccccccccccccccecccceccccecccccccccci=ccccccccccccceccc C
param.p4
c INmGER mXZd, M X E INTEGER NXL SNTE;GER WANG
! l i m i t s on i n t e g r a t i o n s t e p s ! l i m i t s on p a r t i a l waves ! l i m i t s on nu&er o f a n g l e s
C PAamTER ( W N = 1 0 0 0 ) PAmWTER (mXE=f00 1 PAMWTER (=L-100) C INTEGER Z mAL E RE& VZERO XNmGER POT INTEGER LENZ,SQUW,GAUSS V (MAXN+mE) LOGICAL ATTRCT
! c h a r g e of n u c l e u s ! e n e r w of p a r t i c l e tdapth of p o t e n t i a l !which p o t e n t i a l I t y p s o f potentials !p o e e n t i a l f u n c t i o n ?is V a t t r a c t i v e ?
C P A a M E T a f mNZ=1) PAWBTER {SQUAm-2) P-METER (GAUSS-3 1 C
INTEGER NPTS ,NXTM INTEGER LSThRT, LSTOP INmGER HANG
Inuntber o f i n t e g r a t i o n p o i n t s
!range af p a r t i a l waves !nu&r of a n g l e s
c
RMWX REAL PI
! s q u a r e of c h a r g e on e l e c t r o n ! P l a n c k t s s m s t a n t * * 2 / m a s s of elec t i n sV * Angstroms**2 !maximum r a d i u s o f p o t e n t i a l !constants
REAL K, K2 REAL 26 mAL DR INmGER LMAX REAL RXTM INTEGER LTE?rBLE
!wave nu&er !sixth r o o t o f Z !step s i z e ! e s t i m a t e o f l a r g e s t p a r t i a l wave ! v a l u e f o r x2-rl !how many L e g , pol, are i n t a b l e
REAL E 2 REAL MBmM
C
REAL TNE1PZalO:MA~MG),CTHETA(O:~~HG) !theta and cos(tbeta1 =&L DEGREE c 0 :MMHG} ! t h e t a fn degrees !Legendre polynomials :mXL) !spherical BssseL Eunc at rl, r2 R [m X M + m X & ) !array of radii C:
COMONIPPARaM/Z, EtVZERO, PQT CQMON/NPARAM/NPTS,NXTM,LSTART,LSTOEl,NAHG CQMOH/CONSTS/B2,mARN,mX,P1: GOE4MON/PCALG/Z6,R,R2, BRI LMAXIR X T M , V, LTWBLE, PL, JL,NL, THETA@ + CTBETA, R, DEGREE,ATTRCT
C.5 Project 5 AIgorbhm This proe;rm solvw the sGbenratic shell model described in the text for a specified nnmber of p e i d e s and cm$ing streagth, The bases of etates with even and odtd m are treated wparately, For the set of parmeters input, the tri-diwonal H ltonian matrices of Eq. (V.9) are constructed (subroutine WWH), and aJ1 of the negative eigenvdues are found by searching for zeros of the determinant of (H - XI). The Gerschgorin bounds on the eigenvalues, Eq. (5.11), are used to guide the search (subroutine D G ~ Z ) ,and the zeros are computed by the recursion formula (5.10) in subroutine PLYIHL. After an eigenvalue has been found, the associated eigenvector is found by two inverse vector iterations (subroutine ZRVITR), if requested, where the matrix (H- EX) is inverted in subroutine WATIW. In subroutine TXTQUT(J,) is calculated for each eigenvector and the dgendues are sorted into ascen&ng ofder. Input The physical parameters are the nnmber of partides [14], the initial value of X [l.],the increment for X [.5], the number of values for X [10], and whether or not the eigenvectors are to be calculated. The mmimum number of X vdues is fixed by HxBcaz= 500. Only even nurnbers of partides are dlawed; this limitation is imposed to reduce the badkeeping. The numerical parameters are the tolerance for the eigenvalue search [ l.&Q51 and the small factor used to keep (H - E I) nonsingular [1.&05].
Output For each value of X, the program displays X , V, the neg* tive eigenvalues, and (J,) (if the eigenvectors have been requested). Once all eigenvalues for all X values have been calculated, the graphics outputs the eigenvalues vs. X (if more than one value of X is requested) or simply the eigenvalues (if only one X value is requested.) cc~ccc~ccccccccccccc~cccccc~cccccccccccceccceccccccececcccc~cccccecccce C
C C C
PRmUM PROJS PROmCF 5: SolutSon of a schematic shall nodal COMPUTATJOHAL PHYSICS (FORTmN VERSION) by Steven E, Koonin and Dawn C. Meredlth Copyright 1989, Addison-Wesley Publishing Cowany
ceccCeeCeCCCCceGGcGccCCcCCCCcGCccCccCCcCC:CCCCccCccCCcCCCccCGcCccCccccccC
5
CALL IS14 CQNTINUE CALL P A W CALL mCI.ION GOTO 5 END
fdfspfay header screen, setup parameters !main loop/ execute onee for each set of param !get input from screen !find eigenvalues and eigenvectars
ccc~eccec~cceccc~~ccc~cc~cccccccccccccccccccc~ecc~ccccc3ccceccccccccc SUBROUTINE ARCHON calculates the eigenvalues and (optionally) the eiganveetors of a
C s c h e m a t i c s h e l l m o d e l f o r s e v e r a l v a l u e s o f t h e c o u p l i n g s t r e n g t h CBI
c~cccccCcccccccccceccccccccccccccccccccc~ccecccccecccceecccccccccceccccc C Global variables: INCLUDE I Q *ALLr INCLUDE 'P m M . PS' c L o c a l variables leigenvectors REAL C E m N [ m x D I N , MAXDIMf ,CODD (=DIM, =DIM) RJZAL EmVEN (MNCMI ,m D X M ) ,EVODD (MXNCNI M X D I W ) I e i g e n v a l u e s !CHI i n d e x INTEGER JCWX REAL V !coupling strength !nu&er o f l i n e s p r i n t e d o u t INTEGER %LIMES ?send t o t e r m i n a l INTEGER SCREEN INTEGER PAPER !make a h a r d c o p y !send t o a f i l e INTEGER F I L E DATA SCWEN,PAPER,FII;E~~,~,~/
~ccccccCcccccccccecccccccceccccccccccccccccecccccccc~c~cc~cccccc~~cccccc C
output s u m a r y o f parameters XP (TTERM) G a L PMOUT (OUNIT, NLXNES) I F (TFXLE) CALL PMOUT (TUNIT, NLTNES) XF (EFILE cam P ~ O U (GUNIT, T NLXNES
C M)
100 qCBf-5,E-
12"or aaeb va2me of CBX find %he aigmvdu@o ! af ganvacltsrr; @new% t a k r"eaul%s
V = a 1 ($CBI)I (mMT-1) FN (XBZ,V,
,CODD, WODDj CALL TX"XIOUT (JCHI ,V, CEmW, CQDD, E a W N , EVODD, %LINESf
100
@
comxm
fF (TTERN) CALL PAUSE [ ' t o c o n t i n u e .
..
?,
If
I F (TTEW) CALL CmAX C C
g r a p h i c s o u t p u t : p l o t i s d i f f e r e n t i f t h e r e i s o n l y one GHX v a l u e IP (NGHS .HE. 1) THEN SF (GTEMI CALL GRFOUT (SCREEN, EmVEN, EVODD] I F (GFII*E) CALL GWQUT(E"ILE,EWVEM,EVODD) I F (GHRDCP) GBLL GWOUT{PWER,EmVEN,WODD) ELSE IF (GTEM) CALL ONEQUT (SCREEN, EWVEN, EIVODQ) TP ( E F I ~ ) c a L L ONEOUT (FILE, ~ V E WEVQDD) , IF (GHRDCP 1 CALL ONEOUT (PAPER, EaVEM, EVODB) END I F
C RETURN END
cecccccccccccc~ccccccccC:ccccccccccccccccccccccccccccc~cccccccccc~cccc~cc SUBROUTINE HAMLTN (JCWI ,U, CEmM, CODDI E-VEN, EVQDD) C s u b r o u t i n e t o set up a n d d i a g o n a l i z e t h e W a m i l t o n l a n f o r o n e C v a l u e of t h e c o u p l i n g , V
G C C ~ ~ C C ~ ~ C C C C C C C ~ C C C C C ~ C ~ C C ~ C C ~ C C ~ ~ C C C ~ C C ~ ~ C C C ~ @ Global variables:
INCLUDE ' P A N , P s 8 C Input Variables INmGER JGWI RE& V
!index o f t h e coupling !coupling strength
C. Pmgnarms for the Pr~jects
478
C Output variables: CEVeN ( W D f M, W X B I N ) P CODD I W B S N I mXDIN1 !eigenveetors EmVEW (MNGWT,mXDIMj ,EVODD (mNCIfT,M X E l I M j !eigenvalues
e Local Variables INTEGER XDTM,XCOXUIP
!Index on matrix e l e m n t s
! s i z e of matrix INTEGER NDfM DIAG (MlaXDXlvr) ,LBIAG (mXDIE"I) !diagonal, aff diagonal matrf x e l m INTEGER M leigenvalue o f Jz
?temp atorage far LDfAG !number of eigenvalues to find W A L EVAL(~XDIM),TIUIP~C(MAXDXM) Item storage for values and veet TEW
INTEGER HFIND
C~CCCCC~CG~~CC~~~CCC~~~CCGC~C~C~C~CC~~CCC~CC~CC~C~CC
rnm=aJ+%
t
DO 3.00 XDZ-X, E PDm *-3a+2* {ZDrn-Z ) I)X&@ (TDTM) 4 4
i&agmal mkr2x alemat: flawer off-&ag m f x b a 3 a
=mm*(m-(M-%) * (M-2) &D=@ (XDm)=-Vl2*5WE
100 C
=mm camxm 33'
[=S
I
!find only nag eAgavausrr
(mB635,2) .&Q, 0 ) Z m B rnrnD=2+JJ12
E-
== D a m (D=@
m X W p
mTMr mXm#
C W
!save amva2uern C)
300
EmXF 200
Comxm
e C
find ~vacrtos@m& ellganvalluer fez &-m NDmmJa DO aos XDrn=%, mm ~-8G-l+2*XDTM I Z W (XDXI) =H EH' {XBZE .m.2 ) T(iFEl- (84-3) * (M-2) (XDXM) =-V[2*SWE (=S (
-MP* 400
gmzr eamxHm
strfss f
I &agenaX m k r i x ~Immat flawer off
%%em
C
X#' (M@D{gG,2) .EQ. 0 ) WZm=G;7/2. BEIsan(a8+1)/2
D=%
( D W ,D I M ,mIM, W ZM B , m U l
i f f nd t h rigonvrZme.
C
BQ 5QO XBI24=%,B W " m -ODD (acm,ID=)
(ram)
!save aigbtnv~uallr loorrrcbtima find sigemea%orer
X r n r n { D W ,m m , W SOO f C W m I , IDIM COBB f f C-, XDXM)= P W a C (TCOW)
CrnTXErn
CrOQ
-TB" 500
CQ@%ZWOE.
C =TURN END
ccccccccccccecececccceccccccccccceccccccccccccc~cccccccccccccecccccccccc SUBROUTINE DGNLZ (DTAG,LDIAG, NDXMt NFINDIEVAL) of a NDIM X M D I M s y m t r l c t r i d i a g o n a l C m a t r i x with DIAG and LDIAG matrix e l e m e n t s
@ f i n d s HFIND e i g e n v a f u e s (EVAL)
cccccccccccCcccccecccccccccccccccccc~ccccccccccccccccecccccccccccccccccc C Global p a r a m t e r a : INCLUDE 'P m H . PS * C Input Variables !diag, o f f - d l a g m a t r i x elam DSAG (mXDTM), LDIAG ( W D X M J IMTEGER NDXX,NFIND ? m a t r i x dim, number o f v a l u e s ta f i n d C Output V a r i a b l e s : REAL EVAZ (W D E M ) leiqenvalues C Local Variables =&L UBOUND,LBOUMD !bounds on etigenvalues =m MD,GEE !ten\p s t o r a g e f o r c o m u t i n g bounds W& SFACNG !estimate o f e l p n v a l u a s p a c i n g DLAM ! s t e p i n eigenvalue search INTEGER I D I M ? f ndex a&M B D A !currant guess fox t h e eigenvalus INTEGER COUNT, L !how many e q n v l s are .It. LdLMBDA
ccccccccccecccecccccccccccccccccccccccceccccF:ceccccccccccccccccccccccccc gin h u n d e cm eigewdaoe (Eq* !5*ZZ]
C
1 -=g
( m m421 1
asam1 TOO
CQmIm
480
C. Pmtgrmnzs for Ihe Projects
mom=mxntmom, @ER)
(rnXM)+ms(LDrnG(mm))
-=DC
-Wm)/BDa
!*a.. for ffrsd eigenvakue Iwesa fop: siwnva%ueapa~inq
C
DO 200 b&,
Floop to %An& WTm a3~ava1nea linftloLf gnaso for et*
DU=SE&aG
C ZQ3.
tcoorae saarcb Co g%n& Ibam4 for t h i s eiwnva ,MDXW, CQWT)
COBICIm
m
(COrnT .LE* G)
WFO 201
c !=@et& 2632
D
200
-
search, e& an a m& f%narecdar * mzu,C a m ] step A. hg2f a@ big
!m=&too far, seep ba&waxd
camxm
e RETURN END
cccccccccccccceeecccecceccececcccccccccccccccccc~cccccccccceccccccccccec SWROUTIME ELYNML (DSAG, LDIAG, C counts the eigenvafues less than a i s used to eval C by evaluating the terms in the sa C the determinant and looking for changes in sign of those terms
ccccecccccccecccccccccccccceccccccccccccccccccceccccceccccccccccccccccee C Global variables: INCLUDE 'PPAW.PSr !diag, off-dlaq matrix elern DIAG (MXDIM),LD1AG ( M D T N ) TEGER NDIM, NFZND ?matrix dim, n u d e r a f valves to f i n d !guess for the sigenvalue C Outpat Variables INEGER GQUNT Inurtrbar sign changes in the sequence C Lacal Varlabfes mAL FEPIE", T E W I , DE T !terns insthe sewencs TMTEGER SDIM !i n d e x
-
DX&G (1) E@ (DEZ .LP. a) Z m
cawI"=2
L a tb ser-ence I'samd tarn linEtZdize COUMT t f%z& C@=
ELSE
corn*@ Ems C
IEO 3.063 XDIMm2,mIM =W= ID(XDZM) X=DZ% Dzll=zm 33" (DZZ*rnWX .I,%. Q.) C I .Ea. Q,) G0W%40mT+X SF (m(BE%) .€100090) %l.
-
?@mm% zazes
l=zEmziloaooo ZOO
e
e MTURN
END
ccccc~cCccccccecccccccccccccccccccf:cccccccccccccC:cc.cecceecceeccccccccccc SUBROUTINE 3WITR(DIAG,LDfAG,EVAL,NDIMITMPWCf C finds the eigenvector m V E C corresponding to the eigenvalue EVAC C of a spetric, tri-diagonal NDIM x MDIM matrix with mtrix elements G DIAG and LDIAG C eigenvector is faund by two inverse iterations af (E-X)
CccceccccccccceCcccccecccceecececccccccccecccccccccccccceccccccceccccccc C Global variables: INCLUDE ' P W M .PS" C Input VariabTes INTEGER NDIM !size of ntatrix DTAG[WXDIM),LDIAG(mDPM) !diagonaltoffdiagonal mtrix elem m L EVAL !eigenvalue G Output Variables M L T1?"XPmC(MXDIN) !eigenvector C Local Variables DOWLE PRECTSIOB A (MAXDTH,NXDIN) ! (E-W) and its inverse DOUS3LE PWCISION B W C ( N X D f M 1 ltentp starage for the evector XNmGER I,J !indices for matrix elements m B L NORM,SUM !variables for normalizing LOGICAL SINGLR Ifs the matrix sincgular? !temp factar to avoid singularity TMPEPS
c c c c c e c c c c c e e c e c c c c e c c c c c c c c c c c c c c c c c C
10
200
SmmS fincl %he imarss sf {E-W)
linitSal vdua i a inmk vaua
DO 200 X = Z , m m w, aoa J = X , H D ~ &(I, ~)=o.o l sat M(11-g) 3 -@B= {DIAG(I)1 idiagsaal e l m A (X,X)= (1,mOO+%mm5) *DBm ( 337 (I ,LE. LJ13f H) ;R (I,X+%) ( W X X (S+%) ) !off d%ag~rzaX a3em 3 3 f 3 OT l) A (X, E-l 1=-BB= {LDXm (X)) C (X)=%. iazb%trrry fnieirX vector
. .
a%XW(I, mXN, SmGm)
!%An&
A invatres
{SIN-)
23'
END
T m
m
G
oa soa X=T,NDIM: SW=O, 0
W 400 3=l,]LQDm 400
300 C
*
S m B m &{X,3) c {X)=Bm
CaWIW Ham0 * 0 - W _?00
T=%,EDm
swmo. 0 800
700
COmZm
Bam=1/Smz ( N W ) DO 300 I=l,mIM ==c (X)= m a c (I)*Born 900
COmZm
C
RETURN END
~ccceccccceecccccccccccecceceecccecccccccccccccccccccccc~~cccccccccceccc C G C C
SUBROUTXME M T I W (A, NDIM, SfN U inverts the matrix A of dimension NDIM using Gauss-Jordan e l i n r i n a t i o n A i s replaced by its inverse SINGLR is true if A is singular on exit, A, is replaced by its inverse
C@CCC~CCCCCCCC~CCCCCCCCCCCCCCGCCCCCCCCCCCCCC~C:CCCCCCCGCCCCG~CCC~CCCCCCCC
C Global variables:
INCLUDE XIO,mL" INCLUDE T & M . P 5 ' G Input/autput variables: DOUBLE PmCISION A ( M D X N , m D Z M 1 !matrix far inverting XNTgGER NDTM !dimension of matrix LOGXCAL SXNGLR !is the matrix singular? C Local variables: DOUBLE Pmcrsra# P (Warn),Q (WDmt I temporary storage !keeps track of whops zeroed LOGICAL ZEROED ( m D f M) I indices INTEGER I,3, K !index of row being zeroed INTEGER KBfG !largest diag element in A DOUBLE PRECZ510N BIVQT !largest diag elem of nan zeroed saws BIG
~~c~cc~~c~cCc~~~ccccceccccccecccccC:ceececcccceccccecccccccccccI=cec sxBam.Fus* C
zows are zermb? none eo gar DO 10 1 = z * m m
wM&
D (m)=*F-E. 10
e
e C
loop avar ail sows SQO S=l,MDXM mXG=O
W
!@err& for laqmst; diag e1 tin rowa not ye* zeroad
BXWO W 20 z=2,]NBIZ?I
mXwJ m XW E m XF CQESXN W adorn *he Xawest dlagona rlamnd {X .EQ. 2 ) PmOZd{mXG,mX@) $.f a3.P aagenalrr alra zero, % M n the m e s i x is oin@&x 33' (=X@ .EQ. O) EmB W= fOmlt,*) m k x l x ie s i a m a r t XE
SXHGW,ZRrn.
-n C
m s
is ill cm&tiosmd I f the 8tza oP et (ms(A(mxQ,mrnej/~mm) .L%. z.E-z~) m m {OrnP**]' A@ gl.2 ean&t%aad"
E m l3 C G
zeroing raw E33516: (=X@] * a=. Q (=X@) =l l&{=X@, =I@) l? 4rnZG)=l " P (=X@, =I@) SO.
-gin
DO 30 J=l,mXO-l B (8) (3,=X@) f=xG)
( 8 ) ) QtJ)=-QtJl 30
am G C
CQNICXm 33'
s t o tba rSgbt of the &amnaP
m 4mxo
.LP* mXN) DO 40 8=mGf1,na P (3) (mTG,RT) Q (3)=-a(mxo,a)*Q (=IQ)
XB' (ZmaD($1 ) P ( i t )=-B
(a)
484
C.Prvrgmms for the Pr~jecls A (rnXCi, 3 )=O 40
C C
50 60
100 C C
120 1JO
m
*
CWTmm TIi"
tzmafom a11 e f A W bQ J=1, Wr)XM DO 50 Em,XltDm A fir,A) C m T l m
a (3,K) +p ($1 "Q 4x1
CWqtXSW
cmzsm
Criza &**-I O g52,WDfl DQ 120 Z=1, 3-3. 3L (3, =A CoMTxm CQBTm
(E,J)
G
RETURN END
cccccccccc~cecccececccceccccccccecccccccecccC:ccccceceeceeccccccccceccccc SUBROUTINE TXTQUT(JCHX,V,CBWM,CODDIEWWEl,EVODD,NLI:NESj C calcufatea <JzT and outputs results
ccccccccccccccccccccccecC:cecccccececcccccccccccccceccccccccccccceccccccc C Global variables: F 10.ALL' INCLUDE C Input Variables FtmL C Z a N ( W D I M ,=DIN) ,GoDD ( W B X M , MXIIIHI I efgenveetars m L EVE-N (NXMCWI,WWXDIMZ ,EVODD fmNCWI,W D I M I i eigdnvalues INTEGER JCWI !CH1 index RE& V !coupling strength INTEGER NLINES ?number o f lines printed aut C Local Variables INTEGER I,K, IBIM l indices INTEGER M !eigenvalus of Jz E,J Z teigenvalue and Jz G DELIm !nu&er of lines this time round
cccccceececccccccccccccccceccccccccccccccccccccccccccecccccecccccccccccc G
BELINE-3CJ3+1 !nu&er of lines written per call elear the screen at a convenient place IP ( (NLTNES+DELTME GT. TREZIN-6) .AND. (TTERM)) T m N CALL PAUSEfrtocontinue.,,*,l) CALL c L E m NLIMESmO END IF
.
C
IF (TTEM) THE% !write out parameters W I T E (OUMXT,10) CBI (JCWI),V IF (mCTRS) THEM m I T E fOUNZT,2D)
mITE (OUNIT,30) ELSE WRITE (OUNXT, 50) m I T E (OUNIT,SO)
ENiD IF NLZNES=NLIMES+3 END I F IF (TFILE) THEN WRITE (TUTJZZI,IC)) CNL(JGNI),V I F (VECTRS) THEN mI%E (TUWIT, 201 m I T E (TUWET, 3 0 1 ELSE m I T E (TUWIT, 50) m I T E (TUNZT, 6 0 ) END I F
END IF C
]DO 100 TB-%, &J'I-l I IF (MQD(XBm, 2 ) .EQw 01 K=IDfM/Z Xk=WQDf) (acEx,E) XF (-Cm) FmM
aE=D B6 SO@ 1=1,3;7 *-88-2+2*X aEm+M*CQDD (I,R) **2 CBNSCIlrMC.
-1:
all a !ptti
88
in o z h r
I f&nd %he ezpckation vau@ t of iFz i f ? have chigenmators !aan%
mDm rewen a state@
Em& 33' {mCZM)
!their a a k r i M t i e n t o <Jz>
$%m0
W 200 I=%,&3+2
CrnPIrn
100
WZF EmIF write ft a l l out SF (WCTRS .AND. T T E W ) m X T E (OUNIT,401 E, JZ TF (VECTRS ,IIND. T F I L E ) mITE (TUNIT,40) E,JZ IF ("NOT. VECTRS .AMD. T T E M ) WRITE (OUNIT,70) E IF (.NOT. VECTRS .AND. TFTLE) m I T E {TUNIT,70] E IF (TTERM) N t Z m S = N L I N E S + l IF ( (TTEm) .AND. (NLINES .EQ. TRMLEN-6) 1 THEN CALL PAUSE(*tto cantinue,..\,lf CALL CLEAR NLINESmO EWD IF CONTINUE
-.
C
10 20 30 $0 50 60 70
FOMT FQ-T FOmT FOmT FO-T
f23X,'Chf=r,1PBfl.l,SX,CV~*11PE:11.4~ (20X,~Eigsnvalue\,2SXfe~31:>~l (ZOX, ?----------* ,25X; ' 1
---M'
(17Xr1PE15.8,17X, 1PE15.8) (35X,* EQgevalue' 1 F O m T ( 3 5 X , * ----------' 1 F O m T (J2Xr1PE15.8)
c =TURN END
cecc~ceccccceccccccccccccccccecccecccccccccccccccccccccccecccccccccccccc SUBROUTIRE INXT i n i t i a l i z e s c o n s t a n t s , d i s p l a y s header screen, C i n i t i a l i z e s a r r a y s f o r i n p u t pazameters C
cceeecccccccccccecCccccccccccccccccccccccccccccccccecceccccccccccccccccc C Global v a r i a b l e s : INCLUDE ' ZTO. ALL'
INCLUDE
'=NU.
ALLr
INCLUDE V A W , B S 6 C Local p a r a m t e r s :
!program d e s c r i p t i o n SNmGBR N W a D , MTEXT, N G W W
In
r of l i n e s f o r each d e s c r i p t i o n
cccececcccccccccccccf:ecccccccccccccccccccccccccccccccccccccccccccccccGcc CALL SETUP
!get e n v i r o n m n t parameters
C
C
G C
dPsplay header s c r e e n BESCRP 4 f 1 = 'P R O a C T 5' DESCm (2)= * S a l u t f on of a Schematic S h e l l Model* NH=D=2
text o u t p u t d e s c r i p t i o n DESCRP (31 = 'Negative e igenvaluas and NTEXT51
c C
c
graphics output description DESCRP(4}= 'Eigenvalues vs, coupling s t r e n g t h " NGWH=1 CALL WEADER (DESCW,NHEAD, NTEXT I N G W R f
C
CALL =NU
! s e t u p c o n s t a n t p a r t af menu
c MTmE f f 3 1 =NUN W W T ( l J ) = ' E n t + r t h e nu-r of p a r t i c l e s (must h even)' MThG (13) =Wu&r of particlesp WLQLIM113)-1 MNILXH (13f = W N HINTS 43.31 -14
e MTUPE ( 3.4 ) =FLQAT
MPMPT(14)=%nnt@r the intiaf value of coupling constant (ChSI6 MT"AG414)- 'Initial coupling constante NLQLIM (141 4. MMILIN (14)-1 000. NRmLS(14)=1,0 MTYPE ( 15 1 =FLOAT M P ~ (251 T m yEnter
increment in coupfing constant (Ghl) MTAG1151='Tncrement in coupling canstant* MLOLIW f15)=Q. NNfLIM(25)=100ae mmL5 (15jm.5
@
MTJEPE ( 1G ) -NUM WWT(SG)='Enter the nuntber of values for coupling constantF MTAG(I&)=~~umberof values o f couglfng constante MLOLTM (16 )=l MRILIM (161 =KXNCWI MINTS (1S)=lO NTYPE ( S 7) =BOOLEE W W T ( 2 7 1 = * D o you want the eigenvectors <Jz> calculated?" MTAG(17f=*Cal~ulettaeigenveetors6 MINTS (17)51 NTYPE 118) =SKIP mEALS f18)=35
MTMZE (38 1 =FLOAT W W T f 38)=#Enter the tolerance for eigrrnvalue searchy WTAG (38) =' T a f erance for aigenvalue search* mOLIM ( 3 8 )=I.E-07 MNILIM (38f 51. LS ( 3 8 ) -1 .E-05 NTWE 4 39)=FLOAT M P M T (3531 =*Enter small factor to keep (E-M) nonsingular? NTAG (391="actor to keep (E-W1 nonsingular' MLOLIM (39) =X ,E-07 NRILIN (381=l. mmL5 (391 m1 .E-05
MTYPE ( 4 O) =SKIP L5 140) =GO
C-Pragnrma for the Projects
488
NTPE ( 87 1 =SKIP L 5 (871=98.
c RETURN
END
c c c c c c c c c c c c c c c c G e C e c e c c e c c c c c c c c c c ~ ~ SUBROUTINE PAMM C g e t s p a r a m e t e r s from s c r e e n G e n d s grogram a n r e q u e s t
C closes old files C maps =nu v a r i a b l e s t a progrclrn v a r i a b l e s C o p e n s new f i l e s
C c a l c u l a t e s a l l d e r i v a t i v e parameters
ecc~C~cccecc~cccceccccec~cccccccC:ccccccceccc~ccccE:ccccccccccccccccc~~c C Global variables: INCLUDE * MENU, ALL' INCLUDE qO.ALLP INCLUDE 'P W M , 3 5' G Local v a r i a b l e s : !CBI i n d e x INTEGER 3CWI C map between nzenu i n d l e e s a n d i n p u t p a r a m e t e r s XNTEGER INPmT, ICNT, IDELCN,INCH5C IVEC, ZLTQLE, XEPS, INGRF (sNamT = 131
P-METER
(ICMf
=
14 1
P m M E T E R (XDELCN = 15) P W W T E R (INCH1 = 3 6 )
TER (FVEC
-
17)
P m W T E R (ILTOZE 38) TER (IEPS = 39) TER (INGRF = 82 f C Functions:
LOGICAL LOGCVT INTEGER GET1HT
! c o n v e r t s 1 a n d O t o t r u e and f e l s s !get i n t e g e r i n p u t from screen
ccccc~ccccccccccE:cccececccccceccceecceccececccccccc~cccccccecccccceccccc C
C C C C
C C
e
g e t i n p u t Pram t e m i n a P CALL CLEm CALL ASK (2,ISTOP) s t o p program if r e q u e s t e d IF (E?IREALS(INAIN) .EQ. STOP) CBLL FfWlCSW e l a s e f i l e s i f necessary IF (%HA= .NE. MSTRMG (MINTS I I T N W ) ) 1 + CALL FLCLOS (TNAm, TUNTT) I F ( G N m E .NE. NSTRWG (MINTS(IGNMEf 1 ) + CALL FLCLOS (GBAME,GUNIT) set new p a r a m t e r v a l u e s physical and numerical NPmT=MINTS ( INPART)
cwr (1 = ~ E A L Sfrees) MCWIPMINTS (XNCHfk
D E N H I = M m L S ( IDELCN) n C T R S - L W C V T (MINTS ( I m C ) ) LTOLE-mEEILS C I L T Q m 1 E P S = W A L S {IEPS t 2 C
text o u t p u t TTERM=W)GCVT (MINTS (ITTERM) f TFILE=LOGeVT (MINTS { I T F I L E 1 1 THW=MSTRNG {MrMTs ( I a W h r n j 1
c C
graphics output GTmH=LOGCVT (MXMTS (IGTERMj 1 GHRDCP=L~GWT(MIWTS r r E r n a 1 1
GPXLE-LOGCVT(MIPJT~(IGFIL,E:~~ GNWPMSTRNG (MINTS t IGNW* : C
e C
openfiles I F (TFILE) CALL F W P E N ( T N m , TUNTT) IF ( G F X m ) CALL F m P E M (GNME, BUMIT) f i l e s m a y have b 8 e ~renmed NSmHG (MINTS ( I T H A W ) ) =THAM MSmNG (MINTS ( I G N W ) 1 =GM-
e C
IQ
even ( t o avoid l o t s of b o o k k e e p i n g ) 01 THEN NPmT-GETINT 4NPMT-1,2, W N , + Mumber of particles must be e v e n , t r y again') MINTS (I N P m T 1 =MPBRT GOTO IQ END TF CALL C & E m
make sure that WBART IF (MOD(NPART,Z) .NE.
i s
I: G
100
calculated parczmters 3JmMPmT / 2 JJ1-JJ* CJJ-42I DO 1QO JCNI=2,NCWI CH1 (JCHI 1 =eHZ (1) + (JCHE-1) *DEXICEi(T CONTTNUE
C RETURN END
~cccccceccccccccececcccccccccecccccececccccecccccccccceececcccecceccI:ccc SUBROUTINE PMOUT(MUWIT,NLINES) C o u t p u t s p a r a m e t e r sumary t o t h e specified u n i t
ccccccccccccceZ;"~cccceeecc~eccccceccccccecccccccccccccccccc~c~ccc~c~cI:~cc C Global variables: INCLUDE I Q .ALL* INCLUDE V & W . P 5 ' C Input v a r i a b l e s : INTEGER MUNZT INTEGER NLINES
'
t u n i t n u & e r for o u t p u t !nu&er o f l i n e s p r i n t e d o u t f I / O )
cccccccccccccCccccccccccceccecceccc"ecceccceccccccccccccI:ccc"ccI:cI:cccI:cccc
490
6.Pmgmms ,for the Projects TF (HUNIT .EQ. OUMIT) CALL C L E m C
mITE RRXTE Wf TE WRITE
(MUNIT, 2) (NUNIT,4) (HUNIT, 6 )=ART (NUHfT,l0)JJ
C
NLINES-4 C
2 4 C
6 20
FORMAT ( I X , / l FORmT ( ' Otltput from p r a j e c t S : ' , S o l u t i o n of a s c h e m a t i c s h e l l model*) F O m T { I X , * N u h e r of P a r t i c l e s = 5 , 1 1 3 f FORmT ( l X , W ~ u s i S p i n = * , l I 3 !
C
=TURN
EMD
~~cc~~ce~c~~cc~cccccccceccccccceccccccec~cecceccccc~cccccccccccc SmROUTIME CWQUT(BEVSCE,EVEVEN,EVODDI C graphs e i g e n v a l u e s v s . GHT
CccccecccceccceccCcccecccccccccccccccccccccccccccccceccccecccccccccccccc @ Global parameters:
IQ. ALL' TMCLUDE * PAMM. PS' INCLUDE ' GGRFDA ALLf C Input variables TNmCER DEVICE !which d e v i c e a r e w e c a l l i n g m& m W N (NXWGWT,M D I N ) ,EVODD (mPJCWI, =DIM) !eitgenvrllues C Loeal parameters: INTEGER JCW1,TDIM !CWZ and DZM i n d i c e s CHmCTER* 9 GNPART !BPMT as a c h a r a c t e r s t r i n g INmGER L N P m T Ilenqtb of t h a t s t r i n g Et'AL ( W B I M ) !one e i g e n v a l u e a t several CBI INmGER SCREEW !send t o t e r i n a l XWSfI5GER PAPER !make a hardcapy ZUTEGER FILE ?send t o a f i l e D&T& SCREEN, PAPER, PILE/l, 2,3/ f NaUDE
.
ccecccccccccccccccecccccccccecccecceccccccccccccecccC:cccccccccc~~ccccccc C
C C
m s s a g e s f a r t h e inrpatiant T F (DEVICE .M. SCREEN) WRITE (OUMIT,100) c a l c u l a t e p a r a m t e r s f o r graphing I F (BEVTCE .NE. PILE) TWEN MPLOT=T !how nrany plots TOLQT=S,
C VmX=O
.
YMIN=EVEVEN (NCHZ, l) DO 10 JCHX=I,NCWI-1 IF (EmVEM (JCHX, 1 ) .LT. CONTINUE YWIN=YMTW+. O l * (YMXN)
!limits
YMINf VMLN=E
!leave a little extra room
!line and syml>al styles
t.
I C ~ (EJPPIRT, T CNPART,L N P ~ T I !titles TfTLE=~~chemadlc Shell Model with " //CNPART(l:LNPARTZI/" particlesC LABEL(%)=*CWX' MBEL (21 =?eigenvalues"
CALL GTDEV 4 DEVICE1 IF (DEVXCE .E@. SCREEN) CALL GMODE CALL LNLHM END IF
C C
50
60
c C
!device nomination !change to graphics mods
!$raw axes
output results !loop over all elgenvalues DO SO TDIW=l,JJiI ~a 50 JCBX-~,NCH~ ! and values of CXI SF (MOD(ZBTM,2) *E@. 0) EVAL (JCHX)mEVOBD [ JCHIIIIZIM/2) IF (NOD(IDIM,2) .Ea. 1) EVAL(JCHX) =EVEaN (JCWI,(IDXM+1)121 CONTINUE IF (DEVICE .EQ. FILE)THEN WRITE (GUNIT,70) VVRITE (GUNIT,80) (CH1(JCWT),ZVa fJCHI),JCHI=l,NCHXf ELSE CALL XYPLOT f GWI,BVAL 1 END IF CONTINUE end graphing session IF (DEVICE .NE. FILE} CALL GPAGE(BEVICE1 f F (DEVICE .EQI $ W E N ) CALL TMBDE
!end graphics package !switch to text made
G 70 80
100 G
F O W T (5X, * CH1 ' ,5X, ' Eigenvalue ' 1 Fa-T (2(5X11PET5,8)f F O m T (l,' Patience, please; output going to a file.p)
mTmH END CCCCCCCGCCCCCCCCCCCCCCCCCCCGCCCCCCCCCGGCCCCCCCCCCCCCCGCGCCCCCCCGCCCC(SCCC
SmROUTIME OHEOUT(DEVICE,EVEVEN,EVOBD) C graphs eigenvalues for one value o f CH1 C allows user to visually Inspect eiqenvalue spacings
482
C. Pragmms far the Projects
eccCeCcccccccccccceccecccceccccccccc~~~ccc~cceecccc~cccccceecceccccccccc C Global parameters: INCLUDE #IO.ALLf INCLUDE # P N N . P 5 * INCLUDE SGRFBAT ALL' C Input variables INTEGER DEVICE !which d e v i c e are w e c a l l i n g REAL E ~ ~ N ( ~ U C N I , ~ X D X M ) , E V O D D ( ~ N C W I , ~f eXiDg L e nMv~a l u e s C L o ~ a lparamters: f N m G E R JCWX,IBSN !CH1 a n d DTM indices C B m C T E R * 9 CNPART !NPART as a character s t r i n g !length o f t h a t s t r i n g INTEGER LNPART !CH1 a s a c h a r a c t e r s t r i n g C H W C T E R * 9 CCWI INTEGER LCXE !length o f t h a t s t r i n g EVAL(2),X (21 teigenvalue, d a m y variable X INTEGER S C m E N !sand t o t e r m i n a l IEJmGER PAPER ?make a h a r d c o p y !send t o a f i l e IXTmGER FILE DaTA SCREEM,PAPER,FELE/I,2,3/
.
CCCCCCCCCCCCCCGC'CCCCCCCCCCCCCGCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
messagssfortheimpatlent XF ( D N X W .NE. SGREBN) m I T E (OUNIT, 2 0 0 )
C
calculate p a r a m e t e r s f o r graphing f F (DEVICE .NE. F I L E ) THEN NPLOT=1 ?how many p l o t s IPWT=2
C!
! l i n e a n d sy&ol
+
styles
CALL XCmT(XSZ)ART,CMPMT,LNPART) !titles CALL CGHmT (CHI ,CCHf ,LCHl f TITLE=tSSchemetic S h e l l M o d e l w i t h //CMPART(1:ZHPMT)//' p a r t i c l e s and CHI='l/CCHI(1:LCWT) =EL (1)="" m B E L (2)= t e S I g e n ~ a l t l e b @
C m L GTI>EV(DmICE) IF (DEVICE .EQ. SCREEN) C&L CALL LIJLHU END IF G C
50
60 G C
GMODE
!device nomination to graphics mode !draw axes
!change
output results DO 60 IDIM=1,JJi-1 !loop over all elganvalues DO 50 JCMT=1,2 IF (MOD(IDIM,21 .EQ. Q) EVAL (JCBI)=EVODD (I,XDZM/2) IF (MQD(TDIIH,2) .EQ. I) WAL(JCHI)=E~WN(l, (IDIMS1)/2) CONTINUE IF (DEVICE .BQ. PIU) THEN WRITE (GUNIT,"10) m e T E (GUEIT,so) (X (JCHI:~,EVAL (JCHI), JCWI=I,2) ELSE CALL XmLOT (X, EVAL) END XF CONTINUE end graphlng sessf on IF (DEVICE .NE. FILE} CALL GPAGE(DEVICE1 IF (DEVICE .EQ, SCmEN) CALL TMODE
land graphic package !switch to text made
c 70 80
100 C
B , 5 X , C Elgenvalua 1 F O m T f 2 f5X,2PE1 F O m T f /, Vatience, please; output going to a file.' 1 F O m T (5X,'
=TURN END
~cc~cc~ecc~cccccccccccceecccccceccccccccecccecC:cccccccccccceccccccccccc~
eeccccecccc~ccccecccccccceccecccccccccccccccCccc~cc~ccccccccccccc~ccccce C patam,p5
mNCRI
INTEGER XNmGER XNZFEGER
MAXPd
mDSM
PAMmTER
( MXNCHImSOO )
PAWETER
(PII1XDIM=WN/2+1)
!maximum nuder af chi values ?maximum nuher of particles !maximm dimension of matrices
e IEJEGER REU
SMTEGER CkL
mm
NPART CRI(~NCXI),DELCHZ NCRI VEGTRS LTOLE EPS
!nu&er of particles !coupling constant and increment t n u h r of coupling constants ?do w e want eigenvectars? Itafarance fox eigenvalve search !factor to keep (E-H) nonsingular
C f NTEGER
JJ,JJS
!J
value, J* (J+1) value
G
COMMObJ/PB~~%/NP~T,CNIINCRTICtE~NtIIVECTRSILTO~~EPS COM?ION/PCALC/JJ,JJ1
484
C,Prognams for the Pmjeets
C.6 Project 6 Algarithm This program uses a relawation method to solve for the stationary, incarmpressible gow around a plate in two dimensions; the g e m etry is as described in the text. The main relaxation loop begins at line 99 in subroutine ARCffOAf. Subroutines PRaAX: -and V B S A I I relm the stream functions and vorticity, respectively, by solving Eqs. (VI.9) and (VI.10). Only those lines in the relaxation routines marked by the comment "interior point" are unaffected by the boundary conditions specified in the text. Thse sweeps can be regtsicted to a sublattice. For this problem, it is es~elltidto under-refm the lattice in order to avoid cras&ag the program, especially at high Reynold's numbers. After each sweep the viscous and pressure forces are calculated in subroutine FORCES. Every B F R E P ' ~ ~ iteration you are given the option to continue iterating or to return to the main menu, Input 'Fhe input procedure is a Bit diEe~eatfor this p r o g r a , ifrs it is for Exaraple 6, For t h s e two codes, yau may find that during the iteration procedure yau want to kmp the field v d w s and all parmeters, except one or two, the s m e . For example, yea may wish to alter just the s t r e w reiwatim parameter or change the fieqnency at which the fields are? displ-d. Such a pmcedure is straightforwwd, bat only as long ans the 1;Lt;tice dimensions remisin. the same. Therefore, the menu is broken into two pieces: trhe first level obta;ins the ldtice dimensions; the second level (or main menu) obtains all other parameters. As long as you do not enter the fimt bvel menu, aid prameter& a d field 1vaIues am u~lehangd zlnless you &peificaaf&request otlaep'wise, The first level p~omptsyou for the lattice parameters BX [20] and ay [20]. The maximum lattice sizes are fixed by two considerations: first, the parameters BxWAX= 100 and sunrx= 100 which determine the array sizes; second, the size of yovs terminal as defined by TRnVfB and in subroutine SETUP. This last restriction is imposed so that the M d s can be displayed on the screen, using characters to indicate field strength (subroutine DISPLY). If you wilt be using a graphics pachge, you can remove the terminal size restrictions on EX and W in subroutine LATTSC, If it is noZk your fipst time through this menu, you will also be given the option of ending program execution [no], and (if that answer is no) resetting input; parmeters to thdr defadt values. Note that df parameters that depend an lattice dimensions (i.e., the field vdues, the plate position, and sublattice parameters) are automatically reset every time you enter this first level menu,
The physical parameters are the half-width of the plate (in lattice spacings) BY/^], the length of the plate [I(x/~], the location of the front edge [BX/~], and the lattice Reynold's number [l.]. The numerical parameters are the relaxation pasameters for the vorticity [.3] and stream function [.3], the option to relax a sublattice [no] specified by the lower left and upper right corners, and the initial field values. Initial field values at non-boundary points can: 1) be read in from a file [projG.in] created earlier by this program; 2) be set to the free-streaming values (subroutine ~ m m )or; 3) remain unchanged. Option 2 is the default if the calculation is just be@nning,otherwise option 3 is the default. The two graphics parameters are the number of contours for plotting [l01(used only if you have a graphics package), and the frequency at which the field is displayed [IO]. This is also the frequency at which you are asked if you would like to continue iterations, The n n ~ n a u mnumber of contours is fixed by nawv= 20.
Output After each relaxation sweep, the text output displays the iteration number (iteration count is zeroed on return from the main menu), pressure force, viscous force, and minimum and maximum values of the two fields. Eve~yEFREQ"~iteration, the progam will display the field, NoGe that; the field d l be displayed as emtours (if you have requested graphics sent to the screen, see subroutine CRFOUT) or as characters (if you have requested text to the scrwn, see subroutine DISPZ;Y). In the character display, small letters iIldicat?e negative d u e 8 while numbers and capitd letgers indicate posigive vdues; e.g., 'zz' corresponds to the mast negative field vdue; and %', to the most positive. With tEs convention, the spacing in field vdues between the small lettem will not be the same pacing as between the capitd letters. In the eharater display the plate is indicated by blanks, while for the contour plots it is indicated by a dashed line, The appeasance of the contour Lines depends on your graphics package. Because display sf the field c m dovv down cdcufations considerably, you may want to set BREQ to a largc3 number. Again, to avoid volurninaus output, the field is not written, out to a file or sent bardcopy device every M E ; a Q time. Instead, when you request to stop iterations, you will be asked if you want the field vdrtes to be written to requested output devices. Note that the field can be written out in three ways: as character data (if text is requested to a file), as numerical data (if graphics is requested to a file), or as a contour plot (if graphics is requested to a hardcopy device).
496
C. Pmgmms for $he Pr~jeels
cccccccccccccCceeccccccccccccccccctcccccccccecccccccccc~cccccccccccccccc~ I"RQGmM PR036 C Project 6: 2-D viscous incowsessible flow about a rectangular block C COMPUTATIONAL PHYSICS [FORT-% VERSION) C by Steven E. Koonin and Dawn C. Meredith G Copyright 2 9 8 9 , Addison-Wesley Publishing Company cteeCccceccccccccccccccccccecccceeccccccceccccccccccceecccccccccccccccccc CALL TNIT !display header screen, setup parameters 5 CONTINUE ?main loop/ execuka once for each set of paran CALL LATTEC !get lattice size, allow for ending CALL, ARCNON !get detailed bound eond and relax lattice GOTO 5 END ccccccccccccccccccecccccccecccccccccccccccccceccccccccecccccccc~ccccc~cc SUBROUTINE ARCNQN C subroutine to get parameters, relax the lattice, and output results cccce~ccecc~ccccccccccccccccceccceeccccccccccccecccc"ceccccc~ccccecccc~~~ C Global variables: INCLUDE 'P W M , P INCLUDE '1XO.ALLt C Local variables: I stream function REAL P (NXmX,N Y U I !vorticity REAL VE"ORGEpPF0RC1E: 2viseous force and pressure force REAL XSImX,P m ,XSTMIN,PMIN !min. max values of XSI, P INTEGER XMIN,XmX,YNIN,YW feornsrs of relaxing lattice !continue iterating1 LOGICAL ITER LOGICAL PRN !print a u t parameters? !write out field now? INTEGER CHOICE !nuAer a f iterations INTEGER MITER LQGLCAL END fend this run? !lattice indices INTEGER IX, IY INTEGER NLINES !number of lines sent to teminal !send to terdnaf INmGER SCMEN 3Nr"EGER PAPER !make a hardcopy ZNmGER FILE !send to a file m& FGRF I W-X, NVmX ) ?field for graphing C Functions: m A L GETFLT INTEGER GETINT,YESNO LOGICAL LOGCVT DATA SCREEN,PAPER,FXLE/l,2,3/ DATA VRTCTY,STmM / 2 , 2 / ecccccccccccccceccccccC:ccccccccccccccccccccccccccccccccct~cccccccc~cccccc END=-FALSE, !Initialize values DO 5 IX=1, NX DO 5 IV=I,NY P (IX,IY)-0. x s (rx, ~ su)=o, 5 CONTINUE C 200 CONTINUE !allow for many runs with same lattice
CALL P A W (P,XSI END ) I F (END) RETURN I F (SWLATf THEN XMIN=NXLL XWX=NXUR YWIN=NYLL
!get new p a r a n r a t e r s !start f r e s h o r end altogether
!set l i m i t s f o r r e l a x a t i o n
Y W = N Y UR ELSE XMIN-I. YMIN=1 XmX-MX YWX=NU END I F
I F (TFILE) CALL TXTOUT (TUNIT, NITER,
VFORCE,PFORCE~XSIW,P~,XSIWIN,PMXN,MLXNESf XF (TTERM) CALL TXTQUT (OVNIT, NXTER,
WORCE,PF~RCE,XSI~,P~X,XSXMIPiJIPMIrCaCNLXATES~ ITER=. FALSE. PRM-.TRUE. I F (MOD [NfTER, NFWQf .NE. O) T m M I TERm. TRUE. ! continue i t e r a t i n g w i t h o u t asking Pm=. FALSE. ! don" p r i n t o u t header ELSE ! o t h e r w i s e display f i e l d s I F (GTEM) THEN see s t r e a m f u n e t i o n a n d vorticity l) CALL PAUSE(-o CALL C a m CALL GWQUT(SCREEN,STmM,P,PNTfJIPWIFGBFINXyNV} CALL GmOUT (SCWEM, VaTCTY, X S I ,XSIMZWt X S I m X I FGWI NX8HY) ELSE IF (TTEW) THEM GALL PAUSE(*tta see stream % u n c t f o n . , . ' , l ) CALL GmAR GALL DXSPLU(P,OUNTT,STREEhMIPlvtAX,PM3:M> CaLL PAUSE(*to see varti~IQ., 0) CALL C L m R GALL DISPLY(XS~,BUNITyVRTCTY,XSI~XtXS3E"IXN~
...',
.\
498
C Progrcams for the Pmjects EMD XF IF (SUBMT) THEN
!and provide options for continuing SUBmT-L,OGCVT(YESNO{lI'Co~tinu(?relaxing sublattiee?')) SF (SUBMT1 I TER=. T R m
.
ELSE
ITERmLOGCVT (YESNO (l,* Continue relaxing lat tic@?' 1 1 END 5F EEJD SF C 33
(I=)
?~oneLma fdaza&ing
FmH
W T O 09 C
ELSE C
"
pxomt for writing out a f f i e l d values IF ((GF2LE) .C%%, (CBRDCP) .OR. (TFILE)) THEN GHOSCE=VESNO(I,tDo you want l a write out field now?') IF (CHOICE .EQ, l) THBH SF {GFXLE) C U L mTQUT(P,XSI) ?write out, field if rewest;ed I F (GHRDGP) WEB CALL GWOUT (PBPER, ,P,P~IM,PMAX,FGRF,HX,NY) ,XSI,XSIMIM,X S S ~ XFGW, , NX, NY! CALL GRFOUT (PBPER, END IF f F (TFILE) C&L DSSPLY (P,TUNTT, STREaEUI,PM, PMXPJ) IF (TFILE) C&& DISPLY(XSX,TUWIT,VRTCTY,XSIW,XSINSN1 END IF
END IF GOTO 200
!display menu
END f F
C END
ccccccccceecccccc~ccecccccccccccecccccccccceccce~ccccecccccccccccccccccc SUBROUTINE FQRCES(XSI,WORCE,PFORC&) C cafcuf2nt;a pressure Eores (PFORGEl and viscous forces IWORGE) G from the vorticity (XSS)
cccccc~cccCccccccccccccccccccccccccccccccecccecccceeccccccecccccI:ccccccc C Global Variables: INCLUDE 'P & U . P 6' C Passed Variables: )
!vsrtieiey (input)
!viscous Eorca and pressure force (output1 C
L o ~ a lvariables:
6ER I X , I Y P
!lattice indices !pressure
ccccceccc~cceccccccecccecccccccccccccccccccccccccceccccccccccc C C
cralculakat v i a a ~ u aEoz-s by inkwza%ing vortrie%kp almg %be top of the pfate
X0
CONTma
C.6 Project 6 C C
C G
499
clalwZate tb pge~mmforce bjl fntepnrlslng vort;ioity along the ad-@ of t:be pXaLa t o ob%oSnthe prac~lsuze, Lban intsgfating the praamze t o ohta?ta t:ha prsir-a iPorcre Pm0 t up front: E=P- (=I (mm,ZY) -X91 (m@N1C-5, IT] +XSI (=m%,%X-1) -rnI ( m m % - 1 , ZX-%] ] /2/
+
~~am=PFam-g l 2r C
30
EX)
+ 30
C O m Z m PrQm=EFrna-P/2
C 1
1,-3
00 40
I,PT)-XSI
P#
+a, XX+%)
.c
-
BZ?"QRWP@aa-P 40
C@mIIJUE
G mTURPd
END
cccccccccc~cccccccceeccccccecccccccccccceccccccccccccccccecccI:cccccccccc
SUBROUTINE P M = (P,XSP ,XMSN, X U X , UNfN I?IW,P m t PMIPJ] G relaxes the stream function (P) given previous P and vorticity (XSI) C on a lattice w i t h corners at XNIN,Xm,YMTH,VMAX; C returns nin, m x value of F in PMIN, P M
c~cccceccc~ccceccccceecceccccc~ceccccccccccccecccccccccccccccccccccccccc C Global variables:
INCLUDE * P A m . P 6 f C Passed variables:
RE& M&
P ( N X m ,M Y W )
XSI: ( N X W , WVmX) INmGER XMTN,Xm,YMI:N,YE3AX -&L, O W X , FMIM
C Local variables; IMTEGBR TX, I Y
!stream Eunetf on ( I l o f lvarticity (output) !edges of relaxing lattice (input) !min,max valve of P (output) tfatticc indices f temporary storage
R m L TEHP
cccccecccceCccI:cccc~cccccccccccccccceccccccccccccccccccccccccccccccccccc Prn=O. pm=@.
DO 100
zx
DC! 200 I Y = m W , IF ( B H D m (XZ,Et') EQ. 0) Tma
.
t reLax only noa-bmmd pofrsts
C
3H" (TUT .BQ, W - 1 ) E a H
I3uat b l e w top e*e
500
C. Programs for IRe Projects c IJf (XX .EQ. 2) TEIEET ! l e f C corner m e ~ I X ,XY-11 +P ( x x + ~ . XY) -XSX rm, Ir,+r P (IX, I Y ) =SwOA/z*=+MsONEF*P IIX, IY) I? (fX-l r I Y f IPP (IX, I Y ) P (IX-1, mjPliB (IX-1, I Y ) +1 ELSE flP (IX .EQ. NX-X) TEBZS f r i g h t cosnsr ieQ! (XX, IY-1) +a(XX-1, nc)-XSf (IX, I Y ) +Z p ( I X , I Y ) .rSw(;B/2*mww-*p (W, TYI P (m,r Y ) = P [IX, I Y ) P (rn,NY)ap (NX,I P ) + 1
fnot a sonaer
ELSE
!mmPg( I X , KY-1) +P (IX-1, I Y ) f P fIX+1,I Y ) -=I. P (nt,IY):mSMa*TEMP/3*blSONlbG*P END I F
E! (IX,NIC) =P) (SX, rY)+ l
33'
!top cadge given by b w d aond
tnat:
ELSE (XX
.=.2) TRWJ nP
m,
/a, nt)+I.
(WeI Y )
julpt
b a a v t o y , edge
?front edga
,XY41) +P f I X + l ,
.rU).LS /3lrnW**P P (IX-I., I Y ) e f I X , IY)
I T ) -XS3 (U[,IY)
(IX,rYI
ELSE I B ( I X .EQ. Wt-1) Hfel fbacrk edga ..P f I X , TY-1) 4P [(XX-I., X l f j 4P fXX, I Y + l ) -XSI (TX, SY) P ( I X , XY} = S O M E C i A / 3 * T W + H S m * P ( E X , IY) o (la, XY)=P (IX,M ) ELSE l i m t ~ t i o rpoint FEhOlieQ!( X X , SY-1)SP (XX*SP+l)+P (XX-1, I Y ) +B [IX+1, ST) - X S I ( I X , TP) P (TX,I Y ) wSOWgGAk E m KF
END W fE (B(M,XY) .OF, PWiX) P W * ( I X , S Y ) IF (P(IX,NY) .DT, Pb6AX) PW=E(XLX,m) IlrP (B(SX,EY) .LT. PMZS) P M l a P ( U C , f Y ) XF (P(TX,NY) .ST. EMlX) PMCN=F(a(,blY) C
200 100
END IF CONZfNoE
c-m RETURN
END CCCCCCCCCCCCCCCCCCCCcCCCCCCCcCCCCcCCCCCCCCCCcCCcCCCCCCccc~CccccCcccccccc SUBROUTINE VRELAX(P,XSI,XMIN,XMAX,YMIN,Y~X,XSIMAX,XSIMIN) C r e l a x e s the vorticity ( X S I ) given previous XSX and stream function (PI
C on a lattice defined by XNIN,XNAX,YMIN,Ym C return@ min, max value of X f I in XSIMIM, X S X m
ceecc~~~cceccccccccccccceecccecccccccccceecccccc~~cccccccccccce~ccceecec e Global variables: INCLUDE 'P W M . P 6' C Passed variables: MU P(NXW,NVm)
WEAL X S I (NXMAX, NYmX) INTEGERXMTN,X~,PMXN,V~X XSXM,XSJMIM C Local variables: INTEGER I X , SV REAZ TEHP, TEIVIPZ, TEMPS
?stream function (input) !vorticity (X/O! !sdgesof relaxing lattice (input] !max and min value of XST [~utput) !lattice Indices !temporary storage
c~e~cccccccecccCcecceccccccccccccccccccccccc~ccccccccccccc h a n a r y a@n&Lion.
20 C
rL@ng Lhe p Z a & r
G O M T I ~ W 30 ===M, D43 4 0 I Y = m H , m ( ~ w ~ e r r c l ( r x , r r ).SQ.
01
l &onpt re%= h d p i n t ; &
C
I P (ZYC .EQ. =-l) F=XSI (XZ, IY+T) +X91 (XX, m-2) 2 m M m 4 * (P (ZX,E#+%) -P (ZX, I Y - l ] ) *=X 3-m4+ (P ( r x + i , ZY) -P (IZ-i ZY 1)
BC [IX-l,I Y )
d.
+
) / (3+rnrn4* (P (ZX,
JZ+l)-P ( I X , I F - l )
C
E
+ + C
!i,nt%rAor poine
2m-=WD4* (P (IX, IY+1) -l? (XX, I Y - I ) ) * (XSI (IX+T,xT) -XSI (1X-3, ZY) ) 3-8-W=4* ('P (3CX+Z, f l)-E (IX-1, I Y ) ) * ( x s r j r x , r x + r ) -xsz ( X X , XY-1) ) X s I (IX, r u ) =voma/4n(
))
m S F I H (XSX (X%, XV)
IF
(XSZ (XX,IT)
.6T,
=I=)
XS
SI (IX,IY)
.LT, mnMliH) x S ~ % = X s Z ( Z X Xluc.) ,
C
40
30
Em m CQE%IEm COmIm RE"XIUR% EHD
eccceccccccccccccccccccccc~ccccecccccc~cccc~ccc~ccccecccecccC:ccccccccccc SUBROUTIUE ZNXT C initializes constants, displays header screen, C initializes menu arrays for input parameters
cccccccccC:cc~Cccecccccccceecceccccccecccccccccccccccceccccccccc~cccccccc C Global variables: INCLUDE * IQ.ALLt INCLUDE *mEIU.ALLr INCLUDE T N M . P 6 p
C Local parameters:
!program description
C H W C T E R * 8 0 DESCW DXNElNSION DESCRP (20) INTEGER NWMD,NmXT,NGWH
!number o f lines for each description
cc~ccc~ccceeccccccc~ccccccceccccceeccccceccccccccc~ccccccccccecccccccccc C
get environment parameters CALL SETUP
e display header screen DESCW (1)= PROJECT GC DESGRP(Z)= "2-8 viscous incompressible flow about a ' + //'rrectangular blockr NXmD=2
text output description DESCRP 13) = rmaximum vorticity and stream function,' DESCRP(4f 'ffotces at each iteratione DESCRP(5)- ' (all values are in scaled units)' NTEXTm5
graphics output description DESCRP ( 6 )= "trean function and vortieity* NGMPEI=I
CALL HEADER (DESCm, NHEAB,
NTEXT, NCRAPH }
PIRST=.TRUE.
!is this the first time through the menu?
set up constant part of -nu CALL MENU
item 9 has a different use in this program MTUPE t 91 mNTITL8 M P W P T ( 9 1 = @ 7 ) Change lattice size or end altogetherr
MXIOLIM (9) -0 NWILXM ( 9 ) =l d e f a u l t v a l u e s and l i m i t s o f n e x t 3 i t e m s a r e s e t i n s u b r a u t f n e LATTIC s i n c e t h e y depend an t h e s i z e o f l a t t i c e chosen MTWE (13)-NUN N P m T f l 3 ) = "nter h a l f - w i d t h o f p l a t e i n l a t t i c e spzlcings' MTAG(l3)= 'Half-width o f p l a t e i n l a t t i c e s p a c i n g s r MTmE (II ) =MUM MPWT (14)= ' E n t e r f e n g t h a f p l a t e i n l a t t i c e s g a c i n g s C MTAG(14)= 'Length o f p l a t e i n l a t t i c e s p a c i n g s l
MTVPE ( 1S ) -NUH MPWT ( l 5 1= ' E n t e r l a c a t i a n o f p l a t e f ' s f r o n t edge i n l a t t i c e s p a c f n g s " MTAE;IlS)= " ~ o a t i a n o f p l a t e M ' s f r o n t edge i n l a t t i e a s p a e i n g s "
+-
MTYPE (161 =FLOAT M P m T (16)= ' E n t e r l a t t i c e Reynofdt 9 number" MTAG f 16)= * L a t t i c e Reynoldl S n u d e r e MmLIM(16)=0.01 nszLxM (1s) =ao. L5(26)=lr MTUPE (17)=SRTP WmLS (17)-35. MTWE 4 3 8 ) -FLOAT N P m T ( 3 8 ) = ' E n t e r v o r t i e f t y r e l a x a t i o n parameter' MTAG (38) = 6 V o r t f e i t y r e l a x a t i o n p a r a m e t e r t MWLIM (38) PO. MRZLIM ( 3 8 ) -1.9 mmzs ( 3 8 ) = . 3 NTVPB ( 3 B) =FLOAT W m T (351)=. E n t e r stream f u n c t i o n r e l a x a t i o n parameterf MTAG (39) * Stream f u n c t i o n r e l a x a t i an parametere MLOLIN(39f -0, HMILIN (39) ==1.9 mmzs 1391a. 3
-
@
MTUPE ( I0) =NOSKfP m m T f401=@Dayou want t o s p e c i f y a s u b l a t t i c e to r e l a x f i r s t ? " MTAG (40)='R~efax a s u b l a t t i c e f g r s t ? ' HINTS (40) =O NRmLS (40)145, MTWE ( B 1 ) =NUN WMPT f 4 1 ) = + ' E n t e r lower l e f t X ( i n l a t t i c e s p a e i n g s f f o r s u b l a t t i c e ' MTAG (41)= % w e r l e f t X s u b l a t t i c e v a l u e "
504
C. Pmgmms for the P r ~ j e c f s
MTWE ( 42 1 -NUM m m T 142) = + *Enter lower l e f t V ( i n l a t t i c e spacings) f o r s u b l a t t i c e ' MT&G(42)=%~ower l e f t Y s u b l a t t i c e v a l u e f MLQLTM(42) =l MINTS (42) -1 MFYPE (4 3) =NUN M P m T ( 4 3 ) = t E n t e r upper r i g h t X value f o r s u b l a t t i c e ' MThG(93)~'Upper r i g h t X s u b l a t t i e e v a l u e C MLOLIM ( 431 -1 MINTS (43) =l MTUPE 14 4 1 =NUM lun?Mll"(48)=tEnter u p p e r r i g h t Y v a l u e far s s s b l a t t i c e r MTELG ( 4 4 ) Upper r i g h t U s u b l a t t i c e v a l u e ' MLOLLM ( 4 4 1 =l MINTS ( 4 4 ) =l MTYPE ( 4 S f =MTI TLE W W T ( 4 S ) = ' S t a r t i n g V a l u e s (far stream f u n c t i o n and V o r t i c i t y ) " MLOLXH ( 4 5 f m2 IUIMILIM (45) m 1
HTYPE ( 4 6 )=MTITLE MPmPT(46)=C1) Read i n s t a r t i n g v a l u e s from a f i f e " mOLIM (46)==Q M M I L I M (46)=@ MT"UPE ( 4 7 ) =MTITLE W W T ( 4 7 ) = = " 2 ) S e t v a l u e s t o free f l a w v a l u e s e NLOLZM (4 7 ) -0 MHILTM ( 4 7 f l0
MTVPE ( 4 8 1 =MTf TLE W W T (48)1 '33) Leave f i e l d v a l u e s unchangedp
MLOLIM (48) =0 MWILTW (481-0
MTWE (4 9)=MCHQIC m W T (4% = * E n t e r Choicep
MTAG(49)='50 51 51' MLOLIM ( 4 91 -1 MWILfM (491 =3 MINTS (49)a2 E?UREALS(49)=2
MTUPE (SO ) =CHSTR WmPT(SO1- "~nter name aE d a t a f i l e C
MTAGf50)m ' F i l e w i t h i n i t i a l v a l u e s f o r t h e fieldsf MHZLIM (501 =12. MINTS (SO) 4 3 . MSTRNG(MINTSf50))= v p x o j 6 . i n p C
MTYPE (511 =SKIP C
MSSRNG (HINTS(75)f
l
' p r o 3 6* t x t "
C MTWE ( 7 C ) =SKIP mmLS f 761 =80. C
MSTRHG (MINTS (86)l
prajG.grE1
C MTVPE (87 1 =NUM MPWT (87) = E n t e r the d i s p l a y f r e q u e n c y f a r t h e fi e l d s t MTAG(87)m * F i e l d d i s p l a y frequencye MLOLIM(87)= 1, MXILIM(87) = 100. MINTS(87)- 1 0 @
C MTmE ( 881 =NUN M e W T ( 8 8 ) - *Enter n u d e r of contour l e v e l s " MTIIC;(88)= 'Number of c o n t o u r l e v e l s " MLOLlM (88t l. MHIZXM ( 88 1 = PIAXLf;V MINTS {88)= 10
-
e NT"IIPE(89)=SKIP m a ~(ss) s -90. C RETURN END
cccccccccccccccccccccecccccccccccccccc~cccccccccccc~c~c~cccccc SUBROUTINE UTTIC C g e t 8 l a t t i c e s i z e from s c r e e n and e a l ~ u l a t e sb e s t way to d i s p l a y t h e
c f i e l d a s a s c i i c h a r a c t e r s based on l a t t i c e s i z e a n d t e r m i n a l size: C resets a l l boundary c o n d i t i o n s and d e f a u l t menu v a l u e s
ececCcccCccccccccccccccccccccccccccccccccccccccccccccccccc~ccccccccccccc C Global variables:
.
INCLUDE P A M P 6' INCLUDE 'XIQ,ALLp INCLUDE WIUIE .ALLr INCLUDE 'W . P 6 * C Local variables: INTEGER END INmGER IX, I Y , IBC INmGER NXWX,MYHI,NXLO,~LCI INTEGER NXDEF,MVDEF LOGXCAL RESET C Functions:
!end program f l a t t i e e i n d i c e s , BC index ! l i m i t s on l a t t i c e size !default l a t t i e a s i z e s !reset p a r a m e t e r s ?
506
C. Pmgmntsf~rtheProjects I N T E G E R VESMO, G E T I N T
!user input functions
LOGICAL W G C V T
cccccecccccccccecceccccccccccccccccccceceeeccccccceccccccccccccccccccccc C
allow user to end the program CALL CLEAR IF (.NOT, F I R S T ) THEN END=YESNO(Orf Do you want to end the I F (EWD .Ea. 1) CALL F I N X S H ELSE
C C
G
the lattice size is determined by array size and terminal size; if you8re using graphics, taxmina1 size wonCt matter set NXWS-MX-X and N Y H I = N Y m NXHT=HXN(TWID-2,NXmX) NYHX=MIN (TWLSN-3, N Y M X f NXDEF=NIE (NXHI ,201 NYBEF=MIN (NYHI, 20) NXLO=MIN f S, NXmE ) NVLO=MTN ( 5 , MYBEE) END TP
C C
get lattice parameters from the terminal NX-GETINT(NXDEF,NXLQ,NXBS,* Enter nu-r af X lattice pointsr) NV=GETSMT[NYDEF,NYL0,NYEZI6 Enter nuhar o f Y lattice paints') NXDEF=NX NYDEFmNY
C C
calculate parameters Ear best looking display I F (2*NX .LE, T R W I D Z THEN XSKIP=.TRUE. !skip spaces in x XCNTR=(TRMZB-2*NX1/2 !hew to center display ELSE X S R I P m . FALSE. XCMTR- ( T R m x a - N x w END I F I F (XCNTR .LT. I) XCNTR-l
C
I F (2*NV *LE* T M L I N - 3 f THEN YSKIB-,TRUE. YCNTR=fTRMLIN-2*NY)/2-2 ELSE YSRSP=,FALSE. YCMTR= (TMLZM-NV) /2-2 END I F I F (YCNTR .LT. O f YCNTR-O
!skip lines in y !how to canter display
e C
set up default and limits for the plate location and geometry MHf L I M ( X H I D f =NU
MLQZIM ($MID)-2 Hrl.srs
tawraj -mx [ ~ , N E ! / ~ I
MHELEM (ZLENI=NX MLQLfM ( S L E N J =O M I N T S (IEENf=MX/ 4
MNILIM (IFRNTI =MX MLOLTM ( TFRNT ) -3 MINTS ( rPRUT 1 =mx(1,~ ~ 1 3 f
C C
set up limits on sublattice MHZLf W (IWXLL) =NX MHZLIM (INYLLI =NY NWILXM ( INXm)=NX MNILfN (INYOR) =W MINTS (4If=I
f sublattice X, !sublattice y , !sublattice X, !sublattice y,
MINTS (421-3 MINTS (431-1 MINTS 1441-1
loner lower upper lower
left left right left
C C
allow Ear resetting of defaults IF (FIRST) TWEM FIRST=.FACSE, ELSE MSET=LOGCVT(VESNO(Otf I F ( M S E T ) THEN MMALS (15)=1. MmALS (38) m0.3 mE&LS(31)) =O. 3 MXNTS (40)=Q MSTRNG [MINTS (SO)) = MSTRMG (MTNTS (75) ) = MSTRNG (MINTS (86) ) MINTS ( 8 7 ) 10 MfMT5 (88) 30 MINTS (49112
-
MINTS ( 7 3 ) =TXTTRM MINTS (74) -TXTFXL MINTS (83) =GRFTM MINTS 48 4 ) =GRFMRD MSNTS (85)=GIIF"PIL END I F END 3E"
-
Do you want to reset default val~es?~)f) !Reynolds nunber
!vorticity relaxation ! strem relaxation
!no sublattice 'proj6,int !input file "raj6 txt* !text f i l e proj6.grf * !!graphics file !graphing frepency !nu&er of contours ! start from free ! streaming values !default ilo
C
=TURN END
Cec~cCccccceceecccceccccC:cccccccececeeccccCccccCc~cc~cccccccccccc~cccc~c gets parameters from screen ends program on rewest closes old files naps mnu variables to program variables opens new files C calculates all derivative parameters C performs checks an sublattice parameters C set the field to its initial values (P,XSI) G and controls ending aE program (EMD) C G C C C
608
C.Pmgmms for $Be Projec;ts ccCCccCceccccccccccccccecccccccccceccccccccccccccccecccceccceccceccccccc C CZobal v a r i a b l e s : INCLUDE "NU. ALL" INCLUDE @1IO.ALLt INCLUDE @P=M.P6@ INCLUDE 'MM?. P 6C C I n p u t l o u t p u t variables: MAL P (MXmX, N V W ) RE&XSI(NXmX,NUW) LOGICAL END C Loeal variables: INTEGER IX, ZY C Punctlons: LOGICAL LOGGVT INmCER GETINT
Istram E u n c t l o n
!vorticity land program? l l a t t i e s indices ! c o n v e r t s 1 and O t o t r u e a n d false ! g a t i n t e g e r Exam s c r e e n
ccc~ccc~c~~cC~~ccc~cc~ccceccE:~cccce~ccccecccece~cccccecc~cccceccc C
get input f r o m t e r m i n a l CA& C W R CA& BSR(l, 1STQfZ.I
C C
s t a r t f r e s h o r e n d a l t o g e t h e r , i f so reguasted I F ( m A L S ( I M I N ) .Ea. EMD=.TROE. RETURN END TF
STOP)
THEN
C C
c C
close f i l e s i f n e c e s s a r y I F f T N m .NE. MSTRNG (MINTS (ITNAME) 1 1 + CALL FLCLOS ( T H W , TUNXT) physical a n d n u m e r i c a l parameters RmID-MXNTS (XWXDI LENGTW=NINTS (SLEN) FROMT=MINTS (XFRNT 1 MYMLD=WALS (IRNLDS 1 V O a a = M A L S ( IVIOmC;) SQmGh=WALS(XSOmG) SUB~T=WGC~T (ISUB) t NXUrMINTS f INXLL f MY&-MINTS (INYLL) N X m 4 I N T S (XEIXUR) NPm=MIMTS ( IMVUR) PTYPE=~S (MREnLs ( IPTVPEI 1 PPILE=MSTREaG (MXHTS I S P F I ~ I I
C C
C C
text o u t p u t TTERHmLOGCVT (MINTS ( ITTERM) 1 TPILE=LWCVT [MINTS ( I T F P t & l l TNMBmMSTRHG (MINTS ( I m M l l graphics output GTERNmLOGCVT (MXNTS ( ZGTERM] f
c W m c P = L a c C v T ( H r N a s t I G M t ~1
GFXLE=L~GCVT~MXMT~~TGFXLE~I~ G N m = M S T R M G ( M I H T S (XGHAMI5 1 1 NFREQ=MXNTS ( I H F m Q ) NLEVzMINTS ( IMLEV) G C
openfiles I F ( T F I L E ) CALL FWPEN (TNAm, T W I T ) l fAles may have been renamed MSTRNC (MINTS ( I TBAm 1 )
e C 39
40
check sublattice parameters fF ( ( N X L L .GT, NXUR) .QR. (NVLL .GT.
NYUR)) THEN m X T E (OUWfT, 40) CALL R S X 1 4 1 , 4 4 ) NXLLmMINTS ( I N X L L ) NYLLMIMTS (INYLL) MXUR=MIMTS (INXUR) NVUR=MIMTS ( T N Y m ) GOT0 39 END I F F Q W T (' Sublattice parameters must have upper right values
+
"
'greater than lawer leftf1
CALL CLEAR
C C
calculate derivative quantities BAGX;=FROHT+~NGTW-l I F (BACK .GT, MX) BAGK=NX
!make sure bloek doesnit extend too far
MV~G=l.-VQ~GA
MSWG=I,-SQmGA REYND4=='1THLD/4 C
CALL I N T C H D ( P , X S I I
C C C
!get starting values
reset PTUPE menu parameters so that P remains unchanged during runs unless the user explicitly rewests otherwise M I N T S (IPTVPE) m 3 M A L S ( E P T U P E ) -3
C
RETURN
END
cc~cccccceccccccccc~cccccccceececccccccccccceeccccececccceccccccccF=ccccI: SUBROUTTME I M T C N D ( P , X S I )
C get starting values for stream funetion (P) and vorticAty ( X S X ) C and set boundary conditions fn BNDGND, depending on plate location
~ccccecceecccc~cccccececcccccccccccccccccececceccccccccccccccccccF=cccccc C Global variables: INCLUDE
p
.
P m M P 6'
C Outpt variables: R E U P( r J X m , N Y m ) W& X S I I N X m X , N Y W ) C Local variables:
INTEGER IX, TY ! f a t t i e @ indices CCCCCCCCCCCCCCCCCeGCCGCCCCCCCCCCCCCCCCGCCCCCCCCCCCGCGGCCCCCCCCCCCCCCCCCC e .et P C@ A+# idrcu vaima
fB ( P m E .E
in
fxaalf &&I
i. ohmgad DO 60 m m 1 , a M) 70 X%=%, '1SY
(m,
74 50
to fm 8k~8- ~ 8 3 ~ ~ 8
!.at (XY-1)
ImI. ( S X , 3x1-0. Crn%Xrn
@bMmW
mm
nP ( P m $ .acQ. 5 )
"rm
CaBZxm
gm ra' C C
xelrare px8wAou. DO SI XX-l,rn DO
rx, m)no, 71 63.
CWTXm
C m Z m e d i t i o n * on plaCe $&age
am-
U&
Iatt;icl+ mdger =I@&m d p axe ~
(l,11)=l Bmm (m, 3Y)=l !U-=
a&
%OW(IE
. 8
?+@p oi g&&&@ I8
!froat m4 llJ& l?
(mm,3x1-0
*
-1
RETURN END
OF plate
IZNI
cccccecccceccceecce~ccccccccccccceceececcccccccccccceecc~ceccc~ccccccccc SUBROUTINE m&BXM (P,XSI) C r e a d i n s t r e a m f u n c t i o n P and v o r t i c i t y XSI from E i l e w r i t t e n C by s & r a u t i n e mTOUT; f i l e s must have same l a t t i c e parameters CCCCGGCCCCCCCCCCCGGCCCC:~CGCCGCCCCCCCCGCCCCCCCCCC~CCCC~CGCCCCCCCCCCGGCCCC
C Global v a r i a b l e s :
INCLUDE INCLUDE INCLUDE INCLUDE
'IQ.ALLt P a N . P6' * mNU. ALL" %P, P6 " @
C Output v a r i a b l e s :
REAL P ( N X m ,ldlrlw) REAL XSI (NXNAX,N Y m )
!stream f u n c t i o n !v o r l i c i t g
G Local v a r i a b l e s :
IMmGER CH-CTER* LOGICAL INTEGER INTEGER C
IXcIY 8 0 JUNK SUCESS CNQIGE, YESNO MX ,MY, MOmGA
Function: CHWGTER*4l? GMWC
! l a t t i c e Indices !Eirst l i n e i f of no i n t e r e s t ! d i d w e f i n d a f i l e t o open? ! g e t yesno i n p u t from u s e r !parameters from PFILE freturns character input
eccCceccc~cccccc~ceeeecceccccccccccecccceccccccC:cccecceececcc~ccc~cc~cc~ 50
CALL PLQZ"N2(PFILE,DUNIT@SUCESS) MSTRNG (MINTS(IPPXM)1 =PFILE
!open t h e f i l e f o r i n p u t ! f i l e may have been renamed
IF (*NOT. SUCESS) THEN GALL REASK RETURN ELSE
?prompt again f o r i n i t P ! i f na f i f e was found
C
c =AD (DUNIT,S ) JUNK READ (DUNIT,S) ;TUEtffC FORmT (A]
5 G C
! s k i p over t i t l e
l a t t i c e s i z e s must match: i f they d a n f t t , allow f o r o t h e r o p t i o n s * f MX, MY IF ( ( m .NE. NX) .OR. (NV .NE. MY)) THEN CALL FLCmS (PFILE,DUNIT) ! c l o s e it: up WRITE (OUNIT,2-51 MX, MY FORmT ( @ Input f i l e has does n o t have t h e c o r r e c t r l a t t i c e s i z e , it i s "12, * by "12) CNOIGE=VESNOfl,C Do you want t a t r y another f i l e ? ' )
W A D (DUNIT,
15
+
ra
(caaxcE .EQ, 01 THEN CALL MASK
!prompt a g a i n f o r l n i t P
MTURN
ELSE PE'ILE=CKZImC(PFTLE,12, ' E n t e r a n o t h e r f i l e n a m e * ) MSTRNG fMZEtfTS{IPPXLE)) =PFILE GOTO 10 ! t r y t o open t h i s one END SE' END IF
512
C. Programs for $he Projects C C
i f wetve qgotten t h i s f a r , we've opened a f i l e with d a t a from a l a t t i c e of t h e same s i z e ; f i n a l l y r e a d i n f f e l d !skip over parameter v a l u e s READ (DUNIT, S J ;J"UWK READ (DUNIT,S ) JUW READ (DUNIT,$) SUNK
C 100 ~ x = i , ~ x READ (DUMIS, 3.10) (P ( I X , I Y ) ,I V - 1 , NU) CONTINUE ao 200 IX=I,NX =AD (DUNIT, 1101 (XSI (XX, I Y ) ,IY=Z,NY) CONTINUE FORNaT (5(2X,1PE14.7)) GALL FLCZOS (PFTLE, BUNIT) !close f i l e END I F
aa
100
200 110
C
RETURN END
cccccc~ccecccccccccecccccccceccccccccecccceccccceccccecccccccccccccccccc SUBROUTINE REASK C prompt again f o r i n i t i a l P,XSI c o n f i w r a t i o n ; C c a l l e d only i f r e a d i n g i n from a f i l e I s request: and f a i l e d [email protected]~CCCCCCCCCCCCCCC
C Gfakal v a r i a b l e s : INCLUDE P =W. ALLt INCLUDE 'mP.P6' INaUDE ' P A W . P 6*
ccccccec~ccccccc"cccceecccccccccccccc~cccccccccccecccccce~ccccC:cecceC:ccc C
r e d i s p l a y i n i t i a l F i e l d Value Menu, b u t d i s a l l o w c h o i c e I
m W P T ( 4 6)=' 1) (not a f lowad) " MLOLIM ( 4 8) =2 MINTS ( 4 9 ) m2
mmLS (49)m 2 CALL ASK(45,51)
C PTWE==S ( M ~ L S(XPTYPEH
!set p a r a m t e r c h o i c e s
e Read i n s t a r t i n g v a l u e s from a f i l e t WMPT (46) -'l.] MmLTN 149) =l
t reset menu
C RETURN END
cc~~~c~~~cc~e~~~c~ccccec~ccc~cccccc~ecccccccccccccce~cccc SUBROUTINE PWOUT(MUNXS,NLINES) C w r i t e out parameter s u m a r y of l e n g t h NLINES t o NUNST
~~c~c~~~ce~~ccccccccccccc~cccc~ccccccc~ceccccc~ecccc~cccccc~c C Global v a r i a b l e s : INCLUDE I O . ALLf INCLUDE PAMM. 9 6" C Input v a r i a b l e s :
'
@
INTEGER MUNIT INmGER NLIMES
! f o r t r a n u n i t nurriber ! n d s r of l i n e s sent t o t e r m i n a l (I/O)
e~~~~e~~~~cc~~~eccc~c~~ccccccceccccccccc~cccc~~cccccceccccccc I F (NUNST .EQ. OUNIT) CALL CLEAR C
HRXTE (MUHIT, S 1 mITE (MUNIK 6 ) I F (MUNIT .NE. GUNIT) THEN mZI"E {MUNIT,10) NX,W ELSE WRITE ( M U N I T,* ) EX, NY END I F mITE (MWMIT,20) VOmC;II,SOMEGA WRITE (NUNIT, 30) WWID, UNGTW, mONT WRITE (MUNXT, 401 mVNLD I F (SUBLBT) W f TE {MUWIT, 4 5) NXLL, NYLL, NXUR, MYUR
c I F (NtMJIT .NE. GWIT] THEN NRITE (MUNIT,*) ' ' WBTTE; (NNITI 50) mITE (MUPaXT,6Of mITE (mMTT, 70) END I F
c EILTNES-8 IF (SUBZAT) NLXNES=NLLEES+l G F Q m T ( w t p u t from p r o j e e t 1 FQ-T f r 2-D v i s c o u s incompressible*
5 6
"low around a r e c t a n m l a r b l a c k * ) F O m T ( " NX m f ,I3,5X, "#Y = I , I31 F O W T ( * V a r t i e i t y r e l a x a t i o n = *p,F"S.3,SX,*SSrem r e l a x a t i o n = i F5.3) FOmT P l a t e h a l f width=', X3, 5X, ' langlth=@13,5X, C and f r a n t edge4 LT3 1 FOWT ( C Latticc;Reynald*p"snu&er=y,,F7.3) F O M T (C Sublatticedefinedkty (t,,13,t,\131V and t C r + 13,t,'I13p'}'! F O M T ( 3 X , ' l e e r t , $X, * P r e s s u r e r c e V i ~ c a l~l X~r tr V o r t i c i t y y, -t 10X, Stream Function' ) F Q M T (12X, * Forcef I 9XI Foreet 13XP min, maxf ,1,5Xt *mintmax*1 (3X, G---" ,4X, *--------I, @, t ' ,,11X, 8 ---------F FO-T i
10 20 30
',
@
40 45
50
60 70
a,
-------
+
~ Q X r, ---------------P
f
c RETURM END GCCGCCCCCCCCCCCCGCCGCCCCCCCCCCCCGCCCCCC~CCCCCCCGC~CCCCGCCCCGCCCCCC~CCCCC SUBROUTINE
+ TXTOUT(NUNIT,NIT1ER,WORCEIPFORCE,XSX~X~P~XIXSIMTPaIPMZN,NtINES~ C ouctwt f a r c e s and min, max f i e l d v a l u e s t a MUNIT CCCCCCCCCGCCCCCGCCCCCCCGCCCCCCCCCCGCCCCCC~GCCCCCCCCCeCGCCCCCCCCCCCGCCCCC C Global v a r i a b l e s :
INCLUDE *IQ.ALL" C Input variables:
514
C. Pmgmms for the Projects INTEGER NITER !number of iterations REAL VFORCE,PFORCE !viscous force and pressure REAL XSIMAX,PMAX, XSIMIN,PMIN 1min, max values of XSZ, P INTEGER MUNIF !fortran unit number INTEGER NLIUES !number of lines sent to terminal(f/O) CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCcCCCCCCCCCCCCCCCCCCCCCCCCcCCCCCCCCCCCCCCCC C
if screen is full, clear screen and retype headings IF ( (MOP(NLIMES,TRMLIM-6) .EQ. 0) + .AND. (MUNIT .EQ. OUPIIT)) THEN CALL PAUSE(*to continue...*,l) CALL CLEAR BORITE (HUNIT,SO) WRITE (MUNIT,60) WRITE (MUNIT,70) END IF
c IF (MUNIT .EQ, OUNIT) NLINES=NLlNES+l WRITE (MUNXT,40) ~TER,PFORCE,WORCE,XSIMfN,XS~,PMIN,P14AX C 40 50
60 70
FORMAT (2X,15,2 (ZX, 1PE12- 5 ) ,2X, 4 (1PE10 3, 1x1 1
FORWLT ( 3 X , *Iterf,4Xf'Pressuref,6 X I *Viscousf llX, * VorticityO
+
10X, "Stream
FunctionF
FORMAT (12X, 'Forcef,9X, *Forcet 13X, *minemaxf,15Xftnin,ntitx'
FORMAT (3X,'----f, 4X, * 10X,f---------------'
m, -------* f
,11X, r
---------*
+
C RETURN END C C C C C C C C C C C C C C C C C C c C C c C c C C C C C C C C C C C C c C C c
SUEROUTIPIE DISPLY (F,MUNIT, ITYPE,FMAX, FMIN) C display stream function (P,ITME-STREAM) or vorticity C (XSI,ITYPE=VRTCTY) as letters; positive values are capitals or C numbers, nwative values are small letters CCC~CCCCCCCcCCCCcccCCCCCCCCCCCCCCCCCcCCC~cccccccccccccccccccccccccccccc C Global variables: , TNCLUDE PARAM.P6* XNCLUDE * 10 ALL' C Input variables: !stream function or vorticity RFZAL F(NXMAX,WYMAX) lunit wefre writing to INTEGER MUNIT !which field are we dfsplaying? INTEGER ITYPE f min and max field values REAL FMAXIFMIN c Local variables: INTEGER IX, IY !lattice indices INTEGER TEMP !field at current lattice site CHARACTER*1 FIELD (NXMAXl !field as character data !blanks for centering in X CHARACTER*80 BLNK CHARACTER*X AsKII (0: 35) ,NEGASK (12 6 ) f charac 'data for display DATA BLNK / * ' / DATA ~ ~ ~ 1 1 / ' 0 ' ~ * 1 ~ ~ * 2 ' ~ * 3 ' , ' 4 * ~ * 5 ' ~ * 6 * ~ ' 7 * ~ ~ 8 ' ~ ~ ~ ~ ~ + ~A~,~B*,*C*~~D~,*E~~~F~,~G~,*I.I*,*I~,~S 4. ~ ~ ~ , * Q ~ , * ~ ~ , * Q * , * R * , * S ~ , * T ~ , ~ U ~ , * VI*f,Y**W,*f,Z'*X/ *
+
DAT& MEGASK/*afc % b ' , f e ~ ~ d ~ , f e 1 , @ f * t t g 6 , f h f , r i t t ~ j f t f k t , e l p , ' m f ,
r n r r r o * , t p p " , ~ q ' ~ ~ ~ ~ , ' s C I ' t t , ' ~ ~ ,Cf z* '~/ l , t ~ ~ , t x ~ , ~
cecccc~c~ececee~c~ccC:ccccccccccccccceeeeccccccceccec~ceccccccc~~ccccc~c
20
IF (MUNIT .EQ, OUNST) T m M DO 20 XY=T,YaTR !canter output WRITE (OUNIT,*) ' GQNTXNUE ELSE ?or display which f i e l d IF (TTVPE ,&Q. S T W M ) WRITE fMUHITIX)* stream function:' IF (ITPPE .EQ. WTGTY) mSTE (MUNIT,*) "vorticity:' END IF
C
C
50 C C
DQ 180 IU=NV,l,-1 DQ 50 IX-1,NX ZF (FfZX,SV).GE. 8) THEM IF (F= .NE* O) THEN TEW-NIWT (F(IX,IYf*35/FMAX} !seafe field ELSE TENPmO, EPlrD IF !convert to a s c f i FIELD (IX)=ASKIX (TEMP) ELSE SF (FMXM .ME, O) THEN TEW-MINT (F( I X , 1% *26/FMXNf ? scale f i e l d ELSE TEem0 END IF SF {TB= .NE. 0) THEN !convert to a s c i i FIELD (SX)=NEGASR (TEW) ELSE FXELDf sx t =&SKI I ( T e r n END %F END IF leave blanks to Indicate the plate sa (swacao tzx, -EQ. 21 FIELD (3x1=ELM (1:1) CCIETTNVE
rw
write out a line at a time (no centering done for TUNIT) IF (NUNIT .EQ, TUWXT) TWEN VIRJm (TUNIT,16) (FIELD(XXf,XX=J.,m 1 ELSE
XF (XSKXP) THEN liJRXTE (OUNIT,IO) BLHK 41 :XCMTR), (FIELD( I X ) ,PX=l,NX) ELSE
10 15 l6
WRITE (OUNIT,15) BLNX (1:XCNTR) , (FXELDtIX1,IX=1,NX) END IF XF (VSXTP) MRITE (OUNIT,*) * p END IF F O W T (1X,A,100 (AI,1x1 ) FO-T f lX,A, 108 (All) F O m T (lXrlOO(A1))
5 l6
C. Pmgrrrms for $We Projects 100
CONTINUE
e RETURN END
cccccccccccccccccceccccecccceccccccccececccccccccccccccccccc~ccccccccccc" SUBROUTINE GRFQUT~DEVICE,FIELD,F,FMXN~FMAX,E"GW,MX,MV~ C d i s p l a y c o n t o u r s o f t h e s c a l e d s t f e a m f u n c t i o n P and v a r t i ~ i t yPSI C t a DEVICE C t h e f i e l d v a l u e s must b e i n an a r r a y that i s e x a c t l y NX by NY;
C C
t h i s c a n b e a c e o w l i s h e d w i t h imlieit dimensioning which r e q u i r e s t h a t FGRF and i t s d i n e n s i a n s be p a s s e d t o t h i s r o u t i n e
ccceccccccccccccccececccccccccccceccccccccccccccecccccccf:cccecccC=cC:ceccc C Global v a r i a b l e s :
INCLUDE "Q,ALL* INCLUDE
* GRPDAT .&L"
C Input variables:
INTEGER MX, W
FGRF (MX ,MY 1 mAL PMIN,FW INTEGER FIELD C Local v a r i a b l e s : IMTECER SCREEN INTEGER PAPER INTEGER FILE INTEGER I X , l Y REAL PX ( 4 1 ,PV ( 4 1 eHmCTER*S CNIN,CWX,mY INTEGER LMLM, LMX, RLEN DATA SCRE&N,PABER,FILe/l12,3i DATA VRTCTY, STmAM /1,2/
t whf ch d e v i c e !f i e l d !NX and NV i n d i s g u i s e !f i e l d f a r g r a p h i n g !min, max f i e l d v a l u e s !which f i e l d
Isend t c t e m i n a l !make a hardcapy !send t o a f i l e ! l e v e l index, l a t t i c e i n d i c e s [ e d g e s of plate f o r g r a p h i n g !data as c h a r a c t e r s ! l e n g t h of s t r i n g
eccccc~Ccccccccccccec~cccccccccccccccecccccccccccccccccecccccc~ceececccc
15 3.0
DO 20 EX=%, MX DO 15 IY-1,W FGRF ( I X , I Y 1 =F [IX, IU) CONTINUE CQPJTINUE
! f a a d field i n t o FGW
c C
C C
messages f o r t h e i m p a t i e n t I F ( (DEVICE .WE, SCMEN) .AMD. (FIELD + WRITE (QUNIT,1001
.EQ,
STmMj 1
c a l c u l a t e p a r a m t e r s far g r a p h i n g NPmT=2 !how many p l a t s
C
YW--MY
VMXN-1. XMINm1.
XW-MX YOVBL=XXIAI
XOVALmVNXN NXTICKm5 NY TICKm5 EPOINT=5
W E L (1)= FNX' -&EL (21 m' NYr GALL C O m T [FMIW,CNIN,WIN) CALL C O m T f F W ,C m , L M X 1 CALL CQWRT (RIEYNLD,C m U ,RLEN) IF (FTELD .EQ. STmM) THEN 'IDLQT=1 TNFO=fPmin-*//CMX#(l%LMXNf/ / I Pmax='/l/CmX(l:LmX) ELSE IF [FIELD .EQ. VRTCTP) TWEN IPLOT-2 rNFo=fXsInin=~//CMrN(l:LMIIV~//C XsZrna~=~ //CmX(l:Lm) END XF TXTLE=fSStxeam F u n c t i a n and Vorticity, R@gmoldfls n u d e r -' 3. //GREY (1:RmN)
.
IF (FIELD .EQ. STWAM) THEN CALL GTDEV (DEVXCE) !device namfnatlon IF (DEVXCE .EQ. SCREEN) CALL GHODE ?change to graphics mode END IF CALL LNLINAX idraw axes draw in plate 15 i t ' s big enough
IF [LENGTH .GT. 21 TWEN PX 4 1) =REAL (FRONT+I) PY(11-1. ax(aj=Px(l) PU ( 2 )=REAL (HFWXD-1) PX ( 3 ) =REAL (BACK-lf PY f 3) =PY (2) PX (4j=PX ( 3 ) aY(4)=n* EaPOINT=4 ILXMEm2 CALL XYPLOT (PX,PY) END IF
CALL COMTOR(FGRF,mem,FMINIFMAX,NUV) end graphing session sa tPrnazD .&Q. VRTCTY) THEN TF (DEVICE .ME. FTLE) GALL GPAGE(BEVZCE) IF (DEVXCE .EQ. SCREEN) CALL TX"lODE END IF Fa-T
RETURN
!and graphics package !switch to text mode
(I,' Paatience, please; output going ta a f i l e . * )
C. Pmgrans for the Projects
528
END
ccccccececcccccccccccccccccccccccccccccccccccccccccccccceecccccccccccccc SUMQUTINE mTQUT(P, XST 1 C write out stream f u n c t i o n (P) and v o r t i c i t y (XSI) t o GUNIT for reading C back i n as i n i t i a l c o n d i t i o n s ox for g r q h i n g w i t h an e x t e r n a l packaqe
ccccCccceccccececccccccccccccccccccccccccccccccccccccc~cccc~cccccccccccc C Global v a r i a b l e s :
INCLUDE '2IIENU. ALLt INCLUDE ' f O.ALL' f NCLUDE " PAmM, P S" C Input variables: REAL P ( N X M X , N Y M ) WAL XSI ( N X m , M C Local v a r i a b l e s : INTEGER I X , ZY INmGER NLIMES
!stream f u n c t i o n f vorticity ! l a t t i c e indices ! n u h r o f lines written t o f i l e
c~cccccccccecccccccccccccccccccccccccccccccccc"ccccccccceccccc"ccccccccccc CALL FLOPEN (GNANE, GUNXT) MSmBG (MINTS (XGBAM) t =GN;Am CALL PMQIIT(GUMIT, NLINES)
!open f i l e ! n a m may have changed ! w r i t e o u t header
C
DO 3.00 I X m 1 , N X 100
206 l0
WRITE (GUNIT, 10) [P( I X , I Y ),lY=l., MW CONTINUE DO 200 I X - 1 , WX m T T E (GUMIT, 10) (XSI ( I X , SY) ,IY=L, NY) CQNTINUB F O m T (5( 2 X , lPE34,?) ) CALL FLCLOS (GNAm, GUNfT)
C =TURN
END
ccccccccecccccccccc~cccccccecccccccccccccccccccccccceccccccc6rccccccccccc c c e c e c c c e c c c c c c c c c c e c c c c c c c c c e c c c c c C. paran.p6 C
IMmGER HXPIAX, NVmX !=ximm l a t t i c e size P A R A ~ T B R t~xmx-z00, Nrmx=ioo ) ZMTEGER W L E V Imaxlmum nu&er of contour l e v e l s PAMmTER (MXLEV=20) INTEGER VRTCTU, STREAM !d i s p l a y f l a g s
e LOGICAL FIRST IMTEGER NX, NV REAL VOmC;I1 m& SOMEGA REAL PIPVOmG RE& MSOMEG INmGER HFWID INTEGER LENGTH INaGER FRONT INTEGER BACK
!f i r s t t i m e through menu? !lattice size ! v o r t f c P t y r e l a x a t i o n parameter !stream r e l a x a t i o n parameter !one minus v a r t omega !one minus s t r e a m omga ! h a l f width of p l a t e ! l e n g t h o f plate ! f r o n t edge o f p l a t e !back edge a f p l a t a
M&
WMLD REAL REYND4
! l a t t i c e Reynolds nuniber tReynolds nurnber / 4
INmGER PTYPE CBmCTER*12 PFILE LOGICAL S U B U T INTEGER NXLL,NIILL,NXUR,NYUR
!choice f o r i n i t i a l f i e l d ! f i l e t o input i n i t d a t a !is t h e s e a s u b l a t t i c e ? !sublattice prameters
INTEGER NFREQ INT'&C;;ER NLEV
!frequency a f display !nu&er o f contour Levels
c
C
c
!flag t o i n d i c a t e bound @and lmboundary; 2c1plate i n t e r i o r
INTEGER BHDGND (N t0-at a boundary; G
!skip spaces o r l i n e s i n display !how t o @ e n t e r display
LOGICAL XSKXP,VSKIP INmGER XCHTR, YCNTR
c CQmON CQMQN COWON COMQN
/ FxdG 'i FIRST / P P M M / NX,NY,REYNLB f N P A W / VOMEM, SQmGA, SUBmT, mLLI NYLL, NXURI NYURI P T W E / B C P M / BNDCND,HmXD,mMGTW,FRQNT
,MTOMEG p
I NSOWG, REYND4 NFmO, XSKIP, YSRZP, XCNTR, YeNTR
Ccccccccccccccccccccccccccceceeececcccccccccccccccceccccccceeecccccccccc ec~ccce~c~cccccccccccccecccccccccccccccceccccccce~ccccccccC:ecccccc~ccccc C!
map-p6 INTEGER IITD,Z~N~SFREJT,IREILDSffIVONEG,ISOMEG INTEGER XSUB, IMXLLr XNYLL, INXUR, INVURI XPTPPE, I F F I L E INTEGER I N F R E Q , I m V TER (IFIID 13 ) TER (XLEN 14 ) 'PER (IFRPIT 15 f P & m m T E R (IIINLDS 16 ) TER f XVOMEG = 38 f TER (ZSOMEG 39 f P-MTER (ISUB = 40 ) P m M E T E R (INXLL 91 ) P m m T E R f IMVLL = 42 f P m M E T E R ( I N X W = 43 ) P W m T E R (TNVUR = 44 ) e a m m T E R (IPTYPE = 99 ) P A M W T E R ( I P F I m 1 50 ) F m m T E R (INFREQ = 87 ) PAmmTER (IMLEV = 88 ) ;.F
-
520
6,Pmgranas for the E"r0jeet;s
C.7 Project 7 AILgorithm This program d v e s the non-line= reaction-digusion equa-
tions of the Brusselator [Eqs. (VII.3)] in two dimensions (0 5 2 5 1 and O y 5 1) with no-Rux boundary conditions. You can make the problem one-dimensiod by setting BP= 1 (if you set EX= 1 instead, the reaction terms are lwt? and it become8 a simple diffusion problem). Initial conditions for the X and Y eoncentratio~sare taken to be random fiuctuzl;tions about their equiiibrium values (DO loop 5 in subroutine mceor). Time evolution (DOloop 20 in ARCHOH) is then carried out by the alternatingdirection method (7.19 along with 7.1 1-7.16) in subroutine EV~LVE.Note that some of the coeficie~tsreqered for the inversiQns of the tri-diagond matrices are calculated only once for eaeh d u e of D%"(subroutine m r l c and between lines 10 and 15 in subroutine n~caor).Every I I S T E P ' ~iter~ at;i~n,you haw the option to continue &eration@,&mge DT or ISTEP, or return, to the main menu, Note that X and Y refer both to species and direction (horizontal or verticd); if they appear twice (e.g., BETIIXX) the first reference is to the species, the wcond ti, the direction; if they q p e w once, the meadng should be clear from the context.
<
Input The physical parameters are the concentrations of A [2.] and B [4.], diffusion constants for X species [.001] and Y species [.003], and the size of the initial fluctuations for X spedes [.Q11 and Y species [.01]. All &es are scded as described in the t a t , Mter leaving the mafin mean, subroutine SVGGSTcdculates and displays limiting vdaes of B b a ~ e don the linear stability analysis presented in the text (e.g., what values of B give stable or unstable oscillations). You are then given an opportunity to revise your value of B based on this information. The program will also calculate and display the frequencies (VII.10) for the largest and smallest m values (these limits are based on boundary conditions and lattice size). The numerical parameters are the number of lattice points in s [20] and y [20] directions and the random number seed used for the initial Buctuations. The maximum number of r points is fixed by M== 79 and y points by HAZY= 20. These Emits are to ensure that the character display of the concentrations will fit on the typical screen, which is 24 lines long aad 80 characters wide. If you are using graphics, or y ~ m ter 24 X 80, you can adjust these parameters. The graphics parameter is the number of contours for plotting the concentrations and is used only if you have graphics. After you have left the main menu, you will be prompted for the time step [.Q?'], the number of steps (*STEP) until you can end the
iterations, and the frequency for display of the concentrations (BFREQ). Uou sho~ldchoose the time step so that the highest mode described by the lattice &Rases little during one time step. Note that the default random number seed is a large integer (547651. Compilers differ in how many bytes they use to store integers. If your compiler &lows two or four bytes for integers, choose the four byte option. If your compiler only allows two bytes, then you must change the default, high, and low limits for the random number seed so that they do not exceed 215 = 327658. Vou will haye to do the s m e for Exmple 8 and Project- 8 tts well. Output At each time step the text output displays the time and the lowest, highest and average value for both X and Y concentrations. Every A F R E ~step ' ~ ~the concentrations (relative to their equilibrium values) are displayed as characters (if you request text to the screen) or as a contour plot (if you request graphics to the screen). For the character display (subroutine DISPLY) small letters indicate species values s m a e r than equjlibrium, while capital fetters, vdues larger than equilibrium. The appearance of the contour plot depends on your graphics package. If the prabk?m is one-dimeasiond, the graphics displays a one-dimensional plok Every I P S T E P ' ~iteration, ~ graphics are output t s a file or hardeopy be written out in device, if requested. Note that the cancentraLions three ways: as character data (if text is requested to a file), as numerical data (if graphics is requested a file), or as a contour plot (if graphics is requested to a hardcopy device), Subroutine S U G G ~ Tk e s the gaphing scales based on the stability andysis: if the sy~temi~ unstable, the scale is aqud to the m k m n m real frequency times the eq~Ebriumvdae; if the aystem is strtble the scale is equd to tvvictr the initial fluctuar;ians. Since the scde is k e d for the run, it may happen that values at the beginning (for an unstable system) or the end (for an exponentidy decaying system) will not show up on the plot;& However, a fixed scde is necessary to make elear the relative sizes of the fields at diEerc3nt times. cccccccccceccccccccccccc~ccceccccccccececcccccccccccccccccccccCccccceccc P R E M M PRQJ7
c C C G
P r o j e c t 7: The B r u s s e l a t o r in two dimensions COmUTATZOEJAL PHYSICS (FORTMM W R S I O N )
by Stcyven E , Koonin and Dawn C. Neredith Copyright 1989, Addison-Hesley P u b l i s h i n g Cantpany
eeccCceccccccccccccccccccceccccccccccceeccccccccccccccccccccccccccccce:cI: CAU
5
INXT
CONTINUE
! d i s p l a y header screen, s e t u p parameters Inrain loop/ e x e c u t e once f a r each s e t of param
622
C. Pn?gnams f i r the Projects CALL P m M CALL ARGWQN GOT0 5 ENT)
!get input from screen !calculate time evolution of the chem reactions
cccccccc~cecc~ccc~cccccccccccceccceeE:cecceccccc~~~~~cc~c~cccccc~cc SUBROUTINE MCWQ'E3 C calculates the time evolution o f X and Y concentrations
G according to diffusion-reaction equations CCCCCCC~CCceCeecCCCcccCCcCCCGcCeCcCceCcccccccCccccccecccecc~e~ccc~~~cccc C Global variables: INCLUDE 'P-M. P7' TNCLUDE ' 56. ALLt C Local variables: m= X (NAXX, 1UZAXYf !X species on cent ration RE= Y (WX,MAXYl !Y species concentration RE= T I m !time RDT !time step REaL DTNIEd,DTM !limits on time step INTEGER IT !time index TNTEGER XX, TY !horiz and vert indices !nudes of lines printed to t e d n a 2 INTEGER MLXNES IN"fGER SCmEld ?send to terminal INTT&GER PAPER !make a h a r d c q y INTZGER FILE !send t o a file ! n d s r of time steps to take INTEGER NSTEP !options for continuing LQGfCAL MORE, KEWDT XNmGER NFREB lgraphing frswency (movies onlyf !min,max, and tatal conc of species X BE= XLO, XHX, XT02 YLQ, YWT, VTQT !min,max, and total conc of species Y m A L SGRF (MBXX, M Y ) t s ~ c i e svalues for gxapking !flag to indicate apcfes INTEGER XSPEC,VSPEC !C Functions: RE& GETFLT !get; floating point nuder from screen !get yeslno answer from screen INTEGER YESNO !change, from 1.0 to true and false LQGIChL LOGCVT INTEGER GETIHT !get Integer data from screen !returns uniform random nuder REAL M N N 0 5 DATA SCWEN,PAPER,FIm/1,2* DATA XSBZC,YSPEC/1,2/
~~~~~~~cc~~~ee~eceeece~eccccccecececec~C:ccc~~eI:cc~ccccccce C
output sumary a f parmeters IF (TTERM) CALL PI-IMOUT (OUNIT, NLXNEf) I F (TFILE) CALL BMQUT (TUNXT, NLXNES)
IF (EFILE) CALL PRMOUT [GUMIT, NLINES) G G
ixlllt;ialiaaZ an4 ff et@a~nkrslsAcnrr f ~ p c i r aconaenkzakion@ f%mataata 5 EX=%,= DO 6 m=%,=
BQ
X [ Z X , XT) a* [%. +-GC%*
6 fi
CWTIm
coN2IHm
C. ? Project 7
? i n i t i a l i z e time ! d e f a u l t num of time s t e p s until n e x t prompt ! d e f a u l t g r a p h i n g freq ! d e f a u l t , min, and max time s t e p s
!loop o v e r d i f f e r e n t DT andlor NSTEP CONTINUE DT-GETFLT (DT,- D m X , DTMAX, I E n t e r t i m e s t e p ' > SF (ADS (BT) .LT. DTMIM) DT-SIGN (DTHIN, DTJ NSTEP=GETINT(WS~P,1,100OC1Enter nu*er o f time s t e p s ' l
+ +
XP ((TTERM) .OR.
(GTERI"I1)
NFREQ=GETlNT IWFREQ, I, 2 000, ' E n t e r display frequency f o r t h e c o n c e n t r a t i a n ' l NLINES=NLINE5+6 c a l c u l a t e t i m e s t e p dependent c o n s t a n t s IF (MX .GT. 1) THEN
XXPLUS=-XDIFF*DTINX/HX YXPLUS=-YBIFF*DT/HXIWX ELSE XXPLUS=O. YXPLUS=O * END IF fF (MY .GT. 1 ) THEM XYPLUSm-XDIFP*DT/HY/NV YYPLUSm-YDIFF*DT/HYW ELSE XYPLUS-0 * VYPLUS=O END IF XXZEROm1-2*XXPLUS YXZEROol-2*YXPLUS XUZERO-1-2XX'VPLUS YYZERO=1-2*nPLtUS ADITmA* DT BDT=B*DT BPZDll-I. (B+%.j *DT
-
TmX&G
IcalauXaka, m
m
and
Eos tbis DT
IF (TFILEI CALL TITLES (TUNTT,NLXNES, DT) CONTINUE ! l o o p a v e r s e t s of NSTEP t i m e s t e p s IF (TTERM) CALL T I T L E S f QUNIT, NLXNES, DT)
IF (MOD(IT,MFREQ) LF (GTERN) THEN
.EQ,
O) THEM
!graphics output
523
.
IF (TmRM) CAWL PAUSE f * tto see concentrations. ,l , lf CALL GRFOUTfSCREEN,XSPECtX,XLO,XMS,XTOT,SGW,NX,~Y] C a L GWOUT (SCWEN,YSPEC,'15, YLOtYHI,YTQT, NX, RV) IP ( (TTERMI "AND* (IT .WE. NSTEP) 1 CALL TITLES[OUNIT,NLINES,DT) ELSE SF ( T T E M ) THEN CALL PAUSE(@tto see X eoncentration..-',l) CALL DISPLY ~X,OUNIT,XLO,XHI,XTOT~XSPEC~ CALL DISPLY IY, OUNIT,YLO,YWT,YTQT,VSPEG) CALL CLEm NLIHES=O IF (IT .HE. NSTEP 1 CALL TITLES (OUNXT,NLPMS, DTf EPdB IF ! t e x t outlput ELSE 3F (TTEW) CALL TXTOUT(OUMIT,NLEmS, TIME,XLQ(rXWSIXTQI:IYL~,YHEeYTOT~ IF (TPTLE) CALL TXTOUT (TUWIT,NLINESITIME,XLO,XWZ,XTOT,YLO,YHX8YTOTI END IF
+ + 20 C
C0MZ"Zm f graphics output CALL DISPI;Y (X, TUNXT,XLO,XWI,XTOT,XSPEC) CALL DISPLV (Y, TUNIT,YLO,YHI,'15TOTt YSPECI CALL TIT~S(TUNIT,RIZIBJES,DTl END SF SF (GIIRDCP) THEN CALL GWOUT (PAPER,XSPEC,X,XLQtXWItXTOT,SGRh",MX,NY) CALL GWOUT (PAPER,VSPEC,V, YLO,YWI,VTQT, S G W , HX, NY 1 END XF IF (EFILE) CALL WTOfJT (X, Y,TIMEID311
SF fTFILE) THEM
C M O ~ = L O G C V T ( ~ S N O ( l , f C ~ n t iiterating?")) n~e
IF (MORE) THEM NLINESmO IF (TTEBM) CALL CLEm EQTO 15 BND IF C WEtQBTZOGWT(YESNO(1,'Change IF tNEHDT) THEN WLIWES=O IF (TTERM) CALL CLmR GQTQ 10 END IF
+
time step ar frequency and cantinue2'))f
e =TURN END
~ ~ c c ~ c c ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ e e ~ ~ ~ " ~ c c ~ c c ~ ~ e SUBROUTINE EVOLVE (X,H,DT, XLO,xHI~xTOT, VLOIYBI, YTOT") C evolves the species X and Y according to the diffusian-reaction
C equation and c a l c u l a t e s minima, maxima, and average s w c i a s values; C a l l t h e r e a c t i o n t e r m s are i n t h e h a r i z sweep of t h e l a t t i c e ; C see Eq 7.11-L16 and VXIe3a,b
cccccccc~Cccecccccf:cccccccccceeeeccccccc"ccececeCcccccccccccccccccccCcccc C Global variaLzJes: INCLUDE 'PARaP9.P7' C Iny>ut/Output v a r i a b l e s : WAL X(MXX,mXY) l%EZ& Y ( M X X , m X Y ) DT RE= XLO, XHX, XTQT REAL YLO,YHI,YTOT C Local v a r i a b l e s : XNWGER XX,IU
species c o n c e n t r a t i o n !Y s p e c i e s c o n c e n t r a t i o n ftim s t e p (1) Imin,max, and t o t a l eonc !min,max, and t o t a l conc !X
(I/O) fI/Q)
of s p e c i e s X (out) of s p e c i e s V ( o u t )
l h o r i z and v e r t indices !variables foz m t r i x inversion =&L BEzlllXX (0:mm) ,BEThYX ( 0 :M X X ) ,EETaXY t O :mXV),BET&= ( O :m X Y f RE& X2VDT,XRHS,VRHS !tamp v a r i a b l e s
cc~cceccccceccccccCcccccccceecceccccccccccccceecccccccccccccecccccccc~cc 33' (m "@2* Z) P Ifer ea& val- of yr, do an x Ins 2 1 haad* ~ CQ~S DO 20 ===-1,0,-1
tba&wm4 racgttrrion
ttZmT.iJt (=+l, rtr) +DV*% (=+l, 1x1m{XX+I, IT) ~ S ~ % + ~ l D T(XX+l * X,ZY) , +X2mII W S = - X m T + m T * X (ZX.C.1, TP)+X (fX+%,m)
CORgXm
@
t
60 40
Y (IX, XY);r;AW?fm (1Y-1) VY (XX, IY-1) +BET&= (IY-lf CCnsTXblmL CONTIMW,
END IP C
XTOr=O. YTOWO. -x(1,1) YLbY(1,l) XBI=xLQ
m=m
DO 7 0 I X = l , WK DO 80 3Y=&,MI 5E ( X ( I X , N )
80 70
.GT. XXXJ I H ( X ( I X , I Y ) .LT. XLO) IF (Y(TX,IY) . 6 T . XEI) XE ( Y ( r x , x Y ) .LT. YLO) xromai9lcor+x f r x , XY) n w x = Y T O T s P ( x x , XY? COWTIBUR CONTINUE
XTBT=XmY/NX/MI
XgI=X(IX,XY) XLt%XtTX,EY) YbIIWcY(IX,TY) rm=Y(XX,TY)
faweraw value
YTM1=YTOT/NX/WY C
ILETURM END cCCCCCCcCCCCCCCCcCCCCCCcCCCCCCCCCCCCcCCCCCcCCCCCCCCCCCCCCCccCCCCcCCCcCGe SllBROUTINE TRDIAG C c a l c u l a t e ALPHA and GANMA f a r t h e i n v ~ r ~ i oo nf t h e t r i d i a g o n a l matrix C see Eq. 7.11-7.16 and VfI.3a,b
cccccccccccccccceccccccccccccccccccccccccccccccccc=Cccccccccecccccccccccc C G l o b a l variables: INCLUDE ' PARAM.P'18
C Local variables: INTEGER I X , TY
!lattice indices
cccccccccccccccccccccccccccccccccccccccccccccecccccccccccccccccccccccccc C
hoxizantal rear8lrion I?? (HX .GT. 1 ) TEEX aZPiMX (WX) =I. A L P W X (NX) 4.
10
!no-flw b o w d a y conditions
DO 1 0 M=WX,X,-I !traJrward racuraion GAMXX{IX) =-1./ ~ Z E R w X W L u s * A L P m(IX) AfrPmx { I X - l f =wmm(Uf)*XXPLUS (nt)--I. / (YX&$RO+'IRCBLUS*mW ( I X J ) P U s m fIX-XJ=mkmx (3x1*n[PLUS CONTINDIE
E M XP C
C
vertical rcrcursian a (WY .ST. 1) TEEN &mIIXY (El) pel. A L P m ( W )4.
?am-flwboundary maditions
20
C@%SZrn
m m C
=TURN END
cccccccccccceccc~ccC:cceeccccccccccc~ececccceccccceeccec~ccccccccccccc~cc SUBROUTINE SUGGST G s u g g e s t s v a l u e s f a r B based on l i n e a r s t a b i l i t y a n a l y s i s C (see s e c t i o n V I I . 21,
G a l s o c a l c u l a t e s graphin$ s c a l e s based an t h i s a n a l y s i s
~ceccccecccccccecCcccccceecccccecccccceccccccccccccccccccccccccccccccccc C Global v a r i a b l e s :
INCLUDE "MENU. ALL' INGZUDE F IQ.ALLC INCLUDE '&&MM. P7' INCLUDE ' W . P ? ' C Local v a r i a b l e s : REAL PI TEMP m L DELTM,WTSQ ComLBX DISC =&L N,MQS@ m L BLB, BWT ,BCRIT INmGER I M M e BM =&XI =FRO
LOGICAL UNSTBL C Function:
!3 . E4159
!temp v a r i a b l e t o find. o s c i l l a t i o n s ! f u n c t i o n s of t h e made M ? diserimf nanr !wave modes ! c r i t i c a l B values !made Index !temp v a l u e s t o c a l c u l a t e f r e q u e n c i e s !maximm r e a l p a r t of t h e f r e q u e n c i e s ! i s t h e system probtrbly u n s t a b l e ? !get floating p o i n t n u d e r from s c r e e n
G wa bye %be corracJt C (Q-E,
6
e
+ Earn9 +
6)
(QrnXP,*) ' ' (' me Iclol%owAng
pwr Wvrlues of A,
("in
of
B f a %hd a 8 e ~* , and Y D m : ' )
6- !lcnoasC M value; a6 for ne-6Zm be; m S a F ( 2 )
C C C
lao
(am%,S)
=SE 5
l4 by MEfe&iva An all %ha ma2ysis
what: i s tba higheat
for fixed bc
~todsbwbiah gSvaa rfam f o oaciXl.oLtioaa fn t f m ? w~a&v~l~eso~Bg&veoscliXlation~?iast&fXfty?
BX=Q. *A%= (l,0 )
528
C. Programs for the Pr~jeels
mm=%/ ( m m - x D m ) e TmM ("be
20
hiqhecrt
!osaillatlona are possible mdk,
t o give oocrillationr i n M 5 @,,H7.3) floep ovmr a d 1 and 5wgm M !sarallaat M ! l u g e a t B# &to give oec
XF (ZM .Ea. 1) I F (TM .BQ. 2) HMOSC =IS* (M*PI)*"2 DE&m%+mIsQ* {XDmF-mm) ~ X % = I + & * * 2 + ~ Z S Q * ( D I F P + ~ Z ~ !)s m l l s a t t3 CO @vs inartb. DBLZM=BWF (B=%%) (&-DELm)**2 =Zap [ A + D n m j **2
t a m 2 l e r t B t o give osc f l e g a s r t B t o g%ve osc
B-
30
a X T R (OmZF, 30) (owrzl, 40) for M = *,)e"7,3, m l l c r i r t B to #ve watafile eaof?LlttLlons 1s ' 2 7 . 3 1 FO-2 ( W d osafllakiona w i a a onfy f a r B betwetam @,F7.3,
+
40 20 C
,%E.
90
e C
EO-T
Ern
3x
a.) P m I
toarcillations aza not. goselbZa
(QWX31,30) (' %era are no oscrillationar Pox thvass pa
v d u e s o i B a d M e v e u n a t d l e , non-ol~ioillatoq babavioz?
W&&
e B m T (&/PX/PX/sQR% (DIm*PDXBP) ) mSSW*@BX*f?f.
9~T=l+A**2*(XBX~/DX~+l./UID~F/@SSQ)+~X~*WISQ (QrnXT,*) ' ' m m (OmXT,55) (QaXg, 6Qj 24,B W F (' Xnot&llity w,z.(e. avnenLZoXly growing hbarviorF) ("%rat ocranxm PQE M = f,,F7.3,* aand Er r,,F7.3)
m m 55 60 C C
a Z l w meat. t o aeXjusC value o f B usfag t h l s i n f o (owl%,*) p
t =l =B C C C
a a a l a t e t h e f ~ e @ a a e i r sf o x amlXeot I# (&pnda on b.c.) ancl lazgr#t I (whS* depaadrr on t;kr I a e C i a spacing)
IF ( f M ,EQ. 2) WISQ=WZ*mX*PT*PI M=B-%-HBZSQ*=Xm
BM=A**2+~TOQ*~fIi'ZT DXSCm (m+M) **2-4*A**2f B (ZM) ( M - m t S @ T (DISC)) 12 f XMf = (U-rn-SWF (DISC)) 12 70
COmXBm
C
O1QSTBL=-FUSE.
!alljust verlf a m 2 1 sealas tsaale for graphlng ithis scale 5s scat f o p a l l Cfms !for thess vaXnaa o f &he par-l;iarra
m
XI)"
c ETURIOI
END
cceecccccccccccccccc~ccccccccccccccccccccececcecccceeccccccccccccccccccc SUBROUTINE IHJT C initializes constants, displays keader seresn, C initializes m n u arrays for input parameters
cccccccccCcccccccGeccccccccccecccccccccecccccccccccccccccccccccccccccccc C Global variables: INCLUDE XIO.ALLt
INCLUDE MENU. ALL* ZMCLUOE * P A W . P 7' C Local parameters: @
CNmCTER*80 DESCRP ?program description DIMMSIoN DESCRP (20) XNTEGER WWEAD,NTEXT,NGMPW !nu&er of lines for each description ccccccceccecCCececccecceccccccccccc~cceeccccc~cccccccccccccccccccccccccc C get envf ronment parameters CALL SETUP
c C
C C
display header screen BESCRP (11 = PROJECT 7 " DESCRIPIZjm "The Brusselator in two dimensionsf HHE&D=2 text output description DESCRP ( 3 ) = 'time, X and V species minima, maxim and averagesf NTmT-2
C C
graphics output description DESCRP ( 4 ) = 'X and V species concentrations" WGmPN=l
830
C. Pmgram~for the .Pmjeets CALL READER(DESCW,NWEAD,NTEXT,NaPH) setup menu a r r a y s , b e g f n n i n g w i t h c o n s t a n t p a r t GALL =NU MTYPE (131 =FLOAT WmPT (13)= 9 n t a s v a l u e f o r A spcies c o n c e n t r a t i o n ' NTAG (13) =Q cconcentration" ML0LIM(13) =Q* 001 MWILIM (13) 420. m m L S (93) =2* MT-E f l 4 1 =FLOAT W W T { l $ ) = % n t e s v a l u e f o x B smcies c o n c e n t r a t i o n p MTAG (141m* 8 c o n c e n t r a t i o n " MLOLXM(14) =Q MHILTM(I4f=20. I
MTYPE ( l S) =FLOAT M P W T (15)=*Enter v a l u e f o r XBIFF ( X s p c i e s d i f f u s i o n c o n s t a n t f * MTAG (15)=% s p e c i e s d i f f u s i o n c a n s t a n t " MLQLIM (151 -0. HHTLIM ( 1 5) -l 0. LS (15) =a. 001 MT*E
( 1G 1 =FLOAT
M P m T (161= # E n t e r v a l u e f a r YDTFF (U s p c l e a d i f h s i a n c o n s t a n t ) NTAG (161 my Y s p e c i e s d i f f u s i o n c o n s t a n t @
moLsn ( 161 =a-. MHIEXM (16) -10. MmLS(16)-0.003 NTWE ( 17) =FLOAT W W T (17)m * Enter v a l u e f o r XFLUCT (X s p e c i e s f l u c t u a t i o n s ) MTAG f 171 ='X s p e c i e s Ef u c t u a t i a n '
MLQLXM (17) --I, E(UUILXN(f7)=1.
mmzs (17)
1 . .
01
MTrPE (18) =FLOAT W W P T (18)= ? E n t e r v a l u e f o r YFLUCT f Y s p e c i e s f l u c t u a t i o n s 1 MTAG (18)= @ Y sspeeies f l u e t u a t i o n f MLOLIN (18)m - 1 . MHILIM (1B 1=l. mEALS (181-,01
NTUPE (19)=SKTP mALS(19)=35.
MPRMRT(38)- # E n t e r nu&r of X l a t t i c e p o i n t s 1 MTAG (3814 ' N u m b e r of X l a t t i c e p o i n t s f MLOLIM(38)-1. MHILIM (38)=MAXX: MINTS (38) -20 C
MTYFE (39)=NUM MI?RMPT(39)= 'Enter number o f Y l a t t i c e p o i n t s ' MTAG (39) 'Number of Y l a t t f ce p o i n t s 1 MLOLIM(39)=l. MNILfM(39)=MAxY MINTS 139)4%
-
C
-
MTYPE (401 -NUM MPRMPT (40) * I n t e g e r random number seed f o r i n i t f l u c t u a t i o n s 1 MTAG ( 4 0) = * Random number seed1 MLQLIM(40)*1000. MHILXM (40) r99999. MINTS (40) ~ 5 4 7 6 5 C
MTYPE (41) *SKIP MREALS (41)-60. C
MSTRNG (MINTS(75) ) =
'p r o j 7 . t x t t
C
MTYPE (76) =SKIP MREALS (76)-80,
C MSTRNG (MINTS ( 8 6 ) I = "proj7. grf C
-
EmPE (87)=HUM NPRMPT(87) 'Enter number of contour l e v e l s 1 MTAG ($711 Number of contour l e v e l s ' MLOLIM (87)=2. MHILIM (87) 450. MINTS (87) 1 6 C
HTYPE (89) =SKIP MREALS (88) =go. C
RETURN
END CCCCCCCCCCcCCCCCcccCCcccCCCcCcCCCCCCC~ccccccccccccccc~~c~cccccccccc~c SUBROUTINE PARAM C g e t s parameters from screen C ends program on request C c l o s e s old f i l e s C maps menu v a r i a b l e s t o program v a r i a b l e s C o w n s new ff les C c a l c u l a t e s all d e r i v a t i v e parameters C p e r f o r m s checks on parameters CCCCCCccccCCCCCCCCccCCCCCCCCCCcCCCCCccCcccccccccccccc~ccccccccccccccccc
532
C. Programs for the Projects C Global variables: JNCLUDE " m N U , ALLf JNCLUDE ' 10. ALL" INCLUDE P m M . P 7 * INCLUDE ' W - P ? ' @
C
Functions:
!converts 1 and O to true and f a l s e ?get floating point numSser from screen INTEGER GETXNT !get integer from screen CCCCGCCCCCCCCCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCCCCCCCCCC C get input from terminal LWICAL LQGCVT
m L GEmLT
CALL CLEAR e a L ASK(I,~STQP) C C
stop program i f rewasted IF (HMALS ( I M A I N ) .EQ, STOP) CA& FTNISW
C C
close f i l e s it necessary SF (TMAWE NE. NSTRNG (MINTS (ITNWE) 1 )
+
.
CALL FLCLOS (THME, TUNIT) J F fGNAm NE, MSTRNG (MINTS (TGHAKE) ) ) + CALL FLCLOS (GHME, GUNIT)
.
C
C C
set new parameter values physical and numerical B - m A L S (IB) XDSFF=W&LS TXDXFF) YDXFPmmALS (IYDIFF) XFLUCTmNREALS ( IXFL) YFLUCT-M-LS (TVFL) w x - ~ z ~( rMx) ~s NV=MTNTS (INY) DSmD-DBLE (MINTS ( I D S E W
C C
text output TTERM=LQGCVT (MINTS ( ZTTERM) ) TFXLEmmGCVT (MINTS (1T F I W f 1 aNm=MsTRWG (MrWrs ( r T N m 1 1
C C
graphics output GTERH=LaGCVT (MINTS lrGI"ERM1 f c a m c P = L s s c v T {MINTS ( IGWRB 1 1
GFZLE=LQCCVT(MXWTs(XGFIZE)) GHME=MSTRNG (MINTS ( XGNAmj 1 NLEVmMXNTS ( IMLEV)
G C
openfiles I F ( T F I M ) CALL FWPEW (TNAm, TUNIT) XI? (GEILE) CALL FLQPEN (GHAm, GUNET) !f Ales may have been renamed MSTRNG {MINTS(ITN=) ) =TNAm
MSTRNG ( M r N T s trcNAMe) =GM-
e C
60 56
make, s u r e t h a t problem i s a t l e a s t one-dimensional IF ((NX .eg, 1) .ma. (MU .EQ, a,, Twew irJRITE (QUMLT, 50) F O R M T ( I Bath NX and NY c a n w t be = 1') NXmGETINT (20,1,mm,"Enter new v a l u e Esr NX' 1 NY=GETINT(20,1,mXY,%nter new v a l u e f o r NLMTS ( I N X I =W M I N T S (SNU) =NU EOTQ 60
END L F
e !suggest v a l u e s f o r B
CALL SUGGST
CALL C m A R C
e
d e r i v a t i v e parameters HX-0. HU=O. I F (NX GT. If WX-1, / (NX-1) I F (NY GT. 1) HUm1. / (NY-11
.
.
C
!allow far ane-dimensional
systems
!c a l c u l a t e space s t e p s
c a l c u l a t e p a r a m t e r s f a r best looking t e x t d i s p l a y I F (2*NX .LE, T W X D ) THEN XSKIP=. TRUE. XCNTR=(TWXD-2*WX)/2 ELSE X S K I P m . PALSE XCHTR= ( T R W I D - N X ] /2 END I F Sl? (XCNTR .LT, 1 1 XCMTR=1
!@kipspaces i n x !how t o e e n t e r d i s p l a y
I
C
L F (2*NY .LE. T W I N - 4 ) THEN YSKSP= ,TRUE, VCNTR=fTMLTN-2*NYf/2-2 ELSE YSKIP=.FALSE, YCNTRm ITRMLIN-NY 1 /2-2 END Z F I F (YGMTR .LT. 0 ) YCNTR-O
!skip l i n e s i n y !how t o c e n t e r d i s p l a y
e =TURN END
eee~ccceccecceccccccccceeecccceccccccecccececeeecccceccccceeec~ccccccecc SUBROUTINE D I S P L Y (S, MUNTT, SLO, SRI, STQT, S P E C ) G display species ( 5 ) a s a s e i l characters G v a l u e s above t h e e q u i l i b r i u m v a l u e are d i s p l a y e d a s c a p i t a l l e t t e r s , C t h o s e less t h a n the e q u i l i b r i u m v a l u e a r e d i s p l a y e d a s small, betters
ccccec~ccccccccc~ccccccccccccccccccccccc~cccccccccccc~eC:ceccccecccceccc~ Global v a r i a b l e s : XNCLUDE P W M P 7 ' INCLUDE ' I O ,ALLe C Input variables: C
.
534
C. Pmgmms for $he P~ojects RE& S ( M X X , M Y 1 INmGER MUWXT M A L SLO,SW3, STQT INTEGER SPEC G Local v a r i a b l e s : INTEGER I X , IY T N m a R STEW CWmCTER*1 SPECS(MX) RE& SZERO BE= SCALE
I s p e ~ i e sv a l u e s ! u n i t w e t re w r i t i n g t o !min,max, and t o t a l conc of s p e c i e s S !whf ch s p e c i a s
!lattice indices ? S a s an i n t e g e r ! s p e c i e s as c h a r a c t e r d a t a !fzero"alue for s p e c i e s ! s c a l e for s p e c i e s !blanks Eer c e n t e r % n g i n X l f f a g ta i n d i c a t e s p e c i e s INTEGER XSPEG,YSPEC INTEGER CSCBLE l s c a l e aE a s c i i d a t a CWmCTER*1 ASKIII0:2S),MEGASK(O:25) ? c h a r a c data f o r d i s p l a y DATA BLNK I"/ D A m A ~ ~ I ~ / ~ f , t ~ f , f C ~ , ~ * , c E @ , ' F ~ , f G f , t B 4e'Kr,'Lf , f T ' t ', 'JM'f , 4t ~ ~ , f O t I ~ P * , f Q ~ , ~ R t r F S ' , ~ T e ,I'X',fY',8Zf f U ~ t C V * t /f ~ r DATA M E G A S K / * a ~ , f b t , ~ c \ f d * , f e ~ I @ f ~ , * g f , * h @ r f ~ t , r j t ~ ~ k ~ 4~n~I~o?,@p*tpqf,~rt,f~tC6tt,'~t,t~~,F~Cf' DATA XSPEC,VSPEC/f,2/ DATA CSC&ZE/ZS/ ! s i n c e t h e r e a r e 26 c h a r a c
~~~~~~cc~cccCc~ccc~~cccccccececcccccccecccccccccccccccc~cceccecccec
20 25 26
IF (MUMET .Ea. OWNIT] THEN CALL CLEM DO 20 IYm1,YCNm ! c a n t e r output WRITE (OU#TTI") ' CONTINW ! p r i n t ~ u dt a t a IF (SPEC EQ. XSPEC) W I T E fOUNXT,25) SLO,SHI,STOT IF (SPEC EQ. YSPEC) WRITE (OWIT,26) S W ,SXI,STOT PORMT(1SX,'X min =ifjF?,3,f X max *",F7-3rf X a v e r a g e =81F7s3) FOmT(15X,rY min = t , , F 7 . 3 , t Y max af,F7,3,@ Y a v e r a g e =f8,E"7.3f ELSE, WXTE (MUNIT,* ) ' IF (SPEC EQ. XSPEC) mITE (NUWIT,* +* X s p a c i e s c a n c e n t r a t i o n A:@ IF (SPEC EQ. YSPEG) WRITE (MUNIT,*) 4" * V s p e c i e s c o n c e n t r a t f o n A/B;" END IF
. .
.
.
-
c IF (SPEC .EQ. XSPEC) THEN SZERCI=& SCALE=XSCAW/CSCAm ELSE: XF (SPEC .EQ. VSPEC) THEN SZERO-S/A SCALE=YSCAm/CSCBm END TF
!set, s c a l e s !X e q a i l v a l u e
!P e q u i l v a l u e
c DO 100 TY-RV, 1, -1
DO 50 IX=1,NX !STEM? i s s c a l e d d e v i a t i o n from SZERO STEW=NINT( (S( X ,EY)-SZEROjISCAU) IP (STEW .GT. CSCAm) STEMP=CSCALE IF ( S m W .LT. -CSCALE) STEMPm-CSCAm
I F (STEMP .GT. 0 ) THEN ! c o n v e r t species t o A S C I I SPECS EXX) -ASKIX.(S"PEEZP) ELSE IF (STEMP .LT. 0) TEEN SPECS [XX) =NEEASK (-STEW) ELSE I F (STEMP .EQ, 0) THEN I F ( S (SX, I Y ) .GT. SZERD) TEEN SPECS (SX) =ASK11 (0) ELSE SPECS [ IX) =&SKI I ( 0) END I F END I F CONTINUE
10
15 16 100
w r i t e o u f a l i n e a t a t i m e r (no c e n t e r i n g d o n e f o r TUNITI f F (MUNIT .EQ. TUNIT) THEN %RITE {TUNIT, 1 6 ) (SPECS {IX) ,I X = I , EX] ELSE I F (XSKIPI WEN WRITE (OUNZT, 1 0 ) BLNK ( I :XCNTR) , (SPECS ( 1 x 1 , IX=1, NXI ELSE WRXTE (OUNIT, 25) BLNK(l:XCNTR), (SPECS ( I X ) , X X = I , NX) END I F I F (YSKIP) WRITE (OUNITI*I ' ' END I F FORMAT ( l X , a , 1 0 0 (A1,IX) FORMAT ( l X , A , 1 0 0 ( A l l I FORMAT f l X , 1 0 0 ( A l l f CONTXNUE I F (MUNIT .EQ, OUNIT] THEN I F (SPEC .EQ. XSPEC) THEN CALL PAUSE(-o see Y c o n c e n t r a t i o n . . . ' , O ) ELSE CALL PAUSE('to c o n t i n u e . , . ' , O ) ehia IF EHD I F
I
RETURN END
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc SUBROUTXlsE PRMOUT (MUMIT, NLZtdES) C o u t p u t s p a r a m e t e r summary t o MUWZT
ccccccccccccccccccccccccccccccccccccccccC(:ccccc~"cccccccccccccccccccccccc C Global variables: INCLUDE ' I0 .ALLF LNCLVDE 'PARAM.P?' 6 Input/Output variables: INTEGER MUNIT INTEGER NLINES
! u n i t number: f o r o u t p u t ( i n p u t ) !number o f l i n e s w r i t t e n so f a r ( o u t p u t )
CcecCCCcCcCCcCCCCCCcCCcccccCcCCcCcCCccccccccccccccccCcccccccccccccCccccc I F (NUNIT .EQ.
OUIIT) CALL CLEAR
e WRITE (MUNIT, 2)
536
6. Pwgmnas JOP" the IJro;lieets &JRTTIT, (MUNIT*4) W f T E (MUNIT, 6 ) B,B WmTE (MUNIT, B ) XDIFF, YDIm lrJRITE (MUNIT, 10) XFLUCT, YFLUCT T?SBI"f (NUNIT, 12) EJX,NV WRITE (MUNST, 1 6 ) MLO, OMEGAP (l) ,OmGAW (11 WRI TE (MUNIT,16) MHI, OMEGAP ( 2 ) ,0MGAM (2) m I T E (MUNIT, 14) m I T E (MUHIT, 2) C
NLII"JES=10
c 2 4 6 8
F O m T k"( F O m T ("~roject 7: B r u s s e l a t o r i n two dimensions" , F O R W T (Q c o n c e n t r a t i o n ,F8,3,5X,'B c o n c e n t r a t i o n =\,F8.Jf F O m T ( " X s p e c i e s d i f f u s i o n = \,19EX2.5,5X, -IY s p e c i e s d i f f u s i a n = ',lPE12.5) F O M T (' X species i n i t f l u c t = qSPE12.5, 5XI -iU s p e c i e s i n i t f l u c t = 1PE12.5) FQRMT(6NX=*,S4,5X,'NYm*,,%41 FORMAT (' a l l v a l u e s are i n s c a l e d u n i t s r ) F Q M T (' f o r H=\ ,FT, 3, * tba f r e q u e n c i e s a r e ' p + 2 t 2X,* { " r F 7 . 3 , * e 6 , r F 7 . 3 , r f i ) 1 @
10 12
14 16 C
rnTURH END
~ c e c c c c c c c c c c c c c C c c c c c c e c c c c c c c c e c c c c ~ SUBROUTINE TXTOUT (NUNJT, MLLHESt T X W * XLO, XWI XTOZ", VLO, Y H I VTOT) C w r i t e s r e s u l t s f o r one t i m e s t e p t o MUMlT
eecceccccccccc~ccccccccccceccceccccceccccccccccccccceecf:ccceccceeccccc~c e Global variables:
.
INCLUDE X 0 ALL" C Input variables: INTEGER MUMIT RE& TINE INTEGER NLImS =U XLO, XHT ,XWT MAL YLO, YHX, UTOT @
toutgut u n i t s p e c i f i e r !time !number of l i n e s p r i n t e d so f a r ( I l o ) !min,max, and t o t a l c o n e of s p e c i e s X !min,mnax, and t o t a l c o n c af s p e c i e s V
CCG~GCCCG~CCCGCC~CCGCC~CCCCCCCGCCCCGCCCGCCCCCCCCC~CC=CCC:CCCCCC~~CCCCCGCCC
C
i f s c r e e n is f u l l , efaar s c r e e n a n d r e t y p e h e a d i n g s I F ( (MOD(NLXmS, TRMLIN-4f .EQ. Q) -k .AND. (MUNIT .Ea. oUNJT) ,AND. (.NOT, GTEm) ) THEN CALL PAUSE:tPto c o n t i n u e , . . @ , l f CALL CLzm m I T E (MUHIT, 14) WRITE (MUMPT, 1 6 ) NLfMES=.;NLSN&S+2 EAlD PP
C C
m I T E (MUWIT, I Q ) TIME, XLO,XRI, XTOT, YLO,YWI, VTQT keep t r a c k o f p r i n t e d l i n e s o n l y Ear t e m i n a l o u t p u t I F {MUNIT .EQ. OUNIT} NLINES=NLINES+1
C 40
24 l6
F Q m T (3X,lPE12,5,5X,6fOPF8.3,2X]) F O W T (8X,~tfne~,llX,*Xxl0~~7X,~Xhi~~7X~@Xa~e~,7X,~Yl~', + 7X, T h i c r6X, "avee") F O m T (8X,"---8 ,l l x , ~ - - t , ?X, P ---t ?X,L=--*, ?X, - - - t , ?X, 1 ,6, ' ----I 1 i
---"
f
C RETURN END
ccccccccccccc~ccCcecccccccccccccccccccccccecceececC:ccccccc~cccccccccceec SUBROUTIRE TITLES (MUNIT,NLIWES,DTf C write out time step and column titles to NUNIT
ccCccccccccccccccccececccccccecccccceccccccceccccccccc~ccccccccccccccccc C Global variables: INCLUDE ' I T O .ALL' C Passed variables: 1MTEC;ER MUNXT
!unit number for output (input) !nu&er o f lines written so far foutputf !tfm step (input) cccccccecccccccccccccccccececcccccccccceccec1ccccc~ccccccccccceccccCccccc I F ( (MOD (NLIWES, TRMLTN-7) .EQ. Of + .AND, (NUHIT .EQ. OUNTT) .AND, (.NOT. GTERM)J + CALL C L E M c INTEGER NEIRES =L DT
m I T E (MUNIT,*) ' m Z T E (MONIT,PO) BT WRITE (MUNIT,14)
m I T E (MUWIT,16)
e SF (MUWIT .EQ. OUEaIT) NLINES=NLINES+B C
20 14 4"
l6
FORElAT fqteme step E. t,1PE12.S) F O R m T I 8 X , rtime% IlX,'XXT*, ?X, 'Xhir,? X , IXavei '?X86 Y l a r , "?X, "hi * ,6X, * Yavef ) FORmT (@X, '----" ,11X6 ,?X," - - F ,?X, P ?X, , ?X, ---I, ,CX, p 1 '--mf
+
---@
m---"
f
e RETURN END
Ccccccccccc~cccceccccccccccceccccccC:cccccccccccccccccccccccccccccccccccc SUBROUTINE CWOUT (DEVICE, SPEC,S,SLO, SWI,STOT,S G W IMX,MY) C display contours of- the species-equilibrium value C this routine will also do l-dim plots if either NX ar NI' -3.
C C C
the field values must be in an array that is exactly NX by NY; this can be accomplished with implicit dimensioning which rewires that SGRF and its dimensions be passed to this rautine
c c c c c c c c e c c c c c c c c c c e e c e c c c c c c e c c c c c c c c C Global variables: INCLUDE IQ.ALLf @
INCLUDE 'PAMN.P7" INCLUDE 'GRFDAT ALLF
.
C Input variables:
INTEGER DEVICE
!which d e v i c e
INTEGER SPEC RE& S ( W X , M U ) INTEGER M , N Y RE= S G R F ( m , W ) REAL SLD, S H I ,STOT
!which s p c i e s
!species values !NX and NU i n d i s g u i s e ! s p e c i e s v a l u e s f o r graphing ?min,max, average s p e c i e s v a l u e s
C Local v a r i a b l e s : mAL SZERQ f NTEGER f X , I Y
INTEGER I;P;IEGER XWmGER INmGER
SCREEN PWER
FILE EJCONT
C R m C T E R * 9 CLQ,CWI,CTOT CWWCTER* 9 CA, CB INTEGER XSPEC, IFSPEC TNmGER LLQ,LWI,LTOT,M,LE WAL, SMIN, S m X rlATA XSPEC,IFSPEC/1,2/ DATA S C m E P J , P A P E R , F I m / 1 , 2 , 3 1
!"zero' v a l u e of s p e c i e s ? l a t t i c e indices !send t o t e r m i n a l !make a hardcopy !sand t o a f i l c ! n u d e s of c o n t o u r s ! a r r a y for 1-dim p l o t s !data a s characters ! d a t a as c h a r a c t e r s !flag t o indicate species ! l e n g t h of char s t r i n g s
ececccCcccccc~e~eeeccecccccccccccCececcce~cceceeceeecccecceccccec~cccccc
11, 10
I F (SPEC .EQ. XSPECI SZERO=h I F (SPEC .EQ. YSPEC) SZERO=B/A DO 1 0 3 X = 1 , m BD 11 XY=1,MY S C W ( I X , f Y)=S ( I X , SV) -SZERO CONTINUE COWTIWUE SF (m .EQ. l ) THEN
!set equif v a l u e s
!l o a d f i e l d i n t o SGW
! d i s p l a y d e v i a t i o n s from Szero
ao 1.5 XV=I,W U T T I C f IY)==&L (XY1
SGW(IY,l)-S(1,XlP)-SZZRQ 15
CONTZNUE END XF
IF (MY .EQ. 1) THEN DO 1 6 PX=l,NX M T T I C f f X f ==&l,
16
!need t o r e l o a d d a t a for !one-dinplots
(IX)
CONTINUE END I F
C
C
messages f o r t h e impatient I F ( (DEVICE .NE, SCREEN) .AND, (SPEC .EQ, XSPEC) 1 m I T E (OUNIT, 100)
e C
c a l c u l a t e paranreters f o r graphing WLOT=2 !how many p l o t s
C
UW=N?Y
VNIN=l, XMINml
.
XW=NX YOV~Z=X1VIXW
!axis data
XOV"AL=YMf hT
NXTZCICm5 NVTICK-S NFOINTm5 C:
U B E L (1)="X8 m E L (2)='NU8 CALL CON-T 1SLQ,CLO, LLO) CA& e a m t f (swr,CHS ,LWI I CALL COMVRT (STOT, CTOT, LTQT)
G&&
!graph d e s c r i p t i o n
CONmZ:(A,CA, LA)
CALL C O m T ( B , C B , a )
TITLE=' B r u s s e l a t o r w i t h A="/CA(l:zzl)
/ / h a n d B=' / / e B ( l : L B )
C:
I F (NX .EQ. f ) THEN !labels and a x e s are d i f f e r e n f f o r XMTN-1. !one-dim p l o t s XrnXmPIM YOVAL-XMIN (3.1 NVe -EL I F (SPEC .EQ. XSPEG) THEN LABEL ( 2 )=*X C o n c e n t r a t i o n A' UMf PJmMX 4-XSCALE, -A) !scale i s t h e s a m e !for a l l t i m e s YmX=XSCUE ELSE I F (SPEC .EQ. VSPEC) THEN =EL (21m' lr" C o n c e n t r a t i o n B/At uarW=mx(-YSCALE, -B/A) U M a YS C S E END XF XOVAL=YXXM NPOINT=NU ELSE I F {MU EQ. 1) THEN SF (SPEC .EQ. XSPEC) THEN LABEL (2)m r X Concent r a t i o n A* Y M I N m W [-XSCALB, -A) 'I"mX=XSC&E ELSE SF (SPEC .EQ. YSBEC) TmM M B E L ( 2 ) mfY G o n e a n t ~ a t ; i o n B/Ar YNIIU=MX ( - Y S C U , -B/&) YW=YSG&E END I F XOVAL-VMXEJ NPOINT=I?JX END I F
-
-
.
-
C
I F (SPEC .%Q. XSPEG) THEN ?species-deptsndent paramc3texs IPLOT=1 SMZN-mX f -XSCALE, -A) tseale f o r species SMX=XSCALE IN FOP^ XmPn=' //CL0 (1:LLO) I / @ Xmaxmt + / / C H I ( ~ : L H I ~ / / *X ~ V ~ = ~ / / C T ~ T ( S : L T O T ) CALL GTDEV (DEVICE) !device nomination I F (DEVICE .E@. SCmEN) CALL GMOBE ! c h a n g e ta graphics mode
540
C. Pmgnanas for #he Projects ELSE XF (SPEC .EQ, YSPEC) TNEN IPLOT-2 S M I N n W ( - Y S C U , -B/A) SW=')ISCALE
XMFQ=yYdon=f//C&O(1:LLQ} / / I Y w x = ' //CNI(l:LBS)//' Yave='//CTOT(1:LTOT) END I F
-6
c CALL LNLNAX
l draw axes
G
IF
((m .EQ,
1) .OR. (MY ,Ea. 1)) THEN
CALL XYPLOT (MTTXG,S G W ) ELSE
CALL GQNTOR ( SGRF,W, m, SMIM ,S m X , NLEV}
END IF I ;
C
end grapbing session SF (SPEC .EQ. YSPEC) TNEN IF (DEVICE .NE. FILE) GALL GPAGE(DEVICE1 SF IDEVXCE .EQ, SCmEN) C U L TMODE
?close graphics package !suiteh to text made
END IF
e 100
F O m T (/,"aatienc,
gfaaee; output going t~ a fiXee8)
C RETURN
END
cccccccccccccccccceccccccceccceccccccccccccccccccecccccCccc~cccceccccccc SUBROUTIlldE m T O V T (X, V, T I W , BTf C write out X and Y speeiss concentrations to GUNIT C for graphing with an external package
cccccccccccccccceccccccccccccccccccccccccccccccccccccccccccccccccccccccc C Global variables;
INCLUDE m N U . ALL' INCLUDE ' XO. ALLe @
C Input variables:
=L
TIm
M U DT
REAL X IMAXX,mXY)
Mm Y ( W X , m X Y ) G Local variables: ZNTEGER IXIXV
!time !time seep !X species concentration !Y spscfas concentration !lattice indices
ccccccccccccc~cc~ccccccccccccccc~cccccccccccccecccccccc~ccccee~ccccccccc 20
100
WRITE (GUNIT,20) T I m , DT F O m T (' time = IPEf2.5, V i m e stepmf,lPE12.5) m I T E (GUNIT,*) X conceentratfonr Do 100 IX=E,MX m I T E (GUN1T, l O J (X (SX, IY),IY=I,NY) COWTIWUE m I T E (GUNIT,*) Y cooncen$ratione B0 200 SXm1,NX WRITE (GUN&$ ,101 fY( X X , XY) r Z Y - 1 , W ' ) @
200 10 C
CONTINUE F O m T 45 ( 2 X , IPE14.71)
RETURN END CCGCCCCCCCCC@CCCCCCCCGCC:CGCCCCCGGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
ccc~cccccccccccccccecccccccccccccecccccccecccccccccccccccccccccccccccccc C param.p7
c l & and B s p e c i e s c o n c e n t r a t i o n s REAL A,B !X and Y s p e c i e s d i f f c o n s t a n t s XDIFF, YDIFF RE& XFLUCT,YFLUCT ? X and Y s p e c i e s i n i t f l u c t u a t i o n s INTEGER NX, NY !horbz and v e r t nu&er aE l a t t i c e p o i n t s ! h o r i z and v e r t s t e p s REAL HX, HY DQUBLE PRECISSON DSEED trandam nurnber seed f o r i n i t cond INTEGER XCMTR,YCNTR !data for centaring display LOGZGAL XSKfP,YSKZP !data for centesing display INmGER NLEV !number a f contour l e v e l s COWLEX OmGM (2),0MEG&P(2) l Ereq from l i n e a r p e r t t h e o r y -6, MLO, M W I ! s m a l l e s t , Largest made f o r t h i s l a t t i c e m A L XSCUE,YSC&M Igraphing s c a l e s
C
miql
XXPLUS,XYPLUS,YXPLOS,TYPLUS
REAL XXZERO,XYZERO,YXZERO,VYZERQ
RE-
BDT,BDT,BPIDT
!useful constants; f i r s t l e t t e r ! r e f e r s t o s p e c i e s , second t o fhoriz or vert
C IN'XIEaR m X X , m X V P m M E T E R (=X1791 ETER (WY-20)
!maximum h o r i z and v e r t dimensions ! t h e s e a r e set assuming t h a t you !have no g r a p h i c s and t h e l e n g t h of !your terminalm24
C !following a r e t h e terms i n t h e r e c u r s i o n ( s e e Eq. 7-12-7.16) ALFHXX([Z:WXI,G~XX(WX) !boriz xeeur of X 1 , GAWX ( W X ) !horiz r e c u r of Y ) ,GAMXV ( m y f ! w e l t r e c u r aE X 1, f m V ) l v e r t r e c u r of P
RE=
c
COWQN / P P A m I A,B,XDTFF,YDIFF,XFLUCT,YFLUGT COM016 / HP&= / NX,NY,DSEED COWQN / GPAMM / NLEV~XCNTR,PCNTR,XSKJP~VSRXP~XSCALE,YSCALE
MV,AZIPWXX,WLPHXV,ALPWYX,ALPBVU,
+ OmGAP,OmGAM,MHX,MLO cccccecccc~ccceccccc~c~cccccccc~ec~cceccccccccccccccccccccccccecC:ccccccc
c~cccccccceccccccccccceccccccecccccccccccccccccccccccccecceccccceccccccc C mag.p7 IMTEGER I A , IB, SXDIFF, IVDSEF, XXFL,, SVFL, ENX, ZNY, IDSEED, 1EJLEV TER(IA =l31 PAMmTER (IB = 141 P m m T Z R f IXDXFF 25) ETER (IYDIFF = 16)
-
P m M T E R (XXFL = 27) P A m m T E R (IVFL 18) PAMmTER (INX = 38) 'I'ER(TW =39) PAMmTER (SDSEED 9 40) PAMmTER ( I N a V = 87)
C.8 Project 8 Algorithm This program uses variational or Path Integral Monte Carlo mthoets to solve the two-center, twwelectron problem of the H2mdecule using the trial wave functions specified by Eqs. (VIII.6,8). The program calculates either the electronic eigendue or the correlations in the energy, Before calculations begin, Eq. (VII.8) i s solved for a (subroutine FARM), and the initial configuration (for the variational calculation, subroutine IITCFC) or ensemble (for PIMC, subroutine IITERS)are generated. The majn cdculations are done in subroutine AacsoH: thermazation in loop 10 and datatabing in loop 20. The Metropolis steps for the variational edculation are t&en in subroutine R ~ B O Pwhile , time bsteps for the PIMC caleul;3ltions me t&en in subroutine " f ~ mBoth ~ . methods use fanetions ELoCnL (to find the local energy (VIII.5) of a given configuration) and PAI (to calculate the wave function for a given configuration); each of these in turn calls subroutine RABXX to cdcalate relative distmces* IE ddition, 3["sTP&so c d k stt"fiout;iae BR3[m to cdcalate the drift vector and uses function GAUSSto generate a random number from a Gaussiw distdbution with, zero mean a d unit =dance. The electro~cdgenvdue is found from either method, adng observatians t&en every E F R E Q step, ~~ aad divided into goups to estimate the step-to-step carmlations in the enera. The merlgy correlations ase faund by setting E ~ E Q = = A ~ S M P L = ~ , staring the energies found from each sweep, and calculating the averin Eq. 8.17 (subroutine CRLTIIS). When the requested number of p u p s have been calculated, you will be prornpted for the number of additional groups to include [IO.]. Input The physical parameters are the inter-proton separation [a.] (so that a neutral Helium atom is being described) and the variational parameter p [.25]. (All lengths are in Angstroms, all energies are in eV.) The numeric& paameters include the method of cdculation variational] (rather than PIMC), ensemble size (PIMC only) [20], time step (PIMC only) [.Ol], sampling step in configuration space [.4], number of t hermdization sweeps [20], quantity to calculate [Energy] (rather than correlations), sampling frequency (energy only) [G], group size (energy only) [IQ],maJrimum correlation length (correlations only) [40], number of poups [IQ], and random number seed [34767]. Note that the sampling step for PIMC i s set equal to 1.5~in subroutine PnRnn. For correlations, the frequency and group size me se%equd to one. The maximum ensemble size is fixed by WAX=S= 100, and the maximum number of groups al10wed for correlations is fixed by RAXCRE= 500, Mote that for corrddions the number of noups must be
sipificmtly larger than the maximum correlation length (so the averages in Eq. 8.17 are st&isticdly sig&fiemt), but must &so be s m d e r than HAXCRR. These checks are perfarmed in subroutine PARAN. The text output parmeter d o w s you to choose the short version of the output for which the sample sums are not displayed [long version enabled]. Please see the note in C,? c o n c e r ~ a gthe random number seed and compiler storage of inlegtlrs.
Output Every NFREQ"~ step the text output displays the goup index, sample index, group size, and energy (unless the short version of the output is requested). For the electronic eigenvalue calculation, when each P L ' ~the ~ text displays the group group is finished (every ~ F ~ Q * E S Wstep), index, number of goups, average group eneru, and g r o ~ guncertainty as well as the total (inclading all groups calculated so far) average energy, the two estimzltes for the uncertainty in the enerm, the total e n e r g of the Hz system, and the acceptance ratio (variational method only). For the correlation calcul&ions, when ajli g r o q are complete, the program displays correlation vs. correlation length; the results are plotted if graphics are requested, or &e we vrritten as text. ccc~ccccccccecccccc~ccccccecccccccecccccccccccccccceccccccccccCccccccccc PRQGMM PR038 Praject 8: Monte Carlo solution of the H2 molecule C C0WUTATIONAL PHYSICS (FORTMM VERSION) C by Steven E, Koonin and Dawn C. Neredith C Cowright 1989, Addison-Wasley Publishing Company ccccceccccccccccccceccccccce~ccceeccccccccccccccccccecccccccccceecccC:ccc CALL I N X T ?display header screen, setup parameters S CONTXMUE !main loop/ execute once for each set of param C U L PARAM !get input from screen !calculate the efgenvalue far this value of S CALL ARCMON EOTO 5 END
C
CCCCCCCCCCCCCCCGCCeCCCGCCCCCCCCCGCCCCCCCCCCCCCCCCGCCCCGCCCCCCCCCCCCCCCCC
SUBROUTINE mCHOM C calculates t h e electronic eigenvalue or enerm auto-corralation C for a given separation of the protons
cccccccccccc~ccC~ecccceceeccccccccceccecceccecccccccccccceecccccc~cccccc C Global variables: INCLUDE q m M . P 8 " INCLUDE CIO,ALL' C Local variables: C enerw has t w o indices C first index is the level: sweep, group, or total
C
second index is the value: quantity, quantex2, or signa**2 ! energy R m L ENERGY [ 3‘3 ) REAL COlilFXG lhfCOQRD) !configuration
REhL W !weight Ear s i n g l e v a r i a t i o n a l c o n f i g W L WEIGHT ( W E N S 1 !weight of ensefirble meders R N eNSIYLI3&(MCOOW,mXEMS) ! e n s e & l e o f c o n f i g u r a t i o n s R W ESAVE ( m X C m ) !array of f o c a l e n e r g i e s f o r c o r r REAL EPSILN t l a c a l e n e r g y of CONFIG =&L ACCPT !a c c e p t a n c e r a t i o tthermalization index XNTEGER I T H E W !sweep and sample i n d e x INTEGER ISWP,TSMPL INTEGER IQUAWT I w a n t f t y index INTEGER IGRP !group index !nu&er of l i n e s p r i n t a d to t e r m i n a l INmGER NLINES !how many mre groups INTEGER MO= INmGER SaEQ,GROUP,TOTAL !which levef of c a l c u l a t i o n INTeGER VALUE,SQUW,SICSQ !which q u a n t i t y !what i s b e i n g c a l c u l a t e d ? INmGER CORR, EPS !which methad? INmGER P IMC ,VARY C Functions: REAL ELOCAL !local energy INTEGER CETINT ! g e t i n t e g e r d a t a Eran s c r e e n DATA SWEP ,GROUP,TOTAL/I, DATA VALUE, SQUAM, SXGSQ/1,2,3/ DATA EPS,COm /1,2/ DATA VARY,PXMG / 1 , 2 1
cCcecCCccccccccccccccccccccccecceecccccccccccceaccccceccccccccccccccccccc C
outputsumaryofparameters
IF (TTEW) CALL PWOUT (OUNIT, NLINES 1 IF (TFIm) CALL PRPIIOUT f TUNTT, %LINES) If (GFILE) CALL PMOUT (GUMIT,NLINES) G G
g m n r r ~ tialtial ~ mnfi~urrtionor a n s d l e of oonflgurationa (W2fBOD .EQ. V-%) TmE IE%WG(C-%C, I) C ~ F B O D.W.BZMCI
a&= Ern
m m
m
C
EBD IE X0
cm2xm
C
11
DO 11 IQUANT-1,3 ENERGY (TOTAL,IQUANT}=Q. CONTXNUE ACCPT=O WOE-NGROUP
! z e r o t o t a l sums
!zero a c c e p t a n c e ! i n i t i a l number o f g r o u p s
546
6.P ~ m m for s the Pprgjects C
15
!allow f o r more groups over 9ze-e
CONTINUE
!l@* ao zo zm=~aom-~am+1,~aom C
! z e r o group sums
DO 21 IQUANT=1,S ENERGY(GRoUP,IQVANTw CONTINUE
23 G
!loop evmr @weep# C
tta @&cap =L mTRoF (CaWf@,W, & C a ( r ) ELSE IB" (aTBOB .BQe PXHC) f o r a t h step TSTW (EMS=%, m G a T , WSXLE) EH@ PE
nE1- (HOD (XSrn,
IF (.NOT. TERSE) TNEN I F (TTERM) m I T E (OUNfT, 3 0 0 ) XGRP, XSWL, NSWL, EPSILN IF (TFf LE) WRXm (TUWIT,100) IGRP, TSHPL, NSMPL, EPSXLN FORNAT ( 5 X , "roup * (14, * sanrple "19,' of \,X4,5X, "nergy =*,F9,4) END IF
END I P CQWZNm
4
.BQ. CO=) F= E a r n ( Z m) =EmRGY {=@m,
=BE
!tkis %reap f a dexm laava ahnaarw for csrr
!or O.ZLZQa w e z ~ q e ~ { g m = , X C E Z , X-)
Ern X@ C
20
33
Q .
S
E
l czab aorr
C C
200
affaw f o r mare groups, taking care not to exceed a r r a y bounds MQRE=GETXMT (10,0, 10QOI WOW many more graups?? 1 I F ((CALC .EQ, GORR) .AND. (N@OUP+MORE .GT. NXGRR)) TNEN WRITE (OUNIT,200) mXCRR-HGROUP FORmT(' You will run out of s t o r a g e space f o r " + "err if you do mare t h a n "I3,' more gr@upse) MOREmGETINTtMXCRR-NGROUP,B,mXCRR-NGROOP, f # How many mare groups3' 1 END IF IF (NORE .GT. 0) THEN NGRQUZI=NGROW+MQRE NLINESmO IF (TTERM) CALL CLEAR
GQW
115
END IF C
ftETURX END
cccccccCccccccccccccccccccccccccccccccccccccecccceeecceceeccf:cccccccccc~ SUBROUTINE TSTEP(ENSNBL,WEIGHTCEE"51:tNl C take a t i m step using the Path Sntegral Nante Carlo method
~~cc~~cCcccc~cccccceccccecccccccccccc~ccccceecececcccececccccccccccccccc C Global variables: INCLUDE 'PAM,P8' C Input/<put variables RE&L InJEIGHT ( W E N S ) REAL ENSmL(NCOOm,WXENS) m L EPSZLN C Local variables: REAL CONFIG (NCOORD RE& R R m L EBm, INTEGER XENSEM INmGER XCOQRD N A L NQW
REAL SHIFT (NGQORB) C Functions: R M L GAUSS W& EWCAL
!weight o f ansemble m e w r s fI/O) !ense&la o f configurations (X/QZ !Sacal enerw o f CONFIG (output) ! conffguration
!weight for single config lclrnsnrble average local. energy and weight: !anse&le index !coordinats index tnamalfzation af weights !array containing drift vector !Gaussian random nu+r !30ml.energy o f t h e conflpration
ccccecccccccccccccccecccca;.ecccccccccceccccccccccc~cccccccecccccccccccccc 0, 0.
!log, war m u e e Z r
cONTIIx=
20
a m l (cOm16,saw%1
M) 3.0
XCW~11,8CWrn
+ J0 C
C
40 110
comxm
e DO 90 =88==5,
-SEX
Icra%crrhi_irCn
548
C. P.rogrmms for the Projects SO
Cam
(mSm)= B m m I G E F (TrnSEM)
G RETURN END
cccceccceeecccceccccccceccc~cccccccccccccccccccccceccccceccccccceccecccc SUBROUTINE mTROP (COWFZG, W, BCCPT) C take a Wtrapelis step
CCCCCCCCCCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCeCCCCCCGGCCCCCCCCCCCCCCCCC G Global v a r i a b l e s :
INCLUDE
PAMM. P 8'
C Xnput/Output v a r i a b l e s :
WAL COKFIG IP;ICOORD)
!conEipration
=U H
!weight for single c o n f i g REAL ACCPT !acceptance r a t i o C Local v a r i a b l e s : I N T E ~ Rr e a o ~ ~ !coordinate index R ~ CSAVE L (WCOORD) !temp s t o r a g e f a r l a s t c o n f i g !weight f o r t r i a l c o n f i g =&L, MTRY C Function: RmL PBX ! t o t a l wave f u n c t i o n REAL MNWOS !uniform random n u d e r CCCGCCCCGCCCCC@CCCCCGCCCCCCCCCCCCCC~CC~CCCCGCCCCCC~CC~CCC~CCCCCCCCCCCCCC m 10 ICO~m=~,XCOom e valuea I--5)itrial ateg 10
Cm%= W m - P m (CGWXQ) **2
I tz1,al weigh&
C
33'
))
TmN
XWF-aF+%
laemtiraaa aaaepg the taave m u wef** fu@rtcl: acw& r a k l o
E!or also = @ t o m old config 20
CQMZZrn IZ =TURN
END
ccccceccccc~cccccccccecccccccccececccececccccccccceccecccccccccccece~ecc REAL FUNCTXOPll iaL~A&(COBFXGj C c a l c u l a t e t h e l o c a l e n e r w f o r COEFIG
c~ccCcccceeccccecccceccccccccccccccccccccccccccccecccccccccceccccccccccc C Global v a r i a b l e : TMCLUDE V A M M . 9 8 ' C Input variables: REAL CoPJFIG(E3COf)W) C Local v a r i a b l e s : REAL TPOP, VPOP REAL EECQM REAL CROSS, CR0551, CROSS2
REAL ONEEl,ONEE2
!c o n f i g u r a t i o n
! k i n e t i c and p o t e n t i a l c o n t r i b u t i o n s f e l e c - a l e c orr relation ? c r o s s terms !an@ e l e c t r o n terms
a&
XI,XZ,YI,Y2,21,22
RE&
RIL,RIR,R2L,R2R,RJ2
!coordinates of 2 e l e c t r o n s ?relative distances WAL CMX1,CHI2,F !parts o f tba wave f u n c t i o n m& DOTRIL,DQTR2L,DOZ"RJR,DOTR2R !dot p r o d u c t s w i t h R 1 2 W& RJ2DRI,SR12Z !tsnrp v a r s f o r d o t products RE& CWI,FDcMI,SDCNT,UPCHf ! a t a d c o r b i t a l s mAE FEE,FDFEE,SDFEE,WFEE ! e l s e - @ l e e c o r r e l a t i o n s RE& DTST IEuclidean d i s t a n c e RE& R , X , Y t Z !dumy variables
cccccecccccccccecceccccecccecccccceccccccccccccccccccccccccccccccccccccc G
C
&fin* fmction. CEX (R) 2 -R/&) maX (R) =-CH1 (R) /A SD-Z (R) -I (R) /;A/& W a r (R)=$DC= (R)+2*EBCBI (R) /R
la t o d e orb&t a l
t i t * f i r a t diQr%wa%ive, I semnd & r i v a t i v s , ! a d I;aplacim
!aXcro-%lea c o s r e l a t i o n EEZ (R) =m (Rf (U=* (l+mrrAW) ) ) F D m (R) =m (R) / (W=* (l. +mT&*E)**2) li t c f i r a k ,aeaond Blariv, SBmE (R) aPBm8x (R) **a/(R) -2. -m*(R) /U=/ (X+W%&*R) **3 faad U p l a c i m (R) =BD(R)f 2 * F D m (R)/R
C I E%ali&m a m t m c a
DXIP ( X , X, Z) =SWZ (W**2fV**2+Z**2)
ccccccc~cccccccccecccccccccxccccccccccoececccccecc~c(=ccccceccccececc~ G
g a t aoordinatee rad r-i m X Z ( X I , Xz,T%, Y Z , I t r l , L2, Rllr, =L, =R, R2R, R3-2, GWTG)
C
C
aleaXat;e &et products with XL2 Rl2@===* (SEX-X2) +Yl* (XI-Y2) +%I* (21-ZZ) !convenient s t a r t i n g plaocl Im2b=S* 62%-22)12 tusaful wrrctant WWbm2Bm+a122 ! e t praducts wfth RA2 2mm-m122 mwhBOmL-m2**2 R=BO=R-m2**2 rdot pr&uaea of unit v e a t o r s
D@=R=DamR/mP m R C
e
C = T = a I (RlR)+Gal (m&) (=R) +mx(M&) 31
!piaeras of! the t o t a l rave fwct;fon
Icurzelation cxontribution (mCRX (Rlt)+WCHX (RXR) ) /Cm1 f rrlcrckron on* ( m c ~ r + W C H ~ (m) ) /cm2 l electron t w o aOSSl= (EaDaI (R%&) * W ~ M E D G E(R=) l *DQa%R)/Cm% l ozorrrs Lams GRWS2m (FDGWX (=L) *DOWWPDCHX *D@m2R)1-2 ~SS-2*SD~E(Rl2)*(~OSS1-~~S82)/B"
c OmZ+=SS) R + l./R2L
12
+
l.lR2R
- 2./=2)
tkineti a
!potential !t o t a l
5 60
C.Pwrmms for b&e Projects C
RETURN
END
cccccccc~Ccccccecceccccccccccccceecccccccccccccccccccccecccccecccccccccc SUBROUTINE DRIFT (GQNFIG, SHIFT) C c a l c u l a t e t h e d r i f t v e c t o r (SHIFT) for CONFIS
cecccccccccccccccccccccccccccccccccccccccccc~ccceccccccccccccccccccccccc C Global variables: C- Iny>ut/Outgut v a r f ables: =U COWLG (WCWRD)
!e a n f f g u r a t i o n ( i n p u t ) SHIFT (NCWRD) ! a r r a y c o n t a i n i n g d r i f t vector ( o u t p u t ) C Local vari&l@s: INTEGER TCOQRD ?caordinate index ? c o a x d i n a t s s af 2 e l e c t r o n s R m L XI,X2,Pl,Y2,Z1,22 !r e l a t i v e distances REAL RXL, RIR, R2L, R2R, R12 M A L CWTf,CHJ2,F ! p a r t s o f the wave f u n c t i o n -L CWI,FDCHI,SDCWI,WCMI. ! a t o d e o r b i t a l M A L FEE,FDFEE,SDFE;E,WFEE !elec-elec c o r r e l a t i o n s !dumy v a r i a b l e s =&L R aAl,FhGTA,FACTB,FACTE !useful f a c t o r s
RE=
CCCCCCCCCCGCCGCCCCCCCGCCCGCCCC~GCCCCCCCCCCCCC~C:CCCCCCCCCCCCCCGC~CCCCCCCC
C
darfinerf=a&iorta CHX (R) (-R/&) $B(RI =-Cgl: (R) /A s a a x (R) =CB% (R) /&/A (R) =SW= (El) +2*FDCB3 (R) /R
l at-o orbital f f t a Z S r s t hasrivatAve, !.scod
derivatim,
!& MpXaoiaa
C
Si'ES (R)=m (R/(W=*(2+=%&*R)
l o l a c - s f s a aozzelatian
I)
mmE (R) =m(R) / (mm*(2.+=Taw) **2) f i&B fArat, @0aaadb r i w , (R)= m m(E)**2/mz(R) -2 * *==*m (R) /W=/ (%+==*R) **3 w p m (R) e
c
~ m (R) +2q~m ( a ) /R
f a d Laplrai-
t ctoo=*m&ss imd xa&i W I Z (m,xZ?,'%l, Y2, E2,22, R11*,R2L, XbR, =R, R12,C-50)
d" (=R)
(=L)
!piecar of thr t;oCaP w a v e aa&ion
C
!P* ( E m 5 (=L) /mWFXE13 tmR)/=R) /CBI3 g* (E"-3 (=L) / ~ L - F D C(~ ~ 1I-)~ 1 /cm1
!uacafal flaeors
C
SlIImT ( l ) =FACTA*m+E&C!Pg* ( X l - n f
f &Aft
f o r ela&ron
samr (2) = F A ~ ~ A * Y Z + ~ A C ~ E * ) s m z (3)=FACT~*ZX+FAC~*far-%a)+ ~ x m * s 2 C
P* ( s a c g x (ML) / ~ L + F (D1 ~~ 2/=RI ~ ) /mz2 'E* (EDCE3 (W%) /R2L-FDCm (R2Rj /R=) [CBI2
e S-T
(4) =FMT&*X2-FACTE* ( X % - S )
!shift, f o r e l a o t r o n t w o
S=% (S)=FAcn*'P2-FAcm* (Zl-Z2) S m T ( 6 )=EACa*Z2-FXm* (21-ZZ}+B"A6FB*S2
C
mTURN END
cccc~ccccccccccccccccccccccccecccecccceccccccccccecccccccccccccecccccccc FUNCTION GAUSS(DSEED) !C returns a Gaussian randam nu&@r
with zero mean and: unit variance
ccccccccccccCccccccccceeccccccccecccF:ccccccccccccccccccccccccccccccccccc INTEGER IGBUSS ! sum index !randon nu-r seed DOUBLE PMCXSXON DSEEXS RE= MNPJQS !uniform random nu&er ~~cC~cCcc@Cc@cCCcCcCCCCCCcCCcCCcccccc~ccccceccccccccccccccccccccCcccccccc avSS=O * t @%m 12 = i f e m rmdoar it6 50
COmIm aQS5-US5 MTURN
-
?sa%rrcLs i x so that man=O
6.
END
cccccccccc~ccccccceecceccccccceccccececcccccccccccccccccccccceceGccccccc RE=
PUNGTIOlrJ PM1 (CONFIG)
C calculates the total variational wave function for CONFIE
cccccccccccccccccccccccccccccceccccceccccceccccccccccccccccccccccccccccc C Global variables: INCLUDE C P a M . P B ? C Input varSablss: RE& CONFIG (NCOOm) feonfiguration C Local variables: M& X1,X2,YlrY2,21,22 Ecaardinatas o f 2 electrons RE= R1LIRlR,R2LrR2R,R12 !relative distances CHXIR,CWIlL,CHI2R,CW12L,F !parts o f the wave function CNX,FEE !terms in the wave function muR !radius
ecc~~cccccc~e~ccccccccccccccccF:cecccccccccccccccccc~~ccc~~ecccccc~~ EBH (W)=C
(RII-=*
(%+mP&*E ) }Z)
f a k e d a oxbf t r l . f rl2eotzan-rlcrclsron tserzelakion
aaulrtr thr ~ a & i W Z X (X%, 152,Y%,Y 2 , El, Z2,=L,=&,
RZR,5'428,RIZZ, COWPIG)
e -X=&=
(=W)
! ~ I O M Be f Lha te+al wave fmcrL-ion
Z ! P a r (af 2t MHTlR) * (aISLI-CHXm)*E"
!khm whole lsung
C =TURN
END
ccccccce~cccccecccccccccccccccccccccccceeccccccccccceccccccecc~ccccccccc SUBROUTXNE fNTENS(EMS~L,WEIGWT,CONFSG~
C generate the ENSmL at t=Q for PfMC
~~~~e~~cc~~~~cc~~c~c~~~ccccccccecccceccccccccccccccccccc~cccc C Global variables: INCLUDE ' F & W . P 8 ' C Output variables: R E U CONPTG (NCOOM) WAL mIGHT (mXENS1 m m ENSWL(NCO0m,MENSf C Local varSables: INT&GER XSTEP TMTEGER TCOORD REU W KCPT INTEGER f EWSEM
!configuration !weight o f ens~ntblemeders rensenble of canfigurations !step index !coardlinats index !weight for single eonfiq !acceptance ratia ?snse&le index
c~~c~~~~c~~cc~cc~c~cec~ccccccccecccccccccccC:eccccccceccccecccccc fgmaraea r riag2a f n t i a l IW-G ( C m f c ; l , W) e
*EQ' a1
mm mIaT [=S=)
30
11 c
%mm 1sawa1wazy 10th oonggg
IraL rrll migher=l
C
R END
cCcccccecccccccccccccccccccccccccccccccccccccecccecccceccccccccecccccccc SUBROUTINE INTCFC [CONFIG,W) C generate a e~nffgurationICONFIG) and calculate its weight (W)
ccccccecccccccc~ccccccccccccccccccccceccccccceccceccccccccccccceccececcc G Global variable:
INCLUDE *PAWM.P8' C Output variables: MAL CONFIG { M ~ W R D ) m L W C Local variables; XMTEGER ICaORD C Function: RE= PWS WAL MNNOS ccccccceecccc DO 10 X 310
!configuration !weight f or single config !coordinate index !total wave function
!uniform random n-er
~~ee~~~c~~c~ee~~e~~~c~~cc~c~c
cam comxm C Q m I G ( 3 )*-X@
(3)4-52
!p&& configuration rk r m h B [DSrnj-.S) f canter *lac. 3 . at rf@t
GOWXQ ( 6 )EPrCOWIC (6)-S2 W-PBX
(comze)**2
? senter @%%a 2, at lafC lwcsigbd~hi**i?
RETURN END
ecccecc~~~cc~c~e~~~cceccccccccccccecc~~eccccecccccc~cecccccceecccce:c suBRavTxMe C R L T N S ( E S A ~ ) C c a l c u l a t e t h e energy auto-correlations
~c~cccc~cccccc~cc~~~cccecccccececc~ccccccccecceccccccccccccceccccceecccc C Glabal variables: INCLUDE fPARAM .P@' TMCLUDE 'TO ALL' G Input variables: REAL ESAVE f ~ c m ) C Local variables: RE= EI,EZK,ESQT,ESQPR,EIEK INTEGER I, K RE= ECQm ( B :mXCRRf INTEGER M 1 INmGER SCREEN INmGER PAPER INTEGER PILE DATA SCMEN,PAPER,FfLE/1,2,3/ I
!array of l o c a l e n e r g i e s f o r e o r r .
!sms ! i n d e x o f ESAm !energy a u t o - c o r r e l a t i o n s !nu*r o f e n e r g i e s i n sum !send t o terminal !make a hardcopy i s e n d ta a f i l e
c~cccC~ccccccccccccccccccccccccc~ccccccecccecc~e~cccceccccccccc~cccccccc M3 3.0 Z=O,HC=
lloep
w@t: c?ormlr&ion fen#b@
PT=O, EZXmO. BSQZmO. ESQm=O,
EXm=O, nr=Haaw -a 00
acr *%,m E X ~ E X + 4x1 B ~ ~ t eali@rulata EIZ=EfEC+ES&a(ItK) ESQX=ESQZ+ES&m (I)**2 ESQXX=EsQXK+ESAm (XtZ)**2 IEK+rn&rn [X1*ES&rn {Z+K)
EX=EX /MT t-2alat;e av%ragms EIE=EXB/NI ESQX=ESQI/NX rzsqm=ssaxa/Nr I&IBK=EXmIMI EGO= (X) (E~K-BX*EIKI(swv(gsox-Bx**aj1 1fs(zri2IESQ~-BXK**~?I 1 10 C
camzm XF (GTERHI THEN
!display r e s u l t s CALL PAUSE [*to see t h e e n e r g y a u t o - c o r r e l a t i o n s . ..W CALL GBFOUT (SCREEN, ECORR) ELSE I F (TTERN) TmN CALL PAUSE ( * C O see t h e energy auto-correlatians,..@,l) caLL emavT (ounxT, E c a m ) END I F
5 54
C. Pmgmnas for Ihe Projects IP [TFILEf CALL CmOUT (TUNIT, ECORR) IF (GHRDCP) CALL GRFOUT (PAPER,ECOm) SF (GFILE) CALL GWQUT(FILE,ECORR)
c RETURN END CCCCC~CCCCGCCCCCCCCCCCGCCCCCCCGCC~CCCCCCCCCCGCCCCCCCCCCCCGCCCCCCCCCCCCCC
SUBROUTINE AVEWG (ENERGY,ACCPT,SCRP) C c a l c u l a t e group a v e r a w s , add t o t o t a l s , p r i n t o u t
~c~ceecccceccC~ceecccccccceccceccccccec~eccccccccc~cccccC:ccccccccccccccc C Global v a r i a b l e s ;
INCLUDE *PAmM.P8' INCLUDE *1IO.ALL8 C Input variables: C energybastwoindlfces C f i r s t Index i s t h e l e v e l : sweep, group, o r t o t a l C second Sndex S s t h e v a l u e : q u a n t i t y , quant**2, o r sigrrmae*2 !e n e r g y REAL ENERGY (3 , 3 2 INTEGER XGRP !group i n d e x !acceptance r a t i o REAL AGCPT C Local v a r i a b l e s :
=&L EVALUE !c u r r e n t a v e r a g e energy REAL SIG1,5162 ! u n c e r t a i n t i e s i n energy RE& U ? t o t a l p o t energy of t h e system !number of l f n s s p s i n t e d t o t e r m i n a l INTEGER NLINES INmGER SFIEEP,GROUP,TQTAt !which level sf c a l c u l a t f a n 3CNmGER VALUE,S@rUARE,SIESQ ?which q u a n t i t y DATA SmEP,GROUP,TOTAL/3,2,3/ DATA VALUE, SQUAm,SXGSQ/1,2,3/
cccccccccccccccccccecccceeeccecccccccccccccccceecccccccccccccecccecccccc C
e7rrJalatr g z a ~ pamrager m& wmrtaAntfsrr
faam,=W)
(=am, m m ) /@SW& ( m m ,sQU-3 / N S W &
{=am, s1osqt =
0. )
SIGSQ) .&!E,
(=Q-,
G (%OS&,
mm)
(%Q%=,
SXCrSQ)
C C
X-
(%OF&, SXQSQ) ) /XC C
aaleulrcrs t o t d .
o f tha @yet-
]ZEga
D=Q.
Em? IF
c 1F (TTERM) CALL TXTOUT(IGRP,ENERGY,EVALUE,SIG~~SXG~~U,ACCPT~OUNIT~ IF (TFILE) CALL TXTOUT(IGRP,ENERGY,EVALUE,SI,G~.,~XE~~U,ACCPT,TUHXT~
c RETURN
END
~~c~e~~c~~~ee~e~~c~~c~ccceee~ceecceccccccc~ccccccccccccccccccccccc SUBROVTIME AaD11 (XI,X2, V % ,V 2 p 2 1 1 Z 2I R2Le R2LIRLRIR ~ R I G c a l c u l a t e s c a r t e s i a n c o o r d i n a t e s and r a d i i g i v e n CONFIG
coHpxGI
~ccc~e~~~~~ec~c~~ccccecc~~~c~~c~c~ceccccccccccccccccc~ccccccec C Global v a r i a b l e : INCLUDE "PAM.P8' C xngut v a r i a b l e s :
W A L CONFIG (NCBOm)
!configuration
C output variables :
f e o e r d i n a t e s of 2 e l e c t r o n s !r e l a t i v e d i s t a n c e s !Euel i d e a n d i s t a n c e
REAL X1,X2,VI,V2,Zl,Z2 W A L RIL,RIR,R2L,R2R,R12 REAL DIST
ccccccccc~cccecccccccccccecceccccecccccccccccccccccccccccccccccccccccccc DXST ( X X , XI,,!&%)=GmT (X1**2+X1**2+81**2)
!Eucll&ean &atan-
C
X 1 4 0 r n I G i (l)
X 2 d m X 0 (4) X l e W T 0 (2) Y2*0rnXGi
(5)
aoeamrc;( 3 ) Z 2 e w I G (Q)
e
mWDXSZ ( X % , Yl ,Zl+S2) mmD282" (Xl,Vl ,E2-82)
t ealmlrtr reparation*
mWDZST (X2,?C2,22+32) WmD1Sa" [X2,Y 2 , 2 2 - 6 2 )
U2=DSSIP [XI-x2,Yl-X2,21-82)
C
=TURN END CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCCCCCCCCCCC SUBROUTINE INIT C i n i t i a l i z e s constants, d i s p l a y s header screen, C i n i t i a l i z e s menu a r r a y s f o r i n p u t p a r a m e t e r s
ccecec~cccecccccccccecccccecccccec~ccccccccceccccc~~~cec~cc~cccccccccccc C Global v a r i a b l e s : INCLUDE ' 10,ALL'
INCLUDE 'NENU. ALL' XNCLUDE 'PAmW.P8'
C Loeal p a r a m e t e r s :
!program d e s c r i p t i o n DXMENSIOET DESGBE (20) INTEGER NNEAD,NTEXT,NGRAPM
!nu&er
of l i n e s for each d e s c r i p t i o n
558
C. Pmgrams for the P.rojects ecccCcccccccccccccccccccecccececcceeecceeeeccccc~eccccGccccCcccccccccccc C
get environment paramters CALL S E T W
c C
display beader screen DESCRP (1) = 'PRQJECT 8 * DESGRe(2)m 'Monte Carlo solution of the K2 molecule" NBEADm2
C C
textoutputdescription DESCRPf3f='eelectronic elgenvalue and its uncertaintyf DESCRP (4) 'or energy auto-correlationt NTEXTa2
-
G graphics output description DESGBQ ( S ) = *enerw auto-correlation vs. correlation length' NGMP W=1 C
m
HEADER (DESCRI,, MWEAD, NTEXT, N a P W )
calculate constants mHm7.6359 E2=14.409 ABOHR=WBN/EZ
i hbar*2l (mass) Icharge of the electron
setup menu arrays, baginning with constant part MENU
-
MTYPE f 12)= T T T U IVIPWT (12) 'PHYSICAL E"-=TEES* MLOLXN (121 -0. MHILIN (12)-2.
MTEE f l3 f =FLOAT MBMPT(13l='Enter the interproton separation S (Angstroms)' MTAG f l 3 )="Iner proton separatfon (Angstroms)* MLOLXM (23)=Q. WWILIM 113)=IQ. m a L S (13)=Q. MTWE ( 14 1=FLOAT W W T [14)= + #Enngr v a l u e for variational parameter Beta (Angstramsx*-l)@ MTAG(ll)=rvvriatianal parameter Beta (Angstrams**-l)" NLOLIM (l. 4 ) =Q. MHILIM (14)-IQ. MmLS(l4)=.25
m W T 1371 = NUMERfGAL P A m E T E R S f MLOLIM (371 -1. MWTLTM[37)=1. C
MTmE (381 =TITLE M P W T f 38)=%ethods MLOLTM(38) -0. MNILIM f 381 4 3 .
of calculation:
C
MTYPE ( 3 9 )=@TITLE (39)=Q) Variationalf MEOLSM(JB)=O, MHILXM (39)=Q.
IyIPWT
C MTWE (40)=MTITm NPRMPT (4Q) 2) Path Znteqral Monte Carlo'
MLOLTM (40)==Q, MNILIP1(40)=1. C
MTYEE (41) =MGWOIC M I ? W T (41)='Make a menu choice and press return' MTAG ( 4 2 ) - 9 4 42' ~ ~ o ~ r n ( 4=I. 1l MHJLZM(41)=2. MINTS (41) -1 m A L S (41)=X. C
M T W E ( 42) -MUM M P m T (42) * Enter size of the enss&lec MTAG 142) = 3nse&le sizet NLQLIM (421 ==l. MWILIM (42f =MXENS MINTS (421=ZO. C
MTVPE ( 4 3 ) =FLOAT W m T (431=@Enter time step (units o f 1E-16 secthbar) MTAG (43)=*Tine step (units of lE-l6 sec/hbar) NLOLSN143fPO. MWILSP4[(43)=lOI M W L S (43)=.a1 C
NTYPE ( 44) =FLOPIT MPMPT(44)= 'Enter step size far sampling PHI (Angstroms)' MTAG (441 "ampling step size t&gstrans) MLOLIM(44) m.01 MHIXIIN (441=10. MRmLS (441=.4
-
C
MTVPE (45 ) =NU% m W T (451 = 'Mu&er of tbermalization sweeps" MTRGf45f 'Thermalization sweepst MLOLZM (451 =a
558
C. Pmgmms for the Projects MWILIM (45) =100Q MINTS ( 4 5 ) -20 MTUPE ( 4 S) =TITLE M P M T (46)=1Quantlty to calculate: ' FILOLfM(46)=1, MHILIM (46)=Q. MTYPE f 47) =MTITLE MPmPT (47f b 1 Energyf =@
mQLTM(47) =0, MHILIM (47) -0.
MTYPE ( 48) =MTITLE W M P T (481 =22)Correlationsc WLOLIM ( 4 8 f 4. MHILIM ( 4 8 ) =l.
N T W E ( 491 =NCHOTC MPMPT 4 9) =' Make a menu choice and press returnf MT&G(49)-'50 53# NLOLIM (49)=l. MNILIMi49)-2, MfNTS (49)=l LS (49)=1. M T D E ( 5O ) =NUM MPmPT { S O ) = *Enter sampling f requency (to avoid correlations) MTAG ( 5 0 ) = Sampling frequency" MLOLIM (SO)-1 MHILIM (50)m100 MINTS (50)=6 MTZSIIE (511-NUM *Enter nudar of samples in a groupC MThG (53.1~ Group sample s i z e t MLQLIM (511 =l. NHILTM (51f =l000 MINTS (51)=IQ MPWT(SL)=
M T W E (531 =NUM MPWT(53)m 'Enter maximum correlation Lengthe MT&G153)= eMaximum carrelation length8 MLOLIM ( 5 3 f =l MWILIM (53) =100. MINTS ( 5 3 )-40
MTVPE ( 51 ) =NUN M P W T (54)= 'Enter nun\ker of groups"
@
MTAG(54)m q u & e r MLOLIM ( 5 4 1 =X MBILZM(54f-1000 MINTS (54) =10
o f groups'
C
MTYPE (S51 =NUM MPmPT155)= "Integer random nu&er MTAG (55) = "andam n u d e r s e e d " HLOLIM (55) =1ODO. MHILIM (55) -99999. MINTS ( 5 5 )=J4757
seed f o r f n i t fluctuatlsnsf
e MTYPE ( 5 6 )=SKIP NmALS (561 =GO. G
MSmMG (MINTS(75)) = 'proj8, t x t '
c NTYPE ( 7 6)-BOOLEN ME)MPT(76)=9o you want t h e SHORT v e r s i o n a f t h e o u t p u t ? ' MTAG (761=%Short: v e r s f on o f o u t p u t " MINTS ( 7 6 ) m 0 C
MTVPE ( 7 7 ) =SKIP NRMLS 177) =80, C MSTRNG(NINTS(86f) = " r o j 8 , g r f t C
MTWE 4 87 ) =SKIP
Mm&LS (87) 0.90.
c RETURN END
ceccccccccccccccccccccccccccccececcceccccccccccccccccccccccccccccccccccc SUBROUTINE P m M C g e t s p a r a m e t e r s from s c r e e n C ends program on r e q u e s t C c l o s e s old f i l e s C maps menu v a r i a b l e s t o program v a r i h l e s C o p e n s new f i l e s C c a l c u l a t e s a l l d e r i v a t i v e parameters C p e r f o r m s c h e e k s on p a r a m e t e r s
ccccccccecccCcccceCcccccccccceccccccccccccccceccceccec~cccccccccccc~cccc C Global variables:
XNCLUDE
" mNU.ALL'
' TO. ALLe SNCLUBE 'PAMM, P@' C Local v a r i a b l e s : WAL AQLD INCLUDE
!temp v a r i a b l e t o s e a r c h f o r A IMTEGERCORR,EPS !what1sbr?ingcalculated? INTEGER PIMC, V-Y !which method? C g i v e s t h e map between menu indices and p a r a m e t e r s INTEGER f S, IBETA, IMETRD, XNENSM, IDT, IDELTA, fTHEW, ICALC,
560
C. Programs for the Projec.l;r
+
INFREQ, TWSMPL, I N C G m , IGROUP, EBSEED, ETERSE PARAMETER ( I S = 3-31 PAWMETER (IBETZL 24) P m m T E R fZMETMD 41) TEIR (TNEMSM = 421 PAMMZTER t I D T = 431 P A W E T E R (IDELTA = 4 4 ) PAmMETER (ITHERM P 451 PAmHETER (XCALC = 49) P A N E T E R (INFMQ SO) P m m T E R (INSMPL m 5 1 ) 53) PAmmTER (IUCOm P A m m T E R (IGROUP 54) P W M E T E R (TDSEED = 55) P A M m T E R {ITERSE 76)
-
C
-
Functions:
LOGICAL LOGCVT ! c o n v e r t s 1 and O t o t r u e and f a l s e !get i n t e g e r from s c r e e n INIIISE;ER GETIWT DATA VmU,PIMC / l , a / DATA E P S , C O M /1,2/
~~~c~~~cccc~~cCccccceccE:ecc~ce~cccccccccccccceccccccec~ccc~cr:ee~c C
getinputfromterminal CLEAR CALL ASK ( I , ISTOP)
C&=
C
c
stap program i f requested I F [ m A L S ( I M S # ) .EQ, STOP) GALL FINIS&
C C
close files if necessary fF ( T N B CALL I F (GNAm + CALL
+
.NE. NSmHG (MINTS (ITHAME) ) FLCLOS f TNAm, TUNI Tf .NE. MSTRNG (MINTS (SGNAMEI )) FLCLOS (GHME, GONIT)
e G
C
s e t new parameter v a l u e s physical and numerical S - W A L S 4 IS ) B E T f l m m A L S (3BETA) mT&oD=MINTS (IMETHD) NENSEN=NINTS ( INENSM f D T = m A L S (IDTI DELTAmWALS ( IDELfl"A1 NTmW=MIHTS I I T N E M ) CALG=MTNTS (TCALCf MFmQ=MINTS ( INFREQ) NSWL-MENTS (INSM?.I,j NGORR=MTNTS ( I N C O m ) NGROUPmMXNTS (IGROUP ) DSEED-DBLE {MINTS (IDSEED) f
C C
t e x t output
TTERM=LQGCVT (MINTS ( ITTERM) )
TFILE=LoGCvT (MINTS ( I T F I L E ! ) THMaMSTRluG (MINTS ( I T N A B 1 f
TERSE=LOGCVT(MINTS(ITERSE))
e C
graphics output GTERN-LOGCVT (HINTS ( X GTERE(I1) GHIIDCP-LOGCVT (MINTS(IEBRD) 1
GFILE-WGCVT(MZNTS(TGFILE11 GNAME=MSTRNG(MfNTS(IGHAHE)) C G
openfiles
TF ( T F I L E ) CALL FLOPEM ( THAm, TUNIT) I F (GFILE) CALL PLQPEN [GM-, GUMI T) !files may have been renamd MSTRNG (MINTS (ITNAmff =TM&M MSTRHG [MINTS (XGMAm) f -GNAME
c C
check parameters for correlations, fix NPREQ, N S m L IF (CALC .EQ, cow) THEN NFREQ=1 !fixed for correlations NSMPL-5 I F ( (WGROUP GT. mXCRR) CIR. ( (NGRQUP-NCOM) LE. 20 f f THEN
.
20 30
+
.
END fF END I F
e CALL CLEAR G
C
calculate d e r i v a t i v e parameters A=mQRR AQ~I.Q.
10
fP
(&-A@=) &O&M
&-@m/ (S+-0
.
FJRTTE (OUI\IIT,*) ' m I T E (QlfNZT, 20) m T T E (OUNIT, 30) MGRQUP, N C Q m t 2 0 , M C R R F O W T ( 5 X , V o r teasongble values of the correlations ' ) F O W T f 5 X I f 1GROUO ( r , I 1 4 , * j must be btueen NC0=+20 (', f Q , * f and mXCRR ( * f 1 4 t t ) @ ) WRXTE (OUNIT,* l * ' NCOM=GETINT (NCORR,1,100, C Reenter NCOm' ) NGROUP=GETINT(NCORR+lOO,WCO~+ZO,WC~,fRe-ent;drNGROUPrl MTNTS [ INCORR) =NCO= MINTS (fCR0UP) mNGROUP
.G%. 1.E-6) T a H (-51AOW) )
50
END IF s2=s/2 WBrnT=HBM*DZ" SQWBDT-SQRT (NBMDT) ALPWII=2*ABQWR
IF (METHOD .&Q. PIMC] DELTA=l.5*A
582
C. Programs far $he Projects =TURN END
e~ec~e~e~cceec~ce~ecccccf:ecccccccccccccccc~ccccececccf:ceececcc-~~~c SUBROUTINE PRNOUT (MUNIT, NLINESI
C write out parameter su CCCCCGGCCCCCCCG~CCCCCCCCCCCCCCCCCCGCCCCGCCCCCCCC~~~CCCCCCCCCC~CCCCCCCCCC C Global variables: INCLUDE 'X 0 .ALLC INCLUDE V m M . P 8 "
C Input variables: INTEGER M U N I T INTEGER NLINES G Local variables: INTEGER CORR,EPS INTEGER P IMC, VARY DATA aas,com /r,2/ DATA VARY,PZMC /li,a/
!fortran unit nu&er !nu&er of lines sent to terminal !what i s being calculated? !which methad?
~e~~~~~~ceccccccecccccccecc~cccccc~cC:c~ccccccccccccccccccccc~ccccc XF (MUNIT .E@. GALL C L E M
OUMIT) THEM
ELSZ m I T E (MUHIT,"] WRITE (NUNIT,") END I F
"
"
G
e
Ir3RITE [ M W I T , t i ) WRITE (NUNIT, 7 ) S WRXTE (MUNIT, 81 BETA WRITE (MUNIT, 9) A WRIm (NUNXT,*) ' ' I F (MTNOD .EQ. PXMC] T8EN W I T E (MUNLT,IQ) NENSEM, D5 ELSE WRITE (MUMIT, 11) END I F I F (CALC ,Ea. CORE) hlRITE (NUNIT, 12j NCQRR m I T E (MUNIT, 13 f DELTA WRITE (MUHXT,15) %THEW WRITE (MUNIT, 20) WMQ, IJSMPL WRITE (MUNIT,*) ' ' NLXIJES=11
e 5
Output from project 8:* , "ante Carlo solution of the 82 mo2eculetj F O M T (' Proton separation (Angatrams) = * , F 7 . 4 ) F O a T IVariationfll parameter Beta (Angstroms**-2) = ',E"7.4) F O m T (' Wave function parameter A (Angstroms] = @,,FT. 41 E"QW"Pf Path Integral Monte Carlo with ensemble s i z e = 5 x 4 , + "and time step = ',lPE12,5) F O W T t Y Variational Monte Carlo mthode) F Q m T ( ' correlations will. be calculated up to K = 5 14) POMT
+
7 8 9
10
I2 l2
(c
13 15 20 E:
F O m T ("et r o p a l i s s t e p i n c o o r d i n a t e s p a c e (Angstroms) =' ,F7.41 ,141 F O W T ( f nnuder o f t h e r m a l i z a t i o n sweeps =@ t 14, "group size I41 F O W T ( * sweep fraqrlency RETURN END
c~e~~cc~e~c~~~~~~~~~cccccccccccccccccccecccccccceccccI:ececc~ccccec SVaOUTTME TXTOUT(IGW, ENERGY,EVUUEI SIGI, SIG2, U tAGCBT, MUNXT]
e w r i t e o u t r e s u l t s t o MUNIT
~~c~~~ee~e~ec~~~~~~ecceccccccccccccccececcccccE:cccC:~cecccE:cc~cecE:cE e Global variables: INCLUDE * I0.11LL8 C Input variables: e e n e r g y has two i n d i c e s C f i r s t i n d e x i s the l e v e l : sweep, group, o r t a t a l C nd i n d e x i s t h e v a l u e : w a n t i t y , w a n t * * 2 , o r sigma**2 LNERCjY (3,s) t energy !group i n d e x EVALUE !c u r r e n t a v e r a g e e n e r w SIG2, SIG2 ! u n c e r t a i n t i e s i n energy U ! t o t a l energy a f t h e s y s t e m a t this S !a c c e p t a n c e r a t i o REAL ACCPT ! u n i t t o wzlte t o TWmGER M m I T C Local v a r i a b l e s : INTEGER SmEP,GROUP,TOTAL !which l e v e l o f e a l e u l a t i o n INTEGER VALUE,SQUm,SIGSQ !which c.fuantity INmGER PIMC, VARY !which ntrithod? XIA"X "AEF,GROUP,TQTAL/1,2,3/ DATA VALVE, SOU-, SIGSQII, 2,3/ DATA VARY,PIMC /1,2/
GcccccccccccccccccccccccccccccccccccccccccccccccccccccccecccccE:ccccccccc WRITE (MUNIT, 1 0 ) IGm, WGROUP, ENERGY (GROUP, VALVE ) ,SORT (ENERGY (GROUP, SIGSQI 1 I F (WTRQD .EQ. V m Y ) THEM m I T E ( W H I T , 20) EVUUE, SIGl,SXGZ, U,ACCOT/TGW/NFmQ/NSE(VeL ELSE WITE {MUNIT, 30) EVALUE, SIG1, SS62, U END SF I F [NUNIT .EQ. TUNIT} WaITE (MUNIT, * ) ' *
+
G
+ 10
SF ((MUMIT *EBI OUMIT) -AND, (.NOT, TERSE))
FQ-T
+
20
CALL PAUSEtftta c o n t i n u e . . . C , l ) ( 2 X F f G r a u p \ X64,' o f t , I4,SX,"Eigenval~e=~,,F9,4, +- ' , F 8 . 4 )
F O W T (2X,fGrandaverageE=f,F3,4,~-\F8.4,1/F,F884, 4
30
FO-T
+
U=',F9.4,' a c c e p t a n c e = *,,F6.4) (2X,CG~andaveragsE=*,,F9.4,r+-~F8.4,*/1,F8.4, I U=*,F9.4)
RETURN END
ccE:cccecccccccecccceccecccccccceccccccccccccccC:ccccccccccccccccccccccccc
664:
G. Pvogmnzs for the ProjeeZs SUBROUTINE GRFQUT(DEVICE,ECORR) C outputs enerw auto-correlation vs, correlation length CCCCGCCCCCCCCCCCC@CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCC:CCCCCCCCCCCC
C Global variables INCWDE ' IQ.ALL'
INCLUDE * F M M . '!?Bf XNCZUDE GRFDAT ALLC C Input variables: REAL E C O m ( O :W C R R ) IMmGER DEVICE C Local variables mAL K ( 0 :W C R R ) INTEGER IK
.
JNTEGER SGmEM INTEGER PAPER INTEGER FILE IMmGER LB, LS,LG DATA SCREEN,PASER, FfLE/1,2,3/
tener~yyauto-correlatians !which device is being used? !correlation length !correlation length index !Beta, S, NGROUP as character data !send to terminal tmake a hardcopy !send to a file !true length o f character data
ccceCcc~cccecccccc~ccccec~ccccccccccccccccccccceccc~cccccccccceccccc~ccc C
mssagss for the impatient IF (DEVICE .NE, SCREEN) m I T E tOUNIT,l08)
C C
calculate parameters for graphing IF [DEVICE .NE. FILE) THEE NPLOT=I !haw many plots? IPLDT=1 !limits on plot
!line and sy&ol
styles
!titles and labels CALL C O m T (BETA,CB, LE) CALL C O m T [S, CS, LS) CALL XCNVRT (NGRQUP,GG,LG) fNFOmfNGRoUP = *//CG(l:LG) TITLE = ' H2 molecule, S="/CS (5:LS) //', Beta='//CB f1:LB) MBEL (1)= T~crelationlengthr MBEL ( 2 )= *Energy auto-carrelation' CALL GTDEV (DEVICE)
!device ncmination
I F [DEVICE .EQ. SCmEN) CALL GNODE CALL WLNAX END I F
!change t o g r a p h i c s mode !draw a x e s
D0 10 IKeO,N C O M
? f i l l a r r a y a E corr l e n g t h
C K ( I K ) =mAL (XRf CQHTINIEB
l0
c output r e s u l t s I F (DEVICE .Ea. FILE) "rW%
C
mXTE (GUNIT,") ' * WISZTIF: (GUPJIK2S) NC;ROUO
mxTE (GvraxT, 701 (K ( I K ) , ECOm (IKI, IK-0, P;ICOm) ELSE CALL XmLOT (K, ECORR) END I F
e endgrapbingsession I F (DEVICE .NE. FILE) GALL GPAGEtDEVICEf O S g r a p h i c s package EF (DEVICE .EQ. SCREEN) CALL TMODE !switch t o t e x t m d e
C
C 70
F O m T
25
(2(5X,E21,3))
F O m T ( CX, ccrrr l e n g t h f ,,5X, + ' e n e r g y a u t o - c o r r e l a t i o n Ecr NGROUP=',XS) F O M T (I,' P a t i e n c e , p l e a s e ; o u t p u t g o i n g t o a f i l e . ' ) @
100
m"Pm
END cceeecceccceccccccceccccccceecccC:ccceccccccccccccccccececccccccccceccccc SUBROUTINE CRRQUT (NUIUIT, ECOW) C
write o u t c o r r e l a t i o n s t o MUBIT
c c c c c c c c c c c c c c c c c c c C : c c c c c c c c c e c c c c c c c c C Global variables: ,P8, INCLUDE 'P INCLUDE 'XIQ.ALLr C Input variables: W& $Corn 0 :M C R R ) INTEGER MUNIT C Local v a r i a b l e s : INTEGER X. TNmCER NLIMES
!energy a u t o - c o r r e l a t i o n s
!unit t o write t o !correlation length !nu&er o f l i n e s w r i t t e n t o s c r e e n
cccccccccecceccccccccccccccccccccccccccccecccccccccceccE:ccceeccccccccccc I F (MUWIT .EQ. OUMITf THEM GALL CLIF:&R ELSE m I T E (MUNIT,*) END I F
C
30
NLINES=I YilR1'L"X [MUNIT, JO) NGROUP F Q W T ( * C a r r e l a t i o n s w i t h NGROW DQ 10 K=O ,EGORR NLINES=NLINES+l
"151
666
6, Programs for the Projects WRITE (MUNIT, 20) K, ECORR ( K ) IF ( (MUNXT .EQ. OURIT) .AND, (MOD [NLIMES, TRMLIN-3) .EQ8 O) ) THEW CALL PAUSE {*to eontlnue., v 0) NLINES=O EMD I F CONTINUE IF (MUHST .NE. OUNIT) WRITE (MUNIT,*) p FQ-T (5X, Correlation length = ', 13, 5X, + -nerg_y auto-correlation = FF12.51 MTURN END
.
10 20
cccccccccccCcccccccccccccccccccccccceccccececcc~cccccccccccccccccccccccc ceecc~eccccceccccccccccccce~ccecccccccccccceccceccccccccc~ccccceccccccc~ C paramlp8 C =U S WAL S2 M& BETA INTEGER ~ S W O D , C ~ ZNmGER NEMSEM M U IZT RE= DELTA I N m G E R MCQm I N m G E R NGROUP DOUBLE P m C I S I O N DSEED INTEGER M T m m Jc#mGER N F M Q INTEGER MSElIDL LOGICAL TERSE
tinter-praton separation !S / 2
?variational parameter !which method? which want to calculate? !anse&le size !PIMC step size ?step s i z e in confirguration space !max correlation Length !initial group size frandom nu-r seed tnufier of thexnalfzatfon sweeps !freq of sweeps to avoid correXatlans !size o f groups !terse output?
c WAb,
A,ALPm
mm
HBM E2
RE&
AI3OHR RBMDT SQmDT
!constants in PHI !hbar**2 divided by electron =ss !electron charge swared !Bohr radius (Angstrams) !kbar**2*dt/m !sqrt (hbar**2*dt/m)
C
TNTE(;ER M;E:MS
!maximm ense&fe
size
INTEGER mX(3RR !max n d s r of groups fss correlation SMBGER NCOIORD !nu&er of coordinates P W m T E R (MENs=ZOO , M C R R = S O O,NCOORDm6 1 G COmON / PP
/ S,BETA / DSEED, NTWERM, NFREQr NSNPL*NETHOD' CALC, NENSEM@ DT, DELTA, WCORR, NGROUP ,TERSE GONMON / PCALC / A, $2, WEIMDT, SQWBDT CQmON / CONST / E2,ABOMR,ALPHafWBM
+
Appendix D
Common
D.1 Standardization Code This program strips the non-standard '1' comment delimiter out of other FORTRAN codes. It is completely standard, requires no editing to run (except you must set TEM equd to the unit number connected to your keyboard), and prompts for the names of input and output files. C STR1P.FOR C Reads in a FORTMN code and d e l e t e s a l l c C s t a r t i n g with t h e non-fortran-77 standard C a l s o d e l e t e s a l l blank l i n e s
e TER*@D ANSWR, FIRST L G T C A L EXSK OPN, FOUND
INTEGER EXCLN, SPRCE INTEGER TEW,OUNIT,IUNIT INTEGER I,ASCI%,NQMBLK C
EXCLM+xlCNARf ! ' 1 spAce=xcrusa(r * I G
u n i t s f o r keyboard, XNPXLE and DUTFIL (change t h e s s if necessary] TERM=5 EUMITm10 OVNIT=20 CCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGCGCCCICCCCCCCG l0 CQNTXNUE
€2
C C get nam o f input f i l e and open f i l e C
PRINT *, IEWTER N M OF FBRTMN PRBGmM' =D (TERH,SO) INFXLE
C
20
INQUIM(FIZE=lNFILE,EXIST=EXSTIQPE:NED=OPN] IF (EXST EQV. .FALSE. ) THEN PRfNT *, 'FILE DOES NOT EXISTf P R I N V , 'ENTER ANOTHER N M ' READ (TERMI6O) INFILE ELSE IF (OPN .EQV. .FALSE.1 THEN QPEN(UNIT=IUNfT,FIZE=fNFILE:,5TWTUS=fOLDr) QPW=.TRUE. END IF IF (OPM EQV, FaSE,1 GOTO 20
.
.
.
C G g e t name o f output f i l e and open C
PRINT *, "EMER %AME OF NEW P I U p R m D (TERM,60) OUTFEL G
line is f o r a VAX o n l y ~PEN(UNIT=OUMIT,FTLE=OUTFIL,STATUS='NE1f,CARRIAGECONTROL=rLXSTf~ C this line is f o r any other machine OPEN(UNIT=OUNIT,FILE~OUTF~L~STATU~E+'NEW~~ C C read e a c h line o f i n p u t f i l e and s e a r c h f a r * ! " 35 = D (IUMIT,60,END-50) LINE FOUND=.FBLSE. C this
C
S=0 45
C G
NONBLKsO IF ( (FOUND .EQV. .FALSE* 1 .AND. (I .LT. 80)) THEN X=I41 ASCII=ICHAR f LIME (1:Iff I F (ASCL1 .EQ. EXCLH) THEN FOUND=,TRUE. ELSE IF [ASGII .NE. SPACE) THEN NOHBLIC=I END IF GOTO 85 END IF p r i n t up t o last nonblank c h a r a c t e r , exelude "!" IF (NONBW GT , Q1 WRITE (00NET,60) LINE 41 :NONBLR)
.
C
GOTO 35
50
CONTINUE
e CLQSE (UNITmOUNIT) C M S E (UN1TmIUMIT) C C a l l o w for a n o t h e r f i l e PRlClJT *, 'DDO YOU WISH TO STANDmDIZE ANOTHER F I m ? [Yj' READ (TERN, 60) ANSWER G
FIRST-ANSWER (l;11
IF ([FIRST .EQ. C
GOTO 10
C 60
FORWT (A)
END
.OR. (FIRST .EQ. 'n'))
STOP
570
D. Commosz Utility Codes
D.2 Hardware and Compiler Specific Code SETUP.FOR includes afl parmeters that depend on Jrour computing environment, ft therefore w111 require @&tingeFor details on how to make the appropriate changes, see Appedix A.3. C f i l e SETUP-FOR
CC~CCCCGCSCcC~CCCCC~CCCC[:CCCCCCCCCCCCCCCCCCCCCC~I:C~CCCCCCCCCCCGC~CCCCCCCC SWROUTINE SETUP G a l l o w s u s e r s t o supply i l o parameters f o r t h e i r computing e n v i r a n m n t
c~c~cccccccccc~cccccccccccccccccccccececcccccccccececccccccccccccceccccc C Global v a r i a b l e s : INCLUDE ' IQ ,AIL&"
e~~c~ecccC~cccc~c~eecccecc~cccccccccccceccef:eccccccccC:eccecccccccccccccc C G C
f o r t r a n u n i t nu-rs for ilo u n i t f o r t e x t output t o a f i l e TUNTT-10 u n i t f o r g r a p h i c s output t o f i l e
GUNIT-20 C C
u n i t f o r i n p u t from keybaard IUNIT-5 u n i t f o r output t o screen
QEZNIT-6
e
u n i t f o r input of data DONIT=11
c C
how many l i n e s and c o l u r n s of text f i t on your s c r e e n ?
TmLIN-2 4 TmXDm80
C
e
C
d e f a u l t o u t p u t parameters There a r e f i v e farms of o u t p u t provided, h e r e you a r e chaosing which forms of output you w i l l went MOST o f t h e t i n e (any c o M i n a t i o n i s p a s s i b l e f , you always have the o p t i o n t o change your mind a t run time. O=RD f=ye~ do you want text sent to the s c r e e n ? TXTTRM=1 do you want t e x t s e n t t o a f i l e ? TXITFIL=O do you want g r a p h i c s s e n t t o the s c r e e n ?
C
GRFTRNmO do you want g r a p h i c s sent t o a hardeopy d e v i c e ?
C C
C C
G G C
C
GWBRD-0 do you want g r a p h i c s d a t a s e n t t o a f i l e ? EWFEL=0
C WTURM
END
Cccccccccccccccccccccccccceccccecceccccccceccceccccccceecccccececccccccc SUBROUTINE C L E m C c l e a r s t e x t s c r e e n by sending an escape sequence:
-D,$ Bardwane
and Gnapiler Specific Code
571
C check your t e r m i n a l manual f o r t h e c o r r e c t seguence C THIS IS NOT AN ESSENTTAL ROUTINE YOU CAN LEAVE IT BmNK
-
C:cccccccccccccccc~C:ccccccccccccceccccCccccccccccccccccccC:ccccccccccccccc C Global v a r i a b l e s : INCLUDE ' 10,ALLf
C! Local v a r i a b l e s :
CNAmCTER*l ESC2(4),ESe2(6) IHTEGER I,11,22
!escape c h a r a c t e r s !index 05 escape sequence a r r a y s
~ecce~~e~c~~~ecc~~~~eccccc~cccccec~ccccccccececccceececccc~ccccc~cc C VT200 terminal;
t e x t made
ESCl (l)=CHAR f271 ESCI(2) =CH= (911 ESCI(3)=CH&R (50) Esclf4f =CmR(741 114 ESC2 fl)=CH&R (27) ESC2 (2)-CH&R(91) ESC2 ( 3 ) =CHAR (49) ESC2 ( 4) =CHAR (5 9) ESC2 45)=CHAR (491 ESC2 (6)- C M R (102)
! <ESC>[i?J
f2=S
C C TEK4OlQ
C C
C e C
ESCl (l)=CHAR (27) ESCl f 2)=CHAR (121 21.12 I 2=0
C PST [Prime) C ESCllf )=CRARf27) C: ESCl(2 f =CHAR (63f C P1=2 C X2-0
ccccccC:c~cccccccCcccccccceccccccccccccccccccc~cccceccccccccccccc~ccccc~c C C 10
m I T E (OUMIT,10) (ESCl(I1,I=l,I11
bJliZITE (OUNIT,ZO) (ESC2(P),3=1,T2) F O R m T ( 1X,6A1) RETURN EPJD
ccccccccccccecccccccccccecccecccccccccccc~ccceccceccccccccccccec~ccecccc SUBROUTINE GMQDE C switches t e m i n a l from t e x t t o g r a p h i c s mode C! by w r i t i n g hardware dependent escape sequences t o t h e t e r m i n a l C This r o u t i n e c o n t a i n s the escape s e w e n c e f o r a Graphon t e r m i n a l C t o switch between VT200 and TEK4814 modes
~eC:cccccc~ccec~ccccc~ccccccccccccec~ccccce~ccccccccccceccccccecccccccccc C Global v a r i a b l e s : INCLUDE ' IQ.ALL" C Local v a r i a b l e s :
CHmGTER*l ESC (2) ESC (l)=CHAR (27)
! a s c i i codes for eESC> 1
572
D. Common Ufililp Codes ESC(2)=CW{492
ccccccc~cccccccccceccccccecccccccccccccccceecccccccecccccccccccccccccccc C
10
mZTE(OUNI&IO) ESC(lf ,ESC(2) F O W T flX,2Al)
=TURN
eEaa
cccecccccceccccc~ceecccceccccccecccccccecccccccccccecccecccecce~cec~cccc SUBROUTINE TMQDE C s w i t c h e s t e r m i n a l from g r a p h i c s t a t e x t made C by w r i t i n g hardware dependent escape s e w e n c e s t o t h e t e r m i n a l
C This r o u t i n e c o n t a i n s t h e escape sequence f a r a Graphon t e r m i n a l C t o s w i t c h between TEK4014 and VT200 m d e s
ccccecccccccceccc~cf:ccecccccceeececccccecccccccccccecccccccccccccccccccc Global v a r i b l e s : INCLUDE * 10.ALL8 C Local v a r i a b l e s : CHmCTER*P ESC (2f ESC flf =CmR(27f
l a s c i i codes f o r <ESC> 2
~ s (z)=ewmfset c
ccccccccccccccccccececcccccccccccccccccceccccceccccccccccccccccccccccccc C
10
m I T E (oUHIT, 10) ESe ( l ),ESC f 2 ) F O m T (1X,2AT) =TURN END
cccc~~ccccccecccccccccccccccccceecccccccccccccccc~cccccccccc~c~cccc~cec cccccccccccccccecccecccceecccccccccccccccccceccceccceccccccccccccccccccc C io.aX3. C G enviranment dependent parameters INTEGER IUNIT ! u n i t n u a r f o r i n p u t from s c r e e n INTEGER OUMIT ! u n i t nu&@r Eos output t o s e r e e n INTEGER TUNI 'r ! u n i t nuniber f o r t e x t output t o f i l e INTEGER GUNIT ! u n i t nu&er Ear g r a & i c s output t o f i l e ! u n i t nu&er f a r d a t a i n p u t from f i l e INTEGER DUNIT INTEGER TRMLZN !nu&er of l i n e s an t e r m i n a l s c r e e n INTEGER T W I D !width of t e r m i n a l s c r e e n C t h e f o l l o w i n g a r e d e f a u l t answers t o i l o c h a i c e s C C I==yes 0 == no !send t e x t output t o t e r m i n a l ? XMEGER TXTTRM INTEGER TXTFIL !send t e x t output t o a f i l e ? !send g r a p h i c s t o t e r m i n a l ? INTEGER GRFTRM !send g r a p h i e s t o a h a r d copy d e v i c e ? INTEGER GRFHRD !send g r a p h i c s d a t a t o a f i l e ? INTEGER GRIFFIS, C C
i / o i n p u t parameters f o r t h i s sun LOGICAL TTERM ? w r i t e t e x t autput t o terminal? !write t e x t output t o a f i l e ? LOGICAL TFILE !name of t e x t f i l e !send graphics output to t e r m i n a l ? LOGICAL GTERM !send g r a p h i e s output t a hardcopy device? LOGICAL GHRDCP !send g r a p h i c s d a t a t o a f i l e ? LOGICAL GFTLE
!nam of graphics data f i l e
c COWON /IO/TUMST~GUNXT,XUMITIQUNIT~DUMITITRMt1CEJtT~ZDtTXTT~~ TXmXL, G W T W , GRFWRD, GWFXLL -b TTERM, TFf LE, GTERM, GFXLE ,GWRBCP COmON / CTQ / T N m , G N A M E 3
574
D. Comnaoa
Ilti221y Codes
D.3 General Input/Output Codes All of the utility routines that do not need editing are located in the file UTZTIL.FOR. They are as follows: menu
HE@U
rotrtirres
: executes the menu PRTACS : prints menu items and default; vdues PWMS : prints blaak lines FRYORE : prints a 9%' or "0" PARSE : controls menu branching by returning index of
: defines menu array variables that are the s a e
for d l programs ASK
next menu item fie FLOPEH : opens a new file manipdatim FuJpla2 : open8 m existing file FLGLQS : clams a user intedwes
: retnrns a floating point aaxmber GmIIQT: returns an irzteger YES80 : returns a l (yes) or O (no) CEXARAG : returns a chaxacter string
PAUSE : suspends execation until user presses Return key
c~rrversion routines
CO~BVBT: converts a real namber to a stdrrg IWWT : converts m integer to a string LQGCV"P : converts l to .TRUE. everything efse to FAME.
,
.
dscella~eous H ~ D :Eprints ~ the introductov text screen FXBISB ; clo~esopen files m$ stops the p r o g m am^^ : prints default d u e for red numbers in an W propriate format IMTBW : prints default d u e for intqefs in m apprwriate fomat LEgmU : returns the fength of a Gfiaracterstring exclnsive of trdfing blmks RAlNaS : returns a unifomly Gstribnted random between O aad l, CeccccccCcccccccccccccecceccccecccceccccccccccccccccccccccccccccccccccc~ G G C
C
f i l e UTIL,fox
COMPUTATIONAL PHYSICS (FORTRAN VERSION) by Steven E, Koonin and Dawn C. Meredith Capyright 1989, Addison-Mesley Publishing Csmpany
ccecc~ce~ccc~ccceeccccc~cccec~cccceccccccccccccceeccceeccccccccceccccccc
D.3 General 1nputButpu.li Codes
576
SUBROUTINE HEADER (DESGRP ,NNEAD, NTEXT, NGMPH] C d i s p l a y s h e a d e r a n d d e s c r i p t i o n of o u t p u t t o s c r e e n
CCccececcccccccCcceccccccC:cccceccC:eccceccccccecccceccccccccccccccccccccc C Eiabal variables: INCLUDE ' IQ. ALL1 C Input variables: CTER*(*) DESCRP(2Q) INmGER NWEAD,MTEXT,NGRIIPR C Local variables: INTEGER N INTEGER LENGTH 1NI"EGER NBLNKS C H M C T E R " 8 O BUNKS C Function: INTEGER LEMTRU DATA BLAMES / ' ' /
! d e s c r i p t i o n o f program and o u t p u t !nu&er o f l i n e s f o x e a c h d e s c r i p t i o n ! c u r r e n t l i n e rider ! t r u e l e n g t h of c h a r a c t e r s t r i n g s fnum o f b l a n k s needed t o e s n t e r s t r i n g ! a r r a y of b l a n k s f o r c e n t e r i n g ! t r u e length of c h a r a c t e r s t r i n g
~c~c~~c~~~~c~~~~c~~cccccceccc~ccccccccceccc~cccccccc~c~cc~~
190
e c
C C
140
CALL CLEAR ! v e r t i c a l l y center output DO 190 N = 1 , {TRMLIN-X~-NHEAD-MGRAPW-~JTEXT~~~ WRf TE (QUNIT, 20 1 CONTINUE w r i t e out constant p a r t o f header @RITE fQUNIT,40) WRITE (OUNIT, 50) m I T E (QUNIT, 601 WRITE (OUNIT, 80) WWITE (OUMIT, 20) WRITE (OUNIT, 20) w r i t e o u t c h a p t e r dependent s e c t i o n aE t h e h e a d e r DO 140 N=l,NWEAD+NTEXTfMGWW I F f N .EQ. N M W + Z ) THEN ! t e x t o u t p u t h e a d e r WRITE [OURIT, 110) END I F 6P (N .EQ. NMEAD+NTEXT+l) TEEN WRITE (QUNIT,11S) !graphics output header END I F LENGTWmLEMTRU (DESCRP (NI 1 !h o r i z o n t a l l y c e n t s r o u t p u t NBLNXS=(SO-LErJC;TW)12 WRITE (OUNIT, 1201 BLANKS (3:mLNKS) ,DESGRP (NI ( 1:LENGTH) CONTINUE
C
CALL PAUSEt8to b e g i n t h e p r o g r a n , . . f , l f CALL CLEAR C
20 40 50 60
80
FoMT (@' 1 F O m T {/,3OX,'COMPUTATIOWAL PHYSICSf) F O W T f/,32X,'fFORTMNVERSXON)#) F O M T (/,2OX,%y S t e v e n E. Xoonin and Dawn C. Mezedithe 1 F O m T (/,14X, + V o p y r i g h t 1989, BenjaminlCumings P u b l i s h i n g Company')
576
D. Common Uilz'ligy Codes 110 115 3.20
F O m T ( / , 3 0 X , 'Text o u t p u t d i s p l a y s E ) F Q m T ( / , 2 8 X , 'Graphics output d i s p l a y s 8 ) F O m T (&A)
C
=TURN END
cccccc~ccccCcccccccccceccccccccccccccecccccccccecccccccccccccecccccccccc SUBROUTINE MENU C s e t s up t h e p a r t o f the
menu t h a t
i s t h e same for a l l programs
cccccccceccccccccccceccecccccccccceccccceececcef:cccccecccccccecccecccccc G Global v a r i a b l e s : INCLUDE
M N U . ALL'
INCLUDE fIO.&LLr
cccccecccccccccccccccccccccecccccccccccccecceccct:ccccccccccccccccccccccc C
main menu MTVPE ( 5 1 =CLRTRM
C
MTYPE ( 2 1 =#TITLE W W I : (2f =%XPf MENU" H L ~ L X (2 M -2 HHILIM 62) -1
c MTVPE ( 3 ) =MTTTLE EdPWT(3)="1) Change p h y s i c a l parameterst MLQLIN 43 f ==a MWILIM ( 3 )90
c NTWE f 4 E =HTITLE W W T ( 4 1 =' 2) Change n u m r i c a l p a r a m t e r s e MLQLICM(4)=O XHLLIM ( I 1 -0
C MTYPE (5)PMTITLE MFmPT(S)=e3S) Ghanqe o u t p u t parameters" PILOLIM (51 =Q MWf LIM (5) =a C
NTWE C 6) -MTSTLE MPRMPT ( G ) 41 Display p h y s i c a l and numerical parametersf MLQLIM(6)-0. MHXLZN ( 6 1 -0,
C MSYPE ( 7 ) =MTITLE 13XZMPT (7)1-51 Display o u t p u t parametersf NLaLrM (71=Q. MHILIW (71=Q.
C MmPE (8) =MTITLE W W T (81x CB f Run programf MU)LIW I( 8 1 =O MMXLIM ( 8 1 -0
D.$ Generat I n p ~ t / Q ~ t p a Codes ;t W T S E ( S) PMTITLE m M T (9)=@ 71 Stop pragramp NLOLPEJI ( S 1 =B MWILIM ( 9) ==l MTVPE ( 10] =MCROZC M P W T (10) = W a k e a menu choicer MTAG ( 2 Of m' l1 36 61 91 94 99 99" MLQLIEJI (l0f =I. MHILIN (lO f -7 MINTS (10) -6 NWLSff0)=-6 physical parameters M T E E ( 111 =CLRTRM
MTVPE (12)=TITLE MPmPT (12)= "PYSICAX, IFAMmTERS' MLOLIM (121 =2. MWILIM (12)=l.
n u m r f eal parameters MTVPE f 36 1 =CLRTRM
-
NTYPE ( 37 1 -TITLE W W T 137) 'NUMERICAL P MLOLIM ( 3 7 ) 4 2 . MWILXN (37)-1.
output, menu MTYPE ( 61) =CLRTBM
MTYPE ( 62)-P?ITLTLE N P W T (62)= 'OUTPUT MENUt MLOLIN (62) 10, MHILIN 162)=l. MTVPE ( 63f -%TITLE N P M T ( 6 3 ) 21 Change text output parameters" ML0LIM ( 6 3 )-0. MWILIM f 6 3 ) 10. MTWE (C4 ) =MTITLE WRMPT (641-'22) Change graphics output parametersf MLOLfM(641 =Q. MMZLIN (64)PO.
577
578
D. Common Viila'by Codes MTYPE (65) =MTITLE MPWT(55)=@33) Return to main menu" MLQLTM (65)P O . MHILIM ( 65)-1, MTVPE ( S6I =MCHOSC M P W T f64)= 'Wake menu choice and press Returnp MTAG ( 6 6 )=' 772 81 01' MLOLIM t 6 6 )=I MHZZXM (661 =3. MINTS (55)=3. text output paramters M T W E (73, ) =CLRTRM
MTMZE ( 7 2 ) =TITLE PIUPNP 11 ( "12) a;- TEXT OUTPUT P&MmTERS " MLOLIM (72) 4 2 . MHILTM (721 11, M T W E ( "13) =BBQLEM W W T (73) = .Do you want text output displayed on screen?' H T A G ( 7 3 ) = 'Text output to screent WTNTS (73 f =TXTTRM MTYPE ( 74 f =NOSKIP MPMPT(74)- Do you want text aueput sent to a file?' MTAG (74) Text output to filef @
MTNTS (74) =TXTFIL MTWE (75 1 =CWSTR M P W T ( 7 5 1 @Enter name of file for text output6 MTAG(7S)m 'File n m e for text output' NLOLZM 1751 =l. NWXLIM (751=12. MXNTS (751 =l MSTRNG (MTNTS(75)) 1 ' cmhys. txtp
graphics output parameters MTYgE f 8 h f =CLRTRN
-
MTYeE (82) =TITLE W W T (82) * GRB,P&WICS OUTPUT P MLQLTM (821 -2. M81LIN (82)-1. MTVPE (83) =BOOLEN
D3 General lapzl.l//Output Codes
679
E m P T ( 8 3 ) = 'Do you want graphics sent to the terminal?" MTAG (83)= Graphics output to terminal' MIWTS (83) =CRFTRM
c MTYPE 4 84) =BOQLEN you want graphics sent to the hardcopy device?'
WRMPT(84)-
MTAG181)= "raphics MINTS (8 4 ) =GREWRD
output to hardcopy devicer
G
%TYPE f 85 1-NOSKTP N P W T ( 8 5 ) = W o you want data for graphing sent to a file?" HTAG (85)= Wata for graphfng sent. ta filep
LS 185) ~ 8 7 .
MINTS f 85)-GWFIL C
M T S E ( 8 6 ) =@WSTR W W P T (86)= @Enter name of file for graphics dataC MTAG ( @ G ) = Vile for grapbics dataf MLOLTM ( 8 6 ) ==2, MBILIN ( 8 6 ) =l2 I
NIMTS 486)-2. MSTRNGfNINTSf86))- 'cmphys-grf' C
NTUPE (90) =SKIP M M L S (901~ 6 1 ,
C C
printing numerical and physical paramtars MTYPE ( 91)=PPRINT MLOLXM(91)=12. MHTLIW f 91f =GO.
C
c C
MTPE ( 92) =SRIP W A L S (!321=1.
printing output parameters NTYPE ( 94) =PPRINT MLOLTM ( 94 ) =?l. NWILIM ( 9 4 ) -90.
C
NTYPE ( 95)=SKIP MRmLS 4 95 ) -1. C
RETURN
END
ccc~cc~ceccc~~ccccccccccccecccccccce~ccccccecccccccccceccccce~cc~ccccc~c SUBROUTINE ASK(STmT,END) C executes menu items from START to END; C see Appndix A for a description of the menu
cmcccccccccccceccccccccccecccccccccceccceccccccccccccccccc C Global variables: fNCLUBE "MENU. ALLf INCLUDE 'IQ.ALL1
C Xnput v a r i a b l e s :
INTEGER ST&RT,END C Local v a r i a b l e s : INTEGER 1 INTEGER ILC?W, IWIGW INTEGER MVMSKP INTEGER ZCBOXC
t s t a r t i n g l e n d i n g menu i t e m s t o e x e c u t e ! c u r r e n t menu i t e m ! i n t e g e r l i m i t s f o r NlfH t y p e !nu&er a f b l a n k l i n e s t o p r i n t t c u r r e n t menu c h o i c e
C Funclions C H m C T E R * l O GWAmC GETFLT IMT&GER GETINT INTEGER PARSE IHTEGER YESNO
RE&
!character input treai input ! i n t e g e r input I d e t e r m i n e s menu b r a n c h i n g !boolean i n p u t
eeccecccc~ce~cecccccce~ccecccccccccccccccccccccccccccccccccecccC:ccccc~cc lOBO
f=STrn"1: CQHTINUE I F (MTYPE(1) ,EQ. FLOAT) THEN sat = i T F L T ( m A L S ( 1 ) ,MLOLIM(l) ,MWILIM{I] ,WRMPT { I k 1
c
ELSE IF [ MTYPE(I) .m. Nun) ILCIW = NLOLIM(I1 I B f GW = MHILXM ( I ) MINTS (I) 1 GETINT (MINTS {I), XLOW, IHZGH, W R W T (11 )
C ELSE I F (MTVPE ( I ) .EQI 800LE1) THEN VESMO (MINTS ( I ) , W W T ( I ) f MINTS (f ) G
I.
ELSE SF (MTYPE (I) .Ea. CNSTR) T B N NSTRNG (MINTS ( I 1 ) = e m m c ( ~ s r ~ ~ G [ M(11 r ~IT,XNT s ~MHXLIM(X~
c
1
-
ELSE I F ( MTYPE (I) .EQ. MCWQIC) THEM ILOR MLQLIM [X) ZNIGW MHZLTM ( I 1 IcWoxc = CETSNT (MINTS I S ) , ILQN, IWIGB, WFIMPT (S)I if i s > 0, s a v e ICHOXC and change d e f a u l t I F ( W A L S 13) MZNTS (S) =ICHOIC
i f m A L S Ss < 0, s a v e ICMOIC but l e a v e d e f a u l t t h e sam ELSE I F ( M m L S ( I 1 .LT. 0) THEM m E A L S (I)=-REAL f IGWOIC) EMD I F I PaRse (NTAG (I , IcWaIcf 5
C
-
-1
(HTYPE(1) .EQ. TIT= .OR. MTYBE ( 1 ) *EQI MTXTM] MWLIM ( I 1 GALL PRBLKS (NUMSRP 1 mXT& (OUNIT, 1 0 ) WRMPT(Z) MHILIMgI) MUMSKP CALL PRBLKS (PSUMSKP 1
ELSE If
NUNSKB
-
THEN
L;),3 General I.aflzk#/Ou~pzrdCodes
ELSE XF (MTIIPE ( I ) .Ea. YESKIP) TWEN MSNTS (I) = YESNQ (MINTS ( I 1 , E(IPNPT (I)1 IF (MINTStI) .NE. 0) THEN I MREALS(I1 3 END I F
-
ELSE I F (MTVPE ( X ) .EQI NQSRIP) THEN MINTS (X) = YESNO fMZNTS (If , mRMPT ( I 1 IF (MINTS(T) .EQ. 0) THEN X = m&s(xj 1 END I F
-
ELSE I F (MTVPE ( 1 ) .EQ. SRTF) THEN Z = MREALS ( X )
-
1
ELSE IF (MTHPE ( I ) .EQ. RAlT) THEN WRITE (QUMIT, 10) MPRWT (S) GALL PAUSE(@to continuet,l) ELSE IF [MTPPE (I1 CALL GLEm
.EQ, CLRTRM)
TWEN
ELSE I F (MTYPE(T1 .EQ. QUIT) THEN I=END ELSE I F (MTYPE ( I ) .EQ, PPRXNT) THEN ILOW = MLDLTM ( I ) IWXGR 1 NWILIM [I) CALL C L E m CALL ORTAGS (ILOW, IBIGN] CALL O A U S E f f t o osss t h e Main Menutl.%3) CALL CLEAR END I F
display info about defaults IF fI .EQ* 1) THEN WRITE (OUNST,*) * WRITE (OUNIT,100) WRITE (QUNXT,lOI)
'
END X?!
F O m T ( 1X, A 1 F Q m T ( %X, A, 1PE11.3 1 F O W T ( I X , A, I 6 ) FOmT ( " 0 accept the d e f a u l t value [in brackets3 for a n y itemc) FQ-T ( * just press Return a t the p r o m p t ' ) RETURN
581
582
D. Common Ufa'lifyCodes END
ceccccccccecccccccccccccccccccet:cecccecccccccccccccccccccccccccccccccccc s v B R o v r r N E PBTAGS(START,END)
c prints menu prompts and default values for items S T m T to END
cc~cCcecccc~ceeccccceccccccecccccccccecc~ceccccccccccccccceccceccccccc~c C Global variables: INCLUDE MMGNU, ALL" INCLUDE 'IQ.ALL;
C Input variables:
!limiting Indices of printed menu items
INTEGER START, EMD C Local variables: INTEGER I INTEGER PfUMSKP INTEGER INDEX INTEGER PLEN INTEGER ICHOIC
!menu items index !nu&er of lines to skip !subindex for menu items !length of prompt Imenulparameter choice
Functions: ftrus length of character string !menu choice
INTEGER LENTRU INTEGER PARSE
cccccccccccccccccceecc~cccccccccccccccecccccec~ccccecccccccc~ccc~ccccccc 1000
I=S"IE"RT CONTINUE I F (MTVPE (S) .EQ. FLOAT) TNEN WRITE (OUNIT, 3.11 MT&G ( X ) , NmALS (I)
C
ELSE I F (MTUPE (I} .EQ. NUM) THEN WRLTE (OUNIT, 221 MTAG ( I ) , NINTS ( X )
G ELSE I F fMTYPE (1f
.EQ, BOQLEN) TNEN
CALL DRYORN (MTAG (IJ , MINTS ( I 1 )
C ELSE I F (MTYPE (I) .EQ, CHSTR) THEN WRITE ( OUNIT, 1 3 ) MTAG ( I ) , MSTRNG (MINTS (X) ) C
ELSE I F (MSYPE ( I ) .E&. TITLE) THEN NUMSRP = N m L I M (I1 CALL PRBLKS (MIINSKP) WRITE (OUNST, 3.01 MPRMPT(T1 NUMSKP = MHILIN ( I ) cam PRBLKS (NUMSKP1 C
ELSE I F (MTVPE ( I ) .EQ. YESKIP) THEN C&LL PRYORN (EITAG (X 1 , NINTS ( I ) ) T F (MIMTS(1) .NE, O .AND. MREALS(I1 .GT. I = MREALS(I) 1 END I F
-
I ) THEN
C
ELSE I F (MTYPEtI) .E&. NOSXIP) TEEN CALL PRUQRH (MTBG (X 1 , MINTS (I)1 I F (MLNTS (I) .EQ. O .AND, MREALS(I1 .GT. X = MREmS(EJ 1
-
END SF
I) THEN
D.3 G"encraZ I R ~ ' I L I / " "Codes Q ~ E ~ ~583 L ELSE SF (MTYPE (X) .Ea. SKIP) THEM IF (NREALS ( S ) .GT. I ) XmMMALS f L )
-1
f d o n r t s k i p backwards
ELSE I F (MTYPE(L) .EQ. NCWOIC) TWEN IF ( N m A L S ( I ) .GT. Oj TWEN f o r menu c h o i c e s t h a t a r e p a r a m e t e r choices, p r i n t o u t c h o i c e , but f i r s t y o u m a s t f i n d i t DO 20 INDEX=Z-MNTLIM(I),I-1 XF ( (I+MREALS ( I ) - M W I t I M (I1 -1) .Ea. INDEX) THEN PLEN-LEWTRU (NPRWT [INDEX) f WRITE (OUNXT,1 0 ) NPRMPT (INDEX)(4:PLENf END XF COMTINUE END 11" I F (MmALS(1) .m. O) THEN !branch t a chosen p a r m e t e r scwosc=~ss(INT (HmaLs( W X e a R s e ~MTAE( X ,IGROICI -1 END I F
c EWD IF I = 14-1 I F (L .LE. END) GO TO 1 0 0 0 C 10 11
12 13
FOmF( FO-T ( FQmT( FOmT( RETURN END
lX,A) 1X, A, SX, A, XX, A,
lPE11.3 ) X6 1 5 X , Af
ccccccccecccccccccccceccc~ccccccccceccecccccccccccccccc~c~ccccccccccc~cc SUBROUTLNE PRYORM (PMPT, YORN 1 C p r i n t a ' y e s 1 aar %no"
ccecccccccccccccccccecccccccccccccccccccccccccccccccccccccc~ccccccc~cccc G Global variables: INCLUDE 'IO.ALLt C Xnput variables: INTEGER YORN CHmCTER* f *) PNPT
'YES",
* a @mm @NO"
!string t o p r i n t b e f o r e y l n
C Functions: INTEGER LENTRU
!actual length o f p r o m p t
ccecccccccccccccccccccccccccccc"cccccccceecccccccecccececcccccccccccccccc
10
11
I F (YORN .EQ, O) TWEN mXTE (OUNIT, 10) PNPT (1:mNTRU {PMPT) f ELSE WRPTE(OUHIT, 11) PMPT(l:LEMTRU(PmT)) END I F F Q W T 4 IX, A, : not) F O ~ T IX, ( a, : y e s t ) M1URM END
584
D,Common Ufzlity Codes cceccc~ccccccccccccccccceeeccccccceccceccccccccccccccccccccecccceccccccc SUBROUTINE PRBLKS (NUMLIN) C p r i n t s NUMLIN b l a n k l i n e s on t e r m i n a l
ceccecccccccecccccccccecccccecccccccccccccccccccccccccccccccccccc~ccc~cc C Glabal variables:
TMCLUDE 'IIO,ALLf C Passed variables:
JNTEWR NUNLIN
!nu&ar
of b l a n k l i n e s t o p r i n t
C Local variables:
!d u m i n d e x
INTEGER I
ccccccccccceccce~ccceccccccceecceececccccccceccccccccce~cccccccceccccccc aooo
DO 1000 I=l,NUEEILXM WRITE( OUNIT,*) CONTINUE RETURN
' *
END
cccccceccccccccceecccccccccccccccccccccccccccccccccccccccccc~ccccccccccc SUBROUTINE PAUSE (PHRASE, MSKXP ) C g i v e s user t i m t o r e a d s c r e e n by w a i t i n g f o r d u m y I n p u t ; C a l l o w s E a r p r i n t i n g o f PWmSE t o s c r e e n ;
C s k i p s NSKTP l i n e s b e f o r e p r i n t i n g PWmSE
cceccccccccccCccccccc~cccccccccccccccccecccccccceccccccccccccccccccccccc C Global variables: INaUDB XXQ.ALL"
'
C Passed variables: CHWCTER* f * f PHWE INmGER NSKTP C Local variables:
!phrase t o be p r i n t e d Inumber o f l i n e s t o s k i p
C W m C T E R * 1 DUMMY INTEGER XSRIP
!d u m y v a r i a b l e !MSKIP i n d e x
cccceccccccccecccccccccecccccccccceccceceeeccccccccceccccccccccceecccccc 10
5
15 20
DO 10 ISKIP-1, NSKXP
I s k i p 1Snes
WRITE (OVMfT,S) CONTZMIIE F O m T ("1 RR3TE IOUNIT, SS) BWMSE W A D fIUNIT, 20) DUHMU F O m T ("ress r e t u r n p ,A) F O m T (Al) mTURN
!write p h r a s e !wait f o r d u m y i n p u t
END
cecccccceeccccceeccccccccccccccccccccccccccccccccccccccecccccccccccccccc SUBROUTTHE FLOPEN (PHAME,PUNIT) C o p e n s a new f i l e , u n l e s s o n e by t h e same name a l r e a d y e x i s t s
ccccccccccccccccecccccceceecceccececcccccccccccccceccccecccccccccccccccc C Global variables:
INCLUDE pXIO.ALL' C Input variables: CTER* (*1 FNAm
TWTBGER FVNIT C Local variables: LOGICAL OPN
!f i l e name !unit: nu&er
!is t h e f i l e open?
ll.9 General Jiaput/Oufpzt.t Codes LOGICAL EXST CWWCTER*40 C M A M C INTEGER LENTRU
585
Idoes it e x i s t ? !function t h a t return character input
~c~~c~~~cec~~ccccc~ecceccccc~ceccccC:cc~eecc~ecc~cccccccccccccccccc 10
TNQUSm (FILE=FWAMEiEXIST=EXST, OPENED=OPH)
C
I F (QPN) RETURN C
20
I F (EXST) THEN m 6 T E (OVNIT, 243f FNmE (1:mNTRU (FNAME1 1 F O W T f "tputr f i l e ,A, Q l r e a d y e x i st S ' 1 FRA==CHARAC(FNAME,22, ' E n t e r a n a t h e r f i l e n a m e ' } ELSE
oPEN(VNIT=FVNIT,FILE=FNW~STATUS=~NEW'~ =TURN END I F GOTO 10
EWE)
~~~~~ccc~cccccc~cccC:cccccccccccccccccceccccc~eccc~ccccccccccccccccc~cccc SUBROUTINE FLOPN2(FH&m,FUMIT,SUCE55) C opens an e x i s t i n g f i l e f o r input d a t a
ccCccccecccceccccccccccccccc~cccecc~ccecccccccccccc~cccccccccccccccccccc C Global variables: TNCLUDE ' TO. ALL" C Input variables: CHMCTER* f * ) FP3Am INTEGER FUNIT LOGICAL SUCESS C Local v a r i a b l e s : LOGSCU OPEJ LOGICAL EXST
!f i l e R a m f u n i t nu&er ! d i d w e f i n d an e x i s t i n g f i l e t o open?
!is t h e file open? ! d o e s it e x i s t ? !function t h a t return character i n p t ? choice f a r continuing
INTEGER CHOICE C Functions: ! g e t y e s o r no i n p u t INTEGER YESNO INmGER LENTRU GCCCCCCCCCCCCCCCCCCCGCCCCCCCCGCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCC 10 INQUIRE (FILEmPNAME, EXIST=EXST, OPENED=OPH 1 C
20
I F ((*NOT. EXST) .OR, (OPN)) THEN WRlTE (OUNIT, 201 FNAm C1 :mNTRU (FNAEJIW PORmT ("nput, f i l e * ,A, ' does n o t exf st a r i s alreadTy o p e n r } CWOICE=YESNOI1,p Mould you l i k e t a t r y a n o t h e r f i l e n a r n ? ? )
C SF (CHOICE .EQ. 0) THEN SUCESS=-FALSE, RETURN ! l e a v e w i t h o u t opening f i l e f o r r e a d i n g
ELSE FNAME~CWAMC(FNM~l2,"nter another filename6) END I F ELSE OPEN (UNIT=FUNIT,FILEmFNAm, STATUS=' OLDf f
586
D. Common Ufility Codes SUCESS=.TRUE. RETURN END IF GOTO 10 END
ccccccCcccccCCccccccccccccccccccccccccccccccccCCcccccccccccccccccccccccc SUBROUTINE FLCLOS(FNAME,FUNIT) C checks on f i l e s t a t u s of f i l e , and c l o s e s i f open
cccececccccccccc~cececccccccc~cccecccccccccceccccccccccccccccccccccecc~c G Global v a r i a b l e s :
INCLUDE ' IO,ALLE C Input v a r i a b l e s : CHMCTER*(*f FMINS"EGER FUUIT c Local v a r i a b l e s ; LOGX~ALOPN
!file name ! u n i t nunjoer ! i s t h e f i l e open
ccceceeccccc~ccccecccccccccccccccecccccccc~cceccceccccce~cccccccccccc~cc INQUIm (Ffm=FNAME,OPENED=OPEd) SF (OPN) CLOSE (UWTT=FUNIT) RETURN
END
ccccccc~cccccceccccccccccccecccecccececccccccccccccccceccccccccccccccccc SUBROUTINE FINISH C c l o s e s f i l e s and s t o p s e x e c u t i o n
cecccccccecccccecccccccc~ccccceccccccccccceccccccccccccccccccccccccccccc C Global v a r i a b l e s : INCLUDE ' IQ.ALLe
ccccceecccccccccccccccccccecccccccccccceccccccccccccccccccceccccccccccce CALL FLCLOS {TNANE,TUNIT) CALL FLCLOS (GNANE,GUNIT) STOP END
ccccceeceeccccccccccccccccceceeeccccccccccccccccceeccceccccccccccccccccc SUBROUTINE PLTBEF (XPRME"T, X ) C p r i n t s prompt f o r f l o a t i n g number C and d i s p l a y s d e f a u l t X in a format d i c t a t e d by s i z e o f X
cc~ccccc~cc~cccceccec~cccccccccccccccccceccccccccceccceccccccccccecccccc C Global v a r i a b l e s :
TMGLUDE 'IQ.ALL'
C Input v a r i a b l e s :
CHmCTER* ( * 1 XPRWT
m=
X
!prompt s t r i n g !d e f a u l t v a l u e
C Function:
XNmGER LEMTRU !true length a f s t r i n g cccccccceeeecccccccccccC:eccccceccececccccccccccccceccecccccccccccccccccc C p o s i t i v e numbers ( l e a v e no roam f o r a s i g n ) IF [ X .GT. 0) THEN IF ( ( m S ( X ) .LT. 999.49) .AND. (ABS(X) .GE. 99.949)) THEM WRITE (OUNIT,S 1 XPRMPT (1:LENTRU (XPRME"T)),X ELSE IF ((ABS(X) .LT, 99,949) .AND. (ABS(X) .GE. 9.9949)) THEN m T T E (OUMXT, 3.0) X P W T (I:DNTRU (XPWPT)1 , X ELSE IF ((ABS(X) .LT, 9,9949) .AND. (ABS(X) .GE, .99949)f THEN
LT.3 General I~pu.t/Qut;rtufCodes WRITE (OUNIT, 1 5 ) XPRMPT (1:fiEN"rRlf (XPRWTI 1 , X ELSE I F ( ( A B S ( X ) .LT. -99949) .AND. (ABStX) .GE- -099949) f T m N WRITE (OUNXT,20) XPRMPTIl:mNTRU(XPRNPTf ) , X ELSE m X T E (OUNIT, 25) XPRNPT (1: UNTRU (XPRWT') 1 ,X END I F
e C
n e g a t i v e numbers ( l e a v e roam f a r t h e s i g n 1 ELSE I F ( ( A B S ( X ) .LT. 999.49) .AND, IABS(X1 .GE. 99.949)) TWEN m I T E (OUNX21,105] XPRNPT (1:LENTRU (XPRWTI 1 ,X ELSE ZF 4 (IIBS(X) .LT. 99.949) .AND, ( m S ( X ) .GE. 9,9949)) THEM m I T E (OUfdIT,1 2 0 ) XPRNEIT ( 1 :LENTRU (XPRmT) 1 , X ELSE I F ((ABS (X) .LT. 9,9949) .AMD. (ABS(X) .GE. ,39949)) THEN m I T E (OUNI'17,115) XPRWT(P:LENTRU(XPRNPT)),X ELSE I F [ (=$(X) .LT, .99949) .AHD. (X) .GE. .099949) ) TBEN WRITE (OUNZT,12Q) XPRMPT (1:LENTRU (XPRMPTI 1 #X ELSE WRITE (OUNfT, 1 2 5 ) XPRMPT (1; U N T R U ( X P W T f ) r X END 3 F END I F
e 5 10 15 20
25 105 110
115 120 125
FO~T(1X,A,1X,'[',F~.OY'l') ( I X , A , 1 X y 8 ["F1.1,'2"f
FOmT EOmT FOmT FQmT
( l X , A , l X , ' f t , F 4 , 2 , ' l") {IX,A,1X,f[C,F4=3,~fj
(IX,AIIX,'[',1PE8,2,'1')
F O W T (1X,A,1XpP ['t,PS*O,'I 'I F Q W T (1X,A,1X, F O W T ( l X , A , XX, F Q m T ( I X , A , PX, F O m T (1X,A, l X ,
f ' , F 5 . l , * 1") q *,F5,2, ' 1 'l "I" ,F5.3, 1 J')
' l',1PE9.2, ' 1 ' j
c RETURN
END
cccceccccccccccccccecc"eccccecccccccccccceccccccccccccccccccccccccccccccc SWROUTXUE INTBEF (RPWPT, K ) C p r i n t s prarnpt for i n t e g e r i n p u t from s c r e e n C and d e f a u l t v a l u e i n a p p r o p r i a t e f o r m t
cc~ccecccccccecccccccccecccceeecececcccccccccecceccccceeceeccccecccccccc G Global variables:
INCLUDE
' 10,ALLt
C Input variables:
CTER * f * f K P W T SRTEGER K C Function: I N m G E R LENTRU
!prompt s t r i n g !default values
!true l e n g t h a f s t r i n g
cec~cccccceccecccccccccccececccccecceccccccccccccccccccccccceccccccccccc G
p o s i t i v e numbers (leave no room f a r a s i g n ) I F {K .GB. 0 f TWEN I F ( ( I A B S ( X ) .LE. 9999) .AND. (IABStRf ,GE. 1 0 0 0 ) ) THEN WRITE (OUNXT, 1Q1 KPRNPT (1:LEN"I"RU (KPRlrlPT) f ,K
587
688
D,Gmnzon
Ufo'lity Codes
ELSE I F (($mS(K).LE. 999) .&MD. (TABS(K1 .GE. l Q 0 f f TWEM WRITE (OUNIT, 20) K P m T ( 1 :6;EMTRU ( K P R W T W ELSE I F ( f I m S ( K ) .LE. 951) .AND. (IABSfEO .GE. 1 0 ) ) TWEN W I T E (OUNIT, 3 0 ) K P W T f l :WEJTRU (XPRMPT) ,K ELSE I F ( f I M S ( K ) .LE. 9) .AND. (IABS(X) .GE. 0)1 TWEN m X T E (OWNIT,$Q) KFWPT(1:mXJTRU(KPMPT)I,K ELSE WRITE (QUNIT, 505 K B m T (1:LENTRU (KPRMPTI 1 ,K END I F
.
e C
n e g a t i v e numbers ( l e a v e room f o r t h e s f g n f ELSE ( IIABS( K ) .m, 9999) .RHD. (IABS~K) .GE. l e o o l I THEN WRITE (OUHIT, 1 3 0 ) X P M T (1:LENTRU ( R P W T ) 1 ,I(: ELSE I F ( ( I A B S ( X ) .Le. 999) .AMD. (IABSlK) .GE. 3.00)) THEW ~ I T E(swwrT, 1 2 0 ) KPWT (I:LENTRU (XPRWT) I .R ELSE IF ( ( I A B s t a ) .LE. 99) .mn. (IABS(X) .m. 10)) THEN &RITE (OUNIT, 1 3 0 ) K P W T Il:LENTRU(mRMPT) 1 , K ELSE I F ( ( I A B S ( K J .LE, 91 .AND. (IABS(K) .GE. 1)) TWEN RRXTE (OUNXT, 1 1 0 ) K P R m T f1:LENTRU (ICPRWT))rR ELSE WRITE (OUMZT, 350) KPRWT (1:LEWTRU ( K P W T ) )rK END I F END I F
IF
e 10
PO-T
20
F O m T (ZX,A, l X ,
30 40
F F F F
$0 I10 120 130 140
250
O O O O
(lXtZL,lX,' m m m m
T T T T
F O m T
FOmT FOmT FOMT
[*,14,@JF1
*
[#,
' 1' 1
(1X,A,1X,"[',12,*]t~ (1X,A, l& ' ,'E X%, * ] ' k (1X,A, I X , ' f f ,XlO, * ] ") ( I X r A t JX, ' [\,IS, 'J ') fSX,A,lXIf t f , 1 4 , q 1 ' ) (lXeA,lX, l', $ 3 t f 1 1 (lX,A,lX,~f",12,C]') flX,A, 1X, I',,IQ, ' 1 f') @
C
RETURN END
cccccccccccCceccceccceccccccccccccecccececccccccccccccccccccccccccccccc~ SaRQUTXNE COHVRT ( X , STRING, LEN) C c o n v e r t s a real nu&er x t o a c h a r a c t e r v a r i a b l e s t r i n g o f length ZEN C f o r p r i n t i n g ; the format i s chosen a c c o r d i n g t a t h e value o f X,
G t a k i n g raundoff i n t o account
ccccc~cc~cccccceccc~ccecccccccceccecccccccce~ccccccecccccccce~ccceccccec C Passad v a r i a b l e s : RmL X XlOTEGER LEN
!routine output !routine input !string length
C Function
INTEGER LENTRU
!gets string length
cccccccecccccccccccccccccccccccccecccE:cceceecceccecccccccceccccccccccecc C
p o s i t i v e nurnbers ( l e a v e na room for a s i g n )
XP [X .GT,
0) THEN IF ( ( m 5 f X ) .LT. 999.4) .AND. (ABS(X) .GE. WRITE (STRING,5 ) X ELSE IF ((ABS(X) .LT. 99-94} .AND. (ABS(X) m I T E [STRING,10) X ELSE IF ((ABS1X) .LT. 9,994) .MD. (mS(X) WRITE (STRING,15) X ELSE SF ( ( M S f X ) .LT. ,9994) .AND. ( m S ( X ) a X T E (STRLE16,20f X ELSE HRTTE (SmIHG,25) X END SF
99.941) THEN .GB. 9.994)) TWEN .GE.
.9994)f THEN
.GE. ,09994)) THEN
C G
negatfve nu&ers (leave room for the s i * ) ELSE IF ((mS(X) .LT. 999.4) .&tlJD. (ABS(X) .GE. m I T E (STRIIJG,105f X ELSE IF ((mS(X) .LT, 99.94) .AND. ( m S ( X 1 WRITE(STRIIJG,IlO) X E m E fF ((ABS(X) .LT, 9.994) .AND, (ABSfX) WRITE (STRING,1151 X ELSE IF ( ( m S ( X ) .LT. .g9941 .AND, (mS(X) WRITE f STRSNG,120) X ELSE WRITE [STRING,125) X END fF END IF
99.94)) TWEN .GE, 9.994)) THEM .GB. .9994)f TWEN .€SE.
.09994)) THEM
c UZII=mNTRU (STRING1
c 5
10 15 20 25 105 110 13.5 120 125
FOmT(F4,0) F O m T (F4.1) Fa-T (F4.2) F O m T (F4.3) F Q m T flPEB.2) P O M T (F5.0) F O m T (F5.1) Fa-T fF5.21 F O m T (F5.3) F o m 2 (IPE9.2)
C
BETURN END cccccccccccccccccccccccceccceccccccceccceccccC:ccc~cccccccccccccccccccccc SUBROUTINE IGMVRT (1,STRING,LEN) C converts an intager I to a character variable STRING for C printing; the format i s chosen according ta the value af I CCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCC1CCCCCCCGGCCCCGCCCCCCGCCCCCCCCCCCCCCCCCC
C P ~ S S Qvariables: ~
INTEGER X INTEGER LEN
!routine output !routine input !length of string
590
D,Common Ultz"lit?;rCodes cccce~cccecccccceccccccceccccccceccccecccccccccccccccc~~cccccccccccccccc C
positive n u k e r s (leave no room for a sign) I F (S .GE. 0) THEN I F ( ( A B S f I ) .LE. 9) .AND, (ABS(I) .GE. O f ) TmH WRITE (STRING, 51 I ELSE TF ( [ A B S ( I f .LE. 99) .ABED. W I T E (STRING,3.0) I
(ABS(1) .G&
1 0 ) 1 TWEN
mN-2 EzlsE XF ( ( A B S ( I ) .LE, 989) .AND. HRT"X" {STRING,SS) I
(ASSfS)
.GE. 100)) TWEN
mN-3 ELSE I F ( ( m S ( I ) .LE. 9999) .AND. m I T E (STRING,20f S LEH-.4 ELSE WRZTE (STRING, 25 ) REAL ( I )
( A B S t I ) .GE. l o o 0 1 1 THEN
LEN=8 EBB I F (I:
G
negative numbers (leave room far the s i g n ) ELSE I F ((ABSlIf .LE1 91 .AND. (ABStT) .GE, 1)) THEW m I T E (SmINC;, 1 0 5 f I ' LEN-.2 ELSE SF ( ( A B S ( I ) .LE. 99) .AND, (ABS(I) .GE, 10)1 TNEN WRS"SE(STRING,llOf X
LEW-3 E U E 3 F ((ELBStI) .LE. WRITE (STRING, 115) LE8m.g ELSE IF ( ( M S ( I ) .LE* WRITE (STRING, 220)
999) ..&MD.
9999) .AND, I
LEM=5 ELSE: WRITE f STRSMG, 125) REAL ( I ) LENm9 EHD IF END I F
C 5 10 15 2Q
25 105
IlQ
E"OmT(TI)
FOW"rI2) FQRKATff3) F O m T I141 F O m T (IPE8.2) F O m T (12) F O m T 413)
115
FO-T
120 125
FO-T F 8 m T
c RETURN
(14) (I51 (1PE9.2)
(ABSfI) .GE. 100)f THEM
I (ABS4T) .GE,
1OOOf) THEN
Ern
cccccccccccccccccccccccccccccccccccceccccccccccccccccccccccccc~ccccccc3cc INTEGER FUMCTXOM PARSE(STRING,CNOICE) C d e t e r m i n e s b r a n c h i n g f n =nu
list
C C b r e a k s STRING (of t h e f a r m "n n n n n n n nn n n 1 i f n o pieces, and C r e t u r n s t h e i n t e g e r v a l u e represented b y t h e CHQICE group of d i g i t s
...,'
ccecccccecccccccccccccC:ecccccccceccccccccccc~ccccccccceccccccccccccccecc C I n p t variables: C N m C T E R * ( * ) STRING INTEGER CNOXCE C Local variables: INTEGER I P O S INTEGER IGROUP
! s t r i n g t o l o o k at !specific nu-r to look at !currant character p o s i t i o n i n string ! c u r r e n t group o f d i g i t s i n s t r i n g
ccccccccccccccececcc~ccccceccccccccccecccc~ccccccceccccccccccccccccccccc 40
20 10
-
JPOS-l Do 20 IGROUF 1,CHQICE-1 I F t STRING (1POS:IPOS) .NE. IPOS = I P 0 5 + 1 G6TO 40 END IF IPOS-IPOS+1 CONTINUE RE^ STRING (IPOS: 1 e o s + 2 1 , 1 0 ) E'OmT(I2) mTmN END
"HEN
PARSE
cccccccccccc~ccccccec~cccccccccccccccccccccccccccccccccccecccccccccccccc INTEGER FUNCTION LENTRU (CHAmC) C f i n d s the t r u e l e n g t h o f a c h a r a c t e r s t r i n g b y s e a r c h i n g C b a c k w a r d for f i r s t n o n b l a n k c h a r a c t e r
cccccccccccccecccceececccccccccceccccccccccccccccccccccccccccccccccccccccc G Input variables:
CHWCTER *(*l C B W C C Local variables: INTEGER ISPIICE INTEGER f
! s t r i n g whose l e n g t h we are f i n d i n g laseii value of a blank !index of e l e m e n t s i n CWAMC
cceccccccccCccccceeccccccecccccccccccccccecceccccccccccccccccccccccccc~c 10
JSPACE=SCmR ( l ' ) I = a N ( C H N C) I F (ICHAR (CfYIRAC 6 I : I ) 1 .EQ. ISPACE) THEN I=I-l ELSE mNTRU=I =TURN END I F I F ( I ,GT, 0) GOTO 10 LENTRV-O
RETURN EMD
CGCCCCCCCCCCCCCCCCCCGCCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCCC REAL FUNCTION GETFLT ( X , XMIlif, X M , XPRWT)
592
D. Gommonb Utzlify Codes C g e t a f l o a t i n g p o i n t nu&er
X
C and C
GETFLT; make s u r e it Is between XNXN
m and prompt w i t h X P M T
C I f y o u r e a w i l a r a c c e p t s (FMTm*) t o an L n t e r n a l u n i t ,
c o m e n t out
C l i n e s 3 a n d 5 , and u n c o m e n t l i n e s 2 and 4
c~ccccccccccCcCccccccccceeccccccccccccccccccccceccecceccccccccccccccC:ccc C Global v a r i a b l e s :
INCLUDE
10.ALL'
C Input v a r i a b l e s : X
R E U XNIN,XW C Local v a r i a b l e s :
!prompt f default value ? l i m i t s an input !internal unit
C Function INTEGER LEHTRU
!returns true length a f s t r i n g
~cGcC~~eceeCccccecccccccccC:cE:cccccccccceccc~eeccceccccccccccecI:ccccccccc psampt f o r f l o a t , d i s p l a y d e f a u l t v a l u e C & U FLTDEF CXPRNPT, X 1 (TUNIT, 35, ERR=l0f STRING
C
10 G
a c c e p t d e f a u l t v a l u e X i f STRING i s empty I F (MMTRU (STRING) -EQc 0) THEN
C
GETFLTmX ELSE C2 3
(UWIT=STRING,FMT=*,EM=10} GETFLT (UMIT=SmING,FMTm1, E a = l O 1 CETFLT
MAD
5.
F O m T (E9.2)
END IF G C
40 50
m k e s u r e GETFLT % S between X M I M and X m X I F ( (GETFLT .LT. XMIN) .C%, (GEmLT GT, X=) MRXTE (OUNIT, CO) XMIN, X13AX m I )[XOMXT,35,ERR=50) STRING TP [LENTRU(STmNG) .EQ. 0) TNEN GETFLT-X
.
1 THEN
ELSE C4 5
C 35 60 100
=AD (OMXT=STRING,FMT=*,EM=501 GETFLT =hi[) (UMXT=S"lfIMG,FMT=Z,ERR=50) GETFLT END I F GOTO 40 END I F F O m T (A401
F O m T ( V r y ergain: i n p u t o u t s i d e o f r a n g e
+
[*,IPE11.3,
1PE11.3,@]@) F O m T (1PE9.2) =TURN EXVD
ccccccccCcceccccCccccccccecceccccccceccccccccccccccccccccccccececccccccc INTEGER FUNCTION f;ETINT(K,KMXN,K~,KE"RMP"I"} C g e t an i n t e g e r v a l u e GETINT;
D.5 Cerrerat Inper#/Outpui Codes C check t h a t it lies betwean KNXN and C C This function allows input o f integers
593
and prompt w i t h K P W T
i n a n a t u r a l way (i.e., w i t h a u t
C p r e c e d i n g b l a n k s o r decimal p o i n t s ) even though w s c a n n o t u s e l i s t C d i r e c t e d M A D (i.e., P m = * ) from i n t e r n a l u n i t s
c~e~~~ec~ccc~cc~~~~e~eccccC:ccccceccccccccccecccccccceccccccccececccccc C Global variables:
INC"LUDE ' TO.ALL* C Input variables: CNWCTER* (*1 K B W T INTEGER K INTEGER KMIN, K M C Local variables: CTER*40 STRSMG TEP"IP C Functions: INmGER LENTRU
! s t r i n g prompt
!default value !upper and fower l i m i t s !internal unit !temp v a r t o a l l o w f o r e a s i e r i n p u t !returns t r u e length o f s t r i n g
cccccccccceccccccccccccccecececcccccccccccccecccccccccccccccecceeecccccc C 10 C C
promptforinput;dlsplaydeEault CALL XNTDEF (KPRMPT,K) READ fSIENST, 35, EM=lO) STRING a c c e p t d e f a u l t v a l u e K i f STRING is empty SF (LENTRU (STRSNG) EQ. 0 ) THEN GETIHTmK
.
ELSE C
change t h e i n t e g e r i n t o a r e a l nu&r
STRXNG=S~INGf1:LENTRU{STRIN61f/Ii.~ f
I C
r e a d t h e r e a l num$er from s t r i n g M A D [UBfIT=STRING, FNTa1, E M = l O f TEm FORMAT (F7.0) change it t o an i n t e g e r GETINT-INT (TEW) END I F
C
C
so 50
check t h a t GETIWT lies between KNIM and R m X TF ((GETINT .LT, WIN) .OR. (GETINT .GT. K M X ) ) THEN WRITE: (OUNIT, 60) KNIN, K M WAD (1UNIT, 35,EM=50) STRSNG I F [LENTRU (STRING) .EQe 0) THEN GETIMT-K ELSE STRLWG=STRING (1:LENTRU 4STRIMEj f /I"' READ (UMITmSTRXNG, PMT=l, m m 5 0 ) TEMP GETINT=INT f TEMP) EM0 I F GOTO 4 0 END SF
.
C 35
60 100
F Q m T [AllOf P O M T ( I Try a g a i n : i n p u t i s o u t s i d e o f r a n g e = f * ,I G , I C i , ' 1 F O m T fI10)
594
D. Common IfgiZitaf Codes C
RETURN END ccccccccccccccccccccccccccccccccccCcceccccccccccceeccceccccecccecceccce.~ CTER*40 FUMCTIOH CHAMC(C,CLNGTN,CPRWT) a c t e r s t r i n g CBhMC na longer t h a n CLNGTW from t h e s c r e e n
ceccce~ccecccccccce~ececcccceeGcccccccccccc~cccccccc~~ccccc~ccc C Global v a r i a b l e s : XNCLUDE ' 10,ALL' C Input variables:
CHWGTER* ( * ) C CHmCTER* ( * ) CPReT INmGER CLNGTW
! d e f a u l t value f prompt !nax l e n g t h !internal unit
C Functions:
TNmGER LENTRU
! r e t u r n s t r u e l e n g t h of s t r i n g
CCCCCCCCCCCCCCCCCGCCCCCCCCCCCCCCCCCCCCCCCCCCGCC3CCCCCCGCCCCCCCCCCCCCCCCCC
C
d a t a c a n ' t be l o n g e r t h a n 40 c h a r a c t e r s due t o f i x e d Esrmat IF (CLNGTH .GT. 40) CLNETB140
C C
lO C C
prompt f o r s t r i n g ; d i s p l a y d e f a u l t v a l u e C m T T E fOUNTT,20) CIP~ETfl:LENSRU(CPRMPT)f,Cfl:UeNTRU(C~l R E m (IVNIT,35, ERR-10) STRING a c m p t d e f a u l t v a l u e C i f STRING i s empty
XF (mNTRU(STRING) .EQ. O f THEM CWAmG=C ELSE
READ (STRTNC;,35, Em=10) CWAmC END IF c C 40
5O
find t h e t r u e l e n g t h of t h e input; v e r i f y t h a t i t i s not too Long IF (ZENTRU(CHARAC) .GT, CLNGTM) THEN WRITE (OUMIT,60) CLNGTW R m D (IUWIT,35, ERR-501 STRING IF (LENTRU(STRING) .EQ. 0) THEN CHmC=C READ (STRING,35, ERRmS01 CWARAC END IF GOTO 40 END IF
C
20
35 60
F Q m T (IX,A,lX,'[',A,"'f P O m T (A401
F O m T (' Try again: s t r i n g i s too long, maximum l e n g t h = \,I21
c RETURN END
c~ccccc~~~c~cc~~c~cce~ec~cccccccc~~c~cccccc~~cce~ceccccccce INTEGER FUNCTION UESEIQ(BIEIARV,PRONPT)
l2.S C;meralInpu$\Outpa-t Codes
5135
C obtains UESMO f r o m the serean; v a l u e Is O f o r na, 1 f o r yes
Ccccececcccccc~cccccccccccccccccecccccccc~ccccccc~cccceccceecccccecceccc C Global v a r i a b l e s : IMcLuae f x ~ . ~ ~ C Input p a r a m e t e r s : C H W C T E R * (*) P R O m T f NTEGER BINARY C Local variables: CWmCTER'3 STRING C Functions: INmGER LENTRU
~ t !prompt;
!default v a l u e
!internal unit ! r e t u r n s t r u e l e n g t h of s t r i n g
cccccccccccc~cccccccceeecccI:ecC:ccccC:eccccceeccc~eecceccccccecccccccccccc 1000 C
CONTINUE:
write psantr>t and display default values f F (BINARY .EQ. 1) WZTEIOU1JXT,IDI PRQMPT(l:L&NTRU(PRQMBT)) I F (BIMARY .E($, 0 ) WRITE (QUNf T, 31) PROWT (I;LENTRU (PROWTI 1
C RE=
fIUNXT, 20,ERR=1000) STRING
G
e
accept default valua; c h e c k t h a t i n p u t Is # y e or 'n6 I F (LENTRU(STRING1 .EQ, 0) THEN VESMa g BZNARY ) ELSE I F (STRINGI1:I) .Ea. * y f .OR. S T R I N G f 1 : l ) . E a . Y Y "TWEN
VFSNQ = I, ELSE I F (STRSNC(1:I) .EQ. 'nn" .OR. YESNO c- O
STRIUG(l:lf .Ea. ? H N " ) TWEN
etsE WRITE (OUNIT, 2 0 0 ) GOTO 1 0 0 6 END I F C
10 15
ao 200 C
F F F F
O M T ( I X , A , I X , * [yes)' ) Q M T 41X,A, 1X, [ n o ] " 1 omrta) O W T t f T r y again, a n s w e r mst be y e s or no')
MTURN END
CGCCCC~GCCCCCCCCCCCCCCCCGGCCCG~CC~CCCC~CCCCCCCG~CCCGCCCCCCCCCGCCGCCeCC~C LOGICAL FUNCTION MGCVT ( IdK) C c o n v e r t s l t o true a n d a n y t h i n g else ta false
ccccccccceccccCcccccccc~~ccccecccccceeccc~c~ccccccccc~cccccecccc~ccccccc INTEGER I J K !i n p u t I F (IJE ,EQ, 1 ) T m N LIOGCVT=.TRUE. ELSE MGCVT=. FALSE. END I F =TURN END CCCCCCCCCCCCCCCCCCCCCGCCCCCCCCCCCeCC~CCCCeGCCGCCCCC~CCCCCCGCCCCC~~CCCC~~ REAL FUNCTION RANNOS (DSEED)
598
D,Common Utility Codes C r e t u r n s a uniformly d i s t r i b u t e d random numb.er between O and 1
ccccccccecccccccccccceccceccccccccccccccceececcccccccecccccccccccccccccc DOUBm PWCISXON DSEEE) BOUBU PmCISION D2P31MYI, D2P3f DATA ~ze31~/2147ss3~47,~of DATA B2P32 /2147483711,00/
cccccccececcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccec DSEED = MOD (16807. BQ*DSE&BIB2P3IM) MmOS = DSEBD / D2P31
=TURN END
ccccccccccccccececcccccccecceceecccccecccccccccC:cccC:cccccccccccccccccccc
cccccccccccccccc~ccecccccccccccccccccccccccccccccccccccceccccccccccccccc C C
menu.alil
XNTEGER FL~~T,MVM,BOO~M,YES%IPIP30SX:IE"ISKZP~QV1T INTEGER TITLE,lrBATT,CHSTR,MTXT~,MCNOICCPE"RPfdT,CLRTW C IRTEGER I~TN,STOP,TTTERM,ITE"TLEtXTNA~fTGTERM(rXGHRD INTEGER IGFILE,TGHWE,ZSTQP
c C
d a t a a r r a y s f o r menu !prompt s t r i n g !terse d e s c r i p t i o n I d a t a type ! d e f a u l t value f o r i n t e g e r ! d e f a u l t v a l u e for r e a l !lower l i m i t on i n p u t !high l i m i t an i n p u t ! d e f a u l t value f o r s t r i n g
INTEGER MTYPE
INTEGER NTMTS MU m A L S
W A L MWLIM
R M L MHILXM G G
menu d a t a t y p e s P W m T E R (FWAT PAWMETER (NUM PAWET= (mmN
BAmMETER (PPRSNS PAaAMETER (CLRTRB
G
e
--
Of 1) 21
f 2) 13)
!f l o a t i n g p o i n t number !i n t e g e r
!yea o r no u s e r i n p u t !yea o r no, s k i p on YES !Yes o r no, s k i p on NO !Unconditional GBTO f a b o r t c u r r a n t ASK c a l l !print: prompt (in ASK o r PRT&GS) ! p r i n t pronrpt and invoke PAUSE !c h a r a c t e r a t r i n g ! p r i n t IYIE"WT ( 1 d d r l n g ASK only ! p r i n t prompt, get choice, branch ? p r i n t o u t parameters ! c l e a r screen
menu e n t r i e s whieh a r e t h e s a w f o r a l l programs P M m T E R (ZMAIN 50) !-in menu c b o l c c P-METER f STOP = -2) l flag t o stap 73 ) !text t o t e m i n a l TER (ITTEM 74 !text t o f i l e P m m T E R (ITFILE
B.3 General I~p~~\Q"utpatCodes P m m T E R (TT%P m M E T E R (TGTERN P W W T E R (IGWRD = P m m T E R (IGFTLE =
'75 1
83 84 85 TER I f C N M = 86 TEE (ISTOP 98
C
1
1 1 )
f f
!text file nam !graphics to terminal tgra@ies hardcapy lgraphics ta f i l e t graphics f i l e name E last e n t r y
CoWON/WARS/MTYPE t l o o ) , MINTS {l001 , L5 (loot ,MLoLIM(lOo),MX1LTM[1.00} C O m O % / C W m $ / W W T (loo), MTWG (lOO},MSTRNG (3.01
597
D.4 Graphics Codes The two FORTRAN files, CRAPBIT.HI and oRnpaIT.Lo, are collections of subroutines that produce two-dimensional or contour plots. They allow one to four plots per saphies page. The two-dimensional axes can be either linear-linear, log-linear, or log-log, while both the axes for contour plots must be linear. To produce a plot, all of the variables listed in c m n r . n u must be defined, ss well as the data array8 (X and Y for two-dimensional plots; and 2 , ECONT, EX, EY, W I I , a d MIX for contour plots) and the device type (DEVICE). To create a graph the program must first c$l CTDEV to nominate a device and GnoDE (in file SE~P.MR) to change to graphics mode (if necessary). For each plot on the page, the program calls LBLIAX, LCLIAX, or LGLCAX to draw the appropriate axes; and for each data set to be plotted on the same set of axes, the program calls XVPL~T(two-dimensional plots) or COBTOR (contour plots). When the graphics page is finished, the program calls GPAOEto dose the graphics ) switch back to text mode (if pachge and THoDE (in file S E ~ . F O Rto necessary). cRnparr.a1 calls CA-DISSPLA (version 11.0) routines; oRnparl. LO c& UIS routines. For users who do not have access to either CADISSPLA or UIS graphics, these programs are intended as templates to fadlitate the development of code for their graphics package. For users who do have one of these pacbges, please read the information below that is sspecific to your software.
CA-DISSPLA OMPHIT .IIIindudes the following subroutines, which ase not cded directly by the physics pp~grams:SUBPLT, wkich sets the area of the device to be used for plotting, BARBIER, which prints the title, uam, which writes wt; axis lab&, and U G Ewkich ~ , wribs m t an infarnational message. Device namin&ion is often instatlation dependat, so you anight need to edit subroutine GmEV before the code will m k . Note that XQvfi a;ad PovaL are not used by CA-DISSPLA.
'UIS Graphics GMPHI%LO calls to the TTIS gfalphics routines, whi& me avdabie on VAXstations. A11 non-stmdad FORTRAN-77 syntw i s Wsociated solely with UIS calls. The subroutines not explicitly c d e d by the physics progrms ape SUBPLT, which sets the area fjor plotting, &es eharaeter size, creates virtud displi~ysdong with Prindo~rsa ~ transford mations, writes the title, and enables the display list (for hard copy); XAXIS and YAXIS, which draw and label the axes (either linear or log); LEGEBD, which prints an informationd messqe at the bottom of the page; GSm, whi& draws symbols on the dot; and COBTq wBi& does the c&-
Lr.4 GmpAics Codes
599
culation and drawing of contours. Throughout the code, three different attribute blocks are used; block 1 writes text in a size approprizELe to the plot size; block 3 writes the same size as block 1, but rotated 90 degrees; and block 2 contains the correct line type (e.g., solid, dashed, etc.) Hardcopy i s obtained by enabling the display list (subroutine SWPLT), then writing out the display list using m HCUIS routine (subroutine c~nce). Because the HCUIS software is optional it may not be currently available on your machine, but is easily installed. The device independent output file created by HCUIS is then translated by the DCL command IRENBIGR into a Me with the format necessary for o specific harrdcopy device. For more help on hardcopy, see MieroVMS Workgtslation Guide to Printing Gmphies (order number AA-HQ8BB-TB). For general help on U1S routines, h e i M i w VMS Work:sta.tion Gmphics P q m m i n g Guide (order number AI-GIIOB-TN), available from Digital Equipment Corpo eccecccccccccccccccccccececccccccccccccccccccccccccccccccccccccccccccccc C file GaAPXfTeHX eCcCcC~CCcCCCCCeCGCCcCCCcCCCcCCCcCCCCccCcCccCcCCCCccCCCccCCCcccccGc~cccc SUBROUTINE LNLHAX C draws finear-linear axes
cccccccccccccccccccccccccccccccccceccccccccccccccccecccccccccccccccccccc G Global variables INCLUDE 'GWDAT ,ALL* XSIZE, USIZE
C Local variables m L XSTP, USTP REAL VSIZE, WSIZE CWONISIZE/VSIZE,HS%ZE
! s i z e o f axes in inches
Ilength between t i c k s in user units IXSXZE and VSIZE
eecccccccccccccc~cccccccccccccecec~cccccccccCc~ccccccccccccceccccccccccc C
write title I F (IPLOT .EQ. 1) CALL BANNEW (TITLE)
C
set subpfat area CALL SUBPLT (IPLOT, NPLOT, XSIZEt YSXZE)
C
label axes CALL mBELS (MBELI
C
write infoxmtianal message BSIZE=XSIZE VSIZE-VSTZE CmL LEGEMB
C
draw linear-linear axes XSTP- (XmX-XMIN) /NXTzeK
rsTP= ( Y ~ - Y M I W INYTXCK I CALL G W (XMSN, XSTP, X M X , YMIN, YSTP, VlrylXj
WTURN END
cccccccccccccccccccccceccccccccecccccccccccccccccccccccccccccccccccccccc SUBROUTINE LGLNAX C d r a w s l o g - l i n e a r axes
ccccccccceccccccccccccceccccc"cccecccecccccccecccC:ccccccceccccc"ecccccccec C Global v a r i a b l e s
INCLUDE WRFDDAT.AZL~ R a L XSIZE,YSXZE C Local v a r i a b l e s REAL YCYGLE =L XSTEP RML VSIZE, WSIZE CO~QN/SIZE~VSIZE,HSXZE
! s i z e of axes i n i n c h e s ! i n c h e s p e r c y c l e on y axis ! l e n g t h i n u s e r u n i t ~ / l @ n g t hi n i n c h e s !XSIZE and YSIZE
ccCcececcccccccecceccccceccccccccceccccc~cecccccccccccceeecceccecccccccc C C
C G
G
write title I F {SPLQT .EQ. 1) CALL BAEJNER (TITLE) set s u b p l o t area GALL SUBPLT ( I f LOT, WPLOT, XS5ZEI YSIZE) l a b e l taxes CALL MBELS (L&BEL) w r i t e i n f o r m a t i o n a l mssage WSIZE=XSIZE VSJZE=VSTZE C G L LEGEND draw l o g - l i n e a r axes YCuCLE=YSIZE/ (ALmlO (IImX)-AL%lO (YMENb1 XSTEPm ( X M - X W I N ) /XSIZE CALL YLOG (XMIN, XSTEP, VMIN, UCUGLE)
C
RETURN
END
ccc~ccccccccccccccceccccccccccceccccccecccccccccecccccccccccccc~cccccecc SUBROUTINE LGLGU
e draws l o g - l i n e a r axes cec~ccccccc~ccccccccc~cceeccccccccccececcccceeccccceccccccc~cccccccccecc C Global v a r i a b l e s INCLUDE GGRFDAT .ALLt G Local v a r i a b l e s m X 1XSIZE, YSTZE -L XCVCLE,YCYCLE m L VSIZE, BSEZE COWQM/SIZE/VSIZE,RSIZE
! s i z e o f axes i n i n c h e s ? i n c h e s per c y c l e lXSfZE and VSIZE
c~~c~~~~cce~~~~~~~~c~c~ccccc~c~cccccC:cceccceceeccccceccc C C C
C
write title I F (PPLQT .%Q, 1) CALL BANNER(TITLE1 set s u b p l o t area CALL SUBBLT (IPLOT, NPLQT, XSIZE, YSf ZEj l a b e l axes C&L UBELS [UBEL) w r i t e i n f o r m a t i o n a l message NSIZE-XSXZE
D.1 Graphics Codes
801
VSIZE=YSIZE CALL LEGEND C
draw log-log axes
XCYCLE=XSIZE/(ALoGlo{XMAX)-&LOGXI)(XMIN) ! YCYCLE=YSIZE/(ALE10('VNX]-ALOG10[YMIN)) CALL LOGLOG (XMIN,XCYCLE,YMIPJ, YCYCLE1 C
RETURN END
~cc~e~~c~~c~Cccccccccccc~ccecccccc~cccc~ccccc~ccccccccccccccccccccccecc SUBROUTINE LEGEND G write information at the top left o f the plot
c~c~~c~~~~~c~~~e~cccccc~e~cccceccccccccc~ccceccccccccccccccccc~c C Global variables:
INCLUDE
'GWL1AT. ALL'
C Passed variables:
REAL XSXZE,YSIZE c Local variables: IWTEGeR LEN,LENTRU R a L VSIZE,HSIZE COMON/STZE/VSEZE,MSIZE DATA INFOk* ' /
!length af char string !XSTZ& and YSIZE
CcCcc~ecccccccceeccecccceccccecccccccc~ccccccc~cccccccccccccccccc~cccccc C
prints m s s a g e at t o p of plotting area
LEE-LENTRU f INFQ) IF (LEN .GT. O f THEN CALL ~SSAGIINFO(1:LENI,LEN,MSXZE*X05,VS12E*1.03~ END fF RETURN END
cccccccccccccccecccccccccccccccccccccccccccccccecccccccccccccccccccccccc SmROUTIEE C plots xy data
XYPLQT (X,Y)
c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c e c c c c c c c C
Global variables:
INCLUDE @GRFDAT.ALLP -L X !independent variable data array =L Y ?dependent variable data array DImNSION X (WOINT),Y (NPOINTf CCCCCCCCCCCCCCCCCCGCCCCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC C set line type IF f ILXNE .EQ. 2) CALL DOT IF (ILINE .Ea. 31 CALL DASH IF (ILINE .EQ. 4 ) CALL CWHDSH IF (ILINE .EQ. 5) IFmQ=-IFMB !no line at all C
C
set s y h o l type IF (ISYM .EQ. IfCALL mRKERf16) IF (TSVM .EQ. 2 ) CALLmRKER(2) IF (ISYM .Ea. 3 ) CALL mRKER(O1 IF (ISYN .EQ. 4 ) CALL m W E R 1 4 ) IF (TSYM .Ea. 5 ) THEN
!circle !triangle !square !cross !point
602
D. Common Utility Codes CALL SCLPIC ( ,3) END I F
e C
plot CALL CURVE (X,Y, WOINT, IFWQ)
G C
reset l i n e t y p e a n d f r e q u e n c y (%LINE .EQ. 2) CALL M S E T t r D O T * ) ( I L I N E .EQ* 3 ) CALL =SET ('DASHf 1
IF IF SF SF
f I L I N E .EQe 4) CALL RESET (*CCHNDSHf) f I L I N E .Ea. 5 ) IFREQm-1FREQ
G RETURN
Ern CCCCCCGCCCCCCCCCCGCCCCCCCCCC~CCCCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCGCCCCCCCCC
SUBROUTTME COMTQR (Z,MX, MY, ZNSN, ZMAX, NCONT] C d r a w n MCONT l i n e s f o r data c a n t a i n e d i n Z C l i n e s a l t e r n a t e b e t w e e n s o l i d and dashed; C i f passible, s a l i d l i n e s are l a b e l e d
CCCCGCCCCGCCCCCCCCCCCCCCCCCCGCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC G Global variables: INCLUDE GGRFDAT .ALL8 C P a s s e d variables: XNTEGER MX, MY =L Z(MX,m) R m L ZMIN, Z M X INTEGER NCaNT C L o c a l variables: REAL ZlNGR =I ~, ~ ~ ( 4 0 0 0 ) COMMON WOM @
Idimensfons o f Z !data ffirnits sn data ! n u e r of c o n t o u r s t o d r a w ?increment between contours !work space f o r D S S S P m
~~~~~~~~~~~~cc~~ccc~cc~~~ccc~~c~~~~~c~ CALL F W E C&L BCOMON ($000) ZINCR=fZW-ZMSN}/WCQW C S L C O g W (Z,MX, MY, ZINCR) C C
! d r a w a b o x a r o u n d area !pass i n f o r m a t i o n a b o u t w o r k s p a c e !increments between contours f make the c o n t o u r l i n e s
pravfde twa l i n e types CALL CONLINfO, VSOLTD","648ELSff 1.,10) CALL GaNLINfL,'DO"r,'EOWELS\,1,18) GALL CONTUR 12, P WIBELS' , 'DWW9 @
!draw c o n t o u r l i n e s
e RETURN END
ccc~~cc~~~~~c~c~cc~~~~c~ccc~~~~cc~c~~cccS:cceC:c SWRQUTINE GTDEV(DEVICE) C sets d e v i c e f a r g r a p h i c s o u t p u t t o DEVICE
~~~~~~~~c~c~~~ee~cc~e~ccccccc~~~c~cc~cceccccc~cccc~~ C Glabal variables: INCLUDE 'IQ. ALL@ C Passed variables:
INTEGER DEVICE INTEGER SCREEN INTEGER PAPER INTEGER FILE DATA sCREEN,PAPER,FXLE/I~~~~/
!device f l a g !send t o terminal ! m k e a hardcopy ! s e n d La a f i l e
ecccecccccccccccccceccccccccccccccecccccccceccccccceccccc~cccccccccccccc C
reset o u t p u t device
CALL I0MGR (a, -102) C
C
4014 t e k t r o n i x s c r e e n a t 9600 b a u d IF (DEVICE .ea. s c m E N 1 CALL T E ~ L L ( ~ O I ~ , ~ ~ O , O , O , ~ ) postscript Printer with default values I F (DEVICE .EQ, PAPER) CALL PSCWT ( 0 , 0 , 0 ) =TURN END
~cc~~c~~~c~~~~~c~ccccccccccccccccccccccccccccccececccccccccccccccccccc SmROUTINE GPAGE(DEVICE1 C end graphics page
cecccccccccccccccccceccccceccccccccccccccccccccccccccccccccccccceccccccc INTEGER DEVICE
!which d e v i c e i s i t ?
cccccccccccccccccceccccccccccccccccccccccccccccccccccCcccecccccccccccccc CALL ENDPL { O f C m L CLEAR CALL BOEaEPE
RETURN END
ccccccccecccccccccccccccccccecccccccccccceccccccc~cccccccccccccccccccccc C The f o l l o w i n g s u b r o u t i n e s are not: called d i r e c t l y b y t h e u s e r
cccccceccceCcc~cccccecceccccccccccccccccccccccccccccccccccccccccce:cc~ccc SUBROUTINE BAHNER(TITLE1 C p r i n t s t i t l e t o t o p o f g r a p h i c s page
ccccccccccceccccccccccceccececcccccccccccceccccccccccccccccccccccccccccc C Global variables:
! t i t l e t o 12(? p r i n t e d C Functions: INTEGER LENTRU C Local variables: INTEGER LENTTL
! r e t u r n s s t r i n g length ! l e n g t h of titZe
cecccccccccc~ccccccccccccceeccccccccccccccccccccccccec~cccccccc~cccccccc C
t r e a t t i t l e a s a graph by i t s e l f s o t h a t i t i s c a n t e r e d mEA2D("75,9.) CALL HEIGHT 4.14 f LENTTL=LENTRU(TITLE) CALL READIN (TIT= ( 3 :LENTTL) ,LENTTL, 1. ,l) CALL BNDGR ( O f RETURN
C&L
END
cccececc~cccc~cceccccecccccccccccccccccccccecccccc~cecccccc~cccccccccccc SUBROUTINE mBELS f =EEL) C l a h l s both x and y a x e s
cccccccccccccccccceCCGccccccccceGC"ccecccccccccccccccccccccccceccccc C G l o b a l variables: !X and
y labels
604
D. Commolz Utilitg
Codes
C Functions: INTEGER LENTRU C Loeal v a r i a b l e s : INTEGER LENX ,LEMY
!returns s t r i n g length !length o f l a b e l s
ccccccccccccceccccccccccccccccccc~ccccccccc~cccccccccccccecccceccccceccCt LEHXsLENTRU [-EL ( 1,) 1 LENY=LEHTRU (mBEL f 2 f ) C&LL XNkm ( M B L ( 1 ) fl:LENX) ,LE%X) C&L YNAm(MBELt2) (1:LENV),LENY) RETURN END
ccccccccececccccccccccccccccccccccccccccccccccccc~cccccccccce~eccccccccc SUBROUTINE SUBPLT (IPLOT, NPLOT, XSIZE, YSIZE) C defines subplatting
area
cccccecccccccccccccccccccccccccccccccccccccecccccccecccccccecccccccccccc C The c h o i c e o f s u b p l o t size a n d p l a c e m n t i s d e p e n d e n t a n t h e C d e v i c e a n d g r a p h i c s p a c k a g e ; t h o s e g i v e n h e r e are f o x a n 8 - 5 X C i n c h p a g e u s i n g DXSSPm
11
ccccccccccc~cccccccccccccccccccccccccceccccccccccecccccccceeccc~ccCccccc C Passed variables: INTEGER NPLOT INTEGER IPLBT R a L XSIZE,YSXZE: C Local v a r i a b l e s : REAL XORFG, UORIG
? t o t a l nu&ar o f p l o t s o n page !nu-X o f c u r r e n t plot ! s i z e o f p l o t t i n g area i n i n c h e s ! l o c a t i o n o f lower l e f t c o r n e r f i n c h e s )
cecC~CccccccCccCCCcCCCCCCCC@CCCCCeccccccccceccccc~ecccccccc C f i n i s h l a s t p l o t ( s e t s DISSPLW back t o l e v e l I) I F (IPLOT .NE. 1) CALL ENDGR (0) C C
d e f i n e s u b p l o t t i n g area ( i n i n c h e s ) ; w h o l e p a g e i s 8,5 x 11 I F (MPLOT .EQ. 1) THEN XSSZE="I .S YSIZE=9. CALL NEIGBT ( .l11 E M E I F (NPLOT .EQ, 2) TEEN YSIZE-4.25 XSIZE-6.5
XORIG=1, I F (IPLOT .EQ. l) UQRIG-5.75 TF (TPLOT .EQI 2 ) YORIGm.75 CALL HEIGHT (. 3 2 5 ) ELSE I F (NPLOT .EQ. 3 ) TBEN VSIZE=2.80 XSIZE=6 5 XORTG=l, I F (IPLOT *EQ. 1) YOR16=7.20 I F (XPLOT "EQ. 2) UORIG=3.9 XP (IPLOT ,EQ. 3 ) VORXGa. 6 CALL WEIGHT ( . l 2 5 1 ELSE I F (NPLOT .EQ. 4 ) TBEN XSXZEm3.25 YSSZE=4.25
D.4 Gmphies Codes CALL HEIGHT( .Ill I F (IPLOT .Ea. 1) THEN XORIG- .5 YORLG=5.75 ELSE I F (IPLOT .EQ. 2) THEN XORXG=4.?5 YORIG-5.75 ELSE I F f SPLOT .EQ. 3 ) THEN XQRSGm.5 'IORSG= * S ELSE TF (IPLQT .m, 4 ) THEN XORIG=4,75 YORIGm * 5 END I F
END IF C C
u s e d e f a u l t o r i g i n i f t h e r e i s only one p l o t I F (NPLOT .ME. 1) CALL PRYSOR(XORIG,YORIG)
c CALL AWA;?D (XSXZE, VSIZE) C
RETURN END
cecccccccccecccccc~ccccccccccccccccccccccccceccccccccccccccccccccccccccc cccccccccccccccccccccccececccccccccccccecccceccccceccccceccccccccccccccc C f i l e GWHIT,LO
ccCccccccccccc~eccccccccccccccccccccccccccccecccccccf:ccceccccccccccccccc SUBRQUTXNE LNLNAX G d r m s f i n e a r xy a x e s
ccccccccccccc~ccccecccccccccccccccccccccccccecccccccccccccceccccccf:c~ccc C Gfobaf v a r i a b l e s : INCLUDE GGRFDAT .ALLf LWICELL YLQG, XLQG
XO,XZ.,X2 t Y0,Yl,U2
! f l a g s ta s i g n a l l o g p l o t t i n g !tamp v a l u e s f o r x0va1, xmfn, xmax
W ! t a w values f o r yOval,yrnin,ymx CO~0N/LQGLMT/XO,XI,X2,YOIY1,V2 COMMON/LOCFLG/YLO(;, XLOG
c c e c c c c c c c c c c e c e c c c c c c c e e e c c c c c c e c C These temporary v a l u e s a r e e s s e n t i a l for l o g p l o t t i n g , but also must C be set for l i n e a r p l o t t i n g YZIQC;=.FALSE. XMG=.E'USE. Xl-XNIAI X2=XrnX Y 0lt.YOVAL
Vl=YMIN V2=UMAX XO-X OVAL
GALL SUBPLT CALL XAXSS C&L Y A X I S
!define s u b p l o t a r e a !draw and l a b e l x a x i s !drawn and l a b e l y a x i s
605
D. Common Utility
Codes
CALL LEGEND
f w t i t e out i n f o r m a t i o n
C
=TURN END
cccccccccccccccceccccccccccccccccccccccccccccccccccecccccccccccccccccccc SUBROUTINE 1CIC;LNAX C d r a w s l o g - l i n e a r x y axes
cccccccccccccccccccecccccccccccccecccccccectcccccccceccccccccccccccccccC: C G l o b a l variables:
INCLUDE ' GWDAT .ALLc LO%ICAL YLOG,XLOG REAL X O , XI, X 2 WAL YD,Y1,Y2
i f l a g s t o s i g n a l log p l o t t i n g ! t e m p values f o r x 0 v a l , x m i n , x m x !temp v a l u e s for y0val,ymin,ymax
COMP30N/LOGLHT/X0,X1,X2,Y0,Y11Y2 CO~ON/LQGFLG/YLQG,XLOG
ctccccccccccccceccccecccccccccceccccccccccCccccctccccccccccccccccccccecc YLOG=. TRUE,
! c o n v e r t t o log plotting
XLQG=.FWLSE.
c e
c o n v e r t t o log values i f n e c e s s a r y , XI=XHIN X ~ - X ~ X Y O=VOVAL Y1=AL,OGla (mIM) Y2mALOGl O ( Y m X f XO=ALOG10 (XOVAL)
w i t h o u t changing global v a r s
c CBLL SUBPLT CALL mxIS CALL UAXIS CALL LEGEND
! d e f i n e s&plot area ! d r a w a n d label x a x i s ? d z a w and label y a x i s !write out information
e =TURN
END
cccec~ccccceccccccccccccccccccccccccecccccccccccccccc~ccececcccceccccccc SUBROUTINE LGLGAX C d r a w s log-fag xy axes CC~CCCtCCGCCCCCC@CCC~CCCCCCCCCCCCCCGCC~CCCGCCCCCCCCCCCCCCCCCG~CCG~CCCCGC C Global variables: INCLUDE 'GRFDAT.ALL6 ! f l a g s t o signal 1ag p l o t t i n g LOGICAL YLOG, XLOG XO,XZ,X2 ! t e m p v a f u s s Ear x 0 v a l , x m i n , x m a x =L RmZ YO,YI,Y2 !temp v a l u e s far y0val,ymin,ymax
COMMQN/LQGLMT/X0,Xl,X~,VQ,Y~IV2 COMPIOH/LOGFLG/1SrL06;,XL8G
cccccccccccccccccccccecccccccccccceccccccceccccccccccccccccccccccccccccc C
c o n v e r t t o log plotting YLOG=.TRUE, XL,OG=.TRUE.
e C
c o n v e r t t o l o g values i f necessary, w i t h o u t c h a n g i n g global vars X f4LDG1O (XMIM)
D.4 Gmpha'cs Codes
607:
L
CALL SUBPST CALL XAXXS CALL YAXIS CaLL LEGEND
!define subplot area !draw and label x axis !drawn and label y axis !write out information
e RETURN END
ce~e~c~~ec~e~~cc~eccececcecccccceccccecccccccccccccc~cccccc~cccccccccccc C
SUBROUTSHE LEGEND write information at the bottom left of the p l o t
ce~~~cccc~cccccccceccececcceecccececceccccccC:ccccceccccccccccccccccccccc C Global variables: INCLUDE ' UISGW.ALLr INCLUDE %GRFD;AT.ALLr R&AL XD,XI,XZ !temp values for x0val,xmln,xmax Itentp values far yQval,ymin,ymax R m L YO,UI,Y"2 ~0MMOM/LOGLNT/X0,Xl,X21Y~IY11Y2 C Local variables: ll~eatfonof text REAL XTXT,VTXT 2EAL SMALL !small incremnts along either axis !length of t e x t INTEGER LEE C Function: !returns l e n e h of t e x t INTEGER LENTRU DATA SrnLL/.Ql/ DATA INFOjf ' /
ec~ccceccccccccccccC:cecccceccccccccecceccccC:cccccccc~ccccccccccccc~cccce LENmLENTRU ( I N F O ) IF (LEN .GT. 0) THEN YTXT=UP-S*SMALLxULNGTH XTXT=Xl+$*SmLL*XLNGTN CALL UISSTEXTITRID(fPL,OIp),IIINFO(~ZLEN] ,XTXT,YTXT} END SF' =TURN END
cecccccccccce~cccccccccecccccceccceeeecccccccccccccccccccccccccccccccccc SWRQUTINE XYPLOT (X,Y) C plots x, y data
ccccceccccccccccccccccccccceccccccccccccf:cccceccccccccceecececcccccccccc C Global variables:
IMCLUDE ' UISGRF.ALLe INCLUDE ' GRFDAT.ALL" LWICAL YLOG,XLOG COMMOW/WGFLG/YLOE,XLOG C Passed variables: RML X (NPOINT),V (NPOIIJT) C Local variables:
?flags to signal log plotting !data arrays
608
D. Common Uta'li2y Codes ? X and y indices ! p o i n t s t o be p l o t t e d
INTEGER 3 R m L Xl,X2,UI,Y2
cccccceeCc~ceCececcceccccccccccccccceccccccccceccccccccccccececccceccccc C set l i n e t y p e ( t y p e 5 i s no line at all) I F (ILINE -EQ. I f CALL
+
+ + + C C
vIsSsaT-%rHE-sTrLE ITRID ~IPZOT),O, 2 # 8 ~ ~ ~ SF (ILINE .EQ. 2 ) GALL UXSSSET-LIWE-STYLE (TRED fIPLOT1 I O C 2, 'FFOOFFOOtXI I F (%LINE .EQ, 3 ) CALL UISSSET-LINLSTYLE (TRZD IIBLO"P ,,Q, 2, VFFOFFFO' X) XF (ILIME .EQ. 4 ) CALL UISSSET-LXHE-STYLE {TRID ( I P W T ) p 0 , 2 , FOOOFOOOrX]
~ ~ ~ m 8
draw x y p l o t Xl=X (l) V1=Y (l}
C
convert d a t a f o r Log p l o t s IXLOGI XI=UEIO I F (YLOG) Yl=ALSIO ( U l )
ra
DO 1 0 0 X = I , NPOINT-2 X2=X (I-kl)
u2=u ( I + 1 ) fF (XZOG) X2-AL0610 ( X 2 1 I F (ULQG) Y2==8GIO fV2)
fF (IPREQ .ER. 0) THEN p l o t s y d a l s a t ffraq frequency f F (MOD (X, IFREQ) EQ, 0) CALL GSYM 4x1, Y1)
.
EWD I F
500 C C
I F (ILIME .NE. X1=X2 lll-Y2 CQMTINUE
5) CALL UIS$BLOTfTRfD(fPLQTf12tX%,Y~IX2,Y2~ !roll v a l u e s
p l o t sy&oZ a t the l a s t p o i n t XF (ZFREQ .NE, Q) THEN I F (HOD(I,XFm&) .EQ. 0) CALL CSYM(X1,YL) END I F
C
WTURIJ END
CCC~C~GCC~CC~~C~C~C~C~CCCC~~~C~~~CG~CGC~~CCCGCCC~~ SUBROUTSHE CONTOR (25, W, MY, ZNXN, NeQMTl C
draws p o s i t i v e c a n t o u r s s o l i d and n e g a t i v e c o n t o u r s dots
~e~~~ececcec~~~eec~~eee~~ccccccc~ecce~~~~ec~c~ccceccecec G
Glabal v a r i a b l e s :
INCLUDE ' I Q . ALL" INCLUDE @GGRFDAT.ALLe
C Passed variables: INTEGER m, MY REAL Z (MX,MY) -L ZMIEJ, ZMAX INTEGER NCONT
?dimensions of Z !data ! l i m i t s on data ! n u e r of contour Lines
0.4 Gmphics G~ckes BOB C Local variables: =L DELZ =L ZERO INTEGER NNEG
!2 i n t e r v a l !ZMIN ! n u d r of negative contours
cccccceccccccccccceccccccccccceccccccccccccccccceccccccccccccccccccccccc C
a l l 2 v a l u e s are p o s i t i v e I F ( ( Z m X .GT, 0.1 .AND. (ZMIN .GE.
0)) THEN
ILINE=T CALL COWT2 (Z,MX,MY,ZMIN,ZMX,NCONT)
e C
Z v a l u e s are b o t h p o s i t i v e a n d n e g a t i v e ELSE I F ((ZMAX .GT. 0.) ,AND. (ZMIN .LT,
0,)) THEN
DELz-tzmx-zMrWj/(weopIT+1b NNEs=rWT[-zMxN/tleLz) !mln v a l u e f o r p o s i t i v e c a n t ZERD=ZMIPa+DELZ*{NNEGl SLIEJE-S, CALL CONT2 (2, MX, MY, ZERO, ZluLAX, UCQNT-NNEG) ILINE=$ ZERO=ZMTPJ+DELZ* fNNEG+1 f !max v a l u e f o r neq c o n t CALL COMT2 (Z, HX, MY, ZMLN, ZERO*NPaEG)
e 2 v a l u e s are a l l n e g a t i v e .AND. (ZMIN .LT. ELSE ZF ( (ZMX .LE. 0.1 ILINE=$ CALL CQNT2 ( Z , HX, MY, ZMZN, Z m X ,MCONT) END I F
Q) ) THEM
c RETURN END
cCccccccc~cccccccccccecccceccccccccceccccceeccc~cccceececcccccGccccccccc SMROUTINE CONT2 (Z, MX, MY, ZMIN, ZMAX, WCONT 1 C d r a w n WCONT c o n t o u r s b e t w e e n ZMIM a n d ZNAX
c~CccCccccceeCccccccccceccccccceeccceccccccccccccccceccccccccccecccccccc C Global variables:
INCLUDE ' IO.ALL' INCLUDE ' UUIGRF .ALLf INCLUDE "GRFDAT, ALL" C Passed variables: IMTEGER m,MY R m L Z [1?4X,W) =L ZMZN, Z m X INTEGER NCONT C Local v a r i a b l e s : MAL DELX ,DELY ,DELZ INTEGER l X ,IU =L ZLL,ZUR,ZUL,ZLR WAL LL, UR, UL, LR =L X,Y R m L ZLEV INTEGER ICONT INTEGER WCUT RML XX(4),YVf4)
! d i m e n s i o n s of 5 tdata ! l i m i t s on d a t a !nu&er o f e o n t o u r T i n e s
!X,Y a n d Z i n t e n r a l s !X and Y i n d i c e s fZv a l u e s on c o r n e r s of a a w l a r e i d i f f s r e n c e s : ZLmV-ZLL, etc. !X,k' v a l u e s !value of Z on t h i s c o n t o u r ! i n d e x of c o n t o u r !number o f c u t s of ZLEV o n s q u a r e ! l o c a t i o n o f c u t s on s q u a r e
ccccccCececccccccc~ccccccccccccccccceccccccccccccccccceCcccccccce~cccccc C
C
+ +
+ +
draw box CALL UISSSETLTm-STYLE (TRZD(IPLOT],0I ZC'FPFFFFFF' X } CALL UXSSPLOT (TRTD(IPLQT],21XMIEatV m X IX m X C CALL UISSPLOT (TRID(TPLQT),Z,X~X,YMX,XE~AX, YPIINI set line type IF (TLTNE .Ea. 1) CALL UIS$SET-LINZ-STYLEfTRID{IPLOT]IO12,t~FFI"FFFfX~ IF fELTNE .EQ. 2) CALL UISSSET-LINE-STYLE (TRID(SBLOT),0,2? FFOQFFoOrXl fF fILINE .EQI 3 ) CALL UZS$SET-LINE-STYLE (TRXD(1PI;OT),a,2, @PFFOFFPOrX) IF (ILINE .EQe 4 ) CALL UXSSSET-LINE-STYLE {"rWXB(XPWT)I Or2, 'FOFOFOFarX>
C
DELX- (xmx-XHXN) / ~MX-I1 DeLy- (umx-unr~)(NY-It
!step sizes
DELZ= (ZMaX-ZMfN)/ [NCONT+ll C DO 100 IX-1,MX-1
X=XMIN+DELX*TX DO 200 IV=1,Pn-1 V-VPIIN+DELU*IY ZLL=Z( X X , IY) ZUL=Z(IX,IY+E) ZUR-S (IX+1,IY+lf ZLR-Z (SX+1,IYj
!loop over
X
values
!loop over Y values
!value of Z on lower left ?value of Z an upper left !on upper right fan lower right
DO 300 IGONT=I,#CONT !loop over cantaur levels ZLEV=ZHI#+DELZ*(XCQNT) ?level value LLmZLEV-ZLL !differences between UL=ZLW-ZUL !corner values and ZLEV URmZLEV-ZUR LR-ZLm-ZU
G C Far each of the four sides, determine if the contour line cuts that C side; if so find the location of the cut by linear interpolatianG Note that the contour line can cut only 0, 2, or 4 o f the 4 sides NCU[S=O IF (LL*UL .LE, 0) THE% NCUT=NGUT+% XX (MCUT)=X-DELX YU (HCUT)=U-DELY*UL/ (UL-LZ) END IF XF (UL*UR .LE, O f T m % PJCUT=NCUT+f X X (NCVT)=X-DELX*VR/ [UR-UL1 VY (MCUTf-Y END TF IF (UR*ZB .LE. 0) THEN NCUT=NCUT+I
D.4 Graphics Codes 611 INCUT)=X YY (%CUT)=y-aELY*uR/ (UR-LP,) END IF XF (LR*LL .LE. 0) THEN NCUT=NCUT+I XX (NCUT)=X-DEzXrXIR/(LR-LLf YV (NCUT)=Y-DELY END IF XX
.
300 200 100 C
IF (NCUT EQ. 0) TWEN CONEENUE !do notching ELSE IF (NCUT .EQ. 2 ) TWEN ? cannect the cut C A U UfS$PLOT(TRTD(IPLOTII2,XX(1~,YYff1 IXX(2jeYY(211 ELSE IF (NCUT ,EQ, 4 ) THEN f~onncctcuts; there is arbitrariness here vssSPLoT[TRrD(xPLoTl f2,~X[1) C ~(11 Y,XX(21 tYY4211 GALL UXSSPMT(TRID(IFLOT),~,XX~~~ ,YV(3),XX(4),YU(4)f END I F COWTINUE !end loop over contours CONTINUE !end loop over V CONTINUE !end l ~ o pover Z mTURN END
CCCCCCCCCCGC~CCCCCCCCCCCCCCCCCCGCCCCCCCCGCCCCCCCCCCCCCCCC~CCCCCCCCCGCCCC
SUBRGUTINE GPAGEtDEVICE) C close graphics packages
ccecc~ccceccccccccccccccceccccecccceccccceccccecccccccc~cecccccccccccccc C Global variables: INCLUDE "0. ALL' f NCLUDE ' UU1SGRF .ALLf INCLUDE p GRFBAT .ALLf =L XO,XI,X~ Itam values for x0val,xmfn,xnax W A L YO,Yl,YZ !temp values for yaval,ymin,ymax CQMMON/LOGLMT/X0,X1,X2,Y0,YlIY2 C Passed variables: INTEGER DEVICE !which &vice is it? C Local varf ables: !3.EAL XTXT,VTXT !location of text mt SMALL fsmll increments along either axis !d u m y input: !plot index INTEGER SCWEN ! send to ter&nal INTEGER PAPER !make a hardsopy INTEGER FILE !sand to a file !time as character data GKAMCTER*12 FNAMe ! file name DATA S m L L / . O l /
DATA SCmEN,E-'MER,FIILE/1,2,3/
cCcc~ccccccceccccccccccccccccccccccccccccccccccccceecccccccccccccccccccc IF (DEVICE .EQ, SCREEN) THEN
812
D,Conaman UtiZily C C
+ 20 c C
C C
Codes
allow for inspection of graph before deleting type informational message in lower right YTXT=ZV~-~*S~U*VLNG%N XTXT=X1+2*XLNGTN/3 CALL UISSTEXTfTRID(IPLQT~,lCfPre~~ return to continue*, XTXT, YTXT) READ (IUlcffT,20JD U M W FQRMazl ( A I )
ELSE IF (DEVICE .eQI naPaRj THEM get file name, of the form CPtim.UIS, where tim=bhmss this convention allows many plots, each with a unique name CALL TIME (CTICm) F~AME=*CPV/CTI~~l:2)//CTIME~14:5~//CT1CFIlE(7~81 / l r.UISt write data to file, disable display list CALL HCUTSSWRITE-DXSPMY fVDID,FBJAMEf CALL UISSDTSBBLE-DXSPmY-LIST [VDXD) END EP
c C
delete the display CALL UISSDELETE-DISPmV(VDID)
C =TURN END ccecccccccecccccccecccccccccccccccccccc-cccccccccccccccccccccccccecccccec SmROUTXNE GTDEV(DEVICE1 C sets device for graphics output to DEVICE; C for this graphics package, this uark is actually done in SUBPLOT
cccccccccccccccceccccccceccccccccccccccccccecccccccccccccceccccccccccccc C Global variables: INCLUDE 'XIO.ALLt C passed variables: !graphics to h sent to term or hard copy dorvi~e INTEGER DEVICE C lacal variables: INTEGER DEV !DEVZa in disguise COMHON / DEVTNFO/ DEV !pass variable to SUBPLT eCCCcGccCecCcCCCecCCcCcGcGcCCcCCcCGCcCcCccCCCccCGcCcCCCCcCccc~cccc~~cccc DEV=DEVLCE =TURN END
cccccCccccccccccceccccccccccccccccr=ccccccccccccccccccccccccccccccccccccc C The following routines are not called directly kzy t h e physics programs
ccccccccccccccccccccc~ccccccccccccccccccccccccccccceeccccccccc~cc-ccccccc SUBROUTINE SUBPST C defines subplotting area
C does all jobs which depend on the size of the plot
CcccccccccCcecccccccccccccccccccccccccccccccccccccccccccccccccccccc~cccc C The choice of subplt size and placement is dependent on Lbe C device and graphics package; those given hers are for an 30 x 20 em C screen using UIS routines
cccccccccccccc~ccccccccccccccccc~cccecccccccecccceccccccccccccceccc~cccc C Global variables:
INCLUDE 'GRFDAT.ALLr INCLUDE ' UISGRF ,ALLr !flags ta signal log plotting LaICAL YLOG,XLOG !temp values far x0val,xmin,xmax R a L XO,XZ,X2 !temp values for yOval,ymfn,ymax REAL UO,Y1,Y2 !graphics to be sent to term or bard copy device INTEGER DEV ~oIUIE~QN/LOGLMT/XO,X~,X~,V~~Y~~V~
COMMON/WGFLG/YLOGrXLOG COmQH / DEVINFO / DEV C focal variables: INTEGER LENTTL,UNTRU =L BSXMIN ,BSXmX R m L DSUMIEI,DSYmX R m L XSML,Y S m L R=& XmRG,Y W G REAL WIDTW,HEIGHT INTEGER SCREEN INTEGER PAPER INTEGER FILE CMMCTER*6O FONTID m L WID-TO-LEW =L XTXT INTEGER FIRST,YES,NO DATA SCREEN,PAPER,FILE/I,W DATA FIRST, YES,NO/ltl,2 1
!passed from GETDEV Istring lengths without blanks !total x display size in user units ?total y display s i z e in user units !percentage of window in margin !length of maxgin ?character size !sand to terminal !make a hardcopy !send to a file !type of font !width to length ratio for title ! X foeation of title Pn centimeters !first time thraugh?
ccCcccccceCcCcceccceececcccecccccccccecceccceccceccc~cccccce~ccCcccccccc G
C
length a f axes XLEaGTN- (X2-XI) P m G fW= (Y2-P1f a reasonable margin IF ((MPLOT .EQ. 3 ) .OR. XSMAL=. 12.
(NPLOT !EQ. 4) 1 THEM
YSPIIALm. 11
ELSE,
C
XSP31AL=.08 YSML-. 08 END IF XMRG=XSNL*XLHETW YrnRG=YSMAL*YLNGTM limits o f virtual display in user coordinates DSXMIM-XI-XmG QSXMAX=X2+XWG DSYNIN=YI-YWRG DWmX-Y2+2*YmRG
c f:
set size 05 window in centimeters XSXZE-36, YSIZEm25.
c C
C
make eorrectians to some of the above soecifications, as a function of NPLQT and SPLOT IF (NPLOT .EQ. 1) THEN
81.4 L?. Common Utility Codes XSIZE=22. !make this w i n d o w a Little srmsller YSIZEm27, ELSE XP (NPLOT .EQ. 2) THEN IF (IPLOT .EQ. 1 ) DSXMX=X2+3*XmRG+XLNGTf3 IF (IPLOT .E@. 2) DSXMINrXI-3*XmRG-XLNGTN ELSE I F (NPLOT .BC?. 31 THEN 1) D S Y M I N = Y l - 5 * Y ~ R G - 2 * Y L N G T H SF (XFLOT .E@. IF (IPLQT .EQ. 2) TWEN DSUNIN..OV1-3*YMRG-VLNGTH DSYMAX..Y2+4*YmRG+YLNGTR EPaD I F I F (IPLOT ,EQ. 3) DSYM=Y2+6*UPgRRG+2*YLNGTtt
eLsE rF (NPLOT .EO. $ 1 THEN I F (TPLOT .EQ. I) THEN
DSXmX=X2+3*XmRG+XLNGTW DSYMIN=Y1-3*k'~RG-VLNGTB
ELSE IF (TPLOT .EQ. 2 f TWEN DSXNTN-XI-3*XMARG-XLNETW DSYNIN=Vl-3*YmRG-YLHGTR ELSE I F (ZPLOT .EQ. 3 ) THEN DSXmX=X2+3*XmRG+XLNGTW BfYMAX=Y2+4*'JlMRG+YLNGTH ELSE SF (IPLOT ,EQ. 4 1 THEN
DSXMIN=Xl-3*XMRG-XLNGTW DSVMX=Y2+4*YmG+VLNGTH END T F END IF
TF (TPLQT .EQ, 1) TWEN
create a virtual display VDID=UXS$CREA~-DlSPLAY(DSXNXM,DSYMIN,DSX~X,DSY~X, XSSZB,YSXZE) choose a device IF fDEV .EQ. SGREEM) THEN
WDID=UISSCmATE-WINDOW(VDID, ~SYSSWQRKSTATTONf,~Co~ut.atIonal Physicsr) CALL UIS$DISABLE-DfSPLAY-L7:ST(VDXD} ELSE IF (DEV .EQ. PAPER) THEN GALL UZSSENmLE-E)ISPMZI_LIST(VDID) END IF sat character s i z e according ta window s i z e IF (NPLoT .EQ. 3 ) THEN MEIGWT=.05*YLNGTW CALL UISSSET-CHAR-SIZE (VDIB,0 , 1 , I HEIGHT) ELSE IF (NPLQT .EQ. 4 ) THEM WfDTH=.017*XZ1VGTH CALL ULSSSET-CHAR-SIZE (VD1D, 0, I,,WIDTH) ELSE XF (NPLQT .%Q. 2) THEN WIDTW=.015*XLNGTH CALL UISSSET-CHAR-SIZE fVDIB, OI 1, ,1?9I:DTNI
ELSE CALL UISSSET-CM~-SIZE(VDID,0,1) ERD IF allow fox text which is rotated 90 degrees CALL U T S $ S E T - T E X T - S M P E ~ V D I D ~ I , ~ ~ ~ O ~ ~ ~
c
e C C C C
C
write out title X scale is centimet~rs;yscale is user coordinates TRIP (0)~ u I ~ $ ~ ~ T E - T M M S F " O M fVDZD, T X O N0 DS'PMSM, XSXZEp D S Y W ) get infarmation to center the title LEITTL-LENTRU (TITLE) SF (FIRST .EQ. YES) THEN CALL UISSGET-FONT (VDID,Q, PO'EJTID) CALL UXSSGET-FONT-SIZE(PQNTID,TI:TLE:~I:LENTTL~~WXDTH,HEXGHT~ WIDTO-LEN=WXDTH/MAL(LENTSL~ Isave width/length for other calls FIRSTmEIQ END IF WIDTW=UNTTL*WIDTO-LEN XTxT- (XSIZE-WIDTH)l2 !width, height are in centiwters wrlte out title CALL UXSITEXT (TRXD( O f , 0, TITLE I I :LENIITL), XTXTfiY2+l.6*YMZIRGf
G
C
END TF create the tcansfarmtian f o r each pZot TRTD(IPLOTf=~JS$C~&TEET~NSFO~TIOEO~VDID,DSXMJM,DSYM~~, iB S X m ,DSYMX)
C
mTURM EHD
ccccccccceeccccccccccceccccccccccceccccccCccc~cccccccccccc~ccccccccc~ccc SmROUTIME =IS C draws m d fabef S x (hoxizantal) axis
ccccccceecc~ceccccceC:ecccecccccccccccecccccccccceecccc~ec~cccccccccccccc G Global variables: INCLUDE ' UI SGW ,ALLe INCLUDE ' GWDAT .ALL" LWICAL YLW,XLOC; ! f l a g s to signal log plotting W L XD,XI,X2 l tenrp values for xaval,xmin,xmax RmL YO,YX,YZ !temp values for yOval,yrnin,ynax COMMON/LOG~T/XOIXZ,X2,Y0,Y1,Y2 COFIMON/LOGFLG/VLOG,XZOG C Local variables: R W XTXT ,YTXT !location af text TMTEGER LENX,LENSTR,LENTRU !string lengths without blanks =L TCXHIN,TCKMX !y values at ends of tick marks W L XTIGK ! X value at tick mrk !string value aE xtick =L SmLL !small ineremnts along either axis INmGER 5 !indexes tick marks DATA SIUIALL/.OI/
ceccccc~cccccccccccccccccccecccccccccccccccccccccecccccceccceecccccccccc
C
draw x axis CALL UISSPLOT (TRID(IPLOT),a, XI,XQ,X2,XO)
C
C
lake1 X axis LENX=LENTRU (MBEL(1) ) XTXT-X2+5*SMLL*XLUGTW YTXT=XQ+S*SMLL*YLMGTN CALL UISSTEXT(TRIDfIBLOT) 3 , U B E L ( I . ) (1:LENX) ,XTXTfYTXT)
C
C C
tick marks set length o f ticks TCKNS#=XO-SNALL*YLMGI"B TCKWXmXO
C
C
DC3 SO I=O,MXTICK draw tick marks XTICK=X1+I*XLNGTH/NXTIeK CALL UISSPLOT (TRID( XPLOTf,Q,XTXCX:,TCKMXN,XTSCfS.,TCKmX]
c C
16 C
label tick marks XTXT-XTECR IF (XL%) XTIa=3O**XTICK CALL C O m T (XTSCK,STRZNG,LENSTRI CALL OXS$TEXT (TRID(IPLOT)I I t STRING f 1 :LEHSTR) XTXT,TCKMIH} CONTINUE
RETURN END CcCccccccccczccccccccccccecccccccceccccccccccccccccccccceccceccccccccc~c~ SUBROUTINE UAXIS C draws and labels y (vertiealf axis ccc~cccccccccccccccccccccccccccccccccccczcccccceccececcccccccccccccccccec C Global variables: IZJrCLODE ' UISGW .ALLp INCLUDE 'CRFDAT .ALLr LEICAL YLQG,XEOG !flags to signal log plotting !tee values far x0val,xmin,xmx REAL XO,Xl,X2 lU3AL Y O , Y l , Y 2 !tamp values for y0val,ymin,ymax CQMM0H/LOGLMT/XO3XI,X2,Y~,Y~,Y2
COMMON/LQWLG/YLW,XLOG C Local variables: =L XTXT,UTXT INTEGER LENV,LENTRU,UNSTR R M L TCKMIN,T C K m R&AL VTICK C B M C T E R * 9 STRING R m L SWLL INTEGER I DATA SmLt/.Ol/
!lacation o f text !string lengths without blanks !x values at ends a f tick marks fy value at tick mark !string value o f xtick !smll fncrewnts along either axis ?indexes tick marks
~ccCccc~cc~ecceccccccccccccecccccccccccccccccccccccccccccccceccccccccccc C
draw
y
axis
GALL VSSSPLOT(TRID(IPL.OT1, O,Y0,VTfYO,Y2)
D.4 Gmphies Codes C C
817
label y axis UNY=LENTRU (UBEL(21 f YTXT=Y2+S*Sf?lBLL*YLNC;TH
XTXT=U0+4*SMBLL*XLNGTW CALL UXSSTEXT (TRID(IPLOT) 1,UBEL(21 (1.:LEP;IV) ,XTXT,YTXT} c C
c
tick marks set tick length TCKMfU-VQ-SMALL*XLNGTH TCKMAX-Y0
C 80
C
20 I=O,NYTICK draw marks YTfCK=Vf+X*YLNGTH/NVTICR CALL UXSSPLOT fTRID(XPLQTJ,~,TcKMTN, YTIcK,TCK~X,YTIC:K]
e C
label marks YTXTmYTICK-.02*VLNGTH IF (YLOG) YTICK=IU**YTICK CALL C O m T f YTICK,STRING,LENSTR) XTXT=YO-.QB*XtNGTW CALL UISrTEXT(TRIO(SPLOT)'3, STRIP364 1 :mNSTR1, XTXTtYTXTI 20 CONTTNUE =TURN END cccccccccccecceccccccccccceccf:cecccecceecccccccccccccccccccccccecccccccc SUBROUTINE GSYM (XGNTR,YGNTR) C draws a sy&ol at XCNTR,YCNTR
ceeccc~c~cccecccccccccccccccccecccccccccc~cc"cccccccccecccccccceccccccccc G
Global variables
INCLUDE ' UISGRF .ALLe INCLUDE ' GGRFDAT .ALLe G Passed variables: REAL XCNTR,YCNTR C Local variables: R M L XSYM,USYM W A L Xl,X2,Yl,Y2
! x , y coordinates of symbol center
!symbol sizes in world coordinates ledges of square, cross and triangle
eCccc~cccecccc~ccccecccceeceeccceccceeecccecccccceececc~cecc~cccccC:ccccc C
C C
set symbol size XSVN=.005*XLNGTH YSYM=.UOS*YLNGTB circle IF fISVN .EQ. If THEN CALL UISSGIRCLE ITRID (IPLOT],Q,XCNTR, YCNTRIXSYM)
C:
C
triangle ELsE IF (ISUM .Ea. 2) THEN XI-XCNTR-XSYM XZ=XCNTR+XSYN UI-YCMTR-YSYM
61181 D. Common U#ifitg Codes
Y2=YCNTR+YSYM CALL ~ I ~ ~ P L ~ ~ ~ T R I ~ ~ ~ P L ~ T ~ , ~ , X I , Y ~ , X ~ , Y I , X C N T R , Y Z ,
e sware ELSE fF (ISYM .EQ. 3 ) THEM XI-XCNTR-XSYM X2mXCNTRfXSYN YI=YCNTR-YSYM Y2=UCNTR+USYW CALL UIS$PLQT(TRID (IPLOTfI 0 , X 1 r V 1 1 X 2 1 Y 1 1 X 2 1 Y 2 , X ~ e Y ~ , X ~ , Y ~ ~
G
c C
cross ELSE ZF {ISVM .Ea. 4) THEN XI-XCNTR-XSYM X2=XCNTR+XSYM YI=YCNTR-VSYN YZ=YGNTR+YSYM CALL UZSSPLOT (TRID(ICPLOT), a,xl, U, xz, V ~ I CALL UISSPLOT(TRZD(IPLOT],O,X1,Yz,X2# Y11
C C
point ELSE IF (ZSYM .EQ. 51 THEN eau., U~SSCXRCLE (TRID(XPLOT),0,XCNTR~YCWTR,XSYM/~.1 enta IF
c RETURN E%D
c~~~~~~~~ccc~~cececccccccccccccccccccccccccccccecccccccccecccecccccc c~ccceccccccc~cecccccccceccccccccecccc~ccccccccccccccccc~cccccc~cccc~cc C grfdat.all C INTEGER HPOTNT SNTEGER ILINE INTEGER ISVN INTEGER I F m Q INTEGER NPLOT INTEC;eR IPEOT INTEGER NXTICR,MYTICX
!nu&er of points to graph !code for line type !code far s y d o l type ! sy&ol f requeney !tatal n u d e r of plots on page !number of current p l o t !nunrber of tick marks
C"
GmRACTER*60 LABEL [ 2 CmmCTER*GO TZTLE
fxaxis and yaxfs labels !title for graphics page t informational message
RERL XMfN,X W
!limits an independent variable ! L i m i t s on dependent variable !y value alang x axis !X value along y axis
c m L VMTN,Y N X
R a L XOVAL REAL YOVAL
C
+
COMMON/GSTYLE/NPOfNT,ILTNE,ISVM,IFREQINFLOT,IFLOT, NXTZCX,NYTfCK COMNOM{LABELS/TTTLE,LAE?;EL,INFO COMMON/XYAXES/XMIN,XIVtAX YMZN,YlvlAX,XOVALIUOVAL
L14 Gmpkies Codes 6119 cccccccceccccecececceccccccccccccccecccccececececccccceccccceccccccccccc cccccc~ccccccccecCececcccccccccccccccccccccceccc~cccccccc~cccccccecccccc C uisgrf.all
(for GMPWIT.LD only) !these are part of W S INCLUDE pSYs$LTBMRY:UISENTRV" INCLUDE WsYS$LIBMRY:UISUSRDEF" !and only available on a V= !maximm n u e r of graphslpage INTEGER m P L T ? i d ' s ffor display and window INTEGER VDTD,tflDID ! i d t s for transformations INTEGER TRID -L XSXZE,VSIZE !size o f plotting area in centimeters R m L XT;NGTH*YLI\IGTW ! a x e s length In user units
C
CO~~M/DSP~V/XL~GTW,~LNGTB,XS92EtYSIZE COMMON/ XDlWXD, WDlD, TRTD 4 0 :=FLY)
This page intentionally left blank
Appendix E
Network e Transfer The ubiquity of network connections has made network file transfer a praetieal option for code distribution. To transfer files you need ftp (file transfer protocol) software and a connection to the Internet network (but not necessari?y a direct connection). Check with your system manager if you are unsure of the avkiIabllty of either, in The files me adlable on the Internet node physfcaitp, W&, There me thrw sub&rectopies: /fearan conthe dirwtory pab/c~m~hys. t&s d l of the FORTRAN codes fisttad in this book, lbasic contaLias AI of the IBM-BASIC codes, and /grap&ics contains subdire~torieawith additiond FORTRAN interfaws to graphics padtages (i.e., interfaces other than graphit. hi graphit.lo). (At the time of writing, only a GKS interface is available.)
E.1 Sample Session Below is a s a p l e sesdm that transfex's aU of the files en&ing with the .all exten~ion.Phrases that you type are in bddface, our cornmeals are in. italics, and computer responses are in plain type. The host camputer is a U N E environment. For those not familiar with UN=, you need only know the following commmds: fs -1 to list files in a directory, CAto change directories, and qnit to logoff. The ftp commands are as follows: prompt to toggle the prompting for file transfer (the default is that it will verify each file before sending), and wet to get files from the remote host. atgee mast be ~ Q B Q Wby C ?the ~ narne af the file to be sent; wild cards (e.g., *.* or *.&EL) are dlowed. UNIX is care sensitive, so nams must; match both letter and ewe. h t e *ha% sonae features of the host computer may change (e.g., the n m e of the computer, other subdirectoriee;), but every attempt will be made to kwp &heInternet address and directories assaciated with Cornputational Physics the same. Also, some of the details (e.g., prompts)
depend on the speGific implementad-ion of ftp on your xa lacd expat if you m n into diBcdtim, 2 f t p pbyrf crszep m.edu fi'P~pw-hxOws Connected t o mozz.unh.edu, 220 mozz.unh,edu FTP s e r v e r (ULTRfX Version 4.1 Tue Mar 1 9 00:38:17 1991) r e a d y ,
Name ( f t p h o s t : ) :
ul
331 Guest l a g i n ak, send f d e n t a s password. Password: ?ypQ h = $ ~ # *
&h@
230 Guest l o g i n ok, a c c e s s r e s t r i c t i o n s a p p l y , f t p > 2.8 -1
Iwk at c@-clfd&@q
( 0 bytes),
dr-xr-xr-X 4 O 512 May 24 10:26 p& < T r a n s f e r complete. T k "d" a, rl;ut k g i n n h finc * m m a c&q; of rkc d~roo orfilc iP QI m d ufrk Zinc. Etp> oa, p w h c b g c ro r k pub & e & u ~
l. -2
(Q b y t e s ) ,
552 Hay 24 10:2S NeXT 14754 Nay 24 10:26 n c p , d e f i n s s
< T r a n s f e r complete, od w w b g r
ftp>
Etp> 3.a -1,
2 O 2 O 2 0
drwxr-xr-X < T r a n s f e r template, Etp> c4d fartrm
(132.177.128,8,3767)
512 Hay 24 1Q:26 basic 1536 Jun 1 2 11:3J f o r t r a n 512 May 24 1 0 ~ 2 6g r a p h i c s c h g e l@Ikfw&an dk@cfq
10 b y t e s ) .
EST
E, Network: File %mjer 1s; *.rX1
Etp>
k m#
allfires
200 PORT c o m a n d successful. 1 5 0 Opening d a t a c o n n e c t i o n f a r / b i n / l s
(132.177.128.23,1790f
(0 b y t e s ) ,
grfdat-all 3.0, a l l
menu. a11 uisgrf.al1 226 T r a n s f e r complete. 538 b y t e s r e c e i v e d i n 0.27 s e c o n d s (2 f.(fsytes/sf ftp> I n t e r a c t i v e node o f f . Etp>
we& *.a%l
rwa flihe pronylt get n t s q t m wilh fk df a & w b
200 PORT c o m a n d s u c c e s s f u l . 150 Opening d a t a c o n n e c t i o n f o r g r f d a t , a l l f132,177,128,23,1736)
C1050
bytes). 226 T r a n s f e r complete. l o c a l : q r f d a t ' a l l remote: q r f d a t . a l X 10'73 b y t e s r e c e i v e d i n 0,0039 s e c a n d s (2,7e+02 K b y t e s l s ) 200 PORT c o m a n d s u c c e s s f u l . 150 W e n i n g d a t a c o n n e c t i o n Eos i o . a l l
(132.277,228.23,1797)
(1528
bytes). 226 T r a n s f e r completa. local: io.afl
remote: i o . a l l
3560 b y t e s r e c e i v e d i n 0.0078 seconds (2e+02 Rbytasls) 200 PORT c o m a n d s u c c e s s f u l . 1 5 0 Opening d a t a c o n n e c t i o n f o r m n u . a l l
(132.177,128.23,1798)
(2455
bytes), 226 T r a n s f e r complete, l o c a l : menu.all
remote: m n u , a l l
2504 b y t e s r e c e i v e d i n 0.0078 seconds (3,2e+02 Kbytes/s) 200 PORT c a m a n d s u c c s s s f u l ,
150 Opening d a t a c o n n e c t i o n f o r u i s g r f , a l l
(132.177,228.23,1789)
13ylCes) *
226 T r a n s f e r complete, l o c a l : u i s g r f . a l 1 remote: u i s g r f - a l l 637 bytes r e c e i v e d in 0.0039 seconds (3,6e+02 K b y t e s l s f ftg> quit: logcfjrrmte hDsl 222 Goodbye.
>
puvre back to yclur cnvn mehint
(625
623
This page intentionally left blank
References
[Ab64]
IJandboook of Mathematical Functions, eds. M . Abramowitz and I. A. Stegun (Dover, New York, 1964).
[Ab781
R. Abraham and J. E. Marsden, Foundations of Mechanics, Second Edition (Benjamin-Cummings Publishing Corp., Reading, 1978) Chapter 8.
F. S. Acton, Numen'eal Methods that Work (Harper and Row, York, 1910).
&W
S,
L, A&er and "F, Pirm, Rev, Mod, Phys, 56, 1(1984).
V. I. Anndld and A. Awz, Eqodie Pwblems in CIagsicat mchanics (Benjamin Publishing Corp., New York, 1968).
A. Baker, Phys. Rev. 134, B240 (1964). H. A, Bethe and R. W, Jwkiw, Intemdiate Quantum Mechanics (Benjamin Publishing Corp., New York, 1968).
R. Bevington, Data Rductriora and Ewor Artalgsia for the Physical Sciences (McGraw-Hill, New York, 1969).
P,
R. A. Bonham and M. Fink, Higia Enevy Elwtmn Sctitte&ng (Van Nostrand-Reinhold, New York, 1974). J. A. Boa m d D. S. Cohen, SIAM Je AppL Math,, 90, 223 (1976).
R. L. Burden, J. D. FGres, and A. C . Reynolds, Numerical Araalgsb, Semnd E&itiost (Priadfe, Weber, and Sck&dt, Bosto~, 1981).
D,M. Brink and G . R. SatcMer, Angular Momentum, Second edition (Clarencfon Press, Oxford, 19680, J. M. Cavedon, Thesis, tfniversitb de Paris-Sud, 1980.
[Ce79]
D. M. Ceperley and M. H. Kalos in Monte Carlo Methods ia Statkticair Physia, ed, K. Binder (Springer-Verlag, New Yark/BerEn, 1979). D, M.Ceperley and B. J. Alder, Phs. &V. Lett, 45,566 (1980),
S. Chadrmekhar, An IntducEion $0the Studg of Skkkalr Stmctare (Dover, New York, 1957). S. Chandrasekhar, &v. Mod. Phys. 58,137 (1984).
S. A. Chin, J. W. Negele, and S. E. Koonin, Aan. Phys, 187, 140 (1984).
H. nocard, S. E. Koalain, wd M. S, Weicrs, Phys, Rev. G 17, 1682 (1978).
L. D, Fosdick in Methods in Cosnrp'1ctataltmafPh~ic8,ml. 2 , ed, B. Alder et a t , p. 245 (Academic Press, New York, 1963). T. deForest, Jr. and J. D. Wdedta, Adv. Phys. 15, 1 (1966). J.
L. hiar and J. W, Negele, Nucf. Phys. A212, 93 (1973),
J. L. Friar and J. W. NegeIle, Adv. Nucl. Phys. 8 , 219 (1975). B. Rais et at., Phys. Rev, Lett;. 38, 152 (1977). P. Gombaci, Die Statische Theorie des Atoms (Springer, Vienna, f 949).
A. Goldberg, B.M. Sch;ay, and J. L. Schwartz, Am, J. Phys. 35, 177 (1967). H. Goldstein, Classical Mechanics, Second Edition (AddisonWesley Publishing Company, Reading, 1980). J, M. Hmmersley and D. C. Handscomb, The lWonte Carlo Method (Methuen, London, 1964). G. Herzberg, Spectm of Diatomic Molecules (D. Van Nostrand Compa;ny, Inc., NW York, 1950). M. I-Idn~nand C, Heiles, Astron. J. 88, 73 flg(i4).
E, H. G. Helleman in findamentat Pmbbms ira- Statiatrial Mechanics, vol. 5 , d.E. G. D. Cohen (North Holland Publishing, Amsterdam, 1980) pp. 165-233.
R. Hofstadter, Ann. Rev. Nuc. Sd.,7, 231 (1957).
K . Ruang, Statistiml Mechanics (John Wiley and Sons, New York, 1963). K. K. Km, J. J. Griffin, P. C. Lichtner, and M. Dworzecb, Nucl. Phys. A3S2, 109 (1979). M. K. Kalos, M. A. Lee, P. A. Whitlock. and G. V. Chester, Phys. Rev. B 24,115 (1981).
M. H. Kdos iwnd P. A. Whitlad, TIae B w k s of Monte GrIo Methods (J. Wiley and Sons, New York, in press). B. W. Kernighan and P. J. Piauger, The Elements of Progmmming Style, Second Edition (McGraw-Hill Book Company, New York, 1978).
L. J. KieEer, At. Data, 2, 293 (1971). D, Knnth The Art of &napater Pwmmmingf &&me 2: Seminumeriwl Algorithms (Addison-Wesley Publishing Cornpmy, Reading, 1969). E. B. KaEman and F. L. FZriebman, Problem SolPlilrqg and Streretuwd Programming in FORTRAN 77 (Addison-Wesley Publishing Campmy, hc.,Reading, 1987). E, D. Landau and E. M. Lifshitz, Coup#@ of Z"laeoretiwI Php~ics~ Volume 6, Nuid Mechanics (Pergamon Press, Oxford, 1959). B, Lipkin, N. Meshkov, and A. J. Click, Nud. Phys. 62, 188 (1965), and the two papers following.
B. MeCay m d 'X'. T. Wu, The Two-Dimewioottal d s i y Model (I-famard University Press, Camb~dge,1973).
[Me531
N. Metropolis, A. Rosenbluth, M. Rmnbluth, A. Tder, and E. Teller, J. Chem. Phys. 21, 1087 (1953).
A. Messiah, Quantum Mechanics (J, Wley & Sons, Inc., NW York, 1968)
R. G. Newton, Scattering Theory of Waves and Particles (McGraw-Hill Book Co., New York, 1966).
G. Nicolis and I. Prigogine, Self-organization in Nonquilibrium Systems (J. Wley and Sons, New York, 1977), Chapter 7. W. H. Press, B. P. Flannery, S. A. Teukdsky, and W. T. Vetterling , Numerical Recipes (Cambridge University Press, Cambridge, 1986).
P. J. Reynolds, D. M. Ceperley, B. J. Alder, and W. A. Lester, Jr., J. Chem. Phys. 77,5593 (1982). R. D. Echtaneyer and K, W. Moslon, Diflemnce Metfad8 for InitiaGvalue Problems, Second Edition (Interscience, New York, 1967).
S. A. Rice in Quantum Dynamics of Molecules (l$&@), ed. R. G. Wolley (Plenum Publishing Corp., New York, 1980) pp. 257356.
P. J. Roache, Computationat Fhid Dynamics (Hermosa, Albuquerque, 1976).
H. Rufisbauser, C ~ m m .of the AGM, 8, 67, Mgorithatl 150 (February, 1963). R. Shankar, Phys. Rev. Lett. 46, 1088 (1980). S. L. Shapiro m d S. A. TeukaXsky, Black Hoks, m i t e Dwarf@, and Neutron Stars (J. Wiley & Sons, Inc., New York, 1983) CHapder 3.
T, E..Shoup, AppEe'ed Nemerical Me&&& for the Mic (Prentiee Hall, Inc., Englewood Cliffs, 1984).
I. Si&, Nucl. Phys. A218,509 (1974). [W21
R. Varga, Mat riz Item tive A natysis (Prentiee-Hdl, Englewood CliRs, 1962).
E. L. Wachspress, Itemtive Solvtion of Elliptic Systems and Applications to the Neutron Diffusion Equatioras of Reactor Physics (Prentice-Hall, Englewood Cliffs, 1966).
S. J. Wallace, Ann. Phys. 78, 190 (1973); Phys. Rev. D8, 1846 (1973); Phys. Rev. D9,406 (1974).
R. C. Weast, Handbook of Chemistry and Physics, $pdedition, (The Chemical Rubber Company, Cleveland, 1971).
M. Weissblutb, Atoms and Molewles (Academic Press, New York, 1980). R. R. Whitehead, A. Watt, B. J. Cole, and I. Momison, Adv. Nucl. Phys. 9, 123 (1977). A. T. Winfree, Sci. Amer. 220, 82 (June, 1974).
T,-U. Wu and T . Ohmura, Quantum Theorgr o f Scatte9-ing (Prentice-Hd, Englewood Cliffs, 1962).
L.C. YaRe, Reviews ol" Modem Physics, 54,407 (1982). 33, SS,
R*Yennie, D. G. rtavenh&, md D. N. WiXmn, Physi, Rev. S00 (1954).
This page intentionally left blank
Index
40 Eri B, 53. 6-12 potential, 14, 222. see also Lennmd-Jonw potential. absciasm, gausisian quadrtlture, 9.5. acceleration par m e t = , elliptic patial biEerentid equations, 180. accuracy monitoring, ordinary differential equations, 32, a;Ccuracy, ordlinary differential e q u a t i o ~68. ~, plwltial diRerentiaf equation, 114, quadrature, 8, 13. action, 313.. Ad forth, method, 30. tvvo-step method, 29. RlIioulLo~ method^, 31. altern~tine;-directionmethods, pz~stial digerentid equation, 180. wgle, scattrrring, 20. annihilation oper(zt;or, 135, anti-ferromagnetic couplings, 220. anti-ferromagnetism, 216. approximation, Born, Stjfl., 121. Barn-Oppenhrrimer, 14, 221. centrd-Aeld, 78. Hatree-Fock, 728., 222. eikonal, 96@, 99, 129. fillhg, 78. linear, 109, 123. self-consistent field, 72, se~elmsical,114, 98, 139. WKB, 16. ato~e, nucleus, 120. arbitah , linear combination, 224.
sfruetu~e, I2& atom, low-energy resonwces, 108. mu1tkelecfron , 72. t auto-correlatiorr , Metropolk ~ l g o dhm, 214, 219. Besstjl function, cylindrical, 67, 81. polynodal appraxirn&iioxl, 87, recursion relation, 87' aphericd, 92, 104. binary alloy, 215, Bode" rule, 9, Born approximation, 96#., 121. Born-Qppenheimer approximation, 14, 221. Born scattering amplitude, 98. bound salutions, 14, 67, boundmy conditiollls, Dirichled, 146, 169, fixed, 190. Neumann, 146, 150, 178. no-fjtux, 190. no-slip, 165. periodic, 158.. boundmy value problem, 55g, Green" function solution, 6 18. round-aE error, 60. shooting method, 64, 67.. Hrusselator, 189g equilibrium values, 190. linear stability andysis, 1918 '@C&, 133. canonical ensemble, 216, canonical tradormation, 45,
capacitance, 157, central potential, 20, 38, 45, 103. centr~l-Geldapgraxim&ion, 78. centrifugal pokntid, 21, f 04, Cfiwdrasekfiar mms, 53. chwtic, dynmics, 378. regions of phase spwe, 42. & a g e density pmmeters, uncertainty, f 25chernicd reactions, 189g chi-a~quare,xninimitaation, 123. cfwicd sc;attrtring, 208. clmicdly forbidden re@an, 67. codes, gee program. eofleetivc? behavior , 1134. constant of the motion, 38. continuity equation, 159. convecdion, 159. convergence, root finding, 13. ernrelation, electram in Ill2 mobcule, 224, eorrelratioa, Metropolb algorithm, 214, 219. Coulomb potential, 14, 57, 72, 121. Cowtintg's method, 56. creation operator, 135. erws r~ection, dserential, 20, 121. Mott, 122, Rutherford, 121, tat&, 91. cylindrical Besel function, 67, 8Tfl cylindrical geometry, elliptic pastial diRerentid equations, 256. S-funclia~ pote~timl, 72. data analysitjr, 123. de Brofie wave numb=, 16, deaection function, 20' degenerwy paegsure, electrons, 46. d e t e r ~ n m t ,matrk, 110, 112. diatomic mokcule, 14. dileiectric constant, 155. tliEerentid crws wetion, 20, 121-
diffewatial equations, ordinary, 25& partial, 145fi diflerentiation, 1I 28. %point, 3. gpoind, 3 , &point, 6 , &point, 5, 6. b~kvvard, 3. forward, 3. hsta'biliCy, 4, round-oR error, 4, diffusion coeacient , 155. digusion eqrratbn, 146. Dirac gcatterirrg, 129, Diricblrtt boundary conditions, 146, 169. double-well potential, 12. drirt funetion, Path Ixltegaj. Monte Cmlo, 2263. driving term, ordhasy diaerential equation, 55. eddy, 167. eigenvalue problem, matrix, 112@ Gerselrxgorin's bounds, 114. Lanczos algorithm, 119. root finding, 113. trkdiagonaf madrh, 113. digerential equation, 56, Mg,, 147. iterative method, 188@ round-oE errors, 186. non-finear , 72. root finding, 65. eigenvector~,inverse iteration, 118, eikond, approximation, 9ISfF., 99, 129. scattering amplitcude, 99. electrons, correlation, Ha molecuIe, 224., density in atoms, 74. degenerit-ey prMsure in white dwarf s(tara~, 46.
free F e r ~gas, 47. g=$ 221. scatferhg from neutral atom, Ggh-enerm, 968. low-energ, 1038. scatterhg from nuclei, 120fjF. spin state iP1 &Q-, 73. vdence, 78, electronic eigenvdue, H molecule, 2231.
electrostatics problem, 157. elliptic fixed points, 42. elliptic partial digerentiaf equatioas, 146fi, cyXindrial geomtry8 156. ei(~-tnvslueproblem, 147, 1818 iterative metha&, 151fjF: spatidly vmfing dieketric constant, 155. aphczficait gmmetry, 156. twedimensional, 180. vmiatianal priaciple, 1478 equlzzdion of state, 47, polylropic, 52. equifiiibriurn vdues, Brusrrelatsr, 190. errorsp Monte Cetrb methods, 204. see also wcuraey, inaecurailcy, indabgity, round-OR, stability, nncert&tyl Euler's method, 26. Eubr-Lagrage equations, 75. exehaagel energy, 7'9. matrk elements, 75. explicit acheme, pasabolic partial dig fereritial equaLLion, 170. ~ m t b ~ ~cage, a y 157. Fermi, function, 126. g= of electrons, 47, momentum, 48, ferromapetic couptings, 220, ferromg~ethnn, 2 15,
filling appro~matiorx, 78. fin&g of roots, sw rool-finding, 11fi finite square-welf potentid, 72. fixed bounda?ry condition, 190. fixed pdnts, 42, dliptie, 42. hyperbdicic,42. fluid flaw, 158fl, incompressible, v.isco.u~,169. jump gwmtry, 168. nwale g ~ m e f r y168. ~ Fack pohntiaf, 88. forbidden regio~,cfwiesf, 67. force, pavitational, 46. prmsure, 159. vihlcoubs, 159, 167. Fourier expasion, 126, 127. Fourier-BweX trmform, 129. GauseChebyshev quadrature, 96. Gaumflierrite qudraiture, 95. Jordm methd, matrk inversion, 1x0. GaueLamerre quadrature, 94. GaueLegendre quaxfrature, 94, 202. GaueSeidel iteratioxl, 1151. Caumian, wavepacket , 188. dbtribution, rmdom number generation, 208. elhinalion and back-substitution, 175. quabrature, 85&, 9 2 8 well potentid, 101, 188. geometry, cyUmdrical, diptic partial diRerentiaf equations, 156. jump, fluid flow, 168. nozzXe, fluid flow, 168. spherical, elfiptic: ial diRerent i d equatio~a,156, Gerschgoria's bbounds, eigenvajue problem, 114. gravilhational force, 46.
Green's function, Monte Carlo, 225. solution, boundary value problem, 618.
H" ion, 83. E2 molecule, 11, 19, 221$. electron correlation, 224, electronic eigenvdue, 221. moleculas potential, 230, variational enere, 223. variationd wave function, 224, HID molecule, 17. Efmilkonia, integralble, 38. separable, 38. hmmonic-o~cillatorpotentialtl,path integral Monte Carlo, 230. Hartrw-Foch apgroimtion, 72', 133. %e, liquid, 221. Ze atom, 230. heat bath dgorithm, Monte Carlo methscls, 220. Hebenberg model, 2 15. Eermite poiynodah, 87. high energy qumturn scattering, 96fi Born agpr~xirnation, 98. s e m i c l ~ i c dapproximatiart, OS. eikonal approximation, 98, homogeneous equation, 60, 61. I-fou~eholdermethod, 115, hydrodynmies, s t e d y state, 1588, hydrogerric orbit&, 76, 84. hyperbolic fixed points, 42. IX6non and Heila potentid, 42.
inhomgeneow term, digerentid equaition, 55. initial value problem, 26, ordinary digerendid equatiow, 26, 58.
paurtial dsererttitli equation, 169, 172. integrable shgularidim, 10. integrable Efmiltonim, 38. inbgrab, multi-dimeasianal, 197. inkgation, see &&erential equation^, quadraitare, ixlfermlion, G u l a d , 14. Van der W d , 14. invdant torus, 42, inverse vector iteratbn, 118. inversion, m&rkp 1109. Ising mdel, 215fi hfinite lattice, 217. p h m transition, 2118, 220. c properdim, 215. jump geometry, fluid Aow, 168, KAN theorem, 42, Lagrmge multipkar, 77, 124, 182. Laguerre polynodak, 87. 111ac~walprikhm, eigenvalucs problem, 119. Lane-Emden equation, 52, Laplwe" equation, 157fl. lattice gauge thmrim, 221. Legendre polynomi&, 88, 93, 104, recursion reE&iona, 86. hnnard-Jones potential, 14g,20, 69, set: lxbo 6-12 potential. Lenz-Jensen poteitial, 101. impact par&meba, 20, 98, 129, linear cornbindion, atomic orbit&, impiieit methods, 224. ordinary differential equations, 30. linear congruentid method, rsndom parabolic partial differentid equat numbers, 205. tions, 174. linear &ability analysis for the Glrusinttccurmy, ardhary diaerentid equa aelator, 191ff: tions, 26, linear agproximaction, 109, 123. liquid drop, 126. infinite lattice, Isirrg mdef, 217,
Limajous patterns, 38. Lorentzim wwepacket , 188, IOW-energyatomic ressonmces, 108. low-energy scattering, 103fl. magnetic field, 215. magnetic material, 215. magnetizlztion, 227. m-, Chandraseaar , 53. matrix, d e t e r ~ n a n t ,110, 212. eigenvalue problem, l 12,ff. Caussian efiAnation and back substitution, 175. Hou~ehofd w method, 115$, inversion, 1098. equilibration, 112. pivoling, l 1l. Gauss-Jordan method, 110, numericd round-OR error, 112. operations, 109g reduction to tri-diagonal form, Il5jJ. singulas, 111. spar=, 145, 151. tri-diagonal, 151, 175. Metropolis dgorithm, 2108. auto-correjation, 214, 219. thermalization, 214, triral step size, 213. mixliHlization of chi-square, 123. mked boundary conditions, 146. molecuiar , orbitafs, 223. vibrations, 14& moEeculfE?, d i a l o ~ c , 24. Hz, 17, 19, 221F ER, 17,
17. momentum trmsfer, 98, 121, Monte Csuclo methods, 1978 errors, 204. Green's hnetion, 225. heat bath dgmithm, 220.
Path Xntegal, 225. drift function, 226. harmonic-oscillator gotentid, 230. unmrlaikirnty, 198. weight function, 100. see also random number generation. Morse potentid, I f ) , 222. Motd crws metion, 122, mult&dirnensionaI integrals, 197. multi-elec tran izCom, 72. mult ipole decomposition, 79. multistep mthods, 29,
M &vier-Stokes equation, f 59. Neumann boundary condition, 146, 150, 178. Newdon-Got= quadrature formulw, I. Newton-bphson root fincling, 12. no-flu boundary conditione, 190. no-slip boundary condition, 165, non-libear , eigenv~lueequations, 72. equations, 289. atability aadysis, f 91. normal mode solutions, 64, 191. noz;zle geometry, fluid Aow, 167. auele~, charge BZsLribution, 120g form facfor, 121, structure, 120, Numercav method, 56. Qz molecub, 17, ane-dimexlsional Sebroedixrger equatioa, 25, 678. open-sheH systems, atomic, 78. optic& theorem, 100. orbiting, scattering, 23. ordinary diEerential equation, Rrst order, 258. aecurmy monitoring, 32. Adam-Bmhforth, four-step met hod, 30. twestep mthod, 29, Adam-Moulton methodsr, 31.
Eulerk method, 26, implicit methods, 30. multistep methods, 29. predictor-corrector dgorithms, 31. raund-OR error, 38. Rung*Kuttsa, dp;orithm, 328, mcond-order , 32. third-ardw, 33. fourth-order, 33, 42. stability, 34g Taylar series , 28. ordinary diRerentia1 equation@, WCorrd order, 56. accuracy, 68. coupled first order, 25. Cowlingy&method, 56. initial vdue probhnn, 58. Numerov method, 56. over-relaaLlion, 152.
phme shifts, scattering, 104. ghwe space, 113, 31. p h a e transition, lsing model, 218, 220. scbemtic shell model, 141, plane wavet incide~t,97. Poimoa distribudion, random number $@aeration, 206. Poisson's equation, 55, 57, 121, 146, 158. polyn o ~ dapproxhations, Bessef funetion, 87. polyno~zmjts, Hermite, 87, Lquerre, 87, polytropic equzttion of atate, 52. potentid, 6-12!, 14, 222. parabolic we12 potential, (513, 70, 188. centrd, 20, 38, 45, 103. patabdic partial digerent i d equations, centrifugal, 21, 104. 1a9g Goulod, 5.7, 72, 121, 222, aeuracy, 174, B1funcf ion, 72. alternating-direction methods, 180. double-well, 72. explicit scheme, 170. implicit scheme, 174. finite square-well, 7% inst abililEy, 112. Fock, 80. stability, 174, 175. Gauissian well, 101, 188. twg.dhensiona1, 179g. Hz molecular, 230. partial diEerentid equatiom, 1458. hwmnic-oscillatof, 230. elliptic 1458. Hknon and Eeiles, 42. hyperbolic, 145. Lennard-Jones, 1 4 g , 20, 68. initial vdue problem, 169. LenltJe~sen, 101. pmabolic, 145, 1698. part i d wave decompasitio~, 103fl". Mars, 19, 222. parlidion function, 107, 218.. pwiabolic well, 69, 70, 188. path Integral Monte Carlo, 225. periodic, 72, pattern sdection, 189. squme well, 69, 70, 102, 188, Pasttli principle, 14, 73, 221. predictor-corrector dgorithms, 31. peit.iodic, prwsure farem, 159, boundmy conditions, 158. profile function, 100, 129. gotentids, 72. program, how t o use, 2318. perturbation theory, Ra~yleigh-Schraepseudo-random n u d e r s , 205. diager, 138.
quadrdure, 1, 6fl. accuracy, 8, 9. Bode" rule, 9. Gamsian, 85, 928. abscimm, 95. weights, 95. Gauss-Chebyshev, 96, Cam-Eermite, 95. Gauss-Laguerre, 94. Caum-Lesndre, 94, 102. Monte Carlo methods, 197G Newton-Gates, 7. round-off error, 8, 9. S h p m n k rule, 7. Simpson's rule, 9. n ~ p e ~ o i d arule, l 7, quantbation, semiclassical, 148 quantum states, stationary, 67. see alrso Schroedhger equation. quantum scattering, 988. quasi-spin operators, 136,
#
rainbow scattering, 23. randam walk, 210. random number generation, 2058. Gaussian (or normal) distribution, 208. line= congruentiali method, 205. Metropolis algorithm, 216. correlations, 214, 219. thermdizstion, 214. trid step size, 213, Poisson dktribudion, 206, pseudo-random, 205. von Neumann rejection, 207. Rayleigh-Eitz variational prineipb , 73, RayE&gh-Schroedinger perturbation theory, 138. recoil correction, 13l. recursion relation, cylindric& Bessel function, 87g. Legendre pof ynornih, 86. spherical Bessel functions, 92. relativistic kinemtics, 47, 122,
relmation method, eliptic partid differential equations, 154. residud interactions, 134. Reynolds number, lattice, 163. physicd, 163. root-finding, llg, 123, convergence, 13. Newton-Raphson, 12. seeant method, 12. simple =arch, If. round-oR error, boundaq value problem, 60, 61, &Eerentiabtion, 4, eigigenvalue problem, 186. forward recursion of Beml fume$ions, 90. matrix inver~iom, l f 2. ordinary digere~tialequations, 36, quadrature, 8, 9. RtlngeIiCutta dgorikhm, S2@ mcond-order , 32, third-order, 233. fourth+rder, 33, 42. Rutherford crws section, 121, scattering, mplitude, 97 Born, 98. eiko~al, 99. wgle, 20. classical, 20g. Dirrac, 129. electron, 96$, IQ$&, 1028 orbiting, 23. rahbow, 23. high energy electrons, 96& law-energy electrans, 1038. p h m shifts, 104, qumtum-mr;chanieaX3 9Sg schematic shell model, 1348. phme traxlsition, 141. serniclwsieal method, 139. tunneling, 142. Schroedinger equation,
time-independent, 15, 67@, 97, 103, 146, 181, 221. tirn+dependent, 146, 169, X8Bfl, 221. tunneling, 188. searchm, see root finding. secant method, eigenvdue problem, 65. secant, rosbfinding, 12. secand quantia&iaa, 135. second-ctfrder ordinary diflerentid eque tions, Numerav method, 66, seE-consiste~tfield approsmatio~,72. sedclassicd, method, schematic shell model, 139. quantization, 148. scattering, 98.
stability, or dhary diRerentid equations, 34' pm tial diRerential equation, 174. pasabolic partial dieerential equzttioxl, 275. stability an&is, non-linear equations, 191, @tars, 40 Eri B, 53. Skius B, 53. Stein 2051, 83. white dwad, 46g. stationary quadurn @traLes,67. steady state hydrodynamics, 158fl. Stein 2051, 53. strem, function, 261. linea, 161. stretched strhg, 64. segaratrix, 42. surface of eection, 39, shell m d e l , schematic, 133. swceptibilify, magnetic, 217, 8hootirzg metbad, boundary vdue prabTaytor wries, 2, 28. lem, 64, 67. temperature distribution, 157. s b p b =web, t hermalizlation, h"l;etropolis algorithm, eigenvdue problem, 65, 214, root findiag, 11. t hermadynahc pr~pertiw,Xsing model, Simpson's rule, Q. 215. Simpson3s ruXe, 7. ThomeFemmi model of the atom, 101. single-pitrtiele wave function, 72, t imedependent Schroedinger equation, singular martrH, 111. 146, 169, 1888, 221. sv(a) group, 136. thekdependant Sehroedinger equaisingufaritia, integrabb, 10. tioa, 15, 67fl., 97, 103, 146, Sirius B, 53. 181, 221, Slater determinant, 73, torus, 41, solar m= m d radius, 51, invmi~nt, 42. spar= matrix, 145, 151. total erws section, 97, special liunctions, 858, trajectory, 338, recursion relations, 86f. trapezoidal rule, 7. specific heat, 217. trtdisgond matrix, 113, 151, 175. spherical Bern1 functions, 92, 104, Eouseholder met hod, 115. spherical geometry, elliptic partid difmatrix reduction to, 115. ferentid equation, 156. trial a;.teg size, Metropolis algorithm, spin degrem of freedom, 215. 213. spin state, electron, 73. tunnelling, sfluare m11 potentid, 69, 70, 101, 1188. schematic shell model, 142,
8
timedependent Scfirwdi-xzgereqirraLion, 188. uncertainty, nuclear c h a r s (Xenb~ity parrameters, 125. Monte Carlo methods, 198. under-relaation, 152. unitary evolutioon operator, 187,
Virid dhmrem, 77, 81. vheaity, 159. von Neumann rejection, random mumber generation, 207. vortex, 167. vorticity, f 61.
wake, 162. wave function, valence electrons, 78. qumtum state, stationary, 67. vim der W 4 s interaction, 14. 72. shgl~particle, variati~nd, WKB, cBJcuIuki, 77, csleuXation, treatment of twae1e~- weight funetion, Monte Carlo, 200. weighb, gaussim quadrature, 95, tron system, 76. white dwarf s t m ~ ,46' principle, 148. WKB, wave fuxlction, Hz molr~-euXe,224approximtion, 16. energy, H2 molecule, 223. wave function, 70. vibralioaa, 1-46. moIecuIa, Idfi Wr~nskiran, 62.
m.