SolverInfo.hpp 3.83 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
19
20
     *   NAME->absolute tolerance   \ref aTol_
     *   NAME->relative tolerance   \ref rTol_
     *   NAME->info                 \ref info_
     *   NAME->break if tolerance not reached \ref breakTolNotReached_
21
    **/
Praetorius, Simon's avatar
Praetorius, Simon committed
22
23
    explicit SolverInfo(std::string const& prefix)
      : prefix_(prefix)
24
    {
25
      Parameters::get(prefix + "->absolute tolerance", aTol_);
Praetorius, Simon's avatar
Praetorius, Simon committed
26
27
28
      Parameters::get(prefix + "->relative tolerance", rTol_);
      Parameters::get(prefix + "->info", info_);
      Parameters::get(prefix + "->break if tolerance not reached", breakTolNotReached_);
29
30
31
32
33
34
    }

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

Praetorius, Simon's avatar
Praetorius, Simon committed
35
36
    /// Returns \ref aTol_
    double absTolerance() const
37
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
38
      return aTol_;
39
40
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
41
42
    /// Returns \ref rTol_
    double relTolerance() const
43
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
44
      return rTol_;
45
46
47
    }

    /// Returns error code in last run of an iterative solver
Praetorius, Simon's avatar
Praetorius, Simon committed
48
    int errorCode() const
49
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
50
      return error_;
51
52
53
    }

    /// Returns info
Praetorius, Simon's avatar
Praetorius, Simon committed
54
    int info() const
55
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
56
      return info_;
57
58
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
59
60
    /// Returns \ref absResidual_
    double absResidual() const
61
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
62
      return absResidual_;
63
64
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
65
66
    /// Returns \ref relResidual_
    double relResidual() const
67
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
68
      return relResidual_;
69
    }
70

Praetorius, Simon's avatar
Praetorius, Simon committed
71
72
    /// Returns the initfile \ref prefix_
    std::string const& prefix() const
73
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
74
      return prefix_;
75
76
77
78
79
    }

    /// Returns \ref createMatrixData
    bool doCreateMatrixData() const
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
80
      return createMatrixData_;
81
82
83
84
85
    }

    /// Returns \ref storeMatrixData
    bool doStoreMatrixData() const
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
86
      return storeMatrixData_;
87
    }
88

89
90
    bool doBreak() const
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
91
92
93
      return breakTolNotReached_ && (
          (aTol_ > 1.e-30 && absResidual_ > aTol_) ||
          (rTol_ > 1.e-30 && relResidual_ > rTol_) );
94
95
96
97
98
99
100
101
102
    }

    /** \} */


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

Praetorius, Simon's avatar
Praetorius, Simon committed
103
    /// Sets \ref aTol_
104
105
    void setAbsTolerance(double tol)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
106
      aTol_ = tol;
107
108
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
109
    /// Sets \ref rTol_
110
111
    void setRelTolerance(double tol)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
112
      rTol_ = tol;
113
114
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
115
    /// Sets \ref aTol_
116
117
    void setAbsResidual(double r)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
118
      absResidual_ = r;
119
120
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
121
    /// Sets \ref rTol_
122
123
    void setRelResidual(double r)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
124
      relResidual_ = r;
125
126
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
127
    /// Sets \ref info_
128
129
    void setInfo(int i)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
130
      info_ = i;
131
132
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
133
    /// Sets \ref error_
134
135
    void setError(int e)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
136
      error_ = e;
137
138
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
139
    /// Sets \ref createMatrixData_
140
141
    void setCreateMatrixData(bool b)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
142
      createMatrixData_ = b;
143
144
    }

Praetorius, Simon's avatar
Praetorius, Simon committed
145
    /// Sets \ref storeMatrixData_
146
147
    void setStoreMatrixData(bool b)
    {
Praetorius, Simon's avatar
Praetorius, Simon committed
148
      storeMatrixData_ = b;
149
150
151
    }

    /** \} */
152

153
154
  private:
    /// The initfile prefix to read parameters
Praetorius, Simon's avatar
Praetorius, Simon committed
155
    std::string prefix_;
156

157
    /// The abolute tolerance
Praetorius, Simon's avatar
Praetorius, Simon committed
158
    double aTol_ = 0;
159

160
    /// The relative tolerance
Praetorius, Simon's avatar
Praetorius, Simon committed
161
    double rTol_ = 1.e-6;
162

163
    /// Throw an error if tolerance could not be reached
Praetorius, Simon's avatar
Praetorius, Simon committed
164
    bool breakTolNotReached_ = false;
165

166
    /// The solver verbosity level
Praetorius, Simon's avatar
Praetorius, Simon committed
167
    int info_ = 0;
168

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

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

175
    /// The error-code, default (-1): not set
Praetorius, Simon's avatar
Praetorius, Simon committed
176
    int error_ = -1;
177
178
179

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

183
    /// If false, the exit() method of the runner will be called.
Praetorius, Simon's avatar
Praetorius, Simon committed
184
    bool storeMatrixData_ = false;
185
186
187
  };

} // end namespace AMDiS