My Project
BdaSolver.hpp
1 /*
2  Copyright 2019 Equinor ASA
3 
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef OPM_BDASOLVER_BACKEND_HEADER_INCLUDED
21 #define OPM_BDASOLVER_BACKEND_HEADER_INCLUDED
22 
23 
24 #include <opm/simulators/linalg/bda/BdaResult.hpp>
25 #include <opm/simulators/linalg/bda/WellContributions.hpp>
26 
27 namespace bda
28 {
29 
31 
32  enum class SolverStatus {
33  BDA_SOLVER_SUCCESS,
34  BDA_SOLVER_ANALYSIS_FAILED,
35  BDA_SOLVER_CREATE_PRECONDITIONER_FAILED,
36  BDA_SOLVER_UNKNOWN_ERROR
37  };
38 
41  template <unsigned int block_size>
42  class BdaSolver
43  {
44 
45  protected:
46 
47  // verbosity
48  // 0: print nothing during solves, only when initializing
49  // 1: print number of iterations and final norm
50  // 2: also print norm each iteration
51  // 3: also print timings of different backend functions
52 
53  int verbosity = 0;
54 
55  int maxit = 200;
56  double tolerance = 1e-2;
57 
58  std::string bitstream = "";
59 
60  int N; // number of rows
61  int Nb; // number of blocked rows (Nb*block_size == N)
62  int nnz; // number of nonzeroes (scalars)
63  int nnzb; // number of nonzero blocks (nnzb*block_size*block_size == nnz)
64 
65  unsigned int platformID = 0; // ID of OpenCL platform to be used, only used by openclSolver now
66  unsigned int deviceID = 0; // ID of the device to be used
67 
68  bool initialized = false;
69 
70  public:
78  BdaSolver(int linear_solver_verbosity, int max_it, double tolerance_, unsigned int deviceID_) : verbosity(linear_solver_verbosity), maxit(max_it), tolerance(tolerance_), deviceID(deviceID_) {};
79  BdaSolver(int linear_solver_verbosity, int max_it, double tolerance_, unsigned int platformID_, unsigned int deviceID_) : verbosity(linear_solver_verbosity), maxit(max_it), tolerance(tolerance_), platformID(platformID_), deviceID(deviceID_) {};
80  BdaSolver(std::string fpga_bitstream, int linear_solver_verbosity, int max_it, double tolerance_) : verbosity(linear_solver_verbosity), maxit(max_it), tolerance(tolerance_), bitstream(fpga_bitstream) {};
81 
83  virtual ~BdaSolver() {};
84 
86  virtual SolverStatus solve_system(int N, int nnz, int dim,
87  double *vals, int *rows, int *cols,
88  double *b, WellContributions& wellContribs, BdaResult &res) = 0;
89 
90  virtual void get_result(double *x) = 0;
91 
92  }; // end class BdaSolver
93 
94 } // end namespace bda
95 
96 #endif
This class serves to eliminate the need to include the WellContributions into the matrix (with –matri...
Definition: WellContributions.hpp:61
This class is based on InverseOperatorResult struct from dune/istl/solver.hh It is needed to prevent ...
Definition: BdaResult.hpp:29
This class serves to simplify choosing between different backend solvers, such as cusparseSolver and ...
Definition: BdaSolver.hpp:43
BdaSolver(int linear_solver_verbosity, int max_it, double tolerance_, unsigned int deviceID_)
Construct a BdaSolver, can be cusparseSolver, openclSolver, fpgaSolver.
Definition: BdaSolver.hpp:78
virtual SolverStatus solve_system(int N, int nnz, int dim, double *vals, int *rows, int *cols, double *b, WellContributions &wellContribs, BdaResult &res)=0
Define as pure virtual functions, so derivedclass must implement them.
virtual ~BdaSolver()
Define virtual destructor, so that the derivedclass destructor will be called.
Definition: BdaSolver.hpp:83