# geometry is a 1 dimensional line geo = np.asarray([[0, 1]]) print(geo.shape) # the boundary conditions, in this case dirichlet boundary conditions boundary_type = ["dirichlet"]*2 left_f = lambda x: 100.0 right_f = lambda x: 110.0 boundary_functions = [[left_f, right_f]] def stupid_f(*args, **kwargs): return 0.0 rhs_function = lambda x: 0.0 mg_problem = MultigridProblem(laplace_stencil, stupid_f, boundary_functions=boundary_functions, boundaries=boundary_type, geometry=geo) # test some of the methods of mg_problem print("Mid of stencil method", mg_problem.mid_of_stencil(laplace_stencil)) print("Eval_Convolve ([100,105,105,105,110])", laplace_stencil.eval_convolve(np.asarray([100, 105, 105, 105, 110]))) print("===== MultigridProblemTest =====") print("Constructed SpaceTensor", mg_problem.construct_space_tensor(12)) print("Checked if the grid distances are right", mg_problem.act_grid_distances) # they work properly at least for the 1d case # lets define the different levels lets try 3 borders = np.asarray([3, 3])
# the boundary conditions, in this case dirichlet boundary conditions boundary_type = ["dirichlet"]*2 # east_f = lambda x: 2.0 # west_f = lambda x: 8.0 # north_f = lambda x: 1.0 # south_f = lambda x: 4.0 east_f = lambda x: np.sin(x[1]*np.pi) west_f = lambda x: np.sin(x[1]*np.pi) north_f = lambda x: np.sin(x[0]*np.pi) south_f = lambda x: np.sin(x[0]*np.pi) boundary_functions = [[west_f, east_f], [north_f, south_f]] rhs_function = lambda x, y: 0.0 mg_problem = MultigridProblem(laplace_stencil, rhs_function, boundary_functions=boundary_functions, boundaries="dirichlet", geometry=geo) print("Constructed SpaceTensor\n", mg_problem.construct_space_tensor(10)) print("mg_problem.geometry", mg_problem.geometry) print("mg_problem.boundaries", mg_problem.boundaries) print("===== MultiGridLevel2d =====") level = MultigridLevel2D((4, 4), mg_problem=mg_problem, max_borders=np.asarray([[1, 1], [1, 1]]), role="FL") print("level.arr \n", level.arr) print("level.mid \n", level.mid) print("level.south \n", level.south)