2This test checks that the CG solver converges to u_random for the RHS set as b_c = A_CG * u_random with some vector u_random.
3It shows that the solution u of the problem
5approximates u_random. u_random has to satisfy the boundary conditions but can be random at the interior vertices.
91. Generate u_random by assigning a value from [0,1] to each vertex.
102. Set u_random to 0 at the boundary vertices to satisfy the boundary conditions.
113. Compute b_c = A_CG * u_random, where A_CG is the system matrix for CG.
124. Solve A_CG * u = b_c with CollocatedSolver.
135. Check |u - u_random| < tol.
25from actionsets.initCollocatedRandom
import InitDofsCollocatedRandomRhs
28 WARNING: implementation file (eg CollocatedPoisson.cpp) must be removed before
29 running this script if you want custom behaviour.
35parser = argparse.ArgumentParser(description=
'Multigrid - Poisson solver')
36parser.add_argument(
"-j",
"--parallel-builds", dest=
"j", type=int, default=-1, help=
"Parallel builds" )
37parser.add_argument(
"-pt",
"--plot-timestep", dest=
"plot_after_each_mesh_sweep", action=
"store_true", default=
False, help=
"Plot after each timestep. By default (False) we plot after initialisation and at the end" )
38parser.add_argument(
"-pd",
"--peano-dir", dest=
"peanodir", default=
"../../../../", help=
"Peano4 directory" )
39parser.add_argument(
"-v",
"--verbose", dest=
"verbose", action=
"store_true", default=
False, help=
"Verbose")
40parser.add_argument(
"-d",
"--dimensions", dest=
"dimensions", type=int, default=2, help=
"Dimensions")
41parser.add_argument(
"-meshsize",
"--meshsize", dest=
"meshsize", default=0.3, help=
"Mesh size")
42parser.add_argument(
"-m",
"--mode", dest=
"mode", choices=[
"release",
"stats",
"asserts",
"trace"], required=
True, help=
"Pick build type" )
43args = parser.parse_args()
45project = mghype.matrixfree.api.Project( project_name =
"CollocatedFEM",
46 namespace = [
"tests",
"multigrid",
"matrixfree",
"verifyRandom" ]
56 dimensions = args.dimensions,
61system_matrix, system_matrix_scaling = poisson_equation_matrices.get_cell_system_matrix_for_laplacian()
62mass_matrix, mass_matrix_scaling = poisson_equation_matrices.get_cell_mass_matrix()
65solver = mghype.matrixfree.solvers.api.CollocatedDLinearDiscretisationWithPointJacobi(
"CollocatedPoisson",
70 local_assembly_matrix = system_matrix,
71 local_assembly_matrix_scaling=system_matrix_scaling,
72 mass_matrix = mass_matrix,
73 mass_matrix_scaling = mass_matrix_scaling,
74 solver_tolerance=1e-9,
75 custom_init_actionset=InitDofsCollocatedRandomRhs,
76 custom_plot_actionset=[(
"rand",
"getRand")]
80solver.add_to_vertex_data(
"rand", 1)
82project.add_solver(solver)
87if args.mode==
"release":
88 build_mode = peano4.api.output.CompileMode.RELEASE
90 build_mode = peano4.api.output.CompileMode.STATS
91if args.mode==
"asserts":
92 build_mode = peano4.api.output.CompileMode.ASSERTS
94 build_mode = peano4.api.output.CompileMode.TRACE
97project.set_global_simulation_parameters(
98 dimensions = args.dimensions,
99 offset = [ 0.0
for _
in range(args.dimensions) ],
100 domain_size = [ cube_size
for _
in range(args.dimensions) ],
101 plot_after_each_mesh_sweep = args.plot_after_each_mesh_sweep,
102 max_iterations = 5000
105project.set_load_balancing(
"toolbox::loadbalancing::RecursiveSubdivision",
"new ::exahype2::LoadBalancingConfiguration()" )
106project.set_Peano4_installation( args.peanodir, build_mode )
108peano4_project = project.generate_Peano4_project(args.verbose)
109peano4_project.generate()
111os.system(
"make clean" )
113 os.system(
"make -j{}".format(args.j) )
115 os.system(
"make -j" )
Using normalised identity matrix instead of the mass matrix.