SolverInfo.hpp 2.94 KB
Newer Older
1
2
3
4
#pragma once

#include <string>

5
#include <amdis/Initfile.hpp>
6

7
8
namespace AMDiS
{
9
  /// Class that stores information about the solution process, like tolerances
10
11
12
13
14
15
16
  /// and iteration counts and is passed to the solver and filled there.
  class SolverInfo
  {
  public:
    /// The constructor reads needed parameters and sets solver \p prefix.
    /**
     * Reads parameters for a solver with name 'NAME':
Praetorius, Simon's avatar
Praetorius, Simon committed
17
18
     *   NAME->info                 \ref info_
     *   NAME->break if tolerance not reached \ref breakTolNotReached_
19
    **/
Praetorius, Simon's avatar
Praetorius, Simon committed
20
21
    explicit SolverInfo(std::string const& prefix)
      : prefix_(prefix)
22
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
23
24
      Parameters::get(prefix + "->info", info_);
      Parameters::get(prefix + "->break if tolerance not reached", breakTolNotReached_);
25
26
27
28
29
30
31
    }

    /** \name getting methods
     * \{
     */

    /// Returns error code in last run of an iterative solver
32
    int error() const
33
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
34
      return error_;
35
36
37
    }

    /// Returns info
Praetorius, Simon's avatar
Praetorius, Simon committed
38
    int info() const
39
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
40
      return info_;
41
42
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
43
44
    /// Returns \ref absResidual_
    double absResidual() const
45
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
46
      return absResidual_;
47
48
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
49
50
    /// Returns \ref relResidual_
    double relResidual() const
51
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
52
      return relResidual_;
53
    }
54

55
56
57
    /// Returns \ref createMatrixData
    bool doCreateMatrixData() const
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
58
      return createMatrixData_;
59
60
61
62
63
    }

    /// Returns \ref storeMatrixData
    bool doStoreMatrixData() const
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
64
      return storeMatrixData_;
65
    }
66

67
68
    bool doBreak() const
    {
69
      return breakTolNotReached_;
70
71
72
73
74
75
76
77
78
    }

    /** \} */


    /** \name setting methods
     * \{
     */

79
    /// Sets \ref absResidual_
80
81
    void setAbsResidual(double r)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
82
      absResidual_ = r;
83
84
    }

85
    /// Sets \ref relResidual_
86
87
    void setRelResidual(double r)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
88
      relResidual_ = r;
89
90
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
91
    /// Sets \ref info_
92
93
    void setInfo(int i)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
94
      info_ = i;
95
96
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
97
    /// Sets \ref error_
98
99
    void setError(int e)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
100
      error_ = e;
101
102
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
103
    /// Sets \ref createMatrixData_
104
105
    void setCreateMatrixData(bool b)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
106
      createMatrixData_ = b;
107
108
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
109
    /// Sets \ref storeMatrixData_
110
111
    void setStoreMatrixData(bool b)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
112
      storeMatrixData_ = b;
113
114
115
    }

    /** \} */
116

117
118
  private:
    /// The initfile prefix to read parameters
Praetorius, Simon's avatar
Praetorius, Simon committed
119
    std::string prefix_;
120

121
    /// Throw an error if tolerance could not be reached
Praetorius, Simon's avatar
Praetorius, Simon committed
122
    bool breakTolNotReached_ = false;
123

124
    /// The solver verbosity level
Praetorius, Simon's avatar
Praetorius, Simon committed
125
    int info_ = 0;
126

127
    /// The absolute residual, default (-1): not set
Praetorius, Simon's avatar
Praetorius, Simon committed
128
    double absResidual_ = -1.0;
129

130
    /// The relative residual, relative to the two_norm(b), default (-1): not set
Praetorius, Simon's avatar
Praetorius, Simon committed
131
    double relResidual_ = -1.0;
132

133
    /// The error-code, default (-1): not set
Praetorius, Simon's avatar
Praetorius, Simon committed
134
    int error_ = -1;
135
136
137

    /// If true, the matrix will be initialized and the
    /// corresponding runner of the system receives the
138
    /// matrix in the init() method.
Praetorius, Simon's avatar
Praetorius, Simon committed
139
    bool createMatrixData_ = true;
140

141
    /// If false, the exit() method of the runner will be called.
Praetorius, Simon's avatar
Praetorius, Simon committed
142
    bool storeMatrixData_ = false;
143
144
145
  };

} // end namespace AMDiS