13#ifndef dealii_multigrid_h
14#define dealii_multigrid_h
32#include <boost/signals2.hpp>
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."
87 boost::signals2::signal<void(
const bool before,
const unsigned int level)>
98 boost::signals2::signal<void(
const bool before,
const unsigned int level)>
106 boost::signals2::signal<void(
const bool before,
const unsigned int level)>
117 boost::signals2::signal<void(
const bool before,
const unsigned int level)>
125 boost::signals2::signal<void(
const bool before,
const unsigned int level)>
133 boost::signals2::signal<void(
const bool before,
const unsigned int level)>
140 boost::signals2::signal<void(
const bool before,
const unsigned int level)>
162template <
typename VectorType>
313 boost::signals2::connection
315 const std::function<
void(
const bool,
const unsigned int)> &slot);
320 boost::signals2::connection
322 const std::function<
void(
const bool,
const unsigned int)> &slot);
327 boost::signals2::connection
329 const std::function<
void(
const bool,
const unsigned int)> &slot);
334 boost::signals2::connection
336 const std::function<
void(
const bool,
const unsigned int)> &slot);
341 boost::signals2::connection
343 const std::function<
void(
const bool,
const unsigned int)> &slot);
348 boost::signals2::connection
350 const std::function<
void(
const bool,
const unsigned int)> &slot);
355 boost::signals2::connection
357 const std::function<
void(
const bool,
const unsigned int)> &slot);
384 const unsigned int iteration);
485 template <
int dim,
typename OtherVectorType,
typename TransferType>
504template <
int dim,
typename VectorType,
typename TransferType>
536 template <
typename OtherVectorType>
538 vmult(OtherVectorType &dst,
const OtherVectorType &src)
const;
544 template <
typename OtherVectorType>
546 vmult_add(OtherVectorType &dst,
const OtherVectorType &src)
const;
553 template <
typename OtherVectorType>
555 Tvmult(OtherVectorType &dst,
const OtherVectorType &src)
const;
562 template <
typename OtherVectorType>
564 Tvmult_add(OtherVectorType &dst,
const OtherVectorType &src)
const;
593 boost::signals2::connection
599 boost::signals2::connection
618 std::vector<ObserverPointer<const DoFHandler<dim>,
660template <
typename VectorType>
666 const unsigned int min_level,
667 const unsigned int max_level,
670 , matrix(&matrix, typeid(*this).name())
671 , coarse(&coarse, typeid(*this).name())
672 , transfer(&transfer, typeid(*this).name())
673 , pre_smooth(&pre_smooth, typeid(*this).name())
674 , post_smooth(&post_smooth, typeid(*this).name())
675 , edge_out(nullptr, typeid(*this).name())
676 , edge_in(nullptr, typeid(*this).name())
677 , edge_down(nullptr, typeid(*this).name())
678 , edge_up(nullptr, typeid(*this).name())
681 maxlevel = matrix.get_maxlevel();
683 maxlevel = max_level;
684 reinit(min_level, maxlevel);
689template <
typename VectorType>
698template <
typename VectorType>
711 namespace PreconditionMGImplementation
713 template <
typename DoFHandlerType,
715 typename TransferType,
716 typename OtherVectorType>
717 using get_dof_handler_vector_support =
718 decltype(std::declval<TransferType>().copy_from_mg(
719 std::vector<const DoFHandlerType *>{},
720 std::declval<OtherVectorType &>(),
721 std::declval<MGLevelObject<VectorType>>()));
723 template <
typename DoFHandlerType,
725 typename TransferType,
726 typename OtherVectorType>
727 constexpr bool supports_dof_handler_vector =
736 typename TransferType,
737 typename OtherVectorType>
741 const TransferType &transfer,
742 OtherVectorType &dst,
743 const OtherVectorType &src,
744 const bool uses_dof_handler_vector,
745 const typename ::mg::Signals &signals)
747 if constexpr (supports_dof_handler_vector<DoFHandler<dim>,
752 signals.transfer_to_mg(
true);
753 if (uses_dof_handler_vector)
754 transfer.copy_to_mg(dof_handler_vector, multigrid.
defect, src);
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 if (uses_dof_handler_vector)
763 transfer.copy_from_mg(dof_handler_vector, dst, multigrid.
solution);
765 transfer.copy_from_mg(*dof_handler_vector[0],
768 signals.transfer_to_global(
false);
772 (void)uses_dof_handler_vector;
775 signals.transfer_to_mg(
true);
776 transfer.copy_to_mg(*dof_handler_vector[0], multigrid.
defect, src);
777 signals.transfer_to_mg(
false);
781 signals.transfer_to_global(
true);
782 transfer.copy_from_mg(*dof_handler_vector[0],
785 signals.transfer_to_global(
false);
791 typename TransferType,
792 typename OtherVectorType>
794 vmult_add(
const std::vector<
const DoFHandler<dim> *> &dof_handler_vector,
796 const TransferType &transfer,
797 OtherVectorType &dst,
798 const OtherVectorType &src,
799 const bool uses_dof_handler_vector,
800 const typename ::mg::Signals &signals)
802 if constexpr (supports_dof_handler_vector<DoFHandler<dim>,
807 signals.transfer_to_mg(
true);
808 if (uses_dof_handler_vector)
809 transfer.copy_to_mg(dof_handler_vector, multigrid.
defect, src);
811 transfer.copy_to_mg(*dof_handler_vector[0], multigrid.
defect, src);
812 signals.transfer_to_mg(
false);
816 signals.transfer_to_global(
true);
817 if (uses_dof_handler_vector)
818 transfer.copy_from_mg_add(dof_handler_vector,
822 transfer.copy_from_mg_add(*dof_handler_vector[0],
825 signals.transfer_to_global(
false);
829 (void)uses_dof_handler_vector;
832 signals.transfer_to_mg(
true);
833 transfer.copy_to_mg(*dof_handler_vector[0], multigrid.
defect, src);
834 signals.transfer_to_mg(
false);
838 signals.transfer_to_global(
true);
839 transfer.copy_from_mg_add(*dof_handler_vector[0],
842 signals.transfer_to_global(
false);
848template <
int dim,
typename VectorType,
typename TransferType>
852 const TransferType &transfer)
853 : dof_handler_vector(1, &dof_handler)
854 , dof_handler_vector_raw(1, &dof_handler)
856 , transfer(&transfer)
857 , uses_dof_handler_vector(false)
860template <
int dim,
typename VectorType,
typename TransferType>
864 const TransferType &transfer)
865 : dof_handler_vector(dof_handler.
size())
866 , dof_handler_vector_raw(dof_handler.
size())
868 , transfer(&transfer)
869 , uses_dof_handler_vector(true)
871 for (
unsigned int i = 0; i < dof_handler.size(); ++i)
878template <
int dim,
typename VectorType,
typename TransferType>
885template <
int dim,
typename VectorType,
typename TransferType>
886template <
typename OtherVectorType>
889 OtherVectorType &dst,
890 const OtherVectorType &src)
const
892 internal::PreconditionMGImplementation::vmult(dof_handler_vector_raw,
897 uses_dof_handler_vector,
902template <
int dim,
typename VectorType,
typename TransferType>
905 const unsigned int block)
const
908 return dof_handler_vector[block]->locally_owned_dofs();
912template <
int dim,
typename VectorType,
typename TransferType>
915 const unsigned int block)
const
918 return dof_handler_vector[block]->locally_owned_dofs();
923template <
int dim,
typename VectorType,
typename TransferType>
938template <
int dim,
typename VectorType,
typename TransferType>
939boost::signals2::connection
941 const std::function<
void(
bool)> &slot)
943 return this->signals.transfer_to_mg.connect(slot);
948template <
int dim,
typename VectorType,
typename TransferType>
949boost::signals2::connection
951 const std::function<
void(
bool)> &slot)
953 return this->signals.transfer_to_global.connect(slot);
958template <
int dim,
typename VectorType,
typename TransferType>
959template <
typename OtherVectorType>
962 OtherVectorType &dst,
963 const OtherVectorType &src)
const
965 internal::PreconditionMGImplementation::vmult_add(dof_handler_vector_raw,
970 uses_dof_handler_vector,
975template <
int dim,
typename VectorType,
typename TransferType>
976template <
typename OtherVectorType>
980 const OtherVectorType &)
const
986template <
int dim,
typename VectorType,
typename TransferType>
987template <
typename OtherVectorType>
991 const OtherVectorType &)
const
997template <
int dim,
typename VectorType,
typename TransferType>
1001 return *this->multigrid;
1005template <
int dim,
typename VectorType,
typename TransferType>
1009 return *this->multigrid;
ObserverPointer< const MGMatrixBase< VectorType > > edge_out
MGLevelObject< VectorType > defect2
void set_edge_flux_matrices(const MGMatrixBase< VectorType > &edge_down, const MGMatrixBase< VectorType > &edge_up)
MGLevelObject< VectorType > solution
ObserverPointer< const MGSmootherBase< VectorType >, Multigrid< VectorType > > post_smooth
boost::signals2::connection connect_edge_prolongation(const std::function< void(const bool, const unsigned int)> &slot)
void level_step(const unsigned int level, const Cycle cycle, const unsigned int iteration)
ObserverPointer< const MGMatrixBase< VectorType > > edge_in
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)
unsigned int get_maxlevel() const
ObserverPointer< const MGCoarseGridBase< VectorType >, Multigrid< VectorType > > coarse
ObserverPointer< const MGSmootherBase< VectorType >, Multigrid< VectorType > > pre_smooth
const VectorType const_vector_type
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)
ObserverPointer< const MGMatrixBase< VectorType >, Multigrid< VectorType > > matrix
boost::signals2::connection connect_prolongation(const std::function< void(const bool, const unsigned int)> &slot)
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
ObserverPointer< const MGMatrixBase< VectorType >, Multigrid< VectorType > > edge_down
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)
ObserverPointer< const MGMatrixBase< VectorType >, Multigrid< VectorType > > edge_up
boost::signals2::connection connect_pre_smoother_step(const std::function< void(const bool, const unsigned int)> &slot)
ObserverPointer< const MGTransferBase< VectorType >, Multigrid< VectorType > > transfer
std::vector< const DoFHandler< dim > * > dof_handler_vector_raw
void Tvmult(OtherVectorType &dst, const OtherVectorType &src) const
IndexSet locally_owned_domain_indices(const unsigned int block=0) const
ObserverPointer< Multigrid< VectorType >, PreconditionMG< dim, VectorType, TransferType > > multigrid
const Multigrid< VectorType > & get_multigrid() const
boost::signals2::connection connect_transfer_to_global(const std::function< void(bool)> &slot)
boost::signals2::connection connect_transfer_to_mg(const std::function< void(bool)> &slot)
PreconditionMG(const DoFHandler< dim > &dof_handler, Multigrid< VectorType > &mg, const TransferType &transfer)
ObserverPointer< const TransferType, PreconditionMG< dim, VectorType, TransferType > > transfer
MPI_Comm get_mpi_communicator() const
const bool uses_dof_handler_vector
void vmult_add(OtherVectorType &dst, const OtherVectorType &src) const
IndexSet locally_owned_range_indices(const unsigned int block=0) const
std::vector< ObserverPointer< const DoFHandler< dim >, PreconditionMG< dim, VectorType, TransferType > > > dof_handler_vector
PreconditionMG(const std::vector< const DoFHandler< dim > * > &dof_handler, Multigrid< VectorType > &mg, const TransferType &transfer)
Multigrid< VectorType > & get_multigrid()
void Tvmult_add(OtherVectorType &dst, const OtherVectorType &src) const
void vmult(OtherVectorType &dst, const OtherVectorType &src) const
Triangulation< dim, spacedim > & get_triangulation()
virtual MPI_Comm get_mpi_communicator() const override
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NOT_IMPLEMENTED()
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
constexpr bool is_supported_operation
constexpr 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