Thyra_DefaultScaledAdjointLinearOpDecl.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_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
00030 #define THYRA_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
00031 
00032 
00033 #include "Thyra_ScaledAdjointLinearOpBaseDecl.hpp"
00034 #include "Thyra_SingleScalarLinearOpBaseDecl.hpp"
00035 #include "Teuchos_ConstNonconstObjectContainer.hpp"
00036 #include "Teuchos_Handleable.hpp"
00037 
00038 
00039 namespace Thyra {
00040 
00041 
00114 template<class Scalar>
00115 class DefaultScaledAdjointLinearOp
00116   : virtual public ScaledAdjointLinearOpBase<Scalar>     // Interface
00117   , virtual protected SingleScalarLinearOpBase<Scalar>   // Implementation
00118   , virtual public Teuchos::Handleable<LinearOpBase<Scalar> >
00119 {
00120 public:
00121 
00123   TEUCHOS_GET_RCP(LinearOpBase<Scalar>);
00124 
00126   using SingleScalarLinearOpBase<Scalar>::apply;
00127 
00130 
00137   DefaultScaledAdjointLinearOp();
00138 
00145   DefaultScaledAdjointLinearOp(
00146     const Scalar &scalar,
00147     const ETransp &transp,
00148     const RCP<LinearOpBase<Scalar> > &Op
00149     );
00150 
00157   DefaultScaledAdjointLinearOp(
00158     const Scalar &scalar,
00159     const ETransp &transp,
00160     const RCP<const LinearOpBase<Scalar> > &Op
00161     );
00162 
00184   void initialize(
00185     const Scalar &scalar,
00186     const ETransp &transp,
00187     const RCP<LinearOpBase<Scalar> > &Op
00188     );
00189   
00210   void initialize(
00211  const Scalar &scalar
00212  ,const ETransp &transp
00213  ,const RCP<const LinearOpBase<Scalar> > &Op
00214     );
00215 
00219   RCP<LinearOpBase<Scalar> > getNonconstOp();
00220 
00224   RCP<const LinearOpBase<Scalar> > getOp() const;
00225 
00232   void uninitialize();
00233 
00235 
00238                                                 
00243   std::string description() const;
00244 
00253   void describe(
00254     Teuchos::FancyOStream &out,
00255     const Teuchos::EVerbosityLevel verbLevel
00256     ) const;
00257 
00259 
00269   RCP< const VectorSpaceBase<Scalar> > range() const;
00277   RCP< const VectorSpaceBase<Scalar> > domain() const;
00279   RCP<const LinearOpBase<Scalar> > clone() const;
00287   bool opSupported(ETransp M_trans) const;
00289 
00292 
00301  void apply(
00302    const ETransp M_trans,
00303    const MultiVectorBase<Scalar> &X,
00304    MultiVectorBase<Scalar> *Y,
00305    const Scalar alpha,
00306    const Scalar beta
00307    ) const;
00308 
00310 
00313 
00315   Scalar overallScalar() const;
00317   ETransp overallTransp() const;
00319   RCP<LinearOpBase<Scalar> > getNonconstOrigOp();
00321   RCP<const LinearOpBase<Scalar> > getOrigOp() const;
00322 
00324 
00325 private:
00326 
00327   // ////////////////////////////////
00328   // Private types
00329 
00330   template <class Scalar2>
00331   struct ScalarETransp {
00332     Scalar2   scalar;
00333     ETransp   transp;
00334     ScalarETransp()
00335       {}
00336     ScalarETransp( const Scalar2 &_scalar, const ETransp &_transp )
00337       : scalar(_scalar), transp(_transp)
00338       {}
00339   };
00340 
00341   typedef std::vector<ScalarETransp<Scalar> >  allScalarETransp_t;
00342 
00343   typedef Teuchos::ConstNonconstObjectContainer<LinearOpBase<Scalar> > CNLOC;
00344   
00345   // ////////////////////////////////
00346   // Private data members
00347 
00348   CNLOC origOp_;
00349   Scalar overallScalar_;
00350   ETransp overallTransp_;
00351   int my_index_;
00352   
00353  RCP<allScalarETransp_t> allScalarETransp_;
00354   
00355   // ////////////////////////////////
00356   // Private member functions
00357 
00358   void initializeImpl(
00359     const Scalar &scalar,
00360     const ETransp &transp,
00361     const RCP<const LinearOpBase<Scalar> > &Op,
00362     const bool isConst
00363     );
00364   CNLOC getOpImpl() const;
00365   void assertInitialized() const;
00366 
00367   // Not defined and not to be called
00368   DefaultScaledAdjointLinearOp(const DefaultScaledAdjointLinearOp<Scalar>&);
00369   DefaultScaledAdjointLinearOp<Scalar>& operator=(const DefaultScaledAdjointLinearOp<Scalar>&);
00370 
00371 };
00372 
00373 
00389 template<class Scalar>
00390 RCP<LinearOpBase<Scalar> >
00391 nonconstScale( const Scalar &scalar, const RCP<LinearOpBase<Scalar> > &Op );
00392 
00393 
00409 template<class Scalar>
00410 RCP<const LinearOpBase<Scalar> >
00411 scale( const Scalar &scalar, const RCP<const LinearOpBase<Scalar> > &Op );
00412 
00413 
00429 template<class Scalar>
00430 RCP<LinearOpBase<Scalar> >
00431 nonconstAdjoint( const RCP<LinearOpBase<Scalar> > &Op );
00432 
00433 
00449 template<class Scalar>
00450 RCP<const LinearOpBase<Scalar> >
00451 adjoint( const RCP<const LinearOpBase<Scalar> > &Op );
00452 
00453 
00469 template<class Scalar>
00470 RCP<LinearOpBase<Scalar> >
00471 nonconstTranspose( const RCP<LinearOpBase<Scalar> > &Op );
00472 
00473 
00489 template<class Scalar>
00490 RCP<const LinearOpBase<Scalar> >
00491 transpose( const RCP<const LinearOpBase<Scalar> > &Op );
00492 
00493 
00510 template<class Scalar>
00511 RCP<LinearOpBase<Scalar> >
00512 nonconstScaleAndAdjoint(
00513   const Scalar &scalar, const ETransp &transp,
00514   const RCP<LinearOpBase<Scalar> > &Op
00515   );
00516 
00517 
00534 template<class Scalar>
00535 RCP<const LinearOpBase<Scalar> >
00536 scaleAndAdjoint(
00537   const Scalar &scalar, const ETransp &transp,
00538   const RCP<const LinearOpBase<Scalar> > &Op
00539   );
00540 
00541 
00542 // /////////////////////////////////
00543 // Inline members
00544 
00545 
00546 template<class Scalar>
00547 inline
00548 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp()
00549   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00550   ,overallTransp_(NOTRANS)
00551 {}
00552 
00553 
00554 template<class Scalar>
00555 inline
00556 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp(
00557   const Scalar &scalar
00558   ,const ETransp &transp
00559   ,const RCP<LinearOpBase<Scalar> > &Op
00560   )
00561   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00562   ,overallTransp_(NOTRANS)
00563 {
00564   this->initialize(scalar,transp,Op);
00565 }
00566 
00567 
00568 template<class Scalar>
00569 inline
00570 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp(
00571   const Scalar &scalar
00572   ,const ETransp &transp
00573   ,const RCP<const LinearOpBase<Scalar> > &Op
00574   )
00575   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00576   ,overallTransp_(NOTRANS)
00577 {
00578   this->initialize(scalar,transp,Op);
00579 }
00580 
00581 
00582 template<class Scalar>
00583 inline
00584 void DefaultScaledAdjointLinearOp<Scalar>::assertInitialized() const
00585 {
00586 #ifdef TEUCHOS_DEBUG
00587   TEST_FOR_EXCEPT( origOp_.getConstObj().get() == NULL );
00588 #endif
00589 }
00590 
00591 
00592 } // end namespace Thyra
00593 
00594 
00595 // /////////////////////////////////
00596 // Inline non-members
00597 
00598 
00599 template<class Scalar>
00600 inline Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00601 Thyra::nonconstScale(
00602   const Scalar &scalar, const RCP<LinearOpBase<Scalar> > &Op
00603   )
00604 {
00605   return Teuchos::rcp(new DefaultScaledAdjointLinearOp<Scalar>(scalar,NOTRANS,Op));
00606 }
00607 
00608 
00609 template<class Scalar>
00610 inline Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00611 Thyra::scale(
00612   const Scalar &scalar, const RCP<const LinearOpBase<Scalar> > &Op
00613   )
00614 {
00615   return Teuchos::rcp(
00616     new DefaultScaledAdjointLinearOp<Scalar>(scalar,NOTRANS,Op)
00617     );
00618 }
00619 
00620 
00621 template<class Scalar>
00622 inline Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00623 Thyra::nonconstAdjoint( const RCP<LinearOpBase<Scalar> > &Op )
00624 {
00625   return Teuchos::rcp(
00626     new DefaultScaledAdjointLinearOp<Scalar>(
00627       Teuchos::ScalarTraits<Scalar>::one(),CONJTRANS,Op
00628       )
00629     );
00630 }
00631 
00632 
00633 template<class Scalar>
00634 inline Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00635 Thyra::adjoint( const RCP<const LinearOpBase<Scalar> > &Op )
00636 {
00637   return Teuchos::rcp(
00638     new DefaultScaledAdjointLinearOp<Scalar>(
00639       Teuchos::ScalarTraits<Scalar>::one(),CONJTRANS,Op
00640       )
00641     );
00642 }
00643 
00644 
00645 template<class Scalar>
00646 inline Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00647 Thyra::nonconstTranspose( const RCP<LinearOpBase<Scalar> > &Op )
00648 {
00649   return Teuchos::rcp(
00650     new DefaultScaledAdjointLinearOp<Scalar>(
00651       Teuchos::ScalarTraits<Scalar>::one(),TRANS,Op
00652       )
00653     );
00654 }
00655 
00656 
00657 template<class Scalar>
00658 inline Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00659 Thyra::transpose( const RCP<const LinearOpBase<Scalar> > &Op )
00660 {
00661   return Teuchos::rcp(
00662     new DefaultScaledAdjointLinearOp<Scalar>(
00663       Teuchos::ScalarTraits<Scalar>::one(),TRANS,Op
00664       )
00665     );
00666 }
00667 
00668 
00669 template<class Scalar>
00670 inline Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00671 Thyra::nonconstScaleAndAdjoint(
00672   const Scalar &scalar, const ETransp &transp
00673   ,const RCP<LinearOpBase<Scalar> > &Op
00674   )
00675 {
00676   return Teuchos::rcp(new DefaultScaledAdjointLinearOp<Scalar>(scalar,transp,Op));
00677 }
00678 
00679 
00680 template<class Scalar>
00681 inline Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00682 Thyra::scaleAndAdjoint(
00683   const Scalar &scalar, const ETransp &transp
00684   ,const RCP<const LinearOpBase<Scalar> > &Op
00685   )
00686 {
00687   return Teuchos::rcp(
00688     new DefaultScaledAdjointLinearOp<Scalar>(
00689       scalar,transp,Op
00690       )
00691     );
00692 }
00693 
00694 
00695 #endif  // THYRA_SCALED_ADJOINT_LINEAR_OP_DECL_HPP

Generated on Tue Oct 20 12:47:25 2009 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.4.7