Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
52 #include "BelosLinearProblem.hpp"
53 #include "BelosStatusTestCombo.hpp"
54 
56 #include "Teuchos_RCP.hpp"
57 #include "Teuchos_Describable.hpp"
58 
64 namespace Belos {
65 
66 
67 template <class ScalarType, class MV, class OP>
68 class StatusTest;
69 
70 
71 template<class ScalarType, class MV, class OP>
72 class SolverManager : virtual public Teuchos::Describable {
73 
74  public:
75 
77 
78 
81 
83  virtual ~SolverManager() {};
84 
90 
92 
93 
95  virtual const LinearProblem<ScalarType,MV,OP>& getProblem() const = 0;
96 
99 
102 
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 
147  virtual void setUserConvStatusTest(
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 
201 namespace 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  }
257  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
258  "This solver is not implemented for complex ScalarType." );
259  }
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  }
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_COMPLEX
313  template<>
314  class LapackSupportsScalar<std::complex<float> > {
315  public:
316  const static bool value = true;
317  };
318 
319  template<>
320  class LapackSupportsScalar<std::complex<double> > {
321  public:
322  const static bool value = true;
323  };
324 #endif // HAVE_TEUCHOS_COMPLEX
325 
330  template<class ScalarType,
331  class MV,
332  class OP,
333  const bool lapackSupportsScalarType =
336 
341  template<class ScalarType, class MV, class OP>
342  class SolverManagerRequiresLapack<ScalarType, MV, OP, true> :
343  public SolverManager<ScalarType, MV, OP> {
344  public:
347  };
348 
355  template<class ScalarType, class MV, class OP>
356  class SolverManagerRequiresLapack<ScalarType, MV, OP, false> :
357  public SolverManager<ScalarType, MV, OP> {
358  public:
361  (true, std::logic_error, "This solver is not implemented for ScalarType"
362  " types for which Teuchos::LAPACK does not have a valid implementation. "
363  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
364  }
366 
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  }
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  }
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 int getNumIters() const {
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 bool isLOADetected() const {
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  virtual void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem) {
399  (true, std::logic_error, "This solver is not implemented for ScalarType"
400  " types for which Teuchos::LAPACK does not have a valid implementation. "
401  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
402  }
405  (true, std::logic_error, "This solver is not implemented for ScalarType"
406  " types for which Teuchos::LAPACK does not have a valid implementation. "
407  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
408  }
409  virtual void reset (const ResetType type) {
411  (true, std::logic_error, "This solver is not implemented for ScalarType"
412  " types for which Teuchos::LAPACK does not have a valid implementation. "
413  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
414  }
415  virtual ReturnType solve () {
417  (true, std::logic_error, "This solver is not implemented for ScalarType"
418  " types for which Teuchos::LAPACK does not have a valid implementation. "
419  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
420  }
421  };
422 
427  template<class ScalarType,
428  class MV,
429  class OP,
430  const bool supportsScalarType =
434 
442  template<class ScalarType, class MV, class OP>
443  class SolverManagerRequiresRealLapack<ScalarType, MV, OP, true> :
444  public SolverManager<ScalarType, MV, OP> {
445  public:
448  };
449 
457  template<class ScalarType, class MV, class OP>
458  class SolverManagerRequiresRealLapack<ScalarType, MV, OP, false> :
459  public SolverManager<ScalarType, MV, OP> {
460  public:
462  // Do not throw on constructor. The DII system registers all class types
463  // and must construct even if the class will not be usable.
464  }
466 
469  (true, std::logic_error, "This solver is not implemented for complex "
470  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
471  "does not have a valid implementation."
472  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
473  }
476  (true, std::logic_error, "This solver is not implemented for complex "
477  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
478  "does not have a valid implementation."
479  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
480  }
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 int getNumIters() const {
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 bool isLOADetected() const {
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 void
505  (true, std::logic_error, "This solver is not implemented for complex "
506  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
507  "does not have a valid implementation."
508  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
509  }
512  (true, std::logic_error, "This solver is not implemented for complex "
513  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
514  "does not have a valid implementation."
515  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
516  }
517  virtual void reset (const ResetType type) {
519  (true, std::logic_error, "This solver is not implemented for complex "
520  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
521  "does not have a valid implementation."
522  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
523  }
524  virtual ReturnType solve () {
526  (true, std::logic_error, "This solver is not implemented for complex "
527  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
528  "does not have a valid implementation."
529  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
530  }
531  };
532 
533 } // namespace Details
534 } // namespace Belos
535 
536 #endif /* BELOS_SOLVERMANAGER_HPP */
Collection of types and exceptions used within the Belos solvers.
ComboType
The test can be either the AND of all the component tests, or the OR of all the component tests...
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 void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)=0
Set the linear problem that needs to be solved.
virtual Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const =0
Return the current parameters being used for this solver manager.
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return the valid parameters for this solver manager.
virtual ReturnType solve()
Iterate until the status test tells us to stop.
virtual int getNumIters() const =0
Get the iteration count for the most recent call to solve().
virtual ReturnType solve()
Iterate until the status test tells us to stop.
virtual Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Return the current parameters being used 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.
SolverManager()
Empty constructor.
Base class for Belos::SolverManager subclasses which normally can only compile with real ScalarType t...
virtual int getNumIters() const
Get the iteration count for the most recent call to solve().
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual ReturnType solve()=0
Iterate until the status test tells us to stop.
virtual void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set the parameters to use when solving the linear problem.
virtual void setProblem(const Teuchos::RCP< LinearProblem< ScalarType, MV, OP > > &problem)
Set the linear problem that needs to be solved.
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.
Base class for Belos::SolverManager subclasses which normally can only compile for real ScalarType...
virtual void reset(const ResetType type)=0
Reset the solver manager.
virtual bool isLOADetected() const
Returns whether a loss of accuracy was detected in the solver.
virtual bool isLOADetected() const
Returns whether a loss of accuracy was detected in the solver.
A pure virtual class for defining the status tests for the Belos iterative solvers.
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 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 Teuchos::ScalarTraits< ScalarType >::magnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
Belos::StatusTest for logically combining several status tests.
virtual const LinearProblem< ScalarType, MV, OP > & getProblem() const =0
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 setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set the parameters to use when solving the linear problem.
ResetType
How to reset the solver.
Definition: BelosTypes.hpp:206
#define TEUCHOS_TEST_FOR_EXCEPT_MSG(throw_exception_test, msg)
virtual Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Return the current parameters being used for this solver manager.
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.
A linear system to solve, and its associated information.
Class which describes the linear problem to be solved by the iterative solver.
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return the valid parameters for this solver manager.
virtual std::string description() const
virtual void setParameters(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set the parameters to use when solving the linear problem.
Type traits class that says whether Teuchos::LAPACK has a valid implementation for the given ScalarTy...
ReturnType
Whether the Belos solve converged for all linear systems.
Definition: BelosTypes.hpp:155
virtual void setDebugStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &)
Set user-defined debug status test.
The Belos::SolverManager is a templated virtual base class that defines the basic interface that any ...
virtual void reset(const ResetType type)
Reset the solver manager.
virtual void reset(const ResetType type)
Reset the solver manager.
virtual Teuchos::RCP< SolverManager< ScalarType, MV, OP > > clone() const =0
clone the solver manager.
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 int getNumIters() const
Get the iteration count for the most recent call to solve().
virtual bool isLOADetected() const =0
Returns whether a loss of accuracy was detected in the solver.
A class for extending the status testing capabilities of Belos via logical combinations.
virtual ReturnType solve()
Iterate until the status test tells us to stop.
Base class for Belos::SolverManager subclasses which normally can only compile with ScalarType types ...
Belos header file which uses auto-configuration information to include necessary C++ headers...
virtual ~SolverManager()
Destructor.

Generated on Fri Dec 20 2024 09:27:53 for Belos by doxygen 1.8.5