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

TrapezoidalTimeSeriesIntegrator.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.2 $
00022 // $Date: 2001/05/18 04:51:55 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/domain/pattern/TrapezoidalTimeSeriesIntegrator.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/domain/pattern/TrapezoidalTimeSeriesIntegrator.cpp
00027 // 
00028 // Written: MHS
00029 // Created: 10/99
00030 // Revision: A
00031 //
00032 // Description: This file contains the class definition for 
00033 // a TrapezoidalTimeSeriesIntegrator, which integrates a
00034 // ground motion TimeSeries using the trapezoidal rule.
00035 //
00036 // What: "@(#) TrapezoidalTimeSeriesIntegrator.cpp, revA"
00037 
00038 #include <iostream.h>
00039 #include <TrapezoidalTimeSeriesIntegrator.h>
00040 #include <Vector.h>
00041 #include <Channel.h>
00042 #include <PathSeries.h>
00043 
00044 TrapezoidalTimeSeriesIntegrator::TrapezoidalTimeSeriesIntegrator() 
00045   :TimeSeriesIntegrator(TIMESERIES_INTEGRATOR_TAG_Trapezoidal)
00046 {
00047 
00048 }
00049 
00050 TrapezoidalTimeSeriesIntegrator::~TrapezoidalTimeSeriesIntegrator()
00051 {
00052 
00053 }
00054 
00055 TimeSeries*
00056 TrapezoidalTimeSeriesIntegrator::integrate(TimeSeries *theSeries, double delta)
00057 { 
00058   // Check for zero time step, before dividing to get number of steps
00059   if (delta <= 0.0) {
00060     g3ErrorHandler->warning("TrapezoidalTimeSeriesIntegrator::integrate() %s %d %s\n",
00061       "Attempting to integrate time step", delta, "<= 0");
00062     return 0;
00063    }
00064 
00065   // check a TimeSeries object was passed
00066   if (theSeries == 0) {
00067     g3ErrorHandler->warning("TrapezoidalTimeSeriesIntegrator::integrate() %s\n",
00068         "- no TimeSeries passed");
00069     return 0;
00070   }
00071 
00072   // Add one to get ceiling out of type cast
00073   int numSteps = (int)(theSeries->getDuration()/delta + 1.0);
00074 
00075   Vector *theIntegratedValues = new Vector (numSteps);
00076 
00077   // Check that the Vector was allocated properly
00078   if (theIntegratedValues == 0 || theIntegratedValues->Size() == 0) {
00079     g3ErrorHandler->warning("TrapezoidalTimeSeriesIntegrator::integrate() %s %d\n",
00080        "Ran out of memory allocating Vector of size ", numSteps);
00081 
00082     if (theIntegratedValues != 0)
00083       delete theIntegratedValues;
00084 
00085     return 0;
00086   }
00087 
00088   int i;                // Counter for indexing
00089   double dummyTime;     // Dummy variable for integrating
00090   double previousValue; // Temporary storage to avoid accessing same value twice
00091                          // through identical method calls
00092   double currentValue;
00093       
00094   // Set the first point
00095   // Assuming initial condition is zero, i.e. F(0) = 0
00096 
00097 
00098   (*theIntegratedValues)[0] = theSeries->getFactor(0.0) * delta * 0.5;
00099 
00100   previousValue = (*theIntegratedValues)[0];
00101   
00102   dummyTime = delta;
00103     
00104   for (i = 1; i < numSteps; i++, dummyTime += delta) {
00105     currentValue = theSeries->getFactor(dummyTime);
00106     
00107     // Apply the trapezoidal rule to update the integrated value
00108     (*theIntegratedValues)[i] = (*theIntegratedValues)[i-1] +
00109       delta*0.5 * (currentValue + previousValue);
00110     
00111     previousValue = currentValue;
00112   }
00113 
00114   /*
00115   // Set the last point
00116   (*theIntegratedValues)[i] = (*theIntegratedValues)[i-1] +
00117     delta*0.5 * (theSeries->getFactor(dummyTime));
00118   */
00119 
00120   // Set the method return value
00121   PathSeries *returnSeries = new PathSeries (*theIntegratedValues, delta);
00122 
00123   if (returnSeries == 0) {
00124     g3ErrorHandler->warning("TrapezoidalTimeSeriesIntegrator::integrate() %s\n",
00125        "Ran out of memory creating PathSeries");
00126 
00127     return 0;
00128    }
00129 
00130   return returnSeries;
00131 }
00132 
00133 int
00134 TrapezoidalTimeSeriesIntegrator::sendSelf(int commitTag, Channel &theChannel)
00135 {
00136    // Need to implement, return dummy value for now
00137    return 1;
00138 }
00139 
00140 int
00141 TrapezoidalTimeSeriesIntegrator::recvSelf(int commitTag, Channel &theChannel, 
00142              FEM_ObjectBroker &theBroker)
00143 {
00144    // Need to implement, return dummy value for now
00145    return 1;
00146 }
00147 
00148 void
00149 TrapezoidalTimeSeriesIntegrator::Print(ostream &s, int flag)
00150 {
00151    // Need to implement, return for now
00152    return;
00153 }
Copyright Contact Us