Example #1
0
void  paw_end_LogGrid()
{
    paw_dealloc_LogGrid(rgrid);
    paw_dealloc_LogGrid(rgrid2);
    paw_dealloc_LogGrid(rgrid3);
    paw_dealloc_LogGrid(scratch);
}
Example #2
0
/****************************************
 Function name    : paw_generate_pseudopot
 Description        :
 Return type              : void
 Author                   : Marat Valiev
 Date & Time              : 4/10/99 7:40:00 PM
****************************************/
void paw_generate_pseudopot()
{

    int   k;
    int   Ngrid;
    double charge;
    double ps_charge;
    double Z;
    double *Vh;
    double *Vx;
    double *Vc;
    double *rho;
    double *rho_ps;
    double *rho_core;
    double *rho_core_ps;
    double *full_density;
    double *full_ps_density;
    double* V_comp;
    double *rgrid;
    FILE *fp;
    char data_filename[300];

    if ( !(paw_projectors_are_done()) )
    {
        printf("error, pseudopotential cannot be generated ");
        printf(" because projectors have not been yet \n");
        exit(1);
    }

    Ngrid = paw_N_LogGrid();
    rgrid = paw_r_LogGrid();

    Vh      = paw_alloc_LogGrid();

    Vx      = paw_alloc_LogGrid();
    Vc      = paw_alloc_LogGrid();

    full_density = paw_alloc_LogGrid();
    full_ps_density = paw_alloc_LogGrid();

    Z = paw_get_ion_charge();

    paw_set_core();

    /*get densities*/
    rho         = paw_get_pointer_paw_density();
    rho_ps      = paw_get_pointer_paw_ps_density();
    rho_core    = paw_get_pointer_core_density();
    rho_core_ps = paw_get_pointer_ps_core_density();

    paw_Zero_LogGrid(full_density);
    paw_Zero_LogGrid(full_ps_density);

    for (k=0;k<=Ngrid-1;k++)
    {
        full_density[k]    = rho[k] + rho_core[k];
        full_ps_density[k] = rho_ps[k] + rho_core_ps[k];

    }

    charge   = paw_Integrate_LogGrid(full_density);
    ps_charge      = paw_Integrate_LogGrid(full_ps_density);


    V_comp = paw_find_comp_charge_potential(Z,charge,ps_charge);

    paw_generate_hartree_pot(full_ps_density);
    Vh = paw_get_hartree_pot();

    paw_generate_exchange_pot_LDA(full_ps_density);
    Vx = paw_get_exchange_potential();

    paw_generate_corr_pot_LDA(full_ps_density);
    Vc = paw_get_corr_pot_LDA();


    /*form pseudopotential*/
    for (k=0;k<=Ngrid-1;k++)
    {

        V_pseudo[k] = V_ref[k] - Vh[k]- V_comp[k]- Vc[k] - Vx[k];



    }

    if (paw_debug())
    {
        sprintf(data_filename,"%sdensity",paw_sdir());
        fp = fopen(data_filename,"w");

        for (k=0;k<Ngrid;++k)
            fprintf(fp,"%f  %f   %f\n",rgrid[k],rho[k] - rho_ps[k],V_pseudo[k]);
        fclose(fp);
    }

    paw_dealloc_LogGrid(full_density);
    paw_dealloc_LogGrid(full_ps_density);

}
Example #3
0
/****************************************
 Function name	  : solve_pseudo_orbitals
 Description	    :
 Return type		  : void
 Author     		  : Marat Valiev
 Date & Time		  : 4/7/99 2:31:16 PM
****************************************/
void paw_generate_pseudo_orbitals()
{
    int     i;
    int     k;
    int Ngrid;
    int     max_iter;
    int     converged;
    int     iteration;
    int     match;
    int     status;
    double log_amesh;
    double f1,f2;
    double  *V;
    double  *rgrid;
    double  *f;
    double norm;

    char    output[300];
    FILE   *fp;

    Ngrid     = paw_N_LogGrid();
    rgrid     = paw_r_LogGrid();
    log_amesh = paw_log_amesh_LogGrid();

    /*set maximum number of iterations*/
    max_iter = 600;

    for (i = 0; i <= nbasis-1; i++)
    {
        iteration = 0;
        converged = False;
        status    = False;
        match = i_r_orbital[i];

        /*Start the selfconsistent loop over given ps state */

        while ((iteration <= max_iter) && (!converged))
        {
            ++iteration;

            /* get pseudopotential*/
            V = paw_get_paw_potential(i);

            /*
            if(orb_type[i]==bound || orb_type[i]==virt)
            {
              status = paw_R_Schrodinger(prin_n_ps[i], 
                orb_l[i], 
                V, 
                &e_ps[i], 
                phi_ps[i], 
                phi_ps_prime[i]);
              
            }
            else if(orb_type[i]==scattering)
            {
              status = paw_R_Schrodinger_Fixed_Logderiv(prin_n_ps[i], 
                orb_l[i], 
                V, 
                match,      
                log_deriv[i],
                &e_ps[i], 
                phi_ps[i], 
                phi_ps_prime[i]);
                  
            }
            else
            {
              printf("unknown orbital type\n");
              exit(1);
            }
            */

            status = paw_R_Schrodinger_Fixed_Logderiv(prin_n_ps[i],
                     orb_l[i],
                     V,
                     match,
                     log_deriv[i],
                     &e_ps[i],
                     phi_ps[i],
                     phi_ps_prime[i]);

            /*Update pseudopotential potential*/
            paw_update_paw_potential(&converged, i, e[i], e_ps[i],phi_ps[i]);

        }

        /*report on convergence status*/
        if (converged && (status))
        {
            if (paw_debug()) printf("\n%d%d pseudo orbital with the eigenvalue=%f has been found\n",
                                        prin_n[i], orb_l[i], e_ps[i]);
        }
        else
        {
            if (paw_debug()) printf("Unable to find %d%d orbital\n ",
                                        prin_n[i], orb_l[i]);
        }

        norm = phi[i][match]/phi_ps[i][match];

        /*scale ps orbital */
        for (k=0;k<=match;k++)
        {
            phi_ps[i][k]=phi_ps[i][k]*norm;
            phi_ps_prime[i][k]=phi_ps_prime[i][k]*norm;
        }


        for (k=match+1;k<=Ngrid-1;k++)
        {
            phi_ps[i][k]=phi[i][k];
            phi_ps_prime[i][k]=phi_prime[i][k];
        }


    }





    if (paw_debug())
    {
        for (i = 0; i <= nbasis-1; ++i)
        {
            sprintf(output, "%s%s%d%d", paw_sdir(),"test",prin_n[i],orb_l[i]);
            fp = fopen(output, "w+");
            for (k = 0; k < Ngrid; k++)
            {
                fprintf(fp, "%f\t%f\t%f\n", rgrid[k], phi[i][k],phi_ps[i][k]);

            }
            fclose(fp);
        }
    }

    pseudo_orbitals_done = True;

    /* save original basis functions */
    for (i=0;i<=nbasis-1;i++)
    {
        for (k = 0; k <= Ngrid-1; k++)
        {
            phi0[i][k] = phi[i][k];
            phi0_prime[i][k] = phi_prime[i][k];
            phi_ps0[i][k] = phi_ps[i][k];
            phi_ps0_prime[i][k] = phi_ps_prime[i][k];
        }

    }

    /* calculate densities */
    paw_Zero_LogGrid(rho);
    paw_Zero_LogGrid(rho_ps);

    for (i = 0; i <= nbasis-1; i++)
    {
        for (k = 0; k <= Ngrid-1; k++)
        {
            rho[k] += fill[i]*pow((phi0[i][k]/rgrid[k]),2.0);
            rho_ps[k] += fill[i]*pow((phi_ps0[i][k]/rgrid[k]),2.0);
        }
    }

    /*calculate kinetic energy*/
    ekin    = paw_get_kinetic_energy(nbasis, orb_l, fill, phi, phi_prime);

    f = paw_alloc_LogGrid();

    for (i = 0; i <= nbasis-1; i++)
    {

        for (k=0; k<=Ngrid-1; k++)
        {
            f[k] = 0.5*phi_prime[i][k]/(rgrid[k]*log_amesh)*
                   phi_prime[i][k]/(rgrid[k]*log_amesh) -
                   0.5*phi_ps_prime[i][k]/(rgrid[k]*log_amesh)*
                   phi_ps_prime[i][k]/(rgrid[k]*log_amesh);
        }

        f1 = paw_Def_Integr(0.0,f,0.0,Ngrid-1);

        for (k=0; k<=Ngrid-1; k++)
        {
            f[k] = 0.5*phi_prime[i][k]/(rgrid[k]*log_amesh)*
                   phi_prime[i][k]/(rgrid[k]*log_amesh);
        }

        f2 = paw_Def_Integr(0.0,f,0.0,Ngrid-1);

        delta_ekin[i] = (int)(100*f1/f2);

        if (paw_debug())
            printf("kinetic energy of the %d%s orbital was reduced by %d%s\n",
                   prin_n[i],paw_spd_Name(orb_l[i]),delta_ekin[i],"%");
    }

    paw_dealloc_LogGrid(f);

}
Example #4
0
void paw_end_paw_basis()
{
    int i;


    for (i = 0; i < nbasis; ++i)
    {
        paw_dealloc_LogGrid(phi0[i]);
        paw_dealloc_LogGrid(phi[i]);
        paw_dealloc_LogGrid(phi_prime[i]);

        paw_dealloc_LogGrid(phi_ps0[i]);
        paw_dealloc_LogGrid(phi_ps[i]);
        paw_dealloc_LogGrid(phi_ps_prime[i]);

        paw_dealloc_LogGrid(phi_ps0_prime[i]);

        paw_dealloc_LogGrid(phi0_prime[i]);

        paw_dealloc_LogGrid( prj_ps[i]);
        paw_dealloc_LogGrid(prj_ps0[i]);

        paw_dealloc_LogGrid(psi_ps[i]);
        paw_dealloc_LogGrid( psi_ps_prime[i]);
    }
    free(phi);
    free(phi0);
    free(phi_prime);
    free(phi_ps0);
    free(phi_ps0_prime);
    free(phi0_prime);
    free(phi_ps);
    free(phi_ps_prime);
    free(prj_ps);
    free(prj_ps0);
    free(psi_ps);
    free(psi_ps_prime);


    free(delta_ekin);
    free(orb_type);
    free(prin_n_ps);
    free(prin_n);
    free(orb_l);
    free(l_counter);
    free(i_r_orbital);
    free(r_orbital);
    free(fill);
    free(e);
    free(e_ps);
    free(log_deriv);

    paw_dealloc_LogGrid(rho);
    paw_dealloc_LogGrid(rho_ps);

}
Example #5
0
/****************************************
 Function name	  :  paw_solve_occupied_orbitals
 Description	    :
 Return type		  : void
 Author     		  : Marat Valiev
 Date & Time		  : 4/10/99 6:13:22 PM
****************************************/
void   paw_solve_occupied_orbitals()
{
    int   i;
    int   j;
    int  k;
    int  it;
    int  converged;
    int   Ngrid;
    int   max_iter;
    double sum;
    double Etmp;
    double thl;
    double sn;
    double sd;
    double dr;
    double rl0;
    double rl1;
    double vn;
    double Zion;
    double *Vo;
    double *Vo1;
    double *Vi1;
    double *Vi;
    double *rgrid;

    max_iter = 100;

    Ngrid = paw_N_LogGrid();
    rgrid = paw_r_LogGrid();

    /* allocate temporary grids */
    Vi      = paw_alloc_LogGrid();
    Vo1     = paw_alloc_LogGrid();
    Vi1     = paw_alloc_LogGrid();

    /* set initial guess for KS potential as Thomas-Fermi*/
    Zion = paw_get_ion_charge();
    paw_Thomas_Fermi(Zion,Vi);

    /*initial guess for the eigenvalues*/
    paw_guess_eigenvalues(Zion,Vi);

    it = 0;
    converged = False;
    while ((!converged) && (it < max_iter))
    {

        it        = it + 1;
        converged = True;

        /* solve for each of the eigenstates */
        for (i=0; i<= Nvalence-1; i++)
        {

            Etmp = eigenvalue[i];

            if (Solver_Type==Schrodinger)
            {
               paw_R_Schrodinger(n[i],l[i],Vi,
                                 &Etmp,psi[i],psi_prime[i]);
            }
            else
            {
               paw_R_Pauli(n[i],l[i],Zion,Vi,
                           &Etmp,psi[i],psi_prime[i]);
            }

            if (fabs(eigenvalue[i] - Etmp) >1.0e-10)
                converged = False;

            eigenvalue[i]=Etmp;


            /*orthogonalize to lower orbitals*/
            for (j=0;j<=i-1;j++)
            {
                if (l[i]==l[j])
                {
                    sum = paw_dot_product(psi[i],psi[j]);
                    for (k=0;k<Ngrid;++k)
                        psi[i][k] = psi[i][k] - sum*psi[j][k];
                }

            }

            /*normalize the orbital*/
            for (k=0; k<=Ngrid-1; k++)
                psi_tmp[k] = pow((psi[i][k]/rgrid[k]),2.0);

            sum = paw_Integrate_LogGrid(psi_tmp);

            for (k=0; k<=Ngrid-1; k++)
                psi[i][k]=psi[i][k]/pow(sum,0.5);

        }

        /*get new density*/
        paw_generate_density(rho);

        /*get new potential*/
        paw_set_kohn_sham_potential(rho);
        Vo = paw_get_kohn_sham_potential();


        /*****************************************/
        /* Generate the next iteration potential */
        /* using D.G. Anderson method            */
        /*****************************************/
        thl = 0.0;
        if (it > 1)
        {
            sn = 0.0;
            sd = 0.0;

            for (k=0; k<Ngrid; ++k)
            {
                rl0 = Vo[k]  - Vi[k];
                rl1 = Vo1[k] - Vi1[k];
                dr  = rl0 - rl1;
                sn = sn + rl0*dr*(rgrid[k]*rgrid[k]);
                sd = sd +  dr*dr*(rgrid[k]*rgrid[k]);
            }


            thl = sn/sd;

        }

        for (k=0; k<=Ngrid-1; k++)
        {

            vn = (1.0-0.5)*( (1.0-thl)*Vi[k] + thl*Vi1[k] )
                 + 0.5 *( (1.0-thl)*Vo[k] + thl*Vo1[k] );
            Vi1[k] = Vi[k];
            Vo1[k] = Vo[k];
            Vi[k]  = vn;

        }


    } /* end while */

    if (!converged)
    {
        printf("Not Converged\n");
        exit(1);
    }

    occupied_orbitals_done = True;
    paw_generate_density(rho);
    paw_set_kohn_sham_potential(rho);



    /* free up temporary memory */
    paw_dealloc_LogGrid(Vi);
    paw_dealloc_LogGrid(Vo1);
    paw_dealloc_LogGrid(Vi1);

}
Example #6
0
void paw_R_Schrodinger_Fixed_E1(
    int l,
    double *v,
    double *f,
    int match,
    double E,
    double *u,
    double *uprime
)
{
    int     i,j,
    Ngrid;

    double  log_amesh,
    log_amesh2,
    gamma,
    L2,
    r2,
    *r,
    *f_upp,
    *upp;

    double max_u;

    /*set maximum allowed value for u*/
    max_u = 10000000;

    /* define power of the orbital near 0 */
    gamma = ((double) (l+1));

    /* define square of the angular momentum */
    L2    = ((double) (l*(l+1)));

    /* define log grid parameters */
    Ngrid      = paw_N_LogGrid();
    log_amesh  = paw_log_amesh_LogGrid();
    log_amesh2 = log_amesh*log_amesh;

    if (match > Ngrid-1)
    {
        printf("match point is outside the allowed region\n");
        printf("abborting the program\n");
        exit(1);
    }
    /* get pointer rgrid, and extra memory */
    r     = (double *) paw_r_LogGrid();
    f_upp = (double *) paw_alloc_LogGrid();
    upp   = (double *) paw_alloc_LogGrid();

    for (i=0; i<=match; i++)
    {
        u[i]      = 0.0;
        uprime[i] = 0.0;
    }

    /* define f_upp */
    for (i=0; i<match+1; ++i)
    {
        r2 = r[i]*r[i];
        f_upp[i] = log_amesh2*(L2 + 2.0*(v[i] - E)*r2);
    }

    for (i=0; i<4; ++i)
    {
        u[i]      = pow(r[i],gamma);
        uprime[i] = log_amesh*gamma*u[i];
        upp[i]    = log_amesh*uprime[i] + f_upp[i]*u[i];
    }

    /* integrate from 0 to match */
    i=3;
    while (i<match && fabs(u[i])<max_u)
    {
        /* predictors */
        u[i+1]      = paw_Predictor_Out(i,u,uprime);
        uprime[i+1] = paw_Predictor_Out(i,uprime,upp);

        /* correctors */
        for (j=0; j<Corrector_Iterations; ++j)
        {
            upp[i+1]    = log_amesh*uprime[i+1] + f_upp[i+1]*u[i+1]- 2.0*log_amesh2*r[i+1]*r[i+1]*f[i+1];
            uprime[i+1] =  paw_Corrector_Out(i,uprime,upp);
            u[i+1]      =  paw_Corrector_Out(i,u,uprime);
        }

        i = i+1;
    }


    /* dealloc memory */
    paw_dealloc_LogGrid(upp);
    paw_dealloc_LogGrid(f_upp);

    return;

} /* paw_R_Schrodinger */
Example #7
0
int paw_R_Schrodinger_Fixed_Logderiv1(
    int n,
    int l,
    double *v,
    int match,
    double u_logderiv,
    double *Eig,
    double *u,
    double *uprime
)

