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_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:
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 
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  }
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  }
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 {
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 {
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) {
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  }
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) {
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 () {
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 =
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 
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  }
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  }
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 {
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 {
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
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  }
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) {
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 () {
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 */
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 Apr 19 2024 09:25:12 for Belos by doxygen 1.8.5