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

EarthquakePattern.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.1.1.1 $
00022 // $Date: 2000/09/15 08:23:19 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/domain/pattern/EarthquakePattern.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/domain/pattern/EarthquakePattern.cpp
00027 //
00028 // Written: fmk 11/98
00029 // Revised:
00030 //
00031 // Purpose: This file contains the class definition for EarthquakePattern.
00032 // EarthquakePattern is an abstract class.
00033 
00034 #include <EarthquakePattern.h>
00035 #include <GroundMotion.h>
00036 
00037 #include <Domain.h>
00038 #include <NodeIter.h>
00039 #include <Node.h>
00040 #include <ElementIter.h>
00041 #include <Element.h>
00042 #include <stdlib.h>
00043 #include <Channel.h>
00044 #include <ErrorHandler.h>
00045 
00046 EarthquakePattern::EarthquakePattern(int tag, int _classTag)
00047 :LoadPattern(tag, _classTag), theMotions(0), numMotions(0), uDotG(0), uDotDotG(0)
00048 {
00049 
00050 }
00051 
00052 
00053 EarthquakePattern::~EarthquakePattern()
00054 {
00055   // invoke the destructor on all ground motions supplied
00056   for (int i=0; i<numMotions; i++)
00057       delete theMotions[i];
00058   
00059   if (theMotions != 0)
00060     //    free ((void *)theMotions);
00061     delete [] theMotions;
00062 }
00063 
00064 
00065 
00066 void 
00067 EarthquakePattern::applyLoad(double time)
00068 {
00069   // see if quick return, i.e. no Ground Motions or domain set
00070   if (numMotions == 0)
00071     return;
00072 
00073   Domain *theDomain = this->getDomain();
00074   if (theDomain == 0)
00075     return;
00076 
00077 
00078   // set the vel and accel vector
00079   for (int i=0; i<numMotions; i++) {
00080     (*uDotG)(i) = theMotions[i]->getVel(time);
00081     (*uDotDotG)(i) = theMotions[i]->getAccel(time);
00082   }
00083 
00084   NodeIter &theNodes = theDomain->getNodes();
00085   Node *theNode;
00086   while ((theNode = theNodes()) != 0) 
00087     theNode->addInertiaLoadToUnbalance(*uDotDotG, 1.0);
00088   
00089 
00090   ElementIter &theElements = theDomain->getElements();
00091   Element *theElement;
00092   while ((theElement = theElements()) != 0) 
00093     theElement->addInertiaLoadToUnbalance(*uDotDotG);
00094 }
00095     
00096 int
00097 EarthquakePattern::addMotion(GroundMotion &theMotion)
00098 {
00099   // make space for new
00100   GroundMotion **newMotions = new GroundMotion *[numMotions+1];
00101   //  GroundMotion **newMotions = (GroundMotion **)malloc(sizeof(GroundMotion *)*(numMotions+1));
00102   if (newMotions == 0) {
00103     cerr << "EarthquakePattern::addMotion - could not add new, out of mem\n";
00104     return -1;
00105   }
00106   
00107   // copy old
00108   for (int i=0; i<numMotions; i++)
00109     newMotions[i] = theMotions[i];
00110 
00111   // add the new motion to new
00112   newMotions[numMotions] = &theMotion;
00113 
00114   // delete the old
00115   if (theMotions != 0)
00116     delete [] theMotions;
00117 
00118   // reset
00119   theMotions = newMotions;
00120   numMotions++;
00121 
00122   // delete old vectors and create new ones
00123   if (uDotG != 0)
00124     delete uDotG;
00125   uDotG = new Vector(numMotions);
00126 
00127   if (uDotDotG != 0)
00128     delete uDotDotG;
00129   uDotDotG = new Vector(numMotions);
00130 
00131   if (uDotDotG == 0 || uDotDotG->Size() == 0 || uDotG == 0 || uDotG->Size() == 0) {
00132     cerr << "EarthquakePattern::addMotion - ran out of memory creating vectors\n";
00133     numMotions = 0;
00134     return -2;
00135   }
00136   return 0;
00137 }
00138 
00139 
00140 bool
00141 EarthquakePattern::addSP_Constraint(SP_Constraint *)
00142 {
00143   cerr << "EarthquakePattern::addSP_Constraint() - cannot add SP_Constraint to EQ pattern\n";
00144   return false;
00145 }
00146 
00147 bool
00148 EarthquakePattern::addNodalLoad(NodalLoad *)
00149 {
00150   cerr << "EarthquakePattern::addNodalLoad() - cannot add NodalLoad to EQ pattern\n";  
00151   return false;
00152 }
00153 
00154 bool
00155 EarthquakePattern::addElementalLoad(ElementalLoad *)
00156 {
00157   cerr << "EarthquakePattern::addElementalLoad() - cannot add ElementalLoad to EQ pattern\n";    
00158   return false;
00159 }
00160 
00161 
00162 /* **********************************************************************************************
00163 int 
00164 EarthquakePattern::sendSelf(int commitTag, Channel &theChannel)
00165 {
00166   // first send the tag and info about the number of ground motions
00167   int myDbTag = this->getDbTag();
00168   ID theData(2);
00169   theData(0) = this->getTag();
00170   theData(1) = numMotions;
00171 
00172   if (theChannel.sendID(myDbTag, commitTag, theData) < 0) {
00173     g3ErrorHandler->warning("EarthquakePattern::sendSelf - channel failed to send the initial ID");
00174     return -1;
00175   }    
00176 
00177   // now for each motion we send it's classsss tag and dbtag
00178   ID theMotionsData(2*numMotions);
00179   for (int i=0; i<numMotions; i++) {
00180     theMotionsData[i] = theMotions[i]->getClassTag();
00181     int motionsDbTag = theMotions[i]->getDbTag();
00182     if (motionsDbTag == 0) {
00183       motionsDbTag = theChannel.getDbTag();
00184       theMotions[i]->setDbTag(motionsDbTag);
00185     }
00186     theMotionsData[i+numMotions] = motionsDbTag;
00187   }
00188 
00189   if (theChannel.sendID(myDbTag, commitTag, theMotionsData) < 0) {
00190     g3ErrorHandler->warning("EarthquakePattern::sendSelf - channel failed to send the motions ID");
00191     return -1;
00192   }    
00193 
00194   // now we send each motion
00195   for (int j=0; j<numMotions; j++)
00196     if (theMotions[j]->sendSelf(commitTag, theChannel) < 0) {
00197       g3ErrorHandler->warning("EarthquakePattern::sendSelf - motion no: %d failed in sendSelf", j);
00198       return -1;
00199     }
00200 
00201   // if get here successfull
00202   return 0;
00203 }
00204 
00205 int 
00206 EarthquakePattern::recvSelf(int commitTag, Channel &theChannel, 
00207     FEM_ObjectBroker &theBroker)
00208 {
00209   // first get the tag and info about the number of ground motions from the Channel
00210   int myDbTag = this->getDbTag();
00211   ID theData(2);
00212   if (theChannel.recvID(myDbTag, commitTag, theData) < 0) {
00213     g3ErrorHandler->warning("EarthquakePattern::recvSelf - channel failed to recv the initial ID");
00214     return -1;
00215   }    
00216   
00217   // set current tag
00218   this->setTag(theData(0));
00219 
00220   // now get info about each channel
00221   ID theMotionsData (2*theData(1));
00222   if (theChannel.recvID(myDbTag, commitTag, theMotionsData) < 0) {
00223     g3ErrorHandler->warning("EarthquakePattern::recvSelf - channel failed to recv the motions ID");
00224     return -1;
00225   }    
00226 
00227 
00228   if (numMotions != theData(1)) {
00229 
00230     //
00231     // we must delete the old motions and create new ones and then invoke recvSelf on these new ones
00232     //
00233 
00234     if (numMotions != 0) {
00235       for (int i=0; i<numMotions; i++)
00236  delete theMotions[i];
00237       delete [] theMotions;
00238     }
00239     numMotions = theData[1];
00240     theMotions = new (GroundMotion *)[numMotions];
00241     if (theMotions == 0) {
00242       g3ErrorHandler->warning("EarthquakePattern::recvSelf - out of memory creating motion array of size %d\n", numMotions);
00243       numMotions = 0;
00244       return -1;
00245     }    
00246 
00247     for (int i=0; i<numMotions; i++) {
00248       theMotions[i] = theBroker.getNewGroundMotion(theMotionsData[i]);
00249       if (theMotions[i] == 0) {
00250  g3ErrorHandler->warning("EarthquakePattern::recvSelf - out of memory creating motion array of size %d\n", numMotions);
00251  numMotions = 0;
00252  return -1;
00253       }    
00254       theMotions[i]->setDbTag(theMotionsData[i+numMotions]);
00255       if (theMotions[i]->recvSelf(commitTag, theChannel, theBroker) < 0) {
00256  g3ErrorHandler->warning("EarthquakePattern::recvSelf - motion no: %d failed in recvSelf", i);
00257  numMotions = 0;
00258  return -1;
00259       }      
00260     }
00261 
00262   } else {
00263 
00264     // 
00265     // we invoke rrecvSelf on the motions, note if a motion not of correct class
00266     // we must invoke the destructor on the motion and create a new one of correct type
00267     //
00268 
00269     for (int i=0; i<numMotions; i++) {
00270       if (theMotions[i]->getClassTag() == theMotionsData[i]) {
00271  if (theMotions[i]->recvSelf(commitTag, theChannel, theBroker) < 0) {
00272    g3ErrorHandler->warning("EarthquakePattern::recvSelf - motion no: %d failed in recvSelf", i);
00273    return -1;
00274  }      
00275       } else {
00276  // motion not of correct type
00277  delete theMotions[i];
00278  theMotions[i] = theBroker.getNewGroundMotion(theMotionsData[i]);
00279  if (theMotions[i] == 0) {
00280    g3ErrorHandler->warning("EarthquakePattern::recvSelf - out of memory creating motion array of size %d\n", numMotions);
00281    numMotions = 0;
00282    return -1;
00283  }    
00284  theMotions[i]->setDbTag(theMotionsData[i+numMotions]);
00285  if (theMotions[i]->recvSelf(commitTag, theChannel, theBroker) < 0) {
00286    g3ErrorHandler->warning("EarthquakePattern::recvSelf - motion no: %d failed in recvSelf", i);
00287    numMotions = 0;
00288    return -1;
00289  }      
00290       }
00291     }    
00292   }
00293 
00294   // if get here successfull
00295   return 0;
00296 }
00297 
00298 
00299 ***************************************************************************************** */
00300 
00301 void 
00302 EarthquakePattern::Print(ostream &s, int flag)
00303 {
00304   cerr << "EarthquakePattern::Print() - not yet implemented\n";    
00305 }
00306 
00307 /* ****************************************************************************************
00308 // method to obtain a blank copy of the LoadPattern
00309 LoadPattern *
00310 EarthquakePattern::getCopy(void)
00311 {
00312   EarthquakePattern *theCopy = new EarthquakePattern(0, 0);
00313   theCopy->setTag(this->getTag);
00314   theCopy->numMotions = numMotions;
00315   theCopy->theMotions = new (GroundMotion *)[numMotions];
00316   for (int i=0; i<numMotions; i++)
00317     theCopy->theMotions[i] = theMotions[i];
00318 
00319   return 0;
00320 }
00321 ***************************************************************************************** */
Copyright Contact Us