Skip to content

Commit

Permalink
Merge pull request gem#16 from larsbutler/complex-fault-demo-npe-fix
Browse files Browse the repository at this point in the history
[r=angri] [f=901092]
Complex fault demo NullPointerException fix
  • Loading branch information
larsbutler committed Dec 8, 2011
2 parents 1f917ff + 93bdaa4 commit f925c3c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,21 @@

package org.opensha.sha.earthquake.rupForecastImpl;

import java.io.IOException;
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.Site;
import org.opensha.commons.util.FileUtils;
import org.opensha.commons.geo.BorderType;
import org.opensha.commons.geo.Location;
import org.opensha.commons.geo.LocationList;
import org.opensha.commons.geo.LocationUtils;
import org.opensha.commons.geo.Region;
import org.opensha.sha.earthquake.ProbEqkRupture;
import org.opensha.sha.earthquake.ProbEqkSource;
import org.opensha.sha.faultSurface.EvenlyGriddedSurface;
import org.opensha.sha.faultSurface.EvenlyGriddedSurfaceAPI;
import org.opensha.sha.faultSurface.FaultTrace;
import org.opensha.sha.magdist.GaussianMagFreqDist;
import org.opensha.sha.magdist.IncrementalMagFreqDist;
import org.opensha.sha.util.TectonicRegionType;
Expand Down Expand Up @@ -118,7 +114,7 @@
public class FloatingPoissonFaultSource extends ProbEqkSource {

// for Debug purposes
private static String C = new String("FloatingPoissonFaultSource");
private static String C = "FloatingPoissonFaultSource";
private boolean D = false;

// name for this classs
Expand All @@ -127,8 +123,6 @@ public class FloatingPoissonFaultSource extends ProbEqkSource {
// private fields
private ArrayList<ProbEqkRupture> ruptureList;

// private ArrayList<Location> faultCornerLocations = new
// ArrayList<Location>(); // used for the getMinDistance(Site) method
private double duration;
private EvenlyGriddedSurface faultSurface;

Expand Down Expand Up @@ -278,6 +272,7 @@ public void setTectonicRegionType(TectonicRegionType tectRegType){
for (int r = 0; r < ruptureList.size(); r++) {
ruptureList.get(r).setTectRegType(tectRegType);
}
super.setTectonicRegionType(tectRegType);
}

/**
Expand Down Expand Up @@ -364,8 +359,6 @@ private void addRupturesToList(IncrementalMagFreqDist magDist,
rupWidth = 2 * ddw; // factor of 2 more than ensures
// full ddw ruptures

// System.out.println((float)mag+"\t"+(float)rupLen+"\t"+(float)rupWidth+"\t"+(float)(rupLen*rupWidth));

// get number of ruptures depending on whether we're
// floating down the middle
if (floatTypeFlag != 2)
Expand Down Expand Up @@ -403,14 +396,6 @@ private void addRupturesToList(IncrementalMagFreqDist magDist,
rupSurf.getSurfaceCentre());
ruptureList.add(probEqkRupture);
}
/*
* if( D )
* System.out.println(C+": ddw="+ddw+": mag="+mag+"; rupLen="
* +rupLen+"; rupWidth="+rupWidth+
* "; rate="+rate+"; timeSpan="+duration+"; numRup="+numRup+
* "; weight="
* +weight+"; prob="+prob+"; floatTypeFlag="+floatTypeFlag);
*/

}
// Apply full fault rupture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,28 @@ public void peerTestSet1Case5() throws Exception {

return expectedResults;
}

/**
* This test was introduced as a results of this bug report:
* https://bugs.launchpad.net/openquake/+bug/901092
*
* FloatingPoissonFaultSource overrides the setTectonicRegionType
* method from the base class (ProbEqkSource).
*
* However, the override fails to do what the base implementation
* does: set the tectonic region type.
*
* I wonder how long this bug has been here, and why we found
* it just now.
*/
@Test
public void testSetTectonicRegionTypeActuallySetsTectonicRegionType() {
FloatingPoissonFaultSource src =
FloatingPoissonFaultSourceTestHelper.getPeerTestSet1Case5FaultSource();
// We assume the default is ACTIVE_SHALLOW
assertEquals(TectonicRegionType.ACTIVE_SHALLOW, src.getTectonicRegionType());

src.setTectonicRegionType(TectonicRegionType.SUBDUCTION_INTERFACE);
assertEquals(TectonicRegionType.SUBDUCTION_INTERFACE, src.getTectonicRegionType());
}
}

0 comments on commit f925c3c

Please sign in to comment.