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 
54 #include "Teuchos_ParameterList.hpp"
55 #include "Teuchos_RCP.hpp"
56 #include "Teuchos_Describable.hpp"
57 
63 namespace Belos {
64 
65 
66 template <class ScalarType, class MV, class OP>
67 class StatusTest;
68 
69 
70 template<class ScalarType, class MV, class OP>
71 class SolverManager : virtual public Teuchos::Describable {
72 
73  public:
74 
76 
77 
80 
82  virtual ~SolverManager() {};
84 
86 
87 
89  virtual const LinearProblem<ScalarType,MV,OP>& getProblem() const = 0;
90 
92  virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const = 0;
93 
95  virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const = 0;
96 
108  virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType achievedTol() const {
109  TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, "achievedTol() not implemented");
110  }
111 
113  virtual int getNumIters() const = 0;
114 
118  virtual bool isLOADetected() const = 0;
119 
121 
123 
124 
126  virtual void setProblem( const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem ) = 0;
127 
138  virtual void setParameters( const Teuchos::RCP<Teuchos::ParameterList> &params ) = 0;
139 
141  virtual void setUserConvStatusTest(
142  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &userConvStatusTest
143  )
144  {
145  TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error, the function setUserConvStatusTest() has not been"
146  << " overridden for the class" << this->description() << " yet!");
147  }
148 
150  virtual void setDebugStatusTest(
151  const Teuchos::RCP<StatusTest<ScalarType,MV,OP> > &debugStatusTest
152  )
153  {
154  TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "Error, the function setDebugStatusTest() has not been"
155  << " overridden for the class" << this->description() << " yet!");
156  }
157 
159 
161 
162 
169  virtual void reset( const ResetType type ) = 0;
171 
173 
174 
176  //
187  virtual ReturnType solve() = 0;
189 
190 };
191 
192 
193 namespace Details {
194 
212  template<class ScalarType,
213  class MV,
214  class OP,
215  const bool isComplex = Teuchos::ScalarTraits<ScalarType>::isComplex>
217 
218  // Specialization for isComplex = true adds nothing to SolverManager.
219  template<class ScalarType, class MV, class OP>
220  class RealSolverManager<ScalarType, MV, OP, false> :
221  public SolverManager<ScalarType, MV, OP> {
222  public:
224  virtual ~RealSolverManager () {}
225  };
226 
227  // Specialization for isComplex = true (ScalarType is complex) adds
228  // a constructor that always throws std::logic_error. Subclasses
229  // must always call the base class constructor.
230  //
231  // The complex version (isComplex = true) needs to implement all the
232  // pure virtual methods in SolverManager, even though they can never
233  // actually be called, since the constructor throws.
234  template<class ScalarType, class MV, class OP>
235  class RealSolverManager<ScalarType, MV, OP, true> :
236  public SolverManager<ScalarType, MV, OP> {
237  public:
239  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
240  "This solver is not implemented for complex ScalarType." );
241  }
242  virtual ~RealSolverManager () {}
243 
245  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
246  "This solver is not implemented for complex ScalarType." );
247  }
248  virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
249  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
250  "This solver is not implemented for complex ScalarType." );
251  }
252  virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
253  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
254  "This solver is not implemented for complex ScalarType." );
255  }
256  virtual int getNumIters() const {
257  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
258  "This solver is not implemented for complex ScalarType." );
259  }
260  virtual bool isLOADetected() const {
261  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
262  "This solver is not implemented for complex ScalarType." );
263  }
264  virtual void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem) {
265  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
266  "This solver is not implemented for complex ScalarType." );
267  }
268  virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
269  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
270  "This solver is not implemented for complex ScalarType." );
271  }
272  virtual void reset (const ResetType type) {
273  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
274  "This solver is not implemented for complex ScalarType." );
275  }
276  virtual ReturnType solve () {
277  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
278  "This solver is not implemented for complex ScalarType." );
279  }
280  };
281 
282 
286  template<class ScalarType>
288  public:
289  const static bool value = false;
290  };
291 
292  template<>
293  class LapackSupportsScalar<float> {
294  public:
295  const static bool value = true;
296  };
297 
298  template<>
299  class LapackSupportsScalar<double> {
300  public:
301  const static bool value = true;
302  };
303 
304 #ifdef HAVE_TEUCHOS_COMPLEX
305  template<>
306  class LapackSupportsScalar<std::complex<float> > {
307  public:
308  const static bool value = true;
309  };
310 
311  template<>
312  class LapackSupportsScalar<std::complex<double> > {
313  public:
314  const static bool value = true;
315  };
316 #endif // HAVE_TEUCHOS_COMPLEX
317 
322  template<class ScalarType,
323  class MV,
324  class OP,
325  const bool lapackSupportsScalarType =
328 
333  template<class ScalarType, class MV, class OP>
334  class SolverManagerRequiresLapack<ScalarType, MV, OP, true> :
335  public SolverManager<ScalarType, MV, OP> {
336  public:
339  };
340 
347  template<class ScalarType, class MV, class OP>
348  class SolverManagerRequiresLapack<ScalarType, MV, OP, false> :
349  public SolverManager<ScalarType, MV, OP> {
350  public:
352  TEUCHOS_TEST_FOR_EXCEPTION
353  (true, std::logic_error, "This solver is not implemented for ScalarType"
354  " types for which Teuchos::LAPACK does not have a valid implementation. "
355  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
356  }
358 
360  TEUCHOS_TEST_FOR_EXCEPTION
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  }
365  virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
366  TEUCHOS_TEST_FOR_EXCEPTION
367  (true, std::logic_error, "This solver is not implemented for ScalarType"
368  " types for which Teuchos::LAPACK does not have a valid implementation. "
369  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
370  }
371  virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
372  TEUCHOS_TEST_FOR_EXCEPTION
373  (true, std::logic_error, "This solver is not implemented for ScalarType"
374  " types for which Teuchos::LAPACK does not have a valid implementation. "
375  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
376  }
377  virtual int getNumIters() const {
378  TEUCHOS_TEST_FOR_EXCEPTION
379  (true, std::logic_error, "This solver is not implemented for ScalarType"
380  " types for which Teuchos::LAPACK does not have a valid implementation. "
381  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
382  }
383  virtual bool isLOADetected() const {
384  TEUCHOS_TEST_FOR_EXCEPTION
385  (true, std::logic_error, "This solver is not implemented for ScalarType"
386  " types for which Teuchos::LAPACK does not have a valid implementation. "
387  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
388  }
389  virtual void setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> > &problem) {
390  TEUCHOS_TEST_FOR_EXCEPTION
391  (true, std::logic_error, "This solver is not implemented for ScalarType"
392  " types for which Teuchos::LAPACK does not have a valid implementation. "
393  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
394  }
395  virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
396  TEUCHOS_TEST_FOR_EXCEPTION
397  (true, std::logic_error, "This solver is not implemented for ScalarType"
398  " types for which Teuchos::LAPACK does not have a valid implementation. "
399  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
400  }
401  virtual void reset (const ResetType type) {
402  TEUCHOS_TEST_FOR_EXCEPTION
403  (true, std::logic_error, "This solver is not implemented for ScalarType"
404  " types for which Teuchos::LAPACK does not have a valid implementation. "
405  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
406  }
407  virtual ReturnType solve () {
408  TEUCHOS_TEST_FOR_EXCEPTION
409  (true, std::logic_error, "This solver is not implemented for ScalarType"
410  " types for which Teuchos::LAPACK does not have a valid implementation. "
411  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
412  }
413  };
414 
419  template<class ScalarType,
420  class MV,
421  class OP,
422  const bool supportsScalarType =
424  ! Teuchos::ScalarTraits<ScalarType>::isComplex>
426 
434  template<class ScalarType, class MV, class OP>
435  class SolverManagerRequiresRealLapack<ScalarType, MV, OP, true> :
436  public SolverManager<ScalarType, MV, OP> {
437  public:
440  };
441 
449  template<class ScalarType, class MV, class OP>
450  class SolverManagerRequiresRealLapack<ScalarType, MV, OP, false> :
451  public SolverManager<ScalarType, MV, OP> {
452  public:
454  TEUCHOS_TEST_FOR_EXCEPTION
455  (true, std::logic_error, "This solver is not implemented for complex "
456  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
457  "does not have a valid implementation."
458  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
459  }
461 
463  TEUCHOS_TEST_FOR_EXCEPTION
464  (true, std::logic_error, "This solver is not implemented for complex "
465  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
466  "does not have a valid implementation."
467  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
468  }
469  virtual Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
470  TEUCHOS_TEST_FOR_EXCEPTION
471  (true, std::logic_error, "This solver is not implemented for complex "
472  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
473  "does not have a valid implementation."
474  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
475  }
476  virtual Teuchos::RCP<const Teuchos::ParameterList> getCurrentParameters() const {
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 int getNumIters() 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 bool isLOADetected() 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 void
498  setProblem (const Teuchos::RCP<LinearProblem<ScalarType,MV,OP> >& /* problem */) {
499  TEUCHOS_TEST_FOR_EXCEPTION
500  (true, std::logic_error, "This solver is not implemented for complex "
501  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
502  "does not have a valid implementation."
503  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
504  }
505  virtual void setParameters (const Teuchos::RCP<Teuchos::ParameterList>& params) {
506  TEUCHOS_TEST_FOR_EXCEPTION
507  (true, std::logic_error, "This solver is not implemented for complex "
508  "ScalarType types, or for ScalarType types for which Teuchos::LAPACK "
509  "does not have a valid implementation."
510  "ScalarType = " << Teuchos::TypeNameTraits<ScalarType>::name () << ".");
511  }
512  virtual void reset (const ResetType type) {
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 ReturnType solve () {
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  };
527 
528 } // namespace Details
529 } // namespace Belos
530 
531 #endif /* BELOS_SOLVERMANAGER_HPP */
Collection of types and exceptions used within the Belos solvers.
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().
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.
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 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 void setUserConvStatusTest(const Teuchos::RCP< StatusTest< ScalarType, MV, OP > > &userConvStatusTest)
Set user-defined convergence status test.
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.
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:200
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 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:149
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 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.
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 Thu Jul 21 2016 14:43:57 for Belos by doxygen 1.8.11