Reference documentation for deal.II version GIT 6d02bd1105 2022-05-22 03:35:01+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 - 2021 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 
159 template <int dim, typename VectorType>
161 {
162 public:
166  void
167  prolongate_and_add(VectorType &dst, const VectorType &src) const;
168 
172  void
173  restrict_and_add(VectorType &dst, const VectorType &src) const;
174 
181  void
182  interpolate(VectorType &dst, const VectorType &src) const;
183 
188  void
190  const std::shared_ptr<const Utilities::MPI::Partitioner>
191  &partitioner_coarse,
192  const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner_fine);
193 
197  std::size_t
199 };
200 
201 
202 
207 template <int dim, typename Number>
209 {
210 public:
216  void
218  const DoFHandler<dim> & dof_handler_fine,
219  const DoFHandler<dim> & dof_handler_coarse,
220  const AffineConstraints<Number> &constraint_fine =
222  const AffineConstraints<Number> &constraint_coarse =
224  const unsigned int mg_level_fine = numbers::invalid_unsigned_int,
225  const unsigned int mg_level_coarse = numbers::invalid_unsigned_int);
226 
236  void
238  const DoFHandler<dim> & dof_handler_fine,
239  const DoFHandler<dim> & dof_handler_coarse,
240  const AffineConstraints<Number> &constraint_fine =
242  const AffineConstraints<Number> &constraint_coarse =
244  const unsigned int mg_level_fine = numbers::invalid_unsigned_int,
245  const unsigned int mg_level_coarse = numbers::invalid_unsigned_int);
246 
260  void
261  reinit(const DoFHandler<dim> & dof_handler_fine,
262  const DoFHandler<dim> & dof_handler_coarse,
263  const AffineConstraints<Number> &constraint_fine =
265  const AffineConstraints<Number> &constraint_coarse =
267  const unsigned int mg_level_fine = numbers::invalid_unsigned_int,
268  const unsigned int mg_level_coarse = numbers::invalid_unsigned_int);
269 
278  static bool
279  fast_polynomial_transfer_supported(const unsigned int fe_degree_fine,
280  const unsigned int fe_degree_coarse);
281 
285  void
289 
293  void
296 
303  void
306 
311  void
313  const std::shared_ptr<const Utilities::MPI::Partitioner>
314  &partitioner_coarse,
315  const std::shared_ptr<const Utilities::MPI::Partitioner> &partitioner_fine);
316 
320  std::size_t
322 
323 private:
331  struct MGTransferScheme
332  {
336  unsigned int n_coarse_cells;
337 
345 
352  unsigned int n_dofs_per_cell_fine;
353 
357  unsigned int degree_coarse;
358 
364  unsigned int degree_fine;
365 
370 
375 
380 
385 
392  };
393 
397  std::vector<MGTransferScheme> schemes;
398 
405 
409  std::shared_ptr<const Utilities::MPI::Partitioner> partitioner_fine;
410 
414  std::shared_ptr<const Utilities::MPI::Partitioner> partitioner_coarse;
415 
424 
429 
436 
440  std::vector<Number> weights;
441 
447 
452  std::vector<unsigned int> level_dof_indices_fine;
453 
457  unsigned int n_components;
458 
459  friend class internal::MGTwoLevelTransferImplementation;
460 };
461 
462 
463 
474 template <int dim, typename VectorType>
476 {
477 public:
481  using Number = typename VectorType::value_type;
482 
492  const std::function<void(const unsigned int, VectorType &)>
493  &initialize_dof_vector = {});
494 
502  void
503  build(const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
504  &external_partitioners = {});
505 
510  void
511  build(const std::function<void(const unsigned int, VectorType &)>
513 
517  void
518  prolongate(const unsigned int to_level,
519  VectorType & dst,
520  const VectorType & src) const override;
521 
525  void
526  prolongate_and_add(const unsigned int to_level,
527  VectorType & dst,
528  const VectorType & src) const override;
529 
533  virtual void
534  restrict_and_add(const unsigned int from_level,
535  VectorType & dst,
536  const VectorType & src) const override;
537 
544  template <class InVector, int spacedim>
545  void
548  const InVector & src) const;
549 
556  template <class OutVector, int spacedim>
557  void
559  OutVector & dst,
560  const MGLevelObject<VectorType> &src) const;
561 
574  template <class InVector>
575  void
576  interpolate_to_mg(MGLevelObject<VectorType> &dst, const InVector &src) const;
577 
584  template <class InVector, int spacedim>
585  void
588  const InVector & src) const;
589 
596  std::size_t
598 
599 private:
603  void
604  initialize_dof_vector(const unsigned int level, VectorType &vector) const;
605 
610 
614  std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
616 };
617 
618 
619 
625 template <int dim, typename VectorType>
628  dim,
629  typename VectorType::value_type,
630  MGTransferGlobalCoarsening<dim, VectorType>>
631 {
632 public:
638 
639 protected:
641  get_matrix_free_transfer(const unsigned int b) const override;
642 
643 private:
648 };
649 
650 
651 
652 #ifndef DOXYGEN
653 
654 /* ----------------------- Inline functions --------------------------------- */
655 
656 
657 
658 template <int dim, typename VectorType>
661  const std::function<void(const unsigned int, VectorType &)>
662  &initialize_dof_vector)
663  : transfer(transfer)
664 {
665  this->build(initialize_dof_vector);
666 }
667 
668 
669 
670 template <int dim, typename VectorType>
671 void
673  const std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
674  &external_partitioners)
675 {
676  this->external_partitioners = external_partitioners;
677 
678  if (this->external_partitioners.size() > 0)
679  {
680  const unsigned int min_level = transfer.min_level();
681  const unsigned int max_level = transfer.max_level();
682 
683  AssertDimension(this->external_partitioners.size(), transfer.n_levels());
684 
685  for (unsigned int l = min_level + 1; l <= max_level; ++l)
686  transfer[l].enable_inplace_operations_if_possible(
687  this->external_partitioners[l - 1 - min_level],
688  this->external_partitioners[l - min_level]);
689  }
690 }
691 
692 
693 
694 template <int dim, typename VectorType>
695 void
697  const std::function<void(const unsigned int, VectorType &)>
698  &initialize_dof_vector)
699 {
700  if (initialize_dof_vector)
701  {
702  const unsigned int min_level = transfer.min_level();
703  const unsigned int max_level = transfer.max_level();
704  const unsigned int n_levels = transfer.n_levels();
705 
706  std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>>
707  external_partitioners(n_levels);
708 
709  for (unsigned int l = min_level; l <= max_level; ++l)
710  {
712  vector;
713  initialize_dof_vector(l, vector);
714  external_partitioners[l - min_level] = vector.get_partitioner();
715  }
716 
717  this->build(external_partitioners);
718  }
719  else
720  {
721  this->build();
722  }
723 }
724 
725 
726 
727 template <int dim, typename VectorType>
728 void
730  const unsigned int level,
731  VectorType & vec) const
732 {
733  AssertDimension(transfer.n_levels(), external_partitioners.size());
734  AssertIndexRange(level, transfer.max_level() + 1);
735 
736  const auto &external_partitioner =
737  external_partitioners[level - transfer.min_level()];
738 
739  if (vec.get_partitioner().get() != external_partitioner.get())
740  vec.reinit(external_partitioner);
741 }
742 
743 
744 
745 template <int dim, typename VectorType>
746 void
748  const unsigned int to_level,
749  VectorType & dst,
750  const VectorType & src) const
751 {
752  dst = 0;
753  prolongate_and_add(to_level, dst, src);
754 }
755 
756 
757 
758 template <int dim, typename VectorType>
759 void
761  const unsigned int to_level,
762  VectorType & dst,
763  const VectorType & src) const
764 {
765  this->transfer[to_level].prolongate_and_add(dst, src);
766 }
767 
768 
769 
770 template <int dim, typename VectorType>
771 void
773  const unsigned int from_level,
774  VectorType & dst,
775  const VectorType & src) const
776 {
777  this->transfer[from_level].restrict_and_add(dst, src);
778 }
779 
780 
781 
782 template <int dim, typename VectorType>
783 template <class InVector, int spacedim>
784 void
786  const DoFHandler<dim, spacedim> &dof_handler,
788  const InVector & src) const
789 {
790  (void)dof_handler;
791 
792  for (unsigned int level = dst.min_level(); level <= dst.max_level(); ++level)
793  {
794  initialize_dof_vector(level, dst[level]);
795 
796  if (level == dst.max_level())
797  dst[level].copy_locally_owned_data_from(src);
798  else
799  dst[level] = 0.0;
800  }
801 }
802 
803 
804 
805 template <int dim, typename VectorType>
806 template <class OutVector, int spacedim>
807 void
809  const DoFHandler<dim, spacedim> &dof_handler,
810  OutVector & dst,
811  const MGLevelObject<VectorType> &src) const
812 {
813  (void)dof_handler;
814 
815  dst.copy_locally_owned_data_from(src[src.max_level()]);
816 }
817 
818 
819 
820 template <int dim, typename VectorType>
821 template <class InVector>
822 void
825  const InVector & src) const
826 {
827  const unsigned int min_level = transfer.min_level();
828  const unsigned int max_level = transfer.max_level();
829 
830  AssertDimension(min_level, dst.min_level());
831  AssertDimension(max_level, dst.max_level());
832 
833  for (unsigned int level = min_level; level <= max_level; ++level)
834  initialize_dof_vector(level, dst[level]);
835 
836  dst[transfer.max_level()].copy_locally_owned_data_from(src);
837 
838  for (unsigned int l = max_level; l > min_level; --l)
839  this->transfer[l].interpolate(dst[l - 1], dst[l]);
840 }
841 
842 
843 
844 template <int dim, typename VectorType>
845 template <class InVector, int spacedim>
846 void
848  const DoFHandler<dim, spacedim> &dof_handler,
850  const InVector & src) const
851 {
852  (void)dof_handler;
853 
854  this->interpolate_to_mg(dst, src);
855 }
856 
857 
858 
859 template <int dim, typename VectorType>
860 std::size_t
862 {
863  std::size_t size = 0;
864 
865  const unsigned int min_level = transfer.min_level();
866  const unsigned int max_level = transfer.max_level();
867 
868  for (unsigned int l = min_level + 1; l <= max_level; ++l)
869  size += this->transfer[l].memory_consumption();
870 
871  return size;
872 }
873 
874 #endif
875 
877 
878 #endif
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
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={})
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 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 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)
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:416
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:417
unsigned int level
Definition: grid_out.cc:4606
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1667
#define AssertIndexRange(index, range)
Definition: exceptions.h:1732
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_partitioner() const
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< std::is_fundamental< T >::value, std::size_t >::type 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:201
internal::MatrixFreeFunctions::ShapeInfo< VectorizedArray< Number > > shape_info_coarse
const ::Triangulation< dim, spacedim > & tria