2This test checks that the CG solver leaves the input invariant if the RHS is constructed as b_c = A_CG * u_random
3with some vector u_random, when the same u_random is used as the initial guess for the algorithm.
5It shows that the solution of the problem
7converges to u_random in one iteration.
8u_random has to satisfy the boundary conditions but can be random at the interior vertices.
121. Generate u_random by assigning a value from [0,1] to each vertex.
132. Set u_random to 0 at the boundary vertices to satisfy the boundary conditions.
143. Compute b_c = A_CG * u_random, where A_CG is the system matrix for CG.
154. Solve A_CG * u = b_c with CollocatedSolver with u_random as the initial guess.
165. Check |u - u_random| < tol after the first iteration of the solver.
28from actionsets.initCollocatedRandom
import InitDofsCollocatedRandomTest2
31 WARNING: implementation file (eg CollocatedPoisson.cpp) must be removed before
32 running this script if you want custom behaviour.
38parser = argparse.ArgumentParser(description=
'Multigrid - Poisson solver')
39parser.add_argument(
"-j",
"--parallel-builds", dest=
"j", type=int, default=-1, help=
"Parallel builds" )
40parser.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" )
41parser.add_argument(
"-pd",
"--peano-dir", dest=
"peanodir", default=
"../../../../", help=
"Peano4 directory" )
42parser.add_argument(
"-v",
"--verbose", dest=
"verbose", action=
"store_true", default=
False, help=
"Verbose")
43parser.add_argument(
"-d",
"--dimensions", dest=
"dimensions", type=int, default=2, help=
"Dimensions")
44parser.add_argument(
"-meshsize",
"--meshsize", dest=
"meshsize", default=0.3, help=
"Mesh size")
45parser.add_argument(
"-m",
"--mode", dest=
"mode", choices=[
"release",
"stats",
"asserts",
"trace"], required=
True, help=
"Pick build type" )
46args = parser.parse_args()
48project = mghype.matrixfree.api.Project( project_name =
"CollocatedFEM",
49 namespace = [
"tests",
"multigrid",
"matrixfree",
"verifyRandom" ]
54 dimensions = args.dimensions,
59system_matrix, system_matrix_scaling = poisson_equation_matrices.get_cell_system_matrix_for_laplacian()
60mass_matrix, mass_matrix_scaling = poisson_equation_matrices.get_cell_mass_matrix()
63solver = mghype.matrixfree.solvers.api.CollocatedDLinearDiscretisationWithPointJacobi(
"CollocatedPoisson",
68 local_assembly_matrix = system_matrix,
69 local_assembly_matrix_scaling=system_matrix_scaling,
70 mass_matrix = mass_matrix,
71 mass_matrix_scaling = mass_matrix_scaling,
72 solver_tolerance=1e-6,
73 custom_init_actionset=InitDofsCollocatedRandomTest2,
74 custom_plot_actionset=[(
"rand",
"getRand")]
78solver.add_to_vertex_data(
"rand", 1)
80project.add_solver(solver)
85if args.mode==
"release":
86 build_mode = peano4.api.output.CompileMode.RELEASE
88 build_mode = peano4.api.output.CompileMode.STATS
89if args.mode==
"asserts":
90 build_mode = peano4.api.output.CompileMode.ASSERTS
92 build_mode = peano4.api.output.CompileMode.TRACE
95project.set_global_simulation_parameters(
96 dimensions = args.dimensions,
97 offset = [ 0.0
for _
in range(args.dimensions) ],
98 domain_size = [ cube_size
for _
in range(args.dimensions) ],
99 plot_after_each_mesh_sweep = args.plot_after_each_mesh_sweep,
103project.set_load_balancing(
"toolbox::loadbalancing::RecursiveSubdivision",
"new ::exahype2::LoadBalancingConfiguration()" )
104project.set_Peano4_installation( args.peanodir, build_mode )
106peano4_project = project.generate_Peano4_project(args.verbose)
107peano4_project.generate()
109os.system(
"make clean" )
111 os.system(
"make -j{}".format(args.j) )
113 os.system(
"make -j" )
Using normalised identity matrix instead of the mass matrix.