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
16
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
30
31namespace Belos {
32
33
34template <class ScalarType, class MV, class OP, class DM>
35class StatusTest;
36
37
38template<class ScalarType, class MV, class OP, class DM = DefaultDenseMatrix<int,ScalarType>>
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, DM> > clone () const = 0;
57
59
60
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,DM> > &problem ) = 0;
100
111 virtual void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) = 0;
112
115 const Teuchos::RCP<StatusTest<ScalarType,MV,OP,DM> > &/* userConvStatusTest */,
116 const typename StatusTestCombo<ScalarType,MV,OP,DM>::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,DM> > &/* 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,
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, class DM>
195 class RealSolverManager<ScalarType, MV, OP, DM, false> :
196 public SolverManager<ScalarType, MV, OP, DM> {
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, class DM>
210 class RealSolverManager<ScalarType, MV, OP, DM, true> :
211 public SolverManager<ScalarType, MV, OP, DM> {
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,DM> > &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<>
268 class LapackSupportsScalar<float> {
269 public:
270 const static bool value = true;
271 };
272
273 template<>
274 class LapackSupportsScalar<double> {
275 public:
276 const static bool value = true;
277 };
278
279#ifdef HAVE_TEUCHOS_LONG_DOUBLE
280 template<>
281 class LapackSupportsScalar<long double> {
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,
310 const bool lapackSupportsScalarType =
313
318 template<class ScalarType, class MV, class OP, class DM>
319 class SolverManagerRequiresLapack<ScalarType, MV, OP, DM, true> :
320 public SolverManager<ScalarType, MV, OP, DM> {
321 public:
324 };
325
332 template<class ScalarType, class MV, class OP, class DM>
333 class SolverManagerRequiresLapack<ScalarType, MV, OP, DM, false> :
334 public SolverManager<ScalarType, MV, OP, DM> {
335 public:
337 TEUCHOS_TEST_FOR_EXCEPTION
338 (true, std::logic_error, "This solver is not implemented for ScalarType"
339 " types for which Teuchos::LAPACK does not have a valid implementation. "
340 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
341 }
343
345 TEUCHOS_TEST_FOR_EXCEPTION
346 (true, std::logic_error, "This solver is not implemented for ScalarType"
347 " types for which Teuchos::LAPACK does not have a valid implementation. "
348 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
349 }
350 virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
351 TEUCHOS_TEST_FOR_EXCEPTION
352 (true, std::logic_error, "This solver is not implemented for ScalarType"
353 " types for which Teuchos::LAPACK does not have a valid implementation. "
354 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
355 }
356 virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
357 TEUCHOS_TEST_FOR_EXCEPTION
358 (true, std::logic_error, "This solver is not implemented for ScalarType"
359 " types for which Teuchos::LAPACK does not have a valid implementation. "
360 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
361 }
362 virtual int getNumIters() const {
363 TEUCHOS_TEST_FOR_EXCEPTION
364 (true, std::logic_error, "This solver is not implemented for ScalarType"
365 " types for which Teuchos::LAPACK does not have a valid implementation. "
366 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
367 }
368 virtual bool isLOADetected() const {
369 TEUCHOS_TEST_FOR_EXCEPTION
370 (true, std::logic_error, "This solver is not implemented for ScalarType"
371 " types for which Teuchos::LAPACK does not have a valid implementation. "
372 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
373 }
374 virtual void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> > &problem) {
375 TEUCHOS_TEST_FOR_EXCEPTION
376 (true, std::logic_error, "This solver is not implemented for ScalarType"
377 " types for which Teuchos::LAPACK does not have a valid implementation. "
378 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
379 }
380 virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
381 TEUCHOS_TEST_FOR_EXCEPTION
382 (true, std::logic_error, "This solver is not implemented for ScalarType"
383 " types for which Teuchos::LAPACK does not have a valid implementation. "
384 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
385 }
386 virtual void reset (const ResetType type) {
387 TEUCHOS_TEST_FOR_EXCEPTION
388 (true, std::logic_error, "This solver is not implemented for ScalarType"
389 " types for which Teuchos::LAPACK does not have a valid implementation. "
390 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
391 }
392 virtual ReturnType solve () {
393 TEUCHOS_TEST_FOR_EXCEPTION
394 (true, std::logic_error, "This solver is not implemented for ScalarType"
395 " types for which Teuchos::LAPACK does not have a valid implementation. "
396 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
397 }
398 };
399
404 template<class ScalarType,
405 class MV,
406 class OP,
408 const bool supportsScalarType =
410 ! Teuchos::ScalarTraits<ScalarType>::isComplex>
412
420 template<class ScalarType, class MV, class OP, class DM>
421 class SolverManagerRequiresRealLapack<ScalarType, MV, OP, DM, true> :
422 public SolverManager<ScalarType, MV, OP, DM> {
423 public:
426 };
427
435 template<class ScalarType, class MV, class OP, class DM>
436 class SolverManagerRequiresRealLapack<ScalarType, MV, OP, DM, false> :
437 public SolverManager<ScalarType, MV, OP, DM> {
438 public:
440 // Do not throw on constructor. The DII system registers all class types
441 // and must construct even if the class will not be usable.
442 }
444
446 TEUCHOS_TEST_FOR_EXCEPTION
447 (true, std::logic_error, "This solver is not implemented for complex "
448 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
449 "does not have a valid implementation."
450 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
451 }
452 virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
453 TEUCHOS_TEST_FOR_EXCEPTION
454 (true, std::logic_error, "This solver is not implemented for complex "
455 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
456 "does not have a valid implementation."
457 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
458 }
459 virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
460 TEUCHOS_TEST_FOR_EXCEPTION
461 (true, std::logic_error, "This solver is not implemented for complex "
462 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
463 "does not have a valid implementation."
464 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
465 }
466 virtual int getNumIters() const {
467 TEUCHOS_TEST_FOR_EXCEPTION
468 (true, std::logic_error, "This solver is not implemented for complex "
469 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
470 "does not have a valid implementation."
471 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
472 }
473 virtual bool isLOADetected() const {
474 TEUCHOS_TEST_FOR_EXCEPTION
475 (true, std::logic_error, "This solver is not implemented for complex "
476 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
477 "does not have a valid implementation."
478 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
479 }
480 virtual void
481 setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP,DM> >& /* problem */) {
482 TEUCHOS_TEST_FOR_EXCEPTION
483 (true, std::logic_error, "This solver is not implemented for complex "
484 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
485 "does not have a valid implementation."
486 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
487 }
488 virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
489 TEUCHOS_TEST_FOR_EXCEPTION
490 (true, std::logic_error, "This solver is not implemented for complex "
491 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
492 "does not have a valid implementation."
493 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
494 }
495 virtual void reset (const ResetType type) {
496 TEUCHOS_TEST_FOR_EXCEPTION
497 (true, std::logic_error, "This solver is not implemented for complex "
498 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
499 "does not have a valid implementation."
500 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
501 }
502 virtual ReturnType solve () {
503 TEUCHOS_TEST_FOR_EXCEPTION
504 (true, std::logic_error, "This solver is not implemented for complex "
505 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
506 "does not have a valid implementation."
507 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
508 }
509 };
510
511} // namespace Details
512} // namespace Belos
513
514#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 void reset(const ResetType type)
Reset the solver manager.
virtual int getNumIters() const
Get the iteration count for the most recent call to solve().
virtual bool isLOADetected() const
Returns whether a loss of accuracy was detected in the solver.
virtual void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &problem)
Set the linear problem that needs to be solved.
virtual const LinearProblem< ScalarType, MV, OP, DM > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
virtual void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set the parameters to use when solving the linear problem.
virtual ReturnType solve()
Iterate until the status test tells us to stop.
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return the valid parameters for this 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 for real ScalarType.
virtual Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Return the current parameters being used for this solver manager.
virtual ReturnType solve()
Iterate until the status test tells us to stop.
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return the valid parameters for this solver manager.
virtual int getNumIters() const
Get the iteration count for the most recent call to solve().
virtual const LinearProblem< ScalarType, MV, OP, DM > & 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, DM > > &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.
virtual void reset(const ResetType type)
Reset the solver manager.
virtual void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set the parameters to use when solving the linear problem.
Base class for Belos::SolverManager subclasses which normally can only compile with ScalarType types ...
virtual void reset(const ResetType type)
Reset the solver manager.
virtual int getNumIters() const
Get the iteration count for the most recent call to solve().
virtual Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Return the current parameters being used for this solver manager.
virtual bool isLOADetected() const
Returns whether a loss of accuracy was detected in the solver.
virtual ReturnType solve()
Iterate until the status test tells us to stop.
virtual const LinearProblem< ScalarType, MV, OP, DM > & 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, DM > > &)
Set the linear problem that needs to be solved.
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.
Base class for Belos::SolverManager subclasses which normally can only compile with real ScalarType t...
virtual void setDebugStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP, DM > > &)
Set user-defined debug status test.
virtual void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP, DM > > &problem)=0
Set the linear problem that needs to be solved.
virtual Teuchos::ScalarTraits< ScalarType >::magnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
virtual ReturnType solve()=0
Iterate until the status test tells us to stop.
virtual void reset(const ResetType type)=0
Reset the solver manager.
virtual bool isLOADetected() const =0
Returns whether a loss of accuracy was detected in the solver.
virtual void setUserConvStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP, DM > > &, const typename StatusTestCombo< ScalarType, MV, OP, DM >::ComboType &=StatusTestCombo< ScalarType, MV, OP, DM >::SEQ)
Set user-defined convergence status test.
virtual const LinearProblem< ScalarType, MV, OP, DM > & getProblem() const =0
Return a reference to the linear problem being solved by this solver manager.
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const =0
Return the valid parameters for this solver manager.
SolverManager()
Empty constructor.
virtual Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const =0
Return the current parameters being used for this solver manager.
virtual ~SolverManager()
Destructor.
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< SolverManager< ScalarType, MV, OP, DM > > clone() const =0
clone the solver manager.
ComboType
The test can be either the AND of all the component tests, or the OR of all the component tests,...
A pure virtual class for defining the status tests for the Belos iterative solvers.
ReturnType
Whether the Belos solve converged for all linear systems.
ResetType
How to reset the solver.
Teuchos::SerialDenseMatrix< Ordinal, Scalar > DefaultDenseMatrix

Generated for Belos by doxygen 1.15.0