Skip to content

Commit

Permalink
Merge pull request #3643 from moia-oss/noiseMaintencance
Browse files Browse the repository at this point in the history
Noise maintencance
  • Loading branch information
nkuehnel authored Dec 19, 2024
2 parents 1c940ae + 87b2e2d commit ca2af6b
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* Provides the parameters required to build a simple grid with some basic spatial functionality.
* Provides the parameters required to compute noise emissions, immissions and damages.
*
* @author ikaddoura
* @author ikaddoura, nkuehnel
*/
public final class NoiseConfigGroup extends ReflectiveConfigGroup {

Expand Down Expand Up @@ -81,6 +81,7 @@ public final class NoiseConfigGroup extends ReflectiveConfigGroup {
private static final String RECEIVER_POINT_GAP_CMT = "horizontal and vertical distance between receiver points in x-/y-coordinate units";
private static final String WRITE_OUTPUT_ITERATION_CMT = "Specifies how often the noise-specific output is written out.";
private static final String CONSIDER_NOISE_BARRIERS = "considerNoiseBarriers";
private static final String CONSIDER_NOISE_REFLECTION = "considerNoiseReflection";
private static final String NOISE_BARRIERS_GEOJSON_FILE = "noiseBarriersGeojsonPath";
private static final String NOISE_BARRIERS_SOURCE_CRS = "source coordinate reference system of noise barriers geojson file";
private static final String NETWORK_MODES_TO_IGNORE = "networkModesToIgnore";
Expand Down Expand Up @@ -142,6 +143,7 @@ public enum NoiseAllocationApproach {
private double noiseTollFactor = 1.0;

private boolean considerNoiseBarriers = false;
private boolean considerNoiseReflection = false;
private String noiseBarriersFilePath = null;
private String noiseBarriersSourceCrs = null;

Expand Down Expand Up @@ -204,6 +206,7 @@ public Map<String, String> getComments() {
comments.put(NOISE_TOLL_FACTOR, "To be used for sensitivity analysis. Default: 1.0 (= the parameter has no effect)");

comments.put(CONSIDER_NOISE_BARRIERS, "Set to 'true' if noise barriers / building shielding should be considered. Otherwise set to 'false'.");
comments.put(CONSIDER_NOISE_REFLECTION, "Set to 'true' if reflections should be considered. Otherwise set to 'false'. Has a considerable performance impact.");
comments.put(NOISE_BARRIERS_GEOJSON_FILE, "Path to the geojson file for noise barriers.");
comments.put(NOISE_BARRIERS_SOURCE_CRS, "Source coordinate reference system of noise barriers geojson file.");

Expand Down Expand Up @@ -308,6 +311,14 @@ private void checkNoiseParametersForConsistency(Config config) {
+ " It is therefore recommended not to use speeds outside of the range of valid parameters!");
}

if(considerNoiseReflection) {
if (!this.considerNoiseBarriers) {
if (this.noiseBarriersFilePath == null || "".equals(this.noiseBarriersFilePath)) {
log.warn("Cannot consider noise reflection without a specified file path to the geojson file of barriers / buildings.");
this.considerNoiseBarriers = false;
}
}
}
if (this.considerNoiseBarriers) {
if (this.noiseBarriersFilePath == null || "".equals(this.noiseBarriersFilePath)) {
log.warn("Cannot consider noise barriers without a specified file path to the geojson file of barriers / buildings.");
Expand Down Expand Up @@ -782,6 +793,16 @@ public void setConsiderNoiseBarriers(boolean considerNoiseBarriers) {
this.considerNoiseBarriers = considerNoiseBarriers;
}

@StringGetter(CONSIDER_NOISE_REFLECTION)
public boolean isConsiderNoiseReflection() {
return this.considerNoiseReflection;
}

@StringSetter(CONSIDER_NOISE_REFLECTION)
public void setConsiderNoiseReflection(boolean considerNoiseReflection) {
this.considerNoiseReflection = considerNoiseReflection;
}

@StringGetter(NOISE_BARRIERS_GEOJSON_FILE)
public String getNoiseBarriersFilePath() {
return this.noiseBarriersFilePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public double calculateCorrection(double projectedDistance, NoiseReceiverPoint n

@Override
public void setCurrentRp(NoiseReceiverPoint nrp) {
reflection.setCurrentReceiver(nrp);
if(noiseParams.isConsiderNoiseReflection()) {
reflection.setCurrentReceiver(nrp);
}
}

private double getSectionsCorrection(NoiseReceiverPoint nrp, Link link) {
Expand All @@ -127,10 +129,12 @@ private double getSubSectionsCorrection(Coordinate nrpCoordinate, LineSegment se
final double sectionCorrection = 10 * Math.log10(length) - calculateCorrection(nrpCoordinate, segment, null);
correctionTemp += Math.pow(10, 0.1*sectionCorrection);

final Set<ReflectionContext.ReflectionTuple> reflectionLinks = reflection.getReflections(segment);
for(ReflectionContext.ReflectionTuple reflection: reflectionLinks) {
double sectionCorrectionReflection = 10 * Math.log10(reflection.reflectionLink.getLength()) - calculateCorrection(nrpCoordinate, reflection.reflectionLink, reflection.facade);
correctionTemp += Math.pow(10, 0.1 * sectionCorrectionReflection);
if(noiseParams.isConsiderNoiseReflection()) {
final Set<ReflectionContext.ReflectionTuple> reflectionLinks = reflection.getReflections(segment);
for (ReflectionContext.ReflectionTuple reflection : reflectionLinks) {
double sectionCorrectionReflection = 10 * Math.log10(reflection.reflectionLink().getLength()) - calculateCorrection(nrpCoordinate, reflection.reflectionLink(), reflection.facade());
correctionTemp += Math.pow(10, 0.1 * sectionCorrectionReflection);
}
}
} else {
double lMid = length / 2;
Expand All @@ -149,10 +153,12 @@ private double getSubSectionsCorrection(Coordinate nrpCoordinate, LineSegment se
final double sectionCorrection = 10 * Math.log10(central.getLength()) - calculateCorrection(nrpCoordinate, central, null);
correctionTemp += Math.pow(10, 0.1 * sectionCorrection);

final Set<ReflectionContext.ReflectionTuple> reflectionLinks = reflection.getReflections(central);
for(ReflectionContext.ReflectionTuple reflection: reflectionLinks) {
double sectionCorrectionReflection = 10 * Math.log10(reflection.reflectionLink.getLength()) - calculateCorrection(nrpCoordinate, reflection.reflectionLink, reflection.facade);
correctionTemp += Math.pow(10, 0.1 * sectionCorrectionReflection);
if(noiseParams.isConsiderNoiseReflection()) {
final Set<ReflectionContext.ReflectionTuple> reflectionLinks = reflection.getReflections(central);
for (ReflectionContext.ReflectionTuple reflection : reflectionLinks) {
double sectionCorrectionReflection = 10 * Math.log10(reflection.reflectionLink().getLength()) - calculateCorrection(nrpCoordinate, reflection.reflectionLink(), reflection.facade());
correctionTemp += Math.pow(10, 0.1 * sectionCorrectionReflection);
}
}

correctionTemp += getSubSectionsCorrection(nrpCoordinate, leftRemaining);
Expand All @@ -174,7 +180,10 @@ private double calculateCorrection(Coordinate nrp, LineSegment segment, LineSegm
//to maintain the correct signs. nk, Sep'20
double intersectionCorrection = intersection.calculateIntersectionCorrection(coordinate);

double multipleReflectionCorrection = reflection.getMultipleReflectionCorrection(segment);
double multipleReflectionCorrection = 0;
if(noiseParams.isConsiderNoiseReflection()) {
multipleReflectionCorrection = reflection.getMultipleReflectionCorrection(segment);
}

double geometricDivergence = 20 * Math.log10(distance) + 10 * Math.log10(2 * Math.PI);
double airDampeningFactor = distance / 200.;
Expand All @@ -191,11 +200,6 @@ private double calculateCorrection(Coordinate nrp, LineSegment segment, LineSegm
} else {
return geometricDivergence + airDampeningFactor - intersectionCorrection + groundDampening ;
}

//TODO: implement reflection - if someone is looking for a (bachelor) thesis...
// double firstReflectionCorrection = 0;
// double secondReflectionCorrection = 0;
// return dampeningCorrection + firstReflectionCorrection + secondReflectionCorrection;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
package org.matsim.contrib.noise;

import jakarta.inject.Inject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.locationtech.jts.algorithm.Angle;
import org.locationtech.jts.geom.*;
import org.locationtech.jts.geom.util.AffineTransformation;
import org.matsim.core.config.Config;

import jakarta.inject.Inject;
import java.util.*;

/**
* Separate from {@link NoiseContextImpl} for better testability.
*
* @author nkuehnel
*/
public class ReflectionContext {
public final class ReflectionContext {

static final double SCAN_LINE_LENGTH = 1;

private final static Logger logger = LogManager.getLogger(org.matsim.contrib.noise.ShieldingContext.class);
private final static Logger logger = LogManager.getLogger(ReflectionContext.class);

private Set<LineSegment> visibleEdges;
private Coordinate receiver;

private BarrierContext barrierContext;
private GeometryFactory geomFactory = new GeometryFactory();
private final BarrierContext barrierContext;
private final GeometryFactory geomFactory = new GeometryFactory();

record ReflectionTuple(LineSegment facade, LineSegment reflectionLink) { }

@Inject
ReflectionContext(BarrierContext barrierContext) {
Expand All @@ -38,6 +39,7 @@ public class ReflectionContext {
}

void setCurrentReceiver(NoiseReceiverPoint nrp) {

receiver = new Coordinate(nrp.getCoord().getX(), nrp.getCoord().getY());

final Collection<NoiseBarrier> candidates =
Expand All @@ -60,7 +62,7 @@ void setCurrentReceiver(NoiseReceiverPoint nrp) {
}


Set<LineSegment> findVisibleEdgesOfPolygon(List<LineSegment> polygonEdges, Coordinate coordinate) {
private Set<LineSegment> findVisibleEdgesOfPolygon(List<LineSegment> polygonEdges, Coordinate coordinate) {

Coordinate coordXinc = new Coordinate(coordinate.x + 1, coordinate.y);

Expand Down Expand Up @@ -155,13 +157,9 @@ Set<ReflectionTuple> getReflections(LineSegment originalLink) {
}
}
return reflections;
// return Collections.EMPTY_SET;
}

double getMultipleReflectionCorrection(LineSegment segment) {
if(this.receiver.x == 1420 && this.receiver.y == 20) {
System.out.println("jo");
}
final Coordinate coordinate = segment.midPoint();

Coordinate candidateRight = getReflectionSegment(coordinate, segment, 400);
Expand All @@ -174,7 +172,7 @@ Set<ReflectionTuple> getReflections(LineSegment originalLink) {
} else {
return 0;
}
if (candidateLeft != null && candidateRight != null){
if (candidateLeft != null){
double w = candidateLeft.distance(candidateRight);
return Math.min(2 * Math.min(candidateLeft.z, candidateRight.z) / w, 1.6);
}
Expand Down Expand Up @@ -265,7 +263,7 @@ private boolean hit(LineSegment facade, LineSegment originalLink) {
return true;
}

static boolean intersects(LineSegment segment1, LineSegment segment2) {
private static boolean intersects(LineSegment segment1, LineSegment segment2) {

double dx0 = segment1.p1.x - segment1.p0.x;
double dx1 = segment2.p1.x - segment2.p0.x;
Expand All @@ -277,17 +275,6 @@ static boolean intersects(LineSegment segment1, LineSegment segment2) {
double p1 = dy1 * (segment2.p1.x - segment1.p1.x) - dx1 * (segment2.p1.y - segment1.p1.y);
double p2 = dy0 * (segment1.p1.x - segment2.p0.x) - dx0 * (segment1.p1.y - segment2.p0.y);
double p3 = dy0 * (segment1.p1.x - segment2.p1.x) - dx0 * (segment1.p1.y - segment2.p1.y);
return (p0 * p1 <= 0) & (p2 * p3 <= 0);
}


static class ReflectionTuple {
final LineSegment facade;
final LineSegment reflectionLink;

public ReflectionTuple(LineSegment facade, LineSegment reflectionLink) {
this.facade = facade;
this.reflectionLink = reflectionLink;
}
return (p0 * p1 <= 0) && (p2 * p3 <= 0);
}
}
Loading

0 comments on commit ca2af6b

Please sign in to comment.