Peano
Loading...
Searching...
No Matches
dg-two-grid-h-coarsen.py
Go to the documentation of this file.
1import os, sys
2import argparse
3import peano4.api
4import mghype
5import numpy as np
6
7print( """
8
9Peano 4 multigrid solver using Discontinuous Galerkin
10
11""")
12
13parser = argparse.ArgumentParser(description='Multigrid - Poisson solver')
14parser.add_argument("-j", "--parallel-builds", dest="j", type=int, default=-1, help="Parallel builds" )
15parser.add_argument("-pt", "--plot-sweep", 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" )
16parser.add_argument("-fas", "--use-fas", dest="fas", action="store_true", default=False, help="Switch to FAS" )
17parser.add_argument("-pd", "--peano-dir", dest="peanodir", default="../../../../", help="Peano4 directory" )
18parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", default=False, help="Verbose")
19parser.add_argument("-d", "--dimensions", dest="dimensions", type=int, default=2, help="Dimensions")
20parser.add_argument("-p", "--poly_degree", dest="poly_degree", type=int, default=2, help="Polynomial Degree")
21parser.add_argument("-meshsize", "--meshsize", dest="meshsize", default=0.3, help="Mesh size")
22parser.add_argument("-omega_c", "--omega_c", dest="omega_c", default=0.5, help="Smoothing parameter for cells")
23parser.add_argument("-omega_f", "--omega_f", dest="omega_f", default=1.0, help="Smoothing parameter for faces")
24parser.add_argument("-m", "--mode", dest="mode", choices=["release","stats","asserts", "trace"], required=True, help="Pick build type" )
25args = parser.parse_args()
26
27project = mghype.matrixfree.api.Project( project_name = "DGTwoGrid",
28 namespace = [ "tests", "multigrid", "matrixfree", "poisson" ]
29 )
30
32 args.dimensions,
33 args.poly_degree,
34 1, # Unknowns per cell dof. Scalar PDE here
35 2, # We use the penalty formulation (see docu in tutorials)
36 2
37)
38
39assembly_matrix, assembly_matrix_scaling = matrices.get_cell_system_matrix_for_laplacian()
40mass_matrix, mass_matrix_scaling = matrices.get_cell_mass_matrix()
41face_from_cell_projection, \
42face_from_cell_projection_scaling = matrices.get_face_from_cell_matrix()
43cell_from_face_projection, \
44cell_from_face_projection_scaling = matrices.get_cell_from_face_matrix()
45approximate_system_matrix, \
46approximate_system_matrix_scaling = matrices.get_A_tilde()
47
48#! [Instantiate solver]
49solver = mghype.matrixfree.solvers.api.DiscontinuousGalerkinDiscretisationPointWiseRiemannSolver(
50 name = "DGPoisson",
51 dimensions = args.dimensions,
52 poly_degree = args.poly_degree,
53 unknowns_per_cell_node = 1,
54 solutions_per_face_node = 2,
55 projections_per_face_node = 2,
56 min_h = args.meshsize,
57 max_h = args.meshsize,
58 assembly_matrix= assembly_matrix,
59 assembly_matrix_scaling = assembly_matrix_scaling,
60 mass_matrix = mass_matrix,
61 mass_matrix_scaling = mass_matrix_scaling,
62 face_from_cell_projection = face_from_cell_projection,
63 face_from_cell_projection_scaling = face_from_cell_projection_scaling,
64 cell_from_face_projection = cell_from_face_projection,
65 cell_from_face_projection_scaling = cell_from_face_projection_scaling,
66 riemann_matrix = matrices.get_face_face_riemann_problem_matrix(),
67 boundary_matrix = matrices.get_boundary_matrix(),
68 cell_relaxation = args.omega_c,
69 face_relaxation = args.omega_f, # default here is 1, i.e. we solve exactly. See class docu
70 approximate_system_matrix = approximate_system_matrix,
71 approximate_system_matrix_scaling = approximate_system_matrix_scaling,
72 solver_tolerance = 1.0e-6,
73 integration_points = 0.5*(matrices.get_nodal_points_1d() + 1.0) # Should be specified in [0,1] interval
74)
75#! [Instantiate solver]
76
77#! [Construct correction matrices]
79 dimensions = args.dimensions,
80 poly_degree = 1,
81 unknowns_per_node = 1
82)
83
85
86system_matrix, system_matrix_scaling = correction_equation_matrices.get_cell_system_matrix_for_laplacian()
87mass_matrix, mass_matrix_scaling = correction_equation_matrices.get_cell_mass_matrix()
88
89correction_matrix, correction_matrix_scaling = correction_equation_matrices.get_cell_mass_matrix()
90#! [Construct correction matrices]
91
92"""
93We use the identity matrix everywhere...
94"""
95correction_equation_solver = mghype.matrixfree.solvers.api.CollocatedMGSingleThreaded("CollocatedMG",
96 1,
97 args.dimensions,
98 args.meshsize,
99 args.meshsize,
100 local_assembly_matrix = system_matrix,
101 local_assembly_matrix_scaling=system_matrix_scaling,
102 mass_matrix = mass_matrix,
103 mass_matrix_scaling = mass_matrix_scaling,
104 correction_matrix = correction_matrix,
105 correction_matrix_scaling = correction_matrix_scaling,
106 solver_tolerance=1e-12,
107 pre_smoothing_steps =6,
108 post_smoothing_steps=5,
109 restriction_matrix=intergridOperators.restriction(),
110 prolongation_matrix=intergridOperators.prolongation(),
111 descend_order=0,
112 )
113
114#! [Coupling]
116 dim = args.dimensions,
117 coarse_order = 1,
118 fine_order = args.poly_degree
119 )
120prolongation_matrix = [intergrid_operators.prolongation()]
121prolongation_matrix_scaling = [0]
122restriction_matrix = [intergrid_operators.restriction()]
123restriction_matrix_scaling = [0]
124injection_matrix = [intergrid_operators.injection()]
125injection_matrix_scaling = [0]
126
127solver.preprocessing_action_set = mghype.matrixfree.solvers.api.actionsets.MultiplicativeDGCGCoupling(
128 solver, # dg_solver
129 correction_equation_solver, # cg_solver
130 prolongation_matrix,
131 prolongation_matrix_scaling,
132 restriction_matrix,
133 restriction_matrix_scaling,
134 injection_matrix,
135 injection_matrix_scaling,
136 args.fas
137)
138#! [Coupling]
139
140
141#! [Add solvers]
142project.add_solver(correction_equation_solver, auxiliary=True)
143project.add_solver(solver)
144#! [Add solvers]
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 = 2000
166)
167
168project.set_Peano4_installation( args.peanodir, build_mode )
169
170peano4_project = project.generate_Peano4_project(args.verbose)
171peano4_project.output.makefile.add_cpp_file( "Scenario.cpp" )
172peano4_project.generate()
173
174os.system( "make clean" )
175if args.j>0:
176 os.system( "make -j{}".format(args.j) )
177else:
178 os.system( "make -j" )
179
Using normalised identity matrix instead of the mass matrix.
Class to produce restriction/prolongation matrices for multigrid tasks.