00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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