15#ifndef dealii_mg_transfer_global_coarsening_h
16#define dealii_mg_transfer_global_coarsening_h
44 class MGTwoLevelTransferImplementation;
49 template <
int dim,
int spacedim>
53template <
int dim,
typename Number>
148 const unsigned int degree,
156 std::vector<unsigned int>
158 const unsigned int max_degree,
171 template <
int dim,
int spacedim>
172 std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
192 template <
int dim,
int spacedim>
193 std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
197 const bool preserve_fine_triangulation,
198 const bool repartition_fine_triangulation);
205 template <
int dim,
int spacedim>
206 std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
210 const bool repartition_fine_triangulation =
false);
223template <
typename VectorType>
231 "This class is currently only implemented for vectors of "
232 "type LinearAlgebra::distributed::Vector.");
237 using Number =
typename VectorType::value_type;
271 virtual std::pair<bool, bool>
273 const std::shared_ptr<const Utilities::MPI::Partitioner>
275 const std::shared_ptr<const Utilities::MPI::Partitioner>
329 template <
int dim, std::
size_t w
idth,
typename IndexType>
330 std::pair<bool, bool>
332 const std::shared_ptr<const Utilities::MPI::Partitioner>
338 &constraint_info_coarse,
339 std::vector<unsigned
int> &dof_indices_fine);
383 std::shared_ptr<const Utilities::MPI::Partitioner>
432template <
int dim,
typename VectorType>
440 "This class is currently only implemented for vectors of "
441 "type LinearAlgebra::distributed::Vector.");
446 using Number =
typename VectorType::value_type;
524 const unsigned int dof_no_fine,
526 const unsigned int dof_no_coarse);
538 const unsigned int fe_degree_coarse);
544 interpolate(VectorType &dst,
const VectorType &src)
const override;
550 std::pair<bool, bool>
552 const std::shared_ptr<const Utilities::MPI::Partitioner>
566 const VectorType &src)
const override;
570 const VectorType &src)
const override;
642 internal::MatrixFreeFunctions::
643 ConstraintInfo<dim, VectorizedArrayType, types::global_dof_index>
649 internal::MatrixFreeFunctions::
650 ConstraintInfo<dim, VectorizedArrayType, types::global_dof_index>
736template <
int dim,
typename VectorType>
744 "This class is currently only implemented for vectors of "
745 "type LinearAlgebra::distributed::Vector.");
747 using Number =
typename VectorType::value_type;
827 interpolate(VectorType &dst,
const VectorType &src)
const override;
833 std::pair<bool, bool>
835 const std::shared_ptr<const Utilities::MPI::Partitioner>
849 boost::signals2::connection
855 boost::signals2::connection
861 boost::signals2::connection
867 boost::signals2::connection
877 const VectorType &src)
const override;
884 const VectorType &src)
const override;
890 template <
int n_components>
893 const VectorType &src)
const;
898 template <
int n_components>
931 std::shared_ptr<NonMatching::MappingInfo<dim, dim, Number>>
mapping_info;
937 internal::MatrixFreeFunctions::
938 ConstraintInfo<dim, VectorizedArrayType, unsigned int>
992template <
int dim,
typename Number>
994 LinearAlgebra::distributed::Vector<Number>>
1023 template <
typename MGTwoLevelTransferObject>
1025 const std::function<
void(
const unsigned int,
VectorType &)>
1031 template <
typename MGTwoLevelTransferObject>
1045 build(
const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
1097 const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
1111 const std::function<
void(
const unsigned int,
VectorType &)>
1154 template <
class InVector>
1158 const InVector &src)
const;
1169 template <
class OutVector>
1193 template <
class InVector>
1197 const InVector &src)
const;
1207 template <
class InVector>
1262 std::pair<const DoFHandler<dim> *,
unsigned int>
1277 template <
typename MGTwoLevelTransferObject>
1285 template <
class InVector>
1289 const InVector &vector_reference,
1290 const bool omit_zeroing_entries)
const;
1315 std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
1326template <
int dim,
typename Number>
1372 const std::vector<MGConstrainedDoFs> &mg_constrained_dofs);
1403 std::vector<ObserverPointer<const MGTransferMF<dim, Number>>>
1409template <
int dim,
typename VectorType>
1413template <
int dim,
typename VectorType>
1426template <
int dim,
typename Number>
1427template <
typename MGTwoLevelTransferObject>
1430 const std::function<
void(
const unsigned int, VectorType &)>
1431 &initialize_dof_vector)
1433 this->transfer.
clear();
1434 this->internal_transfer.clear();
1436 this->initialize_transfer_references(transfer);
1437 this->build(initialize_dof_vector);
1442template <
int dim,
typename Number>
1443template <
typename MGTwoLevelTransferObject>
1448 this->initialize_transfer_references(transfer);
1453template <
int dim,
typename Number>
1454template <
typename MGTwoLevelTransferObject>
1459 const unsigned int min_level = transfer.
min_level();
1460 const unsigned int max_level = transfer.
max_level();
1462 this->transfer.
resize(min_level, max_level);
1465 for (
unsigned int l = min_level + 1;
l <= max_level; ++
l)
1473template <
int dim,
typename Number>
1474template <
class InVector>
1477 const unsigned int level,
1479 const InVector &vec_reference,
1480 const bool omit_zeroing_entries)
const
1482 std::shared_ptr<const Utilities::MPI::Partitioner> partitioner;
1484 if (external_partitioners.empty())
1486 partitioner = vec_reference.get_partitioner();
1493 partitioner = external_partitioners[
level - transfer.
min_level()];
1499 if (vec.get_partitioner().get() == partitioner.get())
1501 if (omit_zeroing_entries ==
false)
1507 if (vec.size() == partitioner->size() &&
1508 vec.locally_owned_size() == partitioner->locally_owned_size())
1510 if (omit_zeroing_entries ==
false)
1516 vec.reinit(partitioner, omit_zeroing_entries);
1521template <
int dim,
typename Number>
1522template <
class InVector>
1526 const InVector &src)
const
1528 assert_dof_handler(dof_handler);
1532 const bool zero_out_values =
1533 (this->perform_plain_copy ==
false &&
1534 this->perform_renumbered_plain_copy ==
false) ||
1537 this->initialize_dof_vector(
level, dst[
level], src, !zero_out_values);
1540 if (this->perform_plain_copy)
1542 dst[dst.
max_level()].copy_locally_owned_data_from(src);
1544 else if (this->perform_renumbered_plain_copy)
1548 for (
unsigned int i = 0; i < this->copy_indices.back().n_cols(); ++i)
1549 dst_level.local_element(this->copy_indices.back()(1, i)) =
1550 src.local_element(i);
1554 this->ghosted_global_vector = src;
1555 this->ghosted_global_vector.update_ghost_values();
1561 auto &dst_level = dst[
l];
1563 const auto copy_unknowns = [&](
const auto &indices) {
1564 for (
unsigned int i = 0; i < indices.n_cols(); ++i)
1565 dst_level.local_element(indices(1, i)) =
1566 this->ghosted_global_vector.local_element(indices(0, i));
1569 copy_unknowns(this->copy_indices[l]);
1570 copy_unknowns(this->copy_indices_level_mine[l]);
1579template <
int dim,
typename Number>
1580template <
class OutVector>
1587 assert_dof_handler(dof_handler);
1589 if (this->perform_plain_copy)
1591 dst.zero_out_ghost_values();
1592 dst.copy_locally_owned_data_from(src[src.
max_level()]);
1594 else if (this->perform_renumbered_plain_copy)
1596 const auto &src_level = src[src.
max_level()];
1597 dst.zero_out_ghost_values();
1598 for (
unsigned int i = 0; i < this->copy_indices.back().n_cols(); ++i)
1599 dst.local_element(i) =
1600 src_level.local_element(this->copy_indices.back()(1, i));
1607 auto &ghosted_vector = this->ghosted_level_vector[
l];
1609 if (this->ghosted_level_vector[l].
size() > 0)
1610 ghosted_vector = src[l];
1612 const auto *
const ghosted_vector_ptr =
1613 (this->ghosted_level_vector[
l].size() > 0) ? &ghosted_vector :
1616 ghosted_vector_ptr->update_ghost_values();
1618 const auto copy_unknowns = [&](
const auto &indices) {
1619 for (
unsigned int i = 0; i < indices.n_cols(); ++i)
1620 dst.local_element(indices(0, i)) =
1621 ghosted_vector_ptr->local_element(indices(1, i));
1624 copy_unknowns(this->copy_indices[l]);
1625 copy_unknowns(this->copy_indices_global_mine[l]);
1633template <
int dim,
typename Number>
1634template <
class InVector>
1637 const InVector &src)
const
1641 this->interpolate_to_mg(dof_handler_dummy, dst, src);
1646template <
int dim,
typename Number>
1647template <
class InVector>
1651 const InVector &src)
const
1653 assert_dof_handler(dof_handler);
1655 const unsigned int min_level = transfer.
min_level();
1656 const unsigned int max_level = transfer.
max_level();
1663 const bool zero_out_values =
false;
1664 this->initialize_dof_vector(
level, dst[
level], src, !zero_out_values);
1667 if (this->perform_plain_copy)
1669 dst[max_level].copy_locally_owned_data_from(src);
1671 for (
unsigned int l = max_level;
l > min_level; --
l)
1672 this->transfer[l]->
interpolate(dst[l - 1], dst[l]);
1674 else if (this->perform_renumbered_plain_copy)
1676 auto &dst_level = dst[max_level];
1678 for (
unsigned int i = 0; i < this->solution_copy_indices.back().n_cols();
1680 dst_level.local_element(this->solution_copy_indices.back()(1, i)) =
1681 src.local_element(i);
1683 for (
unsigned int l = max_level;
l > min_level; --
l)
1684 this->transfer[l]->
interpolate(dst[l - 1], dst[l]);
1688 this->solution_ghosted_global_vector = src;
1689 this->solution_ghosted_global_vector.update_ghost_values();
1691 for (
unsigned int l = max_level + 1;
l != min_level;)
1695 auto &dst_level = dst[
l];
1697 const auto copy_unknowns = [&](
const auto &indices) {
1698 for (
unsigned int i = 0; i < indices.n_cols(); ++i)
1699 dst_level.local_element(indices(1, i)) =
1700 this->solution_ghosted_global_vector.local_element(
1704 copy_unknowns(this->solution_copy_indices[l]);
1705 copy_unknowns(this->solution_copy_indices_level_mine[l]);
1710 this->transfer[
l]->interpolate(dst[l - 1], dst[l]);
ObserverPointer< const MGConstrainedDoFs > mg_constrained_dofs
std::function< void(const unsigned int, LinearAlgebra::distributed::Vector< Number > &)> initialize_dof_vector
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)
std::vector< ObserverPointer< const MGTransferMF< dim, Number > > > transfer_operators
MGTransferBlockMF()=default
void build(const DoFHandler< dim > &dof_handler)
const MGTransferMF< dim, Number > & get_matrix_free_transfer(const unsigned int b) const override
void initialize_constraints(const std::vector< MGConstrainedDoFs > &mg_constrained_dofs)
MGLevelObject< ObserverPointer< MGTwoLevelTransferBase< VectorType > > > transfer
std::pair< const DoFHandler< dim > *, unsigned int > get_dof_handler_fine() const
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 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
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 initialize_internal_transfer(const DoFHandler< dim > &dof_handler, const ObserverPointer< const MGConstrainedDoFs > &mg_constrained_dofs)
void build(const DoFHandler< dim > &dof_handler, const std::vector< std::shared_ptr< const Utilities::MPI::Partitioner > > &external_partitioners={})
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_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)
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
AlignedVector< Number > buffer_coarse_embedded
void zero_out_ghost_values(const VectorType &vec) const
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner_fine_embedded
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner_coarse
virtual std::size_t memory_consumption() const =0
AlignedVector< Number > buffer_fine_embedded
void prolongate_and_add(VectorType &dst, const VectorType &src) const
bool fine_element_is_continuous
LinearAlgebra::distributed::Vector< Number > vec_fine
void update_ghost_values(const VectorType &vec) const
LinearAlgebra::distributed::Vector< Number > vec_coarse
typename VectorType::value_type Number
bool vec_fine_needs_ghost_update
virtual void restrict_and_add_internal(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const =0
virtual std::pair< bool, bool > 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
void restrict_and_add(VectorType &dst, const VectorType &src) const
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner_coarse_embedded
std::pair< bool, bool > 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 >, IndexType > &constraint_info_coarse, std::vector< unsigned int > &dof_indices_fine)
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner_fine
virtual void interpolate(VectorType &dst, const VectorType &src) const =0
void compress(VectorType &vec, const VectorOperation::values op) const
virtual void prolongate_and_add_internal(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const =0
std::shared_ptr< NonMatching::MappingInfo< dim, dim, Number > > mapping_info
boost::signals2::connection connect_restriction(const std::function< void(const bool)> &slot)
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 >())
AdditionalData additional_data
std::unique_ptr< FiniteElement< dim > > fe_coarse
std::vector< Number > rpe_input_output
ObserverPointer< const DoFHandler< dim > > dof_handler_fine
void restrict_and_add_internal_comp(VectorType &dst, const VectorType &src) const
boost::signals2::connection connect_prolongation_cell_loop(const std::function< void(const bool)> &slot)
std::vector< Number > rpe_buffer
std::size_t memory_consumption() const override
std::pair< bool, bool > 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
Utilities::MPI::RemotePointEvaluation< dim > rpe
void restrict_and_add_internal(VectorType &dst, const VectorType &src) const override
std::vector< unsigned int > level_dof_indices_fine_ptrs
mg::SignalsNonNested signals_non_nested
internal::MatrixFreeFunctions::ConstraintInfo< dim, VectorizedArrayType, unsigned int > constraint_info
boost::signals2::connection connect_prolongation(const std::function< void(const bool)> &slot)
boost::signals2::connection connect_restriction_cell_loop(const std::function< void(const bool)> &slot)
void prolongate_and_add_internal_comp(VectorType &dst, const VectorType &src) const
MGTwoLevelTransferNonNested(const AdditionalData &data=AdditionalData())
void interpolate(VectorType &dst, const VectorType &src) const override
std::vector< unsigned int > level_dof_indices_fine
typename VectorType::value_type Number
unsigned int mg_level_fine
void prolongate_and_add_internal(VectorType &dst, const VectorType &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)
internal::MatrixFreeFunctions::ConstraintInfo< dim, VectorizedArrayType, types::global_dof_index > constraint_info_fine
friend class internal::MGTwoLevelTransferImplementation
std::vector< MGTransferScheme > schemes
ObserverPointer< const DoFHandler< dim > > dof_handler_fine
typename VectorType::value_type Number
std::vector< unsigned char > weights_are_compressed
void interpolate(VectorType &dst, const VectorType &src) const override
internal::MatrixFreeFunctions::ConstraintInfo< dim, VectorizedArrayType, types::global_dof_index > constraint_info_coarse
std::unique_ptr< MatrixFreeRelatedData > matrix_free_data
static bool fast_polynomial_transfer_supported(const unsigned int fe_degree_fine, const unsigned int fe_degree_coarse)
AlignedVector< VectorizedArrayType > weights
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)
unsigned int mg_level_fine
std::pair< bool, bool > 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 restrict_and_add_internal(VectorType &dst, const VectorType &src) const override
unsigned int n_components
std::vector< unsigned int > weights_start
void reinit(const MatrixFree< dim, Number > &matrix_free_fine, const unsigned int dof_no_fine, const MatrixFree< dim, Number > &matrix_free_coarse, const unsigned int dof_no_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)
std::size_t memory_consumption() const override
void prolongate_and_add_internal(VectorType &dst, const VectorType &src) const override
Abstract base class for mapping classes.
static constexpr std::size_t size()
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcInternalError()
std::vector< index_type > data
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
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 degree_coarse
unsigned int n_dofs_per_cell_coarse
unsigned int n_coarse_cells
AlignedVector< double > restriction_matrix
internal::MatrixFreeFunctions::ShapeInfo< double > shape_info_coarse
unsigned int n_dofs_per_cell_fine
AlignedVector< double > prolongation_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