16 #ifndef dealii_mg_transfer_matrix_free_h 17 #define dealii_mg_transfer_matrix_free_h 19 #include <deal.II/base/config.h> 21 #include <deal.II/base/mg_level_object.h> 22 #include <deal.II/base/vectorization.h> 24 #include <deal.II/dofs/dof_handler.h> 26 #include <deal.II/lac/la_parallel_block_vector.h> 27 #include <deal.II/lac/la_parallel_vector.h> 29 #include <deal.II/multigrid/mg_base.h> 30 #include <deal.II/multigrid/mg_constrained_dofs.h> 31 #include <deal.II/multigrid/mg_transfer.h> 32 #include <deal.II/multigrid/mg_transfer_internal.h> 35 DEAL_II_NAMESPACE_OPEN
56 template <
int dim,
typename Number>
112 const unsigned int to_level,
136 const unsigned int from_level,
147 template <
typename Number2,
int spacedim>
208 std::vector<std::vector<std::pair<unsigned int, unsigned int>>>
251 template <
int degree>
254 const unsigned int to_level,
261 template <
int degree>
285 template <
int dim,
typename Number>
287 :
public MGTransferBase<LinearAlgebra::distributed::BlockVector<Number>>
306 const std::vector<MGConstrainedDoFs> &mg_constrained_dofs);
324 const std::vector<MGConstrainedDoFs> &mg_constrained_dofs);
360 const unsigned int to_level,
384 const unsigned int from_level,
398 template <
typename Number2,
int spacedim>
408 template <
typename Number2,
int spacedim>
418 template <
typename Number2,
int spacedim>
429 template <
typename Number2,
int spacedim>
470 template <
int dim,
typename Number>
471 template <
typename Number2,
int spacedim>
478 const unsigned int min_level = dst.min_level();
479 const unsigned int max_level = dst.max_level();
488 MPI_Comm mpi_communicator =
493 for (
unsigned int level = min_level; level <= max_level; ++level)
497 relevant_dofs[level]);
498 if (dst[level].size() !=
500 dst[level].local_size() !=
503 relevant_dofs[level],
510 this->copy_to_mg(dof_handler, dst, src,
true);
515 dst[max_level].update_ghost_values();
517 for (
unsigned int level = max_level; level > min_level; --level)
522 relevant_dofs[level],
524 ghosted_vector = dst[level];
530 std::vector<types::global_dof_index> dof_indices(fe.
dofs_per_cell);
532 dof_handler.
begin(level - 1);
534 for (; cell != endc; ++cell)
535 if (cell->is_locally_owned_on_level())
540 if (!cell->has_children())
543 std::fill(dof_values_coarse.begin(), dof_values_coarse.end(), 0.);
544 for (
unsigned int child = 0; child < cell->n_children(); ++child)
546 cell->child(child)->get_mg_dof_indices(dof_indices);
548 dof_values_fine(i) = ghosted_vector(dof_indices[i]);
550 .vmult(tmp, dof_values_fine);
553 dof_values_coarse[i] += tmp[i];
554 else if (tmp(i) != 0.)
555 dof_values_coarse[i] = tmp[i];
557 cell->get_mg_dof_indices(dof_indices);
559 dst[level - 1](dof_indices[i]) = dof_values_coarse[i];
563 dst[level - 1].update_ghost_values();
569 template <
int dim,
typename Number>
570 template <
typename Number2,
int spacedim>
580 "This object was initialized with support for usage with one " 581 "DoFHandler for each block, but this method assumes that " 582 "the same DoFHandler is used for all the blocks!"));
583 const std::vector<const DoFHandler<dim, spacedim> *> mg_dofs(src.
n_blocks(),
586 copy_to_mg(mg_dofs, dst, src);
589 template <
int dim,
typename Number>
590 template <
typename Number2,
int spacedim>
597 const unsigned int n_blocks = src.
n_blocks();
603 const unsigned int min_level = dst.min_level();
604 const unsigned int max_level = dst.max_level();
613 for (
unsigned int i = 1; i < n_blocks; ++i)
615 &(mg_dof[0]->get_triangulation())) == tria),
616 ExcMessage(
"The DoFHandler use different Triangulations!"));
619 do_reinit.
resize(min_level, max_level);
620 for (
unsigned int level = min_level; level <= max_level; ++level)
622 do_reinit[level] =
false;
623 if (dst[level].n_blocks() != n_blocks)
625 do_reinit[level] =
true;
628 for (
unsigned int b = 0;
b < n_blocks; ++
b)
635 do_reinit[level] =
true;
641 for (
unsigned int level = min_level; level <= max_level; ++level)
643 if (do_reinit[level])
645 dst[level].reinit(n_blocks);
646 for (
unsigned int b = 0;
b < n_blocks; ++
b)
650 v.
reinit(mg_dof[b]->locally_owned_mg_dofs(level),
654 dst[level].collect_sizes();
663 min_level, max_level);
665 for (
unsigned int b = 0;
b < n_blocks; ++
b)
667 for (
unsigned int l = min_level;
l <= max_level; ++
l)
668 dst_non_block[l].reinit(dst[l].block(b));
669 const unsigned int data_block = same_for_all ? 0 :
b;
670 matrix_free_transfer_vector[data_block].copy_to_mg(*mg_dof[b],
674 for (
unsigned int l = min_level;
l <= max_level; ++
l)
675 dst[l].block(b) = dst_non_block[
l];
679 template <
int dim,
typename Number>
680 template <
typename Number2,
int spacedim>
689 const std::vector<const DoFHandler<dim, spacedim> *> mg_dofs(dst.
n_blocks(),
692 copy_from_mg(mg_dofs, dst, src);
695 template <
int dim,
typename Number>
696 template <
typename Number2,
int spacedim>
704 const unsigned int n_blocks = dst.
n_blocks();
710 const unsigned int min_level = src.min_level();
711 const unsigned int max_level = src.max_level();
713 for (
unsigned int l = min_level;
l <= max_level; ++
l)
718 min_level, max_level);
720 for (
unsigned int b = 0;
b < n_blocks; ++
b)
722 for (
unsigned int l = min_level;
l <= max_level; ++
l)
724 src_non_block[
l].reinit(src[l].block(b));
725 src_non_block[
l] = src[
l].
block(b);
727 const unsigned int data_block = same_for_all ? 0 :
b;
728 matrix_free_transfer_vector[data_block].copy_from_mg(*mg_dof[b],
739 DEAL_II_NAMESPACE_CLOSE
const Triangulation< dim, spacedim > & get_triangulation() const
size_type local_size() const
bool restriction_is_additive(const unsigned int index) const
void do_restrict_add(const unsigned int from_level, LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const
#define AssertDimension(dim1, dim2)
std::vector< unsigned int > n_owned_level_cells
cell_iterator begin(const unsigned int level=0) const
AlignedVector< VectorizedArray< Number > > evaluation_data
static ::ExceptionBase & ExcNoProlongation()
unsigned int n_components
std::size_t memory_consumption() const
std::vector< std::vector< std::vector< unsigned short > > > dirichlet_indices
void build(const DoFHandler< dim, dim > &mg_dof)
void initialize_constraints(const MGConstrainedDoFs &mg_constrained_dofs)
cell_iterator end() const
void reinit(const size_type size, const bool omit_zeroing_entries=false)
#define AssertThrow(cond, exc)
const FiniteElement< dim, spacedim > & get_fe(const unsigned int index=0) const
std::size_t memory_consumption() const
void update_ghost_values() const
void interpolate_to_mg(const DoFHandler< dim, spacedim > &mg_dof, MGLevelObject< LinearAlgebra::distributed::Vector< Number >> &dst, const LinearAlgebra::distributed::Vector< Number2 > &src) const
static ::ExceptionBase & ExcMessage(std::string arg1)
AlignedVector< VectorizedArray< Number > > prolongation_matrix_1d
#define Assert(cond, exc)
virtual const FullMatrix< double > & get_restriction_matrix(const unsigned int child, const RefinementCase< dim > &refinement_case=RefinementCase< dim >::isotropic_refinement) const
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
virtual void restrict_and_add(const unsigned int from_level, LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const override
virtual void restrict_and_add(const unsigned int from_level, LinearAlgebra::distributed::BlockVector< Number > &dst, const LinearAlgebra::distributed::BlockVector< Number > &src) const override
virtual void prolongate(const unsigned int to_level, LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const override
virtual MPI_Comm get_communicator() const
void copy_to_mg(const DoFHandler< dim, spacedim > &mg_dof, MGLevelObject< LinearAlgebra::distributed::BlockVector< Number >> &dst, const LinearAlgebra::distributed::BlockVector< Number2 > &src) const
#define DeclException0(Exception0)
std::vector< AlignedVector< VectorizedArray< Number > > > weights_on_refined
const IndexSet & locally_owned_mg_dofs(const unsigned int level) const
bool element_is_continuous
std::vector< std::vector< unsigned int > > level_dof_indices
virtual ~MGTransferBlockMatrixFree() override=default
const unsigned int dofs_per_cell
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
static const bool supports_dof_handler_vector
void copy_from_mg(const DoFHandler< dim, spacedim > &mg_dof, LinearAlgebra::distributed::BlockVector< Number2 > &dst, const MGLevelObject< LinearAlgebra::distributed::BlockVector< Number >> &src) const
virtual size_type size() const override
void do_prolongate_add(const unsigned int to_level, LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const
SmartPointer< const MGConstrainedDoFs, MGLevelGlobalTransfer< LinearAlgebra::distributed::Vector< Number > > > mg_constrained_dofs
unsigned int n_blocks() const
std::vector< std::vector< std::pair< unsigned int, unsigned int > > > parent_child_connect
virtual void prolongate(const unsigned int to_level, LinearAlgebra::distributed::BlockVector< Number > &dst, const LinearAlgebra::distributed::BlockVector< Number > &src) const override
std::vector< MGTransferMatrixFree< dim, Number > > matrix_free_transfer_vector
MGTransferBlockMatrixFree()=default
virtual ~MGTransferMatrixFree() override=default
unsigned int n_child_cell_dofs
void resize(const unsigned int new_minlevel, const unsigned int new_maxlevel)
void initialize_constraints(const MGConstrainedDoFs &mg_constrained_dofs)
BlockType & block(const unsigned int i)
size_type n_elements() const
void build(const DoFHandler< dim, dim > &mg_dof)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)