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 //das nur für snes
26 #include "petscsnes.h"
27 
28 namespace SF {
29 
42 template<class T, class S>
44 {
45  std::string name;
46  const char* options_file;
47 
51 
52  // solver statistics
53  double final_residual = -1.0;
54  int niter = -1;
55  int max_it = 0;
56  int reason = 0;
57  double time = 0.0;
58 
65  virtual void operator() (abstract_vector<T,S> & x, const abstract_vector<T,S> & b) = 0;
66 
68  virtual ~abstract_linear_solver() = default;
69 
81  virtual void setup_solver(abstract_matrix<T, S>& mat, double tol, int max_it,
82  short norm, std::string name, bool has_nullspace,
83  void* logger, // TODO: maybe solver logging needs to be revisited
84  const char* solver_opts_file,
85  const char* default_opts) = 0;
86 
87  protected:
97  virtual void set_stopping_criterion(norm_t normtype, double tol, int max_it,
98  bool verbose, void* logger) = 0;
99 
107  norm_t convert_param_norm_type(short param_norm_type) const
108  {
109  norm_t normtype = absPreResidual;
110 
111  switch (param_norm_type) {
112  default:
113  case 0: normtype = absPreResidual; break;
114  case 1: normtype = absUnpreResidual; break;
115  case 2: normtype = relResidual; break;
116  case 3: normtype = absPreRelResidual; break;
117  }
118 
119  return normtype;
120  }
121 };
122 
135 template<class T, class S>
136 
139 {
140  const char* name;
141  const char* options_file;
142 
146 
147  // solver statistics
148  double final_residual = -1.0;
149  int niter = -1;
150  int max_it = 0;
151  int reason = 0;
152  double time = 0.0;
153 
160  virtual void operator() (abstract_vector<T,S> & x, const abstract_vector<T,S> & b) = 0;
161 
163  virtual ~abstract_nonlinear_solver() = default;
164 
180 // virtual void setup_solver(abstract_matrix<T, S>& mat, double tol, int max_it,
181 // short norm, const char* name, bool has_nullspace,
182 // void* logger, // TODO: maybe solver logging needs to be revisited
183 // const char* solver_opts_file,
184 // const char* default_opts) = 0;
185  virtual void setup_solver(abstract_vector<T, S> &residuum, abstract_matrix<T, S>& mat, double tol, int max_it, short norm, const char* name, bool has_nullspace, void* logger, const char *solver_opts_file, const char* default_opts, PetscErrorCode function(SNES, Vec, Vec, void*), PetscErrorCode jacobian(SNES, Vec, Mat, Mat, void*), void * solver_pointer = NULL) = 0;
186 
187  protected:
197  virtual void set_stopping_criterion(norm_t normtype, double tol, int max_it,
198  bool verbose, void* logger) = 0;
199 
207  norm_t convert_param_norm_type(short param_norm_type) const
208  {
209  norm_t normtype = absPreResidual;
210 
211  switch (param_norm_type) {
212  default:
213  case 0: normtype = absPreResidual; break;
214  case 1: normtype = absUnpreResidual; break;
215  case 2: normtype = relResidual; break;
216  case 3: normtype = absPreRelResidual; break;
217  }
218 
219  return normtype;
220  }
221 };
222 
223 } // namespace SF
224 
225 
226 #endif // _SF_ABSTRACT_LIN_SOLVER_H
Definition: dense_mat.hpp:34
int reason
number of iterations
double final_residual
Holds the residual after convergence.
norm_t convert_param_norm_type(short param_norm_type) const
int niter
number of iterations
int max_it
max number of iterations
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
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
NOTE: A LOT OF THESE THINGS NEED TO BE CHANGED AT A LATER STAGE. THEY ARE CURRENTLY COPIED FROM THE A...
virtual void operator()(abstract_vector< T, S > &x, const abstract_vector< T, S > &b)=0
virtual ~abstract_nonlinear_solver()=default
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
double final_residual
Holds the residual after convergence.
virtual void setup_solver(abstract_vector< T, S > &residuum, abstract_matrix< T, S > &mat, double tol, int max_it, short norm, const char *name, bool has_nullspace, void *logger, const char *solver_opts_file, const char *default_opts, PetscErrorCode function(SNES, Vec, Vec, void *), PetscErrorCode jacobian(SNES, Vec, Mat, Mat, void *), void *solver_pointer=NULL)=0
int max_it
max number of iterations
const char * options_file
the file containing the solver options
const char * name
the solver name