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"
44
45namespace Belos {
46
47 template <class ScalarType, class MV, class OP, class DM = DefaultDenseMatrix<int,ScalarType>>
48 class MatOrthoManager : public OrthoManager<ScalarType,MV,DM> {
49 protected:
50 Teuchos::RCP<const OP> _Op;
51 bool _hasOp;
52
53 public:
55
56
57 MatOrthoManager(Teuchos::RCP<const OP> Op = Teuchos::null) : _Op(Op), _hasOp(Op!=Teuchos::null) {};
58
60 virtual ~MatOrthoManager() {};
62
64
65
67 void setOp( Teuchos::RCP<const OP> Op ) {
68 _Op = Op;
69 _hasOp = (_Op != Teuchos::null);
70 };
71
73 Teuchos::RCP<const OP> getOp() const { return _Op; }
74
76
77
79
80
85 void innerProd( const MV& X, const MV& Y,
86 DM& Z ) const {
87 typedef Teuchos::ScalarTraits<ScalarType> SCT;
90
91 Teuchos::RCP<const MV> P,Q;
92 Teuchos::RCP<MV> R;
93
94 if (_hasOp) {
95 // attempt to minimize the amount of work in applying
96 if ( MVT::GetNumberVecs(X) < MVT::GetNumberVecs(Y) ) {
97 R = MVT::Clone(X,MVT::GetNumberVecs(X));
98 OPT::Apply(*_Op,X,*R);
99 P = R;
100 Q = Teuchos::rcp( &Y, false );
101 }
102 else {
103 P = Teuchos::rcp( &X, false );
104 R = MVT::Clone(Y,MVT::GetNumberVecs(Y));
105 OPT::Apply(*_Op,Y,*R);
106 Q = R;
107 }
108 }
109 else {
110 P = Teuchos::rcp( &X, false );
111 Q = Teuchos::rcp( &Y, false );
112 }
113
114 MVT::MvTransMv(SCT::one(),*P,*Q,Z);
115 }
116
123 void innerProd( const MV& X, const MV& Y, Teuchos::RCP<const MV> MY,
124 DM& Z ) const {
125 typedef Teuchos::ScalarTraits<ScalarType> SCT;
127
128 Teuchos::RCP<MV> P,Q;
129
130 if ( MY == Teuchos::null ) {
131 innerProd(X,Y,Z);
132 }
133 else if ( _hasOp ) {
134 // the user has done the matrix vector for us
135 MVT::MvTransMv(SCT::one(),X,*MY,Z);
136 }
137 else {
138 // there is no matrix vector
139 MVT::MvTransMv(SCT::one(),X,Y,Z);
140 }
141 }
142
145 void norm( const MV& X, std::vector< typename Teuchos::ScalarTraits<ScalarType>::magnitudeType >& normvec ) const {
146 norm(X,Teuchos::null,normvec);
147 }
148
166 void
167 norm (const MV& X,
168 Teuchos::RCP<const MV> MX,
169 std::vector<typename Teuchos::ScalarTraits<ScalarType>::magnitudeType>& normvec) const
170 {
171 typedef Teuchos::ScalarTraits<ScalarType> SCT;
172 typedef Teuchos::ScalarTraits<typename SCT::magnitudeType> MT;
175
176 int nvecs = MVT::GetNumberVecs(X);
177
178 // Make sure that normvec has enough entries to hold the norms
179 // of all the columns of X. std::vector<T>::size_type is
180 // unsigned, so do the appropriate cast to avoid signed/unsigned
181 // comparisons that trigger compiler warnings.
182 if (normvec.size() < static_cast<size_t>(nvecs))
183 normvec.resize (nvecs);
184
185 if (!_hasOp) {
186 // X == MX, since the operator M is the identity.
187 MX = Teuchos::rcp(&X, false);
188 MVT::MvNorm(X, normvec);
189 }
190 else {
191 // The caller didn't give us a previously computed MX, so
192 // apply the operator. We assign to MX only after applying
193 // the operator, so that if the application fails, MX won't be
194 // modified.
195 if(MX == Teuchos::null) {
196 Teuchos::RCP<MV> tempVec = MVT::Clone(X,nvecs);
197 OPT::Apply(*_Op,X,*tempVec);
198 MX = tempVec;
199 }
200 else {
201 // The caller gave us a previously computed MX. Make sure
202 // that it has at least as many columns as X.
203 const int numColsMX = MVT::GetNumberVecs(*MX);
204 TEUCHOS_TEST_FOR_EXCEPTION(numColsMX < nvecs, std::invalid_argument,
205 "MatOrthoManager::norm(X, MX, normvec): "
206 "MX has fewer columns than X: "
207 "MX has " << numColsMX << " columns, "
208 "and X has " << nvecs << " columns.");
209 }
210
211 std::vector<ScalarType> dotvec(nvecs);
212 MVT::MvDot(X,*MX,dotvec);
213 for (int i=0; i<nvecs; i++) {
214 normvec[i] = MT::squareroot( SCT::magnitude(dotvec[i]) );
215 }
216 }
217 }
218
219
241 virtual void project ( MV &X, Teuchos::RCP<MV> MX,
242 Teuchos::Array<Teuchos::RCP<DM> > C,
243 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const = 0;
244
245
246
249 virtual void project ( MV &X,
250 Teuchos::Array<Teuchos::RCP<DM> > C,
251 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const {
252 project(X,Teuchos::null,C,Q);
253 }
254
276 virtual int normalize ( MV &X, Teuchos::RCP<MV> MX,
277 Teuchos::RCP<DM> B ) const = 0;
278
279
282 virtual int normalize ( MV &X, Teuchos::RCP<DM> B ) const {
283 return normalize(X,Teuchos::null,B);
284 }
285
286
287 protected:
288 virtual int
290 Teuchos::RCP<MV> MX,
291 Teuchos::Array<Teuchos::RCP<DM> > C,
292 Teuchos::RCP<DM> B,
293 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const = 0;
294
295 virtual int
297 Teuchos::Array<Teuchos::RCP<DM> > C,
298 Teuchos::RCP<DM> B,
299 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const
300 {
301 return this->projectAndNormalizeWithMxImpl (X, Teuchos::null, C, B, Q);
302 }
303
304 public:
305
340 int
342 Teuchos::RCP<MV> MX,
343 Teuchos::Array<Teuchos::RCP<DM> > C,
344 Teuchos::RCP<DM> B,
345 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const
346 {
347 return this->projectAndNormalizeWithMxImpl (X, MX, C, B, Q);
348 }
349
351
353
356 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
357 orthonormError(const MV &X) const {
358 return orthonormError(X,Teuchos::null);
359 }
360
364 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
365 orthonormError(const MV &X, Teuchos::RCP<const MV> MX) const = 0;
366
369 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
370 orthogError(const MV &X1, const MV &X2) const {
371 return orthogError(X1,Teuchos::null,X2);
372 }
373
378 virtual typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
379 orthogError(const MV &X1, Teuchos::RCP<const MV> MX1, const MV &X2) const = 0;
380
382
383 };
384
385} // end of Belos namespace
386
387
388#endif
389
390// end of file BelosMatOrthoManager.hpp
Belos header file which uses auto-configuration information to include necessary C++ headers.
Full specialization of Belos::DenseMatTraits for Kokkos::DualView with arbitrary scalarType....
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.
Full specialization of Belos::DenseMatTraits for Teuchos::SerialDenseMatrix with ordinal type int and...
Collection of types and exceptions used within the Belos solvers.
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
virtual void project(MV &X, Teuchos::Array< Teuchos::RCP< DM > > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
This method calls project(X,Teuchos::null,C,Q); see documentation for that function.
virtual int normalize(MV &X, Teuchos::RCP< DM > B) const
This method calls normalize(X,Teuchos::null,B); see documentation for that function.
void innerProd(const MV &X, const MV &Y, DM &Z) const
Provides the inner product defining the orthogonality concepts, using the provided operator.
virtual int projectAndNormalizeImpl(MV &X, Teuchos::Array< Teuchos::RCP< DM > > C, Teuchos::RCP< DM > B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
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, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &normvec) const
Provides the norm induced by innerProd().
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 int normalize(MV &X, Teuchos::RCP< MV > MX, Teuchos::RCP< DM > B) const =0
This method takes a multivector X and attempts to compute an orthonormal basis for ,...
void innerProd(const MV &X, const MV &Y, Teuchos::RCP< const MV > MY, DM &Z) const
Provides the inner product defining the orthogonality concepts, using the provided operator....
MatOrthoManager(Teuchos::RCP< const OP > Op=Teuchos::null)
Default constructor.
Teuchos::RCP< const OP > _Op
virtual int projectAndNormalizeWithMxImpl(MV &X, Teuchos::RCP< MV > MX, Teuchos::Array< Teuchos::RCP< DM > > C, Teuchos::RCP< DM > B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const =0
void setOp(Teuchos::RCP< const OP > Op)
Set operator.
int projectAndNormalize(MV &X, Teuchos::RCP< MV > MX, Teuchos::Array< Teuchos::RCP< DM > > C, Teuchos::RCP< DM > 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 void project(MV &X, Teuchos::RCP< MV > MX, Teuchos::Array< Teuchos::RCP< DM > > 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, Teuchos::RCP< const MV > MX) const =0
This method computes the error in orthonormality of a multivector. The method has the option of explo...
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.
Teuchos::RCP< const OP > getOp() const
Get operator.
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.
virtual ~MatOrthoManager()
Destructor.
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