deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20: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\}}\)
Loading...
Searching...
No Matches
trilinos_tpetra_precondition.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2024 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_trilinos_tpetra_precondition_h
14#define dealii_trilinos_tpetra_precondition_h
15
16
17#include <deal.II/base/config.h>
18
21
22#include <deal.II/lac/vector.h>
23
24#ifdef DEAL_II_TRILINOS_WITH_TPETRA
25
27
30
31# include <Teuchos_BLAS_types.hpp>
32# include <Teuchos_ConfigDefs.hpp>
33# include <Teuchos_ParameterList.hpp>
34# include <Teuchos_RCPDecl.hpp>
35# include <Tpetra_Operator.hpp>
36
37#endif // DEAL_II_TRILINOS_WITH_TPETRA
38
40
41#ifdef DEAL_II_TRILINOS_WITH_TPETRA
42namespace LinearAlgebra
43{
44 namespace TpetraWrappers
45 {
46
53 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
55 {
56 public:
62 {};
63
69 PreconditionBase() = default;
70
76 void
78
85 virtual void
87 const Vector<Number, MemorySpace> &src) const;
88
95 virtual void
97 const Vector<Number, MemorySpace> &src) const;
98
105 virtual void
107
111 virtual void
113
122
129 Teuchos::RCP<TpetraTypes::LinearOperator<Number, MemorySpace>>
131
145
155
168 std::string,
169 << "The sparse matrix the preconditioner is based on "
170 << "uses a map that is not compatible to the one in vector " << arg1
171 << ". Check preconditioner and matrix setup.");
172
178 "The chosen preconditioner does not support transposing the matrix.");
181 protected:
186 Teuchos::RCP<TpetraTypes::LinearOperator<Number, MemorySpace>>
188
199 Teuchos::ParameterList parameter_list;
200 };
201
202
203
204# ifdef DEAL_II_TRILINOS_WITH_IFPACK2
214 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
215 class PreconditionIdentity : public PreconditionBase<Number, MemorySpace>
216 {
217 public:
222
232 void
234 };
235
236
237
244 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
245 class PreconditionIfpackBase : public PreconditionBase<Number, MemorySpace>
246 {
247 public:
258
263 void
265
271 std::string,
272 << "You tried to select the preconditioner type <" << arg1 << ">\n"
273 << "but this preconditioner is not supported by Trilinos/Ifpack22\n"
274 << "due to one of the following reasons:\n"
275 << "* This preconditioner does not exist\n"
276 << "* This preconditioner has a specialized constructor not supported by the Ifpack2 Factory.\n"
277 << "* This preconditioner is not (yet) supported by Trilinos/Ifpack2\n"
278 << "* Trilinos/Ifpack2 was not configured for its use.");
279
280 protected:
286 };
287
288
289
303 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
305 : public PreconditionIfpackBase<Number, MemorySpace>
306 {
307 public:
325
335 void
336 set_parameter_list(Teuchos::ParameterList &parameter_list);
337 };
338
339
340
347 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
349 : public PreconditionIfpackBase<Number, MemorySpace>
350 {
351 public:
356 {
368 AdditionalData(const double omega = 1.,
369 const bool fix_diagonal = false,
370 const double min_diagonal = 0.,
371 const int n_sweeps = 1);
372
376 double omega;
377
387
395
400 };
405
412 void
414 const AdditionalData &additional_data = AdditionalData());
415 };
416
417
418
429 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
431 : public PreconditionIfpackBase<Number, MemorySpace>
432 {
433 public:
438 {
451 AdditionalData(const double omega = 1.,
452 const bool fix_diagonal = false,
453 const double min_diagonal = 0.,
454 const int n_sweeps = 1);
455
459 double omega;
460
470
478
483 };
484
489
496 void
498 const AdditionalData &additional_data = AdditionalData());
499 };
500
501
502
514 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
516 : public PreconditionIfpackBase<Number, MemorySpace>
517 {
518 public:
523 {
537 AdditionalData(const double omega = 1,
538 const double eta = 1.5,
539 const bool fix_diagonal = false,
540 const double min_diagonal = 0,
541 const int n_sweeps = 1);
542
546 double omega;
547
554 double eta;
555
565
573
578 };
579
584
591 void
593 const AdditionalData &additional_data = AdditionalData());
594 };
595
596
597
607 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
608 class PreconditionSOR : public PreconditionIfpackBase<Number, MemorySpace>
609 {
610 public:
615 {
628 AdditionalData(const double omega = 1.,
629 const int overlap = 0,
630 const bool fix_diagonal = false,
631 const double min_diagonal = 0.,
632 const int n_sweeps = 1);
633
637 double omega;
638
649
659
667
672 };
673
678
685 void
687 const AdditionalData &additional_data = AdditionalData());
688 };
689
690
691
698 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
699 class PreconditionSSOR : public PreconditionIfpackBase<Number, MemorySpace>
700 {
701 public:
706 {
719 AdditionalData(const double omega = 1.,
720 const int overlap = 0,
721 const bool fix_diagonal = false,
722 const double min_diagonal = 0.,
723 const int n_sweeps = 1);
724
728 double omega;
729
740
750
758
763 };
764
765
770
777 void
779 const AdditionalData &additional_data = AdditionalData());
780 };
781
782
783
790 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
792 : public PreconditionIfpackBase<Number, MemorySpace>
793 {
794 public:
799 {
810 AdditionalData(const int degree = 1,
811 const double max_eigenvalue = 10.,
812 const double min_eigenvalue = 1.,
813 const double eigenvalue_ratio = 30.,
814 const double min_diagonal = 1e-12,
815 const bool nonzero_starting = false);
824
825 /*
826 * @brief Upper bound for the maximum eigenvalue of the matrix.
827 *
828 * This needs to be set properly for the appropriate performance of this
829 * preconditioner.
830 */
832
833 /*
834 * @brief Lower bound for the minimum eigenvalue of the matrix.
835 */
837
842
850
863 };
864
869
876 void
878 const AdditionalData &additional_data = AdditionalData());
879 };
880
881
882
900 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
901 class PreconditionILU : public PreconditionIfpackBase<Number, MemorySpace>
902 {
903 public:
908 {
923 const double ilu_atol = 0.,
924 const double ilu_rtol = 1.,
925 const int overlap = 0);
926
934
938 double ilu_atol;
939
943 double ilu_rtol;
944
955 };
956
961
968 void
970 const AdditionalData &additional_data = AdditionalData());
971 };
972
973
974
982 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
983 class PreconditionILUT : public PreconditionIfpackBase<Number, MemorySpace>
984 {
985 public:
990 {
1005 AdditionalData(const double ilut_drop = 0.,
1006 const double ilut_fill = 0.,
1007 const double ilut_atol = 0.,
1008 const double ilut_rtol = 1.,
1009 const int overlap = 0);
1010
1018
1028
1033
1038
1049 };
1050
1051
1052
1057
1064 void
1066 const AdditionalData &additional_data = AdditionalData());
1067 };
1068
1069
1070
1084 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
1086 : public PreconditionIfpackBase<Number, MemorySpace>
1087 {
1088 public:
1093 {
1106 const double omega = 1.,
1107 const int block_overlap = 0,
1108 const int n_sweeps = 1);
1109
1117
1121 double omega;
1122
1127
1132 };
1133
1134
1139
1146 void
1148 const AdditionalData &additional_data = AdditionalData());
1149 };
1150
1151
1152
1162 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
1164 : public PreconditionIfpackBase<Number, MemorySpace>
1165 {
1166 public:
1171 {
1183 const double omega = 1,
1184 const int overlap = 0,
1185 const int n_sweeps = 1);
1186
1194
1198 double omega;
1199
1210
1215 };
1216
1218
1219 void
1221 const AdditionalData &additional_data = AdditionalData());
1222 };
1223
1224
1225
1235 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
1237 : public PreconditionIfpackBase<Number, MemorySpace>
1238 {
1239 public:
1244 {
1256 const double omega = 1,
1257 const int overlap = 1,
1258 const int n_sweeps = 1);
1259
1267
1271 double omega;
1272
1283
1288 };
1289
1291
1292 void
1294 const AdditionalData &additional_data = AdditionalData());
1295 };
1296# ifdef DEAL_II_TRILINOS_WITH_TPETRA_MUELU
1297
1316 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
1317 class PreconditionAMGMueLu : public PreconditionBase<Number, MemorySpace>
1318 {
1319 public:
1325 std::string,
1326 << "You tried to select the smoother type <" << arg1 << ">\n"
1327 << "but this is not supported by our interface\n"
1328 << "due to one of the following reasons:\n"
1329 << "* This smoother does not exist\n"
1330 << "* This smoother is not (yet) supported by our interface\n"
1331 << "* This smoother is not (yet) supported by MueLu.\n");
1334 std::string,
1335 << "You tried to select the coarse solver type <" << arg1 << ">\n"
1336 << "but this is not supported by our interface\n"
1337 << "due to one of the following reasons:\n"
1338 << "* This coarse solver does not exist\n"
1339 << "* This coarse solver is not (yet) supported by our interface\n"
1340 << "* This coarse solver is not (yet) supported by MueLu.\n");
1341
1346 {
1384 AdditionalData(const bool elliptic = true,
1385 const bool symmetric = true,
1386 const bool w_cycle = false,
1387 const double aggregation_threshold = 1e-4,
1388 const std::vector<std::vector<bool>> &constant_modes =
1389 std::vector<std::vector<bool>>(0),
1390 const int smoother_sweeps = 2,
1391 const int smoother_overlap = 0,
1392 const bool output_details = false,
1393 const std::string &smoother_type = "Chebyshev",
1394 const std::string &coarse_type = "KLU2");
1395
1404
1412
1419
1431
1443 std::vector<std::vector<bool>> constant_modes;
1444
1453
1458
1463
1479 std::string smoother_type;
1480
1487 std::string coarse_type;
1488 };
1489
1491
1503 void
1505 const Teuchos::ParameterList &parameters);
1506
1517 void
1519 const AdditionalData &additional_data = AdditionalData());
1520 };
1521# endif
1522# endif // DEAL_II_TRILINOS_WITH_IFPACK2
1523
1524# ifdef DEAL_II_TRILINOS_WITH_SHYLU_DDFROSCH
1538 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
1539 class PreconditionFROSch : public PreconditionBase<Number, MemorySpace>
1540 {
1541 public:
1545 enum PreconditionerType
1546 {
1550 OneLevel,
1554 TwoLevel
1555 };
1556
1561 enum SolverName
1562 {
1567 KLU,
1572 UMFPACK,
1577 MUMPS,
1582 SuperLU_dist
1583 };
1584
1589 enum CombineMethod
1590 {
1595 Restricted,
1596 /*
1597 * Take the average on the overlap.
1598 */
1599 Averaging,
1600 /*
1601 * Add up the values on the overlap.
1602 */
1603 Full
1604 };
1605
1610 enum CoarseType
1611 {
1615 IPOUHarmonicCoarseOperator,
1619 GDSWCoarseOperator,
1623 RGDSWCoarseOperator
1624 };
1625
1629 struct AdditionalData
1630 {
1631 AdditionalData(
1632 const unsigned int overlap = 1,
1633 const unsigned int dimension = 2,
1634 const enum CombineMethod combine_values_in_overlap = Restricted,
1635 const enum SolverName subdomain_solver = KLU,
1636 const enum CoarseType coarse_operator_type =
1637 IPOUHarmonicCoarseOperator,
1638 const enum SolverName extension_solver = KLU,
1639 const enum SolverName coarse_solver = KLU);
1640
1644 unsigned int overlap;
1645
1649 unsigned int dimension;
1650
1673 enum CombineMethod combine_values_in_overlap;
1674
1688 enum SolverName subdomain_solver;
1689
1701 enum CoarseType coarse_operator_type;
1702
1708 enum SolverName extension_solver;
1709
1715 enum SolverName coarse_solver;
1716 };
1717
1729 PreconditionFROSch(
1730 const enum PreconditionerType precondition_type = OneLevel);
1731
1738 void
1739 set_parameter_list(const Teuchos::ParameterList &parameter_list);
1740
1747 void
1748 initialize(const SparseMatrix<Number, MemorySpace> &A,
1749 const AdditionalData &additional_data = AdditionalData());
1750
1762 template <int dim, int spacedim = dim>
1763 void
1764 initialize(const SparseMatrix<Number, MemorySpace> &A,
1765 const DoFHandler<dim, spacedim> &dof_handler,
1766 const AdditionalData &additional_data = AdditionalData());
1767
1768 private:
1777 const enum PreconditionerType precondition_type;
1778
1784 bool user_provided_parameter_list;
1785 };
1786# endif // DEAL_II_TRILINOS_WITH_SHYLU_DDFROSCH
1787
1788 } // namespace TpetraWrappers
1789} // namespace LinearAlgebra
1790
1791#endif // DEAL_II_TRILINOS_WITH_TPETRA
1792
1794
1795#endif
void initialize(const SparseMatrix< Number, MemorySpace > &A, const Teuchos::ParameterList &parameters)
Full control interface for constructing a MueLu preconditioner.
void initialize(const SparseMatrix< Number, MemorySpace > &A, const AdditionalData &additional_data=AdditionalData())
Simplified interface for constructing a MueLu preconditioner.
virtual void Tvmult(Vector< Number, MemorySpace > &dst, const Vector< Number, MemorySpace > &src) const
Apply the transpose preconditioner.
Teuchos::ParameterList parameter_list
The list of preconditioner parameters.
void clear()
Destructor. Destroys the preconditioner, leaving an object like just after having called the construc...
virtual void vmult(::Vector< Number > &dst, ::Vector< Number > &src) const
Apply the preconditioner.
Teuchos::RCP< TpetraTypes::LinearOperator< Number, MemorySpace > > preconditioner
Teuchos::RCP< TpetraTypes::LinearOperator< Number, MemorySpace > > trilinos_rcp() const
Access to underlying Trilinos data.
virtual void Tvmult(::Vector< Number > &dst, ::Vector< Number > &src) const
Apply the transpose preconditioner.
PreconditionBase()=default
Constructor. Does not do anything. The initialize function of the derived classes will have to create...
const TpetraTypes::LinearOperator< Number, MemorySpace > & trilinos_operator() const
Access to underlying Trilinos data.
virtual void vmult(Vector< Number, MemorySpace > &dst, const Vector< Number, MemorySpace > &src) const
Apply the preconditioner.
void initialize(const SparseMatrix< Number, MemorySpace > &A, const AdditionalData &additional_data=AdditionalData())
Compute the preconditioner based on the given matrix and parameters.
The class for the Block SOR preconditioner within Ifpack2.
void initialize(const SparseMatrix< Number, MemorySpace > &A, const AdditionalData &additional_data=AdditionalData())
The class for the Block SSOR preconditioner within Ifpack2.
void initialize(const SparseMatrix< Number, MemorySpace > &A, const AdditionalData &additional_data=AdditionalData())
void initialize(const SparseMatrix< Number, MemorySpace > &A, const AdditionalData &additional_data=AdditionalData())
Compute the preconditioner based on the given matrix and parameters.
void initialize(const SparseMatrix< Number, MemorySpace > &A, const AdditionalData &additional_data=AdditionalData())
Compute the preconditioner based on the given matrix and parameters.
void initialize(const SparseMatrix< Number, MemorySpace > &A, const AdditionalData &additional_data=AdditionalData())
Compute the preconditioner based on the given matrix and parameters.
Wrapper class for the IdentitySolver preconditioner of Ifpack2.
void initialize(const SparseMatrix< Number, MemorySpace > &A)
Initializes the preconditioner for the matrix A.
PreconditionIdentity()=default
Construct identity preconditioner.
The base class for all Ifpack2 preconditioners which are handled through its Factory.
PreconditionIfpackBase(const std::string &preconditioner_type)
Constructor.
void initialize(const SparseMatrix< Number, MemorySpace > &A)
Wrapper to create custom Ifpack2 preconditioners.
void set_parameter_list(Teuchos::ParameterList &parameter_list)
Set the parameter list for the preconditioner.
PreconditionIfpack(const std::string &preconditioner_type)
Construct a new custom Ifpack2 preconditioner.
The classical Jacobi preconditioner within Ifpack2.
void initialize(const SparseMatrix< Number, MemorySpace > &A, const AdditionalData &additional_data=AdditionalData())
Compute the preconditioner based on the given matrix and parameters.
void initialize(const SparseMatrix< Number, MemorySpace > &A, const AdditionalData &additional_data=AdditionalData())
Compute the preconditioner based on the given matrix and parameters.
void initialize(const SparseMatrix< Number, MemorySpace > &A, const AdditionalData &additional_data=AdditionalData())
Compute the preconditioner based on the given matrix and parameters.
The class for the SOR preconditioner within Ifpack2.
void initialize(const SparseMatrix< Number, MemorySpace > &A, const AdditionalData &additional_data=AdditionalData())
Compute the preconditioner based on the given matrix and parameters.
void initialize(const SparseMatrix< Number, MemorySpace > &A, const AdditionalData &additional_data=AdditionalData())
Compute the preconditioner based on the given matrix and parameters.
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
static ::ExceptionBase & ExcTrilinosMueLuSmootherUnsupported(std::string arg1)
static ::ExceptionBase & ExcTrilinosIpack2PreconditionerUnsupported(std::string arg1)
static ::ExceptionBase & ExcNonMatchingMaps(std::string arg1)
#define DeclExceptionMsg(Exception, defaulttext)
#define DeclException1(Exception1, type1, outsequence)
static ::ExceptionBase & ExcTransposeNotSupported()
static ::ExceptionBase & ExcTrilinosMueLuCoarseSolverUnsupported(std::string arg1)
Tpetra::Operator< Number, LO, GO, NodeType< MemorySpace > > LinearOperator
The set of additional parameters to tune the preconditioner.
AdditionalData(const bool elliptic=true, const bool symmetric=true, const bool w_cycle=false, const double aggregation_threshold=1e-4, const std::vector< std::vector< bool > > &constant_modes=std::vector< std::vector< bool > >(0), const int smoother_sweeps=2, const int smoother_overlap=0, const bool output_details=false, const std::string &smoother_type="Chebyshev", const std::string &coarse_type="KLU2")
Constructor.
std::string smoother_type
Determines which smoother to use for the AMG cycle The following possibilities are implemented in thi...
std::string coarse_type
Type of smoother to use on the finer levels.
int smoother_sweeps
Number of times pre- and post-smoothing are applied.
int smoother_overlap
Determine the overlap in the smoother when run in parallel.
bool output_details
Print internal information details of MueLu to screen.
Standardized data struct to pipe additional flags to the preconditioner.
The set of additional parameters to tune the preconditioner.
int n_sweeps
Set how often the preconditioner should be applied during vmult() or Tvmult().
AdditionalData(const int n_local_parts=1, const double omega=1., const int block_overlap=0, const int n_sweeps=1)
Constructor.
The set of additional parameters to tune the preconditioner.
int n_sweeps
Set how often the preconditioner should be applied during vmult() or Tvmult().
AdditionalData(const int n_local_parts=1, const double omega=1, const int overlap=0, const int n_sweeps=1)
Constructor.
The set of additional parameters to tune the preconditioner.
int n_sweeps
Set how often the preconditioner should be applied during vmult() or Tvmult().
AdditionalData(const int n_local_parts=1, const double omega=1, const int overlap=1, const int n_sweeps=1)
Constructor.
The set of additional parameters to tune the preconditioner.
double eigenvalue_ratio
Estimated ratio between maximum and minimum eigenvalue.
AdditionalData(const int degree=1, const double max_eigenvalue=10., const double min_eigenvalue=1., const double eigenvalue_ratio=30., const double min_diagonal=1e-12, const bool nonzero_starting=false)
Constructor.
bool nonzero_starting
Do not zero starting entries of solution vector.
The set of additional parameters to tune the preconditioner.
AdditionalData(const double ilut_drop=0., const double ilut_fill=0., const double ilut_atol=0., const double ilut_rtol=1., const int overlap=0)
Constructor.
double ilut_rtol
Factor to scale all diagonal entries by before factorization.
double ilut_atol
Constant to be added to each diagonal entry before factorization.
The set of additional parameters to tune the preconditioner.
double ilu_atol
Constant to be added to each diagonal entry before factorization.
AdditionalData(const int ilu_fill=0, const double ilu_atol=0., const double ilu_rtol=1., const int overlap=0)
Constructor.
double ilu_rtol
Factor to scale all diagonal entries by before factorization.
The set of additional parameters to tune the preconditioner.
int n_sweeps
Set how often the preconditioner should be applied during vmult() or Tvmult().
bool fix_diagonal
Whether or not to enlarge entries below a threshold.
AdditionalData(const double omega=1., const bool fix_diagonal=false, const double min_diagonal=0., const int n_sweeps=1)
Constructor.
The set of additional parameters to tune the preconditioner.
bool fix_diagonal
Whether or not to enlarge entries below a threshold.
int n_sweeps
Set how often the preconditioner should be applied during vmult() or Tvmult().
AdditionalData(const double omega=1, const double eta=1.5, const bool fix_diagonal=false, const double min_diagonal=0, const int n_sweeps=1)
Constructor.
The set of additional parameters to tune the preconditioner.
AdditionalData(const double omega=1., const bool fix_diagonal=false, const double min_diagonal=0., const int n_sweeps=1)
Constructor.
bool fix_diagonal
Whether or not to enlarge entries below a threshold.
int n_sweeps
Set how often the preconditioner should be applied during vmult() or Tvmult().
The set of additional parameters to tune the preconditioner.
bool fix_diagonal
Whether or not to enlarge entries below a threshold.
AdditionalData(const double omega=1., const int overlap=0, const bool fix_diagonal=false, const double min_diagonal=0., const int n_sweeps=1)
Constructor.
int n_sweeps
Set how often the preconditioner should be applied during vmult() or Tvmult().
double min_diagonal
Threshold below which entries will be fixed.
The set of additional parameters to tune the preconditioner.
bool fix_diagonal
Whether or not to enlarge entries below a threshold.
int n_sweeps
Set how often the preconditioner should be applied during vmult() or Tvmult().
AdditionalData(const double omega=1., const int overlap=0, const bool fix_diagonal=false, const double min_diagonal=0., const int n_sweeps=1)
Constructor.
double min_diagonal
Threshold below which entries will be fixed.