DOLFIN
DOLFIN C++ interface
EigenFactory.h
1 // Copyright (C) 2015 Chris Richardson and Garth Wells
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 // First added: 2015-02-01
19 
20 #ifndef __EIGEN_FACTORY_H
21 #define __EIGEN_FACTORY_H
22 
23 #include <map>
24 #include <memory>
25 #include <string>
26 
27 #include <dolfin/common/MPI.h>
28 #include <dolfin/log/log.h>
29 #include "EigenKrylovSolver.h"
30 #include "EigenLUSolver.h"
31 #include "EigenMatrix.h"
32 #include "EigenVector.h"
33 #include "TensorLayout.h"
34 #include "GenericLinearAlgebraFactory.h"
35 
36 namespace dolfin
37 {
38  // Forward declaration
39  class GenericLinearSolver;
40 
42 
44  {
45  public:
46 
48  virtual ~EigenFactory() {}
49 
51  std::shared_ptr<GenericMatrix> create_matrix(MPI_Comm comm) const
52  { return std::make_shared<EigenMatrix>(); }
53 
55  std::shared_ptr<GenericVector> create_vector(MPI_Comm comm) const
56  { return std::make_shared<EigenVector>(comm); }
57 
59  std::shared_ptr<TensorLayout> create_layout(MPI_Comm comm,
60  std::size_t rank) const
61  {
62  TensorLayout::Sparsity sparsity = TensorLayout::Sparsity::DENSE;
63  if (rank > 1)
64  sparsity = TensorLayout::Sparsity::SPARSE;
65  return std::make_shared<TensorLayout>(comm, 0, sparsity);
66  }
67 
69  std::shared_ptr<GenericLinearOperator> create_linear_operator(MPI_Comm comm) const
70  {
71  dolfin_not_implemented();
72  std::shared_ptr<GenericLinearOperator> A;
73  return A;
74  }
75 
77  std::shared_ptr<GenericLinearSolver>
78  create_lu_solver(MPI_Comm comm, std::string method) const
79  {
80  return std::make_shared<EigenLUSolver>(method);
81  }
82 
84  std::shared_ptr<GenericLinearSolver>
85  create_krylov_solver(MPI_Comm comm,
86  std::string method,
87  std::string preconditioner) const
88  {
89  std::shared_ptr<GenericLinearSolver>
90  solver(new EigenKrylovSolver(method, preconditioner));
91  return solver;
92  }
93 
95  std::map<std::string, std::string> lu_solver_methods() const
96  { return EigenLUSolver::methods(); }
97 
99  std::map<std::string, std::string> krylov_solver_methods() const
100  { return EigenKrylovSolver::methods(); }
101 
103  std::map<std::string, std::string> krylov_solver_preconditioners() const
105 
108  { return factory; }
109 
110  private:
111 
112  // Private Constructor
113  EigenFactory() {}
114 
115  // Singleton instance
116  static EigenFactory factory;
117  };
118 
119 }
120 #endif
static EigenFactory & instance()
Return singleton instance.
Definition: EigenFactory.h:107
Sparsity
Sparse or dense layout.
Definition: TensorLayout.h:47
std::shared_ptr< GenericLinearSolver > create_lu_solver(MPI_Comm comm, std::string method) const
Create LU solver.
Definition: EigenFactory.h:78
std::map< std::string, std::string > krylov_solver_methods() const
Return a list of available Krylov solver methods.
Definition: EigenFactory.h:99
std::shared_ptr< GenericVector > create_vector(MPI_Comm comm) const
Create empty vector.
Definition: EigenFactory.h:55
Definition: adapt.h:29
std::shared_ptr< TensorLayout > create_layout(MPI_Comm comm, std::size_t rank) const
Create empty tensor layout.
Definition: EigenFactory.h:59
static std::map< std::string, std::string > methods()
Return a list of available solver methods.
Definition: EigenKrylovSolver.cpp:58
std::map< std::string, std::string > lu_solver_methods() const
Return a list of available LU solver methods.
Definition: EigenFactory.h:95
Base class for LinearAlgebra factories.
Definition: GenericLinearAlgebraFactory.h:46
std::map< std::string, std::string > krylov_solver_preconditioners() const
Return a list of available preconditioners.
Definition: EigenFactory.h:103
static std::map< std::string, std::string > preconditioners()
Return a list of available preconditioners.
Definition: EigenKrylovSolver.cpp:63
std::shared_ptr< GenericLinearSolver > create_krylov_solver(MPI_Comm comm, std::string method, std::string preconditioner) const
Create Krylov solver.
Definition: EigenFactory.h:85
static std::map< std::string, std::string > methods()
Return a list of available solver methods.
Definition: EigenLUSolver.cpp:137
virtual ~EigenFactory()
Destructor.
Definition: EigenFactory.h:48
std::shared_ptr< GenericMatrix > create_matrix(MPI_Comm comm) const
Create empty matrix.
Definition: EigenFactory.h:51
Eigen linear algebra factory.
Definition: EigenFactory.h:43
std::shared_ptr< GenericLinearOperator > create_linear_operator(MPI_Comm comm) const
Create empty linear operator.
Definition: EigenFactory.h:69
Definition: EigenKrylovSolver.h:40