Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

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.4 $
00022 // $Date: 2001/07/23 20:41:19 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/matrix/Vector.h,v $
00024 
00025                                                                         
00026 // File: ~/matrix/Vector.h
00027 //
00028 // Written: fmk 
00029 // Created: 11/96
00030 // Revision: A
00031 //
00032 // Description: This file contains the class definition for Vector.
00033 // Vector is a concrete class implementing the vector abstraction.
00034 //
00035 // What: "@(#) Vector.h, revA"
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 /********** INLINED VECTOR FUNCTIONS ***********/
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   // check if it is inside range [0,sz-1]
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     // check if it is inside range [0,sz-1]
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 
Copyright Contact Us