Example #1
0
    print("level.nw_tensor \n", level.nw_tensor)

    level.pad()
    print("level.arr after padding\n", level.arr)
    print("north_east\n", level.ne)
    print("north_west\n", level.nw)
    print("south_east\n", level.se)
    print("south_west\n", level.sw)

    print("evaluable view of stencil\n", level.evaluable_view(laplace_stencil))
    is_on_border = level.border_function_generator(laplace_stencil)
    border_truth = [[is_on_border((i, j)) for j in range(level.arr.shape[1])] for i in range(level.arr.shape[0])]
    print("border_truth\n", np.asarray(border_truth, dtype=np.int))

    level.rhs[:] = 0.0
    laplace_stencil.modify_rhs(level)
    print("level.rhs after modification\n", level.rhs)

    print("==== DirectSolver ====")

    direct_solver = DirectSolverSmoother(laplace_stencil, level)
    laplace_stencil.modify_rhs(level)
    direct_solver.relax()
    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
Example #2
0
    top_jacobi_smoother = SplitSmoother(l_plus / top_level.h**2,
                                        l_minus / top_level.h**2,
                                        top_level)
    mid_jacobi_smoother = SplitSmoother(l_plus / mid_level.h**2,
                                        l_minus / mid_level.h**2,
                                        mid_level)
    low_jacobi_smoother = SplitSmoother(l_plus / low_level.h**2,
                                        l_minus / low_level.h**2,
                                        low_level)
    low_direct_smoother = DirectSolverSmoother(laplace_stencil, low_level)
    # time to test the relaxation methods
    print("===== DirectSolverSmoother Test =====")
    low_level.rhs[:] = 0.0
    low_level.pad()
    print("arr:", low_level.arr)
    laplace_stencil.modify_rhs(low_level)
    print("rhs:", low_level.rhs)
    low_direct_smoother.relax()
    print(low_level.arr)
    low_level.pad()
    # Lets test the SplitSmoother by using the jacobi smoother
    # but for this case we need an initial guess
    print("===== JacobiSmoother Test =====")
    # define the 3 different JacobiSmoother Implementations
    jacobi_loop = WeightedJacobiSmoother(laplace_stencil,
                                         low_level, 0.5, "loop")
    jacobi_matrix = WeightedJacobiSmoother(laplace_stencil,
                                           low_level, 0.5, "matrix")
    jacobi_convolve = WeightedJacobiSmoother(laplace_stencil,
                                            low_level, 0.5, "convolve")
Example #3
0
    ipl_mid_to_top = InterpolationByStencilForLevelsClassical(mid_level, top_level, ipl_stencil_list_standard,
                                                              pre_assign=iadd)

    ipl_low_to_mid = InterpolationByStencilForLevelsClassical(low_level, mid_level, ipl_stencil_list_standard,
                                                              pre_assign=iadd)

    n_pre = 1
    n_post = 1
    print("\t \t --Nothing done--\n")
    print_all(top_level)

    top_level.mid[:] = 1
    top_level.pad()
    mg_problem.fill_rhs(top_level)
    top_stencil.modify_rhs(top_level)
    print("\t \t --Initialisation of top level --\n")
    print_all(top_level)

    top_jacobi_smoother.relax(n_pre)

    print("\t\t --After %d Jacobi iterations --" % n_pre)
    print_all(top_level)

    top_level.compute_residual(top_stencil)

    print("\t\t --After the computation of the residual--")
    print_all(top_level)

    rst_top_to_mid.restrict()