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