Docsity

Computational Physics, Fall 2020 Problem Set # 10 Contents, Lecture notes of Physics

Toggle sidebar
bg1
Cornell University Department of Physics
Physics 4480/7680: Computational Physics, Fall 2020
Problem Set # 10
(Due Wed December 16 at 11:59pm sharp.)
Goal: DFT calculations of solids!!!
Contents
1 Minimal, isotropic spectral representation 2
1.1 “setup.jl” .......................................... 2
1.1.1 Radius of inscribed sphere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1.2 Debugging...................................... 3
1.2 Operators .......................................... 3
1.2.1 L()andK()..................................... 3
1.2.2 cI() ......................................... 3
1.2.3 cIdag() ....................................... 4
1.2.4 Debugging...................................... 4
2 Full benefit from minimal representation 5
2.1 getn(),getE(),H() ..................................... 5
2.2 H().............................................. 5
3 Calculation of solid Ge 6
3.1 “setup.jl” .......................................... 6
3.2 “Geatoms.jl” ........................................ 6
3.2.1 Debugging...................................... 8
4 Optional: Variable fillings and verification of pseudopotential 9
4.1 getn() ............................................ 9
4.2 getE() ............................................ 9
4.3 Q().............................................. 10
4.4 getgrad() .......................................... 10
4.4.1 Debugging...................................... 11
5 Isolated Ge atom 11
A “Q()” 12
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Computational Physics, Fall 2020 Problem Set # 10 Contents and more Lecture notes Physics in PDF only on Docsity!

Cornell University Department of Physics

(Due Wed December 16 at 11:59pm sharp.) Goal: DFT calculations of solids!!!

- Physics 4480/7680: Computational Physics, Fall - Problem Set #
  • 1 Minimal, isotropic spectral representation Contents
    • 1.1 “setup.jl”
      • 1.1.1 Radius of inscribed sphere
      • 1.1.2 Debugging
    • 1.2 Operators
      • 1.2.1 L() and K()
      • 1.2.2 cI()
      • 1.2.3 cIdag()
      • 1.2.4 Debugging
  • 2 Full benefit from minimal representation
    • 2.1 getn(), getE(), H()
    • 2.2 H()
  • 3 Calculation of solid Ge
    • 3.1 “setup.jl”
    • 3.2 “Geatoms.jl”
      • 3.2.1 Debugging
  • 4 Optional: Variable fillings and verification of pseudopotential
    • 4.1 getn()
    • 4.2 getE()
    • 4.3 Q()
    • 4.4 getgrad()
      • 4.4.1 Debugging
  • 5 Isolated Ge atom
  • A “Q()”

1 Minimal, isotropic spectral representation

Expanding the wave functions with an appropriate subset of the full set of basis functions reduces the memory and run-time requirements by a factor of about sixteen in the limit of a large calcu- lation. Fortunately, our software design limits all knowledge of the details of the basis set to the operators O(), L(), cI(), cIdag(), cJ(), cJdag(). Thus, modifying our code to take advantage of reducing the basis set requires only modification of the corresponding functions (if needed) and of the initialization file “setup.jl”.

This optimization represents major modifications to your basic operators. Copy all of the current “.jl” files from your “A3b” folder/directory into a new working folder/directory “A4a”.

1.1 “setup.jl”

As discussed in lecture, the active basis functions which we shall use are those contained within a sphere of radius Gn/2, where Gn is the radius of the sphere inscribed within the edges of our Fourier box. Modify “setup.jl” as follows to determine the associated information and communicate it to the rest of the software.

1.1.1 Radius of inscribed sphere

To locate the edges of the Fourier box, insert the following code block immediately after your computation of G2 in “setup.jl”,

Locate edges (assume S’s are even!) and determine max ’ok’ G

if any(rem.(S,2).!=0) error("Odd dimension in S, cannot continue...\n") end eS=@. S/2+0. edges=findall( any( abs.(M-ones(size(M,1),1)*eS’).<1 ,dims=2) )

