16#ifndef dealii_multigrid_h
17#define dealii_multigrid_h
41 "The name 'signals' is already defined. You are most likely using the QT library \
42and using the 'signals' keyword. You can either #include the Qt headers (or any conflicting headers) \
43*after* the deal.II headers or you can define the 'QT_NO_KEYWORDS' macro and use the 'Q_SIGNALS' macro."
85 boost::signals2::signal<void(
const bool before,
const unsigned int level)>
96 boost::signals2::signal<void(
const bool before,
const unsigned int level)>
104 boost::signals2::signal<void(
const bool before,
const unsigned int level)>
115 boost::signals2::signal<void(
const bool before,
const unsigned int level)>
123 boost::signals2::signal<void(
const bool before,
const unsigned int level)>
131 boost::signals2::signal<void(
const bool before,
const unsigned int level)>
138 boost::signals2::signal<void(
const bool before,
const unsigned int level)>
160template <
typename VectorType>
311 boost::signals2::connection
313 const std::function<
void(
const bool,
const unsigned int)> &slot);
318 boost::signals2::connection
320 const std::function<
void(
const bool,
const unsigned int)> &slot);
325 boost::signals2::connection
327 const std::function<
void(
const bool,
const unsigned int)> &slot);
332 boost::signals2::connection
334 const std::function<
void(
const bool,
const unsigned int)> &slot);
339 boost::signals2::connection
341 const std::function<
void(
const bool,
const unsigned int)> &slot);
346 boost::signals2::connection
348 const std::function<
void(
const bool,
const unsigned int)> &slot);
353 boost::signals2::connection
355 const std::function<
void(
const bool,
const unsigned int)> &slot);
479 template <
int dim,
class OtherVectorType,
class TRANSFER>
498template <
int dim,
typename VectorType,
class TRANSFER>
530 template <
class OtherVectorType>
532 vmult(OtherVectorType &dst,
const OtherVectorType &src)
const;
538 template <
class OtherVectorType>
540 vmult_add(OtherVectorType &dst,
const OtherVectorType &src)
const;
547 template <
class OtherVectorType>
549 Tvmult(OtherVectorType &dst,
const OtherVectorType &src)
const;
556 template <
class OtherVectorType>
558 Tvmult_add(OtherVectorType &dst,
const OtherVectorType &src)
const;
587 boost::signals2::connection
593 boost::signals2::connection
612 std::vector<SmartPointer<const DoFHandler<dim>,
652template <
typename VectorType>
658 const unsigned int min_level,
659 const unsigned int max_level,
662 , matrix(&matrix, typeid(*this).name())
663 , coarse(&coarse, typeid(*this).name())
664 , transfer(&transfer, typeid(*this).name())
665 , pre_smooth(&pre_smooth, typeid(*this).name())
666 , post_smooth(&post_smooth, typeid(*this).name())
667 , edge_out(nullptr, typeid(*this).name())
668 , edge_in(nullptr, typeid(*this).name())
669 , edge_down(nullptr, typeid(*this).name())
670 , edge_up(nullptr, typeid(*this).name())
673 maxlevel = matrix.get_maxlevel();
675 maxlevel = max_level;
676 reinit(min_level, maxlevel);
681template <
typename VectorType>
690template <
typename VectorType>
703 namespace PreconditionMGImplementation
708 typename OtherVectorType>
709 typename std::enable_if<TRANSFER::supports_dof_handler_vector>::type
711 const std::vector<const ::DoFHandler<dim> *> &dof_handler_vector,
713 const TRANSFER & transfer,
714 OtherVectorType & dst,
715 const OtherVectorType & src,
716 const bool uses_dof_handler_vector,
717 const typename ::mg::Signals &signals,
720 signals.transfer_to_mg(
true);
721 if (uses_dof_handler_vector)
722 transfer.copy_to_mg(dof_handler_vector, multigrid.
defect, src);
724 transfer.copy_to_mg(*dof_handler_vector[0], multigrid.
defect, src);
725 signals.transfer_to_mg(
false);
729 signals.transfer_to_global(
true);
730 if (uses_dof_handler_vector)
731 transfer.copy_from_mg(dof_handler_vector, dst, multigrid.
solution);
733 transfer.copy_from_mg(*dof_handler_vector[0], dst, multigrid.
solution);
734 signals.transfer_to_global(
false);
740 typename OtherVectorType>
743 const std::vector<const ::DoFHandler<dim> *> &dof_handler_vector,
745 const TRANSFER & transfer,
746 OtherVectorType & dst,
747 const OtherVectorType & src,
748 const bool uses_dof_handler_vector,
749 const typename ::mg::Signals &signals,
752 (void)uses_dof_handler_vector;
755 signals.transfer_to_mg(
true);
756 transfer.copy_to_mg(*dof_handler_vector[0], multigrid.
defect, src);
757 signals.transfer_to_mg(
false);
761 signals.transfer_to_global(
true);
762 transfer.copy_from_mg(*dof_handler_vector[0], dst, multigrid.
solution);
763 signals.transfer_to_global(
false);
769 typename OtherVectorType>
770 typename std::enable_if<TRANSFER::supports_dof_handler_vector>::type
772 const std::vector<const ::DoFHandler<dim> *> &dof_handler_vector,
774 const TRANSFER & transfer,
775 OtherVectorType & dst,
776 const OtherVectorType & src,
777 const bool uses_dof_handler_vector,
778 const typename ::mg::Signals &signals,
781 signals.transfer_to_mg(
true);
782 if (uses_dof_handler_vector)
783 transfer.copy_to_mg(dof_handler_vector, multigrid.
defect, src);
785 transfer.copy_to_mg(*dof_handler_vector[0], multigrid.
defect, src);
786 signals.transfer_to_mg(
false);
790 signals.transfer_to_global(
true);
791 if (uses_dof_handler_vector)
792 transfer.copy_from_mg_add(dof_handler_vector, dst, multigrid.
solution);
794 transfer.copy_from_mg_add(*dof_handler_vector[0],
797 signals.transfer_to_global(
false);
803 typename OtherVectorType>
806 const std::vector<const ::DoFHandler<dim> *> &dof_handler_vector,
808 const TRANSFER & transfer,
809 OtherVectorType & dst,
810 const OtherVectorType & src,
811 const bool uses_dof_handler_vector,
812 const typename ::mg::Signals &signals,
815 (void)uses_dof_handler_vector;
818 signals.transfer_to_mg(
true);
819 transfer.copy_to_mg(*dof_handler_vector[0], multigrid.
defect, src);
820 signals.transfer_to_mg(
false);
824 signals.transfer_to_global(
true);
825 transfer.copy_from_mg_add(*dof_handler_vector[0],
828 signals.transfer_to_global(
false);
833template <
int dim,
typename VectorType,
class TRANSFER>
837 const TRANSFER & transfer)
838 : dof_handler_vector(1, &dof_handler)
839 , dof_handler_vector_raw(1, &dof_handler)
841 , transfer(&transfer)
842 , uses_dof_handler_vector(false)
845template <
int dim,
typename VectorType,
class TRANSFER>
849 const TRANSFER & transfer)
850 : dof_handler_vector(dof_handler.size())
851 , dof_handler_vector_raw(dof_handler.size())
853 , transfer(&transfer)
854 , uses_dof_handler_vector(true)
856 for (
unsigned int i = 0; i < dof_handler.size(); ++i)
863template <
int dim,
typename VectorType,
class TRANSFER>
870template <
int dim,
typename VectorType,
class TRANSFER>
871template <
class OtherVectorType>
874 OtherVectorType & dst,
875 const OtherVectorType &src)
const
877 internal::PreconditionMGImplementation::vmult(dof_handler_vector_raw,
882 uses_dof_handler_vector,
888template <
int dim,
typename VectorType,
class TRANSFER>
891 const unsigned int block)
const
894 return dof_handler_vector[block]->locally_owned_dofs();
898template <
int dim,
typename VectorType,
class TRANSFER>
901 const unsigned int block)
const
904 return dof_handler_vector[block]->locally_owned_dofs();
909template <
int dim,
typename VectorType,
class TRANSFER>
924template <
int dim,
typename VectorType,
class TRANSFER>
925boost::signals2::connection
927 const std::function<
void(
bool)> &slot)
929 return this->signals.transfer_to_mg.connect(slot);
934template <
int dim,
typename VectorType,
class TRANSFER>
935boost::signals2::connection
937 const std::function<
void(
bool)> &slot)
939 return this->signals.transfer_to_global.connect(slot);
944template <
int dim,
typename VectorType,
class TRANSFER>
945template <
class OtherVectorType>
948 OtherVectorType & dst,
949 const OtherVectorType &src)
const
951 internal::PreconditionMGImplementation::vmult_add(dof_handler_vector_raw,
956 uses_dof_handler_vector,
962template <
int dim,
typename VectorType,
class TRANSFER>
963template <
class OtherVectorType>
966 const OtherVectorType &)
const
972template <
int dim,
typename VectorType,
class TRANSFER>
973template <
class OtherVectorType>
977 const OtherVectorType &)
const
983template <
int dim,
typename VectorType,
class TRANSFER>
987 return *this->multigrid;
991template <
int dim,
typename VectorType,
class TRANSFER>
995 return *this->multigrid;
MGLevelObject< VectorType > defect2
void set_edge_flux_matrices(const MGMatrixBase< VectorType > &edge_down, const MGMatrixBase< VectorType > &edge_up)
SmartPointer< const MGTransferBase< VectorType >, Multigrid< VectorType > > transfer
SmartPointer< const MGMatrixBase< VectorType >, Multigrid< VectorType > > edge_up
SmartPointer< const MGMatrixBase< VectorType > > edge_in
SmartPointer< const MGMatrixBase< VectorType > > edge_out
MGLevelObject< VectorType > solution
boost::signals2::connection connect_edge_prolongation(const std::function< void(const bool, const unsigned int)> &slot)
SmartPointer< const MGMatrixBase< VectorType >, Multigrid< VectorType > > matrix
void set_maxlevel(const unsigned int)
unsigned int get_minlevel() const
void set_edge_matrices(const MGMatrixBase< VectorType > &edge_out, const MGMatrixBase< VectorType > &edge_in)
boost::signals2::connection connect_residual_step(const std::function< void(const bool, const unsigned int)> &slot)
void level_step(const unsigned int level, Cycle cycle)
unsigned int get_maxlevel() const
const VectorType const_vector_type
SmartPointer< const MGSmootherBase< VectorType >, Multigrid< VectorType > > pre_smooth
SmartPointer< const MGSmootherBase< VectorType >, Multigrid< VectorType > > post_smooth
boost::signals2::connection connect_post_smoother_step(const std::function< void(const bool, const unsigned int)> &slot)
boost::signals2::connection connect_coarse_solve(const std::function< void(const bool, const unsigned int)> &slot)
SmartPointer< const MGCoarseGridBase< VectorType >, Multigrid< VectorType > > coarse
boost::signals2::connection connect_prolongation(const std::function< void(const bool, const unsigned int)> &slot)
SmartPointer< const MGMatrixBase< VectorType >, Multigrid< VectorType > > edge_down
void set_edge_in_matrix(const MGMatrixBase< VectorType > &edge_in)
MGLevelObject< VectorType > t
void set_minlevel(const unsigned int level, bool relative=false)
void level_v_step(const unsigned int level)
Multigrid(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)
MGLevelObject< VectorType > defect
boost::signals2::connection connect_restriction(const std::function< void(const bool, const unsigned int)> &slot)
void reinit(const unsigned int minlevel, const unsigned int maxlevel)
boost::signals2::connection connect_pre_smoother_step(const std::function< void(const bool, const unsigned int)> &slot)
SmartPointer< Multigrid< VectorType >, PreconditionMG< dim, VectorType, TRANSFER > > multigrid
Multigrid< VectorType > & get_multigrid()
void vmult_add(OtherVectorType &dst, const OtherVectorType &src) const
void vmult(OtherVectorType &dst, const OtherVectorType &src) const
IndexSet locally_owned_range_indices(const unsigned int block=0) const
SmartPointer< const TRANSFER, PreconditionMG< dim, VectorType, TRANSFER > > transfer
PreconditionMG(const std::vector< const DoFHandler< dim > * > &dof_handler, Multigrid< VectorType > &mg, const TRANSFER &transfer)
const Multigrid< VectorType > & get_multigrid() const
std::vector< SmartPointer< const DoFHandler< dim >, PreconditionMG< dim, VectorType, TRANSFER > > > dof_handler_vector
void Tvmult_add(OtherVectorType &dst, const OtherVectorType &src) const
void Tvmult(OtherVectorType &dst, const OtherVectorType &src) const
boost::signals2::connection connect_transfer_to_mg(const std::function< void(bool)> &slot)
PreconditionMG(const DoFHandler< dim > &dof_handler, Multigrid< VectorType > &mg, const TRANSFER &transfer)
IndexSet locally_owned_domain_indices(const unsigned int block=0) const
boost::signals2::connection connect_transfer_to_global(const std::function< void(bool)> &slot)
const bool uses_dof_handler_vector
MPI_Comm get_mpi_communicator() const
std::vector< const DoFHandler< dim > * > dof_handler_vector_raw
Triangulation< dim, spacedim > & get_triangulation()
virtual MPI_Comm get_communicator() const override
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static const unsigned int invalid_unsigned_int
boost::signals2::signal< void(const bool before, const unsigned int level)> prolongation
boost::signals2::signal< void(const bool before, const unsigned int level)> pre_smoother_step
boost::signals2::signal< void(const bool before, const unsigned int level)> coarse_solve
boost::signals2::signal< void(const bool before, const unsigned int level)> edge_prolongation
boost::signals2::signal< void(const bool before, const unsigned int level)> post_smoother_step
boost::signals2::signal< void(const bool before)> transfer_to_global
boost::signals2::signal< void(const bool before, const unsigned int level)> residual_step
boost::signals2::signal< void(const bool before, const unsigned int level)> restriction
boost::signals2::signal< void(const bool before)> transfer_to_mg
const ::Triangulation< dim, spacedim > & tria