Reference documentation for deal.II version 8.4.2
trilinos_solver.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2008 - 2015 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/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>
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 
66  class SolverBase
67  {
68  public:
69 
77  enum SolverName {cg, cgs, gmres, bicgstab, tfqmr} solver_name;
78 
84  {
93  explicit
94  AdditionalData (const bool output_solver_details = false,
95  const unsigned int gmres_restart_parameter = 30);
96 
102 
106  const unsigned int gmres_restart_parameter;
107  };
108 
113 
118  SolverBase (const enum SolverName solver_name,
119  SolverControl &cn);
120 
124  virtual ~SolverBase ();
125 
131  void
132  solve (const SparseMatrix &A,
133  VectorBase &x,
134  const VectorBase &b,
135  const PreconditionBase &preconditioner);
136 
144  void
145  solve (Epetra_Operator &A,
146  VectorBase &x,
147  const VectorBase &b,
148  const PreconditionBase &preconditioner);
149 
160  void
161  solve (const SparseMatrix &A,
162  ::Vector<double> &x,
163  const ::Vector<double> &b,
164  const PreconditionBase &preconditioner);
165 
177  void
178  solve (Epetra_Operator &A,
179  ::Vector<double> &x,
180  const ::Vector<double> &b,
181  const PreconditionBase &preconditioner);
182 
189  void
190  solve (const SparseMatrix &A,
192  const ::parallel::distributed::Vector<double> &b,
193  const PreconditionBase &preconditioner);
194 
202  void
203  solve (Epetra_Operator &A,
205  const ::parallel::distributed::Vector<double> &b,
206  const PreconditionBase &preconditioner);
207 
208 
212  SolverControl &control() const;
213 
217  DeclException1 (ExcTrilinosError,
218  int,
219  << "An error with error number " << arg1
220  << " occurred while calling a Trilinos function");
221 
222  protected:
223 
231 
232  private:
233 
238  void do_solve(const PreconditionBase &preconditioner);
239 
245  std_cxx11::shared_ptr<Epetra_LinearProblem> linear_problem;
246 
251  AztecOO solver;
252 
257 
258  };
259 
260 
261 
268  class SolverCG : public SolverBase
269  {
270  public:
276  {
280  explicit
281  AdditionalData (const bool output_solver_details = false);
282 
288  };
289 
297  SolverCG (SolverControl &cn,
298  const AdditionalData &data = AdditionalData());
299 
300  protected:
305  };
306 
307 
308 
315  class SolverCGS : public SolverBase
316  {
317  public:
322  {
326  explicit
327  AdditionalData (const bool output_solver_details = false);
328 
334  };
335 
344  const AdditionalData &data = AdditionalData());
345 
346  protected:
351  };
352 
353 
354 
361  class SolverGMRES : public SolverBase
362  {
363  public:
368  {
373  explicit
374  AdditionalData (const bool output_solver_details = false,
375  const unsigned int restart_parameter = 30);
376 
382 
386  unsigned int restart_parameter;
387  };
388 
397  const AdditionalData &data = AdditionalData());
398 
399  protected:
404  };
405 
406 
407 
415  class SolverBicgstab : public SolverBase
416  {
417  public:
422  {
426  explicit
427  AdditionalData (const bool output_solver_details = false);
428 
434  };
435 
444  const AdditionalData &data = AdditionalData());
445 
446  protected:
451  };
452 
453 
454 
462  class SolverTFQMR : public SolverBase
463  {
464  public:
469  {
473  explicit
474  AdditionalData (const bool output_solver_details = false);
475 
481  };
482 
491  const AdditionalData &data = AdditionalData());
492 
493  protected:
498  };
499 
500 
501 
516  {
517  public:
518 
524  {
528  explicit
529  AdditionalData (const bool output_solver_details = false,
530  const std::string &solver_type = "Amesos_Klu");
531 
537 
556  std::string solver_type;
557  };
558 
563  const AdditionalData &data = AdditionalData());
564 
568  virtual ~SolverDirect ();
569 
576  void
577  solve (const SparseMatrix &A,
578  VectorBase &x,
579  const VectorBase &b);
580 
588  void
589  solve (const SparseMatrix &A,
590  ::Vector<double> &x,
591  const ::Vector<double> &b);
592 
599  void
600  solve (const SparseMatrix &A,
602  const ::parallel::distributed::Vector<double> &b);
603 
607  SolverControl &control() const;
608 
612  DeclException1 (ExcTrilinosError,
613  int,
614  << "An error with error number " << arg1
615  << " occurred while calling a Trilinos function");
616 
617  private:
622  void do_solve();
623 
631 
637  std_cxx11::shared_ptr<Epetra_LinearProblem> linear_problem;
638 
643  std_cxx11::shared_ptr<Amesos_BaseSolver> solver;
644 
649  };
650 
651 }
652 
653 DEAL_II_NAMESPACE_CLOSE
654 
655 #endif // DEAL_II_WITH_TRILINOS
656 
657 /*---------------------------- trilinos_solver.h ---------------------------*/
658 
659 #endif
660 /*---------------------------- trilinos_solver.h ---------------------------*/
void do_solve(const PreconditionBase &preconditioner)
std_cxx11::shared_ptr< Epetra_LinearProblem > linear_problem
const AdditionalData additional_data
const AdditionalData additional_data
std_cxx11::shared_ptr< Epetra_LinearProblem > linear_problem
const AdditionalData additional_data
const AdditionalData additional_data
void solve(const SparseMatrix &A, VectorBase &x, const VectorBase &b, const PreconditionBase &preconditioner)
SolverBase(SolverControl &cn)
const AdditionalData additional_data
const AdditionalData additional_data
std_cxx11::shared_ptr< Amesos_BaseSolver > solver
SolverControl & control() const
AdditionalData(const bool output_solver_details=false, const unsigned int gmres_restart_parameter=30)
const AdditionalData additional_data
DeclException1(ExcTrilinosError, int,<< "An error with error number "<< arg1<< " occurred while calling a Trilinos function")