This block first verifies the assumption that the FFT box sizes are all even. After execution of this code block, edges contains a list of the indices of all rows of M with any element equal to S/2 or S/2+1, namely those with any component of G~ of largest possible absolute value.

Next, to find a list of the active rows of G (those corresponding to wave vectors within the Fourier sphere), first compute the minimum magnitude reciprocal lattice vector along the edges, and then find all vectors with magnitude less than one-half of that minimum magnitude (one-fourth of the square magnitude). To do this, add the code block

Compute active list and corresponding "compressed" list of G2’s

G2mx=minimum(G2[edges]) active=findall(@. G2 out[:,col]= ... # previous code else full=zeros(Complex{Float64},prod(S),1); full[active]=in[:,col] out[:,col]= ... # previous code with "full" replacing "in[:,col]" end

Note that, here and below, “along the lines of” indicates that the names of some variables (especially internal working variables of a function which you designed) in the example may not correspond exactly to those in your routine.

1.2.3 cIdag()

The cIdag() operator now becomes I†^ =

F( 3 )B

= B†F† (3). In this case, it turns out that the output cIdag() is always a wave-function-like object (again, the lack of “nonconformant” errors ultimately confirms this). Therefore, allocate the output using code along the lines of

out=zeros(Complex{Float64},length(active),size(in,2))

Finally, implement the operation B†^

F(3)

using statements along the lines of full= ... # Same operation previously applied to in[:,col] out[:,col]=full[active]

Note that, because the output of cIdag() is always in the reduced, active space, this function requires no if statements in its implementation.

1.2.4 Debugging

Finally, modify your hydrogen calculation in “Hatoms.jl” so that your initial wave-function guess has the correct size corresponding to the number of elements in G2c, and rerun and verify that you reproduce your previous results to within better than 0.005 hartree! The modification to “Hatoms.jl” should involve only changing the initialization of W to that of a random array of size length(active)×Ns. You should also notice a decrease in the iteration time and an improvement in the number of iterations needed to reach convergence. Hints: For debugging the above operators (most bugs will involve various “nonconformant” errors), make liberal use the size() function in your various operators in order to print out the sizes of the relevant objects from within any functions that generate errors.

2 Full benefit from minimal representation

Currently, the wave functions are stored in the minimal representation. However, when transformed to sample values with cI(), as occurs in getE() and H(), the output lives in the full FFT box and consumes an unnecessarily large amount of memory (sixteen times more than is needed), whose allocation and deallocation also tends to slow the calculation. To avoid this, we should apply cI() only to one column of the wave functions at a time. To achieve this, make the following modifications.

2.1 getn(), getE(), H()

function getn(psi,f) Input:

  • psi: expansion coefficients of Ns orthonormal wave functions
  • f: fillings of the orbitals (typically f=2). Return value:
  • n: sample values of electron density, ni = f

k ψ ∗ ikψik

Both getE() and H() compute the electron density with a call to cI() on the wave functions. Rather than updating two nearly identical blocks of code, add a function getn() of the above prototype to “physics.jl” that calculates the density with an explicit loop over the columns of psi rather than using calls to diagouter(). Note that you should not need to use any global variables for this function.

Finally, replace the current expressions which calculate the density n in getE() and H() with calls to getn(). Note that, depending on your implementation, you may have to modify getE() and H() somewhat to first obtain the orthonormal wave functions from the input W. The following statement will do this for you,

Y=Winv(sqrt(W’O(W))) # Orthonormal wave functions

Debugging: Rerun “Hatoms.jl” to convince yourself that the output is identical.

2.2 H()

After the above modifications, the only remaining call of cI() on a wave-function object is in the application of the local potential in H(), in the form cIdag(Diagprod(Vdual+Vsc,cI(C))). Rewrite this contribution to H() using an explicit loop over the columns of C with a code fragment along the lines of

for col=1:size(C,2) out[:,col]+=cIdag( (Vdual+Vsc).*cI(C[:,col]) ) end

Note: You may have used a different code fragment to represent Vsc, the sum of the Hartree and exchange-correlation potentials.

Debugging: Rerun “Hatoms.jl” to convince yourself that the output is unchanged.

the FFT box),

