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 TSFLINEARCOMBINATIONDECL_HPP
00030 #define TSFLINEARCOMBINATIONDECL_HPP
00031
00032 #include "SundanceDefs.hpp"
00033 #include "TSFVectorDecl.hpp"
00034 #include "TSFLinearOperatorDecl.hpp"
00035 #include "Teuchos_ScalarTraits.hpp"
00036
00037
00038
00039 namespace TSFExtendedOps
00040 {
00041 using TSFExtended::Vector;
00042 using TSFExtended::VectorSpace;
00043 using TSFExtended::LinearOperator;
00044
00045
00046
00047 template <class Scalar>
00048 class ConvertibleToVector
00049 {
00050 public:
00051
00052 virtual ~ConvertibleToVector(){;}
00053
00054
00055 virtual Vector<Scalar> eval() const = 0 ;
00056
00057
00058 VectorSpace<Scalar> space() const {return eval().space();}
00059
00060
00061 int dim() const {return eval().dim();}
00062
00063
00064
00065
00066 Vector<Scalar> copy() const {return eval().copy();}
00067
00068
00069
00070
00071 Vector<Scalar> dotStar(const Vector<Scalar>& other) const
00072 {return eval().dotStar(other);}
00073
00074
00075
00076
00077 Vector<Scalar> dotSlash(const Vector<Scalar>& other) const
00078 {return eval().dotSlash(other);}
00079
00080
00081
00082
00083 Vector<Scalar> reciprocal() const {return reciprocal();}
00084
00085
00086
00087
00088 Vector<Scalar> abs() const {return abs();}
00089
00090
00091 Scalar norm2() const {return eval().norm2();}
00092
00093
00094 Scalar norm1() const {return eval().norm1();}
00095
00096
00097 Scalar normInf() const {return eval().normInf();}
00098
00099
00100 Scalar max() const {return eval().max();}
00101
00102
00103 Scalar min() const {return eval().min();}
00104
00105
00106 Scalar min(int& index)const {return eval().min(index);}
00107
00108
00109 Scalar max(int& index)const {return eval().max(index);}
00110 };
00111
00112
00113
00114
00115 template <class Scalar, class Node>
00116 class OpTimesLC : public ConvertibleToVector<Scalar>
00117 {
00118 public:
00119
00120
00121 virtual ~OpTimesLC(){;}
00122
00123
00124 OpTimesLC(const Scalar& alpha, const Node& x);
00125
00126
00127 OpTimesLC(const Scalar& alpha,
00128 const TSFExtended::LinearOperator<Scalar>& op,
00129 const Node& x);
00130
00131
00132
00133
00134 void evalInto(TSFExtended::Vector<Scalar>& result) const ;
00135
00136
00137 void addInto(TSFExtended::Vector<Scalar>& result,
00138 LCSign sign = LCAdd) const ;
00139
00140
00141 virtual TSFExtended::Vector<Scalar> eval() const ;
00142
00143
00144 bool containsVector(const Thyra::VectorBase<Scalar>* vec) const ;
00145
00146
00147 const LinearOperator<Scalar>& op() const {return op_;}
00148
00149
00150 const Scalar& alpha() const {return alpha_;}
00151
00152
00153 const Node& node() const {return x_;}
00154
00155
00156 Scalar norm2() const {return eval().norm2();}
00157
00158
00159 Scalar normInf() const {return eval().normInf();}
00160
00161 private:
00162 Scalar alpha_;
00163
00164 TSFExtended::LinearOperator<Scalar> op_;
00165
00166 Node x_;
00167
00168
00169 static Scalar one() {return Teuchos::ScalarTraits<Scalar>::one();}
00170
00171
00172 static Scalar zero() {return Teuchos::ScalarTraits<Scalar>::zero();}
00173 };
00174
00175
00176
00177
00178
00179 template <class Scalar, class Node1, class Node2>
00180 class LC2 : public ConvertibleToVector<Scalar>
00181 {
00182 public:
00183
00184 virtual ~LC2(){;}
00185
00186
00187 LC2(const Node1& x1, const Node2& x2, LCSign sign = LCAdd);
00188
00189
00190 void evalInto(TSFExtended::Vector<Scalar>& result) const ;
00191
00192
00193 void addInto(TSFExtended::Vector<Scalar>& result,
00194 LCSign sign = LCAdd) const ;
00195
00196
00197 virtual TSFExtended::Vector<Scalar> eval() const ;
00198
00199
00200 bool containsVector(const Thyra::VectorBase<Scalar>* vec) const ;
00201
00202
00203 private:
00204 Node1 x1_;
00205
00206 Node2 x2_;
00207
00208 LCSign sign_;
00209
00210
00211 static Scalar one() {return Teuchos::ScalarTraits<Scalar>::one();}
00212
00213
00214 static Scalar zero() {return Teuchos::ScalarTraits<Scalar>::zero();}
00215 };
00216
00217
00218 }
00219
00220 namespace TSFExtended
00221 {
00222 using TSFExtendedOps::OpTimesLC;
00223 using TSFExtendedOps::LC2;
00224 using TSFExtendedOps::LCAdd;
00225 using TSFExtendedOps::LCSubtract;
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 template <class Scalar>
00238 OpTimesLC<Scalar, Vector<Scalar> > operator*(const Scalar& alpha,
00239 const Vector<Scalar>& x);
00240
00241
00242 template <class Scalar>
00243 OpTimesLC<Scalar, Vector<Scalar> > operator*(const Vector<Scalar>& x,
00244 const Scalar& alpha);
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 template <class Scalar, class Node>
00255 OpTimesLC<Scalar, Node>
00256 operator*(const Scalar& alpha,
00257 const OpTimesLC<Scalar, Node>& x);
00258
00259
00260 template <class Scalar, class Node>
00261 OpTimesLC<Scalar, Node>
00262 operator*(const OpTimesLC<Scalar, Node>& x, const Scalar& alpha);
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 template <class Scalar, class Node1, class Node2>
00273 OpTimesLC<Scalar, LC2<Scalar, Node1, Node2> >
00274 operator*(const Scalar& alpha,
00275 const LC2<Scalar, Node1, Node2>& x);
00276
00277
00278 template <class Scalar, class Node1, class Node2>
00279 OpTimesLC<Scalar, LC2<Scalar, Node1, Node2> >
00280 operator*(const LC2<Scalar, Node1, Node2>& x, const Scalar& alpha);
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 template <class Scalar>
00292 OpTimesLC<Scalar, Vector<Scalar> >
00293 operator*(const LinearOperator<Scalar>& op,
00294 const Vector<Scalar>& x);
00295
00296
00297
00298 template <class Scalar, class Node>
00299 OpTimesLC<Scalar, Node>
00300 operator*(const LinearOperator<Scalar>& op,
00301 const OpTimesLC<Scalar, Node>& x);
00302
00303
00304
00305 template <class Scalar, class Node1, class Node2>
00306 OpTimesLC<Scalar, LC2<Scalar, Node1, Node2> >
00307 operator*(const LinearOperator<Scalar>& op,
00308 const LC2<Scalar, Node1, Node2>& x);
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 template <class Scalar>
00319 LC2<Scalar, Vector<Scalar>, Vector<Scalar> >
00320 operator+(const Vector<Scalar>& x1,
00321 const Vector<Scalar>& x2);
00322
00323
00324 template <class Scalar>
00325 LC2<Scalar, Vector<Scalar>, Vector<Scalar> >
00326 operator-(const Vector<Scalar>& x1,
00327 const Vector<Scalar>& x2);
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 template <class Scalar, class Node>
00339 LC2<Scalar, Vector<Scalar>, OpTimesLC<Scalar, Node> >
00340 operator+(const Vector<Scalar>& x1,
00341 const OpTimesLC<Scalar, Node>& x2);
00342
00343
00344
00345 template <class Scalar, class Node>
00346 LC2<Scalar, Vector<Scalar>, OpTimesLC<Scalar, Node> >
00347 operator-(const Vector<Scalar>& x1,
00348 const OpTimesLC<Scalar, Node>& x2);
00349
00350
00351
00352 template <class Scalar, class Node>
00353 LC2<Scalar, OpTimesLC<Scalar, Node>, Vector<Scalar> >
00354 operator+(const OpTimesLC<Scalar, Node>& x1,
00355 const Vector<Scalar>& x2);
00356
00357
00358 template <class Scalar, class Node>
00359 LC2<Scalar, OpTimesLC<Scalar, Node>, Vector<Scalar> >
00360 operator-(const OpTimesLC<Scalar, Node>& x1,
00361 const Vector<Scalar>& x2);
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372 template <class Scalar, class Node1, class Node2>
00373 LC2<Scalar, OpTimesLC<Scalar, Node1>, OpTimesLC<Scalar, Node2> >
00374 operator+(const OpTimesLC<Scalar, Node1>& x1,
00375 const OpTimesLC<Scalar, Node2>& x2);
00376
00377
00378
00379 template <class Scalar, class Node1, class Node2>
00380 LC2<Scalar, OpTimesLC<Scalar, Node1>, OpTimesLC<Scalar, Node2> >
00381 operator-(const OpTimesLC<Scalar, Node1>& x1,
00382 const OpTimesLC<Scalar, Node2>& x2);
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394 template <class Scalar, class Node1, class Node2>
00395 LC2<Scalar, Vector<Scalar>, LC2<Scalar, Node1, Node2> >
00396 operator+(const Vector<Scalar>& x1,
00397 const LC2<Scalar, Node1, Node2>& x2);
00398
00399
00400
00401 template <class Scalar, class Node1, class Node2>
00402 LC2<Scalar, Vector<Scalar>, LC2<Scalar, Node1, Node2> >
00403 operator-(const Vector<Scalar>& x1,
00404 const LC2<Scalar, Node1, Node2>& x2);
00405
00406
00407
00408 template <class Scalar, class Node1, class Node2>
00409 LC2<Scalar, LC2<Scalar, Node1, Node2>, Vector<Scalar> >
00410 operator+(const LC2<Scalar, Node1, Node2>& x1,
00411 const Vector<Scalar>& x2);
00412
00413
00414
00415 template <class Scalar, class Node1, class Node2>
00416 LC2<Scalar, LC2<Scalar, Node1, Node2>, Vector<Scalar> >
00417 operator-(const LC2<Scalar, Node1, Node2>& x1,
00418 const Vector<Scalar>& x2);
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430 template <class Scalar, class Node0, class Node1, class Node2>
00431 LC2<Scalar, OpTimesLC<Scalar, Node0>, LC2<Scalar, Node1, Node2> >
00432 operator+(const OpTimesLC<Scalar, Node0>& x1,
00433 const LC2<Scalar, Node1, Node2>& x2);
00434
00435
00436 template <class Scalar, class Node0, class Node1, class Node2>
00437 LC2<Scalar, OpTimesLC<Scalar, Node0>, LC2<Scalar, Node1, Node2> >
00438 operator-(const OpTimesLC<Scalar, Node0>& x1,
00439 const LC2<Scalar, Node1, Node2>& x2);
00440
00441
00442
00443
00444 template <class Scalar, class Node1, class Node2, class Node3>
00445 LC2<Scalar, LC2<Scalar, Node1, Node2>, OpTimesLC<Scalar, Node3> >
00446 operator+(const LC2<Scalar, Node1, Node2>& x1,
00447 const OpTimesLC<Scalar, Node3>& x2);
00448
00449
00450
00451 template <class Scalar, class Node1, class Node2, class Node3>
00452 LC2<Scalar, LC2<Scalar, Node1, Node2>, OpTimesLC<Scalar, Node3> >
00453 operator-(const LC2<Scalar, Node1, Node2>& x1,
00454 const OpTimesLC<Scalar, Node3>& x2);
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465 template <class Scalar, class Node1, class Node2,
00466 class Node3, class Node4>
00467 LC2<Scalar, LC2<Scalar, Node1, Node2>, LC2<Scalar, Node3, Node4> >
00468 operator+(const LC2<Scalar, Node1, Node2>& x1,
00469 const LC2<Scalar, Node3, Node4>& x2);
00470
00471
00472
00473 template <class Scalar, class Node1, class Node2,
00474 class Node3, class Node4>
00475 LC2<Scalar, LC2<Scalar, Node1, Node2>, LC2<Scalar, Node3, Node4> >
00476 operator-(const LC2<Scalar, Node1, Node2>& x1,
00477 const LC2<Scalar, Node3, Node4>& x2);
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487 }
00488
00489
00490
00491 #endif