Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_DefaultScaledAdjointLinearOp_decl.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef THYRA_DEFAULT_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
00030 #define THYRA_DEFAULT_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
00031 
00032 
00033 #include "Thyra_ScaledAdjointLinearOpBase.hpp"
00034 #include "Teuchos_ConstNonconstObjectContainer.hpp"
00035 
00036 
00037 namespace Thyra {
00038 
00039 
00112 template<class Scalar>
00113 class DefaultScaledAdjointLinearOp
00114   : virtual public ScaledAdjointLinearOpBase<Scalar>
00115 {
00116 public:
00117 
00120 
00127   DefaultScaledAdjointLinearOp();
00128 
00135   DefaultScaledAdjointLinearOp(
00136     const Scalar &scalar,
00137     const EOpTransp &transp,
00138     const RCP<LinearOpBase<Scalar> > &Op
00139     );
00140 
00147   DefaultScaledAdjointLinearOp(
00148     const Scalar &scalar,
00149     const EOpTransp &transp,
00150     const RCP<const LinearOpBase<Scalar> > &Op
00151     );
00152 
00174   void initialize(
00175     const Scalar &scalar,
00176     const EOpTransp &transp,
00177     const RCP<LinearOpBase<Scalar> > &Op
00178     );
00179   
00200   void initialize(
00201  const Scalar &scalar
00202  ,const EOpTransp &transp
00203  ,const RCP<const LinearOpBase<Scalar> > &Op
00204     );
00205 
00209   RCP<LinearOpBase<Scalar> > getNonconstOp();
00210 
00214   RCP<const LinearOpBase<Scalar> > getOp() const;
00215 
00222   void uninitialize();
00223 
00225 
00228                                                 
00233   std::string description() const;
00234 
00243   void describe(
00244     Teuchos::FancyOStream &out,
00245     const Teuchos::EVerbosityLevel verbLevel
00246     ) const;
00247 
00249 
00252 
00260   RCP<const VectorSpaceBase<Scalar> > range() const;
00261 
00269   RCP<const VectorSpaceBase<Scalar> > domain() const;
00270 
00272   RCP<const LinearOpBase<Scalar> > clone() const;
00273 
00275 
00278 
00280   Scalar overallScalar() const;
00282   EOpTransp overallTransp() const;
00284   RCP<LinearOpBase<Scalar> > getNonconstOrigOp();
00286   RCP<const LinearOpBase<Scalar> > getOrigOp() const;
00287 
00289 
00290 protected:
00291   
00294 
00303   bool opSupportedImpl(EOpTransp M_trans) const;
00304 
00313  void applyImpl(
00314    const EOpTransp M_trans,
00315    const MultiVectorBase<Scalar> &X,
00316    const Ptr<MultiVectorBase<Scalar> > &Y,
00317    const Scalar alpha,
00318    const Scalar beta
00319    ) const;
00320 
00322 
00323 private:
00324 
00325   // ////////////////////////////////
00326   // Private types
00327 
00328   template <class Scalar2>
00329   struct ScalarETransp {
00330     Scalar2   scalar;
00331     EOpTransp   transp;
00332     ScalarETransp()
00333       {}
00334     ScalarETransp( const Scalar2 &_scalar, const EOpTransp &_transp )
00335       : scalar(_scalar), transp(_transp)
00336       {}
00337   };
00338 
00339   typedef std::vector<ScalarETransp<Scalar> >  allScalarETransp_t;
00340 
00341   typedef Teuchos::ConstNonconstObjectContainer<LinearOpBase<Scalar> > CNLOC;
00342   
00343   // ////////////////////////////////
00344   // Private data members
00345 
00346   CNLOC origOp_;
00347   Scalar overallScalar_;
00348   EOpTransp overallTransp_;
00349   int my_index_;
00350   
00351  RCP<allScalarETransp_t> allScalarETransp_;
00352   
00353   // ////////////////////////////////
00354   // Private member functions
00355 
00356   void initializeImpl(
00357     const Scalar &scalar,
00358     const EOpTransp &transp,
00359     const RCP<const LinearOpBase<Scalar> > &Op,
00360     const bool isConst
00361     );
00362   CNLOC getOpImpl() const;
00363   void assertInitialized() const;
00364 
00365   // Not defined and not to be called
00366   DefaultScaledAdjointLinearOp(const DefaultScaledAdjointLinearOp<Scalar>&);
00367   DefaultScaledAdjointLinearOp<Scalar>& operator=(const DefaultScaledAdjointLinearOp<Scalar>&);
00368 
00369 };
00370 
00371 
00387 template<class Scalar>
00388 RCP<LinearOpBase<Scalar> >
00389 nonconstScale(
00390   const Scalar &scalar,
00391   const RCP<LinearOpBase<Scalar> > &Op,
00392   const std::string &label = ""
00393   );
00394 
00395 
00411 template<class Scalar>
00412 RCP<const LinearOpBase<Scalar> >
00413 scale(
00414   const Scalar &scalar,
00415   const RCP<const LinearOpBase<Scalar> > &Op,
00416   const std::string &label = ""
00417   );
00418 
00419 
00435 template<class Scalar>
00436 RCP<LinearOpBase<Scalar> >
00437 nonconstAdjoint(
00438   const RCP<LinearOpBase<Scalar> > &Op,
00439   const std::string &label = ""
00440   );
00441 
00442 
00458 template<class Scalar>
00459 RCP<const LinearOpBase<Scalar> >
00460 adjoint(
00461   const RCP<const LinearOpBase<Scalar> > &Op,
00462   const std::string &label = ""
00463   );
00464 
00465 
00481 template<class Scalar>
00482 RCP<LinearOpBase<Scalar> >
00483 nonconstTranspose(
00484   const RCP<LinearOpBase<Scalar> > &Op,
00485   const std::string &label = ""
00486   );
00487 
00488 
00504 template<class Scalar>
00505 RCP<const LinearOpBase<Scalar> >
00506 transpose(
00507   const RCP<const LinearOpBase<Scalar> > &Op,
00508   const std::string &label = ""
00509   );
00510 
00511 
00528 template<class Scalar>
00529 RCP<LinearOpBase<Scalar> >
00530 nonconstScaleAndAdjoint(
00531   const Scalar &scalar, const EOpTransp &transp,
00532   const RCP<LinearOpBase<Scalar> > &Op,
00533   const std::string &label = ""
00534   );
00535 
00536 
00553 template<class Scalar>
00554 RCP<const LinearOpBase<Scalar> >
00555 scaleAndAdjoint(
00556   const Scalar &scalar, const EOpTransp &transp,
00557   const RCP<const LinearOpBase<Scalar> > &Op,
00558   const std::string &label = ""
00559   );
00560 
00561 
00562 // /////////////////////////////////
00563 // Inline members
00564 
00565 
00566 template<class Scalar>
00567 inline
00568 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp()
00569   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00570   ,overallTransp_(NOTRANS)
00571 {}
00572 
00573 
00574 template<class Scalar>
00575 inline
00576 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp(
00577   const Scalar &scalar
00578   ,const EOpTransp &transp
00579   ,const RCP<LinearOpBase<Scalar> > &Op
00580   )
00581   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00582   ,overallTransp_(NOTRANS)
00583 {
00584   this->initialize(scalar,transp,Op);
00585 }
00586 
00587 
00588 template<class Scalar>
00589 inline
00590 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp(
00591   const Scalar &scalar
00592   ,const EOpTransp &transp
00593   ,const RCP<const LinearOpBase<Scalar> > &Op
00594   )
00595   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00596   ,overallTransp_(NOTRANS)
00597 {
00598   this->initialize(scalar,transp,Op);
00599 }
00600 
00601 
00602 template<class Scalar>
00603 inline
00604 void DefaultScaledAdjointLinearOp<Scalar>::assertInitialized() const
00605 {
00606 #ifdef TEUCHOS_DEBUG
00607   TEST_FOR_EXCEPT( origOp_.getConstObj().get() == NULL );
00608 #endif
00609 }
00610 
00611 
00612 } // end namespace Thyra
00613 
00614 
00615 // /////////////////////////////////
00616 // Inline non-members
00617 
00618 
00619 template<class Scalar> inline
00620 Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00621 Thyra::nonconstScale(
00622   const Scalar &scalar,
00623   const RCP<LinearOpBase<Scalar> > &Op,
00624   const std::string &label
00625   )
00626 {
00627   RCP<Thyra::LinearOpBase<Scalar> >
00628     salo = Teuchos::rcp(
00629       new DefaultScaledAdjointLinearOp<Scalar>(
00630         scalar,NOTRANS,Op
00631         )
00632       );
00633   if (label.length())
00634     salo->setObjectLabel(label);
00635   return salo;
00636 }
00637 
00638 
00639 template<class Scalar> inline
00640 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00641 Thyra::scale(
00642   const Scalar &scalar,
00643   const RCP<const LinearOpBase<Scalar> > &Op,
00644   const std::string &label
00645   )
00646 {
00647   RCP<Thyra::LinearOpBase<Scalar> >
00648     salo = Teuchos::rcp(
00649     new DefaultScaledAdjointLinearOp<Scalar>(scalar,NOTRANS,Op)
00650     );
00651   if (label.length())
00652     salo->setObjectLabel(label);
00653   return salo;
00654 }
00655 
00656 
00657 template<class Scalar> inline
00658 Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00659 Thyra::nonconstAdjoint(
00660   const RCP<LinearOpBase<Scalar> > &Op,
00661   const std::string &label
00662   )
00663 {
00664   RCP<Thyra::LinearOpBase<Scalar> >
00665     salo = Teuchos::rcp(
00666       new DefaultScaledAdjointLinearOp<Scalar>(
00667         Teuchos::ScalarTraits<Scalar>::one(),CONJTRANS,Op
00668         )
00669       );
00670   if (label.length())
00671     salo->setObjectLabel(label);
00672   return salo;
00673 }
00674 
00675 
00676 template<class Scalar> inline
00677 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00678 Thyra::adjoint(
00679   const RCP<const LinearOpBase<Scalar> > &Op,
00680   const std::string &label
00681   )
00682 {
00683   RCP<Thyra::LinearOpBase<Scalar> >
00684     salo = Teuchos::rcp(
00685       new DefaultScaledAdjointLinearOp<Scalar>(
00686         Teuchos::ScalarTraits<Scalar>::one(),CONJTRANS,Op
00687         )
00688       );
00689   if (label.length())
00690     salo->setObjectLabel(label);
00691   return salo;
00692 }
00693 
00694 
00695 template<class Scalar> inline
00696 Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00697 Thyra::nonconstTranspose(
00698   const RCP<LinearOpBase<Scalar> > &Op,
00699   const std::string &label
00700   )
00701 {
00702   RCP<Thyra::LinearOpBase<Scalar> >
00703     salo = Teuchos::rcp(
00704       new DefaultScaledAdjointLinearOp<Scalar>(
00705         Teuchos::ScalarTraits<Scalar>::one(),TRANS,Op
00706         )
00707       );
00708   if (label.length())
00709     salo->setObjectLabel(label);
00710   return salo;
00711 }
00712 
00713 
00714 template<class Scalar> inline
00715 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00716 Thyra::transpose(
00717   const RCP<const LinearOpBase<Scalar> > &Op,
00718   const std::string &label
00719   )
00720 {
00721   RCP<Thyra::LinearOpBase<Scalar> >
00722     salo = Teuchos::rcp(
00723       new DefaultScaledAdjointLinearOp<Scalar>(
00724         Teuchos::ScalarTraits<Scalar>::one(),TRANS,Op
00725         )
00726       );
00727   if (label.length())
00728     salo->setObjectLabel(label);
00729   return salo;
00730 }
00731 
00732 
00733 template<class Scalar> inline
00734 Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00735 Thyra::nonconstScaleAndAdjoint(
00736   const Scalar &scalar,
00737   const EOpTransp &transp,
00738   const RCP<LinearOpBase<Scalar> > &Op,
00739   const std::string &label
00740   )
00741 {
00742   RCP<Thyra::LinearOpBase<Scalar> >
00743     salo = Teuchos::rcp(
00744       new DefaultScaledAdjointLinearOp<Scalar>(scalar,transp,Op)
00745       );
00746   if (label.length())
00747     salo->setObjectLabel(label);
00748   return salo;
00749 }
00750 
00751 
00752 template<class Scalar> inline
00753 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00754 Thyra::scaleAndAdjoint(
00755   const Scalar &scalar,
00756   const EOpTransp &transp,
00757   const RCP<const LinearOpBase<Scalar> > &Op,
00758   const std::string &label
00759   )
00760 {
00761   RCP<Thyra::LinearOpBase<Scalar> >
00762     salo = Teuchos::rcp(
00763       new DefaultScaledAdjointLinearOp<Scalar>(
00764         scalar, transp, Op
00765         )
00766       );
00767   if (label.length())
00768     salo->setObjectLabel(label);
00769   return salo;
00770 }
00771 
00772 
00773 #endif  // THYRA_DEFAULT_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines