33#include <deal.II/multigrid/mg_transfer_component.templates.h>
76 template <
int dim,
typename number,
int spacedim>
78 reinit_vector_by_components(
81 const std::vector<bool> &sel,
82 const std::vector<unsigned int> &target_comp,
83 std::vector<std::vector<types::global_dof_index>> &ndofs)
85 std::vector<bool> selected = sel;
86 std::vector<unsigned int> target_component = target_comp;
98 if (target_component.empty())
100 target_component.resize(ncomp);
101 for (
unsigned int i = 0; i < ncomp; ++i)
102 target_component[i] = i;
107 if (selected.empty())
109 selected.resize(target_component.size());
110 std::fill_n(selected.begin(), ncomp,
false);
111 for (
const unsigned int component : target_component)
115 Assert(selected.size() == target_component.size(),
119 const unsigned int n_selected =
120 std::accumulate(selected.begin(), selected.end(), 0u);
124 std::vector<std::vector<types::global_dof_index>> new_dofs(
126 std::vector<types::global_dof_index>(target_component.size()));
127 std::swap(ndofs, new_dofs);
131 for (
unsigned int level = v.min_level(); level <= v.max_level(); ++level)
133 v[level].reinit(n_selected, 0);
135 for (
unsigned int i = 0;
136 i < selected.size() && (k < v[level].
n_blocks());
141 v[level].block(k++).reinit(ndofs[level][i]);
143 v[level].collect_sizes();
175 template <
int dim,
typename number,
int spacedim>
177 reinit_vector_by_components(
181 const std::vector<unsigned int> &target_component,
182 std::vector<std::vector<types::global_dof_index>> &ndofs)
185 ExcMessage(
"The component mask does not have the correct size."));
187 unsigned int selected_block = 0;
188 for (
unsigned int i = 0; i < target_component.size(); ++i)
189 if (component_mask[i])
190 selected_block = target_component[i];
194 std::vector<std::vector<types::global_dof_index>> new_dofs(
196 std::vector<types::global_dof_index>(target_component.size()));
197 std::swap(ndofs, new_dofs);
201 for (
unsigned int level = v.min_level(); level <= v.max_level(); ++level)
203 v[level].reinit(ndofs[level][selected_block]);
209template <
typename number>
210template <
int dim,
class InVector,
int spacedim>
215 const InVector &src)
const
222 reinit_vector_by_components(
241 using IT = std::vector<
242 std::pair<types::global_dof_index, unsigned int>>::const_iterator;
246 dst[level](i->second) = src(i->first);
252template <
int dim,
int spacedim>
305 const unsigned int n_components =
312 ExcMessage(
"Component mask has wrong size."));
315 sizes.resize(n_levels);
316 for (
unsigned int l = 0; l < n_levels; ++l)
317 sizes[l].resize(n_components);
331 level_component_start = k;
372 for (
unsigned int i = 0; i < n_levels - 1; ++i)
381 std::vector<types::global_dof_index> dof_indices_parent(
dofs_per_cell);
382 std::vector<types::global_dof_index> dof_indices_child(
dofs_per_cell);
391 for (
unsigned int level = 0; level < n_levels - 1; ++level)
402 for (
unsigned int i = 0; i < n_components; ++i)
403 for (
unsigned int j = 0; j < n_components; ++j)
415 cell != mg_dof.
end(level);
417 if (cell->has_children())
419 cell->get_mg_dof_indices(dof_indices_parent);
421 for (
unsigned int child = 0; child < cell->n_children(); ++child)
428 child, cell->refinement_case());
430 cell->child(child)->get_mg_dof_indices(dof_indices_child);
437 if (prolongation(i, j) != 0)
439 const unsigned int icomp =
441 const unsigned int jcomp =
445 dof_indices_child[i], dof_indices_parent[j]);
455 cell != mg_dof.
end(level);
457 if (cell->has_children())
459 cell->get_mg_dof_indices(dof_indices_parent);
461 for (
unsigned int child = 0; child < cell->n_children(); ++child)
468 child, cell->refinement_case());
470 cell->child(child)->get_mg_dof_indices(dof_indices_child);
476 if (prolongation(i, j) != 0)
478 const unsigned int icomp =
480 const unsigned int jcomp =
484 dof_indices_child[i],
485 dof_indices_parent[j],
498 std::vector<std::vector<types::global_dof_index>> dofs_per_component(
500 std::vector<types::global_dof_index>(n_components));
505 for (
unsigned int level = 0; level < n_levels - 1; ++level)
510 for (
unsigned int iblock = 0; iblock < n_components; ++iblock)
511 for (
unsigned int jblock = 0; jblock < n_components; ++jblock)
512 if (iblock == jblock)
520 ->block(iblock, jblock)
523 ->block(iblock, jblock)
532 dofs_per_component[level]);
537 std::set<types::global_dof_index>::const_iterator
540 const bool is_boundary_index =
543 if (is_boundary_index)
546 ->block(iblock, jblock)
547 .set(i, column_number, 0);
558template <
typename number>
559template <
int dim,
int spacedim>
564 unsigned int mg_select,
565 const std::vector<unsigned int> &t_component,
566 const std::vector<unsigned int> &mg_t_component,
567 const std::vector<std::set<types::global_dof_index>> &bdry_indices)
580 std::vector<bool> tmp(ncomp,
false);
581 for (
unsigned int c = 0; c < ncomp; ++c)
588 std::vector<bool> tmp(ncomp,
false);
589 for (
unsigned int c = 0; c < ncomp; ++c)
629 std::vector<types::global_dof_index> temp_copy_indices;
630 std::vector<types::global_dof_index> global_dof_indices(fe.
n_dofs_per_cell());
631 std::vector<types::global_dof_index> level_dof_indices(fe.
n_dofs_per_cell());
641 temp_copy_indices.resize(0);
642 temp_copy_indices.resize(mg_dof.
n_dofs(level),
647 for (; level_cell != level_end; ++level_cell)
653 level_cell->get_dof_indices(global_dof_indices);
654 level_cell->get_mg_dof_indices(level_dof_indices);
658 const unsigned int component =
667 temp_copy_indices[level_dof_indices[i] - level_start] =
668 global_dof_indices[i] - global_start;
676 std::count_if(temp_copy_indices.begin(),
677 temp_copy_indices.end(),
679 return index != numbers::invalid_dof_index;
686 std::pair<types::global_dof_index, unsigned int>(
687 temp_copy_indices[i], i);
695#include "multigrid/mg_transfer_component.inst"
size_type local_to_global(const unsigned int block, const size_type index) const
bool represents_n_components(const unsigned int n) const
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
types::global_dof_index n_dofs() const
cell_iterator begin(const unsigned int level=0) const
std::atomic< unsigned int > counter
unsigned int n_dofs_per_cell() const
unsigned int n_components() const
std::pair< unsigned int, unsigned int > system_to_component_index(const unsigned int index) const
virtual const FullMatrix< double > & get_prolongation_matrix(const unsigned int child, const RefinementCase< dim > &refinement_case=RefinementCase< dim >::isotropic_refinement) const
std::vector< unsigned int > mg_target_component
ComponentMask component_mask
ComponentMask mg_component_mask
std::vector< unsigned int > target_component
std::vector< types::global_dof_index > component_start
std::vector< std::shared_ptr< BlockSparseMatrix< double > > > prolongation_matrices
std::vector< std::vector< std::pair< types::global_dof_index, unsigned int > > > copy_to_and_from_indices
std::vector< std::vector< types::global_dof_index > > mg_component_start
std::vector< std::shared_ptr< BlockSparsityPattern > > prolongation_sparsities
void build(const DoFHandler< dim, spacedim > &dof_handler)
std::vector< std::vector< types::global_dof_index > > sizes
std::vector< std::set< types::global_dof_index > > boundary_indices
void do_copy_to_mg(const DoFHandler< dim, spacedim > &mg_dof, MGLevelObject< Vector< number > > &dst, const InVector &src) const
unsigned int mg_selected_component
unsigned int selected_component
void build(const DoFHandler< dim, spacedim > &dof, unsigned int selected, unsigned int mg_selected, const std::vector< unsigned int > &target_component=std::vector< unsigned int >(), const std::vector< unsigned int > &mg_target_component=std::vector< unsigned int >(), const std::vector< std::set< types::global_dof_index > > &boundary_indices=std::vector< std::set< types::global_dof_index > >())
void select(const unsigned int component, const unsigned int mg_component=numbers::invalid_unsigned_int)
std::vector< IndexSet > interface_dofs
SparseMatrixIterators::Iterator< number, false > iterator
unsigned int n_levels() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcMatricesNotBuilt()
static ::ExceptionBase & ExcMessage(std::string arg1)
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)
* * * ScaleZFunction< dim, Number, components >::ScaleZFunction * component(component)
constexpr types::global_dof_index invalid_dof_index
unsigned int global_dof_index
* const unsigned int dofs_per_cell