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 <AlgorithmIncrements.h>
00039 #include <EquiSolnAlgo.h>
00040 #include <LinearSOE.h>
00041 #include <stdlib.h>
00042 #include <string.h>
00043 #include <ctype.h>
00044 #include <ID.h>
00045 #include <Vector.h>
00046
00047 #include <fstream>
00048 using std::ifstream;
00049
00050 #include <iomanip>
00051 using std::ios;
00052
00053 #ifdef _WGL
00054 #include <OpenGLRenderer.h>
00055 #elif _GLX
00056 #include <OpenGLRenderer.h>
00057 #else
00058 #include <X11Renderer.h>
00059 #endif
00060 #include <PlainMap.h>
00061 #include <Vector.h>
00062
00063
00064
00065 AlgorithmIncrements::AlgorithmIncrements(EquiSolnAlgo *theEquiAlgo,
00066 const char *windowTitle,
00067 int xLoc, int yLoc, int width, int height,
00068 bool displayOnRecord, const char *theFileName)
00069 :Recorder(RECORDER_TAGS_AlgorithmIncrements),
00070 theMap(0), theRenderer(0), numRecord(0), displayRecord(displayOnRecord), fileName(0)
00071 {
00072
00073 theAlgo = theEquiAlgo;
00074
00075
00076 theMap = new PlainMap();
00077 #ifdef _WGL
00078 theRenderer = new OpenGLRenderer(windowTitle, xLoc, yLoc, width, height, *theMap);
00079 #elif _GLX
00080 theRenderer = new OpenGLRenderer(windowTitle, xLoc, yLoc, width, height, *theMap);
00081 #else
00082 theRenderer = new X11Renderer(windowTitle, xLoc, yLoc, width, height, *theMap);
00083 #endif
00084
00085 theRenderer->setVRP(0.0, 0.0, 0.0);
00086 theRenderer->setVPN(0.0, 0.0, 1.0);
00087 theRenderer->setVUP(0.0, 1.0, 0.0);
00088 theRenderer->setFillMode("wire");
00089 theRenderer->setPlaneDist(1.0, 100.0);
00090 theRenderer->setPRP(0.0, 0.0, 10.0);
00091
00092 if (theFileName != 0) {
00093 fileName = new char[strlen(theFileName) + 1];
00094 strcpy(fileName, theFileName);
00095 }
00096 }
00097
00098 AlgorithmIncrements::~AlgorithmIncrements()
00099 {
00100
00101
00102
00103 delete theMap;
00104 delete theRenderer;
00105
00106 if (theFile)
00107 theFile.close();
00108 if (fileName != 0)
00109 delete [] fileName;
00110
00111 }
00112
00113 int
00114 AlgorithmIncrements::record(int cTag, double timeStamp)
00115 {
00116 LinearSOE *theSOE = theAlgo->getLinearSOEptr();
00117 if (theSOE == 0)
00118 return 0;
00119
00120
00121 const Vector &B = theSOE->getB();
00122 const Vector &X = theSOE->getX();
00123
00124 if (fileName != 0) {
00125 if (cTag == 0) {
00126
00127 if (theFile)
00128 theFile.close();
00129
00130 numRecord = 0;
00131
00132 theFile.open(fileName, ios::out);
00133 if (!theFile) {
00134 opserr << "WARNING - AlgorithmIncrements::record()";
00135 opserr << " - could not open file " << fileName << endln;
00136 }
00137 }
00138 if (theFile) {
00139 numRecord ++;
00140 int i;
00141 for (i=0; X.Size(); i++) theFile << X(i);
00142 for (i=0; X.Size(); i++) theFile << B(i);
00143 }
00144 }
00145
00146 if (displayRecord == true)
00147 return this->plotData(X, B);
00148
00149 return 0;
00150 }
00151
00152 int
00153 AlgorithmIncrements::playback(int cTag)
00154 {
00155
00156 if (fileName != 0) {
00157
00158 LinearSOE *theSOE = theAlgo->getLinearSOEptr();
00159 if (theSOE == 0)
00160 return 0;
00161
00162 Vector X(theSOE->getNumEqn());
00163 Vector B(theSOE->getNumEqn());
00164
00165 if (theFile) {
00166 theFile.close();
00167 }
00168
00169 ifstream aFile;
00170 aFile.open(fileName, ios::in);
00171 if (!aFile) {
00172 opserr << "WARNING - AlgorithmIncrements::playback()";
00173 opserr << " - could not open file " << fileName << endln;
00174 }
00175 for (int i = 0; i<numRecord; i++) {
00176 int ii;
00177 for (ii=0; X.Size(); ii++) theFile << X(ii);
00178 for (ii=0; X.Size(); ii++) theFile << B(ii);
00179
00180 this->plotData(X,B);
00181
00182 }
00183 }
00184
00185 return 0;
00186 }
00187
00188 int
00189 AlgorithmIncrements::restart(void)
00190 {
00191 return 0;
00192 }
00193
00194 int
00195 AlgorithmIncrements::plotData(const Vector &X, const Vector &B)
00196 {
00197
00198 int size = X.Size();
00199 if (size < 2)
00200 return 0;
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210 theRenderer->clearImage();
00211 theRenderer->setPortWindow(-1.0, 1.0, 0.0, 1.0);
00212
00213 double xMin, xMax, yMin, yMax;
00214 xMin = 0.0;
00215 xMax = B.Size();
00216 yMin = 0.0;
00217 yMax = 0.0;
00218 int i;
00219
00220 for (i=0; i<size; i++) {
00221 double value = B(i);
00222 if (value < yMin) yMin = value;
00223 if (value > yMax) yMax = value;
00224 }
00225
00226 if (-yMin > yMax)
00227 yMax = -yMin;
00228 else
00229 yMin = -yMax;
00230
00231
00232
00233 double xBnd = (xMax-xMin)/10;
00234 double yBnd = (yMax-yMin)/10;
00235
00236 theRenderer->setViewWindow(xMin-xBnd,xMax+xBnd,yMin-yBnd,yMax+yBnd);
00237 theRenderer->startImage();
00238
00239 static Vector pt1(3);
00240 static Vector pt2(3);
00241 pt1(2) = 0.0; pt2(2) = 0.0;
00242
00243
00244 pt1(0) = xMin; pt2(0) = xMax;
00245 pt1(1) = 0.0; pt2(1) = 0.0;
00246 theRenderer->drawLine(pt1, pt2, 0.0, 0.0);
00247
00248
00249 pt1(0) = 0.0; pt2(0) = 0.0;
00250 pt1(1) = yMin; pt2(1) = yMax;
00251 theRenderer->drawLine(pt1, pt2, 0.0, 0.0);
00252
00253
00254 static char theText[20];
00255 if (yMin != 0.0 && -100 *yMin > yMax) {
00256 sprintf(theText,"%.2e",yMin);
00257 theRenderer->drawText(pt1, theText, strlen(theText));
00258 }
00259 if (yMax != 0.0) {
00260 sprintf(theText,"%.2e",yMax);
00261 theRenderer->drawText(pt2, theText, strlen(theText));
00262 }
00263
00264 pt1(0) = 1;
00265 pt1(1) = B(0);
00266
00267 for (i=1; i<size; i++) {
00268 pt2(0) = i+1;
00269 pt2(1) = B(i);
00270 theRenderer->drawLine(pt1, pt2, 1.0, 1.0);
00271 pt1(0) = pt2(0);
00272 pt1(1) = pt2(1);
00273 }
00274
00275 theRenderer->doneImage();
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 theRenderer->setPortWindow(-1.0, 1.0, -1.0, 0.0);
00287
00288 xMin = 0.0;
00289 xMax = X.Size();
00290 yMin = 0.0;
00291 yMax = 0.0;
00292
00293 for (i=0; i<size; i++) {
00294 double value = X(i);
00295 if (value < yMin) yMin = value;
00296 if (value > yMax) yMax = value;
00297 }
00298
00299 if (-yMin > yMax)
00300 yMax = -yMin;
00301 else
00302 yMin = -yMax;
00303
00304
00305
00306 xBnd = (xMax-xMin)/10;
00307 yBnd = (yMax-yMin)/10;
00308
00309 theRenderer->setViewWindow(xMin-xBnd,xMax+xBnd,yMin-yBnd,yMax+yBnd);
00310 theRenderer->startImage();
00311
00312 pt1(2) = 0.0; pt2(2) = 0.0;
00313
00314
00315 pt1(0) = xMin; pt2(0) = xMax;
00316 pt1(1) = 0.0; pt2(1) = 0.0;
00317 theRenderer->drawLine(pt1, pt2, 0.0, 0.0);
00318
00319
00320 pt1(0) = 0.0; pt2(0) = 0.0;
00321 pt1(1) = yMin; pt2(1) = yMax;
00322 theRenderer->drawLine(pt1, pt2, 0.0, 0.0);
00323
00324 if (yMin != 0.0 && -100 *yMin > yMax) {
00325 sprintf(theText,"%.2e",yMin);
00326 theRenderer->drawText(pt1, theText, strlen(theText));
00327 }
00328 if (yMax != 0.0) {
00329 sprintf(theText,"%.2e",yMax);
00330 theRenderer->drawText(pt2, theText, strlen(theText));
00331 }
00332
00333 pt1(0) = 1;
00334 pt1(1) = X(0);
00335
00336 for (i=1; i<size; i++) {
00337 pt2(0) = i+1;
00338 pt2(1) = X(i);
00339 theRenderer->drawLine(pt1, pt2, 1.0, 1.0);
00340 pt1(0) = pt2(0);
00341 pt1(1) = pt2(1);
00342 }
00343
00344 theRenderer->doneImage();
00345
00346 return 0;
00347 }
00348
00349
00350
00351