openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
SF_abstract_lin_solver.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) NumeriCor GmbH
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #ifndef _SF_ABSTRACT_LIN_SOLVER_H
5 #define _SF_ABSTRACT_LIN_SOLVER_H
6 
7 #include "SF_abstract_matrix.h"
8 #include "SF_abstract_vector.h"
9 
10 namespace SF {
11 
24 template<class T, class S>
26 {
27  std::string name;
28  const char* options_file;
29 
33 
34  // solver statistics
36  SF_real time = 0.0;
37  SF_int niter = -1;
38  SF_int max_it = 0;
39  SF_int reason = 0;
40 
42  virtual const char* reason_str() const = 0;
43 
50  virtual void operator() (abstract_vector<T,S> & x, const abstract_vector<T,S> & b) = 0;
51 
53  virtual ~abstract_linear_solver() = default;
54 
66  virtual void setup_solver(abstract_matrix<T, S>& mat, double tol, int max_it,
67  short norm, std::string name, bool has_nullspace,
68  void* logger, // TODO: maybe solver logging needs to be revisited
69  const char* solver_opts_file,
70  const char* default_opts) = 0;
71 
72  protected:
82  virtual void set_stopping_criterion(norm_t normtype, double tol, int max_it,
83  bool verbose, void* logger) = 0;
84 
92  norm_t convert_param_norm_type(short param_norm_type) const
93  {
94  norm_t normtype = absPreResidual;
95 
96  switch (param_norm_type) {
97  default:
98  case 0: normtype = absPreResidual; break;
99  case 1: normtype = absUnpreResidual; break;
100  case 2: normtype = relResidual; break;
101  case 3: normtype = absPreRelResidual; break;
102  }
103 
104  return normtype;
105  }
106 };
107 
108 } // namespace SF
109 
110 
111 #endif // _SF_ABSTRACT_LIN_SOLVER_H
opencarp::real_t SF_real
Global scalar type.
Definition: SF_globals.h:18
opencarp::global_index_t SF_int
Global algebraic index type.
Definition: SF_globals.h:17
Definition: dense_mat.hpp:19
SF_int max_it
max number of iterations
norm_t convert_param_norm_type(short param_norm_type) const
SF_int niter
number of iterations
SF_real final_residual
Holds the residual after convergence.
virtual void set_stopping_criterion(norm_t normtype, double tol, int max_it, bool verbose, void *logger)=0
const char * options_file
the file containing the solver options
virtual ~abstract_linear_solver()=default
SF_int reason
convergence reason, > 0 converged, < 0 failed to converge, 0 not yet solved; codes are backend specif...
virtual const char * reason_str() const =0
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
virtual void operator()(abstract_vector< T, S > &x, const abstract_vector< T, S > &b)=0