Thyra Version of the Day
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef THYRA_DEFAULT_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
00043 #define THYRA_DEFAULT_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
00044 
00045 
00046 #include "Thyra_ScaledAdjointLinearOpBase.hpp"
00047 #include "Teuchos_ConstNonconstObjectContainer.hpp"
00048 
00049 
00050 namespace Thyra {
00051 
00052 
00125 template<class Scalar>
00126 class DefaultScaledAdjointLinearOp
00127   : virtual public ScaledAdjointLinearOpBase<Scalar>
00128 {
00129 public:
00130 
00133 
00140   DefaultScaledAdjointLinearOp();
00141 
00148   DefaultScaledAdjointLinearOp(
00149     const Scalar &scalar,
00150     const EOpTransp &transp,
00151     const RCP<LinearOpBase<Scalar> > &Op
00152     );
00153 
00160   DefaultScaledAdjointLinearOp(
00161     const Scalar &scalar,
00162     const EOpTransp &transp,
00163     const RCP<const LinearOpBase<Scalar> > &Op
00164     );
00165 
00187   void initialize(
00188     const Scalar &scalar,
00189     const EOpTransp &transp,
00190     const RCP<LinearOpBase<Scalar> > &Op
00191     );
00192   
00213   void initialize(
00214  const Scalar &scalar
00215  ,const EOpTransp &transp
00216  ,const RCP<const LinearOpBase<Scalar> > &Op
00217     );
00218 
00222   RCP<LinearOpBase<Scalar> > getNonconstOp();
00223 
00227   RCP<const LinearOpBase<Scalar> > getOp() const;
00228 
00235   void uninitialize();
00236 
00238 
00241                                                 
00246   std::string description() const;
00247 
00256   void describe(
00257     Teuchos::FancyOStream &out,
00258     const Teuchos::EVerbosityLevel verbLevel
00259     ) const;
00260 
00262 
00265 
00273   RCP<const VectorSpaceBase<Scalar> > range() const;
00274 
00282   RCP<const VectorSpaceBase<Scalar> > domain() const;
00283 
00285   RCP<const LinearOpBase<Scalar> > clone() const;
00286 
00288 
00291 
00293   Scalar overallScalar() const;
00295   EOpTransp overallTransp() const;
00297   RCP<LinearOpBase<Scalar> > getNonconstOrigOp();
00299   RCP<const LinearOpBase<Scalar> > getOrigOp() const;
00300 
00302 
00303 protected:
00304   
00307 
00316   bool opSupportedImpl(EOpTransp M_trans) const;
00317 
00326  void applyImpl(
00327    const EOpTransp M_trans,
00328    const MultiVectorBase<Scalar> &X,
00329    const Ptr<MultiVectorBase<Scalar> > &Y,
00330    const Scalar alpha,
00331    const Scalar beta
00332    ) const;
00333 
00335 
00336 private:
00337 
00338   // ////////////////////////////////
00339   // Private types
00340 
00341   template <class Scalar2>
00342   struct ScalarETransp {
00343     Scalar2   scalar;
00344     EOpTransp   transp;
00345     ScalarETransp()
00346       {}
00347     ScalarETransp( const Scalar2 &_scalar, const EOpTransp &_transp )
00348       : scalar(_scalar), transp(_transp)
00349       {}
00350   };
00351 
00352   typedef std::vector<ScalarETransp<Scalar> >  allScalarETransp_t;
00353 
00354   typedef Teuchos::ConstNonconstObjectContainer<LinearOpBase<Scalar> > CNLOC;
00355   
00356   // ////////////////////////////////
00357   // Private data members
00358 
00359   CNLOC origOp_;
00360   Scalar overallScalar_;
00361   EOpTransp overallTransp_;
00362   int my_index_;
00363   
00364  RCP<allScalarETransp_t> allScalarETransp_;
00365   
00366   // ////////////////////////////////
00367   // Private member functions
00368 
00369   void initializeImpl(
00370     const Scalar &scalar,
00371     const EOpTransp &transp,
00372     const RCP<const LinearOpBase<Scalar> > &Op,
00373     const bool isConst
00374     );
00375   CNLOC getOpImpl() const;
00376   void assertInitialized() const;
00377 
00378   // Not defined and not to be called
00379   DefaultScaledAdjointLinearOp(const DefaultScaledAdjointLinearOp<Scalar>&);
00380   DefaultScaledAdjointLinearOp<Scalar>& operator=(const DefaultScaledAdjointLinearOp<Scalar>&);
00381 
00382 };
00383 
00384 
00400 template<class Scalar>
00401 RCP<LinearOpBase<Scalar> >
00402 nonconstScale(
00403   const Scalar &scalar,
00404   const RCP<LinearOpBase<Scalar> > &Op,
00405   const std::string &label = ""
00406   );
00407 
00408 
00424 template<class Scalar>
00425 RCP<const LinearOpBase<Scalar> >
00426 scale(
00427   const Scalar &scalar,
00428   const RCP<const LinearOpBase<Scalar> > &Op,
00429   const std::string &label = ""
00430   );
00431 
00432 
00448 template<class Scalar>
00449 RCP<LinearOpBase<Scalar> >
00450 nonconstAdjoint(
00451   const RCP<LinearOpBase<Scalar> > &Op,
00452   const std::string &label = ""
00453   );
00454 
00455 
00471 template<class Scalar>
00472 RCP<const LinearOpBase<Scalar> >
00473 adjoint(
00474   const RCP<const LinearOpBase<Scalar> > &Op,
00475   const std::string &label = ""
00476   );
00477 
00478 
00494 template<class Scalar>
00495 RCP<LinearOpBase<Scalar> >
00496 nonconstTranspose(
00497   const RCP<LinearOpBase<Scalar> > &Op,
00498   const std::string &label = ""
00499   );
00500 
00501 
00517 template<class Scalar>
00518 RCP<const LinearOpBase<Scalar> >
00519 transpose(
00520   const RCP<const LinearOpBase<Scalar> > &Op,
00521   const std::string &label = ""
00522   );
00523 
00524 
00541 template<class Scalar>
00542 RCP<LinearOpBase<Scalar> >
00543 nonconstScaleAndAdjoint(
00544   const Scalar &scalar, const EOpTransp &transp,
00545   const RCP<LinearOpBase<Scalar> > &Op,
00546   const std::string &label = ""
00547   );
00548 
00549 
00566 template<class Scalar>
00567 RCP<const LinearOpBase<Scalar> >
00568 scaleAndAdjoint(
00569   const Scalar &scalar, const EOpTransp &transp,
00570   const RCP<const LinearOpBase<Scalar> > &Op,
00571   const std::string &label = ""
00572   );
00573 
00574 
00575 // /////////////////////////////////
00576 // Inline members
00577 
00578 
00579 template<class Scalar>
00580 inline
00581 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp()
00582   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00583   ,overallTransp_(NOTRANS)
00584 {}
00585 
00586 
00587 template<class Scalar>
00588 inline
00589 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp(
00590   const Scalar &scalar
00591   ,const EOpTransp &transp
00592   ,const RCP<LinearOpBase<Scalar> > &Op
00593   )
00594   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00595   ,overallTransp_(NOTRANS)
00596 {
00597   this->initialize(scalar,transp,Op);
00598 }
00599 
00600 
00601 template<class Scalar>
00602 inline
00603 DefaultScaledAdjointLinearOp<Scalar>::DefaultScaledAdjointLinearOp(
00604   const Scalar &scalar
00605   ,const EOpTransp &transp
00606   ,const RCP<const LinearOpBase<Scalar> > &Op
00607   )
00608   :overallScalar_(Teuchos::ScalarTraits<Scalar>::zero())
00609   ,overallTransp_(NOTRANS)
00610 {
00611   this->initialize(scalar,transp,Op);
00612 }
00613 
00614 
00615 template<class Scalar>
00616 inline
00617 void DefaultScaledAdjointLinearOp<Scalar>::assertInitialized() const
00618 {
00619 #ifdef TEUCHOS_DEBUG
00620   TEUCHOS_TEST_FOR_EXCEPT( origOp_.getConstObj().get() == NULL );
00621 #endif
00622 }
00623 
00624 
00625 } // end namespace Thyra
00626 
00627 
00628 // /////////////////////////////////
00629 // Inline non-members
00630 
00631 
00632 template<class Scalar> inline
00633 Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00634 Thyra::nonconstScale(
00635   const Scalar &scalar,
00636   const RCP<LinearOpBase<Scalar> > &Op,
00637   const std::string &label
00638   )
00639 {
00640   RCP<Thyra::LinearOpBase<Scalar> >
00641     salo = Teuchos::rcp(
00642       new DefaultScaledAdjointLinearOp<Scalar>(
00643         scalar,NOTRANS,Op
00644         )
00645       );
00646   if (label.length())
00647     salo->setObjectLabel(label);
00648   return salo;
00649 }
00650 
00651 
00652 template<class Scalar> inline
00653 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00654 Thyra::scale(
00655   const Scalar &scalar,
00656   const RCP<const LinearOpBase<Scalar> > &Op,
00657   const std::string &label
00658   )
00659 {
00660   RCP<Thyra::LinearOpBase<Scalar> >
00661     salo = Teuchos::rcp(
00662     new DefaultScaledAdjointLinearOp<Scalar>(scalar,NOTRANS,Op)
00663     );
00664   if (label.length())
00665     salo->setObjectLabel(label);
00666   return salo;
00667 }
00668 
00669 
00670 template<class Scalar> inline
00671 Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00672 Thyra::nonconstAdjoint(
00673   const RCP<LinearOpBase<Scalar> > &Op,
00674   const std::string &label
00675   )
00676 {
00677   RCP<Thyra::LinearOpBase<Scalar> >
00678     salo = Teuchos::rcp(
00679       new DefaultScaledAdjointLinearOp<Scalar>(
00680         Teuchos::ScalarTraits<Scalar>::one(),CONJTRANS,Op
00681         )
00682       );
00683   if (label.length())
00684     salo->setObjectLabel(label);
00685   return salo;
00686 }
00687 
00688 
00689 template<class Scalar> inline
00690 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00691 Thyra::adjoint(
00692   const RCP<const LinearOpBase<Scalar> > &Op,
00693   const std::string &label
00694   )
00695 {
00696   RCP<Thyra::LinearOpBase<Scalar> >
00697     salo = Teuchos::rcp(
00698       new DefaultScaledAdjointLinearOp<Scalar>(
00699         Teuchos::ScalarTraits<Scalar>::one(),CONJTRANS,Op
00700         )
00701       );
00702   if (label.length())
00703     salo->setObjectLabel(label);
00704   return salo;
00705 }
00706 
00707 
00708 template<class Scalar> inline
00709 Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00710 Thyra::nonconstTranspose(
00711   const RCP<LinearOpBase<Scalar> > &Op,
00712   const std::string &label
00713   )
00714 {
00715   RCP<Thyra::LinearOpBase<Scalar> >
00716     salo = Teuchos::rcp(
00717       new DefaultScaledAdjointLinearOp<Scalar>(
00718         Teuchos::ScalarTraits<Scalar>::one(),TRANS,Op
00719         )
00720       );
00721   if (label.length())
00722     salo->setObjectLabel(label);
00723   return salo;
00724 }
00725 
00726 
00727 template<class Scalar> inline
00728 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00729 Thyra::transpose(
00730   const RCP<const LinearOpBase<Scalar> > &Op,
00731   const std::string &label
00732   )
00733 {
00734   RCP<Thyra::LinearOpBase<Scalar> >
00735     salo = Teuchos::rcp(
00736       new DefaultScaledAdjointLinearOp<Scalar>(
00737         Teuchos::ScalarTraits<Scalar>::one(),TRANS,Op
00738         )
00739       );
00740   if (label.length())
00741     salo->setObjectLabel(label);
00742   return salo;
00743 }
00744 
00745 
00746 template<class Scalar> inline
00747 Teuchos::RCP<Thyra::LinearOpBase<Scalar> >
00748 Thyra::nonconstScaleAndAdjoint(
00749   const Scalar &scalar,
00750   const EOpTransp &transp,
00751   const RCP<LinearOpBase<Scalar> > &Op,
00752   const std::string &label
00753   )
00754 {
00755   RCP<Thyra::LinearOpBase<Scalar> >
00756     salo = Teuchos::rcp(
00757       new DefaultScaledAdjointLinearOp<Scalar>(scalar,transp,Op)
00758       );
00759   if (label.length())
00760     salo->setObjectLabel(label);
00761   return salo;
00762 }
00763 
00764 
00765 template<class Scalar> inline
00766 Teuchos::RCP<const Thyra::LinearOpBase<Scalar> >
00767 Thyra::scaleAndAdjoint(
00768   const Scalar &scalar,
00769   const EOpTransp &transp,
00770   const RCP<const LinearOpBase<Scalar> > &Op,
00771   const std::string &label
00772   )
00773 {
00774   RCP<Thyra::LinearOpBase<Scalar> >
00775     salo = Teuchos::rcp(
00776       new DefaultScaledAdjointLinearOp<Scalar>(
00777         scalar, transp, Op
00778         )
00779       );
00780   if (label.length())
00781     salo->setObjectLabel(label);
00782   return salo;
00783 }
00784 
00785 
00786 #endif  // THYRA_DEFAULT_SCALED_ADJOINT_LINEAR_OP_DECL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines