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>
93 const unsigned int degree,
101 std::vector<unsigned int>
103 const unsigned int max_degree,
116 template <
int dim,
int spacedim>
117 std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
137 template <
int dim,
int spacedim>
138 std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
142 const bool preserve_fine_triangulation,
143 const bool repartition_fine_triangulation);
150 template <
int dim,
int spacedim>
151 std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
155 const bool repartition_fine_triangulation =
false);
163 template <
typename VectorType>
194 const std::shared_ptr<const Utilities::MPI::Partitioner>
196 const std::shared_ptr<const Utilities::MPI::Partitioner>
197 &partitioner_fine) = 0;
214 template <
typename Number>
246 const std::shared_ptr<const Utilities::MPI::Partitioner>
248 const std::shared_ptr<const Utilities::MPI::Partitioner>
249 &partitioner_fine) = 0;
305 template <
int dim, std::
size_t w
idth>
308 const std::shared_ptr<const Utilities::MPI::Partitioner>
310 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner_fine,
314 std::vector<unsigned int> &dof_indices_fine);
353 std::shared_ptr<const Utilities::MPI::Partitioner>
382 template <
int dim,
typename VectorType>
403 interpolate(VectorType &dst,
const VectorType &src)
const override;
411 const std::shared_ptr<const Utilities::MPI::Partitioner>
413 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner_fine)
431 template <
int dim,
typename Number>
507 const unsigned int fe_degree_coarse);
524 const std::shared_ptr<const Utilities::MPI::Partitioner>
526 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner_fine)
554 struct MGTransferScheme
651 friend class internal::MGTwoLevelTransferImplementation;
660 template <
int dim,
typename VectorType>
683 interpolate(VectorType &dst,
const VectorType &src)
const override;
700 template <
int dim,
typename Number>
715 struct AdditionalData
727 const unsigned int rtree_level = 0,
728 const bool enforce_all_points_found =
true)
729 : tolerance(tolerance)
730 , rtree_level(rtree_level)
731 , enforce_all_points_found(enforce_all_points_found)
790 const std::shared_ptr<const Utilities::MPI::Partitioner>
792 const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner_fine)
823 template <
int n_components>
832 template <
int n_components>
847 std::shared_ptr<NonMatching::MappingInfo<dim, dim, Number>>
mapping_info;
905 template <
int dim,
typename Number>
907 LinearAlgebra::distributed::Vector<Number>>
936 template <
typename MGTwoLevelTransferObject>
938 const std::function<
void(
const unsigned int,
VectorType &)>
944 template <
typename MGTwoLevelTransferObject>
958 build(
const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
999 const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
1010 const std::function<
void(
const unsigned int,
VectorType &)>
1050 template <
class InVector>
1054 const InVector &src)
const;
1062 template <
class OutVector>
1080 template <
class InVector>
1090 template <
class InVector>
1094 const InVector &src)
const;
1147 template <
typename MGTwoLevelTransferObject>
1155 template <
class InVector>
1159 const InVector &vector_reference,
1160 const bool omit_zeroing_entries)
const;
1177 std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
1188 template <
int dim,
typename Number>
1234 const std::vector<MGConstrainedDoFs> &mg_constrained_dofs);
1270 template <
int dim,
typename VectorType>
1274 template <
int dim,
typename VectorType>
1286 template <
int dim,
typename Number>
1287 template <
typename MGTwoLevelTransferObject>
1290 const std::function<
void(
const unsigned int, VectorType &)>
1291 &initialize_dof_vector)
1293 this->intitialize_transfer_references(transfer);
1294 this->build(initialize_dof_vector);
1299 template <
int dim,
typename Number>
1300 template <
typename MGTwoLevelTransferObject>
1305 this->intitialize_transfer_references(transfer);
1310 template <
int dim,
typename Number>
1311 template <
typename MGTwoLevelTransferObject>
1316 const unsigned int min_level = transfer.
min_level();
1317 const unsigned int max_level = transfer.
max_level();
1319 this->transfer.
resize(min_level, max_level);
1321 for (
unsigned int l = min_level;
l <= max_level; ++
l)
1329 template <
int dim,
typename Number>
1330 template <
class InVector>
1333 const unsigned int level,
1335 const InVector &vec_reference,
1336 const bool omit_zeroing_entries)
const
1338 std::shared_ptr<const Utilities::MPI::Partitioner> partitioner;
1340 if (external_partitioners.empty())
1342 partitioner = vec_reference.get_partitioner();
1349 partitioner = external_partitioners[
level - transfer.
min_level()];
1355 if (vec.get_partitioner().get() == partitioner.get())
1357 if (omit_zeroing_entries ==
false)
1363 if (vec.size() == partitioner->size() &&
1364 vec.locally_owned_size() == partitioner->locally_owned_size())
1366 if (omit_zeroing_entries ==
false)
1372 vec.reinit(partitioner, omit_zeroing_entries);
1377 template <
int dim,
typename Number>
1378 template <
class InVector>
1382 const InVector &src)
const
1388 const bool zero_out_values =
1389 (this->perform_plain_copy ==
false &&
1390 this->perform_renumbered_plain_copy ==
false) ||
1393 this->initialize_dof_vector(
level, dst[
level], src, !zero_out_values);
1396 if (this->perform_plain_copy)
1398 dst[dst.
max_level()].copy_locally_owned_data_from(src);
1400 else if (this->perform_renumbered_plain_copy)
1404 for (
unsigned int i = 0; i < this->copy_indices.back().n_cols(); ++i)
1405 dst_level.local_element(this->copy_indices.back()(1, i)) =
1406 src.local_element(i);
1410 this->ghosted_global_vector = src;
1411 this->ghosted_global_vector.update_ghost_values();
1417 auto &dst_level = dst[
l];
1419 const auto copy_unknowns = [&](
const auto &indices) {
1420 for (
unsigned int i = 0; i < indices.n_cols(); ++i)
1421 dst_level.local_element(indices(1, i)) =
1422 this->ghosted_global_vector.local_element(indices(0, i));
1425 copy_unknowns(this->copy_indices[
l]);
1426 copy_unknowns(this->copy_indices_level_mine[
l]);
1435 template <
int dim,
typename Number>
1436 template <
class OutVector>
1445 if (this->perform_plain_copy)
1447 dst.zero_out_ghost_values();
1448 dst.copy_locally_owned_data_from(src[src.
max_level()]);
1450 else if (this->perform_renumbered_plain_copy)
1452 const auto &src_level = src[src.
max_level()];
1453 dst.zero_out_ghost_values();
1454 for (
unsigned int i = 0; i < this->copy_indices.back().n_cols(); ++i)
1455 dst.local_element(i) =
1456 src_level.local_element(this->copy_indices.back()(1, i));
1463 auto &ghosted_vector = this->ghosted_level_vector[
l];
1465 if (this->ghosted_level_vector[
l].size() > 0)
1466 ghosted_vector = src[
l];
1468 const auto *
const ghosted_vector_ptr =
1469 (this->ghosted_level_vector[
l].size() > 0) ? &ghosted_vector :
1472 ghosted_vector_ptr->update_ghost_values();
1474 const auto copy_unknowns = [&](
const auto &indices) {
1475 for (
unsigned int i = 0; i < indices.n_cols(); ++i)
1476 dst.local_element(indices(0, i)) =
1477 ghosted_vector_ptr->local_element(indices(1, i));
1480 copy_unknowns(this->copy_indices[
l]);
1481 copy_unknowns(this->copy_indices_global_mine[
l]);
1489 template <
int dim,
typename Number>
1490 template <
class InVector>
1493 const InVector &src)
const
1495 const unsigned int min_level = transfer.
min_level();
1496 const unsigned int max_level = transfer.
max_level();
1503 const bool zero_out_values =
false;
1504 this->initialize_dof_vector(
level, dst[
level], src, !zero_out_values);
1507 if (this->perform_plain_copy)
1509 dst[max_level].copy_locally_owned_data_from(src);
1511 for (
unsigned int l = max_level;
l > min_level; --
l)
1514 else if (this->perform_renumbered_plain_copy)
1516 auto &dst_level = dst[max_level];
1518 for (
unsigned int i = 0; i < this->solution_copy_indices.back().n_cols();
1520 dst_level.local_element(this->solution_copy_indices.back()(1, i)) =
1521 src.local_element(i);
1523 for (
unsigned int l = max_level;
l > min_level; --
l)
1528 this->solution_ghosted_global_vector = src;
1529 this->solution_ghosted_global_vector.update_ghost_values();
1531 for (
unsigned int l = max_level + 1;
l != min_level;)
1535 auto &dst_level = dst[
l];
1537 const auto copy_unknowns = [&](
const auto &indices) {
1538 for (
unsigned int i = 0; i < indices.n_cols(); ++i)
1539 dst_level.local_element(indices(1, i)) =
1540 this->solution_ghosted_global_vector.local_element(
1544 copy_unknowns(this->solution_copy_indices[
l]);
1545 copy_unknowns(this->solution_copy_indices_level_mine[
l]);
1550 this->transfer[
l]->interpolate(dst[
l - 1], dst[
l]);
1557 template <
int dim,
typename Number>
1558 template <
class InVector>
1562 const InVector &src)
const
1566 this->interpolate_to_mg(dst, src);
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 intitialize_internal_transfer(const DoFHandler< dim > &dof_handler, const SmartPointer< 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 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
void intitialize_transfer_references(const MGLevelObject< MGTwoLevelTransferObject > &transfer)
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 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)
MGTransferMF(const MGConstrainedDoFs &mg_constrained_dofs)
MGLevelObject< MGTwoLevelTransfer< dim, VectorType > > internal_transfer
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 intitialize_two_level_transfers(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
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner_coarse_embedded
AlignedVector< Number > buffer_fine_embedded
LinearAlgebra::distributed::Vector< Number > vec_fine
void restrict_and_add(VectorType &dst, const VectorType &src) const
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, internal::MatrixFreeFunctions::ConstraintInfo< dim, VectorizedArray< Number, width >> &constraint_info_coarse, std::vector< unsigned int > &dof_indices_fine)
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
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
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
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 >())
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
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
const ::Triangulation< dim, spacedim > & tria