Reference documentation for deal.II version 8.5.1
multigrid.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2016 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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__multigrid_h
17 #define dealii__multigrid_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/subscriptor.h>
22 #include <deal.II/base/smartpointer.h>
23 #include <deal.II/dofs/dof_handler.h>
24 #include <deal.II/lac/sparse_matrix.h>
25 #include <deal.II/lac/vector.h>
26 #include <deal.II/multigrid/mg_base.h>
27 #include <deal.II/base/mg_level_object.h>
28 #include <deal.II/distributed/tria.h>
29 
30 #include <vector>
31 
32 DEAL_II_NAMESPACE_OPEN
33 
36 
64 template <typename VectorType>
65 class Multigrid : public Subscriptor
66 {
67 public:
71  enum Cycle
72  {
79  };
80 
81  typedef VectorType vector_type;
82  typedef const VectorType const_vector_type;
83 
99  template <int dim>
100  Multigrid(const DoFHandler<dim> &mg_dof_handler,
106  const unsigned int minlevel = 0,
107  const unsigned int maxlevel = numbers::invalid_unsigned_int,
108  Cycle cycle = v_cycle) DEAL_II_DEPRECATED;
109 
124  const unsigned int minlevel = 0,
125  const unsigned int maxlevel = numbers::invalid_unsigned_int,
126  Cycle cycle = v_cycle);
127 
131  void reinit (const unsigned int minlevel,
132  const unsigned int maxlevel);
133 
138  void cycle ();
139 
150  void vcycle ();
151 
166 
181 
185  unsigned int get_maxlevel() const;
186 
190  unsigned int get_minlevel() const;
191 
197  void set_maxlevel (const unsigned int);
198 
214  void set_minlevel (const unsigned int level,
215  bool relative = false);
216 
220  void set_cycle(Cycle);
221 
226  void set_debug (const unsigned int);
227 
228 private:
229 
236  void level_v_step (const unsigned int level);
237 
245  void level_step (const unsigned int level, Cycle cycle);
246 
251 
255  unsigned int minlevel;
256 
260  unsigned int maxlevel;
261 
262 public:
268 
273 
274 private:
279 
284 
285 
290 
295 
300 
305 
310 
317 
325 
332 
339 
343  unsigned int debug;
344 
345  template<int dim, class OtherVectorType, class TRANSFER> friend class PreconditionMG;
346 };
347 
348 
361 template<int dim, typename VectorType, class TRANSFER>
363 {
364 public:
371  const TRANSFER &transfer);
372 
376  bool empty () const;
377 
384  template<class OtherVectorType>
385  void vmult (OtherVectorType &dst,
386  const OtherVectorType &src) const;
387 
392  template<class OtherVectorType>
393  void vmult_add (OtherVectorType &dst,
394  const OtherVectorType &src) const;
395 
401  template<class OtherVectorType>
402  void Tvmult (OtherVectorType &dst,
403  const OtherVectorType &src) const;
404 
410  template<class OtherVectorType>
411  void Tvmult_add (OtherVectorType &dst,
412  const OtherVectorType &src) const;
413 
418 
423 
427  MPI_Comm get_mpi_communicator() const;
428 
429 private:
434 
439 
444 };
445 
448 #ifndef DOXYGEN
449 /* --------------------------- inline functions --------------------- */
450 
451 
452 template <typename VectorType>
453 template <int dim>
455  const MGMatrixBase<VectorType> &matrix,
456  const MGCoarseGridBase<VectorType> &coarse,
457  const MGTransferBase<VectorType> &transfer,
458  const MGSmootherBase<VectorType> &pre_smooth,
459  const MGSmootherBase<VectorType> &post_smooth,
460  const unsigned int min_level,
461  const unsigned int max_level,
462  Cycle cycle)
463  :
464  cycle_type(cycle),
465  minlevel(min_level),
466  matrix(&matrix, typeid(*this).name()),
467  coarse(&coarse, typeid(*this).name()),
468  transfer(&transfer, typeid(*this).name()),
469  pre_smooth(&pre_smooth, typeid(*this).name()),
470  post_smooth(&post_smooth, typeid(*this).name()),
471  edge_down(0, typeid(*this).name()),
472  edge_up(0, typeid(*this).name()),
473  debug(0)
474 {
475  const unsigned int dof_handler_max_level
476  = mg_dof_handler.get_triangulation().n_global_levels()-1;
477  if (max_level == numbers::invalid_unsigned_int)
478  maxlevel = dof_handler_max_level;
479  else
480  maxlevel = max_level;
481 
482  reinit(minlevel, maxlevel);
483 }
484 
485 
486 
487 template <typename VectorType>
489  const MGCoarseGridBase<VectorType> &coarse,
490  const MGTransferBase<VectorType> &transfer,
491  const MGSmootherBase<VectorType> &pre_smooth,
492  const MGSmootherBase<VectorType> &post_smooth,
493  const unsigned int min_level,
494  const unsigned int max_level,
495  Cycle cycle)
496  :
497  cycle_type(cycle),
498  matrix(&matrix, typeid(*this).name()),
499  coarse(&coarse, typeid(*this).name()),
500  transfer(&transfer, typeid(*this).name()),
501  pre_smooth(&pre_smooth, typeid(*this).name()),
502  post_smooth(&post_smooth, typeid(*this).name()),
503  edge_out(0, typeid(*this).name()),
504  edge_in(0, typeid(*this).name()),
505  edge_down(0, typeid(*this).name()),
506  edge_up(0, typeid(*this).name()),
507  debug(0)
508 {
509  if (max_level == numbers::invalid_unsigned_int)
510  maxlevel = matrix.get_maxlevel();
511  else
512  maxlevel = max_level;
513  reinit(min_level, maxlevel);
514 }
515 
516 
517 
518 template <typename VectorType>
519 inline
520 unsigned int
522 {
523  return maxlevel;
524 }
525 
526 
527 
528 template <typename VectorType>
529 inline
530 unsigned int
532 {
533  return minlevel;
534 }
535 
536 
537 /* --------------------------- inline functions --------------------- */
538 
539 
540 template<int dim, typename VectorType, class TRANSFER>
542 ::PreconditionMG(const DoFHandler<dim> &dof_handler,
544  const TRANSFER &transfer)
545  :
546  dof_handler(&dof_handler),
547  multigrid(&mg),
548  transfer(&transfer)
549 {}
550 
551 template<int dim, typename VectorType, class TRANSFER>
552 inline bool
554 {
555  return false;
556 }
557 
558 template<int dim, typename VectorType, class TRANSFER>
559 template<class OtherVectorType>
560 void
562 (OtherVectorType &dst,
563  const OtherVectorType &src) const
564 {
565  transfer->copy_to_mg(*dof_handler,
566  multigrid->defect,
567  src);
568  multigrid->cycle();
569 
570  transfer->copy_from_mg(*dof_handler,
571  dst,
572  multigrid->solution);
573 }
574 
575 
576 template<int dim, typename VectorType, class TRANSFER>
577 IndexSet
579 {
580  return dof_handler->locally_owned_dofs();
581 }
582 
583 
584 template<int dim, typename VectorType, class TRANSFER>
585 IndexSet
587 {
588  return dof_handler->locally_owned_dofs();
589 }
590 
591 
592 template<int dim, typename VectorType, class TRANSFER>
593 MPI_Comm
595 {
596  // currently parallel GMG works with distributed Triangulation only,
597  // so it should be a safe bet to use it to query MPI communicator:
598  const Triangulation<dim> &tria = dof_handler->get_triangulation();
600  Assert (ptria != NULL, ExcInternalError());
601  return ptria->get_communicator ();
602 }
603 
604 
605 template<int dim, typename VectorType, class TRANSFER>
606 template<class OtherVectorType>
607 void
609 (OtherVectorType &dst,
610  const OtherVectorType &src) const
611 {
612  transfer->copy_to_mg(*dof_handler,
613  multigrid->defect,
614  src);
615  multigrid->cycle();
616  transfer->copy_from_mg_add(*dof_handler,
617  dst,
618  multigrid->solution);
619 }
620 
621 
622 template<int dim, typename VectorType, class TRANSFER>
623 template<class OtherVectorType>
624 void
626 (OtherVectorType &,
627  const OtherVectorType &) const
628 {
629  Assert(false, ExcNotImplemented());
630 }
631 
632 
633 template<int dim, typename VectorType, class TRANSFER>
634 template<class OtherVectorType>
635 void
637 (OtherVectorType &,
638  const OtherVectorType &) const
639 {
640  Assert(false, ExcNotImplemented());
641 }
642 
643 #endif // DOXYGEN
644 
645 DEAL_II_NAMESPACE_CLOSE
646 
647 #endif
SmartPointer< const MGMatrixBase< VectorType >, Multigrid< VectorType > > matrix
Definition: multigrid.h:289
void vcycle()
void cycle()
SmartPointer< const TRANSFER, PreconditionMG< dim, VectorType, TRANSFER > > transfer
Definition: multigrid.h:443
IndexSet locally_owned_domain_indices() const
static const unsigned int invalid_unsigned_int
Definition: types.h:170
SmartPointer< const MGMatrixBase< VectorType > > edge_in
Definition: multigrid.h:324
void vmult(OtherVectorType &dst, const OtherVectorType &src) const
MPI_Comm get_mpi_communicator() const
void set_edge_matrices(const MGMatrixBase< VectorType > &edge_out, const MGMatrixBase< VectorType > &edge_in)
Definition: mg.h:81
unsigned int get_maxlevel() const
void set_maxlevel(const unsigned int)
MGLevelObject< VectorType > t
Definition: multigrid.h:278
bool empty() const
SmartPointer< const MGCoarseGridBase< VectorType >, Multigrid< VectorType > > coarse
Definition: multigrid.h:294
unsigned int debug
Definition: multigrid.h:343
SmartPointer< const MGMatrixBase< VectorType >, Multigrid< VectorType > > edge_up
Definition: multigrid.h:338
void set_debug(const unsigned int)
void level_v_step(const unsigned int level)
SmartPointer< const MGSmootherBase< VectorType >, Multigrid< VectorType > > post_smooth
Definition: multigrid.h:309
IndexSet locally_owned_range_indices() const
unsigned int maxlevel
Definition: multigrid.h:260
#define Assert(cond, exc)
Definition: exceptions.h:313
The F-cycle.
Definition: multigrid.h:78
virtual MPI_Comm get_communicator() const
Definition: tria_base.cc:146
void Tvmult(OtherVectorType &dst, const OtherVectorType &src) const
SmartPointer< Multigrid< VectorType >, PreconditionMG< dim, VectorType, TRANSFER > > multigrid
Definition: multigrid.h:438
unsigned int get_minlevel() const
SmartPointer< const MGMatrixBase< VectorType > > edge_out
Definition: multigrid.h:316
void vmult_add(OtherVectorType &dst, const OtherVectorType &src) const
The W-cycle.
Definition: multigrid.h:76
SmartPointer< const MGTransferBase< VectorType >, Multigrid< VectorType > > transfer
Definition: multigrid.h:299
void set_minlevel(const unsigned int level, bool relative=false)
The V-cycle.
Definition: multigrid.h:74
void set_edge_flux_matrices(const MGMatrixBase< VectorType > &edge_down, const MGMatrixBase< VectorType > &edge_up)
SmartPointer< const DoFHandler< dim >, PreconditionMG< dim, VectorType, TRANSFER > > dof_handler
Definition: multigrid.h:433
void Tvmult_add(OtherVectorType &dst, const OtherVectorType &src) const
unsigned int minlevel
Definition: multigrid.h:255
MGLevelObject< VectorType > solution
Definition: multigrid.h:272
void set_cycle(Cycle)
Multigrid(const DoFHandler< dim > &mg_dof_handler, const MGMatrixBase< VectorType > &matrix, const MGCoarseGridBase< VectorType > &coarse, const MGTransferBase< VectorType > &transfer, const MGSmootherBase< VectorType > &pre_smooth, const MGSmootherBase< VectorType > &post_smooth, const unsigned int minlevel=0, const unsigned int maxlevel=numbers::invalid_unsigned_int, Cycle cycle=v_cycle) 1
void level_step(const unsigned int level, Cycle cycle)
virtual unsigned int n_global_levels() const
SmartPointer< const MGSmootherBase< VectorType >, Multigrid< VectorType > > pre_smooth
Definition: multigrid.h:304
static ::ExceptionBase & ExcNotImplemented()
const Triangulation< dim, spacedim > & get_triangulation() const
SmartPointer< const MGMatrixBase< VectorType >, Multigrid< VectorType > > edge_down
Definition: multigrid.h:331
MGLevelObject< VectorType > defect2
Definition: multigrid.h:283
MGLevelObject< VectorType > defect
Definition: multigrid.h:267
PreconditionMG(const DoFHandler< dim > &dof_handler, Multigrid< VectorType > &mg, const TRANSFER &transfer)
Cycle cycle_type
Definition: multigrid.h:250
static ::ExceptionBase & ExcInternalError()
Triangulation< dim, spacedim > & get_triangulation()
Definition: tria.cc:11855
void reinit(const unsigned int minlevel, const unsigned int maxlevel)