PRISMS-PF Manual
Loading...
Searching...
No Matches
mg_solver.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2025 PRISMS Center at the University of Michigan
2// SPDX-License-Identifier: GNU Lesser General Public Version 2.1
3
4#pragma once
5#include <deal.II/grid/grid_tools.h>
6#include <deal.II/lac/precondition.h>
7#include <deal.II/lac/solver_cg.h>
8#include <deal.II/matrix_free/matrix_free.h>
9#include <deal.II/matrix_free/operators.h>
10#include <deal.II/multigrid/mg_coarse.h>
11#include <deal.II/multigrid/mg_constrained_dofs.h>
12#include <deal.II/multigrid/mg_matrix.h>
13#include <deal.II/multigrid/mg_smoother.h>
14#include <deal.II/multigrid/mg_tools.h>
15#include <deal.II/multigrid/mg_transfer_global_coarsening.h>
16#include <deal.II/multigrid/mg_transfer_matrix_free.h>
17#include <deal.II/multigrid/multigrid.h>
18
19#include <prismspf/core/timer.h>
20#include <prismspf/core/types.h>
21
24
25#include <prismspf/config.h>
26
28
29template <unsigned int dim, unsigned int degree, typename number>
30class SolveContext;
31
35template <unsigned int dim, unsigned int degree, typename number>
36class MGSolver : public LinearSolver<dim, degree, number>
37{
42 using SolverBase::rhs_operators;
46
47public:
55
59 void
60 solve_level(unsigned int relative_level) override
61 {}
62
63 void
65 {
66 int min_level = 0;
67 int max_level = 0;
68 // 1. Level operators
69 dealii::MGLevelObject<MFOperator<dim, degree, number>> mg_lhs_operators(min_level,
70 max_level);
71 // TODO: Initialize them
72
73 // 2. Solution and rhs vectors (rhs and solution here are used as scratch space by mg,
74 // but are not actually the same as the top level vectors)
75 dealii::MGLevelObject<BlockVector<number>> mg_solution_vectors(min_level, max_level);
76 dealii::MGLevelObject<BlockVector<number>> mg_rhs_vectors(min_level, max_level);
77
78 // TODO: Initialize their shapes
79
80 // 3. MG transfer
81 dealii::MGTransferBlockMatrixFree<dim, number> mg_transfer; // Constraints?
82 // NOTE: dof_handler.distribute_mg_dofs() must have been called
83 mg_transfer.build(
84 solve_context->dof_manager.get_field_dof_handlers(solve_group.field_indices, 0));
85
86 // 4. MG Smoother (takes in operators) This is similar to a solver, but is
87 // conceptually different.
88 // Preconditioner for smoother.
89 // TODO: use PreconditionBlockJacobi or other block preconditioner instead
90 using SmootherPrecond =
91 dealii::PreconditionChebyshev<MFOperator<dim, degree, number>, BlockVector<number>>;
92 dealii::MGLevelObject<typename SmootherPrecond::AdditionalData> smoother_data(
94 max_level);
95 for (unsigned int level = min_level; level <= max_level; ++level)
96 {
97 // smoother_data[level].smoothing_range;
98 // smoother_data[level].degree;
99 // smoother_data[level].eig_cg_n_iterations;
100 // smoother_data[level].preconditioner;
101 // smoother_data[level].constraints;
102 }
103 // Wrapper around a generic preconditioner to be used as a smoother
104 using Smoother = dealii::MGSmootherPrecondition<MFOperator<dim, degree, number>,
109
110 // The MG method requires the choice of a solve on the coarsest level. There are a
111 // couple of main options:
112 // A. Direct solve // we're not doing this
113 // B. Iterative solve (using a Krylov method, (like CG))
114 /* dealii::MGCoarseGridIterativeSolver<BlockVector<number>,
115 dealii::SolverCG<BlockVector<number>>,
116 MFOperator<dim, degree, number>,
117 dealii::PreconditionIdentity> mg_coarse_solver;*/
118 // C. Smoothing operation (don't actually solve, just use the same smoother as on
119 // other levels)
120 /* dealii::MGCoarseGridApplySmoother<BlockVector<number>> mg_coarse_solver;
121 mg_coarse_solver.initialize(mg_smoother); */
122
123 // 5. Coarse grid solver
124 dealii::MGCoarseGridApplySmoother<BlockVector<number>> mg_coarse_solver;
125 mg_coarse_solver.initialize(mg_smoother);
126
127 // 6. Multigrid object
128 dealii::Multigrid<BlockVector<number>> multigrid(
134 min_level,
135 max_level,
136 dealii::Multigrid<BlockVector<number>>::Cycle::v_cycle);
137
138 // 7. Turn MG into a preconditioner object
139 dealii::PreconditionMG<dim,
141 dealii::MGTransferBlockMatrixFree<dim, number>>
143 solve_context->dof_manager.get_field_dof_handlers(solve_group.field_indices, 0),
144 multigrid,
146
147 // 8. Solve the system with CG + MG preconditioner
148 dealii::SolverControl cg_solver_control(/* TODO */);
149 dealii::SolverCG<BlockVector<number>> cg_solver(cg_solver_control);
150 }
151
152private:
156 dealii::SolverControl linear_solver_control;
157};
158
This class handles the explicit solves of all explicit fields.
Definition linear_solver.h:34
int do_linear_solve(BlockVector< number > &b_vector, MFOperator< dim, degree, number > &lhs_operator, BlockVector< number > &x_vector)
Definition linear_solver.h:150
std::vector< MFOperator< dim, degree, number > > lhs_operators
Definition linear_solver.h:186
This class handles the explicit solves of all explicit fields.
Definition mg_solver.h:37
SolveGroup solve_group
Information about the solve group this handler is responsible for.
Definition solver_base.h:259
const SolveContext< dim, degree, number > * solve_context
Solver context provides access to external information.
Definition solver_base.h:264
void solve_level(unsigned int relative_level) override
Solve for a single update step.
Definition mg_solver.h:60
void mg_solve()
Definition mg_solver.h:64
MGSolver(SolveGroup _solve_group, const SolveContext< dim, degree, number > &_solve_context)
Constructor.
Definition mg_solver.h:51
dealii::SolverControl linear_solver_control
Solver control. Contains max iterations and tolerance.
Definition mg_solver.h:156
This class provides context for a solver with ptrs to all the relevant dependencies.
Definition solve_context.h:36
Structure to hold the attributes of a solve-group.
Definition solve_group.h:59
std::set< Types::Index > field_indices
Indices of the fields to be solved in this group.
Definition solve_group.h:98
Definition solver_base.h:32
SolveGroup solve_group
Information about the solve group this handler is responsible for.
Definition solver_base.h:259
GroupSolutionHandler< dim, number > solutions
Solution vectors for fields handled by this solver.
Definition solver_base.h:269
const SolveContext< dim, degree, number > * solve_context
Solver context provides access to external information.
Definition solver_base.h:264
@ Value
Use value of the variable as a criterion for refinement.
Definition grid_refiner_criterion.h:31
dealii::LinearAlgebra::distributed::BlockVector< number > BlockVector
Typedef for solution block vector.
Definition group_solution_handler.h:29
Definition conditional_ostreams.cc:20