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