Skip to content

Commit

Permalink
Large commit including new tests in PathFinder.
Browse files Browse the repository at this point in the history
Iso problem: TC21, TC28.
Rays problem, update the Z of S' after diffraction: TC18.
Gpath problem: TC19.
  • Loading branch information
MaguetteD committed Jul 11, 2024
1 parent 3b44295 commit fe6cd92
Show file tree
Hide file tree
Showing 33 changed files with 5,147 additions and 372 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* NoiseModelling is a library capable of producing noise maps. It can be freely used either for research and education, as well as by experts in a professional use.
* <p>
* NoiseModelling is distributed under GPL 3 license. You can read a copy of this License in the file LICENCE provided with this software.
* <p>
* Official webpage : http://noise-planet.org/noisemodelling.html
* Contact: [email protected]
*/


package org.noise_planet.noisemodelling.emission.directivity;

import java.util.Arrays;
import java.util.Locale;
import java.util.Objects;


public class DirectivityRecord {
double theta;
double phi;
double[] attenuation;

/**
* directivity record is the attenuation value for a specific angle (theta, phi) - a point of the directivity sphere
*
* @param theta (-π/2 π/2) 0 is horizontal; π is top
* @param phi (0 2π) 0 is front
* @param attenuation in dB
*/
public DirectivityRecord(double theta, double phi, double[] attenuation) {
this.theta = theta;
this.phi = phi;
this.attenuation = attenuation;
}

/**
*
* @return
*/
public double getTheta() {
return theta;
}

public double getPhi() {
return phi;
}

/**
* compare the values of theta et phi of the Object DirectivityRecord
* @param o object
* @return a boolean
*/

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DirectivityRecord record = (DirectivityRecord) o;
return Double.compare(record.theta, theta) == 0 &&
Double.compare(record.phi, phi) == 0;
}


/**
* generate a hash code for an object with theta and phi argument
* @return
*/
@Override
public int hashCode() {
return Objects.hash(theta, phi);
}

/**
* generate a string representation of the object DirectivityRecord
* @return a string
*/
@Override
public String toString() {
return String.format(Locale.ROOT, "DirectivityRecord{theta=%.2f (%.2g°)" +
", phi=%.2f (%.2g°) , attenuation=%s}", theta, Math.toDegrees(theta), phi, Math.toDegrees(phi),
Arrays.toString(attenuation));
}

