Permalink
Browse files

Fast W'bal integration

Dave Waterworth has fixed my implementation of W'bal to
remove my "optimisations" and fix the math.

The W'bal is now computed in a single pass and is just
as fast as the differential form from Andy Froncioni but
has the benefit that is still uses Tau.

Many thanks to Dave, and I'll write this up shortly.
  • Loading branch information...
liversedge committed Oct 11, 2014
1 parent 15183e1 commit 40556883e6c95153973716e3d13b7ba012a96929
Showing with 11 additions and 30 deletions.
  1. +2 −1 src/DBAccess.cpp
  2. +9 −29 src/WPrime.cpp
View
@@ -105,8 +105,9 @@
// 84 08 Sep 2014 Mark Liversedge Added HrPw Ratio
// 85 09 Sep 2014 Mark Liversedge Added HrNp Ratio
// 86 26 Sep 2014 Mark Liversedge Added isRun first class var
// 87 11 Oct 2014 Mark Liversedge W'bal inegrator fixed up by Dave Waterworth
int DBSchemaVersion = 86;
int DBSchemaVersion = 87;
DBAccess::DBAccess(Context* context) : context(context), db(NULL)
{
View
@@ -219,19 +219,15 @@ WPrime::setRide(RideFile *input)
int stop = last / 2;
WPrimeIntegrator a(inputArray, 0, stop, TAU);
WPrimeIntegrator b(inputArray, stop+1, last, TAU);
WPrimeIntegrator a(inputArray, 0, last, TAU);
a.start();
b.start();
a.wait();
b.wait();
// sum values
for (int t=0; t<=last; t++) {
values[t] = a.output[t] + b.output[t];
xvalues[t] = double(t) / 60.00f;
values[t] = a.output[t];
xvalues[t] = t / 60.00f;
}
// now subtract WPRIME and work out minimum etc
@@ -428,19 +424,14 @@ WPrime::setErg(ErgFile *input)
int stop = last / 2;
WPrimeIntegrator a(inputArray, 0, stop, TAU);
WPrimeIntegrator b(inputArray, stop+1, last, TAU);
WPrimeIntegrator a(inputArray, 0, last, TAU);
a.start();
b.start();
a.wait();
b.wait();
// sum values
for (int t=0; t<=last; t++) {
values[t] = a.output[t] + b.output[t];
xvalues[t] = t * 1000;
values[t] = a.output[t];
}
// now subtract WPRIME and work out minimum etc
@@ -549,22 +540,11 @@ void
WPrimeIntegrator::run()
{
// run from start to stop adding decay to end
for (int t=begin; t<end; t++) {
if (source[t] <= 0) continue;
double I = 0.00f;
for (int t=0; t<=end; t++) {
// start at 1, since the actual value shouldn't be adjusted with itself !
for (int i=1; i < (TAU*3) /*WPrimeDecayPeriod*/ && t+i < source.size(); i++) {
double value = source[t] * exp(-(double(i)/TAU));
// diminishing returns - we're dealing in kJ, so 10J is nothing !
// this saves about 20% in calculation time typically
if (value < 10.00f) break;
// integrate
output[t+i] += value;
}
I += exp(((double)(t) / TAU)) * source[t];
output[t] = exp(-((double)(t) / TAU)) * I;
}
}

0 comments on commit 4055688

Please sign in to comment.