Thyra_LinearCombinationDecl.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_LINEARCOMBINATION_DECL_HPP
00030 #define THYRA_LINEARCOMBINATION_DECL_HPP
00031 
00032 #include "Teuchos_Handle.hpp"
00033 #include "Thyra_ConfigDefs.hpp"
00034 #include "Thyra_LinearOperatorDecl.hpp"
00035 #include "Thyra_VectorHandleOpsDecl.hpp"
00036 
00037 namespace Thyra
00038 {
00042   template <class Scalar> 
00043   class ConvertibleToVector : public virtual Thyra::Converter<Scalar, Thyra::ConstVector<Scalar> >
00044   {
00045   public:
00047     virtual ~ConvertibleToVector(){;}
00048 
00050     virtual Thyra::Vector<Scalar> formVector() const = 0 ;
00051 
00053     Thyra::ConstVector<Scalar> convert() const 
00054     {
00055       Thyra::ConstVector<Scalar> rtn = this->formVector();
00056       return this->formVector();
00057     }
00058   };
00059 
00060 
00064   template <class Scalar, class Node>
00065   class OpTimesLC : public ConvertibleToVector<Scalar>
00066   {
00067   public:
00068 
00070     virtual ~OpTimesLC(){;}
00071 
00073     OpTimesLC(const Scalar& alpha, const Node& x);
00074 
00076     OpTimesLC(const Scalar& alpha,
00077               const Thyra::ConstLinearOperator<Scalar>& op, 
00078               const Node& x);
00079 
00083     void evalInto(Thyra::Vector<Scalar>& result) const ;
00084 
00086     void addInto(Thyra::Vector<Scalar>& result, 
00087                  LCSign sign = LCAdd) const ;
00088 
00090     virtual Thyra::Vector<Scalar> formVector() const ;
00091 
00093     bool containsVector(const Thyra::VectorBase<Scalar>* vec) const ;
00094 
00096      const Thyra::ConstLinearOperator<Scalar>& op() const {return op_;}
00097 
00099     const Scalar& alpha() const {return alpha_;}
00100 
00102     const Node& node() const {return x_;}
00103 
00104   private:
00105     Scalar alpha_;
00106     
00107     Thyra::ConstLinearOperator<Scalar> op_;
00108 
00109     Node x_;
00110 
00112     static Scalar one() {return Teuchos::ScalarTraits<Scalar>::one();}
00113 
00115     static Scalar zero() {return Teuchos::ScalarTraits<Scalar>::zero();}
00116   };
00117 
00118 
00119   
00121   template <class Scalar, class Node> inline
00122   Thyra::Vector<Scalar> formVector(const OpTimesLC<Scalar, Node>& lc)
00123   {
00124     return lc.formVector();
00125   }
00126 
00127 
00131   template <class Scalar, class Node1, class Node2>
00132   class LC2  : public ConvertibleToVector<Scalar>
00133   {
00134   public:
00136     virtual ~LC2(){;}
00137 
00139     LC2(const Node1& x1, const Node2& x2, LCSign sign = LCAdd);
00140 
00142     void evalInto(Thyra::Vector<Scalar>& result) const ;
00143 
00145     void addInto(Thyra::Vector<Scalar>& result, 
00146                  LCSign sign = LCAdd) const ;
00147 
00149     virtual Thyra::Vector<Scalar> formVector() const ;
00150 
00152     bool containsVector(const Thyra::VectorBase<Scalar>* vec) const ;
00153 
00154     
00155   private:
00156     Node1 x1_;
00157 
00158     Node2 x2_;
00159 
00160     LCSign sign_;
00161 
00163     static Scalar one() {return Teuchos::ScalarTraits<Scalar>::one();}
00164 
00166     static Scalar zero() {return Teuchos::ScalarTraits<Scalar>::zero();}
00167   };
00168 
00169   
00171   template <class Scalar, class Node1, class Node2> inline
00172   Thyra::Vector<Scalar> formVector(const LC2<Scalar, Node1, Node2>& lc)
00173   {
00174     return lc.formVector();
00175   }
00176   
00177   
00178 }
00179 
00180 #endif

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