Belos Version of the Day
Loading...
Searching...
No Matches
BelosSolverManager.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Belos: Block Linear Solvers Package
4//
5// Copyright 2004-2016 NTESS and the Belos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef BELOS_SOLVERMANAGER_HPP
11#define BELOS_SOLVERMANAGER_HPP
12
17#include "BelosConfigDefs.hpp"
18#include "BelosTypes.hpp"
21
22#include "Teuchos_ParameterList.hpp"
23#include "Teuchos_RCP.hpp"
24#include "Teuchos_Describable.hpp"
25
31namespace Belos {
32
33
34template <class ScalarType, class MV, class OP>
35class StatusTest;
36
37
38template<class ScalarType, class MV, class OP>
39class SolverManager : virtual public Teuchos::Describable {
40
41 public:
42
44
45
48
50 virtual ~SolverManager() {};
51
55 virtual Teuchos::RCP<SolverManager<ScalarType, MV, OP> > clone () const = 0;
57
59
60
62 virtual const LinearProblem<ScalarType,MV,OP>& getProblem() const = 0;
63
65 virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const = 0;
66
68 virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const = 0;
69
81 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType achievedTol() const {
82 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "achievedTol() not implemented");
83 }
84
86 virtual int getNumIters() const = 0;
87
91 virtual bool isLOADetected() const = 0;
92
94
96
97
99 virtual void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) = 0;
100
111 virtual void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) = 0;
112
115 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &/* userConvStatusTest */,
116 const typename StatusTestCombo<ScalarType,MV,OP>::ComboType &/* comboType */ =
118 )
119 {
120 TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error, the function setUserConvStatusTest() has not been"
121 << " overridden for the class" << this->description() << " yet!");
122 }
123
125 virtual void setDebugStatusTest(
126 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &/* debugStatusTest */
127 )
128 {
129 TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error, the function setDebugStatusTest() has not been"
130 << " overridden for the class" << this->description() << " yet!");
131 }
132
134
136
137
144 virtual void reset( const ResetType type ) = 0;
146
148
149
151 //
162 virtual ReturnType solve() = 0;
164};
165
166
167namespace Details {
168
186 template<class ScalarType,
187 class MV,
188 class OP,
189 const bool isComplex = Teuchos::ScalarTraits<ScalarType>::isComplex>
191
192 // Specialization for isComplex = true adds nothing to SolverManager.
193 template<class ScalarType, class MV, class OP>
195 public SolverManager<ScalarType, MV, OP> {
196 public:
198 virtual ~RealSolverManager () {}
199 };
200
201 // Specialization for isComplex = true (ScalarType is complex) adds
202 // a constructor that always throws std::logic_error. Subclasses
203 // must always call the base class constructor.
204 //
205 // The complex version (isComplex = true) needs to implement all the
206 // pure virtual methods in SolverManager, even though they can never
207 // actually be called, since the constructor throws.
208 template<class ScalarType, class MV, class OP>
210 public SolverManager<ScalarType, MV, OP> {
211 public:
213 // Do not throw on constructor. The DII system registers all class types
214 // and must construct even if the class will not be usable.
215 }
216 virtual ~RealSolverManager () {}
217
219 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
220 "This solver is not implemented for complex ScalarType." );
221 }
222 virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
223 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
224 "This solver is not implemented for complex ScalarType." );
225 }
226 virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
227 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
228 "This solver is not implemented for complex ScalarType." );
229 }
230 virtual int getNumIters() const {
231 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
232 "This solver is not implemented for complex ScalarType." );
233 }
234 virtual bool isLOADetected() const {
235 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
236 "This solver is not implemented for complex ScalarType." );
237 }
238 virtual void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem) {
239 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
240 "This solver is not implemented for complex ScalarType." );
241 }
242 virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
243 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
244 "This solver is not implemented for complex ScalarType." );
245 }
246 virtual void reset (const ResetType type) {
247 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
248 "This solver is not implemented for complex ScalarType." );
249 }
250 virtual ReturnType solve () {
251 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
252 "This solver is not implemented for complex ScalarType." );
253 }
254 };
255
256
260 template<class ScalarType>
262 public:
263 const static bool value = false;
264 };
265
266 template<>
268 public:
269 const static bool value = true;
270 };
271
272 template<>
274 public:
275 const static bool value = true;
276 };
277
278#ifdef HAVE_TEUCHOS_LONG_DOUBLE
279 template<>
281 public:
282 const static bool value = true;
283 };
284#endif
285
286
287#ifdef HAVE_TEUCHOS_COMPLEX
288 template<>
289 class LapackSupportsScalar<std::complex<float> > {
290 public:
291 const static bool value = true;
292 };
293
294 template<>
295 class LapackSupportsScalar<std::complex<double> > {
296 public:
297 const static bool value = true;
298 };
299#endif // HAVE_TEUCHOS_COMPLEX
300
305 template<class ScalarType,
306 class MV,
307 class OP,
308 const bool lapackSupportsScalarType =
311
316 template<class ScalarType, class MV, class OP>
318 public SolverManager<ScalarType, MV, OP> {
319 public:
322 };
323
330 template<class ScalarType, class MV, class OP>
332 public SolverManager<ScalarType, MV, OP> {
333 public:
336 (true, std::logic_error, "This solver is not implemented for ScalarType"
337 " types for which Teuchos::LAPACK does not have a valid implementation. "
338 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
339 }
341
344 (true, std::logic_error, "This solver is not implemented for ScalarType"
345 " types for which Teuchos::LAPACK does not have a valid implementation. "
346 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
347 }
348 virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
350 (true, std::logic_error, "This solver is not implemented for ScalarType"
351 " types for which Teuchos::LAPACK does not have a valid implementation. "
352 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
353 }
354 virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
356 (true, std::logic_error, "This solver is not implemented for ScalarType"
357 " types for which Teuchos::LAPACK does not have a valid implementation. "
358 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
359 }
360 virtual int getNumIters() const {
362 (true, std::logic_error, "This solver is not implemented for ScalarType"
363 " types for which Teuchos::LAPACK does not have a valid implementation. "
364 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
365 }
366 virtual bool isLOADetected() const {
368 (true, std::logic_error, "This solver is not implemented for ScalarType"
369 " types for which Teuchos::LAPACK does not have a valid implementation. "
370 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
371 }
372 virtual void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem) {
374 (true, std::logic_error, "This solver is not implemented for ScalarType"
375 " types for which Teuchos::LAPACK does not have a valid implementation. "
376 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
377 }
378 virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
380 (true, std::logic_error, "This solver is not implemented for ScalarType"
381 " types for which Teuchos::LAPACK does not have a valid implementation. "
382 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
383 }
384 virtual void reset (const ResetType type) {
386 (true, std::logic_error, "This solver is not implemented for ScalarType"
387 " types for which Teuchos::LAPACK does not have a valid implementation. "
388 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
389 }
390 virtual ReturnType solve () {
392 (true, std::logic_error, "This solver is not implemented for ScalarType"
393 " types for which Teuchos::LAPACK does not have a valid implementation. "
394 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
395 }
396 };
397
402 template<class ScalarType,
403 class MV,
404 class OP,
405 const bool supportsScalarType =
407 ! Teuchos::ScalarTraits<ScalarType>::isComplex>
409
417 template<class ScalarType, class MV, class OP>
419 public SolverManager<ScalarType, MV, OP> {
420 public:
423 };
424
432 template<class ScalarType, class MV, class OP>
434 public SolverManager<ScalarType, MV, OP> {
435 public:
437 // Do not throw on constructor. The DII system registers all class types
438 // and must construct even if the class will not be usable.
439 }
441
444 (true, std::logic_error, "This solver is not implemented for complex "
445 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
446 "does not have a valid implementation."
447 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
448 }
449 virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
451 (true, std::logic_error, "This solver is not implemented for complex "
452 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
453 "does not have a valid implementation."
454 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
455 }
456 virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
458 (true, std::logic_error, "This solver is not implemented for complex "
459 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
460 "does not have a valid implementation."
461 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
462 }
463 virtual int getNumIters() const {
465 (true, std::logic_error, "This solver is not implemented for complex "
466 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
467 "does not have a valid implementation."
468 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
469 }
470 virtual bool isLOADetected() const {
472 (true, std::logic_error, "This solver is not implemented for complex "
473 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
474 "does not have a valid implementation."
475 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
476 }
477 virtual void
478 setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> >& /* problem */) {
480 (true, std::logic_error, "This solver is not implemented for complex "
481 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
482 "does not have a valid implementation."
483 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
484 }
485 virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
487 (true, std::logic_error, "This solver is not implemented for complex "
488 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
489 "does not have a valid implementation."
490 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
491 }
492 virtual void reset (const ResetType type) {
494 (true, std::logic_error, "This solver is not implemented for complex "
495 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
496 "does not have a valid implementation."
497 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
498 }
499 virtual ReturnType solve () {
501 (true, std::logic_error, "This solver is not implemented for complex "
502 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
503 "does not have a valid implementation."
504 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
505 }
506 };
507
508} // namespace Details
509} // namespace Belos
510
511#endif /* BELOS_SOLVERMANAGER_HPP */
Belos header file which uses auto-configuration information to include necessary C++ headers.
Class which describes the linear problem to be solved by the iterative solver.
Belos::StatusTest for logically combining several status tests.
Collection of types and exceptions used within the Belos solvers.
Type traits class that says whether Teuchos::LAPACK has a valid implementation for the given ScalarTy...
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return the valid parameters for this solver manager.
virtual const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
virtual Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Return the current parameters being used for this solver manager.
virtual void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set the parameters to use when solving the linear problem.
virtual void reset(const ResetType type)
Reset the solver manager.
virtual ReturnType solve()
Iterate until the status test tells us to stop.
virtual int getNumIters() const
Get the iteration count for the most recent call to solve().
virtual void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
virtual bool isLOADetected() const
Returns whether a loss of accuracy was detected in the solver.
Base class for Belos::SolverManager subclasses which normally can only compile for real ScalarType.
virtual const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return the valid parameters for this solver manager.
virtual void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
virtual ReturnType solve()
Iterate until the status test tells us to stop.
virtual void reset(const ResetType type)
Reset the solver manager.
virtual bool isLOADetected() const
Returns whether a loss of accuracy was detected in the solver.
virtual int getNumIters() const
Get the iteration count for the most recent call to solve().
virtual void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set the parameters to use when solving the linear problem.
virtual Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Return the current parameters being used for this solver manager.
Base class for Belos::SolverManager subclasses which normally can only compile with ScalarType types ...
virtual int getNumIters() const
Get the iteration count for the most recent call to solve().
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return the valid parameters for this solver manager.
virtual void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set the parameters to use when solving the linear problem.
virtual bool isLOADetected() const
Returns whether a loss of accuracy was detected in the solver.
virtual const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
virtual void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &)
Set the linear problem that needs to be solved.
virtual ReturnType solve()
Iterate until the status test tells us to stop.
virtual void reset(const ResetType type)
Reset the solver manager.
virtual Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Return the current parameters being used for this solver manager.
Base class for Belos::SolverManager subclasses which normally can only compile with real ScalarType t...
Alternative run-time polymorphic interface for operators.
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
virtual void setUserConvStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &, const typename StatusTestCombo< ScalarType, MV, OP >::ComboType &=StatusTestCombo< ScalarType, MV, OP >::SEQ)
Set user-defined convergence status test.
virtual ReturnType solve()=0
Iterate until the status test tells us to stop.
virtual Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const =0
Return the current parameters being used for this solver manager.
virtual void reset(const ResetType type)=0
Reset the solver manager.
SolverManager()
Empty constructor.
virtual int getNumIters() const =0
Get the iteration count for the most recent call to solve().
virtual void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params)=0
Set the parameters to use when solving the linear problem.
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const =0
Return the valid parameters for this solver manager.
virtual void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)=0
Set the linear problem that needs to be solved.
virtual Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const =0
clone the solver manager.
virtual bool isLOADetected() const =0
Returns whether a loss of accuracy was detected in the solver.
virtual ~SolverManager()
Destructor.
virtual const LinearProblem< ScalarType, MV, OP > & getProblem() const =0
Return a reference to the linear problem being solved by this solver manager.
virtual Teuchos::ScalarTraits< ScalarType >::magnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
virtual void setDebugStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &)
Set user-defined debug status test.
A class for extending the status testing capabilities of Belos via logical combinations.
ComboType
The test can be either the AND of all the component tests, or the OR of all the component tests,...
ReturnType
Whether the Belos solve converged for all linear systems.
ResetType
How to reset the solver.

Generated for Belos by doxygen 1.9.8