35#include <deal.II/multigrid/mg_transfer_component.templates.h>
78 template <
int dim,
typename number,
int spacedim>
80 reinit_vector_by_components(
83 const std::vector<bool> &sel,
84 const std::vector<unsigned int> &target_comp,
85 std::vector<std::vector<types::global_dof_index>> &ndofs)
87 std::vector<bool> selected = sel;
88 std::vector<unsigned int> target_component = target_comp;
100 if (target_component.empty())
102 target_component.resize(ncomp);
103 for (
unsigned int i = 0; i < ncomp; ++i)
104 target_component[i] = i;
109 if (selected.empty())
111 selected.resize(target_component.size());
112 std::fill_n(selected.begin(), ncomp,
false);
113 for (
const unsigned int component : target_component)
114 selected[component] =
true;
117 Assert(selected.size() == target_component.size(),
121 const unsigned int n_selected =
122 std::accumulate(selected.begin(), selected.end(), 0u);
126 std::vector<std::vector<types::global_dof_index>> new_dofs(
128 std::vector<types::global_dof_index>(target_component.size()));
129 std::swap(ndofs, new_dofs);
133 for (
unsigned int level = v.min_level(); level <= v.max_level(); ++level)
135 v[level].reinit(n_selected, 0);
137 for (
unsigned int i = 0;
138 i < selected.size() && (k < v[level].
n_blocks());
143 v[level].block(k++).reinit(ndofs[level][i]);
145 v[level].collect_sizes();
177 template <
int dim,
typename number,
int spacedim>
179 reinit_vector_by_components(
183 const std::vector<unsigned int> &target_component,
184 std::vector<std::vector<types::global_dof_index>> &ndofs)
187 ExcMessage(
"The component mask does not have the correct size."));
189 unsigned int selected_block = 0;
190 for (
unsigned int i = 0; i < target_component.size(); ++i)
191 if (component_mask[i])
192 selected_block = target_component[i];
196 std::vector<std::vector<types::global_dof_index>> new_dofs(
198 std::vector<types::global_dof_index>(target_component.size()));
199 std::swap(ndofs, new_dofs);
203 for (
unsigned int level = v.min_level(); level <= v.max_level(); ++level)
205 v[level].reinit(ndofs[level][selected_block]);
211template <
typename number>
212template <
int dim,
class InVector,
int spacedim>
217 const InVector &src)
const
224 reinit_vector_by_components(
243 using IT = std::vector<
244 std::pair<types::global_dof_index, unsigned int>>::const_iterator;
248 dst[level](i->second) = src(i->first);
254template <
int dim,
int spacedim>
307 const unsigned int n_components =
314 ExcMessage(
"Component mask has wrong size."));
317 sizes.resize(n_levels);
318 for (
unsigned int l = 0; l < n_levels; ++l)
319 sizes[l].resize(n_components);
333 level_component_start = k;
374 for (
unsigned int i = 0; i < n_levels - 1; ++i)
383 std::vector<types::global_dof_index> dof_indices_parent(dofs_per_cell);
384 std::vector<types::global_dof_index> dof_indices_child(dofs_per_cell);
393 for (
unsigned int level = 0; level < n_levels - 1; ++level)
404 for (
unsigned int i = 0; i < n_components; ++i)
405 for (
unsigned int j = 0; j < n_components; ++j)
408 sizes[level + 1][i],
sizes[level][j], dofs_per_cell + 1);
417 cell != mg_dof.
end(level);
419 if (cell->has_children())
421 cell->get_mg_dof_indices(dof_indices_parent);
423 for (
unsigned int child = 0; child < cell->n_children(); ++child)
430 child, cell->refinement_case());
432 cell->child(child)->get_mg_dof_indices(dof_indices_child);
437 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
438 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
439 if (prolongation(i, j) != 0)
441 const unsigned int icomp =
443 const unsigned int jcomp =
447 dof_indices_child[i], dof_indices_parent[j]);
457 cell != mg_dof.
end(level);
459 if (cell->has_children())
461 cell->get_mg_dof_indices(dof_indices_parent);
463 for (
unsigned int child = 0; child < cell->n_children(); ++child)
470 child, cell->refinement_case());
472 cell->child(child)->get_mg_dof_indices(dof_indices_child);
476 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
477 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
478 if (prolongation(i, j) != 0)
480 const unsigned int icomp =
482 const unsigned int jcomp =
486 dof_indices_child[i],
487 dof_indices_parent[j],
500 std::vector<std::vector<types::global_dof_index>> dofs_per_component(
502 std::vector<types::global_dof_index>(n_components));
507 for (
unsigned int level = 0; level < n_levels - 1; ++level)
512 for (
unsigned int iblock = 0; iblock < n_components; ++iblock)
513 for (
unsigned int jblock = 0; jblock < n_components; ++jblock)
514 if (iblock == jblock)
522 ->block(iblock, jblock)
525 ->block(iblock, jblock)
527 for (; begin != end; ++begin)
534 dofs_per_component[level]);
539 std::set<types::global_dof_index>::const_iterator
542 const bool is_boundary_index =
545 if (is_boundary_index)
548 ->block(iblock, jblock)
549 .set(i, column_number, 0);
560template <
typename number>
561template <
int dim,
int spacedim>
566 unsigned int mg_select,
567 const std::vector<unsigned int> &t_component,
568 const std::vector<unsigned int> &mg_t_component,
569 const std::vector<std::set<types::global_dof_index>> &bdry_indices)
582 std::vector<bool> tmp(ncomp,
false);
583 for (
unsigned int c = 0; c < ncomp; ++c)
590 std::vector<bool> tmp(ncomp,
false);
591 for (
unsigned int c = 0; c < ncomp; ++c)
631 std::vector<types::global_dof_index> temp_copy_indices;
632 std::vector<types::global_dof_index> global_dof_indices(fe.
n_dofs_per_cell());
633 std::vector<types::global_dof_index> level_dof_indices(fe.
n_dofs_per_cell());
643 temp_copy_indices.resize(0);
644 temp_copy_indices.resize(mg_dof.
n_dofs(level),
649 for (; level_cell != level_end; ++level_cell)
655 level_cell->get_dof_indices(global_dof_indices);
656 level_cell->get_mg_dof_indices(level_dof_indices);
660 const unsigned int component =
669 temp_copy_indices[level_dof_indices[i] - level_start] =
670 global_dof_indices[i] - global_start;
678 std::count_if(temp_copy_indices.begin(),
679 temp_copy_indices.end(),
681 return index != numbers::invalid_dof_index;
688 std::pair<types::global_dof_index, unsigned int>(
689 temp_copy_indices[i], i);
697#include "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
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
std::atomic< unsigned int > counter
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)
const types::global_dof_index invalid_dof_index
unsigned int global_dof_index