GroundMotion.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.10 $
00022 // $Date: 2006/09/05 20:54:46 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/domain/groundMotion/GroundMotion.cpp,v $
00024                                                                         
00025 // Written: fmk 
00026 // Created: 05/98
00027 // Revision: A
00028 
00029 
00030 #include <GroundMotion.h>
00031 #include <TimeSeriesIntegrator.h>
00032 #include <TrapezoidalTimeSeriesIntegrator.h>
00033 #include <OPS_Globals.h>
00034 #include <Channel.h>
00035 #include <FEM_ObjectBroker.h>
00036 #include <ID.h>
00037 
00038 GroundMotion::GroundMotion(TimeSeries *dispSeries, 
00039                            TimeSeries *velSeries, 
00040                            TimeSeries *accelSeries,
00041                            TimeSeriesIntegrator *theIntegratr,
00042                            double dTintegration)
00043 :MovableObject(GROUND_MOTION_TAG_GroundMotion), 
00044  theAccelSeries(accelSeries), theVelSeries(velSeries), 
00045  theDispSeries(dispSeries), theIntegrator(theIntegratr),
00046  data(3), delta(dTintegration)
00047 {
00048 
00049 }
00050 
00051 
00052 
00053 GroundMotion::GroundMotion(int theClassTag)
00054 :MovableObject(theClassTag), 
00055  theAccelSeries(0), theVelSeries(0), theDispSeries(0), theIntegrator(0),
00056  data(3), delta(0.0)
00057 {
00058 
00059 }
00060 
00061 GroundMotion::~GroundMotion()
00062 {
00063   if (theAccelSeries != 0)
00064     delete theAccelSeries;
00065   if (theVelSeries != 0)
00066     delete theVelSeries;
00067   if (theDispSeries != 0)
00068     delete theDispSeries;
00069   if (theIntegrator != 0)
00070     delete theIntegrator;
00071 }
00072 
00073 
00074 void
00075 GroundMotion::setIntegrator(TimeSeriesIntegrator *integrator)
00076 {
00077   if (theIntegrator != 0)
00078     delete theIntegrator;
00079 
00080   theIntegrator = integrator;
00081 }
00082 
00083 TimeSeries*
00084 GroundMotion::integrate(TimeSeries *theSeries, double delta)
00085 {
00086   // check that an integrator & accel series exist
00087   if(theIntegrator == 0) {
00088     //opserr << "WARNING:GroundMotion::integrate() - no TimeSeriesIntegrator provided - will use Trapezoidal. \n";
00089     theIntegrator = new TrapezoidalTimeSeriesIntegrator();
00090     if(theIntegrator == 0) {
00091       opserr << "WARNING:GroundMotion::integrate() - no TimeSeriesIntegrator provided - failed to create a Trapezoidal .. memory problems! \n";
00092       return 0;
00093     }
00094   }
00095 
00096   if(theSeries == 0) {
00097     opserr << "GroundMotion::integrate - no TimeSeries specified\n";
00098     return 0;
00099   }
00100 
00101   // integrate the series, if no vel series exists set it to new one
00102   TimeSeries *theNewSeries = theIntegrator->integrate(theSeries, delta);
00103 
00104   if(theNewSeries == 0) {
00105     opserr << "GroundMotion::integrate - no TimeSeriesIntegrator failed to integrate\n";
00106     return 0;
00107   }
00108 
00109   return theNewSeries;
00110 }
00111 
00112 double 
00113 GroundMotion::getDuration(void)
00114 {
00115   if (theAccelSeries != 0)
00116     return theAccelSeries->getDuration();
00117   else
00118     return 0.0;
00119 }
00120 
00121 double 
00122 GroundMotion::getPeakAccel(void)
00123 {
00124   if (theAccelSeries != 0)
00125     return theAccelSeries->getPeakFactor();
00126   else
00127     return 0.0;
00128 
00129 }
00130 
00131 double 
00132 GroundMotion::getPeakVel(void)
00133 {
00134   if (theVelSeries != 0)
00135     return theVelSeries->getPeakFactor();
00136 
00137   // if theAccel is not 0, integrate accel series to get a vel series
00138   else if (theAccelSeries != 0) {
00139     theVelSeries = this->integrate(theAccelSeries, delta);
00140     if (theVelSeries != 0)
00141       return theVelSeries->getPeakFactor();      
00142     else
00143       return 0.0;
00144   }
00145   return 0.0;
00146 }
00147 
00148 double 
00149 GroundMotion::getPeakDisp(void)
00150 {
00151   if (theDispSeries != 0)
00152     return theDispSeries->getPeakFactor();
00153 
00154   // if theVel is not 0, integrate vel series to get disp series
00155   else if (theVelSeries != 0) {
00156     theDispSeries = this->integrate(theVelSeries, delta);
00157     if (theDispSeries != 0)
00158       return theDispSeries->getPeakFactor();      
00159     else
00160       return 0.0;
00161   }
00162 
00163   // if theAccel is not 0, integrate vel series to get disp series
00164   else if (theAccelSeries != 0) {
00165     theVelSeries = this->integrate(theAccelSeries, delta);
00166     if (theVelSeries != 0) {
00167       theDispSeries = this->integrate(theVelSeries, delta);
00168       if (theDispSeries != 0)
00169         return theDispSeries->getPeakFactor();      
00170       else
00171         return 0.0;
00172     } else
00173       return 0.0;
00174   }
00175 
00176   return 0.0;
00177 }
00178 
00179 double 
00180 GroundMotion::getAccel(double time)
00181 {
00182   if (time < 0.0)
00183     return 0.0;
00184   
00185   if (theAccelSeries != 0)
00186     return theAccelSeries->getFactor(time);
00187   else
00188     return 0.0;
00189 }     
00190 
00191 double 
00192 GroundMotion::getAccelSensitivity(double time)
00193 {
00194   if (time < 0.0)
00195     return 0.0;
00196   
00197   if (theAccelSeries != 0)
00198     return theAccelSeries->getFactorSensitivity(time);
00199   else
00200     return 0.0;
00201 }     
00202 
00203 double 
00204 GroundMotion::getVel(double time)
00205 {
00206   if (time < 0.0)
00207     return 0.0;
00208 
00209   if (theVelSeries != 0)
00210     return theVelSeries->getFactor(time);      
00211 
00212   // if theAccel is not 0, integrate accel series to get a vel series
00213   else if (theAccelSeries != 0) {
00214     //opserr << " WARNING: GroundMotion::getVel(double time) - integration is required to get the ground velocities from the ground accelerations\n";
00215     theVelSeries = this->integrate(theAccelSeries, delta);
00216 
00217     if (theVelSeries != 0) {
00218       return theVelSeries->getFactor(time);      
00219 
00220     } else {
00221       opserr << " WARNING: GroundMotion::getVel(double time) - failed to integrate\n";
00222       return 0.0;
00223     }
00224   }
00225 
00226   return 0.0;
00227 }
00228 
00229 double 
00230 GroundMotion::getDisp(double time)
00231 {
00232   if (time < 0.0)
00233     return 0.0;
00234 
00235   if (theDispSeries != 0)
00236     return theDispSeries->getFactor(time);
00237 
00238   // if theVel is not 0, integrate vel series to get disp series
00239   else if (theVelSeries != 0) {
00240     opserr << " WARNING: GroundMotion::getDisp(double time) - integration is required to get the ground displacements from the ground velocities\n";
00241     theDispSeries = this->integrate(theVelSeries, delta);
00242     if (theDispSeries != 0)
00243       return theDispSeries->getFactor(time);      
00244     else
00245       return 0.0;
00246   }
00247 
00248   // if theAccel is not 0, integrate vel series to get disp series
00249   else if (theAccelSeries != 0) {    
00250     opserr << " WARNING: GroundMotion::getDisp(double time) - default integration required to get the ground displacements from the ground velocities via the ground accelerations\n";
00251     theVelSeries = this->integrate(theAccelSeries, delta);
00252     if (theVelSeries != 0) {
00253       theDispSeries = this->integrate(theVelSeries, delta);
00254       if (theDispSeries != 0)
00255         return theDispSeries->getFactor(time);      
00256       else
00257         return 0.0;
00258     } else
00259       return 0.0;
00260   }
00261 
00262   return 0.0;
00263 }
00264 
00265 const Vector &
00266 GroundMotion::getDispVelAccel(double time)
00267 {
00268   if (time < 0.0) {
00269     data(0) = 0.0;
00270     data(1) = 0.0;
00271     data(2) = 0.0;
00272     return data;
00273   }
00274 
00275   if (theAccelSeries != 0 && theVelSeries != 0 && theDispSeries != 0) {
00276     data(0) = theDispSeries->getFactor(time);
00277     data(1) = theVelSeries->getFactor(time);
00278     data(2) = theAccelSeries->getFactor(time);
00279   } else {
00280     data(2) = this->getAccel(time);
00281     data(1) = this->getVel(time);
00282     data(0) = this->getDisp(time);
00283   }
00284 
00285   return data;
00286 }
00287 
00288 
00289 int 
00290 GroundMotion::sendSelf(int commitTag, Channel &theChannel)
00291 {
00292   int dbTag = this->getDbTag();
00293 
00294   static ID idData(8);
00295   
00296   if (theAccelSeries != 0) {
00297     idData(0) = theAccelSeries->getClassTag();
00298     int seriesDbTag = theAccelSeries->getDbTag();
00299     if (seriesDbTag == 0) {
00300       seriesDbTag = theChannel.getDbTag();
00301       theAccelSeries->setDbTag(seriesDbTag);
00302     }
00303     idData(1) = seriesDbTag;
00304   } else
00305     idData(0) = -1;
00306 
00307   if (theVelSeries != 0) {
00308     idData(2) = theVelSeries->getClassTag();
00309     int seriesDbTag = theVelSeries->getDbTag();
00310     if (seriesDbTag == 0) {
00311       seriesDbTag = theChannel.getDbTag();
00312       theVelSeries->setDbTag(seriesDbTag);
00313     }
00314     idData(3) = seriesDbTag;
00315   } else
00316     idData(2) = -1;
00317 
00318   if (theDispSeries != 0) {
00319     idData(4) = theDispSeries->getClassTag();
00320     int seriesDbTag = theDispSeries->getDbTag();
00321     if (seriesDbTag == 0) {
00322       seriesDbTag = theChannel.getDbTag();
00323       theDispSeries->setDbTag(seriesDbTag);
00324     }
00325     idData(5) = seriesDbTag;
00326   } else
00327     idData(4) = -1;
00328 
00329   if (theIntegrator != 0) {
00330     idData(6) = theIntegrator->getClassTag();
00331     int seriesDbTag = theIntegrator->getDbTag();
00332     if (seriesDbTag == 0) {
00333       seriesDbTag = theChannel.getDbTag();
00334       theIntegrator->setDbTag(seriesDbTag);
00335     }
00336     idData(7) = seriesDbTag;
00337   } else
00338     idData(6) = -1;
00339 
00340   int res = theChannel.sendID(dbTag, commitTag, idData);
00341   if (res < 0) {
00342     opserr << "GroundMotionRecord::sendSelf() - channel failed to send data\n";
00343     return res;
00344   }
00345 
00346   // now send the series
00347   if (theAccelSeries != 0) {
00348     res = theAccelSeries->sendSelf(commitTag, theChannel);
00349     if (res < 0) {
00350       opserr << "GroundMotionRecord::sendSelf - failed to send accel series\n";
00351       return res;
00352     }
00353   }
00354 
00355   if (theVelSeries != 0) {
00356     res = theVelSeries->sendSelf(commitTag, theChannel);
00357     if (res < 0) {
00358       opserr << "GroundMotionRecord::sendSelf - failed to send velocity series\n";
00359       return res;
00360     }
00361   }
00362 
00363   if (theDispSeries != 0) {
00364     res = theDispSeries->sendSelf(commitTag, theChannel);
00365     if (res < 0) {
00366       opserr << "GroundMotionRecord::sendSelf - failed to send disp series\n";
00367       return res;
00368     }
00369   }
00370 
00371   if (theIntegrator != 0) {
00372     res = theIntegrator->sendSelf(commitTag, theChannel);
00373     if (res < 0) {
00374       opserr << "GroundMotionRecord::sendSelf - failed to send disp series\n";
00375       return res;
00376     }
00377   }
00378 
00379   return 0;
00380 }
00381 
00382 
00383 int 
00384 GroundMotion::recvSelf(int commitTag, Channel &theChannel, 
00385                        FEM_ObjectBroker &theBroker)
00386 {
00387           int dbTag = this->getDbTag();
00388 
00389   static ID idData(8);
00390   int res = theChannel.recvID(dbTag, commitTag, idData);
00391   if (res < 0) {
00392     opserr << "UniformExcitation::sendSelf() - channel failed to send data\n";
00393     return res;
00394   }
00395 
00396   int seriesClassTag = idData(0);
00397   if (seriesClassTag != -1) {
00398     int seriesDbTag = idData(1);
00399     if (theAccelSeries == 0 || theAccelSeries->getClassTag() != seriesClassTag) {
00400       if (theAccelSeries != 0)
00401         delete theAccelSeries;
00402       theAccelSeries = theBroker.getNewTimeSeries(seriesClassTag);
00403       if (theAccelSeries == 0) {
00404         opserr << "GroundMotionRecord::sendSelf - could not create a Series object\n";
00405         return -2;
00406       }
00407     }
00408     theAccelSeries->setDbTag(seriesDbTag);
00409     res = theAccelSeries->recvSelf(commitTag, theChannel, theBroker);
00410     if (res < 0) {
00411       opserr << "UniformExcitation::sendSelf() - accel series failed to send data\n";
00412       return res;
00413     }
00414   }
00415 
00416   seriesClassTag = idData(2);
00417   if (seriesClassTag != -1) {
00418     int seriesDbTag = idData(3);
00419     if (theVelSeries == 0 || theVelSeries->getClassTag() != seriesClassTag) {
00420       if (theVelSeries != 0)
00421         delete theVelSeries;
00422       theVelSeries = theBroker.getNewTimeSeries(seriesClassTag);
00423       if (theVelSeries == 0) {
00424         opserr << "GroundMotionRecord::sendSelf - could not create a Series object\n";
00425         return -2;
00426       }
00427     }
00428     theVelSeries->setDbTag(seriesDbTag);
00429     res = theVelSeries->recvSelf(commitTag, theChannel, theBroker);
00430     if (res < 0) {
00431       opserr << "UniformExcitation::sendSelf() - accel series failed to send data\n";
00432       return res;
00433     }
00434   }
00435 
00436   seriesClassTag = idData(4);
00437   if (seriesClassTag != -1) {
00438     int seriesDbTag = idData(5);
00439     if (theDispSeries == 0 || theDispSeries->getClassTag() != seriesClassTag) {
00440       if (theDispSeries != 0)
00441         delete theDispSeries;
00442       theDispSeries = theBroker.getNewTimeSeries(seriesClassTag);
00443       if (theDispSeries == 0) {
00444         opserr << "GroundMotionRecord::sendSelf - could not create a Series object\n";
00445         return -2;
00446       }
00447     }
00448     theDispSeries->setDbTag(seriesDbTag);
00449     res = theDispSeries->recvSelf(commitTag, theChannel, theBroker);
00450     if (res < 0) {
00451       opserr << "UniformExcitation::sendSelf() - accel series failed to send data\n";
00452       return res;
00453     }
00454   }
00455 
00456   seriesClassTag = idData(6);
00457   if (seriesClassTag != -1) {
00458     int seriesDbTag = idData(7);
00459     if (theIntegrator == 0 || theIntegrator->getClassTag() != seriesClassTag) {
00460       if (theIntegrator != 0)
00461         delete theIntegrator;
00462       theIntegrator = theBroker.getNewTimeSeriesIntegrator(seriesClassTag);
00463       if (theIntegrator == 0) {
00464         opserr << "GroundMotionRecord::sendSelf - could not create an Integrator object\n";
00465         return -2;
00466       }
00467     }
00468     theIntegrator->setDbTag(seriesDbTag);
00469     res = theIntegrator->recvSelf(commitTag, theChannel, theBroker);
00470     if (res < 0) {
00471       opserr << "UniformExcitation::sendSelf() - accel series failed to send data\n";
00472       return res;
00473     }
00474   }
00475 
00476   return 0;
00477 }
00478 
00479 // AddingSensitivity:BEGIN ////////////////////////////////////
00480 int
00481 GroundMotion::setParameter(const char **argv, int argc, Parameter &param)
00482 {
00483   return theAccelSeries->setParameter(argv, argc, param);
00484 }
00485 
00486 int
00487 GroundMotion::updateParameter(int parameterID, Information &info)
00488 {
00489   return theAccelSeries->updateParameter(parameterID, info);
00490 }
00491 
00492 int
00493 GroundMotion::activateParameter(int pparameterID)
00494 {
00495   return theAccelSeries->activateParameter(pparameterID);
00496 }
00497 // AddingSensitivity:END ////////////////////////////////////
00498 
00499 
00500 
00501 

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