mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-06 19:12:23 +00:00
First functional test for Oscillation pattern, checks out with values from R script implementation.
This commit is contained in:
1 parent
906d6872ea
commit
80dc774380
2 files changed
+108
-23
No files matched your search
+104
-19
@@ -19,6 +19,7 @@ import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.DegreeBearingImpl;
|
||||
import com.sap.sailing.domain.common.impl.DegreePosition;
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
import com.sap.sailing.domain.tracking.Wind;
|
||||
import com.sap.sailing.simulator.WindControlParameters;
|
||||
import com.sap.sailing.simulator.impl.TimedPositionWithSpeedImpl;
|
||||
@@ -29,13 +30,14 @@ import com.sap.sailing.simulator.impl.WindFieldGeneratorOscillationImpl;
|
||||
|
||||
/**
|
||||
* Test for @WindFieldGenerator
|
||||
*
|
||||
* @author Nidhi Sawhney(D054070)
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class WindFieldGeneratorTest {
|
||||
|
||||
|
||||
private static Logger logger = Logger.getLogger("com.sap.sailing");
|
||||
|
||||
|
||||
@Test
|
||||
public void testWindFieldGeneratorBasic() {
|
||||
Position start = new DegreePosition(54.32447456461419, 10.15613079071045);
|
||||
@@ -43,16 +45,16 @@ public class WindFieldGeneratorTest {
|
||||
List<Position> course = new LinkedList<Position>();
|
||||
course.add(start);
|
||||
course.add(end);
|
||||
|
||||
|
||||
WindControlParameters windParameters = new WindControlParameters(3, 180);
|
||||
RectangularBoundary bd = new RectangularBoundary(start, end, 0.1);
|
||||
WindFieldGeneratorImpl wf = new WindFieldGeneratorBlastImpl(bd, windParameters);
|
||||
int hSteps = 10;
|
||||
int vSteps = 5;
|
||||
List<Position> positionList = bd.extractLattice(hSteps,vSteps);
|
||||
assert(positionList.size() == hSteps*vSteps);
|
||||
List<Position> positionList = bd.extractLattice(hSteps, vSteps);
|
||||
assert (positionList.size() == hSteps * vSteps);
|
||||
int index = 0;
|
||||
for(Position p : positionList) {
|
||||
for (Position p : positionList) {
|
||||
logger.info("P" + ++index + ":" + p);
|
||||
}
|
||||
wf.setPositionGrid(bd.extractGrid(hSteps, vSteps));
|
||||
@@ -62,12 +64,12 @@ public class WindFieldGeneratorTest {
|
||||
assertEquals("Position Grid Number of Columns", hSteps, positionGrid[0].length);
|
||||
for (int i = 0; i < vSteps; ++i) {
|
||||
for (int j = 0; j < hSteps; ++j) {
|
||||
logger.info("P["+i+"]["+j+"]:" + positionGrid[i][j]);
|
||||
assertEquals("Map index check",positionGrid[i][j],wf.getPosition(i, j));
|
||||
logger.info("P[" + i + "][" + j + "]:" + positionGrid[i][j]);
|
||||
assertEquals("Map index check", positionGrid[i][j], wf.getPosition(i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWindFieldGeneratorOscillation() {
|
||||
Position start = new DegreePosition(54.32447456461419, 10.15613079071045);
|
||||
@@ -75,29 +77,112 @@ public class WindFieldGeneratorTest {
|
||||
List<Position> course = new LinkedList<Position>();
|
||||
course.add(start);
|
||||
course.add(end);
|
||||
|
||||
|
||||
WindControlParameters windParameters = new WindControlParameters(10, 180);
|
||||
windParameters.leftWindSpeed = 70.0;
|
||||
windParameters.middleWindSpeed = 80.0;
|
||||
windParameters.rightWindSpeed = 90.0;
|
||||
windParameters.frequency = 0.375;
|
||||
windParameters.amplitude = 20.0;
|
||||
|
||||
RectangularBoundary bd = new RectangularBoundary(start, end, 0.1);
|
||||
WindFieldGeneratorOscillationImpl wf = new WindFieldGeneratorOscillationImpl(bd, windParameters);
|
||||
int hSteps = 30;
|
||||
int vSteps = 15;
|
||||
|
||||
|
||||
wf.setPositionGrid(bd.extractGrid(hSteps, vSteps));
|
||||
Position[][] positionGrid = wf.getPositionsGrid();
|
||||
TimePoint startTime = new MillisecondsTimePoint(0);
|
||||
TimePoint timeStep = new MillisecondsTimePoint(30*1000);
|
||||
wf.generate(startTime,null,timeStep);
|
||||
|
||||
TimePoint timeStep = new MillisecondsTimePoint(30 * 1000);
|
||||
wf.generate(startTime, null, timeStep);
|
||||
|
||||
SpeedWithBearing speed = new KilometersPerHourSpeedWithBearingImpl(0, new DegreeBearingImpl(0));
|
||||
|
||||
for (int i = 0; i < vSteps; ++i) {
|
||||
|
||||
/*
|
||||
* Check the speed & angle at the start time
|
||||
*/
|
||||
List<Wind> windList = new ArrayList<Wind>();
|
||||
for (int i = 0; i < vSteps; ++i) {
|
||||
for (int j = 0; j < hSteps; ++j) {
|
||||
Wind localWind = wf.getWind(new TimedPositionWithSpeedImpl(startTime,positionGrid[i][j],speed));
|
||||
logger.info("Wind["+i+"]["+j+"]" + localWind.toString());
|
||||
Wind localWind = wf.getWind(new TimedPositionWithSpeedImpl(startTime, positionGrid[i][j], speed));
|
||||
logger.info("Wind[" + i + "][" + j + "]" + localWind.toString());
|
||||
windList.add(localWind);
|
||||
}
|
||||
}
|
||||
assertEquals("Size of windList ", hSteps * vSteps, windList.size());
|
||||
double epsilon = 1e-6;
|
||||
// Check the speed
|
||||
assertEquals("StartTime First Wind Speed ", 7, windList.get(0).getKnots(), 0);
|
||||
assertEquals("StartTime Last Wind Speed in first row ", 9, windList.get(hSteps - 1).getKnots(), 0);
|
||||
|
||||
assertEquals("StartTime One before Middle Wind Speed ", 7.928571, windList.get(windList.size() / 2 - 2)
|
||||
.getKnots(), epsilon);
|
||||
assertEquals("StartTime Middle Wind Speed ", 8, windList.get(windList.size() / 2 - 1).getKnots(), 0);
|
||||
assertEquals("StartTime Last Wind Speed ", windList.get(windList.size() - 1).getKnots(), 9, 0);
|
||||
// Check the angle
|
||||
assertEquals("StartTime First Wind Angle ", 0, windList.get(0).getBearing().getRadians(), 0);
|
||||
Pair<Integer, Integer> pairIndex = getIndex(windList.size(), hSteps);
|
||||
logger.info(pairIndex.toString());
|
||||
assertEquals("StartTime One before Middle Wind Angle ", 0.3224948, windList.get(windList.size() / 2 - 2).getBearing()
|
||||
.getRadians(), epsilon);
|
||||
assertEquals("StartTime Middle Wind Angle ", 0.3224948, windList.get(windList.size() / 2 - 1).getBearing().getRadians(),
|
||||
epsilon);
|
||||
assertEquals("StartTime Last Wind Angle ", 0.2468268, windList.get(windList.size() - 1).getBearing().getRadians(), epsilon);
|
||||
|
||||
/**
|
||||
* Check the speed at the next time
|
||||
*/
|
||||
/*
|
||||
* Check the speed & angle at the next time point
|
||||
*/
|
||||
windList.clear();
|
||||
for (int i = 0; i < vSteps; ++i) {
|
||||
for (int j = 0; j < hSteps; ++j) {
|
||||
Wind localWind = wf.getWind(new TimedPositionWithSpeedImpl(new MillisecondsTimePoint(startTime
|
||||
.asMillis() + timeStep.asMillis()), positionGrid[i][j], speed));
|
||||
logger.info("Wind[" + i + "][" + j + "]" + localWind.toString());
|
||||
windList.add(localWind);
|
||||
}
|
||||
}
|
||||
assertEquals("Size of windList ", hSteps * vSteps, windList.size());
|
||||
|
||||
// Check the speed
|
||||
assertEquals("One Time Unit First Wind Speed ", windList.get(0).getKnots(), 7, 0);
|
||||
assertEquals("One Time Unit One before Middle Wind Speed ", windList.get(windList.size() / 2 - 2).getKnots(),
|
||||
7.928571, epsilon);
|
||||
assertEquals("One Time Unit Middle Wind Speed ", windList.get(windList.size() / 2 - 1).getKnots(), 8, 0);
|
||||
assertEquals("One Time Unit Last Wind Speed ", windList.get(windList.size() - 1).getKnots(), 9, 0);
|
||||
// Check the angle
|
||||
assertEquals("One Time Unit First Wind Angle ",0.2019944, windList.get(0).getBearing().getRadians(), epsilon);
|
||||
assertEquals("One Time Unit One before Middle Wind Speed ", -0.1857142, windList.get(windList.size() / 2 - 2).getBearing()
|
||||
.getRadians(), epsilon);
|
||||
assertEquals("One Time Unit Middle Wind Speed ",-0.1857142, windList.get(windList.size() / 2 - 1).getBearing()
|
||||
.getRadians(), epsilon);
|
||||
assertEquals("One Time Unit Last Wind Speed ", -0.3441339, windList.get(windList.size() - 1).getBearing().getRadians(),
|
||||
epsilon);
|
||||
|
||||
}
|
||||
|
||||
private Pair<Integer, Integer> getIndex(int listIndex, int numCols) {
|
||||
Pair<Integer, Integer> indexPair = new Pair<Integer, Integer>(1 + (listIndex - 1) / numCols, 1
|
||||
+ (listIndex - 1) % numCols);
|
||||
return indexPair;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndex() {
|
||||
Pair<Integer, Integer> pairIndex = getIndex(1, 30);
|
||||
assertEquals("Index 1 RowIndex ", 1, (int) pairIndex.getA());
|
||||
assertEquals("Index 1 ColIndex ", 1, (int) pairIndex.getB());
|
||||
pairIndex = getIndex(30, 30);
|
||||
assertEquals("Index 30 RowIndex ", 1, (int) pairIndex.getA());
|
||||
assertEquals("Index 30 ColIndex ", 30, (int) pairIndex.getB());
|
||||
pairIndex = getIndex(31, 30);
|
||||
assertEquals("Index 31 RowIndex ", 2, (int) pairIndex.getA());
|
||||
assertEquals("Index 31 ColIndex ", 1, (int) pairIndex.getB());
|
||||
pairIndex = getIndex(450, 30);
|
||||
assertEquals("Index 450 RowIndex ", 15, (int) pairIndex.getA());
|
||||
assertEquals("Index 450 ColIndex ", 30, (int) pairIndex.getB());
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
package com.sap.sailing.simulator.impl;
|
||||
|
||||
import com.sap.sailing.domain.base.SpeedWithBearing;
|
||||
import com.sap.sailing.domain.base.impl.KilometersPerHourSpeedWithBearingImpl;
|
||||
import com.sap.sailing.domain.base.impl.KnotSpeedImpl;
|
||||
import com.sap.sailing.domain.base.impl.KnotSpeedWithBearingImpl;
|
||||
import com.sap.sailing.domain.common.Bearing;
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.domain.common.Speed;
|
||||
@@ -19,7 +19,7 @@ import com.sap.sailing.simulator.impl.WindFieldGeneratorImpl;
|
||||
|
||||
public class WindFieldGeneratorOscillationImpl extends WindFieldGeneratorImpl implements WindFieldGenerator {
|
||||
|
||||
/* Currectly the speed is time and vertical step invariant, it only changes along the horizontal
|
||||
/* Currently the speed is time and vertical step invariant, it only changes along the horizontal
|
||||
* direction*/
|
||||
private Speed[] speed;
|
||||
|
||||
@@ -77,7 +77,6 @@ public class WindFieldGeneratorOscillationImpl extends WindFieldGeneratorImpl im
|
||||
Bearing phi0 = new DegreeBearingImpl(windParameters.baseWindBearing);
|
||||
phi0 = phi0.reverse();
|
||||
double vStep = 1.0/(positions.length-1);
|
||||
logger.info("Nrows:"+ positions.length + " vstep:"+vStep);
|
||||
double t = (timeIndex+(timeIndex+rowIndex)*vStep);
|
||||
Bearing angle = new DegreeBearingImpl(Math.sin(2*Math.PI*t*windParameters.frequency)*windParameters.amplitude);
|
||||
angle.add(phi0);
|
||||
@@ -92,7 +91,8 @@ public class WindFieldGeneratorOscillationImpl extends WindFieldGeneratorImpl im
|
||||
@Override
|
||||
public Wind getWind(TimedPosition timedPosition) {
|
||||
|
||||
SpeedWithBearing wspeed = new KilometersPerHourSpeedWithBearingImpl(getSpeed(timedPosition).getKilometersPerHour(),
|
||||
Speed speed = getSpeed(timedPosition);
|
||||
SpeedWithBearing wspeed = new KnotSpeedWithBearingImpl(speed.getKnots(),
|
||||
getBearing(timedPosition));
|
||||
|
||||
return new WindImpl(timedPosition.getPosition(), timedPosition.getTimePoint(), wspeed);
|
||||
|
||||
Reference in new issue
Block a user