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
167
168namespace Details {
169
187 template<class ScalarType,
188 class MV,
189 class OP,
190 const bool isComplex = Teuchos::ScalarTraits<ScalarType>::isComplex>
192
193 // Specialization for isComplex = true adds nothing to SolverManager.
194 template<class ScalarType, class MV, class OP>
196 public SolverManager<ScalarType, MV, OP> {
197 public:
199 virtual ~RealSolverManager () {}
200 };
201
202 // Specialization for isComplex = true (ScalarType is complex) adds
203 // a constructor that always throws std::logic_error. Subclasses
204 // must always call the base class constructor.
205 //
206 // The complex version (isComplex = true) needs to implement all the
207 // pure virtual methods in SolverManager, even though they can never
208 // actually be called, since the constructor throws.
209 template<class ScalarType, class MV, class OP>
211 public SolverManager<ScalarType, MV, OP> {
212 public:
214 // Do not throw on constructor. The DII system registers all class types
215 // and must construct even if the class will not be usable.
216 }
217 virtual ~RealSolverManager () {}
218
220 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
221 "This solver is not implemented for complex ScalarType." );
222 }
223 virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
224 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
225 "This solver is not implemented for complex ScalarType." );
226 }
227 virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
228 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
229 "This solver is not implemented for complex ScalarType." );
230 }
231 virtual int getNumIters() const {
232 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
233 "This solver is not implemented for complex ScalarType." );
234 }
235 virtual bool isLOADetected() const {
236 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
237 "This solver is not implemented for complex ScalarType." );
238 }
239 virtual void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem) {
240 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
241 "This solver is not implemented for complex ScalarType." );
242 }
243 virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
244 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
245 "This solver is not implemented for complex ScalarType." );
246 }
247 virtual void reset (const ResetType type) {
248 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
249 "This solver is not implemented for complex ScalarType." );
250 }
251 virtual ReturnType solve () {
252 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
253 "This solver is not implemented for complex ScalarType." );
254 }
255 };
256
257
261 template<class ScalarType>
263 public:
264 const static bool value = false;
265 };
266
267 template<>
269 public:
270 const static bool value = true;
271 };
272
273 template<>
275 public:
276 const static bool value = true;
277 };
278
279#ifdef HAVE_TEUCHOS_LONG_DOUBLE
280 template<>
282 public:
283 const static bool value = true;
284 };
285#endif
286
287
288#ifdef HAVE_TEUCHOS_COMPLEX
289 template<>
290 class LapackSupportsScalar<std::complex<float> > {
291 public:
292 const static bool value = true;
293 };
294
295 template<>
296 class LapackSupportsScalar<std::complex<double> > {
297 public:
298 const static bool value = true;
299 };
300#endif // HAVE_TEUCHOS_COMPLEX
301
306 template<class ScalarType,
307 class MV,
308 class OP,
309 const bool lapackSupportsScalarType =
312
317 template<class ScalarType, class MV, class OP>
319 public SolverManager<ScalarType, MV, OP> {
320 public:
323 };
324
331 template<class ScalarType, class MV, class OP>
333 public SolverManager<ScalarType, MV, OP> {
334 public:
337 (true, std::logic_error, "This solver is not implemented for ScalarType"
338 " types for which Teuchos::LAPACK does not have a valid implementation. "
339 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
340 }
342
345 (true, std::logic_error, "This solver is not implemented for ScalarType"
346 " types for which Teuchos::LAPACK does not have a valid implementation. "
347 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
348 }
349 virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
351 (true, std::logic_error, "This solver is not implemented for ScalarType"
352 " types for which Teuchos::LAPACK does not have a valid implementation. "
353 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
354 }
355 virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
357 (true, std::logic_error, "This solver is not implemented for ScalarType"
358 " types for which Teuchos::LAPACK does not have a valid implementation. "
359 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
360 }
361 virtual int getNumIters() const {
363 (true, std::logic_error, "This solver is not implemented for ScalarType"
364 " types for which Teuchos::LAPACK does not have a valid implementation. "
365 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
366 }
367 virtual bool isLOADetected() const {
369 (true, std::logic_error, "This solver is not implemented for ScalarType"
370 " types for which Teuchos::LAPACK does not have a valid implementation. "
371 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
372 }
373 virtual void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem) {
375 (true, std::logic_error, "This solver is not implemented for ScalarType"
376 " types for which Teuchos::LAPACK does not have a valid implementation. "
377 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
378 }
379 virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
381 (true, std::logic_error, "This solver is not implemented for ScalarType"
382 " types for which Teuchos::LAPACK does not have a valid implementation. "
383 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
384 }
385 virtual void reset (const ResetType type) {
387 (true, std::logic_error, "This solver is not implemented for ScalarType"
388 " types for which Teuchos::LAPACK does not have a valid implementation. "
389 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
390 }
391 virtual ReturnType solve () {
393 (true, std::logic_error, "This solver is not implemented for ScalarType"
394 " types for which Teuchos::LAPACK does not have a valid implementation. "
395 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
396 }
397 };
398
403 template<class ScalarType,
404 class MV,
405 class OP,
406 const bool supportsScalarType =
408 ! Teuchos::ScalarTraits<ScalarType>::isComplex>
410
418 template<class ScalarType, class MV, class OP>
420 public SolverManager<ScalarType, MV, OP> {
421 public:
424 };
425
433 template<class ScalarType, class MV, class OP>
435 public SolverManager<ScalarType, MV, OP> {
436 public:
438 // Do not throw on constructor. The DII system registers all class types
439 // and must construct even if the class will not be usable.
440 }
442
445 (true, std::logic_error, "This solver is not implemented for complex "
446 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
447 "does not have a valid implementation."
448 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
449 }
450 virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
452 (true, std::logic_error, "This solver is not implemented for complex "
453 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
454 "does not have a valid implementation."
455 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
456 }
457 virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
459 (true, std::logic_error, "This solver is not implemented for complex "
460 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
461 "does not have a valid implementation."
462 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
463 }
464 virtual int getNumIters() const {
466 (true, std::logic_error, "This solver is not implemented for complex "
467 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
468 "does not have a valid implementation."
469 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
470 }
471 virtual bool isLOADetected() const {
473 (true, std::logic_error, "This solver is not implemented for complex "
474 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
475 "does not have a valid implementation."
476 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
477 }
478 virtual void
479 setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> >& /* problem */) {
481 (true, std::logic_error, "This solver is not implemented for complex "
482 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
483 "does not have a valid implementation."
484 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
485 }
486 virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
488 (true, std::logic_error, "This solver is not implemented for complex "
489 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
490 "does not have a valid implementation."
491 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
492 }
493 virtual void reset (const ResetType type) {
495 (true, std::logic_error, "This solver is not implemented for complex "
496 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
497 "does not have a valid implementation."
498 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
499 }
500 virtual ReturnType solve () {
502 (true, std::logic_error, "This solver is not implemented for complex "
503 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
504 "does not have a valid implementation."
505 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
506 }
507 };
508
509} // namespace Details
510} // namespace Belos
511
512#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