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 // @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"
19 #include "BelosLinearProblem.hpp"
20 #include "BelosStatusTestCombo.hpp"
21 
23 #include "Teuchos_RCP.hpp"
24 #include "Teuchos_Describable.hpp"
25 
31 namespace Belos {
32 
33 
34 template <class ScalarType, class MV, class OP>
35 class StatusTest;
36 
37 
38 template<class ScalarType, class MV, class OP>
39 class SolverManager : virtual public Teuchos::Describable {
40 
41  public:
42 
44 
45 
48 
50  virtual ~SolverManager() {};
51 
57 
59 
60 
62  virtual const LinearProblem<ScalarType,MV,OP>& getProblem() const = 0;
63 
66 
69 
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 
114  virtual void setUserConvStatusTest(
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 
168 namespace 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>
195  class RealSolverManager<ScalarType, MV, OP, false> :
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>
210  class RealSolverManager<ScalarType, MV, OP, true> :
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  }
224  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
225  "This solver is not implemented for complex ScalarType." );
226  }
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  }
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,
309  const bool lapackSupportsScalarType =
312 
317  template<class ScalarType, class MV, class OP>
318  class SolverManagerRequiresLapack<ScalarType, MV, OP, true> :
319  public SolverManager<ScalarType, MV, OP> {
320  public:
323  };
324 
331  template<class ScalarType, class MV, class OP>
332  class SolverManagerRequiresLapack<ScalarType, MV, OP, false> :
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  }
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  }
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  }
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 =
410 
418  template<class ScalarType, class MV, class OP>
419  class SolverManagerRequiresRealLapack<ScalarType, MV, OP, true> :
420  public SolverManager<ScalarType, MV, OP> {
421  public:
424  };
425 
433  template<class ScalarType, class MV, class OP>
434  class SolverManagerRequiresRealLapack<ScalarType, MV, OP, false> :
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  }
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  }
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
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  }
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 */
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:174
#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:123
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 Nov 22 2024 09:23:06 for Belos by doxygen 1.8.5