33#include <deal.II/multigrid/mg_transfer_component.templates.h>
70 template <
int dim,
typename number,
int spacedim>
72 reinit_vector_by_components(
76 const std::vector<unsigned int> &target_component,
77 std::vector<std::vector<types::global_dof_index>> &ndofs)
80 ExcMessage(
"The component mask does not have the correct size."));
82 unsigned int selected_block = 0;
83 for (
unsigned int i = 0; i < target_component.size(); ++i)
84 if (component_mask[i])
85 selected_block = target_component[i];
89 std::vector<std::vector<types::global_dof_index>> new_dofs(
91 std::vector<types::global_dof_index>(target_component.size()));
92 std::swap(ndofs, new_dofs);
96 for (
unsigned int level = v.min_level();
level <= v.max_level(); ++
level)
104template <
typename number>
105template <
int dim,
class InVector,
int spacedim>
110 const InVector &src)
const
115 ExcMatricesNotBuilt());
117 reinit_vector_by_components(
118 mg_dof_handler, dst, mg_component_mask, mg_target_component, sizes);
136 using IT = std::vector<
137 std::pair<types::global_dof_index, unsigned int>>::const_iterator;
138 for (IT i = copy_to_and_from_indices[
level].
begin();
139 i != copy_to_and_from_indices[
level].end();
141 dst[
level](i->second) = src(i->first);
147template <
int dim,
int spacedim>
200 const unsigned int n_components =
207 ExcMessage(
"Component mask has wrong size."));
210 sizes.resize(n_levels);
211 for (
unsigned int l = 0; l < n_levels; ++l)
212 sizes[l].resize(n_components);
226 level_component_start = k;
267 for (
unsigned int i = 0; i < n_levels - 1; ++i)
276 std::vector<types::global_dof_index> dof_indices_parent(dofs_per_cell);
277 std::vector<types::global_dof_index> dof_indices_child(dofs_per_cell);
297 for (
unsigned int i = 0; i < n_components; ++i)
298 for (
unsigned int j = 0; j < n_components; ++j)
312 if (cell->has_children())
314 cell->get_mg_dof_indices(dof_indices_parent);
316 for (
unsigned int child = 0; child < cell->n_children(); ++child)
323 child, cell->refinement_case());
325 cell->child(child)->get_mg_dof_indices(dof_indices_child);
330 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
331 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
332 if (prolongation(i, j) != 0)
334 const unsigned int icomp =
336 const unsigned int jcomp =
340 dof_indices_child[i], dof_indices_parent[j]);
352 if (cell->has_children())
354 cell->get_mg_dof_indices(dof_indices_parent);
356 for (
unsigned int child = 0; child < cell->n_children(); ++child)
363 child, cell->refinement_case());
365 cell->child(child)->get_mg_dof_indices(dof_indices_child);
369 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
370 for (
unsigned int j = 0; j < dofs_per_cell; ++j)
371 if (prolongation(i, j) != 0)
373 const unsigned int icomp =
375 const unsigned int jcomp =
379 dof_indices_child[i],
380 dof_indices_parent[j],
393 std::vector<std::vector<types::global_dof_index>> dofs_per_component(
395 std::vector<types::global_dof_index>(n_components));
405 for (
unsigned int iblock = 0; iblock < n_components; ++iblock)
406 for (
unsigned int jblock = 0; jblock < n_components; ++jblock)
407 if (iblock == jblock)
415 ->block(iblock, jblock)
418 ->block(iblock, jblock)
427 dofs_per_component[
level]);
432 std::set<types::global_dof_index>::const_iterator
435 const bool is_boundary_index =
438 if (is_boundary_index)
441 ->block(iblock, jblock)
442 .set(i, column_number, 0);
453template <
typename number>
454template <
int dim,
int spacedim>
459 unsigned int mg_select,
460 const std::vector<unsigned int> &t_component,
461 const std::vector<unsigned int> &mg_t_component,
462 const std::vector<std::set<types::global_dof_index>> &bdry_indices)
467 target_component = t_component;
468 mg_target_component = mg_t_component;
469 boundary_indices = bdry_indices;
471 selected_component = select;
472 mg_selected_component = mg_select;
475 std::vector<bool> tmp(ncomp,
false);
476 for (
unsigned int c = 0; c < ncomp; ++c)
477 if (t_component[c] == selected_component)
483 std::vector<bool> tmp(ncomp,
false);
484 for (
unsigned int c = 0; c < ncomp; ++c)
485 if (mg_t_component[c] == mg_selected_component)
494 for (
unsigned int i = 0; i < target_component.size(); ++i)
496 if (target_component[i] == select)
498 selected_component = i;
503 for (
unsigned int i = 0; i < mg_target_component.size(); ++i)
505 if (mg_target_component[i] == mg_select)
507 mg_selected_component = i;
517 interface_dofs[l].clear();
518 interface_dofs[l].set_size(mg_dof.
n_dofs(l));
524 std::vector<types::global_dof_index> temp_copy_indices;
525 std::vector<types::global_dof_index> global_dof_indices(fe.
n_dofs_per_cell());
526 std::vector<types::global_dof_index> level_dof_indices(fe.
n_dofs_per_cell());
530 copy_to_and_from_indices[
level].clear();
536 temp_copy_indices.resize(0);
542 for (; level_cell != level_end; ++level_cell)
548 level_cell->get_dof_indices(global_dof_indices);
549 level_cell->get_mg_dof_indices(level_dof_indices);
553 const unsigned int component =
555 if (component_mask[component] &&
556 !interface_dofs[
level].is_element(level_dof_indices[i]))
559 mg_component_start[
level][mg_target_component[component]];
561 component_start[target_component[component]];
562 temp_copy_indices[level_dof_indices[i] - level_start] =
563 global_dof_indices[i] - global_start;
571 std::count_if(temp_copy_indices.begin(),
572 temp_copy_indices.end(),
574 return index != numbers::invalid_dof_index;
576 copy_to_and_from_indices[
level].resize(n_active_dofs);
580 copy_to_and_from_indices[
level][counter++] =
581 std::pair<types::global_dof_index, unsigned int>(
582 temp_copy_indices[i], i);
590#include "multigrid/mg_transfer_component.inst"
* x_component_mask set(0, true)
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 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
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 > >())
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 & ExcMessage(std::string arg1)
typename ActiveSelector::cell_iterator cell_iterator
typename ActiveSelector::active_cell_iterator active_cell_iterator
constexpr types::global_dof_index invalid_dof_index