{
    int     i;
    int     j;
    int     iteration;
    int     Ngrid;

    double  sum;
    double  E;
    double  de;
    double  Emax;
    double  Emin;
    double  log_amesh;
    double  log_amesh2;
    double  gamma;
    double  L2;
    double  r2;
    double  uout;
    double  upout;
    double  upin;
    double  *r;
    double  *f_upp;
    double  *upp;

    /* define eigenvalues */
    E     = *Eig;

    /* define power of the orbital near 0 */
    gamma = ((double) (l+1));

    /* define square of the angular momentum */
    L2    = ((double) (l*(l+1)));

    /* define log grid parameters */
    Ngrid      = paw_N_LogGrid();
    log_amesh  = paw_log_amesh_LogGrid();
    log_amesh2 = log_amesh*log_amesh;

    /* get pointer rgrid, and extra memory */
    r     = (double *) paw_r_LogGrid();
    f_upp = (double *) paw_alloc_LogGrid();
    upp   = (double *) paw_alloc_LogGrid();

    /* set up bounds for eigenvalue */
    Emax = E + 10.0;
    Emin = E - 10.0;


    iteration = 0;
    while (iteration < Max_Iterations)
    {
        ++iteration;
        /* define f_upp */
        for (i=0; i<Ngrid; ++i)
        {
            r2 = r[i]*r[i];
            f_upp[i] = log_amesh2*(L2 + 2.0*(v[i] - E)*r2);
        }


        /* set the boundry condition near zero */
        for (i=0; i<4; ++i)
        {
            u[i]      = pow(r[i],gamma);
            uprime[i] = log_amesh*gamma*u[i];
            upp[i]    = log_amesh*uprime[i] + f_upp[i]*u[i];
        }


        /* integrate from 0 to match */
        for (i=3; i<match; ++i)
        {
            /* predictors */
            u[i+1]      = paw_Predictor_Out(i,u,uprime);
            uprime[i+1] = paw_Predictor_Out(i,uprime,upp);

            /* correctors */
            for (j=0; j<Corrector_Iterations; ++j)
            {
                upp[i+1]    = log_amesh*uprime[i+1] + f_upp[i+1]*u[i+1];
                uprime[i+1] =  paw_Corrector_Out(i,uprime,upp);
                u[i+1]      =  paw_Corrector_Out(i,u,uprime);
            }

        }


        uout  = u[match];
        upout = uprime[match];


        upin = u_logderiv*uout;

        /* Find Integral(u^2) */
        sum = paw_Norm_LogGrid(match,gamma,u);

        sum = 1.0/sqrt(sum);
        uout  = sum*uout;
        upout = sum*upout;
        upin  = sum*upin;

        for (i=0; i<=match; ++i)
        {
            u[i]      = sum*u[i];
            uprime[i] = sum*uprime[i];
        }

        for (i=match+1; i<Ngrid; ++i)
        {
            u[i]      = 0.0;
            uprime[i] = 0.0;
        }

        /* figure out new eigenvalue */
        de = 0.5*uout*(upout-upin)/(log_amesh*r[match]);

        /* eigenvalue is converged, exit */
        if (fabs(de) <  (Max(fabs(E),0.2)*tolerance))
        {
            *Eig  = E;

            /* dealloc memory */
            paw_dealloc_LogGrid(upp);
            paw_dealloc_LogGrid(f_upp);
            return True;
        }

        if (de > 0.0)
            Emin = E;
        else
            Emax = E;

        E = E + de;

        if ( (E > Emax) || (E < Emin))
            E = 0.5*(Emin+Emax);

    } /* while */

    printf("paw_Error R_Schrodinger_Fixed_Logderiv: More than %d iterations\n",
           Max_Iterations);
    *Eig = E;


    /* dealloc memory */
    paw_dealloc_LogGrid(upp);
    paw_dealloc_LogGrid(f_upp);

    return False;

} /* paw_R_Schrodinger_Fixed_LogDeriv */
Example #8
0
int paw_R_Schrodinger(int n,
                      int l,
                      double* v,
                      double *Eig,
                      double* u,
                      double* uprime)
{
    int     i,j,
    iteration,
    node,
    match,
    Ninf, Ngrid;

    double  E, de,
    Emax,
    Emin,
    log_amesh,
    log_amesh2,
    gamma,
    L2,
    sum, a, scale, m1scale,
    uout,upout,upin,
    *r,
    *f_upp,
    *r2,
    *upp;

    /* define eigenvalues */
    E     = *Eig;
    gamma = ((double) (l+1));
    L2    = ((double) (l*(l+1)));

    /* define log grid parameters */
    Ngrid      = paw_N_LogGrid();
    log_amesh  = paw_log_amesh_LogGrid();
    log_amesh2 = log_amesh*log_amesh;

    /* get pointer rgrid, and extra memory */
    r     = paw_r_LogGrid();
    r2    = paw_r2_LogGrid();
    f_upp = paw_alloc_LogGrid();
    upp   = paw_alloc_LogGrid();


    /* set up bounds for eigenvalue */
    Emin = 0.0;
    Emax = v[Ngrid-1]  + 0.5*L2/(r[Ngrid-1]*r[Ngrid-1]);

    for (i=0; i <= Ngrid-1; i++)
        Emin = Min(Emin, (v[i] + 0.5*L2/r2[i]));


    if (E > Emax) E = 1.25*Emax;
    if (E < Emin) E = 0.75*Emin;
    if (E > Emax) E = 0.5*(Emax+Emin);

    iteration = 0;
    while (iteration < Max_Iterations)
    {
        ++iteration;

        /* define f_upp */
        for (i=0; i<Ngrid; ++i)
            f_upp[i] = log_amesh2*(L2 + 2.0*(v[i] - E)*r2[i]);

        /* classical turning point is used for matching  */
        match = Ngrid-1;
        while (f_upp[match-1]*f_upp[match] > 0.0)
        {
            match = match - 1;

            if (match < 2)
            {
                printf("Error in paw_R_Schrodinger: no turning point\n");
                return False;
            }
        }


        /* set the boundry condition near zero */
        m1scale = 1.0;
        for (i=0; i<(n-l-1); ++i)
            m1scale *= -1.0;
        for (i=0; i<=3; i++)
        {
            u[i]      = m1scale*pow(r[i],gamma);
            uprime[i] = log_amesh*gamma*u[i];
            upp[i]    = log_amesh*uprime[i] + f_upp[i]*u[i];
        }

        /* integrate from 0 to match */
        node = 0;
        for (i=3; i <= match-1; i++)
        {
            /* predictors */
            u[i+1]      = paw_Predictor_Out(i,u,uprime);
            uprime[i+1] = paw_Predictor_Out(i,uprime,upp);

            /* correctors */
            for (j=0; j<= Corrector_Iterations-1; j++)
            {
                upp[i+1]    = log_amesh*uprime[i+1] + f_upp[i+1]*u[i+1];
                uprime[i+1] =  paw_Corrector_Out(i,uprime,upp);
                u[i+1]      =  paw_Corrector_Out(i,u,uprime);
            }

            /* finding nodes */
            if (u[i+1]*u[i] <= 0) node = node + 1;
        }

        uout  = u[match];
        upout = uprime[match];

        /* not enough nodes in u */
        if ((node-n+l+1) < 0)
        {
            Emin = E;
            E    = 0.5*(Emin+Emax);
        }
        /* too many nodes in u */
        else if ((node-n+l+1) > 0)
        {
            Emax = E;
            E    = 0.5*(Emin+Emax);
        }
        /* number of nodes ok, start integration inward */
        else
        {

            /* find infinity

            */
            /* find infinity */
            Ninf = match + floor(2.3/log_amesh);
            if ((Ninf+5) > Ngrid) Ninf = Ngrid - 5;

            /* define boundry near infinity */
            a = sqrt( L2/(r[Ninf]*r[Ninf]) + 2.0*(v[Ninf]-E) );
            for (i=Ninf; i<=(Ninf+4); i++)
            {
                u[i]      = exp(-a*(r[i]-r[Ninf]));
                uprime[i] = -r[i]*log_amesh*a*u[i];
                upp[i]    = log_amesh*uprime[i] + f_upp[i]*u[i];
            }

            /* integrate from infinity to match */
            for (i=Ninf; i>=(match+1); --i)
            {
                /* predictors */
                u[i-1]      = paw_Predictor_In(i,u,uprime);
                uprime[i-1] = paw_Predictor_In(i,uprime,upp);

                /* Correctors */
                for (j=0; j<Corrector_Iterations; ++j)
                {
                    upp[i-1]    = log_amesh*uprime[i-1] + f_upp[i-1]*u[i-1];
                    uprime[i-1] =  paw_Corrector_In(i,uprime,upp);
                    u[i-1]      =  paw_Corrector_In(i,u,uprime);
                }
            }

            /* make the outside u, match the inside u */
            scale = uout/u[match];
            for (i=match; i<= Ninf; i++)
            {
                u[i]      = scale*u[i];
                uprime[i] = scale*uprime[i];
            }
            upin = uprime[match];

            /* Find Integral(u^2) */
            sum = paw_Norm_LogGrid(Ninf,gamma,u);


            sum = 1.0/sqrt(sum);
            uout  = sum*uout;
            upout = sum*upout;
            upin  = sum*upin;

            for (i=0; i<=Ninf; i++)
            {
                u[i]      = sum*u[i];
                uprime[i] = sum*uprime[i];
            }


            /* figure out new eigenvalue */
            de = 0.5*uout*(upout-upin)/(log_amesh*r[match]);

            /* eigenvalue is converged, exit */
            if (fabs(de) <  (Max(fabs(E),0.2)*tolerance))
            {
                *Eig  = E;

                for (i=Ninf+1; i<Ngrid; ++i)
                {

                    u[i]      = u[Ninf]*exp(-a*(r[i]-r[Ninf]));
                    uprime[i] = -r[i]*log_amesh*a*u[i];

                }

                /* dealloc memory */
                paw_dealloc_LogGrid(upp);
                paw_dealloc_LogGrid(f_upp);
                return True;
            }

            if (de > 0.0)
                Emin = E;
            else
                Emax = E;
            E = E + de;
            if (Emax<=Emin)
            {

                /* dealloc memory */
                paw_dealloc_LogGrid(upp);
                paw_dealloc_LogGrid(f_upp);
                *Eig = E;
                return False;

            }

            if ( (E > Emax) || (E < Emin))
                E = 0.5*(Emin+Emax);

        } /* nodes ok */
    } /* while */

    printf("Error paw_R_Schrodinger: More than %d iterations\n",Max_Iterations);
    *Eig = E;

    /* dealloc memory */
    paw_dealloc_LogGrid(upp);
    paw_dealloc_LogGrid(f_upp);

    return False;

} /* paw_R_Schrodinger */