Peano
Loading...
Searching...
No Matches
test6.py
Go to the documentation of this file.
1"""
2The same as Test 3, but for DG.
3This tests checks that the DG solver converges to u_{random} for the RHS constructed as b = A_DG * u_{random}
4with some random u_{random}.
5"""
6
7import os, sys
8import argparse
9import peano4.api
10import mghype
11import numpy as np
12from time import sleep
13
14print( """
15
16Peano 4 multigrid solver using Discontinuous Galerkin
17
18 We set all the face values to 0.
19
20 As a reminder, we then:
21 1. Set the face solution (take the average of 0 and 0 to make 0)
22 2. Project the face solution (into the cell), update the residual and
23 set the cell solution. Note that the residual will be 0 at this point,
24 so we probably don't see any changes to the cell solution itself
25 3. Project new solution onto faces
26 4. Set the residual to mB - AccUc...
27
28 and repeat...
29
30""")
31
32sleep(3)
33
34from actionsets.InitDG import InitDofsDGTest6, InitDofsIntermediatePhaseTest6
35
36
37
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("-p", "--poly_degree", dest="poly_degree", type=int, default=1, help="Polynomial Degree")
45parser.add_argument("-meshsize", "--meshsize", dest="meshsize", default=0.3, help="Mesh size")
46parser.add_argument("-omega_c", "--omega_c", dest="omega_c", default=0.5, help="Mesh size")
47parser.add_argument("-omega_f", "--omega_f", dest="omega_f", default=1.0, help="Mesh size")
48parser.add_argument("-m", "--mode", dest="mode", choices=["release","stats","asserts", "trace"], required=True, help="Pick build type" )
49args = parser.parse_args()
50
51
52project = mghype.matrixfree.api.Project( project_name = "DGPointwise",
53 namespace = [ "tests", "multigrid", "matrixfree", "test6" ]
54 )
55
56
57matrices = mghype.api.matrixgenerators.GLMatrixFree(
58 args.dimensions,
59 args.poly_degree,
60 1, # Unknowns per cell dof. Scalar PDE here
61 2, # We use the penalty formulation (see docu in tutorials)
62 2
63)
64
65assembly_matrix, assembly_matrix_scaling = matrices.get_cell_system_matrix_for_laplacian()
66mass_matrix, mass_matrix_scaling = matrices.get_cell_identity_matrix() # set identity instead of the mass matrix for the random solution test
67face_from_cell_projection, \
68face_from_cell_projection_scaling = matrices.get_face_from_cell_matrix()
69cell_from_face_projection, \
70cell_from_face_projection_scaling = matrices.get_cell_from_face_matrix()
71approximate_system_matrix, \
72approximate_system_matrix_scaling = matrices.get_A_tilde()
73
74solver = mghype.matrixfree.solvers.api.DiscontinuousGalerkinDiscretisationPointWiseRiemannSolver(
75 name = "DGPoisson",
76 dimensions = args.dimensions,
77 poly_degree = args.poly_degree,
78 unknowns_per_cell_node = 1,
79 solutions_per_face_node = 2,
80 projections_per_face_node = 2,
81 min_h = args.meshsize,
82 max_h = args.meshsize,
83 assembly_matrix= assembly_matrix,
84 assembly_matrix_scaling = assembly_matrix_scaling,
85 mass_matrix = mass_matrix,
86 mass_matrix_scaling = mass_matrix_scaling,
87 face_from_cell_projection = face_from_cell_projection,
88 face_from_cell_projection_scaling = face_from_cell_projection_scaling,
89 cell_from_face_projection = cell_from_face_projection,
90 cell_from_face_projection_scaling = cell_from_face_projection_scaling,
91 riemann_matrix = matrices.get_face_face_riemann_problem_matrix(),
92 boundary_matrix = matrices.get_boundary_matrix(),
93 cell_relaxation = args.omega_c,
94 face_relaxation = args.omega_f, # default here is 1, i.e. we solve exactly. See class docu
95 approximate_system_matrix = approximate_system_matrix,
96 approximate_system_matrix_scaling = approximate_system_matrix_scaling,
97 solver_tolerance = 1e-6,
98 custom_init_actionset=InitDofsDGTest6,
99 custom_plot_actionset=[("rand","getRand")]
100)
101
102# add an extra field for the random vector
103nodes_per_cell = (args.poly_degree + 1) ** args.dimensions
104solver.add_to_cell_data("rand", nodes_per_cell)
105solver.add_to_face_data("randProjection", 2*2*(args.poly_degree+1)**(1))
106solver.add_to_face_data("randSolution", 2*(args.poly_degree+1)**(1))
107
108solver.preprocessing_action_set = InitDofsIntermediatePhaseTest6(solver)
109
110#! [Instantiate solver]
111
112project.add_solver(solver)
113
114#
115# Configure build
116#
117if args.mode=="release":
118 build_mode = peano4.api.output.CompileMode.RELEASE
119if args.mode=="stats":
120 build_mode = peano4.api.output.CompileMode.STATS
121if args.mode=="asserts":
122 build_mode = peano4.api.output.CompileMode.ASSERTS
123if args.mode=="trace":
124 build_mode = peano4.api.output.CompileMode.TRACE
125
126
127cube_size = 1.0
128project.set_global_simulation_parameters(
129 dimensions = args.dimensions,
130 offset = [ 0.0 for _ in range(args.dimensions) ],
131 domain_size = [ cube_size for _ in range(args.dimensions) ],
132 plot_after_each_mesh_sweep = args.plot_after_each_mesh_sweep,
133 max_iterations = 1000
134)
135
136project.set_load_balancing( "toolbox::loadbalancing::RecursiveSubdivision", "new ::exahype2::LoadBalancingConfiguration()" )
137project.set_Peano4_installation( args.peanodir, build_mode )
138
139peano4_project = project.generate_Peano4_project(args.verbose)
140# peano4_project.output.makefile.add_cpp_file( "Scenario.cpp" )
141peano4_project.generate()
142
143os.system( "mkdir visualisation" )
144
145os.system( "make clean" )
146if args.j>0:
147 os.system( "make -j{}".format(args.j) )
148else:
149 os.system( "make -j" )
150