Steven E. Koonin Computational Physics, ForTRAN Version 1998

April 28, 2017 | Author: Chris3711 | Category: N/A
Share Embed Donate


Short Description

Descripción: Steven E. Koonin Computational physics...

Description

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, + 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., $ 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 ~ ( 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- ~ ~ - ~ 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

mle 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~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 ) / 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 ~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 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)

! [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 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 oa, p w h c b g c ro r k pub & e & u ~

l. -2

Etp> 3.a -1, 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.

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF