17 #include <deal.II/base/function.h> 18 #include <deal.II/base/logstream.h> 20 #include <deal.II/dofs/dof_accessor.h> 21 #include <deal.II/dofs/dof_tools.h> 23 #include <deal.II/fe/fe.h> 25 #include <deal.II/grid/tria.h> 26 #include <deal.II/grid/tria_iterator.h> 28 #include <deal.II/lac/block_sparse_matrix.h> 29 #include <deal.II/lac/block_vector.h> 30 #include <deal.II/lac/dynamic_sparsity_pattern.h> 31 #include <deal.II/lac/la_parallel_block_vector.h> 32 #include <deal.II/lac/la_parallel_vector.h> 33 #include <deal.II/lac/sparse_matrix.h> 34 #include <deal.II/lac/sparsity_tools.h> 35 #include <deal.II/lac/trilinos_epetra_vector.h> 36 #include <deal.II/lac/trilinos_parallel_block_vector.h> 37 #include <deal.II/lac/trilinos_vector.h> 38 #include <deal.II/lac/vector.h> 40 #include <deal.II/multigrid/mg_tools.h> 41 #include <deal.II/multigrid/mg_transfer.h> 45 DEAL_II_NAMESPACE_OPEN
48 template <
typename VectorType>
52 this->mg_constrained_dofs = &mg_c;
57 template <
typename VectorType>
62 this->mg_constrained_dofs = &mg_c;
67 template <
typename VectorType>
72 this->mg_constrained_dofs = &mg_c;
77 template <
typename VectorType>
83 initialize_constraints(mg_c);
88 template <
typename VectorType>
93 prolongation_matrices.resize(0);
94 prolongation_sparsities.resize(0);
95 interface_dofs.resize(0);
100 template <
typename VectorType>
104 const VectorType & src)
const 106 Assert((to_level >= 1) && (to_level <= prolongation_matrices.size()),
107 ExcIndexRange(to_level, 1, prolongation_matrices.size() + 1));
109 prolongation_matrices[to_level - 1]->vmult(dst, src);
114 template <
typename VectorType>
118 const VectorType & src)
const 120 Assert((from_level >= 1) && (from_level <= prolongation_matrices.size()),
121 ExcIndexRange(from_level, 1, prolongation_matrices.size() + 1));
124 prolongation_matrices[from_level - 1]->Tvmult_add(dst, src);
136 const unsigned int level,
137 std::vector<types::global_dof_index> &dof_indices)
139 if (mg_constrained_dofs !=
nullptr &&
142 for (
auto &ind : dof_indices)
158 template <
typename VectorType>
159 template <
int dim,
int spacedim>
165 const unsigned int dofs_per_cell = mg_dof.
get_fe().dofs_per_cell;
167 this->sizes.resize(n_levels);
168 for (
unsigned int l = 0; l < n_levels; ++l)
169 this->sizes[l] = mg_dof.
n_dofs(l);
181 prolongation_matrices.resize(0);
182 prolongation_sparsities.resize(0);
183 prolongation_matrices.reserve(n_levels - 1);
184 prolongation_sparsities.reserve(n_levels - 1);
186 for (
unsigned int i = 0; i < n_levels - 1; ++i)
188 prolongation_sparsities.emplace_back(
190 prolongation_matrices.emplace_back(
197 std::vector<types::global_dof_index> dof_indices_parent(dofs_per_cell);
198 std::vector<types::global_dof_index> dof_indices_child(dofs_per_cell);
199 std::vector<types::global_dof_index> entries(dofs_per_cell);
206 for (
unsigned int level = 0; level < n_levels - 1; ++level)
218 level_p1_relevant_dofs);
221 level_p1_relevant_dofs);
223 for (cell = mg_dof.
begin(level); cell != endc; ++cell)
224 if (cell->has_children() &&
227 cell->level_subdomain_id() ==
230 cell->get_mg_dof_indices(dof_indices_parent);
232 replace(this->mg_constrained_dofs, level, dof_indices_parent);
234 Assert(cell->n_children() ==
237 for (
unsigned int child = 0; child < cell->n_children(); ++child)
241 mg_dof.
get_fe().get_prolongation_matrix(
242 child, cell->refinement_case());
244 Assert(prolongation.
n() != 0, ExcNoProlongation());
246 cell->child(child)->get_mg_dof_indices(dof_indices_child);
248 replace(this->mg_constrained_dofs,
255 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
258 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
259 if (prolongation(i, j) != 0)
260 entries.push_back(dof_indices_parent[j]);
268 #ifdef DEAL_II_WITH_MPI 269 if (internal::MatrixSelector<
270 VectorType>::requires_distributed_sparsity_pattern)
281 MPI_Comm communicator = dist_tria !=
nullptr ?
286 const std::vector<::IndexSet>
287 &locally_owned_mg_dofs_per_processor =
289 std::vector<::types::global_dof_index>
290 n_locally_owned_mg_dofs_per_processor(
291 locally_owned_mg_dofs_per_processor.size(), 0);
293 for (
size_t index = 0;
294 index < n_locally_owned_mg_dofs_per_processor.size();
297 n_locally_owned_mg_dofs_per_processor[index] =
298 locally_owned_mg_dofs_per_processor[index].n_elements();
302 ::SparsityTools::distribute_sparsity_pattern(
304 n_locally_owned_mg_dofs_per_processor,
310 internal::MatrixSelector<VectorType>::reinit(
311 *prolongation_matrices[level],
312 *prolongation_sparsities[level],
329 for (cell = mg_dof.
begin(level); cell != endc; ++cell)
330 if (cell->has_children() &&
333 cell->level_subdomain_id() ==
336 cell->get_mg_dof_indices(dof_indices_parent);
338 replace(this->mg_constrained_dofs, level, dof_indices_parent);
340 Assert(cell->n_children() ==
343 for (
unsigned int child = 0; child < cell->n_children(); ++child)
346 prolongation = mg_dof.
get_fe().get_prolongation_matrix(
347 child, cell->refinement_case());
349 if (this->mg_constrained_dofs !=
nullptr &&
350 this->mg_constrained_dofs->have_boundary_indices())
351 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
352 if (this->mg_constrained_dofs->is_boundary_index(
353 level, dof_indices_parent[j]))
354 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
355 prolongation(i, j) = 0.;
357 cell->child(child)->get_mg_dof_indices(dof_indices_child);
359 replace(this->mg_constrained_dofs,
364 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
365 prolongation_matrices[level]->
set(dof_indices_child[i],
367 dof_indices_parent.data(),
375 this->fill_and_communicate_copy_indices(mg_dof);
380 template <
typename VectorType>
384 for (
unsigned int level = 0; level < prolongation_matrices.size(); ++level)
386 os <<
"Level " << level << std::endl;
387 prolongation_matrices[level]->print(os);
394 template <
typename VectorType>
399 for (
unsigned int i = 0; i < prolongation_matrices.size(); ++i)
400 result += prolongation_matrices[i]->memory_consumption() +
401 prolongation_sparsities[i]->memory_consumption();
408 #include "mg_transfer_prebuilt.inst" 411 DEAL_II_NAMESPACE_CLOSE
void initialize_constraints(const MGConstrainedDoFs &mg_constrained_dofs)
std::size_t memory_consumption() const
MGTransferPrebuilt()=default
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_unique_and_sorted=false)
const AffineConstraints< double > & get_level_constraint_matrix(const unsigned int level) const
const types::subdomain_id invalid_subdomain_id
void build_matrices(const DoFHandler< dim, spacedim > &mg_dof)
const Triangulation< dim, spacedim > & get_triangulation() const
static::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
virtual void restrict_and_add(const unsigned int from_level, VectorType &dst, const VectorType &src) const override
virtual MPI_Comm get_communicator() const
void print_matrices(std::ostream &os) const
const IndexSet & row_index_set() const
#define Assert(cond, exc)
types::global_dof_index n_dofs() const
void reinit(const size_type m, const size_type n, const IndexSet &rowset=IndexSet())
cell_iterator end() const
virtual void prolongate(const unsigned int to_level, VectorType &dst, const VectorType &src) const override
const std::vector< IndexSet > & locally_owned_mg_dofs_per_processor(const unsigned int level) const
cell_iterator begin(const unsigned int level=0) const
const FiniteElement< dim, spacedim > & get_fe(const unsigned int index=0) const
bool is_identity_constrained(const size_type index) const
static::ExceptionBase & ExcNotImplemented()
const std::vector< std::pair< size_type, number > > * get_constraint_entries(const size_type line) const
std::size_t memory_consumption() const
static::ExceptionBase & ExcInternalError()
size_type n_constraints() const