public double[] getAttenuation() {
return attenuation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* NoiseModelling is a library capable of producing noise maps. It can be freely used either for research and education, as well as by experts in a professional use.
* <p>
* NoiseModelling is distributed under GPL 3 license. You can read a copy of this License in the file LICENCE provided with this software.
* <p>
* Official webpage : http://noise-planet.org/noisemodelling.html
* Contact: [email protected]
*/

package org.noise_planet.noisemodelling.emission.directivity;


public class OmnidirectionalDirection implements DirectivitySphere {


/**
* Returns the attenuation in dB of the directivity pattern at a given angle (phi, theta).
* @param frequency Frequency in Hertz
* @param phi (0 2π) with 0 is front
* @param theta (-π/2 π/2) with 0 is horizontal; π is top
* @return
*/
@Override
public double getAttenuation(double frequency, double phi, double theta) {
return 0;
}

/**
* Returns the attenuation in dB of the directivity pattern at a given angle (phi, theta).
* @param frequencies Frequency array in Hertz (same order will be returned)
* @param phi (0 2π) 0 is front
* @param theta (-π/2 π/2) 0 is horizontal π is top
* @return Attenuation in dB for each frequency
*/
@Override
public double[] getAttenuationArray(double[] frequencies, double phi, double theta) {
return new double[frequencies.length];
}

/**
* Check if this sphere is capable of producing an attenuation for this frequency
* @param frequency Frequency in Hertz
* @return True
*/
@Override
public boolean coverFrequency(double frequency) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* NoiseModelling is a library capable of producing noise maps. It can be freely used either for research and education, as well as by experts in a professional use.
* <p>
* NoiseModelling is distributed under GPL 3 license. You can read a copy of this License in the file LICENCE provided with this software.
* <p>
* Official webpage : http://noise-planet.org/noisemodelling.html
* Contact: [email protected]
*/

package org.noise_planet.noisemodelling.emission.directivity;

import java.io.Serializable;
import java.util.Comparator;


public class PhiComparator implements Comparator<DirectivityRecord>, Serializable {

/**
* Compare two directivity record
* @param o1 the first object to be compared.
* @param o2 the second object to be compared.
* @return 1 or 0 or -1
*/
@Override
public int compare(DirectivityRecord o1, DirectivityRecord o2) {
final int phiCompare = Double.compare(o1.phi, o2.phi);
if (phiCompare != 0) {
return phiCompare;
}
return Double.compare(o1.theta, o2.theta);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* NoiseModelling is a library capable of producing noise maps. It can be freely used either for research and education, as well as by experts in a professional use.
* <p>
* NoiseModelling is distributed under GPL 3 license. You can read a copy of this License in the file LICENCE provided with this software.
* <p>
* Official webpage : http://noise-planet.org/noisemodelling.html
* Contact: [email protected]
*/
package org.noise_planet.noisemodelling.emission.directivity;

import java.io.Serializable;
import java.util.Comparator;

public class ThetaComparator implements Comparator<DirectivityRecord>, Serializable {

/**
* Compare two directivity record
* @param o1 the first object to be compared.
* @param o2 the second object to be compared.
* @return 1 or 0 or -1
*/
@Override
public int compare(DirectivityRecord o1, DirectivityRecord o2) {
final int thetaCompare = Double.compare(o1.theta, o2.theta);
if (thetaCompare != 0) {
return thetaCompare;
}
return Double.compare(o1.phi, o2.phi);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* NoiseModelling is a library capable of producing noise maps. It can be freely used either for research and education, as well as by experts in a professional use.
* <p>
* NoiseModelling is distributed under GPL 3 license. You can read a copy of this License in the file LICENCE provided with this software.
* <p>
* Official webpage : http://noise-planet.org/noisemodelling.html
* Contact: [email protected]
*/

package org.noise_planet.noisemodelling.emission.directivity.cnossos;

import org.noise_planet.noisemodelling.emission.LineSource;
import org.noise_planet.noisemodelling.emission.directivity.DirectivitySphere;
import org.noise_planet.noisemodelling.emission.railway.cnossos.RailWayCnossosParameters;


public final class RailwayCnossosDirectivitySphere implements DirectivitySphere {
LineSource lineSource;

public RailwayCnossosDirectivitySphere(LineSource lineSource) {
this.lineSource = lineSource;
}

/**
* Returns the attenuation in dB due to a particular frequency of the directivity pattern at a given angle (phi, theta)
* @param frequency Frequency in Hertz
* @param phi (0 2π) with 0 is front
* @param theta (-π/2 π/2) with 0 is horizontal; π is top
* @return Attenuation in dB
*/
@Override
public double getAttenuation(double frequency, double phi, double theta) {
return RailWayCnossosParameters.getDirectionAttenuation(lineSource, phi, theta, frequency);
}


/**
* Returns the attenuation in dB of the directivity pattern at a given angle (phi, theta).
* @param frequencies Frequency array in Hertz (same order will be returned)
* @param phi (0 2π) 0 is front
* @param theta (-π/2 π/2) 0 is horizontal π is top
* @return Attenuation in dB for each frequency
*/
@Override
public double[] getAttenuationArray(double[] frequencies, double phi, double theta) {
double[] ret = new double[frequencies.length];
for (int idFrequency = 0; idFrequency < frequencies.length; idFrequency++) {
ret[idFrequency] = getAttenuation(frequencies[idFrequency], phi, theta);
}
return ret;
}


/**
* Check if this sphere is capable of producing an attenuation for this frequency
* @param frequency Frequency in Hertz
* @return True
*/
@Override
public boolean coverFrequency(double frequency) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* NoiseModelling is a library capable of producing noise maps. It can be freely used either for research and education, as well as by experts in a professional use.
* <p>
* NoiseModelling is distributed under GPL 3 license. You can read a copy of this License in the file LICENCE provided with this software.
* <p>
* Official webpage : http://noise-planet.org/noisemodelling.html
* Contact: [email protected]
*/
package org.noise_planet.noisemodelling.emission.railway.nmpb;

import org.noise_planet.noisemodelling.emission.directivity.DirectivitySphere;

public final class TrainAttenuation implements DirectivitySphere {
RailWayNMPBParameters.TrainNoiseSource noiseSource;

public TrainAttenuation(RailWayNMPBParameters.TrainNoiseSource noiseSource) {
this.noiseSource = noiseSource;
}

/**
* Returns the attenuation in dB due to a particular frequency of the directivity pattern at a given angle (phi, theta)
* @param frequency Frequency in Hertz
* @param phi (0 2π) with 0 is front
* @param theta (-π/2 π/2) with 0 is horizontal; π is top
* @return Attenuation in dB
*/
@Override
public double getAttenuation(double frequency, double phi, double theta) {
return RailWayNMPBParameters.getDirectionAttenuation(noiseSource, phi, theta, frequency);
}

/**
* Returns the attenuation in dB of the directivity pattern at a given angle (phi, theta).
* @param frequencies Frequency array in Hertz (same order will be returned)
* @param phi (0 2π) 0 is front
* @param theta (-π/2 π/2) 0 is horizontal π is top
* @return Attenuation in dB for each frequency
*/
@Override
public double[] getAttenuationArray(double[] frequencies, double phi, double theta) {
double[] ret = new double[frequencies.length];
for (int idFrequency = 0; idFrequency < frequencies.length; idFrequency++) {
ret[idFrequency] = getAttenuation(frequencies[idFrequency], phi, theta);
}
return ret;
}

/**
* Check if this sphere is capable of producing an attenuation for this frequency
* @param frequency Frequency in Hertz
* @return True
*/
@Override
public boolean coverFrequency(double frequency) {
return true;
}
}
Loading

0 comments on commit fe6cd92

Please sign in to comment.