Class documentation of Concepts

Loading...
Searching...
No Matches
belosSolver.hh
Go to the documentation of this file.
1
8#ifndef BELOSSOLVER_HH_
9#define BELOSSOLVER_HH_
10
11#include "belosLinProb.hh"
12#include "sparseMatrix.hh"
13#include <BelosSolverManager.hpp>
14#include <BelosTpetraAdapter.hpp>
15#include <Ifpack2_Preconditioner.hpp>
16#include <Tpetra_DefaultPlatform.hpp>
17#include <Tpetra_MultiVector.hpp>
18#include <Teuchos_RCP.hpp>
19#include <Tpetra_CrsMatrix.hpp>
20
21namespace concepts {
22
23 // *********************************************************** BelosSolver **
24
31 template<class T>
32 class BelosSolver: public VecOperator<T> {
33 public:
34
35 //typenames for better reading
36 typedef Tpetra::MultiVector<T, int> MV;
37 typedef Tpetra::Operator<T> OP;
38 typedef Tpetra::CrsMatrix<T, int, int> CRSmat;
40 typedef Belos::SolverManager<T, MV, OP> solverManager;
41
44 Teuchos::RCP<const Teuchos::Comm<int> > comm);
45
47 BelosSolver(Teuchos::RCP<const Teuchos::Comm<int> > comm);
48 inline virtual ~BelosSolver() {
49 }
50 ;
51
53 inline virtual void operator()() {
54 apply_();
55 }
56 ;
57
62 inline virtual void operator()(const Vector<T>& fncY, Vector<T>& fncX) {
63 apply_(fncY, fncX);
64 }
65 ;
66
70 inline void setSolverParam(Teuchos::RCP<Teuchos::ParameterList> param) {
71 solverParam_ = param;
72 }
73 ;
74
80 inline void setSolverParam(int maxIter, int maxRestarts, double tol = 1e-10,
81 int blockSize = 1, int outFreq = 1) {
82 int verbosity = Belos::Warnings + Belos::Errors + Belos::FinalSummary;
83 solverParam_ = Teuchos::RCP<Teuchos::ParameterList>(
84 new Teuchos::ParameterList());
85 solverParam_->set("Verbosity", verbosity);
86 solverParam_->set("Block Size", blockSize);
87 solverParam_->set("Maximum Iterations", maxIter);
88// if (solverType_ != "minres")
89// solverParam_->set("Maximum Restarts", maxRestarts);
90 solverParam_->set("Convergence Tolerance", tol);
91 solverParam_->set("Output Frequency", outFreq);
92 solverParam_->set("Output Stream",
93 Teuchos::rcpFromRef<std::ostream>(std::cout));
94 }
95 ;
96
98 inline Teuchos::RCP<Teuchos::ParameterList> getSolverParam() {
99 return solverParam_;
100 }
101 ;
102
106 inline void setPrecParam(Teuchos::RCP<Teuchos::ParameterList> param) {
107 precParam_ = param;
108 }
109 ;
110
111 //TODO right expl. for fill??
116 inline void setPrecParam(double fill, double tol = 1e-5, int absTresh = 0,
117 int relTresh = 1, double relax = 0) {
118 precParam_ = Teuchos::RCP<Teuchos::ParameterList>(
119 new Teuchos::ParameterList("IFPACK2"));
120 precParam_->set("fact: level-of-fill", fill);
121 precParam_->set("fact: ilut level-of-fill", fill);
122 precParam_->set("fact: riluk level-of-fill", fill);
123 precParam_->set("fact: absolute threshold", absTresh);
124 precParam_->set("fact: relative threshold", relTresh);
125 precParam_->set("fact: relax value", relax);
126 precParam_->set("fact: drop tolerance", tol);
127 }
128 ;
129
131 inline Teuchos::RCP<Teuchos::ParameterList> getPrecParam() {
132 return precParam_;
133 }
134 ;
135
139 inline void setSolverManager(Teuchos::RCP<solverManager> manager) {
140 solverType_ = "";
141 solverManager_ = manager;
142 }
143 ;
144
148 inline Teuchos::RCP<solverManager> getSolverManager() {
149 return solverManager_;
150 }
151 ;
152
153 inline Teuchos::RCP<LP> getLinearProblem() {
154 return lp_;
155 }
156
163 inline void setSolverType(std::string type) {
164 solverType_ = type;
165 }
166 ;
167
169 inline std::string getSolverType() {
170 return solverType_;
171 }
172 ;
173
182 inline void setPrecType(std::string type) {
183 precType_ = type;
184 }
185 ;
186
187 //Getter for the preconditioner type
188 inline std::string getPrecType() {
189 return precType_;
190 }
191 ;
192
194 inline void prepare() {
195 //type and param should be setted
196 createPrec_();
197
198 //type and param should be setted
199 createSolver_();
200
201
202 //precond
203 phasePrecInit_((Comm_->getRank() == 0));
204
205 prepared_ = true;
206 }
207
208 protected:
209 virtual std::ostream& info(std::ostream& os) const;
210 private:
211
213 virtual void apply_(const Vector<T>& fncY, Vector<T>& fncX);
214
216 virtual void apply_();
217
219 bool createSolver_();
220
222 bool createPrec_();
223
225 bool phasePrecInit_(bool verbose = true);
226
228 bool phaseSolve_(bool verbose = true);
229
231 Teuchos::RCP<const Teuchos::Comm<int> > Comm_;
232
234 Teuchos::RCP<LP> lp_;
235
237 Teuchos::RCP<Teuchos::ParameterList> solverParam_;
238 Teuchos::RCP<Teuchos::ParameterList> precParam_;
239
241 Teuchos::RCP<solverManager> solverManager_;
242
244 Teuchos::RCP<Ifpack2::Preconditioner<T, int> > prec_;
245
246 //type of solver/preconditioner as string
247 std::string solverType_;
248 std::string precType_;
249
251 bool prepared_;
252 }
253 ;
254
255 //Constructors
256 template<class T>
258 Teuchos::RCP<const Teuchos::Comm<int> > Comm) :
259 VecOperator<T>(sparse.dimY(), sparse.dimX()) {
260 Comm_ = Comm;
261 prepared_ = false;
262 lp_ = Teuchos::RCP<LP>(new LP(sparse, Comm));
263 }
264 ;
265
266 template<class T>
267 BelosSolver<T>::BelosSolver(Teuchos::RCP<const Teuchos::Comm<int> > Comm) :
268 VecOperator<T>(1, 1) {
269 Comm_ = Comm;
270 prepared_ = false;
271 lp_ = Teuchos::RCP<LP>(new LP(Comm));
272 }
273 ;
274
275} /* namespace concepts */
276#endif /* BELOSSOLVER_HH_ */
Teuchos::RCP< Teuchos::ParameterList > getSolverParam()
Get solver parameter list.
void setPrecParam(double fill, double tol=1e-5, int absTresh=0, int relTresh=1, double relax=0)
void prepare()
Builds the Preconditioner and the solver (sets prepare to true)
Teuchos::RCP< Teuchos::ParameterList > getPrecParam()
Gets the parameter list for the preconditioner.
virtual void operator()()
Solving operator for other the non-root threads.
std::string getSolverType()
Getter for the solver type.
void setSolverParam(int maxIter, int maxRestarts, double tol=1e-10, int blockSize=1, int outFreq=1)
virtual void operator()(const Vector< T > &fncY, Vector< T > &fncX)
Teuchos::RCP< solverManager > getSolverManager()
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
void setSolverParam(Teuchos::RCP< Teuchos::ParameterList > param)
void setPrecType(std::string type)
void setPrecParam(Teuchos::RCP< Teuchos::ParameterList > param)
BelosSolver(concepts::SparseMatrix< T > &sparse, Teuchos::RCP< const Teuchos::Comm< int > > comm)
Constructor for the root thread.
void setSolverManager(Teuchos::RCP< solverManager > manager)
void setSolverType(std::string type)
F type
Type of data, e.g. matrix entries.
Set< F > makeSet(uint n, const F &first,...)
Definition set.hh:320