openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
SF_abstract_lin_solver.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // openCARP is an open cardiac electrophysiology simulator.
3 //
4 // Copyright (C) 2020 openCARP project
5 //
6 // This program is licensed under the openCARP Academic Public License (APL)
7 // v1.0: You can use and redistribute it and/or modify it in non-commercial
8 // academic environments under the terms of APL as published by the openCARP
9 // project v1.0, or (at your option) any later version. Commercial use requires
10 // a commercial license (info@opencarp.org).
11 //
12 // This program is distributed without any warranty; see the openCARP APL for
13 // more details.
14 //
15 // You should have received a copy of the openCARP APL along with this program
16 // and can find it online: http://www.opencarp.org/license
17 // ----------------------------------------------------------------------------
18 
19 #ifndef _SF_ABSTRACT_LIN_SOLVER_H
20 #define _SF_ABSTRACT_LIN_SOLVER_H
21 
22 #include "SF_abstract_matrix.h"
23 #include "SF_abstract_vector.h"
24 
25 namespace SF {
26 
39 template<class T, class S>
41 {
42  std::string name;
43  const char* options_file;
44 
48 
49  // solver statistics
50  double final_residual = -1.0;
51  int niter = -1;
52  int max_it = 0;
53  int reason = 0;
54  double time = 0.0;
55 
62  virtual void operator() (abstract_vector<T,S> & x, const abstract_vector<T,S> & b) = 0;
63 
65  virtual ~abstract_linear_solver() = default;
66 
78  virtual void setup_solver(abstract_matrix<T, S>& mat, double tol, int max_it,
79  short norm, std::string name, bool has_nullspace,
80  void* logger, // TODO: maybe solver logging needs to be revisited
81  const char* solver_opts_file,
82  const char* default_opts) = 0;
83 
84  protected:
94  virtual void set_stopping_criterion(norm_t normtype, double tol, int max_it,
95  bool verbose, void* logger) = 0;
96 
104  norm_t convert_param_norm_type(short param_norm_type) const
105  {
106  norm_t normtype = absPreResidual;
107 
108  switch (param_norm_type) {
109  default:
110  case 0: normtype = absPreResidual; break;
111  case 1: normtype = absUnpreResidual; break;
112  case 2: normtype = relResidual; break;
113  case 3: normtype = absPreRelResidual; break;
114  }
115 
116  return normtype;
117  }
118 };
119 
120 } // namespace SF
121 
122 
123 #endif // _SF_ABSTRACT_LIN_SOLVER_H
Definition: dense_mat.hpp:34
virtual void set_stopping_criterion(norm_t normtype, double tol, int max_it, bool verbose, void *logger)=0
norm_t convert_param_norm_type(short param_norm_type) const
int reason
number of iterations
std::string name
the solver name
virtual void setup_solver(abstract_matrix< T, S > &mat, double tol, int max_it, short norm, std::string name, bool has_nullspace, void *logger, const char *solver_opts_file, const char *default_opts)=0
int max_it
max number of iterations
virtual void operator()(abstract_vector< T, S > &x, const abstract_vector< T, S > &b)=0
double final_residual
Holds the residual after convergence.
virtual ~abstract_linear_solver()=default
int niter
number of iterations
const char * options_file
the file containing the solver options