TrapezoidalTimeSeriesIntegrator.cppGo 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: 2003/02/14 23:01:01 $ 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 <TrapezoidalTimeSeriesIntegrator.h> 00039 #include <Vector.h> 00040 #include <Channel.h> 00041 #include <PathSeries.h> 00042 00043 TrapezoidalTimeSeriesIntegrator::TrapezoidalTimeSeriesIntegrator() 00044 :TimeSeriesIntegrator(TIMESERIES_INTEGRATOR_TAG_Trapezoidal) 00045 { 00046 00047 } 00048 00049 TrapezoidalTimeSeriesIntegrator::~TrapezoidalTimeSeriesIntegrator() 00050 { 00051 00052 } 00053 00054 TimeSeries* 00055 TrapezoidalTimeSeriesIntegrator::integrate(TimeSeries *theSeries, double delta) 00056 { 00057 // Check for zero time step, before dividing to get number of steps 00058 if (delta <= 0.0) { 00059 opserr << "TrapezoidalTimeSeriesIntegrator::integrate() Attempting to integrate time step" << 00060 delta, "<= 0\n"; 00061 return 0; 00062 } 00063 00064 // check a TimeSeries object was passed 00065 if (theSeries == 0) { 00066 opserr << "TrapezoidalTimeSeriesIntegrator::integrate() - - no TimeSeries passed\n"; 00067 return 0; 00068 } 00069 00070 // Add one to get ceiling out of type cast 00071 int numSteps = (int)(theSeries->getDuration()/delta + 1.0); 00072 00073 Vector *theIntegratedValues = new Vector (numSteps); 00074 00075 // Check that the Vector was allocated properly 00076 if (theIntegratedValues == 0 || theIntegratedValues->Size() == 0) { 00077 opserr << "TrapezoidalTimeSeriesIntegrator::integrate() Ran out of memory allocating Vector of size " << 00078 numSteps << endln; 00079 00080 if (theIntegratedValues != 0) 00081 delete theIntegratedValues; 00082 00083 return 0; 00084 } 00085 00086 int i; // Counter for indexing 00087 double dummyTime; // Dummy variable for integrating 00088 double previousValue; // Temporary storage to avoid accessing same value twice 00089 // through identical method calls 00090 double currentValue; 00091 00092 // Set the first point 00093 // Assuming initial condition is zero, i.e. F(0) = 0 00094 00095 00096 (*theIntegratedValues)[0] = theSeries->getFactor(0.0) * delta * 0.5; 00097 00098 previousValue = (*theIntegratedValues)[0]; 00099 00100 dummyTime = delta; 00101 00102 for (i = 1; i < numSteps; i++, dummyTime += delta) { 00103 currentValue = theSeries->getFactor(dummyTime); 00104 00105 // Apply the trapezoidal rule to update the integrated value 00106 (*theIntegratedValues)[i] = (*theIntegratedValues)[i-1] + 00107 delta*0.5 * (currentValue + previousValue); 00108 00109 previousValue = currentValue; 00110 } 00111 00112 /* 00113 // Set the last point 00114 (*theIntegratedValues)[i] = (*theIntegratedValues)[i-1] + 00115 delta*0.5 * (theSeries->getFactor(dummyTime)); 00116 */ 00117 00118 // Set the method return value 00119 PathSeries *returnSeries = new PathSeries (*theIntegratedValues, delta); 00120 00121 if (returnSeries == 0) { 00122 opserr << "TrapezoidalTimeSeriesIntegrator::integrate() Ran out of memory creating PathSeries\n"; 00123 00124 return 0; 00125 } 00126 00127 return returnSeries; 00128 } 00129 00130 int 00131 TrapezoidalTimeSeriesIntegrator::sendSelf(int commitTag, Channel &theChannel) 00132 { 00133 return 0; 00134 } 00135 00136 int 00137 TrapezoidalTimeSeriesIntegrator::recvSelf(int commitTag, Channel &theChannel, 00138 FEM_ObjectBroker &theBroker) 00139 { 00140 return 0; 00141 } 00142 00143 void 00144 TrapezoidalTimeSeriesIntegrator::Print(OPS_Stream &s, int flag) 00145 { 00146 // Need to implement, return for now 00147 return; 00148 } |