Reference documentation for deal.II version 9.2.0
\(\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\}}\)
trilinos_solver.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 2019 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.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_trilinos_solver_h
17 # define dealii_trilinos_solver_h
18 
19 
20 # include <deal.II/base/config.h>
21 
22 # ifdef DEAL_II_WITH_TRILINOS
23 
24 # include <deal.II/lac/exceptions.h>
27 # include <deal.II/lac/vector.h>
28 
29 # include <Amesos.h>
30 # include <AztecOO.h>
31 # include <Epetra_LinearProblem.h>
32 # include <Epetra_Operator.h>
33 
34 # include <memory>
35 
36 
38 
39 namespace TrilinosWrappers
40 {
41  // forward declarations
42 # ifndef DOXYGEN
43  class SparseMatrix;
44  class PreconditionBase;
45 # endif
46 
47 
68  class SolverBase
69  {
70  public:
79  {
83  cg,
87  cgs,
100  } solver_name;
101 
107  {
116  explicit AdditionalData(const bool output_solver_details = false,
117  const unsigned int gmres_restart_parameter = 30);
118 
124 
128  const unsigned int gmres_restart_parameter;
129  };
130 
135  const AdditionalData &data = AdditionalData());
136 
141  SolverBase(const enum SolverName solver_name,
142  SolverControl & cn,
143  const AdditionalData &data = AdditionalData());
144 
148  virtual ~SolverBase() = default;
149 
155  void
156  solve(const SparseMatrix & A,
157  MPI::Vector & x,
158  const MPI::Vector & b,
159  const PreconditionBase &preconditioner);
160 
168  void
169  solve(const Epetra_Operator & A,
170  MPI::Vector & x,
171  const MPI::Vector & b,
172  const PreconditionBase &preconditioner);
173 
183  void
184  solve(const Epetra_Operator &A,
185  MPI::Vector & x,
186  const MPI::Vector & b,
187  const Epetra_Operator &preconditioner);
188 
198  void
199  solve(const Epetra_Operator & A,
200  Epetra_MultiVector & x,
201  const Epetra_MultiVector &b,
202  const PreconditionBase & preconditioner);
203 
214  void
215  solve(const Epetra_Operator & A,
216  Epetra_MultiVector & x,
217  const Epetra_MultiVector &b,
218  const Epetra_Operator & preconditioner);
219 
220 
221 
232  void
233  solve(const SparseMatrix & A,
234  ::Vector<double> & x,
235  const ::Vector<double> &b,
236  const PreconditionBase & preconditioner);
237 
249  void
251  ::Vector<double> & x,
252  const ::Vector<double> &b,
253  const PreconditionBase & preconditioner);
254 
261  void
262  solve(const SparseMatrix & A,
264  const ::LinearAlgebra::distributed::Vector<double> &b,
265  const PreconditionBase &preconditioner);
266 
274  void
277  const ::LinearAlgebra::distributed::Vector<double> &b,
278  const PreconditionBase &preconditioner);
279 
280 
284  SolverControl &
285  control() const;
286 
291  int,
292  << "An error with error number " << arg1
293  << " occurred while calling a Trilinos function");
294 
295  protected:
303 
304  private:
309  template <typename Preconditioner>
310  void
311  do_solve(const Preconditioner &preconditioner);
312 
316  template <typename Preconditioner>
317  void
318  set_preconditioner(AztecOO &solver, const Preconditioner &preconditioner);
319 
325  std::unique_ptr<Epetra_LinearProblem> linear_problem;
326 
331  std::unique_ptr<AztecOO_StatusTest> status_test;
332 
337  AztecOO solver;
338 
343  };
344 
345 
346  // provide a declaration for two explicit specializations
347  template <>
348  void
349  SolverBase::set_preconditioner(AztecOO & solver,
350  const PreconditionBase &preconditioner);
351 
352  template <>
353  void
354  SolverBase::set_preconditioner(AztecOO & solver,
355  const Epetra_Operator &preconditioner);
356 
357 
358 
365  class SolverCG : public SolverBase
366  {
367  public:
373  {
377  explicit AdditionalData(const bool output_solver_details = false);
378  };
379 
387  SolverCG(SolverControl &cn, const AdditionalData &data = AdditionalData());
388 
389  protected:
394  };
395 
396 
397 
404  class SolverCGS : public SolverBase
405  {
406  public:
411  {
415  explicit AdditionalData(const bool output_solver_details = false);
416  };
417 
426 
427  protected:
432  };
433 
434 
435 
442  class SolverGMRES : public SolverBase
443  {
444  public:
449  {
454  explicit AdditionalData(const bool output_solver_details = false,
455  const unsigned int restart_parameter = 30);
456  };
457 
466  const AdditionalData &data = AdditionalData());
467 
468  protected:
473  };
474 
475 
476 
484  class SolverBicgstab : public SolverBase
485  {
486  public:
491  {
495  explicit AdditionalData(const bool output_solver_details = false);
496  };
497 
506  const AdditionalData &data = AdditionalData());
507 
508  protected:
513  };
514 
515 
516 
524  class SolverTFQMR : public SolverBase
525  {
526  public:
531  {
535  explicit AdditionalData(const bool output_solver_details = false);
536  };
537 
546  const AdditionalData &data = AdditionalData());
547 
548  protected:
553  };
554 
555 
556 
571  {
572  public:
578  {
582  explicit AdditionalData(const bool output_solver_details = false,
583  const std::string &solver_type = "Amesos_Klu");
584 
590 
609  std::string solver_type;
610  };
611 
616  const AdditionalData &data = AdditionalData());
617 
621  virtual ~SolverDirect() = default;
622 
629  void
630  initialize(const SparseMatrix &A);
631 
637  void
638  solve(MPI::Vector &x, const MPI::Vector &b);
639 
645  void
647  const ::LinearAlgebra::distributed::Vector<double> &b);
648 
655  void
656  solve(const SparseMatrix &A, MPI::Vector &x, const MPI::Vector &b);
657 
665  void
666  solve(const SparseMatrix & A,
667  ::Vector<double> & x,
668  const ::Vector<double> &b);
669 
676  void
677  solve(const SparseMatrix & A,
679  const ::LinearAlgebra::distributed::Vector<double> &b);
680 
684  SolverControl &
685  control() const;
686 
691  int,
692  << "An error with error number " << arg1
693  << " occurred while calling a Trilinos function");
694 
695  private:
700  void
701  do_solve();
702 
710 
716  std::unique_ptr<Epetra_LinearProblem> linear_problem;
717 
722  std::unique_ptr<Amesos_BaseSolver> solver;
723 
728  };
729 
730 } // namespace TrilinosWrappers
731 
733 
734 # endif // DEAL_II_WITH_TRILINOS
735 
736 /*---------------------------- trilinos_solver.h ---------------------------*/
737 
738 #endif
739 /*---------------------------- trilinos_solver.h ---------------------------*/
TrilinosWrappers::SolverBase::gmres
@ gmres
Definition: trilinos_solver.h:91
TrilinosWrappers::SolverTFQMR::additional_data
const AdditionalData additional_data
Definition: trilinos_solver.h:552
TrilinosWrappers::MPI::Vector
Definition: trilinos_vector.h:400
TrilinosWrappers::SolverBase::additional_data
const AdditionalData additional_data
Definition: trilinos_solver.h:342
TrilinosWrappers::SolverBase::solve
void solve(const SparseMatrix &A, MPI::Vector &x, const MPI::Vector &b, const PreconditionBase &preconditioner)
Definition: trilinos_solver.cc:76
TrilinosWrappers::SolverBase::solver
AztecOO solver
Definition: trilinos_solver.h:337
TrilinosWrappers::SolverDirect::linear_problem
std::unique_ptr< Epetra_LinearProblem > linear_problem
Definition: trilinos_solver.h:716
TrilinosWrappers::SparseMatrix
Definition: trilinos_sparse_matrix.h:515
LinearAlgebra::distributed::Vector< double >
TrilinosWrappers::SolverGMRES::additional_data
const AdditionalData additional_data
Definition: trilinos_solver.h:472
TrilinosWrappers::SolverTFQMR::SolverTFQMR
SolverTFQMR(SolverControl &cn, const AdditionalData &data=AdditionalData())
Definition: trilinos_solver.cc:667
TrilinosWrappers::SolverBicgstab
Definition: trilinos_solver.h:484
TrilinosWrappers::SolverBase::set_preconditioner
void set_preconditioner(AztecOO &solver, const Preconditioner &preconditioner)
TrilinosWrappers::SolverDirect::solver
std::unique_ptr< Amesos_BaseSolver > solver
Definition: trilinos_solver.h:722
TrilinosWrappers::SolverTFQMR::AdditionalData
Definition: trilinos_solver.h:530
SparseMatrix
Definition: sparse_matrix.h:497
TrilinosWrappers::SolverDirect::additional_data
const AdditionalData additional_data
Definition: trilinos_solver.h:727
TrilinosWrappers::SolverBase::ExcTrilinosError
static ::ExceptionBase & ExcTrilinosError(int arg1)
TrilinosWrappers
Definition: types.h:161
TrilinosWrappers::SolverDirect::AdditionalData::output_solver_details
bool output_solver_details
Definition: trilinos_solver.h:589
TrilinosWrappers::SolverCGS::AdditionalData::AdditionalData
AdditionalData(const bool output_solver_details=false)
Definition: trilinos_solver.cc:645
TrilinosWrappers::SolverDirect
Definition: trilinos_solver.h:570
TrilinosWrappers::SolverGMRES
Definition: trilinos_solver.h:442
TrilinosWrappers::SolverBase::SolverBase
SolverBase(SolverControl &cn, const AdditionalData &data=AdditionalData())
Definition: trilinos_solver.cc:49
TrilinosWrappers::SolverBase::AdditionalData::output_solver_details
const bool output_solver_details
Definition: trilinos_solver.h:123
exceptions.h
TrilinosWrappers::SolverDirect::~SolverDirect
virtual ~SolverDirect()=default
TrilinosWrappers::SolverBase::solver_control
SolverControl & solver_control
Definition: trilinos_solver.h:302
TrilinosWrappers::SolverCGS::SolverCGS
SolverCGS(SolverControl &cn, const AdditionalData &data=AdditionalData())
Definition: trilinos_solver.cc:651
TrilinosWrappers::SolverBase::tfqmr
@ tfqmr
Definition: trilinos_solver.h:99
la_parallel_vector.h
TrilinosWrappers::SolverDirect::control
SolverControl & control() const
Definition: trilinos_solver.cc:694
TrilinosWrappers::SolverBase::bicgstab
@ bicgstab
Definition: trilinos_solver.h:95
TrilinosWrappers::SolverBase::status_test
std::unique_ptr< AztecOO_StatusTest > status_test
Definition: trilinos_solver.h:331
TrilinosWrappers::SolverBase::SolverName
SolverName
Definition: trilinos_solver.h:78
TrilinosWrappers::SolverBase::solver_name
enum TrilinosWrappers::SolverBase::SolverName solver_name
TrilinosWrappers::SolverDirect::initialize
void initialize(const SparseMatrix &A)
Definition: trilinos_solver.cc:702
TrilinosWrappers::SolverCG::SolverCG
SolverCG(SolverControl &cn, const AdditionalData &data=AdditionalData())
Definition: trilinos_solver.cc:600
TrilinosWrappers::SolverTFQMR
Definition: trilinos_solver.h:524
TrilinosWrappers::SolverCG::AdditionalData
Definition: trilinos_solver.h:372
TrilinosWrappers::SolverGMRES::SolverGMRES
SolverGMRES(SolverControl &cn, const AdditionalData &data=AdditionalData())
Definition: trilinos_solver.cc:618
TrilinosWrappers::SolverBase::AdditionalData::gmres_restart_parameter
const unsigned int gmres_restart_parameter
Definition: trilinos_solver.h:128
TrilinosWrappers::SolverDirect::AdditionalData
Definition: trilinos_solver.h:577
TrilinosWrappers::SolverCG
Definition: trilinos_solver.h:365
TrilinosWrappers::SolverBase::AdditionalData
Definition: trilinos_solver.h:106
TrilinosWrappers::SolverBase::linear_problem
std::unique_ptr< Epetra_LinearProblem > linear_problem
Definition: trilinos_solver.h:325
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
TrilinosWrappers::SolverTFQMR::AdditionalData::AdditionalData
AdditionalData(const bool output_solver_details=false)
Definition: trilinos_solver.cc:661
Physics::Elasticity::Kinematics::b
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
TrilinosWrappers::SolverBase::~SolverBase
virtual ~SolverBase()=default
TrilinosWrappers::SolverBicgstab::AdditionalData::AdditionalData
AdditionalData(const bool output_solver_details=false)
Definition: trilinos_solver.cc:628
TrilinosWrappers::SolverBicgstab::AdditionalData
Definition: trilinos_solver.h:490
DeclException1
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:518
TrilinosWrappers::SolverGMRES::AdditionalData::AdditionalData
AdditionalData(const bool output_solver_details=false, const unsigned int restart_parameter=30)
Definition: trilinos_solver.cc:610
TrilinosWrappers::SolverDirect::do_solve
void do_solve()
Definition: trilinos_solver.cc:810
TrilinosWrappers::PreconditionBase
Definition: trilinos_precondition.h:82
TrilinosWrappers::SolverDirect::solve
void solve(MPI::Vector &x, const MPI::Vector &b)
Definition: trilinos_solver.cc:747
TrilinosWrappers::SolverBase::control
SolverControl & control() const
Definition: trilinos_solver.cc:68
TrilinosWrappers::SolverBase::do_solve
void do_solve(const Preconditioner &preconditioner)
Definition: trilinos_solver.cc:414
TrilinosWrappers::SolverDirect::AdditionalData::solver_type
std::string solver_type
Definition: trilinos_solver.h:609
LAPACKSupport::A
static const char A
Definition: lapack_support.h:155
TrilinosWrappers::SolverCGS::AdditionalData
Definition: trilinos_solver.h:410
TrilinosWrappers::SolverDirect::SolverDirect
SolverDirect(SolverControl &cn, const AdditionalData &data=AdditionalData())
Definition: trilinos_solver.cc:686
TrilinosWrappers::SolverCGS
Definition: trilinos_solver.h:404
TrilinosWrappers::SolverBase::cgs
@ cgs
Definition: trilinos_solver.h:87
TrilinosWrappers::SolverGMRES::AdditionalData
Definition: trilinos_solver.h:448
vector.h
TrilinosWrappers::SolverBase::AdditionalData::AdditionalData
AdditionalData(const bool output_solver_details=false, const unsigned int gmres_restart_parameter=30)
Definition: trilinos_solver.cc:40
TrilinosWrappers::SolverBicgstab::additional_data
const AdditionalData additional_data
Definition: trilinos_solver.h:512
TrilinosWrappers::SolverCG::additional_data
const AdditionalData additional_data
Definition: trilinos_solver.h:393
config.h
TrilinosWrappers::SolverBase::cg
@ cg
Definition: trilinos_solver.h:83
SolverControl
Definition: solver_control.h:67
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
TrilinosWrappers::SolverBase
Definition: trilinos_solver.h:68
Epetra_Operator
Vector< double >
TrilinosWrappers::SolverDirect::solver_control
SolverControl & solver_control
Definition: trilinos_solver.h:709
TrilinosWrappers::SolverCGS::additional_data
const AdditionalData additional_data
Definition: trilinos_solver.h:431
TrilinosWrappers::SolverDirect::ExcTrilinosError
static ::ExceptionBase & ExcTrilinosError(int arg1)
TrilinosWrappers::SolverBicgstab::SolverBicgstab
SolverBicgstab(SolverControl &cn, const AdditionalData &data=AdditionalData())
Definition: trilinos_solver.cc:635
solver_control.h
TrilinosWrappers::SolverDirect::AdditionalData::AdditionalData
AdditionalData(const bool output_solver_details=false, const std::string &solver_type="Amesos_Klu")
Definition: trilinos_solver.cc:678
TrilinosWrappers::SolverCG::AdditionalData::AdditionalData
AdditionalData(const bool output_solver_details=false)
Definition: trilinos_solver.cc:594