Beispiel #1
0
def dot_product(prec, factor_array1, factor_array2, out_tree, MRA):
    '''
    performs the dot product operation on two tree arrays of size 3.
    the operation is performed as if each of the arrays is a 3D vector and each
    of the trees are a value in that vector.
    '''
    add_tree1 = vp.FunctionTree(MRA)
    mult_tree1 = vp.FunctionTree(MRA)
    mult_tree2 = vp.FunctionTree(MRA)
    mult_tree3 = vp.FunctionTree(MRA)

    vp.multiply(prec, mult_tree1, 1, factor_array1[0], factor_array2[0])
    vp.multiply(prec, mult_tree2, 1, factor_array1[1], factor_array2[1])
    vp.multiply(prec, mult_tree3, 1, factor_array1[2], factor_array2[2])

    vp.add(prec / 10, add_tree1, 1.0, mult_tree1, 1.0, mult_tree2)
    vp.add(prec / 10, out_tree, 1.0, mult_tree3, 1.0, add_tree1)
    mult_tree1.clear()
    mult_tree2.clear()
    mult_tree3.clear()
    add_tree1.clear()
    del mult_tree1
    del mult_tree2
    del mult_tree3
    del add_tree1
Beispiel #2
0
def V_solver_Lin(prec, MRA, DerivativeOperator, PoissonOperator, eps_inv_tree,
                 C_tree, V_tree, rho_eff_tree, old_V_tree):
    gamma_tree = vp.FunctionTree(MRA)
    poiss_tree = vp.FunctionTree(MRA)
    D = DerivativeOperator
    P = PoissonOperator

    DV_vector = D_functree(D, V_tree, MRA)
    clone_tree(V_tree, old_V_tree, prec, MRA)

    V_tree.clear()
    DC_vector = D_functree(D, C_tree, MRA)

    gamma_Lin(eps_inv_tree, DC_vector, DV_vector, gamma_tree, prec, MRA)

    vp.add(prec, poiss_tree, 1, rho_eff_tree, 1, gamma_tree)

    poisson_solver(V_tree, poiss_tree, P, prec)

    return gamma_tree
Beispiel #3
0
def v_generator(v_tree, MRA, prec=10e-3, beta=100.0, mid=0.0, mu=0.0):
    import vampyr3d as vp
    from numpy import pi
    alpha = (beta / pi)**(3 / 2)

    x_tree = vp.FunctionTree(MRA)
    y_tree = vp.FunctionTree(MRA)
    z_tree = vp.FunctionTree(MRA)
    const_tree = vp.FunctionTree(MRA)

    x_tree_generator(x_tree, 0, prec, beta, mid)
    x_tree_generator(y_tree, 1, prec, beta, mid)
    x_tree_generator(z_tree, 2, prec, beta, mid)
    const_tree_generator(const_tree, prec, beta, mu, mid)
    vec = []
    vec.append(tuple([1.0, x_tree]))
    vec.append(tuple([1.0, y_tree]))
    vec.append(tuple([1.0, z_tree]))
    vec.append(tuple([1.0, const_tree]))
    vp.build_grid(v_tree, vec)
    vp.add(prec, v_tree, vec)

    alpha = -alpha / (4.0 * pi)
    v_tree.rescale(alpha)
Beispiel #4
0
sfuncs.poisson_solver(V_tree, rho_eff_tree, P, prec)

x_plt = np.linspace(-2, 2, 60)
j = 1
error = 1
old_V_tree = vp.FunctionTree(MRA)

while (error > prec):
    # solving the poisson equation once
    gamma_tree = sfuncs.V_solver_Lin(prec, MRA, D, P, eps_inv_tree,
                                     Cavity_tree, V_tree, rho_eff_tree,
                                     old_V_tree)

    # finding error once
    temp_tree = vp.FunctionTree(MRA)
    vp.add(prec / 10, temp_tree, 1.0, V_tree, -1.0, old_V_tree)
    error = np.sqrt(temp_tree.getSquareNorm())

    b = gamma_tree.integrate()

    print('iterations %i error %f energy %f' % (j, error, b))

    print('exact energy %f' % ((1 - e_inf) / e_inf))
    if (j % 5 == 0 or j == 1 or error <= prec):

        V_Lin_plt = np.array([V_tree.evalf(x, 0, 0) for x in x_plt])
        eps_inv_plt = np.array([sfuncs.diel_f_Lin_inv(x, 0, 0) for x in x_plt])
        plt.figure()
        plt.plot(x_plt, V_Lin_plt, 'b')
        plt.plot(x_plt, 1 / x_plt, 'g')
        plt.plot(x_plt, eps_inv_plt, 'y')
