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