Skip to content

Commit

Permalink
Merge pull request gem#15 from larsbutler/bug-887989
Browse files Browse the repository at this point in the history
[r=angri] [f=887989]
Fix for bug 887989: Exception when using line ruptures and CY_2008_AttenRel
  • Loading branch information
larsbutler committed Nov 23, 2011
2 parents 75b7c81 + a89c5d0 commit 2f96135
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
package org.opensha.sha.earthquake.rupForecastImpl;

import java.util.ArrayList;
import java.util.Iterator;

import org.opensha.commons.calc.magScalingRelations.MagAreaRelationship;
import org.opensha.commons.calc.magScalingRelations.MagLengthRelationship;
import org.opensha.commons.calc.magScalingRelations.MagScalingRelationship;
import org.opensha.commons.data.DataPoint2D;
import org.opensha.commons.data.Site;
import org.opensha.commons.data.function.ArbitrarilyDiscretizedFunc;
import org.opensha.commons.geo.LocationVector;
Expand Down Expand Up @@ -65,7 +63,7 @@ public class PointToLineSource extends ProbEqkSource implements
java.io.Serializable {

// for Debug purposes
protected static String C = new String("PointToLineEqkSource");
protected static String C = "PointToLineEqkSource";
protected static String NAME = "Point-to-Line Source";
protected boolean D = false;

Expand Down Expand Up @@ -186,8 +184,6 @@ private void mkAllRuptures() {
probEqkRuptureList = new ArrayList<ProbEqkRupture>();
rates = new ArrayList<Double>();

// System.out.println((float)rupLength+"\t"+(float)mag+"\t"+(float)lowerSeisDepth+"\t"+(float)dip+"\t"+magScalingRel);

if (numStrikes == -1) { // random or applied strike
for (int i = 0; i < magFreqDists.length; i++) {
mkAndAddRuptures(location, magFreqDists[i], focalMechanisms[i],
Expand Down Expand Up @@ -292,7 +288,7 @@ else if (mag >= aveRupTopVersusMag.getMaxX()){
getRupLength(mag, aveRupTopVersusMag, lowerSeisDepth,
dip, magScalingRel);

// get randome strike if needed (between -90 and + 90)
// get random strike if needed (between -90 and + 90)
if (isStrikeRandom) {
strike = (Math.random() - 0.5) * 180.0;
}
Expand All @@ -315,8 +311,12 @@ else if (mag >= aveRupTopVersusMag.getMaxX()){
}
// if it's smaller set point surface at hypocentral depth
else{
PointSurface surf = new PointSurface(loc.getLatitude(),loc.getLongitude(),defaultHypoDepth);
rupture.setRuptureSurface(surf);
PointSurface surf = new PointSurface(loc.getLatitude(),
loc.getLongitude(),
defaultHypoDepth);
surf.setAveStrike(strike);
surf.setAveDip(dip);
rupture.setRuptureSurface(surf);
}

// add the rupture to the list and save the rate in case the
Expand Down Expand Up @@ -362,8 +362,6 @@ private double getRupLength(double mag,
throw new RuntimeException("bad type of MagScalingRelationship: "
+ magScalingRel);

// System.out.println((float)rupLength+"\t"+(float)mag+"\t"+(float)lowerSeisDepth+"\t"+(float)dip+"\t"+magScalingRel);

return rupLength;
}

Expand Down
4 changes: 2 additions & 2 deletions java/org/opensha/sha/faultSurface/PointSurface.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public class PointSurface implements EvenlyGriddedSurfaceAPI {
/**
* The average strike of this surface on the Earth. Even though this is a
* point source, an average strike can be assigned to it to assist with
* particular scientific caculations. Initially set to NaN.
* particular scientific calculations. Initially set to NaN.
*/
protected double aveStrike = Double.NaN;

/**
* The average dip of this surface into the Earth. Even though this is a
* point source, an average dip can be assigned to it to assist with
* particular scientific caculations. Initially set to NaN.
* particular scientific calculations. Initially set to NaN.
*/
protected double aveDip = Double.NaN;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package org.opensha.sha.earthquake.rupForecastImpl;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.opensha.commons.calc.magScalingRelations.MagScalingRelationship;
import org.opensha.commons.calc.magScalingRelations.magScalingRelImpl.WC1994_MagAreaRelationship;
import org.opensha.commons.data.function.ArbitrarilyDiscretizedFunc;
import org.opensha.commons.geo.Location;
import org.opensha.sha.earthquake.FocalMechanism;
import org.opensha.sha.earthquake.ProbEqkRupture;
import org.opensha.sha.faultSurface.EvenlyGriddedSurfaceAPI;
import org.opensha.sha.faultSurface.PointSurface;
import org.opensha.sha.imr.param.EqkRuptureParams.DipParam;
import org.opensha.sha.magdist.GutenbergRichterMagFreqDist;
import org.opensha.sha.magdist.IncrementalMagFreqDist;

public class PointToLineSourceTest
{

/**
* When area sources are treated as line source,
* we must set the dip for the rupture surface.
* (PointSurfaces must also have the strike set.)
*
* Previously, the dip was not being set on PointSurfaces,
* resulting in a ConstraintException in the CY_2008_AttenRel GMPE.
*
* See:
* https://bugs.launchpad.net/openquake/+bug/887989
*/
@Test
public void testMkAndAddRuptures_DipAndStrikeAreSet()
{
Location loc = new Location(0.0, 0.0);
double aValue = 3.2;
double bValue = 0.7;
double min = 5.0;
double max = 8.0;
double delta = 0.1;
int num = (int) Math.round((max - min)/delta + 1);
double totCumRate = Math.pow(10.0, aValue - bValue * min) -
Math.pow(10.0, aValue - bValue * max);
IncrementalMagFreqDist magDist =
new GutenbergRichterMagFreqDist(bValue, totCumRate,
min+delta/2, max-delta/2, num);
FocalMechanism fm = new FocalMechanism(0.0, 90.0, 0.0);
ArbitrarilyDiscretizedFunc aveRupTopVersusMag = new ArbitrarilyDiscretizedFunc();
aveRupTopVersusMag.set(6.0, 0.0);
double defaultHypoDepth = 5.0;
MagScalingRelationship magScalingRel = new WC1994_MagAreaRelationship();
double lowerSeisDepth = 15.0; // km
double duration = 50.0;
double minMag = 5.0;
double weight = 1.0;


PointToLineSource pls = new PointToLineSource();
pls.probEqkRuptureList = new ArrayList<ProbEqkRupture>();
pls.rates = new ArrayList<Double>();

pls.mkAndAddRuptures(
loc,
magDist,
fm,
aveRupTopVersusMag,
defaultHypoDepth,
magScalingRel,
lowerSeisDepth,
duration,
minMag,
weight);

assertEquals(31, pls.probEqkRuptureList.size());
ArrayList<EvenlyGriddedSurfaceAPI> surfaces = new ArrayList<EvenlyGriddedSurfaceAPI>();
for (ProbEqkRupture rupture : pls.probEqkRuptureList) {
EvenlyGriddedSurfaceAPI surface = rupture.getRuptureSurface();
surfaces.add(surface);
assertFalse(Double.isNaN(surface.getAveDip()));
// PointSurfaces need to have strike set as well:
if (surface instanceof PointSurface) {
assertFalse(Double.isNaN(surface.getAveStrike()));
}
}
}

}

0 comments on commit 2f96135

Please sign in to comment.