PolyDEAL
 
Loading...
Searching...
No Matches
multigrid_amg.cc
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) XXXX - YYYY by the polyDEAL authors
5//
6// This file is part of the polyDEAL library.
7//
8// Detailed license information governing the source code
9// can be found in LICENSE.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
14
15#include <multigrid_amg.h>
16
17namespace dealii
18{
19
20
21
22 template <int dim, typename VectorType>
25 const std::vector<DoFHandler<dim> *> &dof_handlers_)
26 {
27 Assert(transfer_matrices_.n_levels() > 0, ExcInternalError());
28 transfer_matrices.resize(0, dof_handlers_.size());
29 dof_handlers.resize(dof_handlers_.size());
30
31 for (unsigned int l = transfer_matrices_.min_level();
32 l <= transfer_matrices_.max_level();
33 ++l)
34 {
35 // std::cout << "l in build transfers: " << l << std::endl;
36 transfer_matrices[l] = transfer_matrices_[l];
37 dof_handlers[l] = dof_handlers_[l];
38 }
39 }
40
41
42
43 template <int dim, typename VectorType>
45 const MGLevelObject<TrilinosWrappers::SparseMatrix> &transfer_matrices_,
46 const std::vector<DoFHandler<dim> *> &dof_handlers_)
47 {
48 Assert(transfer_matrices_.n_levels() > 0, ExcInternalError());
49 transfer_matrices.resize(0, dof_handlers_.size());
50 dof_handlers.resize(dof_handlers_.size());
51
52 for (unsigned int l = transfer_matrices_.min_level();
53 l <= transfer_matrices_.max_level();
54 ++l)
55 {
56 // std::cout << "l in build transfers: " << l << std::endl;
57 transfer_matrices[l] =
58 const_cast<dealii::TrilinosWrappers::SparseMatrix *>(
59 &transfer_matrices_[l]);
60 dof_handlers[l] = dof_handlers_[l];
61 }
62 }
63
64
65
66 template <int dim, typename VectorType>
67 void
69 const unsigned int to_level,
70 VectorType &dst,
71 const VectorType &src) const
72 {
73 dst = typename VectorType::value_type(0.0);
74 prolongate_and_add(to_level, dst, src);
75 }
76
77
78
79 template <int dim, typename VectorType>
80 void
82 const unsigned int to_level,
83 VectorType &dst,
84 const VectorType &src) const
85 {
86 Assert(transfer_matrices[to_level - 1] != nullptr,
87 ExcMessage("Transfer matrix has not been initialized."));
88 transfer_matrices[to_level - 1]->vmult_add(dst, src);
89 }
90
91
92
93 template <int dim, typename VectorType>
94 void
96 const unsigned int from_level,
97 VectorType &dst,
98 const VectorType &src) const
99 {
100 // std::cout << "from_level " << from_level << std::endl;
101 // std::cout << "Rows: " << transfer_matrices[from_level - 1]->m()
102 // << std::endl;
103 // std::cout << "Cols: " << transfer_matrices[from_level - 1]->n()
104 // << std::endl;
105 Assert(transfer_matrices[from_level - 1] != nullptr,
106 ExcMessage("Matrix has not been initialized."));
107 transfer_matrices[from_level - 1]->Tvmult_add(dst, src);
108 }
109
110
111
112 template <int dim, typename VectorType>
113 void
115 const DoFHandler<dim> &dof_handler,
117 const VectorType &src) const
118 {
119 (void)dof_handler; // required by interface, but not needed.
120 // std::cout << "Before copy_to_mg() " << std::endl;
121 for (unsigned int level = dst.min_level(); level <= dst.max_level();
122 ++level)
123 {
124 // std::cout << "level = " << level << std::endl;
125 dst[level].reinit(dof_handlers[level]->locally_owned_dofs(),
126 dof_handlers[level]->get_communicator());
127 }
128
129 if constexpr (std::is_same_v<VectorType, TrilinosWrappers::MPI::Vector>)
130 dst[dst.max_level()] = src;
131 else if constexpr (std::is_same_v<
132 VectorType,
134 dst[dst.max_level()].copy_locally_owned_data_from(src);
135 else
137 }
138
139
140
141 template <int dim, typename VectorType>
142 void
144 const DoFHandler<dim> &dof_handler,
145 VectorType &dst,
146 const MGLevelObject<VectorType> &src) const
147 {
148 (void)dof_handler;
149 if constexpr (std::is_same_v<VectorType, TrilinosWrappers::MPI::Vector>)
150 dst = src[src.max_level()];
151 else if constexpr (std::is_same_v<
152 VectorType,
154 dst.copy_locally_owned_data_from(src[src.max_level()]);
155 else
157 }
158
159
160
161 // explicit instantiations for doubles and floats
162 // template class MatrixFreeProjector<1, double>;
163 // template class MatrixFreeProjector<2, double>;
164 // template class MatrixFreeProjector<3, double>;
165
166 template class MGTransferAgglomeration<
167 1,
169 template class MGTransferAgglomeration<
170 2,
172 template class MGTransferAgglomeration<
173 3,
175
176 // Trilinos vectors instantiations
180} // namespace dealii
unsigned int max_level() const
unsigned int min_level() const
unsigned int n_levels() const
void prolongate(const unsigned int to_level, VectorType &dst, const VectorType &src) const override
void copy_from_mg(const DoFHandler< dim > &dof_handler, VectorType &dst, const MGLevelObject< VectorType > &src) const
MGTransferAgglomeration(const MGLevelObject< TrilinosWrappers::SparseMatrix * > &transfer_matrices, const std::vector< DoFHandler< dim > * > &dof_handlers)
void restrict_and_add(const unsigned int from_level, VectorType &dst, const VectorType &src) const override
void prolongate_and_add(const unsigned int to_level, VectorType &dst, const VectorType &src) const override
void copy_to_mg(const DoFHandler< dim > &dof_handler, MGLevelObject< VectorType > &dst, const VectorType &src) const
unsigned int level
#define Assert(cond, exc)
#define DEAL_II_NOT_IMPLEMENTED()
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)