Peano
Loading...
Searching...
No Matches
test5.py
Go to the documentation of this file.
1"""
2This test checks that R * A_DG * P * u_random = A_CG * u_random and R * M_DG * P * u_random = M_CG * u_random
3for some random vector u_random.
4Here R and P are the restriction and prolongation operators, respectively, A_DG, A_CG are system matrices and
5M_DG, M_CG are mass matrices for DG and CG, respectively.
6"""
7
8import os, sys
9import argparse
10import peano4.api
11import mghype
12import numpy as np
13
14from actionsets.InitDG import InitDofsDGTest5
15from actionsets.initCollocatedRandom import InitCollocatedTest5
16from actionsets.DGCGCoupling import Test5Coupling
17
18parser = argparse.ArgumentParser(description='Multigrid - Poisson solver')
19parser.add_argument("-j", "--parallel-builds", dest="j", type=int, default=-1, help="Parallel builds" )
20parser.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" )
21parser.add_argument("-pd", "--peano-dir", dest="peanodir", default="../../../../", help="Peano4 directory" )
22parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", default=False, help="Verbose")
23parser.add_argument("-d", "--dimensions", dest="dimensions", type=int, default=2, help="Dimensions")
24parser.add_argument("-p", "--poly_degree", dest="poly_degree", type=int, default=2, help="Polynomial Degree")
25parser.add_argument("-meshsize", "--meshsize", dest="meshsize", default=0.3, help="Mesh size")
26parser.add_argument("-omega_c", "--omega_c", dest="omega_c", default=0.5, help="Mesh size")
27parser.add_argument("-omega_f", "--omega_f", dest="omega_f", default=1.0, help="Mesh size")
28parser.add_argument("-m", "--mode", dest="mode", choices=["release","stats","asserts", "trace"], required=True, help="Pick build type" )
29args = parser.parse_args()
30
31project = mghype.matrixfree.api.Project( project_name = "DGPointwise",
32 namespace = [ "tests", "multigrid", "matrixfree", "test5" ]
33 )
34
35matrices = mghype.api.matrixgenerators.GLMatrixFree(
36 args.dimensions,
37 args.poly_degree,
38 1, # Unknowns per cell dof. Scalar PDE here
39 2, # We use the penalty formulation (see docu in tutorials)
40 2
41)
42
43assembly_matrix, assembly_matrix_scaling = matrices.get_cell_system_matrix_for_laplacian()
44mass_matrix, mass_matrix_scaling = matrices.get_cell_mass_matrix()
45face_from_cell_projection, \
46face_from_cell_projection_scaling = matrices.get_face_from_cell_matrix()
47cell_from_face_projection, \
48cell_from_face_projection_scaling = matrices.get_cell_from_face_matrix()
49approximate_system_matrix, \
50approximate_system_matrix_scaling = matrices.get_A_tilde()
51
52
53# DG solver
54dg_solver = mghype.matrixfree.solvers.api.DiscontinuousGalerkinDiscretisationPointWiseRiemannSolver(
55 name = "Test5DG",
56 dimensions = args.dimensions,
57 poly_degree = args.poly_degree,
58 unknowns_per_cell_node = 1,
59 solutions_per_face_node = 2,
60 projections_per_face_node = 2,
61 min_h = args.meshsize,
62 max_h = args.meshsize,
63 assembly_matrix= assembly_matrix,
64 assembly_matrix_scaling = assembly_matrix_scaling,
65 mass_matrix = mass_matrix,
66 mass_matrix_scaling = mass_matrix_scaling,
67 face_from_cell_projection = face_from_cell_projection,
68 face_from_cell_projection_scaling = face_from_cell_projection_scaling,
69 cell_from_face_projection = cell_from_face_projection,
70 cell_from_face_projection_scaling = cell_from_face_projection_scaling,
71 riemann_matrix = matrices.get_face_face_riemann_problem_matrix(),
72 boundary_matrix = matrices.get_boundary_matrix(),
73 cell_relaxation = args.omega_c,
74 face_relaxation = args.omega_f, # default here is 1, i.e. we solve exactly. See class docu
75 approximate_system_matrix = approximate_system_matrix,
76 approximate_system_matrix_scaling = approximate_system_matrix_scaling,
77 solver_tolerance = 1e-6,
78 custom_init_actionset=InitDofsDGTest5,
79)
80
81num_dg_face_solutions = 2 * (args.poly_degree + 1) ** (args.dimensions-1)
82num_dg_face_projections = 4 * (args.poly_degree + 1) ** (args.dimensions-1)
83
84dg_solver.add_to_cell_data( "mdgp", (args.poly_degree + 1) ** args.dimensions )
85dg_solver.add_to_cell_data( "adgp", (args.poly_degree + 1) ** args.dimensions )
86dg_solver.add_to_cell_data( "vcell", (args.poly_degree + 1) ** args.dimensions )
87dg_solver.add_to_face_data( "projectionTest", num_dg_face_projections )
88dg_solver.add_to_face_data( "solutionTest", num_dg_face_solutions )
89
90correction_equation_matrices = mghype.api.matrixgenerators.DLinear(
91 dimensions = args.dimensions,
92 unknowns_per_node = 1
93)
94system_matrix, system_matrix_scaling = correction_equation_matrices.get_cell_system_matrix_for_laplacian()
95mass_matrix, maxx_matrix_scaling = correction_equation_matrices.get_cell_mass_matrix()
96
97
98collocated_solver = mghype.matrixfree.solvers.api.CollocatedDLinearDiscretisationWithPointJacobi(
99 name = "Test5CG",
100 unknowns_per_vertex = 1,
101 dimensions = args.dimensions,
102 min_h = args.meshsize,
103 max_h = args.meshsize,
104 local_assembly_matrix = system_matrix,
105 local_assembly_matrix_scaling=system_matrix_scaling,
106 mass_matrix = mass_matrix,
107 mass_matrix_scaling = maxx_matrix_scaling,
108 solver_tolerance = 1e-12,
109 smoother_relaxation = 0.5,
110 custom_plot_actionset=[("rand", "getRand"), ("vrestrictADG", "getVrestrictADG"), ("vrestrictMDG", "getVrestrictMDG"), ("acg", "getAcg"), ("mcg", "getMcg")],
111 custom_init_actionset=InitCollocatedTest5
112)
113
114collocated_solver.add_to_vertex_data( "vrestrictADG", 1 )
115collocated_solver.add_to_vertex_data( "vrestrictMDG", 1 )
116collocated_solver.add_to_vertex_data( "acg", 1 )
117collocated_solver.add_to_vertex_data( "mcg", 1 )
118collocated_solver.add_to_vertex_data( "rand", 1 )
119
121 dim = args.dimensions,
122 coarse_order = 1,
123 fine_order = args.poly_degree
124 )
125prolongation_matrix = [intergrid_operators.prolongation()]
126prolongation_matrix_scaling = [0]
127restriction_matrix = [intergrid_operators.restriction()]
128restriction_matrix_scaling = [0]
129injection_matrix = [intergrid_operators.injection()]
130injection_matrix_scaling = [0]
131
132dg_solver.preprocessing_action_set = Test5Coupling(
133 dg_solver,
134 collocated_solver,
135 prolongation_matrix,
136 prolongation_matrix_scaling,
137 restriction_matrix,
138 restriction_matrix_scaling,
139 injection_matrix,
140 injection_matrix_scaling
141)
142
143project.add_solver( collocated_solver, auxiliary=True )
144project.add_solver( dg_solver )
145
146#
147# Configure build
148#
149if args.mode=="release":
150 build_mode = peano4.api.output.CompileMode.RELEASE
151if args.mode=="stats":
152 build_mode = peano4.api.output.CompileMode.STATS
153if args.mode=="asserts":
154 build_mode = peano4.api.output.CompileMode.ASSERTS
155if args.mode=="trace":
156 build_mode = peano4.api.output.CompileMode.TRACE
157
158
159cube_size = 1.0
160project.set_global_simulation_parameters(
161 dimensions = args.dimensions,
162 offset = [ 0.0 for _ in range(args.dimensions) ],
163 domain_size = [ cube_size for _ in range(args.dimensions) ],
164 plot_after_each_mesh_sweep = args.plot_after_each_mesh_sweep,
165 max_iterations = 2
166)
167
168project.set_load_balancing( "toolbox::loadbalancing::RecursiveSubdivision", "new ::exahype2::LoadBalancingConfiguration()" )
169project.set_Peano4_installation( args.peanodir, build_mode )
170
171peano4_project = project.generate_Peano4_project(args.verbose)
172# peano4_project.output.makefile.add_cpp_file( "Scenario.cpp" )
173peano4_project.generate()
174
175os.system( "mkdir visualisation" )
176
177os.system( "make clean" )
178if args.j>0:
179 os.system( "make -j{}".format(args.j) )
180else:
181 os.system( "make -j" )
Simple matrix generator for continuous d-linear finite elements.
Definition DLinear.py:10