34#include <deal.II/multigrid/mg_transfer_block.templates.h>
52 template <
int dim,
typename number,
int spacedim>
54 reinit_vector_by_blocks(
57 const std::vector<bool> & sel,
58 std::vector<std::vector<types::global_dof_index>> &ndofs)
60 std::vector<bool> selected = sel;
62 const unsigned int n_selected =
63 std::accumulate(selected.begin(), selected.end(), 0u);
65 if (ndofs.size() == 0)
67 std::vector<std::vector<types::global_dof_index>> new_dofs(
69 std::vector<types::global_dof_index>(selected.size()));
70 std::swap(ndofs, new_dofs);
74 for (
unsigned int level = v.min_level();
level <= v.max_level(); ++
level)
76 v[
level].reinit(n_selected, 0);
78 for (
unsigned int i = 0;
79 i < selected.size() && (k < v[
level].n_blocks());
86 v[
level].collect_sizes();
98 template <
int dim,
typename number,
int spacedim>
100 reinit_vector_by_blocks(
103 const unsigned int selected_block,
104 std::vector<std::vector<types::global_dof_index>> &ndofs)
109 std::vector<bool> selected(n_blocks,
false);
110 selected[selected_block] =
true;
112 if (ndofs.size() == 0)
114 std::vector<std::vector<types::global_dof_index>> new_dofs(
116 std::vector<types::global_dof_index>(selected.size()));
117 std::swap(ndofs, new_dofs);
121 for (
unsigned int level = v.min_level();
level <= v.max_level(); ++
level)
123 v[
level].reinit(ndofs[
level][selected_block]);
129template <
typename number>
130template <
int dim,
typename number2,
int spacedim>
137 reinit_vector_by_blocks(dof_handler, dst, selected_block, sizes);
146 for (IT i = copy_indices[selected_block][
level].begin();
147 i != copy_indices[selected_block][
level].end();
149 dst[
level](i->second) = src.
block(selected_block)(i->first);
155template <
typename number>
156template <
int dim,
typename number2,
int spacedim>
163 reinit_vector_by_blocks(dof_handler, dst, selected_block, sizes);
171 for (IT i = copy_indices[selected_block][
level].begin();
172 i != copy_indices[selected_block][
level].end();
174 dst[
level](i->second) = src(i->first);
180template <
typename number>
181template <
int dim,
typename number2,
int spacedim>
188 reinit_vector_by_blocks(dof_handler, dst, selected, sizes);
193 for (
unsigned int block = 0; block < selected.size(); ++block)
195 for (IT i = copy_indices[block][
level].begin();
196 i != copy_indices[block][
level].end();
198 dst[
level].block(mg_block[block])(i->second) =
199 src.
block(block)(i->first);
205template <
int dim,
int spacedim>
210 const unsigned int n_blocks = fe.
n_blocks();
222 for (
unsigned int i = 0; i < n_blocks; ++i)
230 sizes.resize(n_levels, std::vector<types::global_dof_index>(fe.
n_blocks()));
243 level_block_start = k;
265 for (
unsigned int block = 0; block < n_blocks; ++block)
286 for (
unsigned int i = 0; i < n_levels - 1; ++i)
295 std::vector<types::global_dof_index> dof_indices_parent(dofs_per_cell);
296 std::vector<types::global_dof_index> dof_indices_child(dofs_per_cell);
317 for (
unsigned int i = 0; i < n_blocks; ++i)
318 for (
unsigned int j = 0; j < n_blocks; ++j)
332 if (cell->has_children())
334 cell->get_mg_dof_indices(dof_indices_parent);
336 Assert(cell->n_children() ==
339 for (
unsigned int child = 0; child < cell->n_children(); ++child)
346 child, cell->refinement_case());
348 cell->child(child)->get_mg_dof_indices(dof_indices_child);
353 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
354 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
355 if (prolongation(i, j) != 0)
357 const unsigned int icomp =
359 const unsigned int jcomp =
361 if ((icomp == jcomp) &&
selected[icomp])
363 dof_indices_child[i], dof_indices_parent[j]);
375 if (cell->has_children())
377 cell->get_mg_dof_indices(dof_indices_parent);
379 Assert(cell->n_children() ==
382 for (
unsigned int child = 0; child < cell->n_children(); ++child)
389 child, cell->refinement_case());
391 cell->child(child)->get_mg_dof_indices(dof_indices_child);
395 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
396 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
397 if (prolongation(i, j) != 0)
399 const unsigned int icomp =
401 const unsigned int jcomp =
403 if ((icomp == jcomp) &&
selected[icomp])
405 dof_indices_child[i],
406 dof_indices_parent[j],
418 std::vector<types::global_dof_index> constrain_indices;
419 std::vector<std::vector<bool>> constraints_per_block(n_blocks);
431 constrain_indices.resize(0);
436 for (; dof != endd; ++dof)
437 constrain_indices[*dof] = 1;
439 unsigned int index = 0;
440 for (
unsigned int block = 0; block < n_blocks; ++block)
444 constraints_per_block[block].resize(0);
445 constraints_per_block[block].resize(n_dofs,
false);
447 constraints_per_block[block][i] =
448 (constrain_indices[index] == 1);
454 ->block(block, block)
458 for (; start_row != end_row; ++start_row)
460 if (constraints_per_block[block][start_row->column()])
461 start_row->value() = 0.;
469template <
typename number>
470template <
int dim,
int spacedim>
479 selected_block = select;
480 selected.resize(n_blocks,
false);
481 selected[select] =
true;
485 std::vector<types::global_dof_index> temp_copy_indices;
486 std::vector<types::global_dof_index> global_dof_indices(fe.
n_dofs_per_cell());
487 std::vector<types::global_dof_index> level_dof_indices(fe.
n_dofs_per_cell());
497 temp_copy_indices.resize(0);
498 temp_copy_indices.resize(sizes[
level][selected_block],
503 for (; level_cell != level_end; ++level_cell)
509 level_cell->get_dof_indices(global_dof_indices);
510 level_cell->get_mg_dof_indices(level_dof_indices);
517 if (mg_constrained_dofs !=
nullptr)
519 if (!mg_constrained_dofs->at_refinement_edge(
520 level, level_dof_indices[i]))
521 temp_copy_indices[level_dof_indices[i] -
522 mg_block_start[
level][block]] =
523 global_dof_indices[i] - block_start[block];
526 temp_copy_indices[level_dof_indices[i] -
527 mg_block_start[
level][block]] =
528 global_dof_indices[i] - block_start[block];
540 std::count_if(temp_copy_indices.begin(),
541 temp_copy_indices.end(),
543 return index != numbers::invalid_dof_index;
545 copy_indices[selected_block][
level].resize(n_active_dofs);
549 copy_indices[selected_block][
level][counter++] =
550 std::pair<types::global_dof_index, unsigned int>(
551 temp_copy_indices[i], i);
557template <
typename number>
558template <
int dim,
int spacedim>
561 const std::vector<bool> & sel)
568 Assert(sel.size() == n_blocks,
572 if (selected.size() == 0)
573 selected = std::vector<bool>(n_blocks,
true);
577 std::vector<std::vector<types::global_dof_index>> temp_copy_indices(n_blocks);
578 std::vector<types::global_dof_index> global_dof_indices(fe.
n_dofs_per_cell());
579 std::vector<types::global_dof_index> level_dof_indices(fe.
n_dofs_per_cell());
588 for (
unsigned int block = 0; block < n_blocks; ++block)
591 temp_copy_indices[block].resize(0);
592 temp_copy_indices[block].resize(sizes[
level][block],
598 for (; level_cell != level_end; ++level_cell)
604 level_cell->get_dof_indices(global_dof_indices);
605 level_cell->get_mg_dof_indices(level_dof_indices);
611 temp_copy_indices[block][level_dof_indices[i] -
612 mg_block_start[
level][block]] =
613 global_dof_indices[i] - block_start[block];
617 for (
unsigned int block = 0; block < n_blocks; ++block)
621 std::count_if(temp_copy_indices[block].begin(),
622 temp_copy_indices[block].end(),
626 copy_indices[block][
level].resize(n_active_dofs);
629 i < temp_copy_indices[block].size();
632 copy_indices[block][
level][counter++] =
633 std::pair<types::global_dof_index, unsigned int>(
634 temp_copy_indices[block][i], i);
643#include "mg_transfer_block.inst"
BlockType & block(const unsigned int i)
cell_iterator end() const
const FiniteElement< dim, spacedim > & get_fe(const types::fe_index index=0) const
const Triangulation< dim, spacedim > & get_triangulation() const
active_cell_iterator begin_active(const unsigned int level=0) const
active_cell_iterator end_active(const unsigned int level) const
cell_iterator begin(const unsigned int level=0) const
unsigned int n_dofs_per_cell() const
unsigned int n_blocks() const
std::pair< unsigned int, types::global_dof_index > system_to_block_index(const unsigned int component) const
virtual const FullMatrix< double > & get_prolongation_matrix(const unsigned int child, const RefinementCase< dim > &refinement_case=RefinementCase< dim >::isotropic_refinement) const
size_type n_elements() const
ElementIterator begin() const
ElementIterator end() const
bool have_boundary_indices() const
const IndexSet & get_boundary_indices(const unsigned int level) const
std::vector< unsigned int > mg_block
std::vector< std::vector< types::global_dof_index > > sizes
void build(const DoFHandler< dim, spacedim > &dof_handler)
std::vector< bool > selected
std::vector< types::global_dof_index > block_start
std::vector< std::shared_ptr< BlockSparseMatrix< double > > > prolongation_matrices
std::vector< std::shared_ptr< BlockSparsityPattern > > prolongation_sparsities
SmartPointer< const MGConstrainedDoFs, MGTransferBlockBase > mg_constrained_dofs
std::vector< std::vector< types::global_dof_index > > mg_block_start
std::vector< std::vector< std::vector< std::pair< unsigned int, unsigned int > > > > copy_indices
void copy_to_mg(const DoFHandler< dim, spacedim > &dof_handler, MGLevelObject< Vector< number > > &dst, const Vector< number2 > &src) const
void build(const DoFHandler< dim, spacedim > &dof_handler, unsigned int selected)
void build(const DoFHandler< dim, spacedim > &dof_handler, const std::vector< bool > &selected)
void copy_to_mg(const DoFHandler< dim, spacedim > &dof_handler, MGLevelObject< BlockVector< number > > &dst, const BlockVector< number2 > &src) const
unsigned int n_levels() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
typename ActiveSelector::cell_iterator cell_iterator
typename ActiveSelector::active_cell_iterator active_cell_iterator
std::enable_if_t< IsBlockVector< VectorType >::value, unsigned int > n_blocks(const VectorType &vector)
static const unsigned int invalid_unsigned_int
const types::global_dof_index invalid_dof_index