1 / 36

Computational Physics (Lecture 2)

Computational Physics (Lecture 2) . PHY4061. Random number generation . Randomness a property of an infinite sequence x i with i = 1, 2, . . . . Impossible to tell whether a single number is random or not. A negative property, it is the absence of any order. Uniform distribution

quintonr
Download Presentation

Computational Physics (Lecture 2)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computational Physics(Lecture 2) PHY4061

  2. Random number generation • Randomness • a property of an infinite sequence • xi with i = 1, 2, . . . . • Impossible to tell whether a single number is random or not. • A negative property, it is the absence of any order. • Uniform distribution • Uniformly distributed in the range of (0,1) or (1, 2M) • The prediction of very smart person is not better than average. • Rock paper scissor game. • John Nash’s equilibria: a mix of strategies always exists where no single player can do any better by changing their own strategy alone.  • https://www.quantamagazine.org/the-game-theory-math-behind-rock-paper-scissors-20180402/ • Question: Are there game without Nash’s equilibria? • Question: Can you generate true random numbers using a computer?

  3. Desired properties of random numbers • Determinism. • odd property for a random sequence • if it is deterministic, one can predict with certainty the next number, if you know the algorithm. • Useful property for debugging! • Computers as they are now constructed are deterministic. • The only possibilities for randomness are to read an "external" device, • the microsecond clock or a very unreliable memory. • This is not done • too slow and too expensive. • Any other problems for such random numbers?

  4. Russian mathematician Ilya M. Sobol: • "A random variable that satisfactorily describes a physical quantity in one type of phenomenon may prove unsatisfactory when used to describe the same quantity in other phenomena". • Question: any other ways to generate random numbers, instead of reading external devices or using pseudo random number generators?

  5. Tables of Random Numbers • Very simple • Just like shuffling cards. • Suppose: you write each number from 0 to 99 on a card, • put all the cards in a hat • shake it and draw all the cards from this hat one by one • you end up with a sequence of 100 random numbers.

  6. To use these numbers in a program, • you can store them in memory • the same order in which they were picked from the hat • create a global variable to keep track the next random number that can be used from that table. • Problems of this method?

  7. Simple code: short rand[100] = {16, 55, 30, 12, 3, 92, ... }; int counter = 0; int N = 32; for (inti = 0; i < N; ++i) { short randNumber = rand[counter++]; ... }

  8. In 1955, Rand Corporation released a sequence of 1 million random digits. • It is the longest sequence of random numbers ever published! • Also probably the most boring book ever.

  9. PRNG • pseudo-randomnumber generators (PRNG) • perhaps seeding (or initializing) them with the clock. • A perfect pseudo-random number generator appears to be perfectly random, • unless you happen to know both the algorithm and its internal state. • Only discuss pseudo-random numbers. • Let s be the internal state of the PRNG. Then a PRNG is a mapping from one state to another: sn+1 = f(sn). The nth random number is then some mapping of the internal state onto the integers or reals.

  10. Desired properties of random numbers • Cycle length. • Any PRNG eventually has to repeat or cycle • since there are a finite number of internal states. • One would like the cycle length to be longer than a typical run. • Consider the worst-case scenario, where all a code is doing is generating PRNs. Suppose a computer now can generate 109 operations/second. If we run it for 1 week we can generate 1015 = 249 PRNs. • Hence if the PRNG has the maximal cycle length we should have at least 49 bits in the internal state. The continuing increase in computer performance means that methods that worked in the past, may fail with tomorrow's computers. • Luckily, it is easy to make very long cycle lengths.

  11. Desired properties of random numbers • Uniformity. • if we go through a complete cycle, all the integers occur once. • Usually uniformity is easy to guarantee if you go over an entire cycle. • Correlation • completely uncorrelated with each other. • any average such as: < f1(xi+1) f2(xi+2) . . . fk(xi+k) > = < f1(xi+1) > < f2(xi+2) > . . . < fk(xi+k) > for any set of functions f. The average is over all internal states of the random number generator. • Monte Carlo simulations of statistical mechanics • sensitive to very long-range correlations. • Which particular correlations they are sensitive to is not very obvious, so often the only real test to run the code for a case where the exact answer is known or alternatively to try several different PRNGs.

  12. Common types of PRNG • Linear congruential generator: • xi+1 = (axi+ b) mod c, • where a, b, and c are magic numbers: their values determine the quality of the generator. • One common choice, a = 75 = 16 807, b = 0, and c = 231 − 1 =2 147 483 647, • excellent for generating unsigned 32-bit random integers. • It has the full period of 231 − 1 and is very fast.

  13. Very homogeneous and random. There are no stripes, lattice structures, or any other visible patterns in the plot.

  14. // Method to generate a uniform random number in [0,1] // following x(i+1)=a*x(i) mod c with a=pow(7,5) and // c=pow(2,31)-1. Here the seed is a global variable. public static double ranf() { final int a = 16807, c = 2147483647, q = 127773, r = 2836; final double cd = c; int h = seed/q; int l = seed%q; int t = a*l-r*h; if (t > 0) seed = t; else seed = c+t; return seed/cd; }

  15. Seed from system time • In order to start the random-number generator differently every time, • we need to have a systematic way of obtaining a different initial seed. • Almost every computer language has intrinsic routines to report the current time in an integer form, and we can use this integer to construct an initial seed

  16. GregorianCalendar t = new GregorianCalendar(); int t1 = t.get(Calendar.SECOND); int t2 = t.get(Calendar.MINUTE); int t3 = t.get(Calendar.HOUR_OF_DAY); int t4 = t.get(Calendar.DAY_OF_MONTH); int t5 = t.get(Calendar.MONTH)+1; int t6 = t.get(Calendar.YEAR); seed = t6+70*(t5+12*(t4+31*(t3+23*(t2+59*t1)))); if ((seed%2) == 0) seed = seed-1; To initiate the 64-bit generator, we can use the method getTime() from the Date class in Java, which returns the current time in milliseconds in a 64-bit (long) integer, measured from the beginning of January 1, 1970.

  17. Other PRNG • Tausworth Generator. • Ii = Ii - 250XORIi-147, • where XOR indicates a bitwise exclusive-or operation. This is very fast on the computer. It also has a very long internal state (the last 250 integers). Hence the cycle length is very long. It must be seeded correctly otherwise it can get stuck. • Lagged Fibbonacci generator. • Ii = ( Ii - 250 + Ii-147 ) mod 2M • This differs from the Tausworth generator because it is regular addition (modulo 2M).

  18. How to generate random numbers following a certain distribution? • Inverse transform sampling method. • Acceptance and rejection method. • Sample a point (an x-position) from the proposal distribution. • Draw a vertical line at this x-position, up to the curve of the proposal distribution. • Sample uniformly along this line (i.e. uniformly from 0 to the value of the proposal distribution (maximum of the probability density function)). If the sampled value is greater than the value of the desired distribution at this vertical line, return to step 1.

  19. Introduction to Crystal structureReference books: Any solid state physics text books, Kittel’s or Kun Huang’s for example.

  20. Crystal structure • Periodically placed building blocks (atoms, molecules, ions…) • Translational symmetry of the basis • Proved by X-ray diffractions • Crystal: basis + lattice • Or basis in the primitive cell + Bravais lattice • Why many high quality solid samples have long range ordering at low temperature?

  21. Bravais Lattices • A regular periodic arrangement of points in space. • tn=n1t1+n2t2+n3t3 • t1, t2,t3: primitive vectors • n1, n2, n3: integers • t1, t2, t3 form primitive cells. • Volume of primitive cell: • V= t1∙(t2xt3) • Right handed system • The primitive cell contains one lattice point, smallest cell • Question: The choice of the primitive vectors is unique or not?

  22. The choice of the primitive vectors is unique or not? • t1 = (a, 0, 0); t2 = (0, b, 0) • t1’ = (2a, -b,0); t2’ = (-a, b, 0) • Unit determinant of the transformation matrix • Therefore the volume is independent of the primitive vectors

  23. Unit Cell • Possible to describe the whole lattice using non-primitive cells => unit cell. • One example: t1 =(a, 0, 0) t2 = (a/2, b/2, 0) t1c = (a, 0, 0) t2c=(0, b, 0) • When to use primitive cell and when to use unit cell? • Full translation symmetry: use primitive cell • Wave vector quantum number, Brillouin zone concept…

  24. 1 oblique (1, 2), 2 rectangular (1m 2mm) including 3 centered rectangular (rhombic) , 4 hexagonal (3, 3m, 6, 6mm) , 5 square (4, 4m)

  25. Diamond and Zincblende

  26. ABABAB stacking Packing fraction: the maximum ratio of the volume of hard balls that occupy the lattice points to the total volume Graphene (Scienc 306,666,2004)

  27. Geometrical description of some crystal structures • Fcc: t1 = a/2(0,1,1) t2= a/2(1,0,1) t3=a/2(1,1,0) • Bcc: t1 = a/2(-1,1,1) t2= a/2(1,-1,1) t3=a/2(1,1,-1)

  28. NaCl: t1 = a/2(0,1,1) t2= a/2(1,0,1) t3=a/2(1,1,0), d1 = 0, d2 = a/2(1,1,1) Diamond structure and zincblende structure t1 = a/2(0,1,1) t2= a/2(1,0,1) t3=a/2(1,1,0), d1 = 0, d2 = a/4(1,1,1)

  29. Crystal direction: [l1,l2,l3] l1 a1+l2 a2+l3a3 equivalent: <l1l2l3> By convention, negative index are written with a bar, as in for −3 Crystal planes (h1,h2,h3) :Miller index a1/ h1,a2/ h2,a3/ h3. equivalent {h1,h2,h3} a1a2a3 are unit cell vectors!

  30. Crystal direction for a simple cubic

  31. Sample code for a simple cubic lattice Input: cell size (Lx ´ Ly ´ Lz) = (nx ´ ny ´ nz)a3 , a --- lattice constant. Sc: Na = 0 (no. of atoms) i=1, nx j=1, ny k=1, nz Na = Na +1 x(Na) = 0.0 + (i-1)*a y(Na) = 0.0 + (j-1)*a z(Na) = 0.0 + (k-1)*a Next k Next j Next i Nt(Sc) = Na (total no. of Sc atoms)

  32. Project A part I: Programming Sc, Bcc, Fcc, and Diamond crystalline structures. Detailed requirements: The simulation cell size is adjustable in both periodicity and lattice constant. The shape of the cell has to be cubic like (or tetragonal). Make sure to include correct number of atoms in your cell. Plot the structure using any graphic software, like VMD… Score will be deducted if the program has bad variable/function naming conventions or without adequate comments. Email the code and output to Felixdirectly. Project is due two weeks after the lab. Score will be deducted if the submission is late.

More Related