예제 #1
0
    print("Now we do a jacobi step using sparse matrix algorithms:")
    print("But just before one needs to fill the rhs")
    print("rhs at the beginning: \n", low_level.rhs)
    mg_problem.fill_rhs(low_level)
    print("rhs after filling it: \n", low_level.rhs)
    # laplace_stencil.modify_rhs(low_level)
    print("rhs after modification: \n", low_level.rhs)
    jacobi_matrix.relax()
    print(low_level.arr)

    print("Now we check if the more general SplitSmootherClass :")
    mg_problem.fill_rhs(low_level)
    low_level.mid[:] = 105.0
    low_level.pad()
    low_jacobi_smoother.relax()
    print(low_level.arr)

    print("===== Restriction and Interpolation =====")
    # generate restriction stencil
    rst_inject = RestrictionStencilPure(np.asarray([1.0]), 2)
    rst_fw = RestrictionStencilPure(np.asarray([0.25, 0.5, 0.25]), 2)
    # try it with just some simple arrays
    x_in = np.arange(9) ** 2
    x_out = np.zeros(5)
    print("test injection,\n x_in :", x_in)
    print(" x_out :", x_out)
    rst_inject.eval(x_in, x_out)
    print("inject,\n x_out :", x_out)
    # full weighting restriction needs another interpretation because
    # the stencil needs also the values on the boundary, this men
예제 #2
0
    print("level.arr after direct solution\n", level.mid)
    print("test of the solution Ax=b by convolve\n ", laplace_stencil.eval_convolve(level.mid, "same"))
    rhs_test = np.zeros(level.rhs.shape)
    laplace_stencil.eval_sparse(level.mid, rhs_test)
    print("test of the solution Ax=b by sparse matrix application \n", rhs_test)

    print("==== SplitSmoother ====")
    omega = 2.0/3.0
    l_plus = np.asarray([[0, 0, 0],
                         [0, -4.0/omega, 0],
                         [0, 0, 0]])
    l_minus = np.asarray([[0, 1.0, 0], [1.0, -4.0*(1.0 - 1.0/omega), 1.0], [0., 1., 0.]])

    jacobi_smoother = SplitSmoother(l_plus, l_minus, level)
    level.mid[:] = 0
    jacobi_smoother.relax()
    print("level.arr after one jacobi step with modified rhs\n", level.arr)

    level.mid[:] = 0.
    level.modified_rhs = False
    level.rhs[:] = 0.
    jacobi_smoother = SplitSmoother(l_plus, l_minus, level)
    jacobi_smoother.relax()
    print("level.arr after one jacobi step with unmodified rhs\n", level.arr)

    # For the test of the level transitioning we define 3 levels
    # with different roles but the same borders
    n_jacobi_pre = 5
    n_jacobi_post = 5
    borders = np.ones((2, 2))
    top_level = MultigridLevel2D((259, 259), mg_problem=mg_problem,