Computational Physics (Lecture 2)

1 / 33

# Computational Physics (Lecture 2) - PowerPoint PPT Presentation

Computational Physics (Lecture 2) . PHY4370. Approximation of a function. Interpolation Least square approximation. spline approximation. Random number generators. Random number generation . R andomness a property of an infinite sequence x i with i = 1, 2, . . . .

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'Computational Physics (Lecture 2)' - tamika

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Computational Physics(Lecture 2)

PHY4370

Approximation of a function
• Interpolation
• Least square approximation.
• spline approximation.
• Random number generators.
Random number generation
• Randomness
• a property of an infinite sequence
• xiwith 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, 2^M)
• The prediction of very smart person is not better than average.
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.
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.
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.
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.
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 = 7^5 = 16 807, b = 0, and c = 2^31 − 1 =2 147 483 647,
• excellent for generating unsigned 32-bit random integers.
• It has the full period of 2^31 − 1 and is very fast.

Very homogeneous and

random. There are no stripes, lattice structures, or any other visible patterns in

the plot.

// 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;

}

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

GregorianCalendar t = new GregorianCalendar();

intt1 = 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.

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).
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?

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 unit cells.
• Volume of unit cell:
• V= t1∙(t2xt3)
• Right handed system
• The primitive cell contains one lattice point, smallest cell
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
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…

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

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)

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)

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)

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!

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 + (i-1)*a

z(Na) = 0.0 + (i-1)*a

Next k

Next j

Next i

Nt(Sc) = Na (total no. of Sc atoms)

Detailed requirements:

The unit cell size is adjustable in both periodicity and lattice constant. The unit cell has to be cubic. Plot the structure using any graphic software, like matlab, origin, excel…

Score will be deducted if the program has bad variable/function naming conventions or without adequate comments. Email the code and output to me directly.

Project is due two weeks after the lab. Score will be deducted if the submission is late.

HW1 (due in two weeks after the class)

• Show the packing fraction in the following crystal structures: bcc = (√3/8)pi, fcc = (√ 2/6)pi, and Diamond=(√ 3/16)pi.

Dear Prof.Zhu, No problem, already reserved March & April every Thur 5:30-7:30pm for your course. Best Regards, Jason On Thu, 9 Jan 2014 18:43:14 +0800, Prof. ZHU Junyi wrote > Dear Jason, > >    Thanks for the arrangement. The time for the first five classes > is fine. Can we postpone the last class for one week, because I need > some time to arrange that project based on the results of the first > 5 classes? > > Best regards, > Junyi> > On Wed, 8 Jan 2014 17:50:22 +0800, M.W.Chan Jason wrote > > Dear Prof.Zhu, > > > > Yes, I've booked Lab326 for PHYS4370 Lab Sessions : > > > > from 16/1 to 27/2 (every Thurs) 5:300-7:30pm > > > > Best Regards, > > Jason