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
00039
00040 #include <PathSeries.h>
00041 #include <Vector.h>
00042 #include <Channel.h>
00043 #include <math.h>
00044
00045 #include <fstream>
00046 using std::ifstream;
00047
00048 #include <iomanip>
00049 using std::ios;
00050
00051 PathSeries::PathSeries()
00052 :TimeSeries(TSERIES_TAG_PathSeries),
00053 thePath(0), pathTimeIncr(0.0), cFactor(0.0), otherDbTag(0), lastSendCommitTag(-1)
00054 {
00055
00056 }
00057
00058
00059 PathSeries::PathSeries(const Vector &theLoadPath,
00060 double theTimeIncr,
00061 double theFactor)
00062 :TimeSeries(TSERIES_TAG_PathSeries),
00063 thePath(0), pathTimeIncr(theTimeIncr), cFactor(theFactor), otherDbTag(0), lastSendCommitTag(-1)
00064 {
00065
00066 thePath = new Vector(theLoadPath);
00067
00068
00069 if (thePath == 0 || thePath->Size() == 0) {
00070 opserr << "PathSeries::PathSeries() - ran out of memory constructing";
00071 opserr << " a Vector of size: " << theLoadPath.Size() << endln;
00072 if (thePath != 0)
00073 delete thePath;
00074 thePath = 0;
00075 }
00076 }
00077
00078
00079 PathSeries::PathSeries(const char *fileName,
00080 double theTimeIncr,
00081 double theFactor)
00082 :TimeSeries(TSERIES_TAG_PathSeries),
00083 thePath(0), pathTimeIncr(theTimeIncr), cFactor(theFactor), otherDbTag(0), lastSendCommitTag(-1)
00084 {
00085
00086 int numDataPoints =0;
00087 double dataPoint;
00088
00089 ifstream theFile;
00090 theFile.open(fileName);
00091
00092 if (theFile.bad() || !theFile.is_open()) {
00093 opserr << "WARNING - PathSeries::PathSeries()";
00094 opserr << " - could not open file " << fileName << endln;
00095 } else {
00096 while (theFile >> dataPoint)
00097 numDataPoints++;
00098 }
00099 theFile.close();
00100
00101
00102
00103 if (numDataPoints != 0) {
00104
00105
00106 ifstream theFile1;
00107 theFile1.open(fileName, ios::in);
00108 if (theFile1.bad() || !theFile1.is_open()) {
00109 opserr << "WARNING - PathSeries::PathSeries()";
00110 opserr << " - could not open file " << fileName << endln;
00111 } else {
00112
00113
00114 thePath = new Vector(numDataPoints);
00115
00116
00117 if (thePath == 0 || thePath->Size() == 0) {
00118 opserr << "PathSeries::PathSeries() - ran out of memory constructing";
00119 opserr << " a Vector of size: " << numDataPoints << endln;
00120
00121 if (thePath != 0)
00122 delete thePath;
00123 thePath = 0;
00124 }
00125
00126
00127 else {
00128 int count = 0;
00129 while (theFile1 >> dataPoint) {
00130 (*thePath)(count) = dataPoint;
00131 count++;
00132 }
00133 }
00134
00135
00136 theFile1.close();
00137 }
00138 }
00139 }
00140
00141
00142 PathSeries::~PathSeries()
00143 {
00144 if (thePath != 0)
00145 delete thePath;
00146 }
00147
00148 double
00149 PathSeries::getFactor(double pseudoTime)
00150 {
00151
00152 if (pseudoTime < 0.0 || thePath == 0)
00153 return 0.0;
00154
00155
00156 double incr = pseudoTime/pathTimeIncr;
00157 int incr1 = floor(incr);
00158 int incr2 = incr1+1;
00159
00160 if (incr2 >= thePath->Size())
00161 return 0.0;
00162 else {
00163 double value1 = (*thePath)[incr1];
00164 double value2 = (*thePath)[incr2];
00165 return cFactor*(value1 + (value2-value1)*(pseudoTime/pathTimeIncr - incr1));
00166 }
00167 }
00168
00169
00170 double
00171 PathSeries::getDuration()
00172 {
00173 if (thePath == 0)
00174 {
00175 opserr << "WARNING -- PathSeries::getDuration() on empty Vector" << endln;
00176 return 0.0;
00177 }
00178 return (thePath->Size() * pathTimeIncr);
00179 }
00180
00181 double
00182 PathSeries::getPeakFactor()
00183 {
00184 if (thePath == 0)
00185 {
00186 opserr << "WARNING -- PathSeries::getPeakFactor() on empty Vector" << endln;
00187 return 0.0;
00188 }
00189
00190 double peak = fabs((*thePath)[0]);
00191 int num = thePath->Size();
00192 double temp;
00193
00194 for (int i = 1; i < num; i++)
00195 {
00196 temp = fabs((*thePath)[i]);
00197 if (temp > peak)
00198 peak = temp;
00199 }
00200
00201 return (peak*cFactor);
00202 }
00203
00204 int
00205 PathSeries::sendSelf(int commitTag, Channel &theChannel)
00206 {
00207 int dbTag = this->getDbTag();
00208
00209 Vector data(5);
00210 data(0) = cFactor;
00211 data(1) = pathTimeIncr;
00212 data(2) = -1;
00213
00214 if (thePath != 0) {
00215 int size = thePath->Size();
00216 data(2) = size;
00217 if (otherDbTag == 0)
00218 otherDbTag = theChannel.getDbTag();
00219 data(3) = otherDbTag;
00220 }
00221
00222 if ((lastSendCommitTag == -1) && (theChannel.isDatastore() == 1)) {
00223 lastSendCommitTag = commitTag;
00224 }
00225
00226 data(4) = lastSendCommitTag;
00227
00228 int result = theChannel.sendVector(dbTag,commitTag, data);
00229 if (result < 0) {
00230 opserr << "PathSeries::sendSelf() - channel failed to send data\n";
00231 return result;
00232 }
00233
00234
00235
00236
00237 if ((lastSendCommitTag == commitTag) || (theChannel.isDatastore() == 0)) {
00238 if (thePath != 0) {
00239 result = theChannel.sendVector(otherDbTag, commitTag, *thePath);
00240 if (result < 0) {
00241 opserr << "PathSeries::sendSelf() - ";
00242 opserr << "channel failed to send tha Path Vector\n";
00243 return result;
00244 }
00245 }
00246 }
00247
00248 return 0;
00249 }
00250
00251
00252 int
00253 PathSeries::recvSelf(int commitTag, Channel &theChannel,
00254 FEM_ObjectBroker &theBroker)
00255 {
00256 int dbTag = this->getDbTag();
00257
00258 Vector data(5);
00259 int result = theChannel.recvVector(dbTag,commitTag, data);
00260 if (result < 0) {
00261 opserr << "PathSeries::sendSelf() - channel failed to receive data\n";
00262 cFactor = 1.0;
00263 return result;
00264 }
00265
00266 cFactor = data(0);
00267 pathTimeIncr = data(1);
00268 int size = data(2);
00269 otherDbTag = data(3);
00270 lastSendCommitTag = data(4);
00271
00272
00273 if (thePath == 0 && size > 0) {
00274 thePath = new Vector(size);
00275 if (thePath == 0 || thePath->Size() == 0) {
00276 opserr << "PathSeries::recvSelf() - ran out of memory";
00277 opserr << " a Vector of size: " << size << endln;
00278 if (thePath != 0)
00279 delete thePath;
00280 thePath = 0;
00281 return -1;
00282 }
00283
00284 result = theChannel.recvVector(otherDbTag, lastSendCommitTag, *thePath);
00285 if (result < 0) {
00286 opserr << "PathSeries::recvSelf() - ";
00287 opserr << "channel failed to receive tha Path Vector\n";
00288 return result;
00289 }
00290 }
00291
00292 return 0;
00293 }
00294
00295
00296
00297 void
00298 PathSeries::Print(OPS_Stream &s, int flag)
00299 {
00300
00301
00302 if (flag == 1 && thePath != 0)
00303
00304 s << *thePath;
00305 }