lim G→ 0

4 πZ G^2

e−i G~·~x Vps(~x)

= 4πZ

1 + e−λrc

r^2 c 2

λ^2

π^2 6

∑^ ∞

n=

(−1)n^

e−λrcn n^2

To avoid needless heartache in implementing the above, feel free to simply replace the original computation of Vps in “Geatoms.jl”,

Vps=-4piZ./G2; Vps[1]=0.

with the Julia form for the pseudopotential:

Ge pseudopotential

Z= lambda=18. rc=1. Gm=sqrt.(G2) Vps=@. -2piexp(-piGm/lambda)cos(Gmrc)(Gm/lambda)/(1-exp(-2piGm/lambda)) for n=0: global Vps=@. Vps+(-1)^nexp(-lambdarcn)/(1+(nlambda/Gm)^2) end Vps=@. Vps4piZ/Gm^2(1+exp(-lambdarc))-4pi*Z/Gm^

n=[i for i=1:4] Vps[1]=4piZ(1+exp(-lambdarc))(rc^2/2+1/lambda^2(pi^2/ +sum((-1).^n.exp.(-lambdarc*n)./n.^2)))

Finally, to allow for viewing of the total charge density, add the code block below to the very end of “Geatoms.jl” (deleting or commenting out any statements that may remain in your code for viewing individual wave functions).

Compute density for final viewing

Y=Winv(sqrt(W’O(W))) # Orthonormal wave functions n=getn(Y,gbl_f) # Charge density

Basic slice from ‘‘100’’ edge of cell

sl=reshape(n[1:S[1]*S[2]],S[1],S[2])

Make and view image

heatmap(sl); savefig("100.jpg"); println("Hit "); readline()

110 slice cutting bonds (assumes cube)

sl=reshape(n[findall(M[:,2].==M[:,3])],S[1],S[2])

Make and view image

heatmap(sl); savefig("110l.jpg"); println("Hit "); readline()

Drop data to restore (approximate) aspect ratio

li=findall(mod.([i for i=1:size(sl,1)],3).!=0); sl=sl[li,:]

Make and view image

heatmap(sl); savefig("110.jpg"); println("Hit "); readline()

3.2.1 Debugging

Run “Geatoms.jl”. The code should display and save three graphics files “100.jpg”, “110l.jpg”, “110.jpg”. The graphics each show a brightness and a color proportional to the total charge density at each point in a plane cutting through the solid. The first graphic (“100.jpg”) shows a slice across the top of the cubic cell. The atoms should appear as rings of round charge distributions with low density (dark regions) centered on the nuclei. The reason why there are no electrons on the nuclei is that we are using a pseudopotential and are not computing the core electrons. You should see one atom in the center of the 100 slice and four atoms cut off at the corners. This reflects the basic faced-centered cubic (fcc) structure of the germanium crystal. The second and third graphics (“110l.jpg” and “110.jpg”) are more exciting. These cuts slice through the centers of neighboring atoms, showing significant buildup of charge right in between them. These are the bonds which hold the crystal together!!! (The first slice “110l.jpg” show the raw data, whereas the second slice is more accurate to the actual aspect ratio of the unit cell.)

Next, run “ewald.jl”, and compute the total energy per atom of the crystal. (We find an Ewald energy of -31.9038 H and an electronic energy of 1.0561 H – you may wish to run more minimization iterations using ‘pccg(Y,30,1)’ to get a more accurate electronic energy.)

Finally, compare your results to the total energy of the pseudoatom calculated at the same spatial resolution, -3.7301 H. (See Section 5 if you’d like to compute this for yourself.) Finally, using the conversion 1 hartree=27.21 eV, compute your prediction for the cohesive energy of germanium, the energy gained by bringing atoms together to form the solid. You should find agreement with the experimental value for Ge (3.85 eV/atom) to within about 10%, which is truly remarkable given that you have computed this value for yourself from first principles!!!

