Skip to content

Commit

Permalink
attenuation cnossos test ok, fix pk and index
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Dec 13, 2024
1 parent acd21c9 commit ab7ef91
Show file tree
Hide file tree
Showing 40 changed files with 273 additions and 1,677 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ public NoiseMap(AttenuationCnossosParameters dayPathData, AttenuationCnossosPara
this.noiseMapParameters = noiseMapParameters;
}

/*public LdenData getLdenData() {
return ldenData;
}*/

/**
*
* @return an instance of the interface IComputePathsOut
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public NoiseMapInStack(NoiseMap multiThreadParent) {
* @param receiverAttenuationLevels
* @return
*/
double[] sumLevels(List<double[]> wjSources,List<Attenuation.SourceReceiverAttenuation> receiverAttenuationLevels) {
double[] sumLevels(List<double[]> wjSources, List<Attenuation.SourceReceiverAttenuation> receiverAttenuationLevels) {
double[] levels = new double[noiseMapComputeRaysOut.dayPathData.freq_lvl.size()];
for (Attenuation.SourceReceiverAttenuation lvl : receiverAttenuationLevels) {
if(wjSources.size() > lvl.sourceId && lvl.sourceId >= 0) {
if(wjSources.size() > lvl.sourceIndex && lvl.sourceIndex >= 0) {
levels = sumArray(levels,
dbaToW(sumArray(wToDba(wjSources.get((int) lvl.sourceId)), lvl.value)));
dbaToW(sumArray(wToDba(wjSources.get(lvl.sourceIndex)), lvl.value)));
}
}
return levels;
Expand All @@ -69,17 +69,18 @@ public NoiseMapInStack(NoiseMap multiThreadParent) {

/**
* Processes the attenuation levels for a receiver and pushes the result into a concurrent linked deque.
* @param receiverIndex the index of the receiver in memory list
* @param receiverPK the primary key of the receiver.
* @param wjSources the list of source attenuation levels.
* @param receiverAttenuationLevels the list of attenuation levels from receiver to sources.
* @param result the concurrent linked deque to push the result into.
* @param feedStack {@code true} if the result should be pushed into the result stack, {@code false} otherwise.
* @return the computed attenuation levels for the receiver.
*/
double[] processAndPushResult(long receiverPK, List<double[]> wjSources, List<Attenuation.SourceReceiverAttenuation> receiverAttenuationLevels, ConcurrentLinkedDeque<Attenuation.SourceReceiverAttenuation> result, boolean feedStack) {
double[] processAndPushResult(int receiverIndex, long receiverPK, List<double[]> wjSources, List<Attenuation.SourceReceiverAttenuation> receiverAttenuationLevels, ConcurrentLinkedDeque<Attenuation.SourceReceiverAttenuation> result, boolean feedStack) {
double[] levels = sumLevels(wjSources, receiverAttenuationLevels);
if(feedStack) {
pushInStack(result, new Attenuation.SourceReceiverAttenuation(receiverPK, -1, wToDba(levels)));
pushInStack(result, new Attenuation.SourceReceiverAttenuation(receiverPK, receiverIndex,-1, -1, wToDba(levels)));
}
return levels;
}
Expand Down Expand Up @@ -254,16 +255,16 @@ public void finalizeReceiver(int receiverId) {
double[] dayLevels = new double[0], eveningLevels = new double[0], nightLevels = new double[0];
if (!noiseMapParameters.mergeSources) {
// Aggregate by source id
Map<Long, NoiseMapParameters.TimePeriodParameters> levelsPerSourceLines = new HashMap<>();
Map<Integer, NoiseMapParameters.TimePeriodParameters> levelsPerSourceLines = new HashMap<>();
for (NoiseMapParameters.TIME_PERIOD timePeriod : org.noise_planet.noisemodelling.jdbc.NoiseMapParameters.TIME_PERIOD.values()) {
AttenuationVisitor attenuationVisitor = lDENAttenuationVisitor[timePeriod.ordinal()];
for (Attenuation.SourceReceiverAttenuation lvl : attenuationVisitor.receiverAttenuationLevels) {
NoiseMapParameters.TimePeriodParameters timePeriodParameters;
if (!levelsPerSourceLines.containsKey(lvl.sourceId)) {
if (!levelsPerSourceLines.containsKey(lvl.sourceIndex)) {
timePeriodParameters = new NoiseMapParameters.TimePeriodParameters();
levelsPerSourceLines.put(lvl.sourceId, timePeriodParameters);
levelsPerSourceLines.put(lvl.sourceIndex, timePeriodParameters);
} else {
timePeriodParameters = levelsPerSourceLines.get(lvl.sourceId);
timePeriodParameters = levelsPerSourceLines.get(lvl.sourceIndex);
}
if (timePeriodParameters.getTimePeriodLevel(timePeriod) == null) {
timePeriodParameters.setTimePeriodLevel(timePeriod, lvl.value);
Expand All @@ -275,8 +276,8 @@ public void finalizeReceiver(int receiverId) {
}
}
long sourcePK;
for (Map.Entry<Long, NoiseMapParameters.TimePeriodParameters> entry : levelsPerSourceLines.entrySet()) {
final long sourceId = entry.getKey();
for (Map.Entry<Integer, NoiseMapParameters.TimePeriodParameters> entry : levelsPerSourceLines.entrySet()) {
final int sourceId = entry.getKey();
sourcePK = sourceId;
if (noiseMapComputeRaysOut.inputData != null) {
// Retrieve original source identifier
Expand All @@ -287,19 +288,19 @@ public void finalizeReceiver(int receiverId) {
if (noiseMapParameters.computeLDay || noiseMapParameters.computeLDEN) {
dayLevels = sumArray(wToDba(noiseMapComputeRaysOut.noiseEmissionMaker.wjSourcesD.get((int) sourceId)), entry.getValue().dayLevels);
if(noiseMapParameters.computeLDay) {
pushInStack(noiseMapComputeRaysOut.attenuatedPaths.lDayLevels, new Attenuation.SourceReceiverAttenuation(receiverPK, sourcePK, dayLevels));
pushInStack(noiseMapComputeRaysOut.attenuatedPaths.lDayLevels, new Attenuation.SourceReceiverAttenuation(receiverPK,receiverId, sourcePK, sourceId, dayLevels));
}
}
if (noiseMapParameters.computeLEvening || noiseMapParameters.computeLDEN) {
eveningLevels = sumArray(wToDba(noiseMapComputeRaysOut.noiseEmissionMaker.wjSourcesE.get((int) sourceId)), entry.getValue().eveningLevels);
if(noiseMapParameters.computeLEvening) {
pushInStack(noiseMapComputeRaysOut.attenuatedPaths.lEveningLevels, new Attenuation.SourceReceiverAttenuation(receiverPK, sourcePK, eveningLevels));
pushInStack(noiseMapComputeRaysOut.attenuatedPaths.lEveningLevels, new Attenuation.SourceReceiverAttenuation(receiverPK,receiverId, sourcePK, sourceId, eveningLevels));
}
}
if (noiseMapParameters.computeLNight || noiseMapParameters.computeLDEN) {
nightLevels = sumArray(wToDba(noiseMapComputeRaysOut.noiseEmissionMaker.wjSourcesN.get((int) sourceId)), entry.getValue().nightLevels);
if(noiseMapParameters.computeLNight) {
pushInStack(noiseMapComputeRaysOut.attenuatedPaths.lNightLevels, new Attenuation.SourceReceiverAttenuation(receiverPK, sourcePK, nightLevels));
pushInStack(noiseMapComputeRaysOut.attenuatedPaths.lNightLevels, new Attenuation.SourceReceiverAttenuation(receiverPK,receiverId, sourcePK, sourceId, nightLevels));
}
}
if (noiseMapParameters.computeLDEN) {
Expand All @@ -309,25 +310,25 @@ public void finalizeReceiver(int receiverId) {
4 * dbaToW(wToDba(eveningLevels[idFrequency]) + 5) +
8 * dbaToW(wToDba(nightLevels[idFrequency]) + 10)) / 24.0;
}
pushInStack(noiseMapComputeRaysOut.attenuatedPaths.lDenLevels, new Attenuation.SourceReceiverAttenuation(receiverPK, sourcePK, levels));
pushInStack(noiseMapComputeRaysOut.attenuatedPaths.lDenLevels, new Attenuation.SourceReceiverAttenuation(receiverPK,receiverId, sourcePK, sourceId, levels));
}
}
} else {
// Merge all results
if (noiseMapParameters.computeLDay || noiseMapParameters.computeLDEN) {
dayLevels = processAndPushResult(receiverPK,
dayLevels = processAndPushResult(receiverId ,receiverPK,
noiseMapComputeRaysOut.noiseEmissionMaker.wjSourcesD,
lDENAttenuationVisitor[0].receiverAttenuationLevels, noiseMapComputeRaysOut.attenuatedPaths.lDayLevels,
noiseMapParameters.computeLDay);
}
if (noiseMapParameters.computeLEvening || noiseMapParameters.computeLDEN) {
eveningLevels = processAndPushResult(receiverPK,
eveningLevels = processAndPushResult(receiverId ,receiverPK,
noiseMapComputeRaysOut.noiseEmissionMaker.wjSourcesE,
lDENAttenuationVisitor[1].receiverAttenuationLevels, noiseMapComputeRaysOut.attenuatedPaths.lEveningLevels,
noiseMapParameters.computeLEvening);
}
if (noiseMapParameters.computeLNight || noiseMapParameters.computeLDEN) {
nightLevels = processAndPushResult(receiverPK,
nightLevels = processAndPushResult(receiverId ,receiverPK,
noiseMapComputeRaysOut.noiseEmissionMaker.wjSourcesN,
lDENAttenuationVisitor[2].receiverAttenuationLevels, noiseMapComputeRaysOut.attenuatedPaths.lNightLevels,
noiseMapParameters.computeLNight);
Expand All @@ -339,7 +340,8 @@ public void finalizeReceiver(int receiverId) {
4 * dbaToW(wToDba(eveningLevels[idFrequency]) + 5) +
8 * dbaToW(wToDba(nightLevels[idFrequency]) + 10)) / 24.0;
}
pushInStack(noiseMapComputeRaysOut.attenuatedPaths.lDenLevels, new Attenuation.SourceReceiverAttenuation(receiverPK, -1, wToDba(levels)));
pushInStack(noiseMapComputeRaysOut.attenuatedPaths.lDenLevels,
new Attenuation.SourceReceiverAttenuation(receiverPK, receiverId,-1, -1, wToDba(levels)));
}
}
for (AttenuationVisitor attenuationVisitor : lDENAttenuationVisitor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public int getMaximumRaysOutputCount() {
}
int outputMaximumQueue = 50000;

static boolean mergeSources = true;
public boolean mergeSources = true;

String lDayTable = "LDAY_RESULT";
String lEveningTable = "LEVENING_RESULT";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void processStack(String tableName, ConcurrentLinkedDeque<Attenuation.SourceRece
AttenuatedPaths.queueSize.decrementAndGet();
int parameterIndex = 1;
ps.setLong(parameterIndex++, row.receiverId);
if(!NoiseMapParameters.mergeSources) {
if(!noiseMapParameters.mergeSources) {
ps.setLong(parameterIndex++, row.sourceId);
}

Expand Down Expand Up @@ -206,7 +206,7 @@ void processStack(String tableName, ConcurrentLinkedDeque<Attenuation.SourceRece
private String forgeCreateTable(String tableName) {
StringBuilder sb = new StringBuilder("create table ");
sb.append(tableName);
if(!NoiseMapParameters.mergeSources) {
if(!noiseMapParameters.mergeSources) {
sb.append(" (IDRECEIVER bigint NOT NULL");
sb.append(", IDSOURCE bigint NOT NULL");
} else {
Expand All @@ -232,7 +232,7 @@ private String forgeCreateTable(String tableName) {
* @param tableName
* @return the SQL statement for creating the primary key or index */
private String forgePkTable(String tableName) {
if (NoiseMapParameters.mergeSources) {
if (noiseMapParameters.mergeSources) {
return "ALTER TABLE " + tableName + " ADD PRIMARY KEY(IDRECEIVER);";
} else {
return "CREATE INDEX ON " + tableName + " (IDRECEIVER);";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,8 @@ public void testPointDirectivity() throws Exception {
}

public static void assertOrientationEquals(Orientation orientationA, Orientation orientationB, double epsilon) {
assertEquals(orientationA.pitch, orientationB.pitch, epsilon);
assertEquals(orientationA.roll, orientationB.roll, epsilon);
assertEquals(orientationA.yaw, orientationB.yaw, epsilon);
assertArrayEquals(new double[]{orientationA.yaw, orientationA.pitch, orientationA.roll},
new double[]{orientationB.yaw, orientationB.pitch, orientationB.roll}, epsilon, orientationA+" != "+orientationB);
}


Expand All @@ -291,8 +290,8 @@ public void testLineDirectivity() throws Exception {
new Coordinate(223920.72,6757485.22, 5.1 )}), 91,
new Orientation(0,0,0),4));
st.execute("create table receivers(id serial PRIMARY KEY, the_geom GEOMETRY(pointZ));\n" +
"insert into receivers(the_geom) values ('POINTZ (223922.55 6757495.27 0.0)');" +
"insert into receivers(the_geom) values ('POINTZ (223936.42 6757471.91 0.0)');");
"insert into receivers(the_geom) values ('POINTZ (223922.55 6757495.27 4.0)');" +
"insert into receivers(the_geom) values ('POINTZ (223936.42 6757471.91 4.0)');");
NoiseMapByReceiverMaker noiseMapByReceiverMaker = new NoiseMapByReceiverMaker("BUILDINGS", "ROADS_GEOM", "RECEIVERS");
noiseMapByReceiverMaker.setComputeHorizontalDiffraction(false);
noiseMapByReceiverMaker.setComputeVerticalDiffraction(false);
Expand Down Expand Up @@ -348,14 +347,14 @@ public void testLineDirectivity() throws Exception {
assertEquals(0, new Coordinate(0, 5.07).distance(pathParameters.getPointList().get(0).coordinate), 0.1);
// This is source orientation, not relevant to receiver position
assertOrientationEquals(new Orientation(45, 0.81, 0), pathParameters.getSourceOrientation(), 0.01);
assertOrientationEquals(new Orientation(330.07, -24.12, 0.0), pathParameters.raySourceReceiverDirectivity, 0.01);
assertOrientationEquals(new Orientation(336.9922375343167,-4.684918495003125,0.0), pathParameters.raySourceReceiverDirectivity, 0.01);

pathParameters = pathsParameters.remove(0);;
assertEquals(1, pathParameters.getIdReceiver());
assertEquals(0, new Coordinate(0, 5.02).
distance(pathParameters.getPointList().get(0).coordinate), 0.1);
assertOrientationEquals(new Orientation(45, 0.81, 0), pathParameters.getSourceOrientation(), 0.01);
assertOrientationEquals(new Orientation(336.90675972385696, -19.398969693698437, 0), pathParameters.raySourceReceiverDirectivity, 0.01);
assertOrientationEquals(new Orientation(330.2084079818916,-5.947213381005439,0.0), pathParameters.raySourceReceiverDirectivity, 0.01);
pathParameters = pathsParameters.remove(0);
assertEquals(2, pathParameters.getIdReceiver());
assertOrientationEquals(new Orientation(45, 0.81, 0), pathParameters.getSourceOrientation(), 0.01);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,12 @@ public CutProfile computeVEdgeDiffraction(ReceiverPointInfo rcv, SourcePointInfo
mainProfile.insertCutPoint(false,
cutPoints.subList(1, cutPoints.size() - 1).toArray(CutPoint[]::new));


mainProfile.getReceiver().id = rcv.receiverIndex;
if(rcv.receiverIndex >= 0 && rcv.receiverIndex < data.receiversPk.size()) {
mainProfile.getReceiver().id = rcv.receiverIndex;
mainProfile.getReceiver().receiverPk = data.receiversPk.get(rcv.receiverIndex);
}
mainProfile.getSource().id = src.sourceIndex;
if(src.sourceIndex >= 0 && src.sourceIndex < data.sourcesPk.size()) {
mainProfile.getSource().id = src.sourceIndex;
mainProfile.getSource().sourcePk = data.sourcesPk.get(src.sourceIndex);
}

Expand Down Expand Up @@ -733,12 +732,12 @@ public IComputePathsOut.PathSearchStrategy computeReflexion(ReceiverPointInfo rc
mainProfile.insertCutPoint(false, mainProfileCutPoints.subList(1,
mainProfileCutPoints.size() - 1).toArray(CutPoint[]::new));

mainProfile.getReceiver().id = rcv.receiverIndex;
if(rcv.receiverIndex >= 0 && rcv.receiverIndex < data.receiversPk.size()) {
mainProfile.getReceiver().id = rcv.receiverIndex;
mainProfile.getReceiver().receiverPk = data.receiversPk.get(rcv.receiverIndex);
}
mainProfile.getSource().id = src.sourceIndex;
if(src.sourceIndex >= 0 && src.sourceIndex < data.sourcesPk.size()) {
mainProfile.getSource().id = src.sourceIndex;
mainProfile.getSource().sourcePk = data.sourcesPk.get(src.sourceIndex);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ public Orientation(double yaw, double pitch, double roll) {

@Override
public String toString() {
return "Orientation{" +
"yaw=" + yaw +
", pitch=" + pitch +
", roll=" + roll +
'}';
return "Orientation("+yaw+","+pitch+","+roll+")";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,6 @@
},
"zGround" : 0.0,
"groundCoefficient" : 0.2
}, {
"type" : "Wall",
"coordinate" : {
"x" : 176.57888256132614,
"y" : 45.06923843396339,
"z" : 0.0
},
"zGround" : 0.0,
"groundCoefficient" : 0.2,
"wall" : {
"p0" : {
"x" : 100.0,
"y" : 240.0,
"z" : 6.0
},
"p1" : {
"x" : 265.0,
"y" : -180.0,
"z" : 6.0
}
},
"wallAlpha" : [ ]
}, {
"type" : "Wall",
"coordinate" : {
Expand All @@ -76,29 +54,8 @@
"z" : 6.0
}
},
"wallAlpha" : [ ]
}, {
"type" : "Wall",
"coordinate" : {
"x" : 176.5808396608961,
"y" : 45.069650454925494,
"z" : 0.0
},
"zGround" : 0.0,
"groundCoefficient" : 0.2,
"wall" : {
"p0" : {
"x" : 100.0,
"y" : 240.0,
"z" : 6.0
},
"p1" : {
"x" : 265.0,
"y" : -180.0,
"z" : 6.0
}
},
"wallAlpha" : [ ]
"wallAlpha" : [ ],
"intersectionType" : "THIN_WALL_ENTER_EXIT"
}, {
"type" : "Receiver",
"coordinate" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,6 @@
},
"zGround" : 0.0,
"groundCoefficient" : 0.2
}, {
"type" : "Wall",
"coordinate" : {
"x" : 176.82828974289797,
"y" : 45.12174520903115,
"z" : 0.0
},
"zGround" : 0.0,
"groundCoefficient" : 0.2,
"wall" : {
"p0" : {
"x" : 175.0,
"y" : 50.0,
"z" : 6.0
},
"p1" : {
"x" : 190.0,
"y" : 10.0,
"z" : 6.0
}
},
"wallAlpha" : [ ]
}, {
"type" : "Wall",
"coordinate" : {
Expand All @@ -76,29 +54,8 @@
"z" : 6.0
}
},
"wallAlpha" : [ ]
}, {
"type" : "Wall",
"coordinate" : {
"x" : 176.83024684246791,
"y" : 45.12215722999325,
"z" : 0.0
},
"zGround" : 0.0,
"groundCoefficient" : 0.2,
"wall" : {
"p0" : {
"x" : 175.0,
"y" : 50.0,
"z" : 6.0
},
"p1" : {
"x" : 190.0,
"y" : 10.0,
"z" : 6.0
}
},
"wallAlpha" : [ ]
"wallAlpha" : [ ],
"intersectionType" : "THIN_WALL_ENTER_EXIT"
}, {
"type" : "Receiver",
"coordinate" : {
Expand Down
Loading

0 comments on commit ab7ef91

Please sign in to comment.