Skip to content

Commit

Permalink
TC11 pass
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Oct 17, 2024
1 parent 3241a17 commit 2c314ef
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,8 @@ public void TC08() throws IOException {
//Run computation
computeRays.run(propDataOut);

assertEquals(3, propDataOut.getPropagationPaths().size());

//Expected values
//Path0 : vertical plane
double[] expectedDeltaDiffSRH = new double[]{6.02, 6.97, 8.42, 10.38, 12.75, 15.40, 18.21, 21.12};
Expand Down Expand Up @@ -3481,6 +3483,18 @@ public void TC10() throws IOException {
assertArrayEquals( new double[]{46.09,42.49,38.44,35.97,34.67,33.90,33.09,31.20},L, ERROR_EPSILON_VERY_LOW);
}

private static void exportRays(String path, List<CnossosPath> cnossosPaths) throws IOException {
JsonMapper.Builder builder = JsonMapper.builder();
JsonMapper mapper = builder.build();
mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
mapper.writerWithDefaultPrettyPrinter().writeValue(new File(path), cnossosPaths);
}

/**
* Test TC11 -- Flat ground with homogeneous acoustic properties and cubic building – receiver at large height
*/
Expand Down Expand Up @@ -3522,19 +3536,7 @@ public void TC11() throws IOException {
//Run computation
computeRays.run(propDataOut);

JsonMapper.Builder builder = JsonMapper.builder();
JsonMapper mapper = builder.build();
mapper.setVisibility(mapper.getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
try {
mapper.writeValue(new File("target/cnossosPath.json"), propDataOut.getPropagationPaths());
} catch (StreamWriteException ex) {

}
exportRays("src/test/resources/org/noise_planet/noisemodelling/jdbc/regression2/cnossosPath.json", propDataOut.getPropagationPaths());

//Expected values
//Path0 : vertical plane
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,11 @@ public List<CnossosPath> directPath(PointPath.SourcePointInfo src,
* @param rcvId Receiver point identifier.
* @return Calculated propagation paths.
*/
public List<CnossosPath> directPath(Coordinate srcCoord, int srcId, Orientation orientation, Coordinate rcvCoord, int rcvId, boolean verticalDiffraction, boolean horizontalDiffraction, boolean bodyBarrier) {
public List<CnossosPath> directPath(Coordinate srcCoord, int srcId, Orientation orientation, Coordinate rcvCoord,
int rcvId, boolean verticalDiffraction, boolean horizontalDiffraction,
boolean bodyBarrier) {
List<CnossosPath> pathsParameters = new ArrayList<>();
CutProfile cutProfile = data.profileBuilder.getProfile(srcCoord, rcvCoord, data.gS);
cutProfile.getSource().setGroundCoef(data.gS);
cutProfile.setSrcOrientation(orientation);
//If the field is free, simplify the computation
if(cutProfile.isFreeField()) {
Expand Down Expand Up @@ -849,8 +850,6 @@ public CnossosPath computeHEdgeDiffraction(CutProfile cutProfile , boolean bodyB
pathParameters.init(data.freq_lvl.size());
pathParameters.angle=Angle.angle(cutProfile.getReceiver().getCoordinate(), cutProfile.getSource().getCoordinate());
pathParameters.setCutPoints(cutPts);
LineSegment srcRcvLine = new LineSegment(firstPts2D, lastPts2D);
List<Coordinate> pts = new ArrayList<>();

// Extract the first and last points to define the line segment
Coordinate firstPt = pts2D.get(0);
Expand Down Expand Up @@ -896,7 +895,7 @@ public CnossosPath computeHEdgeDiffraction(CutProfile cutProfile , boolean bodyB
convexHullPoints.add(convexHullCoords[j]);
}
}
pts = convexHullPoints;
List<Coordinate> pts = convexHullPoints;

double e = 0;
Coordinate src = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,31 +211,19 @@ public boolean intersectGroundEffect(){
* @return the absorption coefficient of this path
*/
public double getGPath(CutPoint p0, CutPoint p1) {
CutPoint current = p0;
double totLength = p0.getCoordinate().distance(p1.getCoordinate());
double totalLength = 0;
double rsLength = 0.0;

List<CutPoint> pts = new ArrayList<>();
for(CutPoint cut : getCutPoints()) {
if(cut.getType() != TOPOGRAPHY && cut.getType() != BUILDING) {
pts.add(cut);
}
}
if(p0.compareTo(p1)<=0) {
pts.sort(CutPoint::compareTo);
} else {
pts.sort(Collections.reverseOrder());
}
// Extract part of the path from the specified argument
List<CutPoint> reduced = pts.subList(pts.indexOf(p0), pts.indexOf(p1) + 1);

int dir = -p0.compareTo(p1);
for(CutPoint cut : pts) {
if(dir*cut.compareTo(current)>=0 && dir*cut.compareTo(p1)<0) {
rsLength += current.getCoordinate().distance(cut.getCoordinate()) * current.getGroundCoef();
current = cut;
}
for(int index = 0; index < reduced.size() - 1; index++) {
CutPoint current = reduced.get(index);
double segmentLength = current.getCoordinate().distance(reduced.get(index+1).getCoordinate());
rsLength += segmentLength * current.getGroundCoef();
totalLength += segmentLength;
}
rsLength += current.getCoordinate().distance(p1.getCoordinate()) * current.getGroundCoef();
return rsLength / totLength;
return rsLength / totalLength;
}

public double getGPath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.locationtech.jts.index.ItemVisitor;
import org.locationtech.jts.index.strtree.STRtree;
import org.locationtech.jts.math.Vector2D;
import org.locationtech.jts.math.Vector3D;
import org.locationtech.jts.operation.distance.DistanceOp;
import org.locationtech.jts.triangulate.quadedge.Vertex;
import org.noise_planet.noisemodelling.pathfinder.delaunay.LayerDelaunay;
Expand All @@ -45,10 +44,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

import static java.lang.Double.NaN;
import static java.lang.Double.isNaN;
Expand All @@ -69,7 +66,7 @@
*/
public class ProfileBuilder {
public static final double epsilon = 1e-7;
public static final double CENTIMETER = 0.01;
public static final double MILLIMETER = 0.001;
public static final double LEFT_SIDE = Math.PI / 2;
/** Class {@link java.util.logging.Logger}. */
private static final Logger LOGGER = LoggerFactory.getLogger(ProfileBuilder.class);
Expand Down Expand Up @@ -1056,8 +1053,8 @@ public int getIntersectingGroundAbsorption(Geometry query) {
* @param profile Object to feed the results (out)
*/
private void addGroundBuildingCutPts(LineSegment fullLine, CutProfile profile) {
Vector2D directionBefore = Vector2D.create(fullLine.p1, fullLine.p0).normalize().multiply(CENTIMETER);
Vector2D directionAfter = Vector2D.create(fullLine.p0, fullLine.p1).normalize().multiply(CENTIMETER);
Vector2D directionBefore = Vector2D.create(fullLine.p1, fullLine.p0).normalize().multiply(MILLIMETER);
Vector2D directionAfter = Vector2D.create(fullLine.p0, fullLine.p1).normalize().multiply(MILLIMETER);
// Collect all objects where envelope intersects all sub-segments of fullLine
Set<Integer> indexes = new HashSet<>();

Expand Down Expand Up @@ -1089,7 +1086,7 @@ private void addGroundBuildingCutPts(LineSegment fullLine, CutProfile profile) {
Vector2D facetVector = Vector2D.create(facetLine.p0, facetLine.p1);
// exterior polygon segments are CW, so the exterior of the polygon is on the left side of the vector
// it works also with polygon holes as interiors are CCW
Vector2D exteriorVector = facetVector.rotate(LEFT_SIDE).normalize().multiply(CENTIMETER);
Vector2D exteriorVector = facetVector.rotate(LEFT_SIDE).normalize().multiply(MILLIMETER);
Coordinate exteriorPoint = exteriorVector.add(Vector2D.create(intersection)).toCoordinate();
CutPoint exteriorPointCutPoint = profile.addBuildingCutPt(exteriorPoint, facetLine.originId, i,false);
if(topoTree == null) {
Expand Down

0 comments on commit 2c314ef

Please sign in to comment.