of the electron density and associated terms. The calculation of the kinetic energy, however, must change. In our matrix language, the new expression is

T = −

Tr

(Diag f~ )

Y †LY

where Y is the matrix of expansion coefficients for the orthonormal wave functions. Change getE() to reflect this change. Hint: The extra parentheses in the above expression limit the size of and number computations required in evaluating intermediate expressions.

4.3 Q()

Copy the function Q() from Appendix A into “physics.jl”. This function evaluates an operator

which is needed for the expression for the gradient in the general case of non-constant f~. Note that the subscript “U ” to the operator “QU (X)” in Eq. (3) below is sent as the second argument to the function. (To understand the function, type ‘?Q’ at the Julia prompt after compiling with ‘include("physics.jl")’. You may need to first run “Geatoms.jl” in your new folder to have all needed libraries loaded for the compilation.)

4.4 getgrad()

function getgrad(W) Input:

  • W: Expansion coefficients for Ns unconstrained wave functions, stored as an

Sk × Ns matrix Output:

  • grad:

Sk × Ns matrix containing the derivatives ∂E/∂W (^) α,i∗ ≡ [∇W † E]α,i Global variable:

  • gbl f: State fillings stored as an Ns × 1 column vector.

Modify getgrad() as above to employ the appropriate formula for the case of variable fillings,

∇W † E =

H(W ) − O(W )U −^1

W †H(W )

U −^

(^12) F U −^

+ O(W )

U −^

(^12) QU ( HF˜ − F H˜)

where U ≡ W †O(W ), H˜ ≡ U −^

W †H(W )

U −^

(^12) , F ≡ Diag f~ , and QU (A) is the operator which the function in Appendix A computes.^1 Note that the parentheses have been arranged here again to minimize the size and cost of the calculation of intermediate expressions and that U −^ (^12) may be computed in Julia as sqrt(inv(U)). (Don’t use a ‘.’ with the sqrt: sqrt calculates the actual matrix square root that we need, as opposed to simply taking the square root of each element of the matrix.)

(^1) We will derive this expression on the last day of class, if there is time. You may verify for yourself that if f~ is constant, this reduces to your current expression.

4.4.1 Debugging

For basic debugging, delete the statement “gbl f=2;” from “Geatoms.jl” and add the statement

gbl_f=2*ones(Ns,1) # Constant fillings as a vector

just after the definition of Ns in “Geatoms.jl”. Rerun “Geatoms.jl” and verify that your output is as it was before.

5 Isolated Ge atom

As a non-trivial test of your variable fillings code, and to compute the energy (given in Section 3.2.1) of an isolated Ge atom at the same resolution as your solid state calculation, set the parameter X=a*[0.00 0.00 0.00] in “setup.jl” and the parameters Ns=4 and gbl f=[2;2/3;2/3;2/3] in “Geatoms.jl”, and rerun “setup.jl” and “ewald.jl” and “Geatoms.jl”. Passing the finite-difference test should be sufficient to verify your new code, and summing the resulting Ewald and electronic energies should give the value of for an isolated Ge atom that we quoted in Section 3.2.1.

Finally, as (partial) verification that the pseudopotential indeed gives states which correspond to the valence states of the germanium atom, compare your results for the s-p energy difference (the energy difference between the s and p states of the atom) with those either from your d = 1 dimensional atomic code, or equivalently, from the table at NIST.^2 To see your results for the s and p energies, add the statements

(Psi,epsilon)=getPsi(Y) println("Eigenvalues=",epsilon)

at the end of “Geatoms.jl” and rerun. (Note that only the 4s-4p energy difference here is physical because of the arbitrary choice in zero in the definition of potential energy.) You should find agreement to within about 3 mH!

(^2) math.nist.gov/DFTdata/atomdata/tables/ptable.html.