Belos Version of the Day
Loading...
Searching...
No Matches
BelosMatOrthoManager.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
15#ifndef BELOS_MATORTHOMANAGER_HPP
16#define BELOS_MATORTHOMANAGER_HPP
17
37#include "BelosConfigDefs.hpp"
38#include "BelosTypes.hpp"
39#include "BelosOrthoManager.hpp"
42
43namespace Belos {
44
45 template <class ScalarType, class MV, class OP>
46 class MatOrthoManager : public OrthoManager<ScalarType,MV> {
47 protected:
48 Teuchos::RCP<const OP> _Op;
49 bool _hasOp;
50
51 public:
53
54
55 MatOrthoManager(Teuchos::RCP<const OP> Op = Teuchos::null) : _Op(Op), _hasOp(Op!=Teuchos::null) {};
56
58 virtual ~MatOrthoManager() {};
60
62
63
65 void setOp( Teuchos::RCP<const OP> Op ) {
66 _Op = Op;
67 _hasOp = (_Op != Teuchos::null);
68 };
69
71 Teuchos::RCP<const OP> getOp() const { return _Op; }
72
74
75
77
78
83 void innerProd( const MV& X, const MV& Y,
84 Teuchos::SerialDenseMatrix<int,ScalarType>& Z ) const {
85 typedef Teuchos::ScalarTraits<ScalarType> SCT;
88
89 Teuchos::RCP<const MV> P,Q;
90 Teuchos::RCP<MV> R;
91
92 if (_hasOp) {
93 // attempt to minimize the amount of work in applying
94 if ( MVT::GetNumberVecs(X) < MVT::GetNumberVecs(Y) ) {
95 R = MVT::Clone(X,MVT::GetNumberVecs(X));
96 OPT::Apply(*_Op,X,*R);
97 P = R;
98 Q = Teuchos::rcp( &Y, false );
99 }
100 else {
101 P = Teuchos::rcp( &X, false );
102 R = MVT::Clone(Y,MVT::GetNumberVecs(Y));
103 OPT::Apply(*_Op,Y,*R);
104 Q = R;
105 }
106 }
107 else {
108 P = Teuchos::rcp( &X, false );
109 Q = Teuchos::rcp( &Y, false );
110 }
111
112 MVT::MvTransMv(SCT::one(),*P,*Q,Z);
113 }
114
121 void innerProd( const MV& X, const MV& Y, Teuchos::RCP<const MV> MY,
122 Teuchos::SerialDenseMatrix<int,ScalarType>& Z ) const {
123 typedef Teuchos::ScalarTraits<ScalarType> SCT;
125
126 Teuchos::RCP<MV> P,Q;
127
128 if ( MY == Teuchos::null ) {
129 innerProd(X,Y,Z);
130 }
131 else if ( _hasOp ) {
132 // the user has done the matrix vector for us
133 MVT::MvTransMv(SCT::one(),X,*MY,Z);
134 }
135 else {
136 // there is no matrix vector
137 MVT::MvTransMv(SCT::one(),X,Y,Z);
138 }
139 }
140
143 void norm( const MV& X, std::vector< typename Teuchos::ScalarTraits<ScalarType>::magnitudeType >& normvec ) const {
144 norm(X,Teuchos::null,normvec);
145 }
146
164 void
165 norm (const MV& X,
166 Teuchos::RCP<const MV> MX,
167 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>& normvec) const
168 {
169 typedef Teuchos::ScalarTraits<ScalarType> SCT;
170 typedef Teuchos::ScalarTraits<typename SCT::magnitudeType> MT;
173
174 int nvecs = MVT::GetNumberVecs(X);
175
176 // Make sure that normvec has enough entries to hold the norms
177 // of all the columns of X. std::vector<T>::size_type is
178 // unsigned, so do the appropriate cast to avoid signed/unsigned
179 // comparisons that trigger compiler warnings.
180 if (normvec.size() < static_cast<size_t>(nvecs))
181 normvec.resize (nvecs);
182
183 if (!_hasOp) {
184 // X == MX, since the operator M is the identity.
185 MX = Teuchos::rcp(&X, false);
186 MVT::MvNorm(X, normvec);
187 }
188 else {
189 // The caller didn't give us a previously computed MX, so
190 // apply the operator. We assign to MX only after applying
191 // the operator, so that if the application fails, MX won't be
192 // modified.
193 if(MX == Teuchos::null) {
194 Teuchos::RCP<MV> tempVec = MVT::Clone(X,nvecs);
195 OPT::Apply(*_Op,X,*tempVec);
196 MX = tempVec;
197 }
198 else {
199 // The caller gave us a previously computed MX. Make sure
200 // that it has at least as many columns as X.
201 const int numColsMX = MVT::GetNumberVecs(*MX);
202 TEUCHOS_TEST_FOR_EXCEPTION(numColsMX < nvecs, std::invalid_argument,
203 "MatOrthoManager::norm(X, MX, normvec): "
204 "MX has fewer columns than X: "
205 "MX has " << numColsMX << " columns, "
206 "and X has " << nvecs << " columns.");
207 }
208
209 std::vector<ScalarType> dotvec(nvecs);
210 MVT::MvDot(X,*MX,dotvec);
211 for (int i=0; i<nvecs; i++) {
212 normvec[i] = MT::squareroot( SCT::magnitude(dotvec[i]) );
213 }
214 }
215 }
216
217
239 virtual void project ( MV &X, Teuchos::RCP<MV> MX,
240 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
241 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const = 0;
242
243
244
247 virtual void project ( MV &X,
248 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
249 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const {
250 project(X,Teuchos::null,C,Q);
251 }
252
274 virtual int normalize ( MV &X, Teuchos::RCP<MV> MX,
275 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B ) const = 0;
276
277
280 virtual int normalize ( MV &X, Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B ) const {
281 return normalize(X,Teuchos::null,B);
282 }
283
284
285 protected:
286 virtual int
288 Teuchos::RCP<MV> MX,
289 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
290 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
291 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const = 0;
292
293 virtual int
295 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
296 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
297 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const
298 {
299 return this->projectAndNormalizeWithMxImpl (X, Teuchos::null, C, B, Q);
300 }
301
302 public:
303
338 int
340 Teuchos::RCP<MV> MX,
341 Teuchos::Array<Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > > C,
342 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> > B,
343 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const
344 {
345 return this->projectAndNormalizeWithMxImpl (X, MX, C, B, Q);
346 }
347
349
351
354 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
355 orthonormError(const MV &X) const {
356 return orthonormError(X,Teuchos::null);
357 }
358
362 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
363 orthonormError(const MV &X, Teuchos::RCP<const MV> MX) const = 0;
364
367 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
368 orthogError(const MV &X1, const MV &X2) const {
369 return orthogError(X1,Teuchos::null,X2);
370 }
371
376 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
377 orthogError(const MV &X1, Teuchos::RCP<const MV> MX1, const MV &X2) const = 0;
378
380
381 };
382
383} // end of Belos namespace
384
385
386#endif
387
388// end of file BelosMatOrthoManager.hpp
Belos header file which uses auto-configuration information to include necessary C++ headers.
Declaration of basic traits for the multivector type.
Class which defines basic traits for the operator type.
Templated virtual class for providing orthogonalization/orthonormalization methods.
Collection of types and exceptions used within the Belos solvers.
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
void innerProd(const MV &X, const MV &Y, Teuchos::RCP< const MV > MY, Teuchos::SerialDenseMatrix< int, ScalarType > &Z) const
Provides the inner product defining the orthogonality concepts, using the provided operator....
virtual int normalize(MV &X, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B) const
This method calls normalize(X,Teuchos::null,B); see documentation for that function.
virtual ~MatOrthoManager()
Destructor.
MatOrthoManager(Teuchos::RCP< const OP > Op=Teuchos::null)
Default constructor.
void innerProd(const MV &X, const MV &Y, Teuchos::SerialDenseMatrix< int, ScalarType > &Z) const
Provides the inner product defining the orthogonality concepts, using the provided operator.
int projectAndNormalize(MV &X, Teuchos::RCP< MV > MX, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
Given a set of bases Q[i] and a multivector X, this method computes an orthonormal basis for .
virtual int projectAndNormalizeWithMxImpl(MV &X, Teuchos::RCP< MV > MX, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const =0
virtual Teuchos::ScalarTraits< ScalarType >::magnitudeType orthogError(const MV &X1, Teuchos::RCP< const MV > MX1, const MV &X2) const =0
This method computes the error in orthogonality of two multivectors. The method has the option of exp...
virtual void project(MV &X, Teuchos::RCP< MV > MX, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const =0
Given a list of (mutually and internally) orthonormal bases Q, this method takes a multivector X and ...
virtual Teuchos::ScalarTraits< ScalarType >::magnitudeType orthonormError(const MV &X) const
This method computes the error in orthonormality of a multivector.
void norm(const MV &X, Teuchos::RCP< const MV > MX, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec) const
Compute norm of each column of X.
void norm(const MV &X, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec) const
Provides the norm induced by innerProd().
virtual Teuchos::ScalarTraits< ScalarType >::magnitudeType orthonormError(const MV &X, Teuchos::RCP< const MV > MX) const =0
This method computes the error in orthonormality of a multivector. The method has the option of explo...
virtual int normalize(MV &X, Teuchos::RCP< MV > MX, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B) const =0
This method takes a multivector X and attempts to compute an orthonormal basis for ,...
virtual int projectAndNormalizeImpl(MV &X, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C, Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
void setOp(Teuchos::RCP< const OP > Op)
Set operator.
virtual void project(MV &X, Teuchos::Array< Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
This method calls project(X,Teuchos::null,C,Q); see documentation for that function.
Teuchos::RCP< const OP > _Op
virtual Teuchos::ScalarTraits< ScalarType >::magnitudeType orthogError(const MV &X1, const MV &X2) const
This method computes the error in orthogonality of two multivectors. This method.
Teuchos::RCP< const OP > getOp() const
Get operator.
Alternative run-time polymorphic interface for operators.
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...

Generated for Belos by doxygen 1.9.8