while (Radius[0] <= 6.0):
    initialize_cavity([[0.0, 0.0, 0.0]], Radius, d)
    change_e_inf(e_inf)

    gamma_tree = V_SCF_exp(MRA, prec, P, D, charge, rho_tree, V_tree, Heh_p,
                           Heh_p_Z)
    # finding E_r
    V_r_tree = vp.FunctionTree(MRA)
    eps_diff_tree = vp.FunctionTree(MRA)
    rho_diff_tree = vp.FunctionTree(MRA)
    poiss_tree = vp.FunctionTree(MRA)
    integral_tree = vp.FunctionTree(MRA)
    print('set V_r')
    vp.project(prec, eps_diff_tree, exp_eps_diff)
    vp.multiply(prec, rho_diff_tree, 1, eps_diff_tree, rho_tree)
    vp.add(prec, poiss_tree, 1, gamma_tree, -1, rho_diff_tree)
    poisson_solver(V_r_tree, poiss_tree, P, prec)
    # vp.multiply(prec, integral_tree, 1, rho_tree, V_r_tree)
    print('plotting potentials')
    x_plt = np.linspace(-7, 7, 1000)
    z_plt = np.linspace(-7, 7, 1000)
    X, Z = np.meshgrid(x_plt, z_plt)
    gamma_plt = np.zeros_like(X)
    V_r_plt = np.zeros_like(X)
    for i in range(len(x_plt)):
        for j in range(len(z_plt)):
            # gamma_plt[i][j] = gamma_tree.evalf([X[i][j], 0.0, Z[i][j]])]
            V_r_plt[i][j] = V_r_tree.evalf([X[i][j], 0.0, Z[i][j]])
    # plt.plot(x_plt, gamma_plt, 'r')
    # plt.plot(x_plt, V_r_plt, 'b')
    # plt.show()
Beispiel #6
0
def test_add_vec():
    sum_vec = []
    sum_vec.append(tuple([1.0, phi_tree]))
    sum_vec.append(tuple([-1.0, phi_tree]))
    vp.add(prec / 10, add_vec_tree, sum_vec)
    assert isclose(add_vec_tree.evalf([0.0, 0.0, 0.0]), 0.0, abs_tol=prec * 10)
Beispiel #7
0
def test_add():
    vp.add(prec / 10, add_tree, 1.0, phi_tree, -1, phi_tree_pois)
    assert isclose(add_tree.evalf([0, 0, 0]), 0.0, abs_tol=prec * 10)
Beispiel #8
0
def V_SCF_exp(MRA, prec, P, D, charge, rho_tree, V_tree, pos, Z):
    global e_inf
    global e_0
    global Cavity

    # initializing FunctionTrees
    eps_inv_tree = vp.FunctionTree(MRA)
    rho_eff_tree = vp.FunctionTree(MRA)
    Cavity_tree = vp.FunctionTree(MRA)
    old_V_tree = vp.FunctionTree(MRA)
    print('set rho')
    set_rho(pos, Z, charge, 1000.0, rho_tree, prec)
    # making rho_eff_tree containing rho_eff
    print('set cavity functions')
    vp.project(prec / 100, eps_inv_tree, diel_f_exp_inv)
    vp.project(prec / 100, Cavity_tree, Cavity)

    vp.multiply(prec, rho_eff_tree, 1, eps_inv_tree, rho_tree)
    print("plotting the cavity")
    x_plt = np.linspace(-7.0, 7.0, 1000)
    Cavity_plt = np.array([Cavity_tree.evalf([x, 0., 0.]) for x in x_plt])
    plt.plot(x_plt, Cavity_plt)
    plt.show()

    Cavity_tree.rescale(np.log(e_0 / e_inf))

    j = 1
    error = 1
    poisson_solver(V_tree, rho_eff_tree, P, prec)

    while (error >= prec):
        # solving the poisson equation once
        gamma_tree = V_solver_exp(rho_eff_tree, V_tree, Cavity_tree, D, P, MRA,
                                  prec, old_V_tree)

        # finding error once
        temp_tree = vp.FunctionTree(MRA)
        vp.add(prec / 10, temp_tree, 1.0, V_tree, -1.0, old_V_tree)
        error = np.sqrt(temp_tree.getSquareNorm())
        temp_tree.clear()
        del temp_tree

        # Reaction_charge = gamma_tree.integrate()
        # print('iter:\t\t\t%i\nerror:\t\t\t%f\nR charge:\t\t%f' % (j, error,
        #      Reaction_charge))
        print('iter:\t', j, '\t error:\t', error)
        # print('exact Reaction charge:\t%f\n'%((charge)*((1 - e_inf)/e_inf)))
        j += 1

    print('converged total electrostatic potential\n')

    eps_inv_tree.clear()
    rho_eff_tree.clear()
    Cavity_tree.clear()
    old_V_tree.clear()
    del eps_inv_tree
    del rho_eff_tree
    del Cavity_tree
    del old_V_tree

    return gamma_tree