Reference documentation for deal.II version GIT c9976103bc 2022-12-09 17:30:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
mg_transfer_global_coarsening.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2020 - 2022 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_mg_transfer_global_coarsening_h
17 #define dealii_mg_transfer_global_coarsening_h
18 
21 
23 
26 
29 
32 
34 
35 // Forward declarations
36 #ifndef DOXYGEN
37 namespace internal
38 {
39  class MGTwoLevelTransferImplementation;
40 }
41 
43 {
44  template <int dim, int spacedim>
45  class Base;
46 }
47 #endif
48 
49 
50 
55 {
64  {
69  bisect,
79  go_to_one
80  };
81 
86  unsigned int
88  const unsigned int degree,
89  const PolynomialCoarseningSequenceType &p_sequence);
90 
96  std::vector<unsigned int>
98  const unsigned int max_degree,
99  const PolynomialCoarseningSequenceType &p_sequence);
100 
111  template <int dim, int spacedim>
112  std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
115 
132  template <int dim, int spacedim>
133  std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
137  const bool preserve_fine_triangulation,
138  const bool repartition_fine_triangulation);
139 
145  template <int dim, int spacedim>
146  std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
150  const bool repartition_fine_triangulation = false);
151 
152 } // namespace MGTransferGlobalCoarseningTools
153 
154 
155 
161 template <int dim, typename VectorType>
163 {
164 public:
168  void
169  prolongate_and_add(VectorType &dst, const VectorType &src) const;
170 
174  void
175  restrict_and_add(VectorType &dst, const VectorType &src) const;
176 
183  void
184  interpolate(VectorType &dst, const VectorType &src) const;
185 
190  void
192  const std::shared_ptr<const Utilities::MPI::Partitioner>
193  &partitioner_coarse,
194  const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner_fine);
195 
199  std::size_t
201 };
202 
203 
204 
211 template <int dim, typename Number>
213 {
214 public:
220  void
222  const DoFHandler<dim> & dof_handler_fine,
223  const DoFHandler<dim> & dof_handler_coarse,
224  const AffineConstraints<Number> &constraint_fine =
226  const AffineConstraints<Number> &constraint_coarse =
228  const unsigned int mg_level_fine = numbers::invalid_unsigned_int,
229  const unsigned int mg_level_coarse = numbers::invalid_unsigned_int);
230 
240  void
242  const DoFHandler<dim> & dof_handler_fine,
243  const DoFHandler<dim> & dof_handler_coarse,
244  const AffineConstraints<Number> &constraint_fine =
246  const AffineConstraints<Number> &constraint_coarse =
248  const unsigned int mg_level_fine = numbers::invalid_unsigned_int,
249  const unsigned int mg_level_coarse = numbers::invalid_unsigned_int);
250 
264  void
265  reinit(const DoFHandler<dim> & dof_handler_fine,
266  const DoFHandler<dim> & dof_handler_coarse,
267  const AffineConstraints<Number> &constraint_fine =
269  const AffineConstraints<Number> &constraint_coarse =
271  const unsigned int mg_level_fine = numbers::invalid_unsigned_int,
272  const unsigned int mg_level_coarse = numbers::invalid_unsigned_int);
273 
282  static bool
283  fast_polynomial_transfer_supported(const unsigned int fe_degree_fine,
284  const unsigned int fe_degree_coarse);
285 
289  void
293 
297  void
300 
307  void
310 
315  void
317  const std::shared_ptr<const Utilities::MPI::Partitioner>
318  &partitioner_coarse,
319  const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner_fine);
320 
324  std::size_t
326 
327 private:
328  void
330 
331  void
333  const VectorOperation::values) const;
334 
335  void
338 
346  struct MGTransferScheme
347  {
351  unsigned int n_coarse_cells;
352 
360 
367  unsigned int n_dofs_per_cell_fine;
368 
372  unsigned int degree_coarse;
373 
379  unsigned int degree_fine;
380 
385 
390 
395 
400 
407  };
408 
412  std::vector<MGTransferScheme> schemes;
413 
420 
424  std::shared_ptr<const Utilities::MPI::Partitioner> partitioner_fine;
425 
430  std::shared_ptr<const Utilities::MPI::Partitioner> partitioner_fine_embedded;
431 
437 
441  std::shared_ptr<const Utilities::MPI::Partitioner> partitioner_coarse;
442 
447  std::shared_ptr<const Utilities::MPI::Partitioner>
449 
455 
464 
469 
476 
480  std::vector<Number> weights;
481 
487 
492  std::vector<unsigned int> level_dof_indices_fine;
493 
497  unsigned int n_components;
498 
499  friend class internal::MGTwoLevelTransferImplementation;
500 };
501 
502 
503 
516 template <int dim, typename VectorType>
518 {
519 public:
523  using Number = typename VectorType::value_type;
524 
534  const std::function<void(const unsigned int, VectorType &)>
535  &initialize_dof_vector = {});
536 
545  void
546  build(const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
547  &external_partitioners = {});
548 
553  void
554  build(const std::function<void(const unsigned int, VectorType &)>
556 
560  void
561  prolongate(const unsigned int to_level,
562  VectorType & dst,
563  const VectorType & src) const override;
564 
568  void
569  prolongate_and_add(const unsigned int to_level,
570  VectorType & dst,
571  const VectorType & src) const override;
572 
576  virtual void
577  restrict_and_add(const unsigned int from_level,
578  VectorType & dst,
579  const VectorType & src) const override;
580 
587  template <class InVector, int spacedim>
588  void
591  const InVector & src) const;
592 
599  template <class OutVector, int spacedim>
600  void
602  OutVector & dst,
603  const MGLevelObject<VectorType> &src) const;
604 
617  template <class InVector>
618  void
619  interpolate_to_mg(MGLevelObject<VectorType> &dst, const InVector &src) const;
620 
627  template <class InVector, int spacedim>
628  void
631  const InVector & src) const;
632 
639  std::size_t
641 
645  unsigned int
646  min_level() const;
647 
651  unsigned int
652  max_level() const;
653 
654 private:
658  void
659  initialize_dof_vector(const unsigned int level, VectorType &vector) const;
660 
665 
669  std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
671 };
672 
673 
674 
680 template <int dim, typename VectorType>
683  dim,
684  typename VectorType::value_type,
685  MGTransferGlobalCoarsening<dim, VectorType>>
686 {
687 public:
693 
694 protected:
696  get_matrix_free_transfer(const unsigned int b) const override;
697 
698 private:
703 };
704 
705 
706 
707 #ifndef DOXYGEN
708 
709 /* ----------------------- Inline functions --------------------------------- */
710 
711 
712 
713 template <int dim, typename VectorType>
716  const std::function<void(const unsigned int, VectorType &)>
717  &initialize_dof_vector)
718  : transfer(transfer)
719 {
720  this->build(initialize_dof_vector);
721 }
722 
723 
724 
725 template <int dim, typename VectorType>
726 void
728  const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
729  &external_partitioners)
730 {
731  this->external_partitioners = external_partitioners;
732 
733  if (this->external_partitioners.size() > 0)
734  {
735  const unsigned int min_level = transfer.min_level();
736  const unsigned int max_level = transfer.max_level();
737 
738  AssertDimension(this->external_partitioners.size(), transfer.n_levels());
739 
740  for (unsigned int l = min_level + 1; l <= max_level; ++l)
741  transfer[l].enable_inplace_operations_if_possible(
742  this->external_partitioners[l - 1 - min_level],
743  this->external_partitioners[l - min_level]);
744  }
745 }
746 
747 
748 
749 template <int dim, typename VectorType>
750 void
752  const std::function<void(const unsigned int, VectorType &)>
753  &initialize_dof_vector)
754 {
755  if (initialize_dof_vector)
756  {
757  const unsigned int min_level = transfer.min_level();
758  const unsigned int max_level = transfer.max_level();
759  const unsigned int n_levels = transfer.n_levels();
760 
761  std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
762  external_partitioners(n_levels);
763 
764  for (unsigned int l = min_level; l <= max_level; ++l)
765  {
767  vector;
768  initialize_dof_vector(l, vector);
769  external_partitioners[l - min_level] = vector.get_partitioner();
770  }
771 
772  this->build(external_partitioners);
773  }
774  else
775  {
776  this->build();
777  }
778 }
779 
780 
781 
782 template <int dim, typename VectorType>
783 void
785  const unsigned int level,
786  VectorType & vec) const
787 {
788  AssertDimension(transfer.n_levels(), external_partitioners.size());
789  AssertIndexRange(level, transfer.max_level() + 1);
790 
791  const auto &external_partitioner =
792  external_partitioners[level - transfer.min_level()];
793 
794  if (vec.get_partitioner().get() != external_partitioner.get())
795  vec.reinit(external_partitioner);
796 }
797 
798 
799 
800 template <int dim, typename VectorType>
801 void
803  const unsigned int to_level,
804  VectorType & dst,
805  const VectorType & src) const
806 {
807  dst = 0;
808  prolongate_and_add(to_level, dst, src);
809 }
810 
811 
812 
813 template <int dim, typename VectorType>
814 void
816  const unsigned int to_level,
817  VectorType & dst,
818  const VectorType & src) const
819 {
820  this->transfer[to_level].prolongate_and_add(dst, src);
821 }
822 
823 
824 
825 template <int dim, typename VectorType>
826 void
828  const unsigned int from_level,
829  VectorType & dst,
830  const VectorType & src) const
831 {
832  this->transfer[from_level].restrict_and_add(dst, src);
833 }
834 
835 
836 
837 template <int dim, typename VectorType>
838 template <class InVector, int spacedim>
839 void
841  const DoFHandler<dim, spacedim> &dof_handler,
843  const InVector & src) const
844 {
845  (void)dof_handler;
846 
847  for (unsigned int level = dst.min_level(); level <= dst.max_level(); ++level)
848  {
849  initialize_dof_vector(level, dst[level]);
850 
851  if (level == dst.max_level())
852  dst[level].copy_locally_owned_data_from(src);
853  else
854  dst[level] = 0.0;
855  }
856 }
857 
858 
859 
860 template <int dim, typename VectorType>
861 template <class OutVector, int spacedim>
862 void
864  const DoFHandler<dim, spacedim> &dof_handler,
865  OutVector & dst,
866  const MGLevelObject<VectorType> &src) const
867 {
868  (void)dof_handler;
869 
870  dst.copy_locally_owned_data_from(src[src.max_level()]);
871 }
872 
873 
874 
875 template <int dim, typename VectorType>
876 template <class InVector>
877 void
880  const InVector & src) const
881 {
882  const unsigned int min_level = transfer.min_level();
883  const unsigned int max_level = transfer.max_level();
884 
885  AssertDimension(min_level, dst.min_level());
886  AssertDimension(max_level, dst.max_level());
887 
888  for (unsigned int level = min_level; level <= max_level; ++level)
889  initialize_dof_vector(level, dst[level]);
890 
891  dst[transfer.max_level()].copy_locally_owned_data_from(src);
892 
893  for (unsigned int l = max_level; l > min_level; --l)
894  this->transfer[l].interpolate(dst[l - 1], dst[l]);
895 }
896 
897 
898 
899 template <int dim, typename VectorType>
900 template <class InVector, int spacedim>
901 void
903  const DoFHandler<dim, spacedim> &dof_handler,
905  const InVector & src) const
906 {
907  (void)dof_handler;
908 
909  this->interpolate_to_mg(dst, src);
910 }
911 
912 
913 
914 template <int dim, typename VectorType>
915 std::size_t
917 {
918  std::size_t size = 0;
919 
920  const unsigned int min_level = transfer.min_level();
921  const unsigned int max_level = transfer.max_level();
922 
923  for (unsigned int l = min_level + 1; l <= max_level; ++l)
924  size += this->transfer[l].memory_consumption();
925 
926  return size;
927 }
928 
929 
930 
931 template <int dim, typename VectorType>
932 inline unsigned int
934 {
935  return transfer.min_level();
936 }
937 
938 
939 
940 template <int dim, typename VectorType>
941 inline unsigned int
943 {
944  return transfer.max_level();
945 }
946 
947 #endif
948 
950 
951 #endif
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_partitioner() const
unsigned int max_level() const
unsigned int min_level() const
MGTransferBlockGlobalCoarsening(const MGTransferGlobalCoarsening< dim, VectorType > &transfer_operator)
const MGTransferGlobalCoarsening< dim, VectorType > & transfer_operator
const MGTransferGlobalCoarsening< dim, VectorType > & get_matrix_free_transfer(const unsigned int b) const override
void copy_from_mg(const DoFHandler< dim, spacedim > &dof_handler, OutVector &dst, const MGLevelObject< VectorType > &src) const
void interpolate_to_mg(const DoFHandler< dim, spacedim > &dof_handler, MGLevelObject< VectorType > &dst, const InVector &src) const
void prolongate(const unsigned int to_level, VectorType &dst, const VectorType &src) const override
typename VectorType::value_type Number
unsigned int min_level() 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 copy_to_mg(const DoFHandler< dim, spacedim > &dof_handler, MGLevelObject< VectorType > &dst, const InVector &src) const
virtual void restrict_and_add(const unsigned int from_level, VectorType &dst, const VectorType &src) const override
std::size_t memory_consumption() const
void initialize_dof_vector(const unsigned int level, VectorType &vector) const
void build(const std::function< void(const unsigned int, VectorType &)> &initialize_dof_vector)
void interpolate_to_mg(MGLevelObject< VectorType > &dst, const InVector &src) const
MGLevelObject< MGTwoLevelTransfer< dim, VectorType > > transfer
void prolongate_and_add(const unsigned int to_level, VectorType &dst, const VectorType &src) const override
MGTransferGlobalCoarsening(const MGLevelObject< MGTwoLevelTransfer< dim, VectorType >> &transfer, const std::function< void(const unsigned int, VectorType &)> &initialize_dof_vector={})
unsigned int max_level() const
void update_ghost_values(const LinearAlgebra::distributed::Vector< Number > &) const
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)
void prolongate_and_add(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const
void zero_out_ghost_values(const LinearAlgebra::distributed::Vector< Number > &) const
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)
static bool fast_polynomial_transfer_supported(const unsigned int fe_degree_fine, const unsigned int fe_degree_coarse)
void compress(LinearAlgebra::distributed::Vector< Number > &, const VectorOperation::values) const
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner_fine_embedded
void interpolate(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const
internal::MatrixFreeFunctions::ConstraintInfo< dim, VectorizedArray< Number > > constraint_info
void restrict_and_add(LinearAlgebra::distributed::Vector< Number > &dst, const LinearAlgebra::distributed::Vector< Number > &src) const
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 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)
std::shared_ptr< const Utilities::MPI::Partitioner > partitioner_coarse_embedded
void restrict_and_add(VectorType &dst, const VectorType &src) const
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)
std::size_t memory_consumption() const
void interpolate(VectorType &dst, const VectorType &src) const
void prolongate_and_add(VectorType &dst, const VectorType &src) const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:458
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:459
unsigned int level
Definition: grid_out.cc:4608
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1695
#define AssertIndexRange(index, range)
Definition: exceptions.h:1760
void interpolate(const DoFHandler< dim, spacedim > &dof1, const InVector &u1, const DoFHandler< dim, spacedim > &dof2, OutVector &u2)
std::vector< std::shared_ptr< const Triangulation< dim, spacedim > > > create_geometric_coarsening_sequence(const Triangulation< dim, spacedim > &tria)
unsigned int create_next_polynomial_coarsening_degree(const unsigned int degree, const PolynomialCoarseningSequenceType &p_sequence)
std::vector< unsigned int > create_polynomial_coarsening_sequence(const unsigned int max_degree, const PolynomialCoarseningSequenceType &p_sequence)
std::enable_if_t< std::is_fundamental< T >::value, std::size_t > memory_consumption(const T &t)
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)
static const unsigned int invalid_unsigned_int
Definition: types.h:206
internal::MatrixFreeFunctions::ShapeInfo< VectorizedArray< Number > > shape_info_coarse
const ::Triangulation< dim, spacedim > & tria