MCPcopy Create free account
hub / github.com/OpenSees/OpenSees / differentiate

Method differentiate

SRC/domain/pattern/SimpsonTimeSeriesIntegrator.cpp:128–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126
127
128TimeSeries* SimpsonTimeSeriesIntegrator::differentiate(TimeSeries *theSeries, double delta)
129{
130 // check for zero time step, before dividing to get number of steps
131 if (delta <= 0.0) {
132 opserr << "SimpsonTimeSeriesIntegrator::differentiate() - attempting to differentiate using time step "
133 << delta << "<= 0.0.\n";
134 return 0;
135 }
136
137 // check a TimeSeries object was passed
138 if (theSeries == 0) {
139 opserr << "SimpsonTimeSeriesIntegrator::differentiate() - no TimeSeries passed.\n";
140 return 0;
141 }
142
143 // add one to get ceiling out of type cast
144 long long numSteps = (long long)(theSeries->getDuration()/delta + 1.0);
145
146 // create new vector for integrated values
147 Vector *theDif = new Vector(numSteps);
148
149 // check that the Vector was allocated properly
150 if (theDif == 0 || theDif->Size() == 0) {
151 opserr << "SimpsonTimeSeriesIntegrator::differentiate() - ran out of memory allocating Vector " << endln;
152
153 if (theDif != 0)
154 delete theDif;
155
156 return 0;
157 }
158
159 double dummyTime;
160 double Fi, Fj, Fk; //function values
161 double fi, fj, fk; //derivative values
162
163 dummyTime = theSeries->getStartTime();
164
165 Fi = 0.0;
166 Fj = 0.0;
167
168 fi = 0.0;
169 fj = 0.0;
170
171 for (long long i = 0; i < numSteps; i++, dummyTime += delta) {
172
173 Fk = theSeries->getFactor(dummyTime);
174 // Apply the Simpson's rule to update the derivative
175 fk = 3.0 * (Fk - Fi) / delta - fi - 4.0 * fj;
176
177 (*theDif)[i] = fk;
178
179 fi = fj;
180 fj = fk;
181
182 Fi = Fj;
183 Fj = Fk;
184 }
185

Callers

nothing calls this directly

Calls 4

getDurationMethod · 0.45
SizeMethod · 0.45
getStartTimeMethod · 0.45
getFactorMethod · 0.45

Tested by

no test coverage detected