Exemplo n.º 1
0
def f(a):
    print "Evaluating a =", a
    print "Mesh parameters:"
    print "r_min =", r_min
    print "r_max =", r_max
    print "a =", a
    print "N =", N
    r = mesh_log(r_min, r_max, a, N)
    print r


    # Potential:
    vr = -Z/r

    # Speed of light taken from:
    # http://arxiv.org/abs/1012.3627
    #c = 137.035999037

    # Elk value:
    c  = 137.035999679

    # Polynomial degree for predictor-corrector:
    np = 4

    tot_error = -1
    # (n, l):
    # either k == l, or k == l + 1:
    for n in range(1, 7):
        for l in range(0, n):
            k_list = []
            if l > 0:
                k_list.append(l)
            k_list.append(l+1)

            for k in k_list:
                # Initial guess:
                E = -1.0
                E, g, f = rdirac(c, n, l, k, np, r, vr, E)
                E_exact = E_nl_dirac(n, l, spin_up=(k == l+1), Z=Z, c=c)
                delta = abs(E-E_exact)
                if delta > tot_error:
                    tot_error = delta
                print ("(n=%d, l=%d, k=%d): E_calc=%12.6f    E_xact=%12.6f    " + \
                                                        "delta=%9.2e") % (n, l, k, E, E_exact, delta)
    print "tot_error = ", tot_error

    return tot_error
Exemplo n.º 2
0
def f(a):
    assert len(a) == 1
    a = a[0]
    print "Evaluating a =", a
    # Mesh:
    #r = create_hyperbolic_grid(rmin=5e-8, rmax=20, k0=30000)
    #r = create_log_mesh(a=1e-5, b=100, par=10000, n_elem=10000)
    r = mesh_log(r_min=1e-8, r_max=50, a=a, N=1000)

    # Potential:
    vr = -Z/r

    # Speed of light taken from:
    # http://arxiv.org/abs/1012.3627
    c = 137.035999037

    # Polynomial degree for predictor-corrector:
    np = 2

    tot_error = -1
    # (n, l):
    # either k == l, or k == l + 1:
    for n in range(1, 5):
        for l in range(0, n):
            k_list = []
            if l > 0:
                k_list.append(l)
            k_list.append(l+1)

            for k in k_list:
                # Initial guess:
                E = -1.0
                E, g, f = rdirac(c, n, l, k, np, r, vr, E)
                E_exact = E_nl_dirac(n, l, spin_up=(k == l+1), Z=Z, c=c)
                delta = abs(E-E_exact)
                if delta > tot_error:
                    tot_error = delta
                #print ("(n=%d, l=%d, k=%d): E_calc=%12.6f    E_xact=%12.6f    " + \
                        #                        "delta=%9.2e") % (n, l, k, E, E_exact, delta)

    return tot_error
Exemplo n.º 3
0
def f(a):
    # Mesh:
    #r = create_hyperbolic_grid(rmin=5e-8, rmax=20, k0=30000)
    #r = create_log_mesh(a=1e-5, b=100, par=10000, n_elem=10000)
    r = mesh_exp(r_min=1e-8, r_max=50, a=a, N=1000)

    Z = 82

    # Potential:
    vr = -Z/r

    # Speed of light taken from:
    # http://arxiv.org/abs/1012.3627
    c = 137.035999037

    # Polynomial degree for predictor-corrector:
    np = 2

    tot_error = -1
    # (n, l):
    # either k == l, or k == l + 1:
    for n in range(1, 5):
        for l in range(0, n):
            k_list = []
            if l > 0:
                k_list.append(l)
            k_list.append(l+1)

            for k in k_list:
                # Initial guess:
                E = -1.0
                E, R = rdirac(c, n, l, k, np, r, vr, E)
                E_exact = E_nl_dirac(n, l, spin_up=(k == l+1), Z=Z, c=c)
                delta = abs(E-E_exact)
                if delta > tot_error:
                    tot_error = delta

    return tot_error
Exemplo n.º 4
0
        except dftatom_ConvergeError, e:
            raise ConvergeError(str(e))
        return E, R
    elif solver == "elk":
        from elk.pyelk import rdirac
        if relat == 2:
            k = l + 1
        elif relat == 3:
            k = l
        else:
            raise ValueError("relat must be 2 or 3")
        #E_init = params.get("E_init", -3000)
        E_init = params.get("E_init", -1)
        # Polynomial degree for predictor-corrector:
        np = params.get("np", 4)
        E, R = rdirac(c, n, l, k, np, r, u, E_init)
        if abs(E) > 1e6:
            raise ConvergeError("Elk solver didn't converge")
        return E, R
    else:
        raise Exception("Uknown solver")

def solve_hydrogen_like_atom(Z, mesh_params, solver_params, verbose=False):
    from sympy.physics.hydrogen import E_nl_dirac, E_nl
    from sympy import TableForm
    r_min = mesh_params["r_min"]
    r_max = mesh_params["r_max"]
    a = mesh_params["a"]
    N = mesh_params["N"]
    r = mesh_exp(r_min, r_max, a, N)
    if verbose: