print("the space_tensor of the last level") print(low_level.space_tensor) print(*mg_problem.act_grid_distances) print("test the is on border function") is_on_border = low_level.border_function_generator(laplace_stencil) border_truth = [is_on_border((i,)) for i in range(low_level.evaluable_view(laplace_stencil).size)] print(border_truth) # define the smoother from the split smoother class on each level, # where the last level is solved directly # omega = 1/np.sqrt(2) omega = 0.5 l_plus = np.asarray([0, -2.0/omega, 0]) l_minus = np.asarray([1.0, -2.0*(1.0 - 1.0/omega), 1.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)
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 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