00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
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
00066 if (theSeries == 0) {
00067 g3ErrorHandler->warning("TrapezoidalTimeSeriesIntegrator::integrate() %s\n",
00068 "- no TimeSeries passed");
00069 return 0;
00070 }
00071
00072
00073 int numSteps = (int)(theSeries->getDuration()/delta + 1.0);
00074
00075 Vector *theIntegratedValues = new Vector (numSteps);
00076
00077
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;
00089 double dummyTime;
00090 double previousValue;
00091
00092 double currentValue;
00093
00094
00095
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
00108 (*theIntegratedValues)[i] = (*theIntegratedValues)[i-1] +
00109 delta*0.5 * (currentValue + previousValue);
00110
00111 previousValue = currentValue;
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
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
00137 return 1;
00138 }
00139
00140 int
00141 TrapezoidalTimeSeriesIntegrator::recvSelf(int commitTag, Channel &theChannel,
00142 FEM_ObjectBroker &theBroker)
00143 {
00144
00145 return 1;
00146 }
00147
00148 void
00149 TrapezoidalTimeSeriesIntegrator::Print(ostream &s, int flag)
00150 {
00151
00152 return;
00153 }