Belos  Version of the Day
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() {};
85 
87 
88 
90  virtual const LinearProblem<ScalarType,MV,OP>& getProblem() const = 0;
91 
94 
97 
110  TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "achievedTol() not implemented");
111  }
112 
114  virtual int getNumIters() const = 0;
115 
119  virtual bool isLOADetected() const = 0;
120 
122 
124 
125 
127  virtual void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) = 0;
128 
139  virtual void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) = 0;
140 
142  virtual void setUserConvStatusTest(
143  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &userConvStatusTest,
144  const typename StatusTestCombo<ScalarType,MV,OP>::ComboType &comboType =
146  )
147  {
148  TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error, the function setUserConvStatusTest() has not been"
149  << " overridden for the class" << this->description() << " yet!");
150  }
151 
153  virtual void setDebugStatusTest(
154  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &debugStatusTest
155  )
156  {
157  TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error, the function setDebugStatusTest() has not been"
158  << " overridden for the class" << this->description() << " yet!");
159  }
160 
162 
164 
165 
172  virtual void reset( const ResetType type ) = 0;
174 
176 
177 
179  //
190  virtual ReturnType solve() = 0;
192 
193 };
194 
195 
196 namespace Details {
197 
215  template<class ScalarType,
216  class MV,
217  class OP,
218  const bool isComplex = Teuchos::ScalarTraits<ScalarType>::isComplex>
220 
221  // Specialization for isComplex = true adds nothing to SolverManager.
222  template<class ScalarType, class MV, class OP>
223  class RealSolverManager<ScalarType, MV, OP, false> :
224  public SolverManager<ScalarType, MV, OP> {
225  public:
227  virtual ~RealSolverManager () {}
228  };
229 
230  // Specialization for isComplex = true (ScalarType is complex) adds
231  // a constructor that always throws std::logic_error. Subclasses
232  // must always call the base class constructor.
233  //
234  // The complex version (isComplex = true) needs to implement all the
235  // pure virtual methods in SolverManager, even though they can never
236  // actually be called, since the constructor throws.
237  template<class ScalarType, class MV, class OP>
238  class RealSolverManager<ScalarType, MV, OP, true> :
239  public SolverManager<ScalarType, MV, OP> {
240  public:
242  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
243  "This solver is not implemented for complex ScalarType." );
244  }
245  virtual ~RealSolverManager () {}
246 
248  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
249  "This solver is not implemented for complex ScalarType." );
250  }
252  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
253  "This solver is not implemented for complex ScalarType." );
254  }
256  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
257  "This solver is not implemented for complex ScalarType." );
258  }
259  virtual int getNumIters() const {
260  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
261  "This solver is not implemented for complex ScalarType." );
262  }
263  virtual bool isLOADetected() const {
264  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
265  "This solver is not implemented for complex ScalarType." );
266  }
267  virtual void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem) {
268  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
269  "This solver is not implemented for complex ScalarType." );
270  }
272  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
273  "This solver is not implemented for complex ScalarType." );
274  }
275  virtual void reset (const ResetType type) {
276  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
277  "This solver is not implemented for complex ScalarType." );
278  }
279  virtual ReturnType solve () {
280  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
281  "This solver is not implemented for complex ScalarType." );
282  }
283  };
284 
285 
289  template<class ScalarType>
291  public:
292  const static bool value = false;
293  };
294 
295  template<>
296  class LapackSupportsScalar<float> {
297  public:
298  const static bool value = true;
299  };
300 
301  template<>
302  class LapackSupportsScalar<double> {
303  public:
304  const static bool value = true;
305  };
306 
307 #ifdef HAVE_TEUCHOS_COMPLEX
308  template<>
309  class LapackSupportsScalar<std::complex<float> > {
310  public:
311  const static bool value = true;
312  };
313 
314  template<>
315  class LapackSupportsScalar<std::complex<double> > {
316  public:
317  const static bool value = true;
318  };
319 #endif // HAVE_TEUCHOS_COMPLEX
320 
325  template<class ScalarType,
326  class MV,
327  class OP,
328  const bool lapackSupportsScalarType =
331 
336  template<class ScalarType, class MV, class OP>
337  class SolverManagerRequiresLapack<ScalarType, MV, OP, true> :
338  public SolverManager<ScalarType, MV, OP> {
339  public:
342  };
343 
350  template<class ScalarType, class MV, class OP>
351  class SolverManagerRequiresLapack<ScalarType, MV, OP, false> :
352  public SolverManager<ScalarType, MV, OP> {
353  public:
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  }
361 
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  }
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  }
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 int getNumIters() const {
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 bool isLOADetected() const {
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 void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem) {
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  }
400  (true, std::logic_error, "This solver is not implemented for ScalarType"
401  " types for which Teuchos::LAPACK does not have a valid implementation. "
402  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
403  }
404  virtual void reset (const ResetType type) {
406  (true, std::logic_error, "This solver is not implemented for ScalarType"
407  " types for which Teuchos::LAPACK does not have a valid implementation. "
408  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
409  }
410  virtual ReturnType solve () {
412  (true, std::logic_error, "This solver is not implemented for ScalarType"
413  " types for which Teuchos::LAPACK does not have a valid implementation. "
414  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
415  }
416  };
417 
422  template<class ScalarType,
423  class MV,
424  class OP,
425  const bool supportsScalarType =
429 
437  template<class ScalarType, class MV, class OP>
438  class SolverManagerRequiresRealLapack<ScalarType, MV, OP, true> :
439  public SolverManager<ScalarType, MV, OP> {
440  public:
443  };
444 
452  template<class ScalarType, class MV, class OP>
453  class SolverManagerRequiresRealLapack<ScalarType, MV, OP, false> :
454  public SolverManager<ScalarType, MV, OP> {
455  public:
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  }
464 
467  (true, std::logic_error, "This solver is not implemented for complex "
468  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
469  "does not have a valid implementation."
470  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
471  }
474  (true, std::logic_error, "This solver is not implemented for complex "
475  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
476  "does not have a valid implementation."
477  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
478  }
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 int getNumIters() const {
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 bool isLOADetected() const {
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 void
503  (true, std::logic_error, "This solver is not implemented for complex "
504  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
505  "does not have a valid implementation."
506  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
507  }
510  (true, std::logic_error, "This solver is not implemented for complex "
511  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
512  "does not have a valid implementation."
513  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
514  }
515  virtual void reset (const ResetType type) {
517  (true, std::logic_error, "This solver is not implemented for complex "
518  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
519  "does not have a valid implementation."
520  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
521  }
522  virtual ReturnType solve () {
524  (true, std::logic_error, "This solver is not implemented for complex "
525  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
526  "does not have a valid implementation."
527  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
528  }
529  };
530 
531 } // namespace Details
532 } // namespace Belos
533 
534 #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 Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Return the current parameters being used for 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 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 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 Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return the valid parameters for this solver manager.
SolverManager()
Empty constructor.
virtual Teuchos::ScalarTraits< ScalarType >::magnitudeType achievedTol() const
Tolerance achieved by the last solve() invocation.
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...
#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 Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return the valid parameters for this solver manager.
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 void setDebugStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &debugStatusTest)
Set user-defined debug status test.
virtual bool isLOADetected() const
Returns whether a loss of accuracy was detected in the solver.
virtual std::string description() const
virtual int getNumIters() const
Get the iteration count for the most recent call to solve().
A pure virtual class for defining the status tests for the Belos iterative solvers.
virtual void reset(const ResetType type)
Reset the solver manager.
Belos::StatusTest for logically combining several status tests.
virtual const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
virtual const LinearProblem< ScalarType, MV, OP > & getProblem() const =0
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.
ResetType
How to reset the solver.
Definition: BelosTypes.hpp:205
#define TEUCHOS_TEST_FOR_EXCEPT_MSG(throw_exception_test, msg)
virtual void setUserConvStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &userConvStatusTest, const typename StatusTestCombo< ScalarType, MV, OP >::ComboType &comboType=StatusTestCombo< ScalarType, MV, OP >::SEQ)
Set user-defined convergence status test.
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.
virtual int getNumIters() const
Get the iteration count for the most recent call to solve().
Class which describes the linear problem to be solved by the iterative solver.
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 > 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().
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:154
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 const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.
virtual bool isLOADetected() const
Returns whether a loss of accuracy was detected in the solver.
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 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 ...
virtual Teuchos::RCP< const Teuchos::ParameterList > getCurrentParameters() const
Return the current parameters being used for this solver manager.
Belos header file which uses auto-configuration information to include necessary C++ headers...
virtual ~SolverManager()
Destructor.
virtual const LinearProblem< ScalarType, MV, OP > & getProblem() const
Return a reference to the linear problem being solved by this solver manager.

Generated for Belos by doxygen 1.8.14