Reference documentation for deal.II version Git c679197b1a 2019-11-19 16:09:58 -0500
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
trilinos_solver.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 2018 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>
25 # include <deal.II/lac/la_parallel_vector.h>
26 # include <deal.II/lac/solver_control.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 
37 DEAL_II_NAMESPACE_OPEN
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
250  solve(Epetra_Operator & A,
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
275  solve(Epetra_Operator & A,
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
350  const PreconditionBase &preconditioner);
351 
352  template <>
353  void
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 
732 DEAL_II_NAMESPACE_CLOSE
733 
734 # endif // DEAL_II_WITH_TRILINOS
735 
736 /*---------------------------- trilinos_solver.h ---------------------------*/
737 
738 #endif
739 /*---------------------------- trilinos_solver.h ---------------------------*/
void set_preconditioner(AztecOO &solver, const Preconditioner &preconditioner)
SolverBase(SolverControl &cn, const AdditionalData &data=AdditionalData())
std::unique_ptr< Amesos_BaseSolver > solver
const AdditionalData additional_data
std::unique_ptr< AztecOO_StatusTest > status_test
const AdditionalData additional_data
const AdditionalData additional_data
static ::ExceptionBase & ExcTrilinosError(int arg1)
void solve(const SparseMatrix &A, MPI::Vector &x, const MPI::Vector &b, const PreconditionBase &preconditioner)
const AdditionalData additional_data
virtual ~SolverBase()=default
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:518
std::unique_ptr< Epetra_LinearProblem > linear_problem
std::unique_ptr< Epetra_LinearProblem > linear_problem
const AdditionalData additional_data
const AdditionalData additional_data
SolverControl & control() const
void do_solve(const Preconditioner &preconditioner)
AdditionalData(const bool output_solver_details=false, const unsigned int gmres_restart_parameter=30)
const AdditionalData additional_data