Vector.h

Go to the documentation of this file.
```00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020
00021 // \$Revision: 1.10 \$
00022 // \$Date: 2006/10/02 17:30:05 \$
00023 // \$Source: /usr/local/cvs/OpenSees/SRC/matrix/Vector.h,v \$
00024
00025 // Written: fmk
00026 // Created: 11/96
00027 // Revision: A
00028 //
00029 // Description: This file contains the class definition for Vector.
00030 // Vector is a concrete class implementing the vector abstraction.
00031 //
00032 // What: "@(#) Vector.h, revA"
00033
00034 #ifndef Vector_h
00035 #define Vector_h
00036
00037 #include <OPS_Globals.h>
00038
00039 class ID;
00040
00041 #define VECTOR_VERY_LARGE_VALUE 1.0e200
00042
00043 class Matrix;
00044 class Message;
00045 class SystemOfEqn;
00046
00047 #include <Tensor.h> // cannot use class as Tensor is itself defined in Tensor.h
00048
00049 class Vector
00050 {
00051   public:
00052     // constructors and destructor
00053     Vector();
00054     Vector(int);
00055     Vector(const Vector &);
00056     Vector(double *data, int size);
00057     ~Vector();
00058
00059     // utility methods
00060     int setData(double *newData, int size);
00061     int Assemble(const Vector &V, const ID &l, double fact = 1.0);
00062     double Norm(void) const;
00063     double pNorm(int p) const;
00064     inline int Size(void) const;
00065     int resize(int newSize);
00066     inline void Zero(void);
00067     int Normalize(void);
00068
00069     int addVector(double factThis, const Vector &other, double factOther);
00070     int addMatrixVector(double factThis, const Matrix &m, const Vector &v, double factOther);
00071     int addMatrixTransposeVector(double factThis, const Matrix &m, const Vector &v, double factOther);
00072
00073
00074     // overloaded operators
00075     inline double operator()(int x) const;
00076     inline double &operator()(int x);
00077     double operator[](int x) const;  // these two operator do bounds checks
00078     double &operator[](int x);
00079     Vector operator()(const ID &rows) const;
00080     Vector &operator=(const Vector  &V);
00081     Vector &operator=(const Tensor  &T);
00082
00083     Vector &operator+=(double fact);
00084     Vector &operator-=(double fact);
00085     Vector &operator*=(double fact);
00086     Vector &operator/=(double fact);
00087
00088     Vector operator+(double fact) const;
00089     Vector operator-(double fact) const;
00090     Vector operator*(double fact) const;
00091     Vector operator/(double fact) const;
00092
00093     Vector &operator+=(const Vector &V);
00094     Vector &operator-=(const Vector &V);
00095
00096     Vector operator+(const Vector &V) const;
00097     Vector operator-(const Vector &V) const;
00098     double operator^(const Vector &V) const;
00099     Vector operator/(const Matrix &M) const;
00100
00101     int operator==(const Vector &V) const;
00102     int operator!=(const Vector &V) const;
00103
00104     // methods added by Remo
00105     int  Assemble(const Vector &V, int init_row, double fact = 1.0);
00106     int  Extract (const Vector &V, int init_row, double fact = 1.0);
00107
00108     friend OPS_Stream &operator<<(OPS_Stream &s, const Vector &V);
00109     // friend istream &operator>>(istream &s, Vector &V);
00110     friend Vector operator*(double a, const Vector &V);
00111
00112     friend class Message;
00113     friend class SystemOfEqn;
00114     friend class Matrix;
00115     friend class TCP_SocketNoDelay;
00116     friend class TCP_Socket;
00117     friend class UDP_Socket;
00118     friend class MPI_Channel;
00119     friend class MySqlDatastore;
00120     friend class BerkeleyDbDatastore;
00121
00122   private:
00123     static double VECTOR_NOT_VALID_ENTRY;
00124     int sz;
00125     double *theData;
00126     int fromFree;
00127 };
00128
00129
00130 /********* INLINED VECTOR FUNCTIONS ***********/
00131 inline int
00132 Vector::Size(void) const
00133 {
00134   return sz;
00135 }
00136
00137
00138 inline void
00139 Vector::Zero(void){
00140   for (int i=0; i<sz; i++) theData[i] = 0.0;
00141 }
00142
00143
00144 inline double
00145 Vector::operator()(int x) const
00146 {
00147 #ifdef _G3DEBUG
00148   // check if it is inside range [0,sz-1]
00149   if (x < 0 || x >= sz) {
00150       opserr << "Vector::(loc) - loc " << x << " outside range [0, " << sz-1 << endln;
00151       return VECTOR_NOT_VALID_ENTRY;
00152   }
00153 #endif
00154
00155       return theData[x];
00156 }
00157
00158
00159 inline double &
00160 Vector::operator()(int x)
00161 {
00162 #ifdef _G3DEBUG
00163     // check if it is inside range [0,sz-1]
00164   if (x < 0 || x >= sz) {
00165       opserr << "Vector::(loc) - loc " << x << " outside range [0, " << sz-1 << endln;
00166       return VECTOR_NOT_VALID_ENTRY;
00167   }
00168 #endif
00169
00170   return theData[x];
00171 }
00172
00173
00174 #endif
00175
```

Generated on Mon Oct 23 15:05:23 2006 for OpenSees by  1.5.0