Thyra_DefaultScaledAdjointLinearOp_decl.hpp

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 "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> >  // ToDo: Remove!
00119 {
00120 public:
00121 
00122 #ifdef THYRA_INJECT_USING_DECLARATIONS
00123   using SingleScalarLinearOpBase<Scalar>::apply;
00124 #endif
00125 
00127   TEUCHOS_GET_RCP(LinearOpBase<Scalar>);
00128 
00131 
00138   DefaultScaledAdjointLinearOp();
00139 
00146   DefaultScaledAdjointLinearOp(
00147     const Scalar &scalar,
00148     const EOpTransp &transp,
00149     const RCP<LinearOpBase<Scalar> > &Op
00150     );
00151 
00158   DefaultScaledAdjointLinearOp(
00159     const Scalar &scalar,
00160     const EOpTransp &transp,
00161     const RCP<const LinearOpBase<Scalar> > &Op
00162     );
00163 
00185   void initialize(
00186     const Scalar &scalar,
00187     const EOpTransp &transp,
00188     const RCP<LinearOpBase<Scalar> > &Op
00189     );
00190   
00211   void initialize(
00212  const Scalar &scalar
00213  ,const EOpTransp &transp
00214  ,const RCP<const LinearOpBase<Scalar> > &Op
00215     );
00216 
00220   RCP<LinearOpBase<Scalar> > getNonconstOp();
00221 
00225   RCP<const LinearOpBase<Scalar> > getOp() const;
00226 
00233   void uninitialize();
00234 
00236 
00239                                                 
00244   std::string description() const;
00245 
00254   void describe(
00255     Teuchos::FancyOStream &out,
00256     const Teuchos::EVerbosityLevel verbLevel
00257     ) const;
00258 
00260 
00263 
00271   RCP< const VectorSpaceBase<Scalar> > range() const;
00272 
00280   RCP< const VectorSpaceBase<Scalar> > domain() const;
00281 
00283   RCP<const LinearOpBase<Scalar> > clone() const;
00284 
00286 
00289 
00291   Scalar overallScalar() const;
00293   EOpTransp overallTransp() const;
00295   RCP<LinearOpBase<Scalar> > getNonconstOrigOp();
00297   RCP<const LinearOpBase<Scalar> > getOrigOp() const;
00298 
00300 
00301 protected:
00302   
00305 
00314   bool opSupported(EOpTransp M_trans) const;
00315 
00324  void apply(
00325    const EOpTransp M_trans,
00326    const MultiVectorBase<Scalar> &X,
00327    MultiVectorBase<Scalar> *Y,
00328    const Scalar alpha,
00329    const Scalar beta
00330    ) const;
00331 
00333 
00334 private:
00335 
00336   // ////////////////////////////////
00337   // Private types
00338 
00339   template <class Scalar2>
00340   struct ScalarETransp {
00341     Scalar2   scalar;
00342     EOpTransp   transp;
00343     ScalarETransp()
00344       {}
00345     ScalarETransp( const Scalar2 &_scalar, const EOpTransp &_transp )
00346       : scalar(_scalar), transp(_transp)
00347       {}
00348   };
00349 
00350   typedef std::vector<ScalarETransp<Scalar> >  allScalarETransp_t;
00351 
00352   typedef Teuchos::ConstNonconstObjectContainer<LinearOpBase<Scalar> > CNLOC;
00353   
00354   // ////////////////////////////////
00355   // Private data members
00356 
00357   CNLOC origOp_;
00358   Scalar overallScalar_;
00359   EOpTransp overallTransp_;
00360   int my_index_;
00361   
00362  RCP<allScalarETransp_t> allScalarETransp_;
00363   
00364   // ////////////////////////////////
00365   // Private member functions
00366 
00367   void initializeImpl(
00368     const Scalar &scalar,
00369     const EOpTransp &transp,
00370     const RCP<const LinearOpBase<Scalar> > &Op,
00371     const bool isConst
00372     );
00373   CNLOC getOpImpl() const;
00374   void assertInitialized() const;
00375 
00376   // Not defined and not to be called
00377   DefaultScaledAdjointLinearOp(const DefaultScaledAdjointLinearOp<Scalar>&);
00378   DefaultScaledAdjointLinearOp<Scalar>& operator=(const DefaultScaledAdjointLinearOp<Scalar>&);
00379 
00380 };
00381 
00382 
00398 template<class Scalar>
00399 RCP<LinearOpBase<Scalar> >
00400 nonconstScale(
00401   const Scalar &scalar,
00402   const RCP<LinearOpBase<Scalar> > &Op,
00403   const std::string &label = ""
00404   );
00405 
00406 
00422 template<class Scalar>
00423 RCP<const LinearOpBase<Scalar> >
00424 scale(
00425   const Scalar &scalar,
00426   const RCP<const LinearOpBase<Scalar> > &Op,
00427   const std::string &label = ""
00428   );
00429 
00430 
00446 template<class Scalar>
00447 RCP<LinearOpBase<Scalar> >
00448 nonconstAdjoint(
00449   const RCP<LinearOpBase<Scalar> > &Op,
00450   const std::string &label = ""
00451   );
00452 
00453 
00469 template<class Scalar>
00470 RCP<const LinearOpBase<Scalar> >
00471 adjoint(
00472   const RCP<const LinearOpBase<Scalar> > &Op,
00473   const std::string &label = ""
00474   );
00475 
00476 
00492 template<class Scalar>
00493 RCP<LinearOpBase<Scalar> >
00494 nonconstTranspose(
00495   const RCP<LinearOpBase<Scalar> > &Op,
00496   const std::string &label = ""
00497   );
00498 
00499 
00515 template<class Scalar>
00516 RCP<const LinearOpBase<Scalar> >
00517 transpose(
00518   const RCP<const LinearOpBase<Scalar> > &Op,
00519   const std::string &label = ""
00520   );
00521 
00522 
00539 template<class Scalar>
00540 RCP<LinearOpBase<Scalar> >
00541 nonconstScaleAndAdjoint(
00542   const Scalar &scalar, const EOpTransp &transp,
00543   const RCP<LinearOpBase<Scalar> > &Op,
00544   const std::string &label = ""
00545   );
00546 
00547 
00564 template<class Scalar>
00565 RCP<const LinearOpBase<Scalar> >
00566 scaleAndAdjoint(
00567   const Scalar &scalar, const EOpTransp &transp,
00568   const RCP<const LinearOpBase<Scalar> > &Op,
00569   const std::string &label = ""
00570   );
00571 
00572 
00573 // /////////////////////////////////
00574 // Inline members
00575 
00576 
00577 template<class Scalar>
00578 inline
00579 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp()
00580   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00581   ,overallTransp_(NOTRANS)
00582 {}
00583 
00584 
00585 template<class Scalar>
00586 inline
00587 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp(
00588   const Scalar &scalar
00589   ,const EOpTransp &transp
00590   ,const RCP<LinearOpBase<Scalar> > &Op
00591   )
00592   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00593   ,overallTransp_(NOTRANS)
00594 {
00595   this->initialize(scalar,transp,Op);
00596 }
00597 
00598 
00599 template<class Scalar>
00600 inline
00601 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp(
00602   const Scalar &scalar
00603   ,const EOpTransp &transp
00604   ,const RCP<const LinearOpBase<Scalar> > &Op
00605   )
00606   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00607   ,overallTransp_(NOTRANS)
00608 {
00609   this->initialize(scalar,transp,Op);
00610 }
00611 
00612 
00613 template<class Scalar>
00614 inline
00615 void DefaultScaledAdjointLinearOp<Scalar>::assertInitialized() const
00616 {
00617 #ifdef TEUCHOS_DEBUG
00618   TEST_FOR_EXCEPT( origOp_.getConstObj().get() == NULL );
00619 #endif
00620 }
00621 
00622 
00623 } // end namespace Thyra
00624 
00625 
00626 // /////////////////////////////////
00627 // Inline non-members
00628 
00629 
00630 template<class Scalar> inline
00631 Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00632 Thyra::nonconstScale(
00633   const Scalar &scalar,
00634   const RCP<LinearOpBase<Scalar> > &Op,
00635   const std::string &label
00636   )
00637 {
00638   RCP<Thyra::LinearOpBase<Scalar> >
00639     salo = Teuchos::rcp(
00640       new DefaultScaledAdjointLinearOp<Scalar>(
00641         scalar,NOTRANS,Op
00642         )
00643       );
00644   if (label.length())
00645     salo->setObjectLabel(label);
00646   return salo;
00647 }
00648 
00649 
00650 template<class Scalar> inline
00651 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00652 Thyra::scale(
00653   const Scalar &scalar,
00654   const RCP<const LinearOpBase<Scalar> > &Op,
00655   const std::string &label
00656   )
00657 {
00658   RCP<Thyra::LinearOpBase<Scalar> >
00659     salo = Teuchos::rcp(
00660     new DefaultScaledAdjointLinearOp<Scalar>(scalar,NOTRANS,Op)
00661     );
00662   if (label.length())
00663     salo->setObjectLabel(label);
00664   return salo;
00665 }
00666 
00667 
00668 template<class Scalar> inline
00669 Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00670 Thyra::nonconstAdjoint(
00671   const RCP<LinearOpBase<Scalar> > &Op,
00672   const std::string &label
00673   )
00674 {
00675   RCP<Thyra::LinearOpBase<Scalar> >
00676     salo = Teuchos::rcp(
00677       new DefaultScaledAdjointLinearOp<Scalar>(
00678         Teuchos::ScalarTraits<Scalar>::one(),CONJTRANS,Op
00679         )
00680       );
00681   if (label.length())
00682     salo->setObjectLabel(label);
00683   return salo;
00684 }
00685 
00686 
00687 template<class Scalar> inline
00688 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00689 Thyra::adjoint(
00690   const RCP<const LinearOpBase<Scalar> > &Op,
00691   const std::string &label
00692   )
00693 {
00694   RCP<Thyra::LinearOpBase<Scalar> >
00695     salo = Teuchos::rcp(
00696       new DefaultScaledAdjointLinearOp<Scalar>(
00697         Teuchos::ScalarTraits<Scalar>::one(),CONJTRANS,Op
00698         )
00699       );
00700   if (label.length())
00701     salo->setObjectLabel(label);
00702   return salo;
00703 }
00704 
00705 
00706 template<class Scalar> inline
00707 Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00708 Thyra::nonconstTranspose(
00709   const RCP<LinearOpBase<Scalar> > &Op,
00710   const std::string &label
00711   )
00712 {
00713   RCP<Thyra::LinearOpBase<Scalar> >
00714     salo = Teuchos::rcp(
00715       new DefaultScaledAdjointLinearOp<Scalar>(
00716         Teuchos::ScalarTraits<Scalar>::one(),TRANS,Op
00717         )
00718       );
00719   if (label.length())
00720     salo->setObjectLabel(label);
00721   return salo;
00722 }
00723 
00724 
00725 template<class Scalar> inline
00726 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00727 Thyra::transpose(
00728   const RCP<const LinearOpBase<Scalar> > &Op,
00729   const std::string &label
00730   )
00731 {
00732   RCP<Thyra::LinearOpBase<Scalar> >
00733     salo = Teuchos::rcp(
00734       new DefaultScaledAdjointLinearOp<Scalar>(
00735         Teuchos::ScalarTraits<Scalar>::one(),TRANS,Op
00736         )
00737       );
00738   if (label.length())
00739     salo->setObjectLabel(label);
00740   return salo;
00741 }
00742 
00743 
00744 template<class Scalar> inline
00745 Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00746 Thyra::nonconstScaleAndAdjoint(
00747   const Scalar &scalar,
00748   const EOpTransp &transp,
00749   const RCP<LinearOpBase<Scalar> > &Op,
00750   const std::string &label
00751   )
00752 {
00753   RCP<Thyra::LinearOpBase<Scalar> >
00754     salo = Teuchos::rcp(
00755       new DefaultScaledAdjointLinearOp<Scalar>(scalar,transp,Op)
00756       );
00757   if (label.length())
00758     salo->setObjectLabel(label);
00759   return salo;
00760 }
00761 
00762 
00763 template<class Scalar> inline
00764 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00765 Thyra::scaleAndAdjoint(
00766   const Scalar &scalar,
00767   const EOpTransp &transp,
00768   const RCP<const LinearOpBase<Scalar> > &Op,
00769   const std::string &label
00770   )
00771 {
00772   RCP<Thyra::LinearOpBase<Scalar> >
00773     salo = Teuchos::rcp(
00774       new DefaultScaledAdjointLinearOp<Scalar>(
00775         scalar, transp, Op
00776         )
00777       );
00778   if (label.length())
00779     salo->setObjectLabel(label);
00780   return salo;
00781 }
00782 
00783 
00784 #endif  // THYRA_DEFAULT_SCALED_ADJOINT_LINEAR_OP_DECL_HPP

Generated on Wed May 12 21:26:54 2010 for Thyra Operator/Vector Support by  doxygen 1.4.7