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

ElementRecorder.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.4 $
00022 // $Date: 2001/06/30 01:24:43 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/recorder/ElementRecorder.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/recorder/ElementRecorder.C
00027 //
00028 // Written: fmk 
00029 // Created: 09/99
00030 // Revision: A
00031 //
00032 // Description: This file contains the class implementatation of ElementRecorder.
00033 //
00034 // What: "@(#) ElementRecorder.C, revA"
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   // if file is specified, copy name and open the file
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     // close the file
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   // print out the pseudo time if requested
00113   if (echoTimeFlag == true) {
00114     if (!theFile) 
00115       cerr << theDomain->getCurrentTime() << " ";   
00116     else 
00117       theFile << theDomain->getCurrentTime() << " "; 
00118   }
00119 
00120   // for each element do a getResponse() & print the result
00121   int result = 0;
00122   for (int i=0; i< numEle; i++) {
00123     int theID = responseID(i);
00124     if (theResponses[i] != 0) {
00125       
00126       // ask the element for the reponse
00127       int res;
00128       Information &eleInfo = eleInfoObjects[i];
00129       if (( res = theResponses[i]->getResponse()) < 0)
00130  result = res;
00131       else {
00132  // print results to file or stderr depending on whether
00133  // a file was opened
00134  
00135  if (theFile.bad())
00136    theResponses[i]->Print(cerr);     
00137  else {
00138    theResponses[i]->Print(theFile);
00139    theFile << "  ";  // added for OSP
00140  }
00141       }
00142     } 
00143   }
00144 
00145   if (theFile.bad()) 
00146     cerr << endl;
00147   else {
00148     theFile << " \n";
00149     theFile.flush();
00150   }
00151 
00152   // succesfull completion - return 0
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 }
Copyright Contact Us