Belos Version of the Day
Loading...
Searching...
No Matches
BelosCGIteration.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_CG_ITERATION_HPP
11#define BELOS_CG_ITERATION_HPP
12
17#include "BelosConfigDefs.hpp"
18#include "BelosTypes.hpp"
19#include "BelosIteration.hpp"
21#include "Teuchos_Assert.hpp"
22
23namespace Belos {
24
26
27
32 template <class ScalarType, class MV>
34
35 public:
36 virtual void initialize(Teuchos::RCP<const MV> tmp, int _numVectors) {
37 TEUCHOS_ASSERT(!R.is_null());
38 TEUCHOS_ASSERT(!Z.is_null());
39 TEUCHOS_ASSERT(!P.is_null());
40 TEUCHOS_ASSERT(!AP.is_null());
41 isInitialized_ = true;
42 numVectors_ = _numVectors;
43 }
44
45 virtual ~CGIterationStateBase() = default;
46
47 bool isInitialized() const { return isInitialized_; }
48
49 int numVectors() const { return numVectors_; }
50
51 virtual bool matches(Teuchos::RCP<const MV> tmp, int _numVectors=1) const {
53 return (isInitialized() &&
54 !R.is_null() &&
55 !Z.is_null() &&
56 !P.is_null() &&
57 !AP.is_null() &&
58 (numVectors() == _numVectors) &&
59 (MVT::GetGlobalLength(*tmp) == MVT::GetGlobalLength(*R)));
60 }
61
63 Teuchos::RCP<MV> R;
64
66 Teuchos::RCP<MV> Z;
67
69 Teuchos::RCP<MV> P;
70
72 Teuchos::RCP<MV> AP;
73
74 private:
75
76 bool isInitialized_;
77 int numVectors_;
78
79 };
80
82
83
95 class CGIterationInitFailure : public BelosError {public:
97 {}};
98
105 class CGIterateFailure : public BelosError {public:
107 {}};
108
117
124 class CGIterationOrthoFailure : public BelosError {public:
126 {}};
127
134 class CGIterationLAPACKFailure : public BelosError {public:
136 {}};
137
139
140
141template<class ScalarType, class MV, class OP>
142class CGIteration : virtual public Iteration<ScalarType,MV,OP> {
143
144 public:
145
147
148
162 virtual void initializeCG(Teuchos::RCP<CGIterationStateBase<ScalarType,MV> > newstate, Teuchos::RCP<MV> R_0) = 0;
163
170 virtual Teuchos::RCP<CGIterationStateBase<ScalarType,MV> > getState() const = 0;
171
172 virtual void setState(Teuchos::RCP<CGIterationStateBase<ScalarType,MV> > state) = 0;
174
175
177 virtual void setDoCondEst(bool val) = 0;
178
180 virtual Teuchos::ArrayView<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> getDiag() = 0;
181
183 virtual Teuchos::ArrayView<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType> getOffDiag() = 0;
184
185};
186
187} // end Belos namespace
188
189#endif /* BELOS_CG_ITERATION_HPP */
Belos header file which uses auto-configuration information to include necessary C++ headers.
Pure virtual base class which describes the basic interface to the linear solver iteration.
Declaration of basic traits for the multivector type.
Collection of types and exceptions used within the Belos solvers.
Parent class to all Belos exceptions.
CGIterateFailure is thrown when the CGIteration object is unable to compute the next iterate in the C...
CGIterateFailure(const std::string &what_arg)
CGIterationInitFailure is thrown when the CGIteration object is unable to generate an initial iterate...
CGIterationInitFailure(const std::string &what_arg)
CGIterationLAPACKFailure is thrown when a nonzero return value is passed back from an LAPACK routine.
CGIterationLAPACKFailure(const std::string &what_arg)
CGIterationOrthoFailure is thrown when the CGIteration object is unable to compute independent direct...
CGIterationOrthoFailure(const std::string &what_arg)
Structure to contain pointers to CGIteration state variables.
Teuchos::RCP< MV > R
The current residual.
Teuchos::RCP< MV > P
The current decent direction vector.
virtual void initialize(Teuchos::RCP< const MV > tmp, int _numVectors)
virtual bool matches(Teuchos::RCP< const MV > tmp, int _numVectors=1) const
Teuchos::RCP< MV > Z
The current preconditioned residual.
Teuchos::RCP< MV > AP
The matrix A applied to current decent direction vector.
virtual ~CGIterationStateBase()=default
virtual Teuchos::RCP< CGIterationStateBase< ScalarType, MV > > getState() const =0
Get the current state of the linear solver.
virtual Teuchos::ArrayView< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getOffDiag()=0
Gets the off-diagonal for condition estimation.
virtual void setDoCondEst(bool val)=0
Sets whether or not to store the diagonal for condition estimation.
virtual Teuchos::ArrayView< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > getDiag()=0
Gets the diagonal for condition estimation.
virtual void setState(Teuchos::RCP< CGIterationStateBase< ScalarType, MV > > state)=0
virtual void initializeCG(Teuchos::RCP< CGIterationStateBase< ScalarType, MV > > newstate, Teuchos::RCP< MV > R_0)=0
Initialize the solver to an iterate, providing a complete state.
CGPositiveDefiniteFailure is thrown when the the CG 'alpha = p^H*A*P' value is less than zero,...
CGPositiveDefiniteFailure(const std::string &what_arg)
Alternative run-time polymorphic interface for operators.

Generated for Belos by doxygen 1.9.8