next up previous contents
Next: Debugging Up: Putting it all together Previous: Putting it all together

``test_atoms.c''

Write a main program which attains self-consistency with the algorithm,

where tex2html_wrap_inline442 is any value between 0 and 1.

Note that if tex2html_wrap_inline446 , Rho tex2html_wrap_inline436 =Rhonew, and we are just putting the output charge density back in as the input, and iterating. This process, however, often is unstable because the electron density Rho changes too quickly. Taking tex2html_wrap_inline450 helps calm this instability by changing Rho more slowly. For instance, for tex2html_wrap_inline452 (which seems to work in most cases), we are ``mixing'' 75% of the previous estimate of Rho with 25% of the new estimate.

Finally, to monitor the progress of your program, you should have it print out the total energy at each iteration. A suitable code fragment for computing this is

                        .
                        .
      /* Compute and output total energy */

      /* Get correction to sum of electron energies */
      getDepsxc(Depsxc,Rho,r,dr,N);
      for (k=0; k<=N; k++)
        integrand[k]=(-0.5*phi[k]+Depsxc[k])*Rho[k];
      Etot=simpint(integrand,r,dr,N);

      /* Add on the sum of the electron energies times the occupancies */
      for (l=0; l<=lmax; l++)
        for (n=0; n<=nmax[l]; n++)
          Etot+=F[l][n]*E[l][n];
      
      printf("Etot: %20.15f\n",Etot);
                        .
                        .
Note that, because, your solution is converging (hopefully!) and all the quantities eventually stop changing, it doesn't really matter if you use Rho[] or Rhonew[] or if you compute phi[] from Rho[] or Rhonew[] in the above code fragment.





Tomas Arias
Sat Mar 3 19:45:19 EST 2001