MultiSupportPattern.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: 2006/01/04 21:59:10 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/domain/pattern/MultiSupportPattern.cpp,v $
00024                                                                         
00025 // Written: fmk 11/00
00026 // Revised:
00027 //
00028 // Purpose: This file contains the class definition for MultiSupportPattern.
00029 // MultiSupportPattern is an abstract class.
00030 
00031 #include <MultiSupportPattern.h>
00032 #include <GroundMotion.h>
00033 
00034 #include <FEM_ObjectBroker.h>
00035 #include <Domain.h>
00036 #include <SP_Constraint.h>
00037 #include <SP_ConstraintIter.h>
00038 #include <stdlib.h>
00039 #include <Channel.h>
00040 #include <ErrorHandler.h>
00041 
00042 MultiSupportPattern::MultiSupportPattern(int tag, int _classTag)
00043   :LoadPattern(tag, _classTag), 
00044    theMotions(0), theMotionTags(0,16), numMotions(0), dbMotions(0)
00045 {
00046 
00047 }
00048 
00049 
00050 MultiSupportPattern::MultiSupportPattern(int tag)
00051   :LoadPattern(tag, PATTERN_TAG_MultiSupportPattern), 
00052    theMotions(0), theMotionTags(0,16), numMotions(0), dbMotions(0)
00053 {
00054 
00055 }
00056 
00057 
00058 MultiSupportPattern::MultiSupportPattern()
00059   :LoadPattern(0, PATTERN_TAG_MultiSupportPattern), 
00060    theMotions(0), theMotionTags(0,16), numMotions(0), dbMotions(0)
00061 {
00062 
00063 }
00064 
00065 MultiSupportPattern::~MultiSupportPattern()
00066 {
00067   // invoke the destructor on all ground motions supplied
00068   for (int i=0; i<numMotions; i++)
00069       delete theMotions[i];
00070   
00071   if (theMotions != 0)
00072     //    free ((void *)theMotions);
00073     delete [] theMotions;
00074 }
00075 
00076 
00077 
00078 void 
00079 MultiSupportPattern::applyLoad(double time)
00080 {
00081   SP_Constraint *sp;
00082   SP_ConstraintIter &theIter = this->getSPs();
00083   while ((sp = theIter()) != 0)
00084     sp->applyConstraint(time);
00085 }
00086     
00087 
00088 int
00089 MultiSupportPattern::addMotion(GroundMotion &theMotion, int tag)
00090 {
00091   // ensure no motion with given tag already added
00092   if (theMotionTags.getLocation(tag) >= 0) {
00093     opserr << "MultiSupportPattern::addMotion - could not add new, motion wih same tag exists\n";
00094     return -1;
00095   }    
00096 
00097   // make space for new
00098   GroundMotion **newMotions = new GroundMotion *[numMotions+1];
00099   //  GroundMotion **newMotions = (GroundMotion **)malloc(sizeof(GroundMotion *)*(numMotions+1));
00100   if (newMotions == 0) {
00101     opserr << "MultiSupportPattern::addMotion - could not add new, out of mem\n";
00102     return -1;
00103   }
00104   
00105   // copy old
00106   for (int i=0; i<numMotions; i++)
00107     newMotions[i] = theMotions[i];
00108 
00109   // add the new motion to new
00110   newMotions[numMotions] = &theMotion;
00111 
00112   // delete the old
00113   if (theMotions != 0)
00114     delete [] theMotions;
00115 
00116   // reset
00117   theMotions = newMotions;
00118   theMotionTags[numMotions] = tag;
00119   numMotions++;
00120 
00121   return 0;
00122 }
00123 
00124 
00125 
00126 GroundMotion *
00127 MultiSupportPattern::getMotion(int tag)
00128 {
00129   int loc = theMotionTags.getLocation(tag);
00130   if (loc < 0)
00131     return 0;
00132   else
00133     return theMotions[loc];
00134 
00135 }
00136 
00137 
00138 bool
00139 MultiSupportPattern::addNodalLoad(NodalLoad *)
00140 {
00141   opserr << "MultiSupportPattern::addNodalLoad() - cannot add NodalLoad to EQ pattern\n";  
00142   return false;
00143 }
00144 
00145 bool
00146 MultiSupportPattern::addElementalLoad(ElementalLoad *)
00147 {
00148   opserr << "MultiSupportPattern::addElementalLoad() - cannot add ElementalLoad to EQ pattern\n";    
00149   return false;
00150 }
00151 
00152 
00153 
00154 int 
00155 MultiSupportPattern::sendSelf(int commitTag, Channel &theChannel)
00156 {
00157 
00158   // get my current database tag
00159 
00160   // NOTE - dbTag equals 0 if not sending to a database OR has not yet been sent
00161   int myDbTag = this->getDbTag();
00162 
00163   if (this->LoadPattern::sendSelf(commitTag, theChannel) < 0) {
00164     opserr << "MultiSupportPattern::sendSelf() - LoadPattern class failed in sendSelf()";
00165     return -1;
00166   }
00167 
00168   /*
00169   SP_Constraint *sp;
00170   SP_ConstraintIter &theIter = this->getSPs();
00171   int numSP = 0;
00172   while ((sp = theIter()) != 0)
00173     numSP++;
00174   */
00175 
00176   static ID myData(3);
00177   myData(0) = numMotions;
00178   if (dbMotions == 0)
00179     dbMotions = theChannel.getDbTag();
00180   myData(1) = dbMotions;
00181   
00182   if (theChannel.sendID(myDbTag, commitTag, myData) < 0) {
00183     opserr << "MultiSupportPattern::sendSelf - channel failed to send the initial ID\n";
00184     return -1;
00185   }    
00186 
00187   // create the ID and get the node iter
00188   if (numMotions != 0) {
00189     ID motionData(numMotions*2);
00190     GroundMotion *theMotion;
00191     for (int i=0; i<numMotions; i++) {
00192       theMotion = theMotions[i];
00193       motionData(i*2) = theMotion->getClassTag();
00194       int dbTag = theMotion->getDbTag();
00195         
00196       // if dbTag still 0 get one from Channel; 
00197       // if this tag != 0 set the dbTag in node
00198       if (dbTag == 0 && myDbTag != 0) {// go get a new tag and setDbTag in ele if this not 0 
00199         dbTag = theChannel.getDbTag();
00200         if (dbTag != 0)
00201           theMotion->setDbTag(dbTag);
00202       }
00203       motionData(i*2+1) = dbTag;
00204     }    
00205 
00206     // now send the ID
00207     if (theChannel.sendID(dbMotions, commitTag, motionData) < 0) {
00208       opserr << "MultiSupportPattern::sendSelf - channel failed to send the NodalLoads ID\n";
00209       return -4;
00210     }
00211 
00212     
00213     for (int j=0; j<numMotions; j++) {
00214       theMotion = theMotions[j];
00215       if (theMotion->sendSelf(commitTag, theChannel) < 0) {
00216         opserr << "MultiSupportPattern::sendSelf - ground motion  failed in sendSelf\n";
00217         return -7;
00218       }
00219     }
00220   }
00221 
00222   // if we get here we are successfull
00223   return 0;
00224 }
00225 
00226 int 
00227 MultiSupportPattern::recvSelf(int commitTag, Channel &theChannel, 
00228                          FEM_ObjectBroker &theBroker)
00229 {
00230   // get my current database tag
00231   // NOTE - dbTag equals 0 if not sending to a database OR has not yet been sent
00232   int myDbTag = this->getDbTag();
00233   
00234   if (this->LoadPattern::recvSelf(commitTag, theChannel, theBroker) < 0) {
00235     opserr << "MultiSupportPattern::recvSelf() - LoadPattern class failed in sendSelf()";
00236     return -1;
00237   }
00238   
00239   // clear out the all the components in the current load pattern
00240   if (theMotions != 0) {
00241     for (int i=0; i<numMotions; i++)
00242       if (theMotions[i] != 0)
00243         delete theMotions[i];
00244     delete [] theMotions;
00245     numMotions = 0;
00246   }
00247 
00248   // 
00249   // now we rebuild the motions
00250   //
00251 
00252   static ID myData(3);
00253   if (theChannel.recvID(myDbTag, commitTag, myData) < 0) {
00254     opserr << "MultiSupportPattern::sendSelf - channel failed to send the initial ID\n";
00255     return -1;
00256   }    
00257 
00258   int numMotions = myData(0);
00259   int dbMotions = myData(1);
00260 
00261   if (numMotions != 0) {
00262     ID motionData(numMotions*2);
00263 
00264     // now send the ID
00265     if (theChannel.recvID(dbMotions, commitTag, motionData) < 0) {
00266       opserr << "MultiSupportPattern::sendSelf - channel failed to send the NodalLoads ID\n";
00267       return -4;
00268     }
00269 
00270     theMotions = new GroundMotion *[numMotions];
00271     if (theMotions == 0) {
00272       opserr << "MultiSupportPattern::recvSelf() - out of memory\n";
00273       return -1;
00274     }
00275 
00276     GroundMotion *theMotion;
00277     for (int i=0; i<numMotions; i++) {
00278       theMotion = theBroker.getNewGroundMotion(motionData(i*2));
00279       if (theMotion == 0) {
00280         return -1;
00281       }
00282 
00283       theMotion->setDbTag(motionData(i*2+1));
00284 
00285       if (theMotion->recvSelf(commitTag, theChannel, theBroker) < 0) {
00286         opserr << "MultiSupportPattern::sendSelf - ground motion failed in sendSelf\n";
00287         return -7;
00288       }
00289     }    
00290   }
00291   return 0;
00292 }
00293 
00294 void 
00295 MultiSupportPattern::Print(OPS_Stream &s, int flag)
00296 {
00297   s << "MultiSupportPattern  tag: " << this->getTag() << endln;
00298   SP_Constraint *sp;
00299   SP_ConstraintIter &theIter = this->getSPs();
00300   while ((sp = theIter()) != 0)
00301     sp->Print(s, flag);
00302 }
00303 
00304 LoadPattern *
00305 MultiSupportPattern::getCopy(void)
00306 {
00307   LoadPattern *theCopy = new MultiSupportPattern(this->getTag());
00308   return theCopy;
00309 }

Generated on Mon Oct 23 15:05:02 2006 for OpenSees by doxygen 1.5.0