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 //
4 // Belos: Block Linear Solvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 
44 
45 #ifndef __BelosTsqrOrthoManager_hpp
46 #define __BelosTsqrOrthoManager_hpp
47 
49 // Belos doesn't have an SVQB orthomanager implemented yet, so we just
50 // use a default orthomanager for the case where the inner product
51 // matrix is nontrivial.
52 #include "BelosDGKSOrthoManager.hpp"
53 
54 
55 namespace Belos {
56 
78  template<class Scalar, class MV>
80  public:
81  typedef Scalar scalar_type;
85  typedef MV multivector_type;
86 
89 
98  virtual int
99  normalizeOutOfPlace (MV& X, MV& Q, mat_ptr B) const = 0;
100 
119  virtual int
121  MV& X_out,
123  mat_ptr B,
125 
128  };
129 
136  template<class Scalar, class MV>
138  public OrthoManager<Scalar, MV>,
139  public OutOfPlaceNormalizerMixin<Scalar, MV>,
141  {
142  public:
143  typedef Scalar scalar_type;
146  typedef MV multivector_type;
147 
150 
152  impl_.setParameterList (params);
153  }
154 
156  return impl_.getNonconstParameterList ();
157  }
158 
160  return impl_.unsetParameterList ();
161  }
162 
171  return impl_.getValidParameters();
172  }
173 
184  return impl_.getFastParameters();
185  }
186 
204  const std::string& label = "Belos") :
205  impl_ (params, label)
206  {}
207 
212  TsqrOrthoManager (const std::string& label) :
213  impl_ (label)
214  {}
215 
217  virtual ~TsqrOrthoManager() {}
218 
240  void
242  {
243  impl_.setReorthogonalizationCallback (callback);
244  }
245 
246  void innerProd (const MV &X, const MV &Y, mat_type& Z) const {
247  return impl_.innerProd (X, Y, Z);
248  }
249 
250  void norm (const MV& X, std::vector<magnitude_type>& normVec) const {
251  return impl_.norm (X, normVec);
252  }
253 
254  void
255  project (MV &X,
258  {
259  return impl_.project (X, C, Q);
260  }
261 
262  int
263  normalize (MV &X, mat_ptr B) const
264  {
265  return impl_.normalize (X, B);
266  }
267 
268  int
271  mat_ptr B,
273  {
274  return impl_.projectAndNormalize (X, C, B, Q);
275  }
276 
293  int
294  normalizeOutOfPlace (MV& X, MV& Q, mat_ptr B) const
295  {
296  return impl_.normalizeOutOfPlace (X, Q, B);
297  }
298 
319  int
321  MV& X_out,
323  mat_ptr B,
325  {
326  return impl_.projectAndNormalizeOutOfPlace (X_in, X_out, C, B, Q);
327  }
328 
329  magnitude_type orthonormError (const MV &X) const {
330  return impl_.orthonormError (X);
331  }
332 
333  magnitude_type orthogError (const MV &X1, const MV &X2) const {
334  return impl_.orthogError (X1, X2);
335  }
336 
344  void setLabel (const std::string& label) {
345  impl_.setLabel (label);
346  }
347 
348  const std::string& getLabel() const { return impl_.getLabel(); }
349 
350  private:
356  mutable TsqrOrthoManagerImpl<Scalar, MV> impl_;
357 
359  std::string label_;
360  };
361 
362 
376  template<class Scalar, class MV, class OP>
378  public MatOrthoManager<Scalar, MV, OP>,
379  public OutOfPlaceNormalizerMixin<Scalar, MV>,
381  {
382  public:
383  typedef Scalar scalar_type;
386  typedef MV multivector_type;
388  typedef OP operator_type;
389 
392 
393  private:
403 
407 
411 
415 
416  public:
438  const std::string& label = "Belos",
439  Teuchos::RCP<const OP> Op = Teuchos::null) :
440  MatOrthoManager<Scalar, MV, OP> (Op),
441  tsqr_ (params, label),
442  pDgks_ (Teuchos::null) // Initialized lazily
443  {}
444 
453  TsqrMatOrthoManager (const std::string& label = "Belos",
454  Teuchos::RCP<const OP> Op = Teuchos::null) :
455  MatOrthoManager<Scalar, MV, OP> (Op),
456  tsqr_ (label),
457  pDgks_ (Teuchos::null) // Initialized lazily
458  {}
459 
461  virtual ~TsqrMatOrthoManager() {}
462 
471  return tsqr_.getValidParameters ();
472  }
473 
484  return tsqr_.getFastParameters ();
485  }
486 
488  tsqr_.setParameterList (params);
489  }
490 
491  const std::string& getLabel() const { return tsqr_.getLabel (); }
492 
493  void
495  {
496  // We override the base class' setOp() so that the
497  // DGKSOrthoManager instance gets the new op.
498  //
499  // The base_type notation helps C++ resolve the name for a
500  // member function of a templated base class.
501  base_type::setOp (Op); // base class gets a copy of the Op too
502 
503  if (! Op.is_null()) {
504  ensureDgksInit (); // Make sure the DGKS object has been initialized
505  pDgks_->setOp (Op);
506  }
507  }
508 
510  // The base_type notation helps C++ resolve the name for a
511  // member function of a templated base class.
512  return base_type::getOp();
513  }
514 
515  void
516  project (MV &X,
517  Teuchos::RCP<MV> MX,
520  {
521  if (getOp().is_null()) {
522  tsqr_.project (X, C, Q);
523  if (! MX.is_null()) {
524  // MX gets a copy of X; M is the identity operator.
525  MVT::Assign (X, *MX);
526  }
527  } else {
528  ensureDgksInit ();
529  pDgks_->project (X, MX, C, Q);
530  }
531  }
532 
533  void
534  project (MV &X,
537  {
538  project (X, Teuchos::null, C, Q);
539  }
540 
541  int
542  normalize (MV& X, Teuchos::RCP<MV> MX, mat_ptr B) const
543  {
544  if (getOp().is_null()) {
545  const int rank = tsqr_.normalize (X, B);
546  if (! MX.is_null()) {
547  // MX gets a copy of X; M is the identity operator.
548  MVT::Assign (X, *MX);
549  }
550  return rank;
551  } else {
552  ensureDgksInit ();
553  return pDgks_->normalize (X, MX, B);
554  }
555  }
556 
557  int normalize (MV& X, mat_ptr B) const {
558  return normalize (X, Teuchos::null, B);
559  }
560 
561  int
563  Teuchos::RCP<MV> MX,
565  mat_ptr B,
567  {
568  if (getOp().is_null()) {
569  const int rank = tsqr_.projectAndNormalize (X, C, B, Q);
570  if (! MX.is_null()) {
571  // MX gets a copy of X; M is the identity operator.
572  MVT::Assign (X, *MX);
573  }
574  return rank;
575  } else {
576  ensureDgksInit ();
577  return pDgks_->projectAndNormalize (X, MX, C, B, Q);
578  }
579  }
580 
581  int
582  normalizeOutOfPlace (MV& X, MV& Q, mat_ptr B) const
583  {
584  if (getOp().is_null()) {
585  return tsqr_.normalizeOutOfPlace (X, Q, B);
586  } else {
587  // DGKS normalizes in place, so we have to copy.
588  ensureDgksInit ();
589  const int rank = pDgks_->normalize (X, B);
590  MVT::Assign (X, Q);
591  return rank;
592  }
593  }
594 
595  int
597  MV& X_out,
599  mat_ptr B,
601  {
602  using Teuchos::null;
603 
604  if (getOp().is_null()) {
605  return tsqr_.projectAndNormalizeOutOfPlace (X_in, X_out, C, B, Q);
606  } else {
607  // DGKS normalizes in place, so we have to copy.
608  ensureDgksInit ();
609  const int rank = pDgks_->projectAndNormalize (X_in, null, C, B, Q);
610  MVT::Assign (X_in, X_out);
611  return rank;
612  }
613  }
614 
616  orthonormError (const MV &X, Teuchos::RCP<const MV> MX) const
617  {
618  if (getOp().is_null()) {
619  return tsqr_.orthonormError (X); // Ignore MX
620  } else {
621  ensureDgksInit ();
622  return pDgks_->orthonormError (X, MX);
623  }
624  }
625 
626  magnitude_type orthonormError (const MV &X) const {
627  return orthonormError (X, Teuchos::null);
628  }
629 
630  magnitude_type orthogError (const MV &X1, const MV &X2) const {
631  return orthogError (X1, Teuchos::null, X2);
632  }
633 
635  orthogError (const MV &X1,
637  const MV &X2) const
638  {
639  if (getOp().is_null()) {
640  // Ignore MX1, since we don't need to write to it.
641  return tsqr_.orthogError (X1, X2);
642  } else {
643  ensureDgksInit ();
644  return pDgks_->orthogError (X1, MX1, X2);
645  }
646  }
647 
648  void
649  setLabel (const std::string& label)
650  {
651  tsqr_.setLabel (label);
652 
653  // Make sure DGKS gets the new label, if it's initialized.
654  // Otherwise, it will get the new label on initialization.
655  if (! pDgks_.is_null()) {
656  pDgks_->setLabel (label);
657  }
658  }
659 
660  private:
662  void
663  ensureDgksInit () const
664  {
665  // NOTE (mfh 11 Jan 2011) DGKS has a parameter that needs to be
666  // set. For now, we just use the default value of the
667  // parameter.
668  if (pDgks_.is_null()) {
669  pDgks_ = Teuchos::rcp (new dgks_type (getLabel(), getOp()));
670  }
671  }
672 
680  mutable tsqr_type tsqr_;
681 
686  mutable Teuchos::RCP<dgks_type> pDgks_;
687  };
688 
689 } // namespace Belos
690 
691 #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)
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 .
int projectAndNormalize(MV &X, Teuchos::RCP< MV > MX, 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
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
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 projectAndNormalize(MV &X, 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)
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