Peano
Loading...
Searching...
No Matches
dg-two-grid.py
Go to the documentation of this file.
1import os, sys
2import argparse
3import peano4.api
4import mghype
5import numpy as np
6
7import commonsteps
8
9
10args = commonsteps.get_args()
11
12
13executable = "peano4matrixfree"
14
15project = mghype.matrixfree.api.Project( project_name = "DGTwoGrid",
16 namespace = [ "tests", "multigrid", "matrixfree", "poisson" ],
17 executable = executable
18 )
19
20
22 args.dimensions,
23 args.poly_degree,
24 1, # Unknowns per cell dof. Scalar PDE here
25 2, # We use the penalty formulation (see docu in tutorials)
26 2
27)
28
29
30assembly_matrix, assembly_matrix_scaling = matrices.get_cell_system_matrix_for_laplacian()
31mass_matrix, mass_matrix_scaling = matrices.get_cell_mass_matrix()
32face_from_cell_projection, \
33face_from_cell_projection_scaling = matrices.get_face_from_cell_matrix()
34cell_from_face_projection, \
35cell_from_face_projection_scaling = matrices.get_cell_from_face_matrix()
36approximate_system_matrix, \
37approximate_system_matrix_scaling = matrices.get_A_tilde()
38
39
40solver = mghype.matrixfree.solvers.api.DiscontinuousGalerkinDiscretisationPointWiseRiemannSolver(
41 name = "DGPoisson",
42 dimensions = args.dimensions,
43 poly_degree = args.poly_degree,
44 unknowns_per_cell_node = 1,
45 solutions_per_face_node = 2,
46 projections_per_face_node = 2,
47 min_h = args.meshsize,
48 max_h = args.meshsize,
49 assembly_matrix= assembly_matrix,
50 assembly_matrix_scaling = assembly_matrix_scaling,
51 mass_matrix = mass_matrix,
52 mass_matrix_scaling = mass_matrix_scaling,
53 face_from_cell_projection = face_from_cell_projection,
54 face_from_cell_projection_scaling = face_from_cell_projection_scaling,
55 cell_from_face_projection = cell_from_face_projection,
56 cell_from_face_projection_scaling = cell_from_face_projection_scaling,
57 riemann_matrix = matrices.get_face_face_riemann_problem_matrix(),
58 boundary_matrix = matrices.get_boundary_matrix(),
59 cell_relaxation = args.omega_c,
60 face_relaxation = args.omega_f, # default here is 1, i.e. we solve exactly. See class docu
61 approximate_system_matrix = approximate_system_matrix,
62 approximate_system_matrix_scaling = approximate_system_matrix_scaling,
63 solver_tolerance = 1.0e-14,
64 integration_points = 0.5*(matrices.get_nodal_points_1d() + 1.0) # Should be specified in [0,1] interval
65)
66
67
68#! [Construct correction matrices]
70 dimensions = args.dimensions,
71 poly_degree = 1,
72 unknowns_per_node = 1
73)
74system_matrix, system_matrix_scaling = correction_equation_matrices.get_cell_system_matrix_for_laplacian()
75mass_matrix, mass_matrix_scaling = correction_equation_matrices.get_cell_mass_matrix()
76#! [Construct correction matrices]
77
78
79#! [Correction equation solver]
80correction_equation_solver = mghype.matrixfree.solvers.api.CollocatedDLinearDiscretisationWithPointJacobi(
81 name = "CollocatedPoisson",
82 unknowns_per_vertex = 1,
83 dimensions = args.dimensions,
84 min_h = args.meshsize,
85 max_h = args.meshsize,
86 local_assembly_matrix = system_matrix,
87 local_assembly_matrix_scaling=system_matrix_scaling,
88 mass_matrix = mass_matrix,
89 mass_matrix_scaling = mass_matrix_scaling,
90 solver_tolerance = 1e-12,
91 smoother_relaxation = 0.5
92)
93#! [Correction equation solver]
94
95
96#! [Coupling]
98 dim = args.dimensions,
99 coarse_order = 1,
100 fine_order = args.poly_degree
101 )
102prolongation_matrix = [intergrid_operators.prolongation()]
103prolongation_matrix_scaling = [0]
104restriction_matrix = [intergrid_operators.restriction()]
105restriction_matrix_scaling = [0]
106injection_matrix = [intergrid_operators.injection()]
107injection_matrix_scaling = [0]
108
109solver.preprocessing_action_set = mghype.matrixfree.solvers.api.actionsets.MultiplicativeDGCGCoupling(
110 solver, # dg_solver
111 correction_equation_solver, # cg_solver
112 prolongation_matrix,
113 prolongation_matrix_scaling,
114 restriction_matrix,
115 restriction_matrix_scaling,
116 injection_matrix,
117 injection_matrix_scaling,
118 args.fas
119)
120#! [Coupling]
121
122
123#! [Add solvers]
124project.add_solver(correction_equation_solver, auxiliary=True)
125project.add_solver(solver)
126#! [Add solvers]
127
128commonsteps.configure_and_build_project(args,project)
129commonsteps.run_and_validate(args,executable)
Using normalised identity matrix instead of the mass matrix.