36#include <deal.II/multigrid/mg_transfer_component.templates.h>
79 template <
int dim,
typename number,
int spacedim>
84 const std::vector<bool> &
sel,
86 std::vector<std::vector<types::global_dof_index>> &
ndofs)
88 std::vector<bool> selected =
sel;
89 std::vector<unsigned int> target_component =
target_comp;
90 const unsigned int ncomp =
mg_dof.get_fe(0).n_components();
101 if (target_component.size() == 0)
103 target_component.resize(
ncomp);
104 for (
unsigned int i = 0; i <
ncomp; ++i)
105 target_component[i] = i;
110 if (selected.size() == 0)
112 selected.resize(target_component.size());
113 std::fill_n(selected.begin(),
ncomp,
false);
114 for (
const unsigned int component : target_component)
115 selected[component] =
true;
118 Assert(selected.size() == target_component.size(),
123 std::accumulate(selected.begin(), selected.end(), 0
u);
127 std::vector<std::vector<types::global_dof_index>>
new_dofs(
128 mg_dof.get_triangulation().n_levels(),
129 std::vector<types::global_dof_index>(target_component.size()));
134 for (
unsigned int level = v.min_level();
level <= v.max_level(); ++
level)
138 for (
unsigned int i = 0;
139 i < selected.size() && (
k < v[
level].n_blocks());
146 v[
level].collect_sizes();
178 template <
int dim,
typename number,
int spacedim>
184 const std::vector<unsigned int> & target_component,
185 std::vector<std::vector<types::global_dof_index>> &
ndofs)
188 ExcMessage(
"The component mask does not have the correct size."));
190 unsigned int selected_block = 0;
191 for (
unsigned int i = 0; i < target_component.size(); ++i)
192 if (component_mask[i])
193 selected_block = target_component[i];
197 std::vector<std::vector<types::global_dof_index>>
new_dofs(
198 mg_dof.get_triangulation().n_levels(),
199 std::vector<types::global_dof_index>(target_component.size()));
204 for (
unsigned int level = v.min_level();
level <= v.max_level(); ++
level)
212template <
typename number>
213template <
int dim,
class InVector,
int spacedim>
223 ExcMatricesNotBuilt());
226 mg_dof_handler, dst, mg_component_mask, mg_target_component, sizes);
244 using IT = std::vector<
247 i != copy_to_and_from_indices[
level].
end();
249 dst[
level](i->second) = src(i->first);
255template <
int dim,
int spacedim>
273 mg_dof.get_fe(0).n_components()));
293 mg_dof.get_fe(0).n_components()));
308 const unsigned int n_components =
311 const unsigned int dofs_per_cell = fe.n_dofs_per_cell();
312 const unsigned int n_levels =
mg_dof.get_triangulation().n_levels();
315 ExcMessage(
"Component mask has wrong size."));
318 sizes.resize(n_levels);
319 for (
unsigned int l = 0; l < n_levels; ++l)
320 sizes[l].resize(n_components);
375 for (
unsigned int i = 0; i < n_levels - 1; ++i)
405 for (
unsigned int i = 0; i < n_components; ++i)
406 for (
unsigned int j = 0;
j < n_components; ++
j)
420 if (cell->has_children())
424 for (
unsigned int child = 0; child < cell->n_children(); ++child)
430 mg_dof.get_fe().get_prolongation_matrix(
431 child, cell->refinement_case());
438 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
439 for (
unsigned int j = 0;
j < dofs_per_cell; ++
j)
440 if (prolongation(i,
j) != 0)
442 const unsigned int icomp =
443 fe.system_to_component_index(i).first;
444 const unsigned int jcomp =
445 fe.system_to_component_index(
j).first;
460 if (cell->has_children())
464 for (
unsigned int child = 0; child < cell->n_children(); ++child)
470 mg_dof.get_fe().get_prolongation_matrix(
471 child, cell->refinement_case());
477 for (
unsigned int i = 0; i < dofs_per_cell; ++i)
478 for (
unsigned int j = 0;
j < dofs_per_cell; ++
j)
479 if (prolongation(i,
j) != 0)
481 const unsigned int icomp =
482 fe.system_to_component_index(i).first;
483 const unsigned int jcomp =
484 fe.system_to_component_index(
j).first;
501 std::vector<std::vector<types::global_dof_index>> dofs_per_component(
502 mg_dof.get_triangulation().n_levels(),
503 std::vector<types::global_dof_index>(n_components));
528 for (; begin != end; ++begin)
535 dofs_per_component[
level]);
540 std::set<types::global_dof_index>::const_iterator
543 const bool is_boundary_index =
546 if (is_boundary_index)
550 .set(i, column_number, 0);
561template <
typename number>
562template <
int dim,
int spacedim>
570 const std::vector<std::set<types::global_dof_index>> &
bdry_indices)
573 unsigned int ncomp =
mg_dof.get_fe(0).n_components();
579 selected_component = select;
583 std::vector<bool> tmp(
ncomp,
false);
584 for (
unsigned int c = 0; c <
ncomp; ++c)
591 std::vector<bool> tmp(
ncomp,
false);
592 for (
unsigned int c = 0; c <
ncomp; ++c)
602 for (
unsigned int i = 0; i < target_component.size(); ++i)
604 if (target_component[i] == select)
606 selected_component = i;
611 for (
unsigned int i = 0; i < mg_target_component.size(); ++i)
615 mg_selected_component = i;
622 interface_dofs.resize(
mg_dof.get_triangulation().n_levels());
623 for (
unsigned int l = 0; l <
mg_dof.get_triangulation().n_levels(); ++l)
625 interface_dofs[l].clear();
626 interface_dofs[l].set_size(
mg_dof.n_dofs(l));
634 std::vector<types::global_dof_index> level_dof_indices(fe.n_dofs_per_cell());
638 copy_to_and_from_indices[
level].clear();
650 for (; level_cell !=
level_end; ++level_cell)
657 level_cell->get_mg_dof_indices(level_dof_indices);
659 for (
unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i)
661 const unsigned int component =
662 fe.system_to_component_index(i).first;
663 if (component_mask[component] &&
664 !interface_dofs[
level].is_element(level_dof_indices[i]))
667 mg_component_start[
level][mg_target_component[component]];
669 component_start[target_component[component]];
682 return index != numbers::invalid_dof_index;
688 copy_to_and_from_indices[
level][counter++] =
689 std::pair<types::global_dof_index, unsigned int>(
698#include "mg_transfer_component.inst"
void reinit(value_type *starting_element, const std::size_t n_elements)
const ElementType * const_iterator
bool represents_n_components(const unsigned int n) 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 > >())
#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
const types::global_dof_index invalid_dof_index