deal.II version GIT relicensing-2652-g41e7496fd4 2025-02-17 19:10:00+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: LGPL-2.1-or-later
4// Copyright (C) 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_trilinos_tpetra_precondition_h
16#define dealii_trilinos_tpetra_precondition_h
17
18
19#include <deal.II/base/config.h>
20
23
24#include <deal.II/lac/vector.h>
25
26#ifdef DEAL_II_TRILINOS_WITH_TPETRA
27
29
32
33# include <Teuchos_BLAS_types.hpp>
34# include <Teuchos_ConfigDefs.hpp>
35# include <Teuchos_ParameterList.hpp>
36# include <Teuchos_RCPDecl.hpp>
37# include <Tpetra_Operator.hpp>
38
39
41
42namespace LinearAlgebra
43{
44 namespace TpetraWrappers
45 {
46
53 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
55 {
56 public:
63 {};
64
71 PreconditionBase() = default;
72
78 void
80
87 virtual void
89 const Vector<Number, MemorySpace> &src) const;
90
97 virtual void
99 const Vector<Number, MemorySpace> &src) const;
100
107 virtual void
109
113 virtual void
115
124
133
147
157
170 std::string,
171 << "The sparse matrix the preconditioner is based on "
172 << "uses a map that is not compatible to the one in vector " << arg1
173 << ". Check preconditioner and matrix setup.");
174
180 "The chosen preconditioner does not support transposing the matrix.");
183 protected:
190
202 Teuchos::ParameterList parameter_list;
203 };
204
205
206
207# ifdef DEAL_II_TRILINOS_WITH_IFPACK2
217 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
218 class PreconditionIdentity : public PreconditionBase<Number, MemorySpace>
219 {
220 public:
225 PreconditionIdentity() = default;
226
236 void
237 initialize(const SparseMatrix<Number, MemorySpace> &A);
238 };
239
240
241
248 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
249 class PreconditionIfpackBase : public PreconditionBase<Number, MemorySpace>
250 {
251 public:
262
268 void
269 initialize(const SparseMatrix<Number, MemorySpace> &A);
270
276 std::string,
277 << "You tried to select the preconditioner type <" << arg1 << ">\n"
278 << "but this preconditioner is not supported by Trilinos/Ifpack22\n"
279 << "due to one of the following reasons:\n"
280 << "* This preconditioner does not exist\n"
281 << "* This preconditioner has a specialized constructor not supported by the Ifpack2 Factory.\n"
282 << "* This preconditioner is not (yet) supported by Trilinos/Ifpack2\n"
283 << "* Trilinos/Ifpack2 was not configured for its use.");
284
285 protected:
290 std::string preconditioner_type;
291 };
292
293
294
308 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
310 : public PreconditionIfpackBase<Number, MemorySpace>
311 {
312 public:
329 PreconditionIfpack(const std::string &preconditioner_type);
330
340 void
341 set_parameter_list(Teuchos::ParameterList &parameter_list);
342 };
343
344
345
353 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
355 : public PreconditionIfpackBase<Number, MemorySpace>
356 {
357 public:
362 struct AdditionalData
363 {
375 AdditionalData(const double omega = 1.,
376 const bool fix_diagonal = false,
377 const double min_diagonal = 0.,
378 const int n_sweeps = 1);
379
384 double omega;
393 bool fix_diagonal;
401 double min_diagonal;
406 int n_sweeps;
407 };
413
420 void
421 initialize(const SparseMatrix<Number, MemorySpace> &A,
422 const AdditionalData &additional_data = AdditionalData());
423 };
424
425
426
437 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
439 : public PreconditionIfpackBase<Number, MemorySpace>
440 {
441 public:
446 struct AdditionalData
447 {
460 AdditionalData(const double omega = 1.,
461 const bool fix_diagonal = false,
462 const double min_diagonal = 0.,
463 const int n_sweeps = 1);
464
469 double omega;
478 bool fix_diagonal;
486 double min_diagonal;
491 int n_sweeps;
492 };
493
499
506 void
507 initialize(const SparseMatrix<Number, MemorySpace> &A,
508 const AdditionalData &additional_data = AdditionalData());
509 };
510
511
512
524 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
526 : public PreconditionIfpackBase<Number, MemorySpace>
527 {
528 public:
533 struct AdditionalData
534 {
548 AdditionalData(const double omega = 1,
549 const double eta = 1.5,
550 const bool fix_diagonal = false,
551 const double min_diagonal = 0,
552 const int n_sweeps = 1);
553
558 double omega;
559
567 double eta;
576 bool fix_diagonal;
584 double min_diagonal;
589 int n_sweeps;
590 };
591
597
604 void
605 initialize(const SparseMatrix<Number, MemorySpace> &A,
606 const AdditionalData &additional_data = AdditionalData());
607 };
608
609
610
620 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
621 class PreconditionSOR : public PreconditionIfpackBase<Number, MemorySpace>
622 {
623 public:
628 struct AdditionalData
629 {
642 AdditionalData(const double omega = 1.,
643 const int overlap = 0,
644 const bool fix_diagonal = false,
645 const double min_diagonal = 0.,
646 const int n_sweeps = 1);
647
652 double omega;
662 int overlap;
671 bool fix_diagonal;
679 double min_diagonal;
684 int n_sweeps;
685 };
686
692
699 void
700 initialize(const SparseMatrix<Number, MemorySpace> &A,
701 const AdditionalData &additional_data = AdditionalData());
702 };
703
704
705
712 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
713 class PreconditionSSOR : public PreconditionIfpackBase<Number, MemorySpace>
714 {
715 public:
720 struct AdditionalData
721 {
734 AdditionalData(const double omega = 1.,
735 const int overlap = 0,
736 const bool fix_diagonal = false,
737 const double min_diagonal = 0.,
738 const int n_sweeps = 1);
739
744 double omega;
754 int overlap;
763 bool fix_diagonal;
771 double min_diagonal;
776 int n_sweeps;
777 };
778
779
785
792 void
793 initialize(const SparseMatrix<Number, MemorySpace> &A,
794 const AdditionalData &additional_data = AdditionalData());
795 };
796
797
798
805 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
807 : public PreconditionIfpackBase<Number, MemorySpace>
808 {
809 public:
814 struct AdditionalData
815 {
826 AdditionalData(const int degree = 1,
827 const double max_eigenvalue = 10.,
828 const double min_eigenvalue = 1.,
829 const double eigenvalue_ratio = 30.,
830 const double min_diagonal = 1e-12,
831 const bool nonzero_starting = false);
840 int degree;
841 /*
842 * @brief Upper bound for the maximum eigenvalue of the matrix.
843 *
844 * This needs to be set properly for the appropriate performance of this
845 * preconditioner.
846 */
847 double max_eigenvalue;
848 /*
849 * @brief Lower bound for the minimum eigenvalue of the matrix.
850 *
851 */
852 double min_eigenvalue;
857 double eigenvalue_ratio;
865 double min_diagonal;
878 bool nonzero_starting;
879 };
880
886
893 void
894 initialize(const SparseMatrix<Number, MemorySpace> &A,
895 const AdditionalData &additional_data = AdditionalData());
896 };
897
898
899
917 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
918 class PreconditionILU : public PreconditionIfpackBase<Number, MemorySpace>
919 {
920 public:
925 struct AdditionalData
926 {
940 AdditionalData(const int ilu_fill = 0,
941 const double ilu_atol = 0.,
942 const double ilu_rtol = 1.,
943 const int overlap = 0);
944
952 int ilu_fill;
957 double ilu_atol;
962 double ilu_rtol;
972 int overlap;
973 };
974
980
987 void
988 initialize(const SparseMatrix<Number, MemorySpace> &A,
989 const AdditionalData &additional_data = AdditionalData());
990 };
991
992
993
1001 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
1002 class PreconditionILUT : public PreconditionIfpackBase<Number, MemorySpace>
1003 {
1004 public:
1009 struct AdditionalData
1010 {
1025 AdditionalData(const double ilut_drop = 0.,
1026 const double ilut_fill = 0.,
1027 const double ilut_atol = 0.,
1028 const double ilut_rtol = 1.,
1029 const int overlap = 0);
1030
1037 double ilut_drop;
1047 double ilut_fill;
1052 double ilut_atol;
1057 double ilut_rtol;
1067 int overlap;
1068 };
1069
1070
1071
1076 PreconditionILUT();
1077
1084 void
1085 initialize(const SparseMatrix<Number, MemorySpace> &A,
1086 const AdditionalData &additional_data = AdditionalData());
1087 };
1088
1089
1090
1104 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
1106 : public PreconditionIfpackBase<Number, MemorySpace>
1107 {
1108 public:
1113 struct AdditionalData
1114 {
1126 AdditionalData(const int n_local_parts = 1,
1127 const double omega = 1.,
1128 const int block_overlap = 0,
1129 const int n_sweeps = 1);
1130
1137 int n_local_parts;
1142 double omega;
1147 int block_overlap;
1152 int n_sweeps;
1153 };
1154
1155
1161
1168 void
1169 initialize(const SparseMatrix<Number, MemorySpace> &A,
1170 const AdditionalData &additional_data = AdditionalData());
1171 };
1172
1173
1174
1184 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
1186 : public PreconditionIfpackBase<Number, MemorySpace>
1187 {
1188 public:
1193 struct AdditionalData
1194 {
1205 AdditionalData(const int n_local_parts = 1,
1206 const double omega = 1,
1207 const int overlap = 0,
1208 const int n_sweeps = 1);
1209
1216 int n_local_parts;
1221 double omega;
1231 int overlap;
1236 int n_sweeps;
1237 };
1238
1240
1241 void
1242 initialize(const SparseMatrix<Number, MemorySpace> &A,
1243 const AdditionalData &additional_data = AdditionalData());
1244 };
1245
1246
1247
1257 template <typename Number, typename MemorySpace = ::MemorySpace::Host>
1259 : public PreconditionIfpackBase<Number, MemorySpace>
1260 {
1261 public:
1266 struct AdditionalData
1267 {
1278 AdditionalData(const int n_local_parts = 1,
1279 const double omega = 1,
1280 const int overlap = 1,
1281 const int n_sweeps = 1);
1288 int n_local_parts;
1293 double omega;
1303 int overlap;
1308 int n_sweeps;
1309 };
1310
1312
1313 void
1314 initialize(const SparseMatrix<Number, MemorySpace> &A,
1315 const AdditionalData &additional_data = AdditionalData());
1316 };
1317# endif // DEAL_II_TRILINOS_WITH_IFPACK2
1318
1319 } // namespace TpetraWrappers
1320} // namespace LinearAlgebra
1321
1322
1324
1325#endif // DEAL_II_TRILINOS_WITH_TPETRA
1326
1327#endif
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.
friend class Tensor
Definition tensor.h:865
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:518
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:519
static ::ExceptionBase & ExcNonMatchingMaps(std::string arg1)
#define DeclExceptionMsg(Exception, defaulttext)
Definition exceptions.h:491
#define DeclException1(Exception1, type1, outsequence)
Definition exceptions.h:513
static ::ExceptionBase & ExcTransposeNotSupported()
PETScWrappers::PreconditionILU PreconditionILU
Tpetra::Operator< Number, LO, GO, NodeType< MemorySpace > > LinearOperator
Standardized data struct to pipe additional flags to the preconditioner.