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 #include <PathTimeSeries.h>
00039 #include <Vector.h>
00040 #include <Channel.h>
00041 #include <math.h>
00042
00043 #include <fstream>
00044 using std::ifstream;
00045
00046 #include <iomanip>
00047 using std::ios;
00048
00049 PathTimeSeries::PathTimeSeries()
00050 :TimeSeries(TSERIES_TAG_PathTimeSeries),
00051 thePath(0), time(0), currentTimeLoc(0),
00052 cFactor(0.0), dbTag1(0), dbTag2(0), lastSendCommitTag(-1)
00053 {
00054
00055 }
00056
00057
00058 PathTimeSeries::PathTimeSeries(const Vector &theLoadPath,
00059 const Vector &theTimePath,
00060 double theFactor)
00061 :TimeSeries(TSERIES_TAG_PathTimeSeries),
00062 thePath(0), time(0), currentTimeLoc(0),
00063 cFactor(theFactor), dbTag1(0), dbTag2(0), lastSendCommitTag(-1), lastChannel(0)
00064 {
00065
00066 if (theLoadPath.Size() != theTimePath.Size()) {
00067 opserr << "WARNING PathTimeSeries::PathTimeSeries() - vector containing data ";
00068 opserr << "points for path and time are not of the same size\n";
00069 } else {
00070
00071
00072 thePath = new Vector(theLoadPath);
00073 time = new Vector(theTimePath);
00074
00075
00076 if (thePath == 0 || thePath->Size() == 0 ||
00077 time == 0 || time->Size() == 0) {
00078
00079 opserr << "WARNING PathTimeSeries::PathTimeSeries() - out of memory\n ";
00080 if (thePath != 0)
00081 delete thePath;
00082 if (time != 0)
00083 delete time;
00084 thePath = 0;
00085 time = 0;
00086 }
00087 }
00088 }
00089
00090
00091 PathTimeSeries::PathTimeSeries(const char *filePathName,
00092 const char *fileTimeName,
00093 double theFactor)
00094 :TimeSeries(TSERIES_TAG_PathTimeSeries),
00095 thePath(0), time(0), currentTimeLoc(0),
00096 cFactor(theFactor), dbTag1(0), dbTag2(0), lastSendCommitTag(-1), lastChannel(0)
00097 {
00098
00099
00100 int numDataPoints1 =0;
00101 int numDataPoints2 =0;
00102 double dataPoint;
00103 ifstream theFile;
00104
00105
00106 theFile.open(filePathName, ios::in);
00107 if (theFile.bad() || !theFile.is_open()) {
00108 opserr << "WARNING - PathTimeSeries::PathTimeSeries()";
00109 opserr << " - could not open file " << filePathName << endln;
00110 } else {
00111 while (theFile >> dataPoint)
00112 numDataPoints1++;
00113 }
00114 theFile.close();
00115
00116
00117 ifstream theFile1;
00118 theFile1.open(fileTimeName, ios::in);
00119 if (theFile1.bad() || !theFile1.is_open()) {
00120 opserr << "WARNING - PathTimeSeries::PathTimeSeries()";
00121 opserr << " - could not open file " << fileTimeName << endln;
00122 } else {
00123 while (theFile1 >> dataPoint)
00124 numDataPoints2++;
00125 }
00126 theFile1.close();
00127
00128
00129 if (numDataPoints1 != numDataPoints2) {
00130 opserr << "WARNING PathTimeSeries::PathTimeSeries() - files containing data ";
00131 opserr << "points for path and time do not contain same number of points\n";
00132 } else {
00133
00134
00135
00136 if (numDataPoints1 != 0) {
00137
00138
00139 thePath = new Vector(numDataPoints1);
00140 time = new Vector(numDataPoints1);
00141
00142
00143 if (thePath == 0 || thePath->Size() == 0 ||
00144 time == 0 || time->Size() == 0) {
00145
00146 opserr << "WARNING PathTimeSeries::PathTimeSeries() - out of memory\n ";
00147 if (thePath != 0)
00148 delete thePath;
00149 if (time != 0)
00150 delete time;
00151 thePath = 0;
00152 time = 0;
00153 }
00154
00155
00156 ifstream theFile2;
00157 theFile2.open(filePathName, ios::in);
00158 if (theFile2.bad() || !theFile2.is_open()) {
00159 opserr << "WARNING - PathTimeSeries::PathTimeSeries()";
00160 opserr << " - could not open file " << filePathName << endln;
00161 delete thePath;
00162 delete time;
00163 thePath = 0;
00164 time =0;
00165 } else {
00166 int count = 0;
00167 while (theFile2 >> dataPoint) {
00168 (*thePath)(count) = dataPoint;
00169 count++;
00170 }
00171
00172
00173 theFile2.close();
00174
00175
00176 ifstream theFile3;
00177 theFile3.open(fileTimeName, ios::in);
00178 if (theFile3.bad() || !theFile3.is_open()) {
00179 opserr << "WARNING - PathTimeSeries::PathTimeSeries()";
00180 opserr << " - could not open file " << fileTimeName << endln;
00181 delete thePath;
00182 delete time;
00183 thePath = 0;
00184 time =0;
00185 } else {
00186 int count = 0;
00187 while (theFile3 >> dataPoint) {
00188 (*time)(count) = dataPoint;
00189 count++;
00190 }
00191 theFile3.close();
00192 }
00193 }
00194 }
00195 }
00196 }
00197
00198
00199 PathTimeSeries::PathTimeSeries(const char *fileName,
00200 double theFactor)
00201 :TimeSeries(TSERIES_TAG_PathTimeSeries),
00202 thePath(0), time(0), currentTimeLoc(0),
00203 cFactor(theFactor), dbTag1(0), dbTag2(0), lastChannel(0)
00204 {
00205
00206
00207
00208 int numDataPoints = 0;
00209 double dataPoint;
00210 ifstream theFile;
00211
00212
00213 theFile.open(fileName, ios::in);
00214 if (theFile.bad() || !theFile.is_open()) {
00215 opserr << "WARNING - PathTimeSeries::PathTimeSeries()";
00216 opserr << " - could not open file " << fileName << endln;
00217 }
00218 else {
00219 while (theFile >> dataPoint) {
00220 numDataPoints++;
00221 theFile >> dataPoint;
00222 }
00223 }
00224 theFile.close();
00225
00226
00227
00228
00229 if (numDataPoints != 0) {
00230
00231
00232 thePath = new Vector(numDataPoints);
00233 time = new Vector(numDataPoints);
00234
00235
00236 if (thePath == 0 || thePath->Size() == 0 || time == 0 || time->Size() == 0) {
00237
00238 opserr << "WARNING PathTimeSeries::PathTimeSeries() - out of memory\n ";
00239 if (thePath != 0)
00240 delete thePath;
00241 if (time != 0)
00242 delete time;
00243 thePath = 0;
00244 time = 0;
00245 }
00246
00247
00248 ifstream theFile1;
00249 theFile1.open(fileName, ios::in);
00250 if (theFile1.bad() || !theFile1.is_open()) {
00251
00252 opserr << "WARNING - PathTimeSeries::PathTimeSeries()";
00253 opserr << " - could not open file " << fileName << endln;
00254 delete thePath;
00255 delete time;
00256 thePath = 0;
00257 time =0;
00258 }
00259 else {
00260 int count = 0;
00261 while (theFile1 >> dataPoint) {
00262 (*time)(count) = dataPoint;
00263 theFile1 >> dataPoint;
00264 (*thePath)(count) = dataPoint;
00265 count++;
00266 }
00267
00268
00269 theFile1.close();
00270 }
00271
00272 }
00273
00274 }
00275
00276 PathTimeSeries::~PathTimeSeries()
00277 {
00278 if (thePath != 0)
00279 delete thePath;
00280 if (time != 0)
00281 delete time;
00282 }
00283
00284 double
00285 PathTimeSeries::getTimeIncr (double pseudoTime)
00286 {
00287
00288 return 1.0;
00289 }
00290
00291 double
00292 PathTimeSeries::getFactor(double pseudoTime)
00293 {
00294
00295 if (thePath == 0)
00296 return 0.0;
00297
00298
00299 double time1 = (*time)(currentTimeLoc);
00300
00301
00302 if (pseudoTime == time1)
00303 return cFactor * (*thePath)[currentTimeLoc];
00304
00305 int size = time->Size();
00306 int sizem1 = size - 1;
00307 int sizem2 = size - 2;
00308
00309
00310 if (pseudoTime > time1 && currentTimeLoc == sizem1)
00311 return 0.0;
00312
00313 if (pseudoTime < time1 && currentTimeLoc == 0)
00314 return 0.0;
00315
00316
00317 double time2 = (*time)(currentTimeLoc+1);
00318 if (pseudoTime > time2) {
00319 while ((pseudoTime > time2) && (currentTimeLoc < sizem2)) {
00320 currentTimeLoc++;
00321 time1 = time2;
00322 time2 = (*time)(currentTimeLoc+1);
00323 }
00324
00325 if (pseudoTime > time2)
00326 return 0.0;
00327
00328 } else if (pseudoTime < time1) {
00329 while ((pseudoTime < time1) && (currentTimeLoc > 0)) {
00330 currentTimeLoc--;
00331 time2 = time1;
00332 time1 = (*time)(currentTimeLoc);
00333 }
00334
00335 if (pseudoTime < time1)
00336 return 0.0;
00337 }
00338
00339 double value1 = (*thePath)[currentTimeLoc];
00340 double value2 = (*thePath)[currentTimeLoc+1];
00341 return cFactor*(value1 + (value2-value1)*(pseudoTime-time1)/(time2 - time1));
00342 }
00343
00344 double
00345 PathTimeSeries::getDuration()
00346 {
00347 if (thePath == 0)
00348 {
00349 opserr << "WARNING -- PathTimeSeries::getDuration() on empty Vector" << endln;
00350 return 0.0;
00351 }
00352
00353 int lastIndex = time->Size();
00354 return ((*time)[lastIndex-1]);
00355 }
00356
00357 double
00358 PathTimeSeries::getPeakFactor()
00359 {
00360 if (thePath == 0)
00361 {
00362 opserr << "WARNING -- PathTimeSeries::getPeakFactor() on empty Vector" << endln;
00363 return 0.0;
00364 }
00365
00366 double peak = fabs((*thePath)[0]);
00367 int num = thePath->Size();
00368 double temp;
00369
00370 for (int i = 1; i < num; i++)
00371 {
00372 temp = fabs((*thePath)[i]);
00373 if (temp > peak)
00374 peak = temp;
00375 }
00376
00377 return (peak*cFactor);
00378 }
00379
00380 int
00381 PathTimeSeries::sendSelf(int commitTag, Channel &theChannel)
00382 {
00383 int dbTag = this->getDbTag();
00384 Vector data(5);
00385 data(0) = cFactor;
00386 data(1) = -1;
00387
00388 if (thePath != 0) {
00389 int size = thePath->Size();
00390 data(1) = size;
00391 if (dbTag1 == 0) {
00392 dbTag1 = theChannel.getDbTag();
00393 dbTag2 = theChannel.getDbTag();
00394 }
00395 data(2) = dbTag1;
00396 data(3) = dbTag2;
00397 }
00398
00399 if ((lastSendCommitTag == -1) && (theChannel.isDatastore() == 1)) {
00400 lastSendCommitTag = commitTag;
00401 }
00402
00403 data(4) = lastSendCommitTag;
00404
00405 int result = theChannel.sendVector(dbTag,commitTag, data);
00406 if (result < 0) {
00407 opserr << "PathTimeSeries::sendSelf() - channel failed to send data\n";
00408 return result;
00409 }
00410
00411
00412
00413
00414 if (lastChannel != &theChannel || (lastSendCommitTag == commitTag) || (theChannel.isDatastore() == 0)) {
00415
00416 lastChannel = &theChannel;
00417
00418 if (thePath != 0) {
00419 result = theChannel.sendVector(dbTag1, commitTag, *thePath);
00420 if (result < 0) {
00421 opserr << "PathTimeSeries::sendSelf() - ";
00422 opserr << "channel failed to send tha Path Vector\n";
00423 return result;
00424 }
00425 }
00426 if (time != 0) {
00427 result = theChannel.sendVector(dbTag2, commitTag, *time);
00428 if (result < 0) {
00429 opserr << "PathTimeSeries::sendSelf() - ";
00430 opserr << "channel failed to send tha Path Vector\n";
00431 return result;
00432 }
00433 }
00434 return 0;
00435 }
00436 return 0;
00437 }
00438
00439
00440 int
00441 PathTimeSeries::recvSelf(int commitTag, Channel &theChannel,
00442 FEM_ObjectBroker &theBroker)
00443 {
00444 int dbTag = this->getDbTag();
00445 Vector data(5);
00446 int result = theChannel.recvVector(dbTag,commitTag, data);
00447 if (result < 0) {
00448 opserr << "PathTimeSeries::sendSelf() - channel failed to receive data\n";
00449 cFactor = 1.0;
00450 return result;
00451 }
00452 cFactor = data(0);
00453 int size = data(1);
00454 lastSendCommitTag = data(4);
00455
00456
00457 if (thePath == 0 && size > 0) {
00458 dbTag1 = data(2);
00459 dbTag2 = data(3);
00460 thePath = new Vector(size);
00461 time = new Vector(size);
00462 if (thePath == 0 || time == 0 ||
00463 thePath->Size() == 0 || time->Size() == 0) {
00464
00465 opserr << "PathTimeSeries::recvSelf() - ran out of memory";
00466 opserr << " a Vector of size: " << size << endln;
00467 if (thePath != 0)
00468 delete thePath;
00469 if (time != 0)
00470 delete time;
00471 thePath = 0;
00472 time = 0;
00473 return -1;
00474 }
00475 result = theChannel.recvVector(dbTag1, lastSendCommitTag, *thePath);
00476 if (result < 0) {
00477 opserr << "PathTimeSeries::recvSelf() - ";
00478 opserr << "channel failed to receive tha Path Vector\n";
00479 return result;
00480 }
00481 result = theChannel.recvVector(dbTag2, lastSendCommitTag, *time);
00482 if (result < 0) {
00483 opserr << "PathTimeSeries::recvSelf() - ";
00484 opserr << "channel failed to receive tha time Vector\n";
00485 return result;
00486 }
00487 }
00488 return 0;
00489 }
00490
00491
00492
00493 void
00494 PathTimeSeries::Print(OPS_Stream &s, int flag)
00495 {
00496 s << "Path Time Series: constant factor: " << cFactor;
00497 if (flag == 1 && thePath != 0) {
00498 s << " specified path: " << *thePath;
00499 s << " specified time: " << *time;
00500 }
00501 }