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
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef Vector_h
00039 #define Vector_h
00040
00041 #include <iostream.h>
00042 #include <G3Globals.h>
00043
00044 #include <ID.h>
00045
00046 #define VECTOR_VERY_LARGE_VALUE 1.0e200
00047
00048 #include <Matrix.h>
00049 #include <Message.h>
00050 #include <SystemOfEqn.h>
00051
00052 #include <Tensor.h>
00053
00054
00070 class Vector
00071 {
00072 public:
00074 Vector();
00078 Vector(int);
00079
00087 Vector(const Vector &);
00088
00097 Vector(double *data, int size);
00098
00107 ~Vector();
00108
00109
00111 int setData(double *newData, int size);
00120 int Assemble(const Vector &V, const ID &l, double fact = 1.0);
00121
00127 double Norm(void) const;
00128
00133 inline int Size(void) const;
00134
00136 int resize(int newSize);
00137
00139 inline void Zero(void);
00141 int Normalize(void);
00142
00144 int addVector(double factThis, const Vector &other, double factOther);
00146 int addMatrixVector(double factThis, const Matrix &m, const Vector &v, double factOther);
00148 int addMatrixTransposeVector(double factThis, const Matrix &m, const Vector &v, double factOther);
00149
00150
00152 inline double operator()(int x) const;
00154 inline double &operator()(int x);
00156 double operator[](int x) const;
00157 double &operator[](int x);
00159 Vector operator()(const ID &rows) const;
00161 Vector &operator=(const Vector &V);
00163 Vector &operator=(const Tensor &T);
00164
00166 Vector &operator+=(double fact);
00168 Vector &operator-=(double fact);
00170 Vector &operator*=(double fact);
00172 Vector &operator/=(double fact);
00173
00175 Vector operator+(double fact) const;
00177 Vector operator-(double fact) const;
00179 Vector operator*(double fact) const;
00181 Vector operator/(double fact) const;
00182
00184 Vector &operator+=(const Vector &V);
00186 Vector &operator-=(const Vector &V);
00187
00189 Vector operator+(const Vector &V) const;
00191 Vector operator-(const Vector &V) const;
00193 double operator^(const Vector &V) const;
00195 Vector operator/(const Matrix &M) const;
00196
00198 int Assemble(const Vector &V, int init_row, double fact = 1.0);
00200 int Extract (const Vector &V, int init_row, double fact = 1.0);
00201
00203 friend ostream &operator<<(ostream &s, const Vector &V);
00205 friend istream &operator>>(istream &s, Vector &V);
00207 friend Vector operator*(double a, const Vector &V);
00208
00210 friend #include <Message.h>
00211 friend #include <SystemOfEqn.h>
00212 friend #include <Matrix.h>
00213 friend #include <TCP_SocketNoDelay.h>
00214 friend #include <TCP_Socket.h>
00215 friend #include <UDP_Socket.h>
00216 friend #include <MPI_Channel.h>
00217
00218 private:
00219 static double VECTOR_NOT_VALID_ENTRY;
00221 int sz;
00223 double *theData;
00225 int fromFree;
00226 };
00227
00228
00229
00230
00231
00232 inline int
00233 Vector::Size(void) const
00234 {
00235 return sz;
00236 }
00237
00238
00240 inline void
00241 Vector::Zero(void){
00242 for (int i=0; i<sz; i++) theData[i] = 0.0;
00243 }
00244
00245
00247 inline double
00248 Vector::operator()(int x) const
00249 {
00250 #ifdef _G3DEBUG
00251
00252 if (x < 0 || x >= sz) {
00253 g3ErrorHandler->warning("Vector::(loc) - loc %d outside range [0, %d]\n",x,sz-1);
00254 return VECTOR_NOT_VALID_ENTRY;
00255 }
00256 #endif
00257
00258 return theData[x];
00259 }
00260
00261
00263 inline double &
00264 Vector::operator()(int x)
00265 {
00266 #ifdef _G3DEBUG
00267
00268 if (x < 0 || x >= sz) {
00269 g3ErrorHandler->warning("Vector::(loc) - loc %d outside range [0, %d]\n",x,sz-1);
00270 return VECTOR_NOT_VALID_ENTRY;
00271 }
00272 #endif
00273
00274 return theData[x];
00275 }
00276
00277
00278 #endif
00279