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

PathSeries.cpp

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.1.1.1 $
00022 // $Date: 2000/09/15 08:23:19 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/domain/pattern/PathSeries.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/domain/pattern/PathSeries.C
00027 //
00028 // Written: fmk 
00029 // Created: 07/99
00030 // Revision: A
00031 //
00032 // Purpose: This file contains the class definition for PathSeries.
00033 // PathSeries is a concrete class. A PathSeries object provides
00034 // a linear time series. the factor is given by the pseudoTime and 
00035 // a constant factor provided in the constructor.
00036 //
00037 // What: "@(#) PathSeries.C, revA"
00038 
00039 
00040 #include <PathSeries.h>
00041 #include <Vector.h>
00042 #include <Channel.h>
00043 #include <math.h>
00044 
00045 #include <fstream.h>
00046 #include <iostream.h>
00047 
00048 PathSeries::PathSeries() 
00049   :TimeSeries(TSERIES_TAG_PathSeries),
00050    thePath(0), pathTimeIncr(0.0), cFactor(0.0), otherDbTag(0)
00051 {
00052   // does nothing
00053 }
00054 
00055      
00056 PathSeries::PathSeries(const Vector &theLoadPath, 
00057          double theTimeIncr, 
00058          double theFactor)
00059   :TimeSeries(TSERIES_TAG_PathSeries),
00060    thePath(0), pathTimeIncr(theTimeIncr), cFactor(theFactor), otherDbTag(0)
00061 {
00062   // create a copy of the vector containg path points
00063   thePath = new Vector(theLoadPath);
00064 
00065   // ensure we did not run out of memory
00066   if (thePath == 0 || thePath->Size() == 0) {
00067     cerr << "PathSeries::PathSeries() - ran out of memory constructing";
00068     cerr << " a Vector of size: " <<  theLoadPath.Size() << endl;
00069     if (thePath != 0)
00070       delete thePath; 
00071     thePath = 0;
00072   }
00073 }
00074 
00075 
00076 PathSeries::PathSeries(char *fileName, 
00077          double theTimeIncr, 
00078          double theFactor)
00079   :TimeSeries(TSERIES_TAG_PathSeries),
00080    thePath(0), pathTimeIncr(theTimeIncr), cFactor(theFactor)
00081 {
00082   // determine the number of data points
00083   int numDataPoints =0;
00084   double dataPoint;
00085   ifstream theFile;
00086   theFile.open(fileName);
00087 
00088   if (!theFile) {
00089     cerr << "WARNING - PathSeries::PathSeries()";
00090     cerr << " - could not open file " << fileName << endl;
00091   } else {
00092     while (theFile >> dataPoint)
00093       numDataPoints++;
00094   }   
00095   theFile.close();
00096 
00097 
00098   // create a vector and read in the data
00099   if (numDataPoints != 0) {
00100 
00101     // first open the file
00102     theFile.open(fileName, ios::in);
00103     if (!theFile) {
00104       cerr << "WARNING - PathSeries::PathSeries()";
00105       cerr << " - could not open file " << fileName << endl;
00106     } else {
00107 
00108       // now create the vector
00109       thePath = new Vector(numDataPoints);
00110 
00111       // ensure we did not run out of memory
00112       if (thePath == 0 || thePath->Size() == 0) {
00113  cerr << "PathSeries::PathSeries() - ran out of memory constructing";
00114  cerr << " a Vector of size: " << numDataPoints << endl;
00115 
00116  if (thePath != 0)
00117    delete thePath;
00118  thePath = 0;
00119       }
00120 
00121       // read the data from the file
00122       else {
00123  int count = 0;
00124  while (theFile >> dataPoint) {
00125    (*thePath)(count) = dataPoint;
00126    count++;
00127  }
00128       }
00129 
00130       // finally close the file
00131       theFile.close();
00132     }
00133   }
00134 }
00135 
00136 
00137 PathSeries::~PathSeries()
00138 {
00139   if (thePath != 0)
00140     delete thePath;
00141 }
00142 
00143 double
00144 PathSeries::getFactor(double pseudoTime)
00145 {
00146   // check for a quick return
00147   if (pseudoTime < 0.0 || thePath == 0)
00148     return 0.0;
00149 
00150   // determine indexes into the data array whose boundary holds the time
00151   double incr = pseudoTime/pathTimeIncr; 
00152   int incr1 = floor(incr);
00153   int incr2 = incr1+1;
00154 
00155   if (incr2 >= thePath->Size())
00156     return 0.0;
00157   else {
00158     double value1 = (*thePath)[incr1];
00159     double value2 = (*thePath)[incr2];
00160     return cFactor*(value1 + (value2-value1)*(pseudoTime/pathTimeIncr - incr1));
00161   }
00162 }
00163 
00164 
00165 double
00166 PathSeries::getDuration()
00167 {
00168   if (thePath == 0)
00169   {
00170     cerr << "WARNING -- PathSeries::getDuration() on empty Vector" << endl;
00171  return 0.0;
00172   }
00173   return (thePath->Size() * pathTimeIncr);
00174 }
00175 
00176 double
00177 PathSeries::getPeakFactor()
00178 {
00179   if (thePath == 0)
00180   {
00181     cerr << "WARNING -- PathSeries::getPeakFactor() on empty Vector" << endl;
00182  return 0.0;
00183   }
00184 
00185   double peak = fabs((*thePath)[0]);
00186   int num = thePath->Size();
00187   double temp;
00188 
00189   for (int i = 1; i < num; i++)
00190   {
00191  temp = fabs((*thePath)[i]);
00192  if (temp > peak)
00193    peak = temp;
00194   }
00195   
00196   return (peak*cFactor);
00197 }
00198 
00199 int
00200 PathSeries::sendSelf(int commitTag, Channel &theChannel)
00201 {
00202   int dbTag = this->getDbTag();
00203   Vector data(4);
00204   data(0) = cFactor;
00205   data(1) = pathTimeIncr;
00206   data(2) = -1;
00207   
00208   if (thePath != 0) {
00209     int size = thePath->Size();
00210     data(2) = size;
00211     if (otherDbTag == 0)
00212       otherDbTag = theChannel.getDbTag();
00213     data(3) = otherDbTag;
00214   }
00215   
00216   int result = theChannel.sendVector(dbTag,commitTag, data);
00217   if (result < 0) {
00218     cerr << "PathSeries::sendSelf() - channel failed to send data\n";
00219     return result;
00220   }
00221   
00222   if (thePath != 0) {
00223     result = theChannel.sendVector(otherDbTag, commitTag, *thePath);
00224     if (result < 0) {
00225       cerr << "PathSeries::sendSelf() - ";
00226       cerr << "channel failed to send tha Path Vector\n";
00227       return result;  
00228     }
00229   }
00230   return 0;
00231 }
00232 
00233 
00234 int 
00235 PathSeries::recvSelf(int commitTag, Channel &theChannel, 
00236          FEM_ObjectBroker &theBroker)
00237 {
00238   int dbTag = this->getDbTag();
00239   Vector data(4);
00240   int result = theChannel.recvVector(dbTag,commitTag, data);
00241   if (result < 0) {
00242     cerr << "PathSeries::sendSelf() - channel failed to receive data\n";
00243     cFactor = 1.0;
00244     return result;
00245   }
00246   cFactor = data(0);
00247   pathTimeIncr = data(1);
00248   int size = data(2);
00249   otherDbTag = data(3);
00250 
00251   // get the other path vector
00252   if (size > 0) {
00253     thePath = new Vector(size);
00254     if (thePath == 0 || thePath->Size() == 0) {
00255       cerr << "PathSeries::recvSelf() - ran out of memory";
00256       cerr << " a Vector of size: " <<  size << endl;  
00257       if (thePath != 0)
00258  delete thePath;
00259       thePath = 0;
00260       return -1;
00261     }
00262     result = theChannel.recvVector(otherDbTag,commitTag, *thePath);    
00263     if (result < 0) {
00264       cerr << "PathSeries::recvSelf() - ";
00265       cerr << "channel failed to receive tha Path Vector\n";
00266       return result;  
00267     }
00268   }
00269   return 0;    
00270 }
00271 
00272 
00273 
00274 void
00275 PathSeries::Print(ostream &s, int flag)
00276 {
00277     //s << "Path Time Series: constant factor: " << cFactor;
00278     //s << "  time Incr: " << pathTimeIncr << endl;
00279     if (flag == 1 && thePath != 0)
00280       //s << " specified path: " << *thePath;
00281    s << *thePath;
00282 }
Copyright Contact Us