Reference documentation for deal.II version Git 73c87d96ef 2021-11-30 22:54:44 +0100
\(\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 
28 
30 
31 // Forward declarations
32 #ifndef DOXYGEN
33 namespace internal
34 {
35  class MGTwoLevelTransferImplementation;
36 }
37 
39 {
40  template <int dim, int spacedim>
41  class Base;
42 }
43 #endif
44 
45 
46 
51 {
60  {
65  bisect,
75  go_to_one
76  };
77 
82  unsigned int
84  const unsigned int degree,
85  const PolynomialCoarseningSequenceType &p_sequence);
86 
92  std::vector<unsigned int>
94  const unsigned int max_degree,
95  const PolynomialCoarseningSequenceType &p_sequence);
96 
107  template <int dim, int spacedim>
108  std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
111 
128  template <int dim, int spacedim>
129  std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
133  const bool preserve_fine_triangulation,
134  const bool repartition_fine_triangulation);
135 
141  template <int dim, int spacedim>
142  std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
144  const Triangulation<dim, spacedim> & tria,
146  const bool repartition_fine_triangulation = false);
147 
148 } // namespace MGTransferGlobalCoarseningTools
149 
150 
151 
155 template <int dim, typename VectorType>
157 {
158 public:
162  void
163  prolongate_and_add(VectorType &dst, const VectorType &src) const;
164 
168  void
169  restrict_and_add(VectorType &dst, const VectorType &src) const;
170 
177  void
178  interpolate(VectorType &dst, const VectorType &src) const;
179 
183  std::size_t
184  memory_consumption() const;
185 };
186 
187 
188 
193 template <int dim, typename Number>
195 {
196 public:
202  void
203  reinit_geometric_transfer(
204  const DoFHandler<dim> & dof_handler_fine,
205  const DoFHandler<dim> & dof_handler_coarse,
206  const AffineConstraints<Number> &constraint_fine =
208  const AffineConstraints<Number> &constraint_coarse =
210  const unsigned int mg_level_fine = numbers::invalid_unsigned_int,
211  const unsigned int mg_level_coarse = numbers::invalid_unsigned_int);
212 
222  void
223  reinit_polynomial_transfer(
224  const DoFHandler<dim> & dof_handler_fine,
225  const DoFHandler<dim> & dof_handler_coarse,
226  const AffineConstraints<Number> &constraint_fine =
228  const AffineConstraints<Number> &constraint_coarse =
230  const unsigned int mg_level_fine = numbers::invalid_unsigned_int,
231  const unsigned int mg_level_coarse = numbers::invalid_unsigned_int);
232 
246  void
247  reinit(const DoFHandler<dim> & dof_handler_fine,
248  const DoFHandler<dim> & dof_handler_coarse,
249  const AffineConstraints<Number> &constraint_fine =
251  const AffineConstraints<Number> &constraint_coarse =
253  const unsigned int mg_level_fine = numbers::invalid_unsigned_int,
254  const unsigned int mg_level_coarse = numbers::invalid_unsigned_int);
255 
264  static bool
265  fast_polynomial_transfer_supported(const unsigned int fe_degree_fine,
266  const unsigned int fe_degree_coarse);
267 
271  void
272  prolongate_and_add(
275 
279  void
280  restrict_and_add(LinearAlgebra::distributed::Vector<Number> & dst,
282 
289  void
292 
296  std::size_t
297  memory_consumption() const;
298 
299 private:
307  struct MGTransferScheme
308  {
312  unsigned int n_coarse_cells;
313 
321 
328  unsigned int n_dofs_per_cell_fine;
329 
333  unsigned int degree_coarse;
334 
340  unsigned int degree_fine;
341 
346 
351 
356 
361  };
362 
366  std::vector<MGTransferScheme> schemes;
367 
374 
378  std::shared_ptr<const Utilities::MPI::Partitioner> partitioner_fine;
379 
383  std::shared_ptr<const Utilities::MPI::Partitioner> partitioner_coarse;
384 
393 
398 
403  std::vector<unsigned int> distribute_local_to_global_indices;
404 
410 
415  std::vector<unsigned int> distribute_local_to_global_ptr;
416 
420  std::vector<Number> weights;
421 
426  std::vector<unsigned int> level_dof_indices_coarse;
427 
432  std::vector<unsigned int> level_dof_indices_fine;
433 
437  unsigned int n_components;
438 
439  friend class internal::MGTwoLevelTransferImplementation;
440 };
441 
442 
443 
454 template <int dim, typename VectorType>
456 {
457 public:
461  using Number = typename VectorType::value_type;
462 
472  const std::function<void(const unsigned int, VectorType &)>
473  &initialize_dof_vector = {});
474 
478  void
479  prolongate(const unsigned int to_level,
480  VectorType & dst,
481  const VectorType & src) const override;
482 
486  void
487  prolongate_and_add(const unsigned int to_level,
488  VectorType & dst,
489  const VectorType & src) const override;
490 
494  virtual void
495  restrict_and_add(const unsigned int from_level,
496  VectorType & dst,
497  const VectorType & src) const override;
498 
505  template <class InVector, int spacedim>
506  void
507  copy_to_mg(const DoFHandler<dim, spacedim> &dof_handler,
509  const InVector & src) const;
510 
517  template <class OutVector, int spacedim>
518  void
519  copy_from_mg(const DoFHandler<dim, spacedim> &dof_handler,
520  OutVector & dst,
521  const MGLevelObject<VectorType> &src) const;
522 
535  template <class InVector>
536  void
537  interpolate_to_mg(MGLevelObject<VectorType> &dst, const InVector &src) const;
538 
545  template <class InVector, int spacedim>
546  void
547  interpolate_to_mg(const DoFHandler<dim, spacedim> &dof_handler,
549  const InVector & src) const;
550 
557  std::size_t
558  memory_consumption() const;
559 
560 private:
565 
569  const std::function<void(const unsigned int, VectorType &)>
571 };
572 
573 
574 
575 #ifndef DOXYGEN
576 
577 /* ----------------------- Inline functions --------------------------------- */
578 
579 
580 
581 template <int dim, typename VectorType>
584  const std::function<void(const unsigned int, VectorType &)>
585  &initialize_dof_vector)
586  : transfer(transfer)
587  , initialize_dof_vector(initialize_dof_vector)
588 {}
589 
590 
591 
592 template <int dim, typename VectorType>
593 void
595  const unsigned int to_level,
596  VectorType & dst,
597  const VectorType & src) const
598 {
599  dst = 0;
600  prolongate_and_add(to_level, dst, src);
601 }
602 
603 
604 
605 template <int dim, typename VectorType>
606 void
608  const unsigned int to_level,
609  VectorType & dst,
610  const VectorType & src) const
611 {
612  this->transfer[to_level].prolongate_and_add(dst, src);
613 }
614 
615 
616 
617 template <int dim, typename VectorType>
618 void
620  const unsigned int from_level,
621  VectorType & dst,
622  const VectorType & src) const
623 {
624  this->transfer[from_level].restrict_and_add(dst, src);
625 }
626 
627 
628 
629 template <int dim, typename VectorType>
630 template <class InVector, int spacedim>
631 void
633  const DoFHandler<dim, spacedim> &dof_handler,
635  const InVector & src) const
636 {
637  (void)dof_handler;
638 
639  Assert(
641  ExcMessage(
642  "To be able to use this function, a function to initialize an internal "
643  "DoF vector has to be provided in the constructor of "
644  "MGTransferGlobalCoarsening."));
645 
646  for (unsigned int level = dst.min_level(); level <= dst.max_level(); ++level)
647  {
649 
650  if (level == dst.max_level())
651  dst[level].copy_locally_owned_data_from(src);
652  else
653  dst[level] = 0.0;
654  }
655 }
656 
657 
658 
659 template <int dim, typename VectorType>
660 template <class OutVector, int spacedim>
661 void
663  const DoFHandler<dim, spacedim> &dof_handler,
664  OutVector & dst,
665  const MGLevelObject<VectorType> &src) const
666 {
667  (void)dof_handler;
668 
669  dst.copy_locally_owned_data_from(src[src.max_level()]);
670 }
671 
672 
673 
674 template <int dim, typename VectorType>
675 template <class InVector>
676 void
679  const InVector & src) const
680 {
681  Assert(
683  ExcMessage(
684  "To be able to use this function, a function to initialize an internal "
685  "DoF vector has to be provided in the constructor of "
686  "MGTransferGlobalCoarsening."));
687 
688  const unsigned int min_level = transfer.min_level();
689  const unsigned int max_level = transfer.max_level();
690 
691  AssertDimension(min_level, dst.min_level());
692  AssertDimension(max_level, dst.max_level());
693 
694  for (unsigned int level = min_level; level <= max_level; ++level)
696 
697  dst[transfer.max_level()].copy_locally_owned_data_from(src);
698 
699  for (unsigned int l = max_level; l > min_level; --l)
700  this->transfer[l].interpolate(dst[l - 1], dst[l]);
701 }
702 
703 
704 
705 template <int dim, typename VectorType>
706 template <class InVector, int spacedim>
707 void
709  const DoFHandler<dim, spacedim> &dof_handler,
711  const InVector & src) const
712 {
713  (void)dof_handler;
714 
715  this->interpolate_to_mg(dst, src);
716 }
717 
718 
719 
720 template <int dim, typename VectorType>
721 std::size_t
723 {
724  std::size_t size = 0;
725 
726  const unsigned int min_level = transfer.min_level();
727  const unsigned int max_level = transfer.max_level();
728 
729  for (unsigned int l = min_level + 1; l <= max_level; ++l)
730  size += this->transfer[l].memory_consumption();
731 
732  return size;
733 }
734 
735 #endif
736 
738 
739 #endif
unsigned int max_level() const
std::size_t memory_consumption() const
static const unsigned int invalid_unsigned_int
Definition: types.h:196
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
Definition: matrix_block.h:618
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1655
const std::function< void(const unsigned int, VectorType &)> initialize_dof_vector
void copy_from_mg(const DoFHandler< dim, spacedim > &dof_handler, OutVector &dst, const MGLevelObject< VectorType > &src) const
const ::Triangulation< dim, spacedim > & tria
void prolongate(const unsigned int to_level, VectorType &dst, const VectorType &src) const override
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, const RepartitioningPolicyTools::Base< dim, spacedim > &policy, const bool repartition_fine_triangulation=false)
const MGLevelObject< MGTwoLevelTransfer< dim, VectorType > > & transfer
unsigned int min_level() const
void prolongate_and_add(const unsigned int to_level, VectorType &dst, const VectorType &src) const override
std::vector< unsigned int > create_polynomial_coarsening_sequence(const unsigned int max_degree, const PolynomialCoarseningSequenceType &p_sequence)
void copy_to_mg(const DoFHandler< dim, spacedim > &dof_handler, MGLevelObject< VectorType > &dst, const InVector &src) const
unsigned int create_next_polynomial_coarsening_degree(const unsigned int degree, const PolynomialCoarseningSequenceType &p_sequence)
static ::ExceptionBase & ExcMessage(std::string arg1)
void interpolate_to_mg(MGLevelObject< VectorType > &dst, const InVector &src) const
#define Assert(cond, exc)
Definition: exceptions.h:1461
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:401
unsigned int level
Definition: grid_out.cc:4614
MGTransferGlobalCoarsening(const MGLevelObject< MGTwoLevelTransfer< dim, VectorType >> &transfer, const std::function< void(const unsigned int, VectorType &)> &initialize_dof_vector={})
typename VectorType::value_type Number
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:400
virtual void restrict_and_add(const unsigned int from_level, VectorType &dst, const VectorType &src) const override
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)