Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
gamg.hpp
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// Copyright (C) 2024 - 2026 by the Vulpes authors.
4// This file is part of Vulpes.
5//
6// Vulpes is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Vulpes is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Vulpes. If not, see <http://www.gnu.org/licenses/>.
18//
19// ----------------------------------------------------------------------
20
21// Author: Nicola De March <nicola.demarch@polimi.it>
22
23#ifndef VULPES_LA_GAMG_HPP_
24#define VULPES_LA_GAMG_HPP_
25
26#include <cassert>
27#include <cmath>
28#include <type_traits>
29
30#include "vulpes/la/vector.hpp"
31
32namespace vulpes {
33namespace la {
34
45struct DataGAMG {
51 double threshold = 0.0;
52
57 unsigned int n_smooths = 1;
58
64 unsigned int aggressive_levels = 1;
65
70 unsigned int coarse_eq_limit = 1000;
71
80
86 bool reuse_interpolation = false;
87};
88
104template <typename CellManagerType, typename DofHandlerType>
106 CellManagerType& cell_manager,
107 const DofHandlerType& dof_handler,
108 double value = 1.0) {
109 const auto& mesh = cell_manager.getMesh();
110 const auto& fe_space = cell_manager.getFeSpace();
111 const auto& constant_mode = fe_space.getBasisFast()[0];
112 using Point = typename std::decay_t<decltype(mesh)>::SelfPoint;
113 const double mode_value = constant_mode.evaluate(Point::Zero());
114 assert(
115 std::abs(constant_mode.evaluate(Point::Ones()) - mode_value) <=
116 1e-12 * std::abs(mode_value) &&
117 "the first basis function must be the constant mode");
118
119 const auto n_cells = [&]() {
120 if constexpr (std::decay_t<decltype(mesh)>::parallel()) {
121 return mesh.nOwnedCells();
122 } else {
123 return mesh.numCells();
124 }
125 }();
126 Vector coeffs(dof_handler);
127 for (std::decay_t<decltype(n_cells)> cell_id = 0; cell_id < n_cells;
128 ++cell_id) {
129 cell_manager.getCell(cell_id); // builds the mapping if needed
130 // Same basis scaling as the integrators (IntegratorBase::
131 // applyBasisScaling): physical basis = reference basis / sqrt(det J)
132 double basis_value = mode_value;
133 if constexpr (std::decay_t<decltype(fe_space)>::needBasisScaling()) {
134 basis_value /=
135 std::sqrt(cell_manager.getMapping(cell_id)->jacobianDet({}));
136 }
137 coeffs.setValue(
138 dof_handler.getCellToDof()[cell_id][0], value / basis_value);
139 }
140 coeffs.compress();
141 return coeffs;
142}
143
144} // namespace la
145} // namespace vulpes
146
147#endif // VULPES_LA_GAMG_HPP_
A wrapper around PETSc Vec for distributed vectors.
Definition vector.hpp:54
void setValue(PetscInt idx, PetscScalar value, InsertMode mode=INSERT_VALUES)
Set a single value in the vector.
Definition vector.cpp:146
void compress()
Compress the vector (do intracommunication).
Definition vector.cpp:49
Definition boomer_amg.hpp:27
Vector constantModalCoefficients(CellManagerType &cell_manager, const DofHandlerType &dof_handler, double value=1.0)
Coefficients of a constant function in a modal DG space.
Definition gamg.hpp:105
Definition cell_manager.hpp:38
Definition gamg.hpp:45
unsigned int aggressive_levels
Definition gamg.hpp:64
unsigned int coarse_eq_limit
Definition gamg.hpp:70
double threshold
Definition gamg.hpp:51
unsigned int n_smooths
Definition gamg.hpp:57
bool reuse_interpolation
Definition gamg.hpp:86
bool point_block_smoother
Definition gamg.hpp:79