Go to the documentation of this file.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 TSFVECTORDECL_HPP
00030 #define TSFVECTORDECL_HPP
00031
00032 #include "SundanceDefs.hpp"
00033 #include "SundanceHandle.hpp"
00034 #include "Thyra_VectorBase.hpp"
00035 #include "Thyra_VectorSpaceBase.hpp"
00036 #include "TSFVectorSpaceDecl.hpp"
00037 #include "TSFLoadableVector.hpp"
00038 #include "TSFAccessibleVector.hpp"
00039 #include "TSFRawDataAccessibleVector.hpp"
00040 #include "Thyra_VectorStdOps.hpp"
00041 #include "Teuchos_TimeMonitor.hpp"
00042
00043 #ifdef TRILINOS_6
00044 #include "Thyra_ProductVector.hpp"
00045 #else
00046 #include "Thyra_DefaultProductVector.hpp"
00047 #include "Thyra_VectorStdOps.hpp"
00048 #endif
00049
00050 namespace TSFExtendedOps
00051 {
00052 template <class Scalar, class Node1, class Node2> class LC2;
00053 template <class Scalar, class Node> class OpTimesLC;
00054
00055
00056
00057 enum LCSign {LCAdd = 1, LCSubtract = -1};
00058 }
00059
00060 namespace TSFExtended
00061 {
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 template <class Scalar>
00105 class Vector : public Sundance::Handle<Thyra::VectorBase<Scalar> >
00106 {
00107 public:
00108
00109
00110 HANDLE_CTORS(Vector<Scalar>, Thyra::VectorBase<Scalar>);
00111
00112
00113 template<class Node1, class Node2>
00114 Vector(const TSFExtendedOps::LC2<Scalar, Node1, Node2>& x);
00115
00116
00117 template<class Node>
00118 Vector(const TSFExtendedOps::OpTimesLC<Scalar, Node>& x);
00119
00120
00121 template<class Node1, class Node2>
00122 Vector& operator=(const TSFExtendedOps::LC2<Scalar, Node1, Node2>& x);
00123
00124
00125 template<class Node>
00126 Vector& operator=(const TSFExtendedOps::OpTimesLC<Scalar, Node>& x);
00127
00128
00129
00130 VectorSpace<Scalar> space() const
00131 {return this->ptr()->space();}
00132
00133
00134 int dim() const
00135 {
00136 return this->ptr()->space()->dim();
00137 }
00138
00139
00140
00141
00142
00143
00144 void setBlock(int i, const Vector<Scalar>& v);
00145
00146
00147 Vector<Scalar> getBlock(int i) const;
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 Vector<Scalar>& scale(const Scalar& alpha);
00159
00160
00161
00162
00163
00164
00165
00166 Vector<Scalar>& update(const Scalar& alpha, const Vector<Scalar>& x);
00167
00168
00169
00170
00171
00172
00173
00174 Vector<Scalar>& update(const Scalar& alpha, const Vector<Scalar>& x,
00175 const Scalar& gamma);
00176
00177
00178
00179
00180
00181
00182 Vector<Scalar>& update(const Scalar& alpha, const Vector<Scalar>& x,
00183 const Scalar& beta, const Vector<Scalar>& y,
00184 const Scalar& gamma);
00185
00186
00187
00188
00189
00190
00191
00192 Vector<Scalar>& acceptCopyOf(const Vector<Scalar>& x);
00193
00194
00195
00196
00197 Vector<Scalar> copy() const ;
00198
00199
00200
00201
00202 Vector<Scalar> dotStar(const Vector<Scalar>& other) const ;
00203
00204
00205
00206
00207
00208 void dotStarInto(const Vector<Scalar>& a, const Vector<Scalar>& b) const ;
00209
00210
00211
00212
00213 Vector<Scalar> dotSlash(const Vector<Scalar>& other) const ;
00214
00215
00216
00217
00218 Vector<Scalar> reciprocal() const ;
00219
00220
00221
00222
00223
00224 Vector<Scalar> abs() const ;
00225
00226
00227
00228
00229 Vector<Scalar>& reciprocal() ;
00230
00231
00232
00233
00234 Vector<Scalar>& abs() ;
00235
00236
00237
00238
00239 void setToConstant(const Scalar& alpha) ;
00240
00241
00242
00243
00244
00245 Scalar dot(const Vector<Scalar>& other) const ;
00246
00247
00248
00249
00250 Scalar operator*(const Vector<Scalar>& other) const ;
00251
00252
00253
00254
00255 Scalar norm1() const ;
00256
00257
00258
00259
00260 Scalar norm2() const ;
00261
00262
00263
00264
00265 Scalar norm2(const Vector<Scalar>& weights) const ;
00266
00267
00268
00269
00270
00271 Scalar normInf() const ;
00272
00273
00274
00275
00276 void zero();
00277
00278
00279
00280 Scalar max() const;
00281
00282
00283 Scalar max(int& index)const;
00284
00285
00286 Scalar max(const Scalar& bound, int& index)const;
00287
00288
00289 Scalar min()const;
00290
00291
00292 Scalar min(int& index)const;
00293
00294
00295 Scalar min(const Scalar& bound, int& index)const;
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 void setElement(OrdType globalIndex, const Scalar& value) ;
00306
00307
00308
00309 void addToElement(OrdType globalIndex, const Scalar& value) ;
00310
00311
00312 void setElements(OrdType numElems, const OrdType* globalIndices,
00313 const Scalar* values)
00314 {castToLoadable()->setElements(numElems, globalIndices, values);}
00315
00316
00317 void addToElements(OrdType numElems, const OrdType* globalIndices,
00318 const Scalar* values)
00319 {castToLoadable()->addToElements(numElems, globalIndices, values);}
00320
00321
00322
00323
00324 void finalizeAssembly() {castToLoadable()->finalizeAssembly();}
00325
00326
00327
00328
00329
00330 Scalar getElement(OrdType globalIndex) const ;
00331
00332
00333
00334 void getElements(const int* globalIndices, int numElems,
00335 Teuchos::Array<Scalar>& elems) const
00336 {castToAccessible()->getElements(globalIndices, numElems, elems);}
00337
00338
00339
00340 const Scalar& operator[](const SequentialIterator<Scalar>& index) const ;
00341
00342
00343 Scalar& operator[](const SequentialIterator<Scalar>& index);
00344
00345
00346
00347
00348
00349
00350 const Scalar* dataPtr() const
00351 {return castToRawDataAccessible()->dataPtr();}
00352
00353
00354 Scalar* dataPtr()
00355 {return castToRawDataAccessible()->dataPtr();}
00356
00357
00358
00359
00360
00361 static RCP<Time>& opTimer()
00362 {
00363 static RCP<Time> rtn
00364 = TimeMonitor::getNewTimer("Low-level vector operations");
00365 return rtn;
00366 }
00367
00368
00369
00370 Vector<Scalar> eval() const {return copy();}
00371
00372 bool containsVector(const Thyra::VectorBase<Scalar>* vec) const
00373 {return this->ptr().get()==vec;}
00374
00375 void evalInto(Vector<Scalar>& other) const {other.acceptCopyOf(*this);}
00376
00377 void addInto(Vector<Scalar>& other, TSFExtendedOps::LCSign sign) const
00378 {
00379 other.update(sign, *this);
00380 }
00381
00382
00383 std::string description() const
00384 {
00385 const Describable* d =
00386 dynamic_cast<const Describable* >(this->ptr().get());
00387 if (d != 0)
00388 {
00389 return d->description();
00390 }
00391 return "Vector not describable";
00392 }
00393
00394 void print(std::ostream& os) const ;
00395
00396
00397 private:
00398
00399
00400 const AccessibleVector<Scalar>* castToAccessible() const ;
00401
00402
00403 LoadableVector<Scalar>* castToLoadable() ;
00404
00405
00406 const RawDataAccessibleVector<Scalar>* castToRawDataAccessible() const ;
00407
00408
00409 RawDataAccessibleVector<Scalar>* castToRawDataAccessible();
00410
00411
00412 void boundscheck(OrdType i, int dim) const ;
00413
00414
00415 const Scalar& localElement(const OrdType& blockIndex, const OrdType& indexInBlock) const ;
00416
00417
00418 Scalar& localElement(const OrdType& blockIndex, const OrdType& indexInBlock) ;
00419
00420
00421 };
00422 }
00423
00424 template <class Scalar> inline
00425 std::ostream& operator<<(std::ostream& os, const TSFExtended::Vector<Scalar>& x)
00426 {
00427 x.print(os);
00428 return os;
00429 }
00430
00431
00432
00433
00434 #endif