Reference documentation for deal.II version 8.5.1
trilinos_solver.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 2017 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 at
12 // the top level of the deal.II distribution.
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/base/std_cxx11/shared_ptr.h>
25 # include <deal.II/lac/exceptions.h>
26 # include <deal.II/lac/solver_control.h>
27 # include <deal.II/lac/vector.h>
28 # include <deal.II/lac/la_parallel_vector.h>
29 
30 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
31 # include <Epetra_LinearProblem.h>
32 # include <AztecOO.h>
33 # include <Epetra_Operator.h>
34 # include <Amesos.h>
35 DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
36 
37 
38 DEAL_II_NAMESPACE_OPEN
39 
40 namespace TrilinosWrappers
41 {
42  // forward declarations
43  class SparseMatrix;
44  class VectorBase;
45  class PreconditionBase;
46 
47 
67  class SolverBase
68  {
69  public:
70 
79  {
83  cg,
87  cgs,
100  } solver_name;
101 
107  {
116  explicit
117  AdditionalData (const bool output_solver_details = false,
118  const unsigned int gmres_restart_parameter = 30);
119 
125 
129  const unsigned int gmres_restart_parameter;
130  };
131 
136 
141  SolverBase (const enum SolverName solver_name,
142  SolverControl &cn);
143 
147  virtual ~SolverBase ();
148 
154  void
155  solve (const SparseMatrix &A,
156  VectorBase &x,
157  const VectorBase &b,
158  const PreconditionBase &preconditioner);
159 
167  void
168  solve (const Epetra_Operator &A,
169  VectorBase &x,
170  const VectorBase &b,
171  const PreconditionBase &preconditioner);
172 
182  void
183  solve (const Epetra_Operator &A,
184  VectorBase &x,
185  const VectorBase &b,
186  const Epetra_Operator &preconditioner);
187 
197  void
198  solve (const Epetra_Operator &A,
199  Epetra_MultiVector &x,
200  const Epetra_MultiVector &b,
201  const PreconditionBase &preconditioner);
202 
213  void
214  solve (const Epetra_Operator &A,
215  Epetra_MultiVector &x,
216  const Epetra_MultiVector &b,
217  const Epetra_Operator &preconditioner);
218 
219 
220 
231  void
232  solve (const SparseMatrix &A,
233  ::Vector<double> &x,
234  const ::Vector<double> &b,
235  const PreconditionBase &preconditioner);
236 
248  void
249  solve (Epetra_Operator &A,
250  ::Vector<double> &x,
251  const ::Vector<double> &b,
252  const PreconditionBase &preconditioner);
253 
260  void
261  solve (const SparseMatrix &A,
263  const ::LinearAlgebra::distributed::Vector<double> &b,
264  const PreconditionBase &preconditioner);
265 
273  void
274  solve (Epetra_Operator &A,
276  const ::LinearAlgebra::distributed::Vector<double> &b,
277  const PreconditionBase &preconditioner);
278 
279 
283  SolverControl &control() const;
284 
289  int,
290  << "An error with error number " << arg1
291  << " occurred while calling a Trilinos function");
292 
293  protected:
294 
302 
303  private:
304 
309  template<typename Preconditioner>
310  void do_solve(const Preconditioner &preconditioner);
311 
315  template<typename Preconditioner>
316  void set_preconditioner (AztecOO &solver,
317  const Preconditioner &preconditioner);
318 
324  std_cxx11::shared_ptr<Epetra_LinearProblem> linear_problem;
325 
330  std_cxx11::shared_ptr<AztecOO_StatusTest> status_test;
331 
336  AztecOO solver;
337 
342  };
343 
344 
345  // provide a declaration for two explicit specializations
346  template <>
347  void
348  SolverBase::set_preconditioner(AztecOO &solver,
349  const PreconditionBase &preconditioner);
350 
351  template <>
352  void
353  SolverBase::set_preconditioner(AztecOO &solver,
354  const Epetra_Operator &preconditioner);
355 
356 
357 
364  class SolverCG : public SolverBase
365  {
366  public:
372  {
376  explicit
377  AdditionalData (const bool output_solver_details = false);
378 
384  };
385 
393  SolverCG (SolverControl &cn,
394  const AdditionalData &data = AdditionalData());
395 
396  protected:
401  };
402 
403 
404 
411  class SolverCGS : public SolverBase
412  {
413  public:
418  {
422  explicit
423  AdditionalData (const bool output_solver_details = false);
424 
430  };
431 
440  const AdditionalData &data = AdditionalData());
441 
442  protected:
447  };
448 
449 
450 
457  class SolverGMRES : public SolverBase
458  {
459  public:
464  {
469  explicit
470  AdditionalData (const bool output_solver_details = false,
471  const unsigned int restart_parameter = 30);
472 
478 
482  unsigned int restart_parameter;
483  };
484 
493  const AdditionalData &data = AdditionalData());
494 
495  protected:
500  };
501 
502 
503 
511  class SolverBicgstab : public SolverBase
512  {
513  public:
518  {
522  explicit
523  AdditionalData (const bool output_solver_details = false);
524 
530  };
531 
540  const AdditionalData &data = AdditionalData());
541 
542  protected:
547  };
548 
549 
550 
558  class SolverTFQMR : public SolverBase
559  {
560  public:
565  {
569  explicit
570  AdditionalData (const bool output_solver_details = false);
571 
577  };
578 
587  const AdditionalData &data = AdditionalData());
588 
589  protected:
594  };
595 
596 
597 
612  {
613  public:
614 
620  {
624  explicit
625  AdditionalData (const bool output_solver_details = false,
626  const std::string &solver_type = "Amesos_Klu");
627 
633 
652  std::string solver_type;
653  };
654 
659  const AdditionalData &data = AdditionalData());
660 
664  virtual ~SolverDirect ();
665 
672  void initialize (const SparseMatrix &A);
673 
679  void solve (VectorBase &x, const VectorBase &b);
680 
687  void
688  solve (const SparseMatrix &A,
689  VectorBase &x,
690  const VectorBase &b);
691 
699  void
700  solve (const SparseMatrix &A,
701  ::Vector<double> &x,
702  const ::Vector<double> &b);
703 
710  void
711  solve (const SparseMatrix &A,
713  const ::LinearAlgebra::distributed::Vector<double> &b);
714 
718  SolverControl &control() const;
719 
724  int,
725  << "An error with error number " << arg1
726  << " occurred while calling a Trilinos function");
727 
728  private:
733  void do_solve();
734 
742 
748  std_cxx11::shared_ptr<Epetra_LinearProblem> linear_problem;
749 
754  std_cxx11::shared_ptr<Amesos_BaseSolver> solver;
755 
760  };
761 
762 }
763 
764 DEAL_II_NAMESPACE_CLOSE
765 
766 #endif // DEAL_II_WITH_TRILINOS
767 
768 /*---------------------------- trilinos_solver.h ---------------------------*/
769 
770 #endif
771 /*---------------------------- trilinos_solver.h ---------------------------*/
void set_preconditioner(AztecOO &solver, const Preconditioner &preconditioner)
SolverCG(SolverControl &cn, const AdditionalData &data=AdditionalData())
std_cxx11::shared_ptr< Epetra_LinearProblem > linear_problem
const AdditionalData additional_data
const AdditionalData additional_data
std_cxx11::shared_ptr< Epetra_LinearProblem > linear_problem
AdditionalData(const bool output_solver_details=false, const unsigned int restart_parameter=30)
const AdditionalData additional_data
void initialize(const SparseMatrix &A)
static ::ExceptionBase & ExcTrilinosError(int arg1)
const AdditionalData additional_data
void solve(const SparseMatrix &A, VectorBase &x, const VectorBase &b, const PreconditionBase &preconditioner)
void do_solve(const Preconditioner &preconditioner)
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:564
SolverCGS(SolverControl &cn, const AdditionalData &data=AdditionalData())
SolverBase(SolverControl &cn)
AdditionalData(const bool output_solver_details=false)
SolverBicgstab(SolverControl &cn, const AdditionalData &data=AdditionalData())
SolverControl & control() const
std_cxx11::shared_ptr< AztecOO_StatusTest > status_test
SolverTFQMR(SolverControl &cn, const AdditionalData &data=AdditionalData())
AdditionalData(const bool output_solver_details=false)
void solve(VectorBase &x, const VectorBase &b)
const AdditionalData additional_data
AdditionalData(const bool output_solver_details=false, const std::string &solver_type="Amesos_Klu")
SolverDirect(SolverControl &cn, const AdditionalData &data=AdditionalData())
const AdditionalData additional_data
std_cxx11::shared_ptr< Amesos_BaseSolver > solver
AdditionalData(const bool output_solver_details=false)
SolverControl & control() const
AdditionalData(const bool output_solver_details=false, const unsigned int gmres_restart_parameter=30)
SolverGMRES(SolverControl &cn, const AdditionalData &data=AdditionalData())
const AdditionalData additional_data
static ::ExceptionBase & ExcTrilinosError(int arg1)
AdditionalData(const bool output_solver_details=false)