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 #include <ElementRecorder.h>
00037 #include <Domain.h>
00038 #include <Element.h>
00039 #include <Matrix.h>
00040 #include <Vector.h>
00041 #include <ID.h>
00042 #include <string.h>
00043 #include <Response.h>
00044
00045 ElementRecorder::ElementRecorder(const ID &eleID, Domain &theDom,
00046 char **argv, int argc,
00047 bool echoTime, char *fileName)
00048 :numEle(eleID.Size()), responseID(eleID.Size()), theDomain(&theDom),
00049 echoTimeFlag(echoTime)
00050 {
00051 theElements = new Element *[numEle];
00052 for (int ii=0; ii<numEle; ii++)
00053 theElements[ii] = 0;
00054
00055 theResponses = new Response *[numEle];
00056 for (int j=0; j<numEle; j++)
00057 theResponses[j] = 0;
00058
00059 eleInfoObjects = new Information[numEle];
00060 for (int i=0; i<numEle; i++) {
00061 Element *theEle = theDom.getElement(eleID(i));
00062 if (theEle == 0) {
00063 cerr << "WARNING ElementRecorder::ElementRecorder() -";
00064 cerr << " no element with tag: " << eleID(i) << " exists in Domain\n";
00065 numEle = 0;
00066 return;
00067 } else {
00068 theResponses[i] = theEle->setResponse(argv, argc, eleInfoObjects[i]);
00069 theElements[i] = theEle;
00070 }
00071 }
00072
00073
00074 if (fileName != 0) {
00075 if (strlen(fileName) > MAX_FILENAMELENGTH)
00076 g3ErrorHandler->warning("WARNING - ElementRecorder::ElementRecorder() - fileName %s too long, max %d\n",
00077 fileName, MAX_FILENAMELENGTH);
00078 else {
00079 strcpy(theFileName, fileName);
00080 theFile.open(fileName, ios::out);
00081 if (theFile.bad()) {
00082 cerr << "WARNING - ElementRecorder::ElementRecorder()";
00083 cerr << " - could not open file " << fileName << endl;
00084 }
00085 }
00086 }
00087 }
00088
00089 ElementRecorder::~ElementRecorder()
00090 {
00091
00092 if (!theFile.bad())
00093 theFile.close();
00094
00095 if (theElements != 0)
00096 delete [] theElements;
00097
00098 if (theResponses != 0) {
00099 for (int i = 0; i < numEle; i++)
00100 delete theResponses[i];
00101 delete [] theResponses;
00102 }
00103
00104 if (eleInfoObjects != 0)
00105 delete [] eleInfoObjects;
00106 }
00107
00108
00109 int
00110 ElementRecorder::record(int commitTag)
00111 {
00112
00113 if (echoTimeFlag == true) {
00114 if (!theFile)
00115 cerr << theDomain->getCurrentTime() << " ";
00116 else
00117 theFile << theDomain->getCurrentTime() << " ";
00118 }
00119
00120
00121 int result = 0;
00122 for (int i=0; i< numEle; i++) {
00123 int theID = responseID(i);
00124 if (theResponses[i] != 0) {
00125
00126
00127 int res;
00128 Information &eleInfo = eleInfoObjects[i];
00129 if (( res = theResponses[i]->getResponse()) < 0)
00130 result = res;
00131 else {
00132
00133
00134
00135 if (theFile.bad())
00136 theResponses[i]->Print(cerr);
00137 else {
00138 theResponses[i]->Print(theFile);
00139 theFile << " ";
00140 }
00141 }
00142 }
00143 }
00144
00145 if (theFile.bad())
00146 cerr << endl;
00147 else {
00148 theFile << " \n";
00149 theFile.flush();
00150 }
00151
00152
00153 return result;
00154 }
00155
00156
00157 int
00158 ElementRecorder::playback(int commitTag)
00159 {
00160 return 0;
00161 }
00162
00163 void
00164 ElementRecorder::restart(void)
00165 {
00166 theFile.close();
00167 theFile.open(theFileName, ios::out);
00168 if (!theFile) {
00169 cerr << "WARNING - FileNodeDispRecorder::restart() - could not open file ";
00170 cerr << theFileName << endl;
00171 }
00172 }