Belos Version of the Day
Loading...
Searching...
No Matches
BelosTsqrOrthoManager.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
12
13#ifndef __BelosTsqrOrthoManager_hpp
14#define __BelosTsqrOrthoManager_hpp
15
17// Belos doesn't have an SVQB orthomanager implemented yet, so we just
18// use a default orthomanager for the case where the inner product
19// matrix is nontrivial.
21
22
23namespace Belos {
24
46template<class Scalar, class MV>
48public:
50 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitude_type;
53 typedef MV multivector_type;
54
55 typedef Teuchos::SerialDenseMatrix<int, Scalar> mat_type;
56 typedef Teuchos::RCP<mat_type> mat_ptr;
57
66 virtual int
67 normalizeOutOfPlace (MV& X, MV& Q, mat_ptr B) const = 0;
68
87 virtual int
89 MV& X_out,
90 Teuchos::Array<mat_ptr> C,
91 mat_ptr B,
92 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const = 0;
93
96};
97
104template<class Scalar, class MV>
106 public OrthoManager<Scalar, MV>,
107 public OutOfPlaceNormalizerMixin<Scalar, MV>
108{
109public:
111 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitude_type;
114
115 typedef Teuchos::SerialDenseMatrix<int, Scalar> mat_type;
116 typedef Teuchos::RCP<mat_type> mat_ptr;
117
118 void setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& params) {
119 impl_.setParameterList (params);
120 }
121
122 Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList () {
123 return impl_.getNonconstParameterList ();
124 }
125
126 Teuchos::RCP<Teuchos::ParameterList> unsetParameterList () {
127 return impl_.unsetParameterList ();
128 }
129
137 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
138 return impl_.getValidParameters();
139 }
140
150 Teuchos::RCP<const Teuchos::ParameterList> getFastParameters() const {
151 return impl_.getFastParameters();
152 }
153
169 TsqrOrthoManager (const Teuchos::RCP<Teuchos::ParameterList>& params,
170 const std::string& label = "Belos") :
171 impl_ (params, label)
172 {}
173
178 TsqrOrthoManager (const std::string& label) :
179 impl_ (label)
180 {}
181
183 virtual ~TsqrOrthoManager() {}
184
206 void
208 {
209 impl_.setReorthogonalizationCallback (callback);
210 }
211
212 void innerProd (const MV &X, const MV &Y, mat_type& Z) const {
213 return impl_.innerProd (X, Y, Z);
214 }
215
216 void norm (const MV& X, std::vector<magnitude_type>& normVec) const {
217 return impl_.norm (X, normVec);
218 }
219
220 void
221 project (MV &X,
222 Teuchos::Array<mat_ptr> C,
223 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const
224 {
225 return impl_.project (X, C, Q);
226 }
227
228 int
229 normalize (MV &X, mat_ptr B) const
230 {
231 return impl_.normalize (X, B);
232 }
233
234protected:
235 virtual int
237 Teuchos::Array<mat_ptr> C,
238 mat_ptr B,
239 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const
240 {
241 return impl_.projectAndNormalize (X, C, B, Q);
242 }
243
244public:
261 int
262 normalizeOutOfPlace (MV& X, MV& Q, mat_ptr B) const
263 {
264 return impl_.normalizeOutOfPlace (X, Q, B);
265 }
266
287 int
289 MV& X_out,
290 Teuchos::Array<mat_ptr> C,
291 mat_ptr B,
292 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const
293 {
294 return impl_.projectAndNormalizeOutOfPlace (X_in, X_out, C, B, Q);
295 }
296
297 magnitude_type orthonormError (const MV &X) const {
298 return impl_.orthonormError (X);
299 }
300
301 magnitude_type orthogError (const MV &X1, const MV &X2) const {
302 return impl_.orthogError (X1, X2);
303 }
304
312 void setLabel (const std::string& label) {
313 impl_.setLabel (label);
314 }
315
316 const std::string& getLabel() const { return impl_.getLabel(); }
317
318private:
325
327 std::string label_;
328};
329
330
344template<class Scalar, class MV, class OP>
346 public MatOrthoManager<Scalar, MV, OP>,
347 public OutOfPlaceNormalizerMixin<Scalar, MV>
348{
349public:
351 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType magnitude_type;
356
357 typedef Teuchos::SerialDenseMatrix<int, Scalar> mat_type;
358 typedef Teuchos::RCP<mat_type> mat_ptr;
359
360private:
370
374
378
382
383public:
404 TsqrMatOrthoManager (const Teuchos::RCP<Teuchos::ParameterList>& params,
405 const std::string& label = "Belos",
406 Teuchos::RCP<const OP> Op = Teuchos::null) :
407 MatOrthoManager<Scalar, MV, OP> (Op),
408 tsqr_ (params, label),
409 pDgks_ (Teuchos::null) // Initialized lazily
410 {}
411
420 TsqrMatOrthoManager (const std::string& label = "Belos",
421 Teuchos::RCP<const OP> Op = Teuchos::null) :
422 MatOrthoManager<Scalar, MV, OP> (Op),
423 tsqr_ (label),
424 pDgks_ (Teuchos::null) // Initialized lazily
425 {}
426
429
437 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const {
438 return tsqr_.getValidParameters ();
439 }
440
450 Teuchos::RCP<const Teuchos::ParameterList> getFastParameters() {
451 return tsqr_.getFastParameters ();
452 }
453
454 void setParameterList (const Teuchos::RCP<Teuchos::ParameterList>& params) {
455 tsqr_.setParameterList (params);
456 }
457
458 const std::string& getLabel() const { return tsqr_.getLabel (); }
459
460 void
461 setOp (Teuchos::RCP<const OP> Op)
462 {
463 // We override the base class' setOp() so that the
464 // DGKSOrthoManager instance gets the new op.
465 //
466 // The base_type notation helps C++ resolve the name for a
467 // member function of a templated base class.
468 base_type::setOp (Op); // base class gets a copy of the Op too
469
470 if (! Op.is_null()) {
471 ensureDgksInit (); // Make sure the DGKS object has been initialized
472 pDgks_->setOp (Op);
473 }
474 }
475
476 Teuchos::RCP<const OP> getOp () const {
477 // The base_type notation helps C++ resolve the name for a
478 // member function of a templated base class.
479 return base_type::getOp();
480 }
481
482 void
483 project (MV &X,
484 Teuchos::RCP<MV> MX,
485 Teuchos::Array<mat_ptr> C,
486 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const
487 {
488 if (getOp().is_null()) {
489 tsqr_.project (X, C, Q);
490 if (! MX.is_null()) {
491 // MX gets a copy of X; M is the identity operator.
492 MVT::Assign (X, *MX);
493 }
494 } else {
495 ensureDgksInit ();
496 pDgks_->project (X, MX, C, Q);
497 }
498 }
499
500 void
501 project (MV &X,
502 Teuchos::Array<mat_ptr> C,
503 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const
504 {
505 project (X, Teuchos::null, C, Q);
506 }
507
508 int
509 normalize (MV& X, Teuchos::RCP<MV> MX, mat_ptr B) const
510 {
511 if (getOp().is_null()) {
512 const int rank = tsqr_.normalize (X, B);
513 if (! MX.is_null()) {
514 // MX gets a copy of X; M is the identity operator.
515 MVT::Assign (X, *MX);
516 }
517 return rank;
518 } else {
519 ensureDgksInit ();
520 return pDgks_->normalize (X, MX, B);
521 }
522 }
523
524 int normalize (MV& X, mat_ptr B) const {
525 return normalize (X, Teuchos::null, B);
526 }
527
528 // Attempted fix for a warning about hiding
529 // OrthoManager::projectAndNormalize(). Unfortunately, this fix turns out
530 // to produce a compilation error with cray++, see bug #6129,
531 // <https://software.sandia.gov/bugzilla/show_bug.cgi?id=6129>.
532 //using Belos::OrthoManager<Scalar, MV>::projectAndNormalize;
533
534protected:
535 virtual int
537 Teuchos::RCP<MV> MX,
538 Teuchos::Array<mat_ptr> C,
539 mat_ptr B,
540 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const
541 {
542 if (getOp().is_null()) {
543 const int rank = tsqr_.projectAndNormalize (X, C, B, Q);
544 if (! MX.is_null()) {
545 // MX gets a copy of X; M is the identity operator.
546 MVT::Assign (X, *MX);
547 }
548 return rank;
549 } else {
550 ensureDgksInit ();
551 return pDgks_->projectAndNormalize (X, MX, C, B, Q);
552 }
553 }
554
555public:
556 int
557 normalizeOutOfPlace (MV& X, MV& Q, mat_ptr B) const
558 {
559 if (getOp().is_null()) {
560 return tsqr_.normalizeOutOfPlace (X, Q, B);
561 } else {
562 // DGKS normalizes in place, so we have to copy.
563 ensureDgksInit ();
564 const int rank = pDgks_->normalize (X, B);
565 MVT::Assign (X, Q);
566 return rank;
567 }
568 }
569
570 int
572 MV& X_out,
573 Teuchos::Array<mat_ptr> C,
574 mat_ptr B,
575 Teuchos::ArrayView<Teuchos::RCP<const MV> > Q) const
576 {
577 using Teuchos::null;
578
579 if (getOp().is_null()) {
580 return tsqr_.projectAndNormalizeOutOfPlace (X_in, X_out, C, B, Q);
581 } else {
582 // DGKS normalizes in place, so we have to copy.
583 ensureDgksInit ();
584 const int rank = pDgks_->projectAndNormalize (X_in, null, C, B, Q);
585 MVT::Assign (X_in, X_out);
586 return rank;
587 }
588 }
589
591 orthonormError (const MV &X, Teuchos::RCP<const MV> MX) const
592 {
593 if (getOp().is_null()) {
594 return tsqr_.orthonormError (X); // Ignore MX
595 } else {
596 ensureDgksInit ();
597 return pDgks_->orthonormError (X, MX);
598 }
599 }
600
601 magnitude_type orthonormError (const MV &X) const {
602 return orthonormError (X, Teuchos::null);
603 }
604
605 magnitude_type orthogError (const MV &X1, const MV &X2) const {
606 return orthogError (X1, Teuchos::null, X2);
607 }
608
610 orthogError (const MV &X1,
611 Teuchos::RCP<const MV> MX1,
612 const MV &X2) const
613 {
614 if (getOp ().is_null ()) {
615 // Ignore MX1, since we don't need to write to it.
616 return tsqr_.orthogError (X1, X2);
617 } else {
618 ensureDgksInit ();
619 return pDgks_->orthogError (X1, MX1, X2);
620 }
621 }
622
623 void
624 setLabel (const std::string& label)
625 {
626 tsqr_.setLabel (label);
627
628 // Make sure DGKS gets the new label, if it's initialized.
629 // Otherwise, it will get the new label on initialization.
630 if (! pDgks_.is_null ()) {
631 pDgks_->setLabel (label);
632 }
633 }
634
635private:
637 void
638 ensureDgksInit () const
639 {
640 // NOTE (mfh 11 Jan 2011) DGKS has a parameter that needs to be
641 // set. For now, we just use the default value of the parameter.
642 if (pDgks_.is_null ()) {
643 pDgks_ = Teuchos::rcp (new dgks_type (getLabel (), getOp ()));
644 }
645 }
646
654 mutable tsqr_type tsqr_;
655
661 mutable Teuchos::RCP<dgks_type> pDgks_;
662};
663
664} // namespace Belos
665
666#endif // __BelosTsqrOrthoManager_hpp
Classical Gram-Schmidt (with DGKS correction) implementation of the Belos::OrthoManager class.
Orthogonalization manager back end based on Tall Skinny QR (TSQR)
Belos's templated virtual class for providing routines for orthogonalization and orthonormzalition of...
void setOp(Teuchos::RCP< const OP > Op)
Set operator.
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...
Mixin for out-of-place orthogonalization.
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitude_type
MV multivector_type
Multivector type with which this class was specialized.
virtual int projectAndNormalizeOutOfPlace(MV &X_in, MV &X_out, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const =0
Project and normalize X_in into X_out.
virtual int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B) const =0
Normalize X into Q*B.
Teuchos::SerialDenseMatrix< int, Scalar > mat_type
virtual ~OutOfPlaceNormalizerMixin()
Trivial virtual destructor, to silence compiler warnings.
MatOrthoManager subclass using TSQR or DGKS.
int normalize(MV &X, Teuchos::RCP< MV > MX, mat_ptr B) const
virtual ~TsqrMatOrthoManager()
Destructor (declared virtual for memory safety of derived classes).
magnitude_type orthogError(const MV &X1, Teuchos::RCP< const MV > MX1, const MV &X2) const
This method computes the error in orthogonality of two multivectors. The method has the option of exp...
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters()
Get "fast" parameters for TsqrMatOrthoManager.
int normalize(MV &X, mat_ptr B) const
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &params)
void project(MV &X, Teuchos::Array< mat_ptr > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
Teuchos::SerialDenseMatrix< int, Scalar > mat_type
TsqrMatOrthoManager(const std::string &label="Belos", Teuchos::RCP< const OP > Op=Teuchos::null)
Constructor (that sets default parameters).
magnitude_type orthonormError(const MV &X) const
This method computes the error in orthonormality of a multivector.
int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B) const
Normalize X into Q*B.
void setLabel(const std::string &label)
This method sets the label used by the timers in the orthogonalization manager.
Teuchos::RCP< const OP > getOp() const
MV multivector_type
Multivector type with which this class was specialized.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get default parameters for TsqrMatOrthoManager.
magnitude_type orthogError(const MV &X1, const MV &X2) const
This method computes the error in orthogonality of two multivectors. This method.
void setOp(Teuchos::RCP< const OP > Op)
const std::string & getLabel() const
This method returns the label being used by the timers in the orthogonalization manager.
magnitude_type orthonormError(const MV &X, Teuchos::RCP< const MV > MX) const
This method computes the error in orthonormality of a multivector. The method has the option of explo...
TsqrMatOrthoManager(const Teuchos::RCP< Teuchos::ParameterList > &params, const std::string &label="Belos", Teuchos::RCP< const OP > Op=Teuchos::null)
Constructor (that sets user-specified parameters).
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitude_type
void project(MV &X, Teuchos::RCP< MV > MX, Teuchos::Array< mat_ptr > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
int projectAndNormalizeOutOfPlace(MV &X_in, MV &X_out, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
Project and normalize X_in into X_out.
Teuchos::RCP< mat_type > mat_ptr
OP operator_type
Operator type with which this class was specialized.
virtual int projectAndNormalizeWithMxImpl(MV &X, Teuchos::RCP< MV > MX, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
TSQR-based OrthoManager subclass.
TsqrOrthoManager(const std::string &label)
Constructor (that sets default parameters).
magnitude_type orthonormError(const MV &X) const
This method computes the error in orthonormality of a multivector.
void project(MV &X, Teuchos::Array< mat_ptr > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
void norm(const MV &X, std::vector< magnitude_type > &normVec) const
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitude_type
const std::string & getLabel() const
This method returns the label being used by the timers in the orthogonalization manager.
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters() const
Get "fast" parameters for TsqrOrthoManager.
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
void innerProd(const MV &X, const MV &Y, mat_type &Z) const
Provides the inner product defining the orthogonality concepts.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Default valid parameter list.
virtual int projectAndNormalizeImpl(MV &X, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
magnitude_type orthogError(const MV &X1, const MV &X2) const
This method computes the error in orthogonality of two multivectors.
int normalize(MV &X, mat_ptr B) const
int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B) const
Normalize X into Q*B, overwriting X with invalid values.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &params)
TsqrOrthoManager(const Teuchos::RCP< Teuchos::ParameterList > &params, const std::string &label="Belos")
Constructor (that sets user-specified parameters).
Teuchos::SerialDenseMatrix< int, Scalar > mat_type
virtual ~TsqrOrthoManager()
Destructor, declared virtual for safe inheritance.
int projectAndNormalizeOutOfPlace(MV &X_in, MV &X_out, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
Project and normalize X_in into X_out; overwrite X_in.
Teuchos::RCP< mat_type > mat_ptr
void setReorthogonalizationCallback(const Teuchos::RCP< ReorthogonalizationCallback< Scalar > > &callback)
Set callback to be invoked on reorthogonalization.
void setLabel(const std::string &label)
Set the label for (the timers for) this orthogonalization manager, and create new timers if the label...

Generated for Belos by doxygen 1.9.8