/**
  * This tests the OpenSHA parameter mechanism of</br> (</br> org.opensha.sha.imr.param.
  * PropagationEffectParams.WarningDoublePropagationEffectParameter</br> )</br> respectively (</br>
  * org.opensha.commons.param.Parameter</br> )</br>
  *
  * <p>In the OpenSHA program flow the parameters are set to the AttenuationRelation subclasses
  * when a ParameterChangeEvent is fired. E.g. here, this happens with the call
  * bw_1997_AttenRel.setEqkRupture(eqkRupture).
  */
 public void testParameterClasses() {
   double mag = 5.0;
   double aveRake = 0.0;
   Location hypo = new Location(0.0, 0.0, 5.0);
   Location location = new Location(0.0, 0.1, 0.0);
   EqkRupture eqkRupture = PredictionEquationTestHelper.getPointEqkRupture(mag, hypo, aveRake);
   double epicentralDistance = LocationUtils.horzDistance(hypo, location);
   /*
    * This is what we want to test: The following call triggers a call
    * chain that finally calls
    * WarningDoublePropagationEffectParameter.setValue(), which then fires
    * a ParameterChangeEvent which sets the parameters correctly in the
    * attenuation relation equation (e.g. class BW_1997_AttenRel).
    */
   bw_1997_AttenRel.setSite(new Site(location));
   /*
    * dito
    */
   bw_1997_AttenRel.setEqkRupture(eqkRupture);
   /*
    * These are the equation's results if if parameters are set by the
    * parameter change event:
    */
   double meanParameterListener = bw_1997_AttenRel.getMean();
   double stdDevParameterListener = bw_1997_AttenRel.getStdDev();
   /*
    * These are the results of the directly called calculation method(s):
    */
   double meanDirect = bw_1997_AttenRel.getMean(mag, epicentralDistance);
   double stdDevDirect = bw_1997_AttenRel.getStdDev();
   /*
    * If the results match, we take that as a proof that parameters have
    * been been properly set by the ParameterChangeEvent mechanism.
    *
    * They should be exactly equal, do not specify a tolerance to the
    * assertion methods (as done in other tests).
    */
   assertEquals(meanParameterListener, meanDirect);
   assertEquals(stdDevParameterListener, stdDevDirect);
 }
  public GEMFaultSourceData getFaultSourceData() {

    // Create the fault trace
    Location loc1 = new Location(this.lat, this.lon, this.depth);
    if (this.strike > 180) this.strike -= 360;
    // Location loctmp =
    // RelativeLocation.location(loc1,strike/180.0*Math.PI,this.rectangleLenght);
    Location loctmp = LocationUtils.location(loc1, strike / 180.0 * Math.PI, this.rectangleLenght);
    if (INFO) {
      System.out.printf("  Fault origin   : %6.2f %6.2f\n", this.lon, this.lat);
      System.out.printf(
          "  Fault end point: %6.2f %6.2f\n", loctmp.getLongitude(), loctmp.getLatitude());
    }

    System.out.printf("New fault strike .......: %+6.2f\n", this.strike);
    FaultTrace trace = new FaultTrace(String.format("%d", this.id));
    Location loc2 = new Location(loctmp.getLatitude(), loctmp.getLongitude(), this.depth);
    if (this.dip > 90.0) {
      trace.add(loc2);
      trace.add(loc1);
      this.dip = 180.0 - this.dip;
      System.out.println("reverting");
    } else {
      trace.add(loc1);
      trace.add(loc2);
    }

    // Magnitude-frequency distribution - mmin, mmax, numInt
    IncrementalMagFreqDist mfd = new IncrementalMagFreqDist(this.magnitude, this.magnitude, 1);
    mfd.add(0, this.averageActivity);

    // Lower seismogenic depth
    double seismDepthLow = this.depth + this.rectangleWidth * Math.sin(this.dip / 180.0 * Math.PI);

    if (INFO) System.out.println(this.id);

    // Checking dip value
    if (dip > 90.0 || this.dip < 0.0) {
      System.out.println("ID" + id + " dip:" + dip);
      throw new RuntimeException("dip out of range");
    }

    // Checking depth value
    if (depth < 0.0) {
      System.out.println("ID" + id + " depth:" + depth);
      throw new RuntimeException("depth out of range");
    }

    // Checking Seismogenic layer
    if (seismDepthLow < this.depth) {
      System.out.println("ID" + id + " Depth upp:" + depth + " Depth low" + seismDepthLow);
      throw new RuntimeException("inconsistent depths");
    }

    // Create the GEM fault source data
    GEMFaultSourceData srcData =
        new GEMFaultSourceData(
            String.format("%d", this.id),
            this.name,
            TectonicRegionType.ACTIVE_SHALLOW,
            mfd,
            trace,
            this.dip,
            -90.0,
            seismDepthLow,
            this.depth,
            true);

    return srcData;
  }
 /**
  * This returns the shortest horizontal dist to the point source.
  *
  * @param site
  * @return minimum distance
  */
 public double getMinDistance(Site site) {
   return LocationUtils.horzDistance(site.getLocation(), location);
 }