16 #ifndef dealii_mg_transfer_global_coarsening_h
17 #define dealii_mg_transfer_global_coarsening_h
44 class MGTwoLevelTransferImplementation;
49 template <
int dim,
int spacedim>
53 template <
int dim,
typename Number>
143 const unsigned int degree,
151 std::vector<unsigned int>
153 const unsigned int max_degree,
166 template <
int dim,
int spacedim>
167 std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
187 template <
int dim,
int spacedim>
188 std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
192 const bool preserve_fine_triangulation,
193 const bool repartition_fine_triangulation);
200 template <
int dim,
int spacedim>
201 std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
205 const bool repartition_fine_triangulation =
false);
213 template <
typename VectorType>
244 const std::shared_ptr<const Utilities::MPI::Partitioner>
246 const std::shared_ptr<const Utilities::MPI::Partitioner>
247 &partitioner_fine) = 0;
264 template <
typename Number>
301 const std::shared_ptr<const Utilities::MPI::Partitioner>
303 const std::shared_ptr<const Utilities::MPI::Partitioner>
304 &partitioner_fine) = 0;
360 template <
int dim, std::
size_t w
idth>
363 const std::shared_ptr<const Utilities::MPI::Partitioner>
365 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner_fine,
366 bool &vec_fine_needs_ghost_update,
370 std::vector<unsigned int> &dof_indices_fine);
414 std::shared_ptr<const Utilities::MPI::Partitioner>
443 template <
int dim,
typename VectorType>
464 interpolate(VectorType &dst,
const VectorType &src)
const override;
472 const std::shared_ptr<const Utilities::MPI::Partitioner>
474 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner_fine)
492 template <
int dim,
typename Number>
568 const unsigned int fe_degree_coarse);
585 const std::shared_ptr<const Utilities::MPI::Partitioner>
587 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner_fine)
615 struct MGTransferScheme
722 friend class internal::MGTwoLevelTransferImplementation;
733 template <
int dim,
typename VectorType>
756 interpolate(VectorType &dst,
const VectorType &src)
const override;
773 template <
int dim,
typename Number>
790 struct AdditionalData
802 const unsigned int rtree_level = 0,
803 const bool enforce_all_points_found =
true)
804 : tolerance(tolerance)
805 , rtree_level(rtree_level)
806 , enforce_all_points_found(enforce_all_points_found)
865 const std::shared_ptr<const Utilities::MPI::Partitioner>
867 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner_fine)
879 boost::signals2::connection
885 boost::signals2::connection
891 boost::signals2::connection
897 boost::signals2::connection
922 template <
int n_components>
931 template <
int n_components>
956 std::shared_ptr<NonMatching::MappingInfo<dim, dim, Number>>
mapping_info;
1016 template <
int dim,
typename Number>
1018 LinearAlgebra::distributed::Vector<Number>>
1047 template <
typename MGTwoLevelTransferObject>
1049 const std::function<
void(
const unsigned int,
VectorType &)>
1055 template <
typename MGTwoLevelTransferObject>
1069 build(
const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
1121 const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
1135 const std::function<
void(
const unsigned int,
VectorType &)>
1178 template <
class InVector>
1182 const InVector &src)
const;
1193 template <
class OutVector>
1217 template <
class InVector>
1221 const InVector &src)
const;
1231 template <
class InVector>
1286 std::pair<const DoFHandler<dim> *,
unsigned int>
1301 template <
typename MGTwoLevelTransferObject>
1309 template <
class InVector>
1313 const InVector &vector_reference,
1314 const bool omit_zeroing_entries)
const;
1339 std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
1350 template <
int dim,
typename Number>
1396 const std::vector<MGConstrainedDoFs> &mg_constrained_dofs);
1432 template <
int dim,
typename VectorType>
1436 template <
int dim,
typename VectorType>
1448 template <
int dim,
typename Number>
1449 template <
typename MGTwoLevelTransferObject>
1452 const std::function<
void(
const unsigned int, VectorType &)>
1453 &initialize_dof_vector)
1455 this->transfer.
clear();
1456 this->internal_transfer.clear();
1458 this->initialize_transfer_references(transfer);
1459 this->build(initialize_dof_vector);
1464 template <
int dim,
typename Number>
1465 template <
typename MGTwoLevelTransferObject>
1470 this->initialize_transfer_references(transfer);
1475 template <
int dim,
typename Number>
1476 template <
typename MGTwoLevelTransferObject>
1481 const unsigned int min_level = transfer.
min_level();
1482 const unsigned int max_level = transfer.
max_level();
1484 this->transfer.
resize(min_level, max_level);
1486 for (
unsigned int l = min_level;
l <= max_level; ++
l)
1494 template <
int dim,
typename Number>
1495 template <
class InVector>
1498 const unsigned int level,
1500 const InVector &vec_reference,
1501 const bool omit_zeroing_entries)
const
1503 std::shared_ptr<const Utilities::MPI::Partitioner> partitioner;
1505 if (external_partitioners.empty())
1507 partitioner = vec_reference.get_partitioner();
1514 partitioner = external_partitioners[
level - transfer.
min_level()];
1520 if (vec.get_partitioner().get() == partitioner.get())
1522 if (omit_zeroing_entries ==
false)
1528 if (vec.size() == partitioner->size() &&
1529 vec.locally_owned_size() == partitioner->locally_owned_size())
1531 if (omit_zeroing_entries ==
false)
1537 vec.reinit(partitioner, omit_zeroing_entries);
1542 template <
int dim,
typename Number>
1543 template <
class InVector>
1547 const InVector &src)
const
1549 assert_dof_handler(dof_handler);
1553 const bool zero_out_values =
1554 (this->perform_plain_copy ==
false &&
1555 this->perform_renumbered_plain_copy ==
false) ||
1558 this->initialize_dof_vector(
level, dst[
level], src, !zero_out_values);
1561 if (this->perform_plain_copy)
1563 dst[dst.
max_level()].copy_locally_owned_data_from(src);
1565 else if (this->perform_renumbered_plain_copy)
1569 for (
unsigned int i = 0; i < this->copy_indices.back().n_cols(); ++i)
1570 dst_level.local_element(this->copy_indices.back()(1, i)) =
1571 src.local_element(i);
1575 this->ghosted_global_vector = src;
1576 this->ghosted_global_vector.update_ghost_values();
1582 auto &dst_level = dst[
l];
1584 const auto copy_unknowns = [&](
const auto &indices) {
1585 for (
unsigned int i = 0; i < indices.n_cols(); ++i)
1586 dst_level.local_element(indices(1, i)) =
1587 this->ghosted_global_vector.local_element(indices(0, i));
1590 copy_unknowns(this->copy_indices[
l]);
1591 copy_unknowns(this->copy_indices_level_mine[
l]);
1600 template <
int dim,
typename Number>
1601 template <
class OutVector>
1608 assert_dof_handler(dof_handler);
1610 if (this->perform_plain_copy)
1612 dst.zero_out_ghost_values();
1613 dst.copy_locally_owned_data_from(src[src.
max_level()]);
1615 else if (this->perform_renumbered_plain_copy)
1617 const auto &src_level = src[src.
max_level()];
1618 dst.zero_out_ghost_values();
1619 for (
unsigned int i = 0; i < this->copy_indices.back().n_cols(); ++i)
1620 dst.local_element(i) =
1621 src_level.local_element(this->copy_indices.back()(1, i));
1628 auto &ghosted_vector = this->ghosted_level_vector[
l];
1630 if (this->ghosted_level_vector[
l].size() > 0)
1631 ghosted_vector = src[
l];
1633 const auto *
const ghosted_vector_ptr =
1634 (this->ghosted_level_vector[
l].size() > 0) ? &ghosted_vector :
1637 ghosted_vector_ptr->update_ghost_values();
1639 const auto copy_unknowns = [&](
const auto &indices) {
1640 for (
unsigned int i = 0; i < indices.n_cols(); ++i)
1641 dst.local_element(indices(0, i)) =
1642 ghosted_vector_ptr->local_element(indices(1, i));
1645 copy_unknowns(this->copy_indices[
l]);
1646 copy_unknowns(this->copy_indices_global_mine[
l]);
1654 template <
int dim,
typename Number>
1655 template <
class InVector>
1658 const InVector &src)
const
1662 this->interpolate_to_mg(dof_handler_dummy, dst, src);
1667 template <
int dim,
typename Number>
1668 template <
class InVector>
1672 const InVector &src)
const
1674 assert_dof_handler(dof_handler);
1676 const unsigned int min_level = transfer.
min_level();
1677 const unsigned int max_level = transfer.
max_level();
1684 const bool zero_out_values =
false;
1685 this->initialize_dof_vector(
level, dst[
level], src, !zero_out_values);
1688 if (this->perform_plain_copy)
1690 dst[max_level].copy_locally_owned_data_from(src);
1692 for (
unsigned int l = max_level;
l > min_level; --
l)
1695 else if (this->perform_renumbered_plain_copy)
1697 auto &dst_level = dst[max_level];
1699 for (
unsigned int i = 0; i < this->solution_copy_indices.back().n_cols();
1701 dst_level.local_element(this->solution_copy_indices.back()(1, i)) =
1702 src.local_element(i);
1704 for (
unsigned int l = max_level;
l > min_level; --
l)
1709 this->solution_ghosted_global_vector = src;
1710 this->solution_ghosted_global_vector.update_ghost_values();
1712 for (
unsigned int l = max_level + 1;
l != min_level;)
1716 auto &dst_level = dst[
l];
1718 const auto copy_unknowns = [&](
const auto &indices) {
1719 for (
unsigned int i = 0; i < indices.n_cols(); ++i)
1720 dst_level.local_element(indices(1, i)) =
1721 this->solution_ghosted_global_vector.local_element(
1725 copy_unknowns(this->solution_copy_indices[
l]);
1726 copy_unknowns(this->solution_copy_indices_level_mine[
l]);
1731 this->transfer[
l]->interpolate(dst[
l - 1], dst[
l]);
std::function< void(const unsigned int, LinearAlgebra::distributed::Vector< Number > &)> initialize_dof_vector
SmartPointer< const MGConstrainedDoFs > mg_constrained_dofs
void resize(const unsigned int new_minlevel, const unsigned int new_maxlevel, Args &&...args)
unsigned int max_level() const
unsigned int min_level() const
void initialize_constraints(const MGConstrainedDoFs &mg_constrained_dofs)
MGTransferBlockMF(const std::vector< MGConstrainedDoFs > &mg_constrained_dofs)
MGTransferBlockMF(const MGConstrainedDoFs &mg_constrained_dofs)
void build(const std::vector< const DoFHandler< dim > * > &dof_handler)
std::vector< MGTransferMF< dim, Number > > transfer_operators_internal
MGTransferBlockMF(const MGTransferMF< dim, Number > &transfer_operator)
const MGTransferMF< dim, Number > & get_matrix_free_transfer(const unsigned int b) const override
MGTransferBlockMF()=default
void build(const DoFHandler< dim > &dof_handler)
std::vector< SmartPointer< const MGTransferMF< dim, Number > > > transfer_operators
void initialize_constraints(const std::vector< MGConstrainedDoFs > &mg_constrained_dofs)
void copy_to_mg(const DoFHandler< dim > &dof_handler, MGLevelObject< VectorType > &dst, const InVector &src) const
unsigned int min_level() const
void build(const std::function< void(const unsigned int, VectorType &)> &initialize_dof_vector)
void build(const DoFHandler< dim > &dof_handler, const std::vector< std::shared_ptr< const Utilities::MPI::Partitioner >> &external_partitioners={})
void assert_dof_handler(const DoFHandler< dim > &dof_handler_out) const
void interpolate_to_mg(const DoFHandler< dim > &dof_handler, MGLevelObject< VectorType > &dst, const InVector &src) const
std::vector< std::shared_ptr< const Utilities::MPI::Partitioner > > external_partitioners
void prolongate_and_add(const unsigned int to_level, VectorType &dst, const VectorType &src) const override
unsigned int max_level() const
std::pair< const DoFHandler< dim > *, unsigned int > get_dof_handler_fine() const
MGTransferMF(const MGLevelObject< MGTwoLevelTransferObject > &transfer, const std::function< void(const unsigned int, VectorType &)> &initialize_dof_vector={})
void build(const DoFHandler< dim > &dof_handler, const std::function< void(const unsigned int, VectorType &)> &initialize_dof_vector)
void build(const std::vector< std::shared_ptr< const Utilities::MPI::Partitioner >> &external_partitioners={})
void initialize_dof_vector(const unsigned int level, VectorType &vector, const InVector &vector_reference, const bool omit_zeroing_entries) const
void initialize_constraints(const MGConstrainedDoFs &mg_constrained_dofs)
void initialize_internal_transfer(const DoFHandler< dim > &dof_handler, const SmartPointer< const MGConstrainedDoFs > &mg_constrained_dofs)
void initialize_two_level_transfers(const MGLevelObject< MGTwoLevelTransferObject > &transfer)
MGTransferMF(const MGConstrainedDoFs &mg_constrained_dofs)
MGLevelObject< MGTwoLevelTransfer< dim, VectorType > > internal_transfer
void fill_and_communicate_copy_indices_global_coarsening(const DoFHandler< dim > &dof_handler)
MGLevelObject< SmartPointer< MGTwoLevelTransferBase< VectorType > > > transfer
std::size_t memory_consumption() const
virtual void restrict_and_add(const unsigned int from_level, VectorType &dst, const VectorType &src) const override
void initialize_transfer_references(const MGLevelObject< MGTwoLevelTransferObject > &transfer)
void prolongate(const unsigned int to_level, VectorType &dst, const VectorType &src) const override
void copy_from_mg(const DoFHandler< dim > &dof_handler, OutVector &dst, const MGLevelObject< VectorType > &src) const
void interpolate_to_mg(MGLevelObject< VectorType > &dst, const InVector &src) const
void prolongate_and_add(VectorType &dst, const VectorType &src) const
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner_fine_embedded
bool fine_element_is_continuous
virtual void enable_inplace_operations_if_possible(const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner_coarse, const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner_fine)=0
virtual std::size_t memory_consumption() const =0
LinearAlgebra::distributed::Vector< Number > vec_coarse
void compress(LinearAlgebra::distributed::Vector< Number > &vec, const VectorOperation::values op) const
void zero_out_ghost_values(const LinearAlgebra::distributed::Vector< Number > &vec) const
virtual void restrict_and_add_internal(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const =0
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner_coarse
virtual void interpolate(VectorType &dst, const VectorType &src) const =0
void update_ghost_values(const LinearAlgebra::distributed::Vector< Number > &vec) const
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner_fine
AlignedVector< Number > buffer_coarse_embedded
virtual void prolongate_and_add_internal(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const =0
void internal_enable_inplace_operations_if_possible(const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner_coarse, const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner_fine, bool &vec_fine_needs_ghost_update, internal::MatrixFreeFunctions::ConstraintInfo< dim, VectorizedArray< Number, width >> &constraint_info_coarse, std::vector< unsigned int > &dof_indices_fine)
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner_coarse_embedded
AlignedVector< Number > buffer_fine_embedded
LinearAlgebra::distributed::Vector< Number > vec_fine
bool vec_fine_needs_ghost_update
void restrict_and_add(VectorType &dst, const VectorType &src) const
virtual void enable_inplace_operations_if_possible(const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner_coarse, const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner_fine)=0
virtual std::size_t memory_consumption() const =0
virtual void restrict_and_add(VectorType &dst, const VectorType &src) const =0
virtual void interpolate(VectorType &dst, const VectorType &src) const =0
virtual void prolongate_and_add(VectorType &dst, const VectorType &src) const =0
boost::signals2::connection connect_restriction_cell_loop(const std::function< void(const bool)> &slot)
void enable_inplace_operations_if_possible(const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner_coarse, const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner_fine) override
std::shared_ptr< NonMatching::MappingInfo< dim, dim, Number > > mapping_info
std::size_t memory_consumption() const override
std::vector< unsigned int > level_dof_indices_fine
unsigned int mg_level_fine
internal::MatrixFreeFunctions::ConstraintInfo< dim, VectorizedArrayType > constraint_info
std::unique_ptr< FiniteElement< dim > > fe_coarse
void prolongate_and_add_internal_comp(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const
boost::signals2::connection connect_prolongation(const std::function< void(const bool)> &slot)
boost::signals2::connection connect_prolongation_cell_loop(const std::function< void(const bool)> &slot)
SmartPointer< const DoFHandler< dim > > dof_handler_fine
boost::signals2::connection connect_restriction(const std::function< void(const bool)> &slot)
Utilities::MPI::RemotePointEvaluation< dim > rpe
std::vector< unsigned int > level_dof_indices_fine_ptrs
void prolongate_and_add_internal(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const override
AdditionalData additional_data
void interpolate(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const override
void restrict_and_add_internal(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const override
MGTwoLevelTransferNonNested(const AdditionalData &data=AdditionalData())
void reinit(const DoFHandler< dim > &dof_handler_fine, const DoFHandler< dim > &dof_handler_coarse, const Mapping< dim > &mapping_fine, const Mapping< dim > &mapping_coarse, const AffineConstraints< Number > &constraint_fine=AffineConstraints< Number >(), const AffineConstraints< Number > &constraint_coarse=AffineConstraints< Number >())
mg::SignalsNonNested signals_non_nested
void restrict_and_add_internal_comp(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const
void prolongate_and_add(VectorType &dst, const VectorType &src) const override
std::size_t memory_consumption() const override
void restrict_and_add(VectorType &dst, const VectorType &src) const override
void interpolate(VectorType &dst, const VectorType &src) const override
internal::MatrixFreeFunctions::ConstraintInfo< dim, VectorizedArrayType > constraint_info_fine
SmartPointer< const DoFHandler< dim > > dof_handler_fine
unsigned int mg_level_fine
std::vector< Number > weights
void enable_inplace_operations_if_possible(const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner_coarse, const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner_fine) override
void reinit_polynomial_transfer(const DoFHandler< dim > &dof_handler_fine, const DoFHandler< dim > &dof_handler_coarse, const AffineConstraints< Number > &constraint_fine=AffineConstraints< Number >(), const AffineConstraints< Number > &constraint_coarse=AffineConstraints< Number >(), const unsigned int mg_level_fine=numbers::invalid_unsigned_int, const unsigned int mg_level_coarse=numbers::invalid_unsigned_int)
void interpolate(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const override
static bool fast_polynomial_transfer_supported(const unsigned int fe_degree_fine, const unsigned int fe_degree_coarse)
unsigned int n_components
void prolongate_and_add_internal(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const override
internal::MatrixFreeFunctions::ConstraintInfo< dim, VectorizedArrayType > constraint_info_coarse
void reinit(const DoFHandler< dim > &dof_handler_fine, const DoFHandler< dim > &dof_handler_coarse, const AffineConstraints< Number > &constraint_fine=AffineConstraints< Number >(), const AffineConstraints< Number > &constraint_coarse=AffineConstraints< Number >(), const unsigned int mg_level_fine=numbers::invalid_unsigned_int, const unsigned int mg_level_coarse=numbers::invalid_unsigned_int)
void restrict_and_add_internal(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const override
void reinit_geometric_transfer(const DoFHandler< dim > &dof_handler_fine, const DoFHandler< dim > &dof_handler_coarse, const AffineConstraints< Number > &constraint_fine=AffineConstraints< Number >(), const AffineConstraints< Number > &constraint_coarse=AffineConstraints< Number >(), const unsigned int mg_level_fine=numbers::invalid_unsigned_int, const unsigned int mg_level_coarse=numbers::invalid_unsigned_int)
AlignedVector< VectorizedArrayType > weights_compressed
std::size_t memory_consumption() const override
std::vector< MGTransferScheme > schemes
void enable_inplace_operations_if_possible(const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner_coarse, const std::shared_ptr< const Utilities::MPI::Partitioner > &partitioner_fine) override
void interpolate(VectorType &dst, const VectorType &src) const override
void restrict_and_add(VectorType &dst, const VectorType &src) const override
void prolongate_and_add(VectorType &dst, const VectorType &src) const override
std::size_t memory_consumption() const override
Abstract base class for mapping classes.
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcInternalError()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
T & get_underlying_value(T &p)
static const unsigned int invalid_unsigned_int
bool enforce_all_points_found
AdditionalData(const double tolerance=1e-6, const unsigned int rtree_level=0, const bool enforce_all_points_found=true)
unsigned int n_coarse_cells
AlignedVector< VectorizedArrayType > prolongation_matrix
internal::MatrixFreeFunctions::ShapeInfo< VectorizedArrayType > shape_info_coarse
unsigned int n_dofs_per_cell_coarse
unsigned int n_dofs_per_cell_fine
AlignedVector< VectorizedArrayType > prolongation_matrix_1d
unsigned int degree_coarse
AlignedVector< VectorizedArrayType > restriction_matrix_1d
AlignedVector< VectorizedArrayType > restriction_matrix
boost::signals2::signal< void(const bool before)> prolongation_cell_loop
boost::signals2::signal< void(const bool before)> restriction
boost::signals2::signal< void(const bool before)> restriction_cell_loop
boost::signals2::signal< void(const bool before)> prolongation
const ::Triangulation< dim, spacedim > & tria