Belos Package Browser (Single Doxygen Collection) Development
Loading...
Searching...
No Matches
BelosSolverManager.hpp
Go to the documentation of this file.
1
2//@HEADER
3// ************************************************************************
4//
5// Belos: Block Linear Solvers Package
6// Copyright 2004 Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39//
40// ************************************************************************
41//@HEADER
42
43#ifndef BELOS_SOLVERMANAGER_HPP
44#define BELOS_SOLVERMANAGER_HPP
45
50#include "BelosConfigDefs.hpp"
51#include "BelosTypes.hpp"
54
55#include "Teuchos_ParameterList.hpp"
56#include "Teuchos_RCP.hpp"
57#include "Teuchos_Describable.hpp"
58
64namespace Belos {
65
66
67template <class ScalarType, class MV, class OP>
68class StatusTest;
69
70
71template<class ScalarType, class MV, class OP>
72class SolverManager : virtual public Teuchos::Describable {
73
74 public:
75
77
78
81
83 virtual ~SolverManager() {};
84
88 virtual Teuchos::RCP<SolverManager<ScalarType, MV, OP> > clone () const = 0;
90
92
93
95 virtual const LinearProblem<ScalarType,MV,OP>& getProblem() const = 0;
96
98 virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const = 0;
99
101 virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const = 0;
102
114 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType achievedTol() const {
115 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "achievedTol() not implemented");
116 }
117
119 virtual int getNumIters() const = 0;
120
124 virtual bool isLOADetected() const = 0;
125
127
129
130
132 virtual void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) = 0;
133
144 virtual void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) = 0;
145
148 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &/* userConvStatusTest */,
149 const typename StatusTestCombo<ScalarType,MV,OP>::ComboType &/* comboType */ =
151 )
152 {
153 TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error, the function setUserConvStatusTest() has not been"
154 << " overridden for the class" << this->description() << " yet!");
155 }
156
158 virtual void setDebugStatusTest(
159 const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &/* debugStatusTest */
160 )
161 {
162 TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error, the function setDebugStatusTest() has not been"
163 << " overridden for the class" << this->description() << " yet!");
164 }
165
167
169
170
177 virtual void reset( const ResetType type ) = 0;
179
181
182
184 //
195 virtual ReturnType solve() = 0;
197
198};
199
200
201namespace Details {
202
220 template<class ScalarType,
221 class MV,
222 class OP,
223 const bool isComplex = Teuchos::ScalarTraits<ScalarType>::isComplex>
225
226 // Specialization for isComplex = true adds nothing to SolverManager.
227 template<class ScalarType, class MV, class OP>
228 class RealSolverManager<ScalarType, MV, OP, false> :
229 public SolverManager<ScalarType, MV, OP> {
230 public:
232 virtual ~RealSolverManager () {}
233 };
234
235 // Specialization for isComplex = true (ScalarType is complex) adds
236 // a constructor that always throws std::logic_error. Subclasses
237 // must always call the base class constructor.
238 //
239 // The complex version (isComplex = true) needs to implement all the
240 // pure virtual methods in SolverManager, even though they can never
241 // actually be called, since the constructor throws.
242 template<class ScalarType, class MV, class OP>
243 class RealSolverManager<ScalarType, MV, OP, true> :
244 public SolverManager<ScalarType, MV, OP> {
245 public:
247 // Do not throw on constructor. The DII system registers all class types
248 // and must construct even if the class will not be usable.
249 }
250 virtual ~RealSolverManager () {}
251
253 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
254 "This solver is not implemented for complex ScalarType." );
255 }
256 virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
257 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
258 "This solver is not implemented for complex ScalarType." );
259 }
260 virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
261 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
262 "This solver is not implemented for complex ScalarType." );
263 }
264 virtual int getNumIters() const {
265 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
266 "This solver is not implemented for complex ScalarType." );
267 }
268 virtual bool isLOADetected() const {
269 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
270 "This solver is not implemented for complex ScalarType." );
271 }
272 virtual void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem) {
273 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
274 "This solver is not implemented for complex ScalarType." );
275 }
276 virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
277 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
278 "This solver is not implemented for complex ScalarType." );
279 }
280 virtual void reset (const ResetType type) {
281 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
282 "This solver is not implemented for complex ScalarType." );
283 }
284 virtual ReturnType solve () {
285 TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
286 "This solver is not implemented for complex ScalarType." );
287 }
288 };
289
290
294 template<class ScalarType>
296 public:
297 const static bool value = false;
298 };
299
300 template<>
301 class LapackSupportsScalar<float> {
302 public:
303 const static bool value = true;
304 };
305
306 template<>
307 class LapackSupportsScalar<double> {
308 public:
309 const static bool value = true;
310 };
311
312#ifdef HAVE_TEUCHOS_LONG_DOUBLE
313 template<>
314 class LapackSupportsScalar<long double> {
315 public:
316 const static bool value = true;
317 };
318#endif
319
320
321#ifdef HAVE_TEUCHOS_COMPLEX
322 template<>
323 class LapackSupportsScalar<std::complex<float> > {
324 public:
325 const static bool value = true;
326 };
327
328 template<>
329 class LapackSupportsScalar<std::complex<double> > {
330 public:
331 const static bool value = true;
332 };
333#endif // HAVE_TEUCHOS_COMPLEX
334
339 template<class ScalarType,
340 class MV,
341 class OP,
342 const bool lapackSupportsScalarType =
345
350 template<class ScalarType, class MV, class OP>
351 class SolverManagerRequiresLapack<ScalarType, MV, OP, true> :
352 public SolverManager<ScalarType, MV, OP> {
353 public:
356 };
357
364 template<class ScalarType, class MV, class OP>
365 class SolverManagerRequiresLapack<ScalarType, MV, OP, false> :
366 public SolverManager<ScalarType, MV, OP> {
367 public:
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 }
375
377 TEUCHOS_TEST_FOR_EXCEPTION
378 (true, std::logic_error, "This solver is not implemented for ScalarType"
379 " types for which Teuchos::LAPACK does not have a valid implementation. "
380 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
381 }
382 virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
383 TEUCHOS_TEST_FOR_EXCEPTION
384 (true, std::logic_error, "This solver is not implemented for ScalarType"
385 " types for which Teuchos::LAPACK does not have a valid implementation. "
386 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
387 }
388 virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
389 TEUCHOS_TEST_FOR_EXCEPTION
390 (true, std::logic_error, "This solver is not implemented for ScalarType"
391 " types for which Teuchos::LAPACK does not have a valid implementation. "
392 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
393 }
394 virtual int getNumIters() const {
395 TEUCHOS_TEST_FOR_EXCEPTION
396 (true, std::logic_error, "This solver is not implemented for ScalarType"
397 " types for which Teuchos::LAPACK does not have a valid implementation. "
398 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
399 }
400 virtual bool isLOADetected() const {
401 TEUCHOS_TEST_FOR_EXCEPTION
402 (true, std::logic_error, "This solver is not implemented for ScalarType"
403 " types for which Teuchos::LAPACK does not have a valid implementation. "
404 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
405 }
406 virtual void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem) {
407 TEUCHOS_TEST_FOR_EXCEPTION
408 (true, std::logic_error, "This solver is not implemented for ScalarType"
409 " types for which Teuchos::LAPACK does not have a valid implementation. "
410 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
411 }
412 virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
413 TEUCHOS_TEST_FOR_EXCEPTION
414 (true, std::logic_error, "This solver is not implemented for ScalarType"
415 " types for which Teuchos::LAPACK does not have a valid implementation. "
416 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
417 }
418 virtual void reset (const ResetType type) {
419 TEUCHOS_TEST_FOR_EXCEPTION
420 (true, std::logic_error, "This solver is not implemented for ScalarType"
421 " types for which Teuchos::LAPACK does not have a valid implementation. "
422 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
423 }
424 virtual ReturnType solve () {
425 TEUCHOS_TEST_FOR_EXCEPTION
426 (true, std::logic_error, "This solver is not implemented for ScalarType"
427 " types for which Teuchos::LAPACK does not have a valid implementation. "
428 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
429 }
430 };
431
436 template<class ScalarType,
437 class MV,
438 class OP,
439 const bool supportsScalarType =
441 ! Teuchos::ScalarTraits<ScalarType>::isComplex>
443
451 template<class ScalarType, class MV, class OP>
452 class SolverManagerRequiresRealLapack<ScalarType, MV, OP, true> :
453 public SolverManager<ScalarType, MV, OP> {
454 public:
457 };
458
466 template<class ScalarType, class MV, class OP>
467 class SolverManagerRequiresRealLapack<ScalarType, MV, OP, false> :
468 public SolverManager<ScalarType, MV, OP> {
469 public:
471 // Do not throw on constructor. The DII system registers all class types
472 // and must construct even if the class will not be usable.
473 }
475
477 TEUCHOS_TEST_FOR_EXCEPTION
478 (true, std::logic_error, "This solver is not implemented for complex "
479 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
480 "does not have a valid implementation."
481 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
482 }
483 virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
484 TEUCHOS_TEST_FOR_EXCEPTION
485 (true, std::logic_error, "This solver is not implemented for complex "
486 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
487 "does not have a valid implementation."
488 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
489 }
490 virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
491 TEUCHOS_TEST_FOR_EXCEPTION
492 (true, std::logic_error, "This solver is not implemented for complex "
493 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
494 "does not have a valid implementation."
495 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
496 }
497 virtual int getNumIters() const {
498 TEUCHOS_TEST_FOR_EXCEPTION
499 (true, std::logic_error, "This solver is not implemented for complex "
500 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
501 "does not have a valid implementation."
502 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
503 }
504 virtual bool isLOADetected() const {
505 TEUCHOS_TEST_FOR_EXCEPTION
506 (true, std::logic_error, "This solver is not implemented for complex "
507 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
508 "does not have a valid implementation."
509 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
510 }
511 virtual void
512 setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> >& /* problem */) {
513 TEUCHOS_TEST_FOR_EXCEPTION
514 (true, std::logic_error, "This solver is not implemented for complex "
515 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
516 "does not have a valid implementation."
517 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
518 }
519 virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
520 TEUCHOS_TEST_FOR_EXCEPTION
521 (true, std::logic_error, "This solver is not implemented for complex "
522 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
523 "does not have a valid implementation."
524 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
525 }
526 virtual void reset (const ResetType type) {
527 TEUCHOS_TEST_FOR_EXCEPTION
528 (true, std::logic_error, "This solver is not implemented for complex "
529 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
530 "does not have a valid implementation."
531 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
532 }
533 virtual ReturnType solve () {
534 TEUCHOS_TEST_FOR_EXCEPTION
535 (true, std::logic_error, "This solver is not implemented for complex "
536 "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
537 "does not have a valid implementation."
538 "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
539 }
540 };
541
542} // namespace Details
543} // namespace Belos
544
545#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...
A linear system to solve, and its associated information.
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,...
A pure virtual class for defining the status tests for the Belos iterative solvers.
ReturnType
Whether the Belos solve converged for all linear systems.
Definition: BelosTypes.hpp:155
ResetType
How to reset the solver.
Definition: BelosTypes.hpp:206