Thyra_DefaultScaledAdjointLinearOpDecl.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_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
00030 #define THYRA_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
00031 
00032 #include "Thyra_ScaledAdjointLinearOpBaseDecl.hpp"
00033 #include "Thyra_SingleScalarLinearOpBaseDecl.hpp"
00034 #include "Teuchos_ConstNonconstObjectContainer.hpp"
00035 #include "Teuchos_Handleable.hpp"
00036 
00037 namespace Thyra {
00038 
00111 template<class Scalar>
00112 class DefaultScaledAdjointLinearOp
00113   : virtual public ScaledAdjointLinearOpBase<Scalar>     // Interface
00114   , virtual protected SingleScalarLinearOpBase<Scalar>   // Implementation
00115   , virtual public Teuchos::Handleable<LinearOpBase<Scalar> >
00116 {
00117 public:
00118   /* */
00119   TEUCHOS_GET_RCP(LinearOpBase<Scalar>);
00120 
00122   using SingleScalarLinearOpBase<Scalar>::apply;
00123 
00126 
00133   DefaultScaledAdjointLinearOp();
00134 
00141   DefaultScaledAdjointLinearOp(
00142     const Scalar                                               &scalar
00143     ,const ETransp                                             &transp
00144     ,const Teuchos::RefCountPtr<LinearOpBase<Scalar> >         &Op
00145     );
00146 
00153   DefaultScaledAdjointLinearOp(
00154     const Scalar                                               &scalar
00155     ,const ETransp                                             &transp
00156     ,const Teuchos::RefCountPtr<const LinearOpBase<Scalar> >   &Op
00157     );
00158 
00174   void initialize(
00175     const Scalar                                               &scalar
00176     ,const ETransp                                             &transp
00177     ,const Teuchos::RefCountPtr<LinearOpBase<Scalar> >         &Op
00178     );
00179 
00195   void initialize(
00196     const Scalar                                               &scalar
00197     ,const ETransp                                             &transp
00198     ,const Teuchos::RefCountPtr<const LinearOpBase<Scalar> >   &Op
00199     );
00200 
00204   Teuchos::RefCountPtr<LinearOpBase<Scalar> > getNonconstOp();
00205 
00209   Teuchos::RefCountPtr<const LinearOpBase<Scalar> > getOp() const;
00210 
00217   void uninitialize();
00218 
00220 
00223                                                 
00228   std::string description() const;
00229 
00238   void describe(
00239     Teuchos::FancyOStream                &out
00240     ,const Teuchos::EVerbosityLevel      verbLevel
00241     ) const;
00242 
00244 
00254   Teuchos::RefCountPtr< const VectorSpaceBase<Scalar> > range() const;
00262   Teuchos::RefCountPtr< const VectorSpaceBase<Scalar> > domain() const;
00264   Teuchos::RefCountPtr<const LinearOpBase<Scalar> > clone() const;
00272   bool opSupported(ETransp M_trans) const;
00274 
00277 
00286   void apply(
00287     const ETransp                     M_trans
00288     ,const MultiVectorBase<Scalar>    &X
00289     ,MultiVectorBase<Scalar>          *Y
00290     ,const Scalar                     alpha
00291     ,const Scalar                     beta
00292     ) const;
00293 
00295 
00298 
00300   Scalar overallScalar() const;
00302   ETransp overallTransp() const;
00304   Teuchos::RefCountPtr<LinearOpBase<Scalar> > getNonconstOrigOp();
00306   Teuchos::RefCountPtr<const LinearOpBase<Scalar> > getOrigOp() const;
00307 
00309 
00310 private:
00311 
00312   // ////////////////////////////////
00313   // Private types
00314 
00315   template <class Scalar2>
00316   struct ScalarETransp {
00317     Scalar2   scalar;
00318     ETransp   transp;
00319     ScalarETransp()
00320       {}
00321     ScalarETransp( const Scalar2 &_scalar, const ETransp &_transp )
00322       : scalar(_scalar), transp(_transp)
00323       {}
00324   };
00325 
00326   typedef std::vector<ScalarETransp<Scalar> >  allScalarETransp_t;
00327 
00328   typedef Teuchos::ConstNonconstObjectContainer<LinearOpBase<Scalar> > CNLOC;
00329   
00330   // ////////////////////////////////
00331   // Private data members
00332 
00333   CNLOC                                              origOp_;
00334   Scalar                                             overallScalar_;
00335   ETransp                                            overallTransp_;
00336   int                                                my_index_;
00337 
00338   Teuchos::RefCountPtr<allScalarETransp_t>           allScalarETransp_;
00339   
00340   // ////////////////////////////////
00341   // Private member functions
00342 
00343   void initializeImpl(
00344     const Scalar                                               &scalar
00345     ,const ETransp                                             &transp
00346     ,const Teuchos::RefCountPtr<const LinearOpBase<Scalar> >   &Op
00347     ,const bool                                                isConst
00348     );
00349   CNLOC getOpImpl() const;
00350   void assertInitialized() const;
00351 
00352   // Not defined and not to be called
00353   DefaultScaledAdjointLinearOp(const DefaultScaledAdjointLinearOp<Scalar>&);
00354   DefaultScaledAdjointLinearOp<Scalar>& operator=(const DefaultScaledAdjointLinearOp<Scalar>&);
00355 
00356 };
00357 
00372 template<class Scalar>
00373 Teuchos::RefCountPtr<LinearOpBase<Scalar> >
00374 nonconstScale( const Scalar &scalar, const Teuchos::RefCountPtr<LinearOpBase<Scalar> > &Op );
00375 
00390 template<class Scalar>
00391 Teuchos::RefCountPtr<const LinearOpBase<Scalar> >
00392 scale( const Scalar &scalar, const Teuchos::RefCountPtr<const LinearOpBase<Scalar> > &Op );
00393 
00408 template<class Scalar>
00409 Teuchos::RefCountPtr<LinearOpBase<Scalar> >
00410 nonconstAdjoint( const Teuchos::RefCountPtr<LinearOpBase<Scalar> > &Op );
00411 
00426 template<class Scalar>
00427 Teuchos::RefCountPtr<const LinearOpBase<Scalar> >
00428 adjoint( const Teuchos::RefCountPtr<const LinearOpBase<Scalar> > &Op );
00429 
00444 template<class Scalar>
00445 Teuchos::RefCountPtr<LinearOpBase<Scalar> >
00446 nonconstTranspose( const Teuchos::RefCountPtr<LinearOpBase<Scalar> > &Op );
00447 
00462 template<class Scalar>
00463 Teuchos::RefCountPtr<const LinearOpBase<Scalar> >
00464 transpose( const Teuchos::RefCountPtr<const LinearOpBase<Scalar> > &Op );
00465 
00480 template<class Scalar>
00481 Teuchos::RefCountPtr<LinearOpBase<Scalar> >
00482 nonconstScaleAndAdjoint( const Scalar &scalar, const ETransp &transp, const Teuchos::RefCountPtr<LinearOpBase<Scalar> > &Op );
00483 
00498 template<class Scalar>
00499 Teuchos::RefCountPtr<const LinearOpBase<Scalar> >
00500 scaleAndAdjoint( const Scalar &scalar, const ETransp &transp, const Teuchos::RefCountPtr<const LinearOpBase<Scalar> > &Op );
00501 
00502 // /////////////////////////////////
00503 // Inline members
00504 
00505 template<class Scalar>
00506 inline
00507 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp()
00508   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00509   ,overallTransp_(NOTRANS)
00510 {}
00511 
00512 template<class Scalar>
00513 inline
00514 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp(
00515   const Scalar                                               &scalar
00516   ,const ETransp                                             &transp
00517   ,const Teuchos::RefCountPtr<LinearOpBase<Scalar> >         &Op
00518   )
00519   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00520   ,overallTransp_(NOTRANS)
00521 {
00522   this->initialize(scalar,transp,Op);
00523 }
00524 
00525 template<class Scalar>
00526 inline
00527 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp(
00528   const Scalar                                               &scalar
00529   ,const ETransp                                             &transp
00530   ,const Teuchos::RefCountPtr<const LinearOpBase<Scalar> >   &Op
00531   )
00532   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00533   ,overallTransp_(NOTRANS)
00534 {
00535   this->initialize(scalar,transp,Op);
00536 }
00537 
00538 template<class Scalar>
00539 inline
00540 void DefaultScaledAdjointLinearOp<Scalar>::assertInitialized() const
00541 {
00542 #ifdef TEUCHOS_DEBUG
00543   TEST_FOR_EXCEPT( origOp_.getConstObj().get() == NULL );
00544 #endif
00545 }
00546 
00547 } // end namespace Thyra
00548 
00549 // /////////////////////////////////
00550 // Inline non-members
00551 
00552 template<class Scalar>
00553 inline Teuchos::RefCountPtr<Thyra::LinearOpBase<Scalar> >
00554 Thyra::nonconstScale(
00555   const Scalar &scalar, const Teuchos::RefCountPtr<LinearOpBase<Scalar> > &Op
00556   )
00557 {
00558   return Teuchos::rcp(new DefaultScaledAdjointLinearOp<Scalar>(scalar,NOTRANS,Op));
00559 }
00560 
00561 template<class Scalar>
00562 inline Teuchos::RefCountPtr<const Thyra::LinearOpBase<Scalar> >
00563 Thyra::scale(
00564   const Scalar &scalar, const Teuchos::RefCountPtr<const LinearOpBase<Scalar> > &Op
00565   )
00566 {
00567   return Teuchos::rcp(
00568     new DefaultScaledAdjointLinearOp<Scalar>(scalar,NOTRANS,Op)
00569     );
00570 }
00571 
00572 template<class Scalar>
00573 inline Teuchos::RefCountPtr<Thyra::LinearOpBase<Scalar> >
00574 Thyra::nonconstAdjoint( const Teuchos::RefCountPtr<LinearOpBase<Scalar> > &Op )
00575 {
00576   return Teuchos::rcp(
00577     new DefaultScaledAdjointLinearOp<Scalar>(
00578       Teuchos::ScalarTraits<Scalar>::one(),CONJTRANS,Op
00579       )
00580     );
00581 }
00582 
00583 template<class Scalar>
00584 inline Teuchos::RefCountPtr<const Thyra::LinearOpBase<Scalar> >
00585 Thyra::adjoint( const Teuchos::RefCountPtr<const LinearOpBase<Scalar> > &Op )
00586 {
00587   return Teuchos::rcp(
00588     new DefaultScaledAdjointLinearOp<Scalar>(
00589       Teuchos::ScalarTraits<Scalar>::one(),CONJTRANS,Op
00590       )
00591     );
00592 }
00593 
00594 template<class Scalar>
00595 inline Teuchos::RefCountPtr<Thyra::LinearOpBase<Scalar> >
00596 Thyra::nonconstTranspose( const Teuchos::RefCountPtr<LinearOpBase<Scalar> > &Op )
00597 {
00598   return Teuchos::rcp(
00599     new DefaultScaledAdjointLinearOp<Scalar>(
00600       Teuchos::ScalarTraits<Scalar>::one(),TRANS,Op
00601       )
00602     );
00603 }
00604 
00605 template<class Scalar>
00606 inline Teuchos::RefCountPtr<const Thyra::LinearOpBase<Scalar> >
00607 Thyra::transpose( const Teuchos::RefCountPtr<const LinearOpBase<Scalar> > &Op )
00608 {
00609   return Teuchos::rcp(
00610     new DefaultScaledAdjointLinearOp<Scalar>(
00611       Teuchos::ScalarTraits<Scalar>::one(),TRANS,Op
00612       )
00613     );
00614 }
00615 
00616 template<class Scalar>
00617 inline Teuchos::RefCountPtr<Thyra::LinearOpBase<Scalar> >
00618 Thyra::nonconstScaleAndAdjoint(
00619   const Scalar &scalar, const ETransp &transp
00620   ,const Teuchos::RefCountPtr<LinearOpBase<Scalar> > &Op
00621   )
00622 {
00623   return Teuchos::rcp(new DefaultScaledAdjointLinearOp<Scalar>(scalar,transp,Op));
00624 }
00625 
00626 template<class Scalar>
00627 inline Teuchos::RefCountPtr<const Thyra::LinearOpBase<Scalar> >
00628 Thyra::scaleAndAdjoint(
00629   const Scalar &scalar, const ETransp &transp
00630   ,const Teuchos::RefCountPtr<const LinearOpBase<Scalar> > &Op
00631   )
00632 {
00633   return Teuchos::rcp(
00634     new DefaultScaledAdjointLinearOp<Scalar>(
00635       scalar,transp,Op
00636       )
00637     );
00638 }
00639 
00640 #endif  // THYRA_SCALED_ADJOINT_LINEAR_OP_DECL_HPP

Generated on Thu Sep 18 12:32:31 2008 for Thyra Operator/Vector Support by doxygen 1.3.9.1