mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-08 20:12:23 +00:00
Started implementing the getImpliedWindNewton() method of ORCPerformanceCurveImpl. Goal is to analyse the difference of the accuracy with this method in comparison to the ORC way.
This commit is contained in:
1 parent
9e2211048a
commit
8fa3992941
2 files changed
+50
-3
No files matched your search
+27
-3
@@ -11,6 +11,7 @@ import java.util.Map;
|
||||
|
||||
import org.apache.commons.math.ArgumentOutsideDomainException;
|
||||
import org.apache.commons.math.FunctionEvaluationException;
|
||||
import org.apache.commons.math.MaxIterationsExceededException;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
@@ -137,9 +138,32 @@ public class TestORCPerformanceCurve {
|
||||
ORCPerformanceCurveImpl performanceCurve = (ORCPerformanceCurveImpl) certificate.getPerformanceCurve(course);
|
||||
|
||||
|
||||
assertEquals(6, performanceCurve.getImpliedWind(performanceCurve.getAllowancePerCourse(new KnotSpeedImpl(6))).getKnots(), accuracy);
|
||||
assertEquals(11.5, performanceCurve.getImpliedWind(performanceCurve.getAllowancePerCourse(new KnotSpeedImpl(11.5))).getKnots(), accuracy);
|
||||
assertEquals( 6, performanceCurve.getImpliedWind(performanceCurve.getAllowancePerCourse(new KnotSpeedImpl( 6))).getKnots(), accuracy);
|
||||
assertEquals( 11.5, performanceCurve.getImpliedWind(performanceCurve.getAllowancePerCourse(new KnotSpeedImpl( 11.5))).getKnots(), accuracy);
|
||||
assertEquals(17.23, performanceCurve.getImpliedWind(performanceCurve.getAllowancePerCourse(new KnotSpeedImpl(17.23))).getKnots(), accuracy);
|
||||
}
|
||||
|
||||
assertEquals( 500, performanceCurve.getAllowancePerCourse(performanceCurve.getImpliedWind(Duration.ONE_SECOND.times(500))).asSeconds(), accuracy);
|
||||
assertEquals( 600, performanceCurve.getAllowancePerCourse(performanceCurve.getImpliedWind(Duration.ONE_SECOND.times(600))).asSeconds(), accuracy);
|
||||
assertEquals( 700, performanceCurve.getAllowancePerCourse(performanceCurve.getImpliedWind(Duration.ONE_SECOND.times(700))).asSeconds(), accuracy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerformanceCurveInvertationNewton() throws MaxIterationsExceededException, FunctionEvaluationException {
|
||||
System.out.println("- testPerformanceCurveInvertationNewton() -");
|
||||
Double accuracy = 0.1;
|
||||
ORCCertificateImpl certificate = (ORCCertificateImpl) importer.getCertificate("GER 5549");
|
||||
ORCPerformanceCurveImpl performanceCurve = (ORCPerformanceCurveImpl) certificate.getPerformanceCurve(course);
|
||||
|
||||
|
||||
//assertEquals( 6, performanceCurve.getImpliedWindNewton(performanceCurve.getAllowancePerCourse(new KnotSpeedImpl( 6))).getKnots(), accuracy);
|
||||
assertEquals( 11.5, performanceCurve.getImpliedWindNewton(performanceCurve.getAllowancePerCourse(new KnotSpeedImpl( 11.5))).getKnots(), accuracy);
|
||||
assertEquals(17.23, performanceCurve.getImpliedWindNewton(performanceCurve.getAllowancePerCourse(new KnotSpeedImpl(17.23))).getKnots(), accuracy);
|
||||
|
||||
/*
|
||||
assertEquals( 500, performanceCurve.getAllowancePerCourse(performanceCurve.getImpliedWindNewton(Duration.ONE_SECOND.times(500))).asSeconds(), accuracy);
|
||||
assertEquals( 600, performanceCurve.getAllowancePerCourse(performanceCurve.getImpliedWindNewton(Duration.ONE_SECOND.times(600))).asSeconds(), accuracy);
|
||||
assertEquals( 700, performanceCurve.getAllowancePerCourse(performanceCurve.getImpliedWindNewton(Duration.ONE_SECOND.times(700))).asSeconds(), accuracy);
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -13,9 +13,12 @@ import java.util.Map.Entry;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.math.ArgumentOutsideDomainException;
|
||||
import org.apache.commons.math.FunctionEvaluationException;
|
||||
import org.apache.commons.math.MaxIterationsExceededException;
|
||||
import org.apache.commons.math.analysis.interpolation.SplineInterpolator;
|
||||
import org.apache.commons.math.analysis.polynomials.PolynomialFunction;
|
||||
import org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm;
|
||||
import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
|
||||
import org.apache.commons.math.analysis.solvers.NewtonSolver;
|
||||
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.domain.common.impl.KnotSpeedImpl;
|
||||
@@ -204,6 +207,26 @@ public class ORCPerformanceCurveImpl implements Serializable, ORCPerformanceCurv
|
||||
return new KnotSpeedImpl(functionAllowanceToTwa.value(time.asSeconds()));
|
||||
}
|
||||
|
||||
public Speed getImpliedWindNewton(Duration time) throws MaxIterationsExceededException, FunctionEvaluationException {
|
||||
PolynomialFunction workingFunction;
|
||||
double[] allowances = new double[functionTwaToAllowance.getKnots().length];
|
||||
|
||||
for (int i = 0; i < allowances.length; i++) {
|
||||
allowances[i] = functionTwaToAllowance.value(functionTwaToAllowance.getKnots()[i]);
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while(i < allowances.length && time.asSeconds() <= allowances[i]) {
|
||||
i += 1;
|
||||
}
|
||||
i -= 1;
|
||||
workingFunction = functionTwaToAllowance.getPolynomials()[i-1];
|
||||
|
||||
NewtonSolver solver = new NewtonSolver(workingFunction.subtract(new PolynomialFunction(new double[] {time.asSeconds()})));
|
||||
solver.setAbsoluteAccuracy(0.000001);
|
||||
return new KnotSpeedImpl(solver.solve(functionTwaToAllowance.getKnots()[i], functionTwaToAllowance.getKnots()[i+1]));
|
||||
}
|
||||
|
||||
public Duration getAllowancePerCourse(Speed twa) throws ArgumentOutsideDomainException {
|
||||
return Duration.ONE_SECOND.times(functionTwaToAllowance.value(twa.getKnots()));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user