Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
23 namespace Belos {
24 
46 template<class Scalar, class MV>
48 public:
49  typedef Scalar scalar_type;
53  typedef MV multivector_type;
54 
57 
66  virtual int
67  normalizeOutOfPlace (MV& X, MV& Q, mat_ptr B) const = 0;
68 
87  virtual int
89  MV& X_out,
91  mat_ptr B,
93 
96 };
97 
104 template<class Scalar, class MV>
106  public OrthoManager<Scalar, MV>,
107  public OutOfPlaceNormalizerMixin<Scalar, MV>
108 {
109 public:
110  typedef Scalar scalar_type;
113  typedef MV multivector_type;
114 
117 
119  impl_.setParameterList (params);
120  }
121 
123  return impl_.getNonconstParameterList ();
124  }
125 
127  return impl_.unsetParameterList ();
128  }
129 
138  return impl_.getValidParameters();
139  }
140 
151  return impl_.getFastParameters();
152  }
153 
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,
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 
234 protected:
235  virtual int
238  mat_ptr B,
240  {
241  return impl_.projectAndNormalize (X, C, B, Q);
242  }
243 
244 public:
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,
291  mat_ptr B,
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 
318 private:
324  mutable TsqrOrthoManagerImpl<Scalar, MV> impl_;
325 
327  std::string label_;
328 };
329 
330 
344 template<class Scalar, class MV, class OP>
346  public MatOrthoManager<Scalar, MV, OP>,
347  public OutOfPlaceNormalizerMixin<Scalar, MV>
348 {
349 public:
350  typedef Scalar scalar_type;
353  typedef MV multivector_type;
355  typedef OP operator_type;
356 
359 
360 private:
370 
374 
378 
382 
383 public:
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 
428  virtual ~TsqrMatOrthoManager() {}
429 
438  return tsqr_.getValidParameters ();
439  }
440 
451  return tsqr_.getFastParameters ();
452  }
453 
455  tsqr_.setParameterList (params);
456  }
457 
458  const std::string& getLabel() const { return tsqr_.getLabel (); }
459 
460  void
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 
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,
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,
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 
534 protected:
535  virtual int
537  Teuchos::RCP<MV> MX,
539  mat_ptr B,
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 
555 public:
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,
574  mat_ptr B,
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,
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 
635 private:
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
Teuchos::RCP< mat_type > mat_ptr
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.
void project(MV &X, Teuchos::RCP< MV > MX, Teuchos::Array< mat_ptr > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
int projectAndNormalize(MV &X, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q)
Project X against Q and normalize X.
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
Interface of callback invoked by TsqrOrthoManager on reorthogonalization.
virtual ~TsqrMatOrthoManager()
Destructor (declared virtual for memory safety of derived classes).
bool is_null(const boost::shared_ptr< T > &p)
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
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.
void project(MV &X, Teuchos::Array< mat_ptr > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q)
Compute and .
magnitude_type orthogError(const MV &X1, const MV &X2) const
Return the Frobenius norm of the inner product of X1 with itself.
void norm(const MV &X, std::vector< magnitude_type > &normVec) const
void project(MV &X, Teuchos::Array< mat_ptr > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
Mixin for out-of-place orthogonalization.
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters()
Get &quot;fast&quot; parameters for TsqrMatOrthoManager.
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &params)
Set parameters from the given parameter list.
const std::string & getLabel() const
This method returns the label being used by the timers in the orthogonalization manager.
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitude_type
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters()
Get &quot;fast&quot; parameters for TsqrOrthoManagerImpl.
TSQR-based OrthoManager subclass implementation.
virtual ~OutOfPlaceNormalizerMixin()
Trivial virtual destructor, to silence compiler warnings.
int normalize(MV &X, mat_ptr B)
Orthogonalize the columns of X in place.
int normalize(MV &X, mat_ptr B) const
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...
OP operator_type
Operator type with which this class was specialized.
void setLabel(const std::string &label)
Set the label for timers.
Teuchos::RCP< mat_type > mat_ptr
void setLabel(const std::string &label)
Set the label for (the timers for) this orthogonalization manager, and create new timers if the label...
const std::string & getLabel() const
This method returns the label being used by the timers in the orthogonalization manager.
Teuchos::SerialDenseMatrix< int, Scalar > mat_type
static void Assign(const MV &A, MV &mv)
mv := A
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Default valid parameter list.
Traits class which defines basic operations on multivectors.
TsqrOrthoManager(const std::string &label)
Constructor (that sets default parameters).
int normalize(MV &X, Teuchos::RCP< MV > MX, mat_ptr B) const
Belos&#39;s templated virtual class for providing routines for orthogonalization and orthonormzalition of...
int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B) const
Normalize X into Q*B, overwriting X with invalid values.
Classical Gram-Schmidt (with DGKS correction) implementation of the Belos::OrthoManager class...
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitude_type
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void innerProd(const MV &X, const MV &Y, mat_type &Z) const
Provides the inner product defining the orthogonality concepts.
void setOp(Teuchos::RCP< const OP > Op)
void setReorthogonalizationCallback(const Teuchos::RCP< ReorthogonalizationCallback< Scalar > > &callback)
Set callback to be invoked on reorthogonalization.
virtual int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B) const =0
Normalize X into Q*B.
magnitude_type orthonormError(const MV &X) const
This method computes the error in orthonormality of a multivector.
const std::string & getLabel() const
Get the label for timers (if timers are enabled).
magnitude_type orthonormError(const MV &X) const
Return .
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Get default parameters for TsqrMatOrthoManager.
Teuchos::ScalarTraits< Scalar >::magnitudeType magnitude_type
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.
int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B) const
Normalize X into Q*B.
virtual ~TsqrOrthoManager()
Destructor, declared virtual for safe inheritance.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Default valid parameter list.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &params)
int normalize(MV &X, mat_ptr B) const
MV multivector_type
Multivector type with which this class was specialized.
Teuchos::SerialDenseMatrix< int, Scalar > mat_type
virtual int projectAndNormalizeImpl(MV &X, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
MV multivector_type
Multivector type with which this class was specialized.
void setLabel(const std::string &label)
This method sets the label used by the timers in the orthogonalization manager.
TsqrMatOrthoManager(const std::string &label="Belos", Teuchos::RCP< const OP > Op=Teuchos::null)
Constructor (that sets default parameters).
Teuchos::SerialDenseMatrix< int, Scalar > mat_type
Teuchos::RCP< const OP > getOp() const
Get operator.
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).
An implementation of the Belos::MatOrthoManager that performs orthogonalization using (potentially) m...
Orthogonalization manager back end based on Tall Skinny QR (TSQR)
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &params)
magnitude_type orthogError(const MV &X1, const MV &X2) const
This method computes the error in orthogonality of two multivectors. This method. ...
Belos&#39;s templated virtual class for providing routines for orthogonalization and orthonormzalition of...
int projectAndNormalizeOutOfPlace(MV &X_in, MV &X_out, Teuchos::Array< mat_ptr > C, mat_ptr B, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q)
Project and normalize X_in into X_out; overwrite X_in.
int normalizeOutOfPlace(MV &X, MV &Q, mat_ptr B)
Normalize X into Q*B, overwriting X.
MatOrthoManager subclass using TSQR or DGKS.
Teuchos::RCP< const Teuchos::ParameterList > getFastParameters() const
Get &quot;fast&quot; parameters for TsqrOrthoManager.
Teuchos::RCP< const OP > getOp() const
void setOp(Teuchos::RCP< const OP > Op)
Set operator.
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...
TsqrOrthoManager(const Teuchos::RCP< Teuchos::ParameterList > &params, const std::string &label="Belos")
Constructor (that sets user-specified parameters).
void project(MV &X, Teuchos::Array< mat_ptr > C, Teuchos::ArrayView< Teuchos::RCP< const MV > > Q) const
magnitude_type orthonormError(const MV &X) const
This method computes the error in orthonormality of a multivector.
TSQR-based OrthoManager subclass.
magnitude_type orthogError(const MV &X1, const MV &X2) const
This method computes the error in orthogonality of two multivectors.
bool is_null() const

Generated on Thu Oct 24 2024 09:25:34 for Belos by doxygen 1.8.5