DOLFIN
DOLFIN C++ interface
GenericLinearAlgebraFactory.h
1 // Copyright (C) 2007 Ola Skavhaug
2 //
3 // This file is part of DOLFIN.
4 //
5 // DOLFIN is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // DOLFIN is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // Modified by Anders Logg 2011-2012
19 //
20 // First added: 2007-11-30
21 // Last changed: 2012-08-22
22 
23 #ifndef __GENERIC_LINEAR_ALGEBRA_FACTORY_H
24 #define __GENERIC_LINEAR_ALGEBRA_FACTORY_H
25 
26 #include <string>
27 #include <vector>
28 #include <memory>
29 #include <dolfin/common/MPI.h>
30 #include <dolfin/common/types.h>
31 #include <dolfin/log/log.h>
32 
33 // Included here so we can define dummy class below
34 #include "GenericLinearOperator.h"
35 
36 namespace dolfin
37 {
38 
39  class GenericLinearSolver;
40  class GenericMatrix;
41  class GenericVector;
42  class TensorLayout;
43 
45 
47  {
48  public:
49 
52 
55 
57  virtual std::shared_ptr<GenericMatrix> create_matrix(MPI_Comm comm) const = 0;
58 
60  virtual std::shared_ptr<GenericVector>
61  create_vector(MPI_Comm comm) const = 0;
62 
64  virtual std::shared_ptr<TensorLayout>
65  create_layout(MPI_Comm comm, std::size_t rank) const = 0;
66 
68  virtual std::shared_ptr<GenericLinearOperator>
69  create_linear_operator(MPI_Comm comm) const = 0;
70 
72  virtual std::shared_ptr<GenericLinearSolver>
73  create_lu_solver(MPI_Comm comm, std::string method) const = 0;
74 
76  virtual std::shared_ptr<GenericLinearSolver>
77  create_krylov_solver(MPI_Comm comm,
78  std::string method,
79  std::string preconditioner) const = 0;
80 
83  virtual std::map<std::string, std::string> lu_solver_methods() const
84  { return std::map<std::string, std::string>(); }
85 
88  virtual std::map<std::string, std::string> krylov_solver_methods() const
89  { return std::map<std::string, std::string>(); }
90 
93  virtual std::map<std::string, std::string>
95  { return std::map<std::string, std::string>(); }
96 
97  protected:
98 
99  // Dummy class that can be returned for linear algebra backends
100  // that do not support the GenericLinearOperator interface
102  {
103  public:
104 
105  std::size_t size(std::size_t dim) const
106  { return 0; }
107 
108  void mult(const GenericVector& x, GenericVector& y) const
109  { dolfin_not_implemented(); }
110 
111  MPI_Comm mpi_comm() const
112  { dolfin_not_implemented(); return MPI_COMM_WORLD; }
113 
114  std::string str(bool verbose) const
115  { dolfin_not_implemented(); return ""; }
116 
117  };
118 
119  };
120 
121 }
122 
123 #endif
virtual std::shared_ptr< GenericLinearSolver > create_lu_solver(MPI_Comm comm, std::string method) const =0
Create LU solver.
std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: GenericLinearAlgebraFactory.h:114
Definition: adapt.h:29
virtual ~GenericLinearAlgebraFactory()
Destructor.
Definition: GenericLinearAlgebraFactory.h:54
virtual std::shared_ptr< GenericLinearSolver > create_krylov_solver(MPI_Comm comm, std::string method, std::string preconditioner) const =0
Create Krylov solver.
void mult(const GenericVector &x, GenericVector &y) const
Compute matrix-vector product y = Ax.
Definition: GenericLinearAlgebraFactory.h:108
virtual std::shared_ptr< GenericLinearOperator > create_linear_operator(MPI_Comm comm) const =0
Create empty linear operator.
std::size_t size(std::size_t dim) const
Return size of given dimension.
Definition: GenericLinearAlgebraFactory.h:105
Definition: GenericLinearAlgebraFactory.h:101
Definition: GenericLinearOperator.h:42
GenericLinearAlgebraFactory()
Constructor.
Definition: GenericLinearAlgebraFactory.h:51
Base class for LinearAlgebra factories.
Definition: GenericLinearAlgebraFactory.h:46
virtual std::map< std::string, std::string > lu_solver_methods() const
Definition: GenericLinearAlgebraFactory.h:83
MPI_Comm mpi_comm() const
Return MPI communicator.
Definition: GenericLinearAlgebraFactory.h:111
virtual std::map< std::string, std::string > krylov_solver_methods() const
Definition: GenericLinearAlgebraFactory.h:88
virtual std::shared_ptr< GenericMatrix > create_matrix(MPI_Comm comm) const =0
Create empty matrix.
virtual std::map< std::string, std::string > krylov_solver_preconditioners() const
Definition: GenericLinearAlgebraFactory.h:94
virtual std::shared_ptr< TensorLayout > create_layout(MPI_Comm comm, std::size_t rank) const =0
Create empty tensor layout.
virtual std::shared_ptr< GenericVector > create_vector(MPI_Comm comm) const =0
Create empty vector.
This class defines a common interface for vectors.
Definition: GenericVector.h:47