mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-17 01:31:01 +00:00
First cut at the Oscillation pattern, WIP.
This commit is contained in:
1 parent
254f7cd5f4
commit
e031fe5def
4 files changed
+174
-8
No files matched your search
+9
-3
@@ -6,9 +6,11 @@ import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.Bearing;
|
||||
import com.sap.sailing.domain.common.Distance;
|
||||
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.NauticalMileDistance;
|
||||
@@ -40,6 +42,7 @@ import com.sap.sailing.simulator.impl.PolarDiagramImpl;
|
||||
import com.sap.sailing.simulator.impl.RectangularBoundary;
|
||||
import com.sap.sailing.simulator.impl.SailingSimulatorImpl;
|
||||
import com.sap.sailing.simulator.impl.SimulationParametersImpl;
|
||||
import com.sap.sailing.simulator.impl.TimedPositionWithSpeedImpl;
|
||||
import com.sap.sailing.simulator.impl.TimedPositionWithSpeedSimple;
|
||||
|
||||
public class SimulatorServiceImpl extends RemoteServiceServlet implements SimulatorService {
|
||||
@@ -175,13 +178,16 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
|
||||
WindFieldGenerator wf = WindFieldGeneratorFactory.INSTANCE.createWindFieldGenerator(pattern.getWindPattern()
|
||||
.name(), bd, controlParameters);
|
||||
|
||||
List<Position> lattice =bd.extractLattice(params.getxRes(),params.getyRes());//wf.extractLattice(params.getxRes(), params.getyRes());
|
||||
|
||||
List<Position> lattice = bd.extractLattice(params.getxRes(),params.getyRes());//wf.extractLattice(params.getxRes(), params.getyRes());
|
||||
wf.setPositionGrid(bd.extractGrid(params.getxRes(), params.getyRes()));
|
||||
TimePoint start = new MillisecondsTimePoint(0);
|
||||
TimePoint timeStep = new MillisecondsTimePoint(30*1000);
|
||||
wf.generate(start,null,timeStep);
|
||||
List<WindDTO> wList = new ArrayList<WindDTO>();
|
||||
|
||||
if (lattice != null) {
|
||||
for (Position p : lattice) {
|
||||
Wind localWind = wf.getWind(new TimedPositionWithSpeedSimple(p));
|
||||
Wind localWind = wf.getWind(new TimedPositionWithSpeedImpl(start,p,null));
|
||||
logger.fine(localWind.toString());
|
||||
WindDTO w = createWindDTO(localWind);
|
||||
wList.add(w);
|
||||
|
||||
+44
-1
@@ -5,17 +5,27 @@ package com.sap.sailing.simulator.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sailing.domain.base.SpeedWithBearing;
|
||||
import com.sap.sailing.domain.base.impl.KilometersPerHourSpeedWithBearingImpl;
|
||||
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
|
||||
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.tracking.Wind;
|
||||
import com.sap.sailing.simulator.WindControlParameters;
|
||||
import com.sap.sailing.simulator.impl.TimedPositionWithSpeedImpl;
|
||||
import com.sap.sailing.simulator.impl.WindFieldGeneratorBlastImpl;
|
||||
import com.sap.sailing.simulator.impl.RectangularBoundary;
|
||||
import com.sap.sailing.simulator.impl.WindFieldGeneratorImpl;
|
||||
import com.sap.sailing.simulator.impl.WindFieldGeneratorOscillationImpl;
|
||||
|
||||
/**
|
||||
* Test for @WindFieldGenerator
|
||||
@@ -36,7 +46,7 @@ public class WindFieldGeneratorTest {
|
||||
|
||||
WindControlParameters windParameters = new WindControlParameters(3, 180);
|
||||
RectangularBoundary bd = new RectangularBoundary(start, end, 0.1);
|
||||
WindFieldGeneratorBlastImpl wf = new WindFieldGeneratorBlastImpl(bd, windParameters);
|
||||
WindFieldGeneratorImpl wf = new WindFieldGeneratorBlastImpl(bd, windParameters);
|
||||
int hSteps = 10;
|
||||
int vSteps = 5;
|
||||
List<Position> positionList = bd.extractLattice(hSteps,vSteps);
|
||||
@@ -57,4 +67,37 @@ public class WindFieldGeneratorTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWindFieldGeneratorOscillation() {
|
||||
Position start = new DegreePosition(54.32447456461419, 10.15613079071045);
|
||||
Position end = new DegreePosition(54.32877915239163, 10.156173706054688);
|
||||
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;
|
||||
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);
|
||||
|
||||
SpeedWithBearing speed = new KilometersPerHourSpeedWithBearingImpl(0, new DegreeBearingImpl(0));
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+39
-2
@@ -25,13 +25,24 @@ public abstract class WindFieldGeneratorImpl implements WindFieldGenerator {
|
||||
|
||||
protected Boundary boundary;
|
||||
protected WindControlParameters windParameters;
|
||||
|
||||
protected List<Position> sortedPositionList;
|
||||
|
||||
protected Position[][] positions;
|
||||
protected Map<Pair<Integer, Integer>, Position> indexPositionMap;
|
||||
protected Map<Position,Pair<Integer, Integer>> positionIndexMap;
|
||||
|
||||
protected Map<TimePoint, SpeedWithBearing[][]> timeSpeedWithBearingMap;
|
||||
|
||||
protected TimePoint startTime;
|
||||
protected TimePoint endTime;
|
||||
/**
|
||||
* TimePoint which constitutes one unit of time
|
||||
*/
|
||||
protected TimePoint timeStep;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static Logger logger = Logger.getLogger("com.sap.sailing");
|
||||
protected static Logger logger = Logger.getLogger("com.sap.sailing");
|
||||
|
||||
private class LatLngComparator implements Comparator<Position> {
|
||||
|
||||
@@ -60,6 +71,7 @@ public abstract class WindFieldGeneratorImpl implements WindFieldGenerator {
|
||||
this.windParameters = windParameters;
|
||||
this.positions = null;
|
||||
this.indexPositionMap = new HashMap<Pair<Integer, Integer>, Position>();
|
||||
this.positionIndexMap = new HashMap<Position, Pair<Integer, Integer>>();
|
||||
}
|
||||
|
||||
private List<Position> extractLattice(int hPoints, int vPoints) {
|
||||
@@ -114,12 +126,15 @@ public abstract class WindFieldGeneratorImpl implements WindFieldGenerator {
|
||||
public void setPositionGrid(Position[][] positions) {
|
||||
this.positions = positions;
|
||||
indexPositionMap.clear();
|
||||
positionIndexMap.clear();
|
||||
if (positions == null || positions.length < 1) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < positions.length; ++i) {
|
||||
for (int j = 0; j < positions[0].length; ++j) {
|
||||
indexPositionMap.put(new Pair<Integer, Integer>(i, j), positions[i][j]);
|
||||
Pair<Integer,Integer> index = new Pair<Integer, Integer>(i, j);
|
||||
indexPositionMap.put(index, positions[i][j]);
|
||||
positionIndexMap.put(positions[i][j],index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,4 +145,26 @@ public abstract class WindFieldGeneratorImpl implements WindFieldGenerator {
|
||||
return indexPositionMap.get(indexKey);
|
||||
|
||||
}
|
||||
|
||||
public Pair<Integer,Integer> getPositionIndex(Position p) {
|
||||
return positionIndexMap.get(p);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param t
|
||||
* @return time units relative to the startTime where each unit is timeStep long
|
||||
*/
|
||||
public int getTimeIndex(TimePoint t) {
|
||||
return (int) ((t.asMillis()-startTime.asMillis())/timeStep.asMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(TimePoint start, TimePoint end, TimePoint step) {
|
||||
this.startTime = start;
|
||||
this.endTime = end;
|
||||
this.timeStep = step;
|
||||
}
|
||||
|
||||
}
|
||||
+82
-2
@@ -1,21 +1,101 @@
|
||||
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.common.Bearing;
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.domain.common.Speed;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.DegreeBearingImpl;
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
import com.sap.sailing.domain.tracking.Wind;
|
||||
import com.sap.sailing.domain.tracking.impl.WindImpl;
|
||||
import com.sap.sailing.simulator.Boundary;
|
||||
import com.sap.sailing.simulator.TimedPosition;
|
||||
import com.sap.sailing.simulator.WindControlParameters;
|
||||
import com.sap.sailing.simulator.WindFieldGenerator;
|
||||
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
|
||||
* direction*/
|
||||
private Speed[] speed;
|
||||
|
||||
public WindFieldGeneratorOscillationImpl(Boundary boundary, WindControlParameters windParameters) {
|
||||
super(boundary, windParameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(TimePoint start, TimePoint end, TimePoint step) {
|
||||
// TODO Auto-generated method stub
|
||||
super.generate(start,end,step);
|
||||
initializeSpeed();
|
||||
}
|
||||
|
||||
private void initializeSpeed() {
|
||||
if (positions == null || positions.length < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
int ncol = positions[0].length;
|
||||
|
||||
speed = new Speed[ncol];
|
||||
double leftSpeed = windParameters.baseWindSpeed*windParameters.leftWindSpeed/100.0;
|
||||
double middleSpeed = windParameters.baseWindSpeed*windParameters.middleWindSpeed/100.0;
|
||||
double rightSpeed = windParameters.baseWindSpeed*windParameters.rightWindSpeed/100.0;
|
||||
int midPoint = ncol/2;
|
||||
for (int i = 0; i < midPoint; ++i) {
|
||||
speed[i] = new KnotSpeedImpl(leftSpeed + i*(middleSpeed-leftSpeed)/(midPoint-1));
|
||||
}
|
||||
for (int i = 1; i <= ncol - midPoint; ++i) {
|
||||
speed[midPoint -1 + i] = new KnotSpeedImpl(middleSpeed + i*(rightSpeed-middleSpeed)/(ncol - midPoint));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Speed getSpeed(TimedPosition timedPosition) {
|
||||
Position p = timedPosition.getPosition();
|
||||
Pair<Integer,Integer> positionIndex = getPositionIndex(p);
|
||||
if (positionIndex != null) {
|
||||
int colIndex = positionIndex.getB();
|
||||
return speed[colIndex];
|
||||
} else {
|
||||
logger.severe("Error finding position " + p);
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private Bearing getBearing(TimedPosition timedPosition) {
|
||||
Position p = timedPosition.getPosition();
|
||||
Pair<Integer,Integer> positionIndex = getPositionIndex(p);
|
||||
if (positionIndex != null) {
|
||||
int rowIndex = positionIndex.getA();
|
||||
TimePoint timePoint = timedPosition.getTimePoint();
|
||||
int timeIndex = getTimeIndex(timePoint);
|
||||
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);
|
||||
|
||||
return angle;
|
||||
} else {
|
||||
logger.severe("Error finding position " + p);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Wind getWind(TimedPosition timedPosition) {
|
||||
|
||||
SpeedWithBearing wspeed = new KilometersPerHourSpeedWithBearingImpl(getSpeed(timedPosition).getKilometersPerHour(),
|
||||
getBearing(timedPosition));
|
||||
|
||||
return new WindImpl(timedPosition.getPosition(), timedPosition.getTimePoint(), wspeed);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user