| 123 | } |
| 124 | |
| 125 | TimeSeries* |
| 126 | TrapezoidalTimeSeriesIntegrator::differentiate(TimeSeries *theSeries, double delta) |
| 127 | { |
| 128 | // Check for zero time step, before dividing to get number of steps |
| 129 | if (delta <= 0.0) { |
| 130 | opserr << "TrapezoidalTimeSeriesIntegrator::differentiate() Attempting to differentiate using time step" << |
| 131 | delta << "<= 0\n"; |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | // check a TimeSeries object was passed |
| 136 | if (theSeries == 0) { |
| 137 | opserr << "TrapezoidalTimeSeriesIntegrator::differentiate() - - no TimeSeries passed\n"; |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | // Add one to get ceiling out of type cast |
| 142 | long long numSteps = (long long)(theSeries->getDuration() / delta + 1.0); |
| 143 | |
| 144 | Vector *theDif = new Vector (numSteps); |
| 145 | |
| 146 | // Check that the Vector was allocated properly |
| 147 | if (theDif == 0 || theDif->Size() == 0) { |
| 148 | opserr << "TrapezoidalTimeSeriesIntegrator::differentiate() Ran out of memory allocating Vector " << endln; |
| 149 | |
| 150 | if (theDif != 0) |
| 151 | delete theDif; |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | double dummyTime; // Dummy variable for integrating |
| 157 | double Fi, Fj; // function values |
| 158 | double f; // derivative value |
| 159 | |
| 160 | dummyTime = theSeries->getStartTime(); |
| 161 | |
| 162 | f = 0.0; |
| 163 | |
| 164 | Fi = 0.0; |
| 165 | |
| 166 | opserr<<"differentiate()\n"; |
| 167 | for (long long i = 0; i < numSteps; i++, dummyTime += delta) { |
| 168 | Fj = theSeries->getFactor(dummyTime); |
| 169 | |
| 170 | // Apply the trapezoidal rule to update the derivative |
| 171 | f = 2.0 * (Fj - Fi) / delta - f; |
| 172 | |
| 173 | (*theDif)[i] = f; |
| 174 | |
| 175 | Fi = Fj; |
| 176 | if (i < 10) |
| 177 | opserr<<"data"<<f<<" "<<Fi<<" "<<Fj<<"\n"; |
| 178 | } |
| 179 | |
| 180 | // Set the method return value |
| 181 | PathSeries *returnSeries = new PathSeries (0, *theDif, delta, 1.0, true, false, theSeries->getStartTime()); |
| 182 | delete theDif; |
nothing calls this directly
no test coverage detected