TBTK
LinearEquationSolver.h
Go to the documentation of this file.
1 /* Copyright 2017 Kristofer Bj√∂rnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
23 #ifndef COM_DAFER45_TBTK_SOLVER_LINEAR_EQUATION_SOLVER
24 #define COM_DAFER45_TBTK_SOLVER_LINEAR_EQUATION_SOLVER
25 
26 #include "TBTK/Communicator.h"
27 #include "TBTK/Model.h"
28 #include "TBTK/Solver/Solver.h"
29 
30 #include <complex>
31 #include <vector>
32 
33 namespace TBTK{
34 namespace Solver{
35 
36 class LinearEquationSolver : public Solver, public Communicator{
37 public:
40 
42  virtual ~LinearEquationSolver();
43 
45  enum class Mode {LU, ConjugateGradient};
46 
48  void setMode(Mode mode);
49 
51  std::vector<std::complex<double>> solve(
52  const std::vector<std::complex<double>> &y
53  );
54 private:
56  std::complex<double> *hamiltonian;
57 
59  Mode mode;
60 
62  std::vector<std::complex<double>> solveLU(
63  const std::vector<std::complex<double>> &y
64  );
65 
67  std::vector<std::complex<double>> solveConjugateGradient(
68  const std::vector<std::complex<double>> &y
69  );
70 };
71 
73  this->mode = mode;
74 }
75 
76 inline std::vector<std::complex<double>> LinearEquationSolver::solve(
77  const std::vector<std::complex<double>> &y
78 ){
79  switch(mode){
80  case Mode::LU:
81  return solveLU(y);
82  case Mode::ConjugateGradient:
83  return solveConjugateGradient(y);
84  default:
85  TBTKExit(
86  "LinearEquationSolver::solve()",
87  "Unknown mode.",
88  "This should never happen, contact the developer."
89  );
90  }
91 }
92 
93 }; //End of namespace Solver
94 }; //End of namespace TBTK
95 
96 #endif
Base class for Solvers.
Definition: Solver.h:32
Mode
Definition: LinearEquationSolver.h:45
std::vector< std::complex< double > > solve(const std::vector< std::complex< double >> &y)
Definition: LinearEquationSolver.h:76
Container of Model related information.
void setMode(Mode mode)
Definition: LinearEquationSolver.h:72
Definition: LinearEquationSolver.h:36
Base class for Solvers.
Definition: ModelFactory.h:35
Base class that communicate their current status during execution.
Definition: Communicator.h:28