From 9d8a9cbe64666b7f97f72e5c8000cd378607d9d5 Mon Sep 17 00:00:00 2001
From: Peter Powers <pmpowers@usgs.gov>
Date: Mon, 31 Mar 2025 13:56:52 -0600
Subject: [PATCH] grid edits

---
 .../usgs/earthquake/nshmp/model/GridLoader.java   |  1 +
 .../earthquake/nshmp/model/GridSourcePlanar.java  | 15 +++++++++------
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/main/java/gov/usgs/earthquake/nshmp/model/GridLoader.java b/src/main/java/gov/usgs/earthquake/nshmp/model/GridLoader.java
index ca45dd3f..f364da0c 100644
--- a/src/main/java/gov/usgs/earthquake/nshmp/model/GridLoader.java
+++ b/src/main/java/gov/usgs/earthquake/nshmp/model/GridLoader.java
@@ -147,6 +147,7 @@ class GridLoader {
       this.mfdsPath = data.gridRateFile().orElseThrow();
       this.mfdTreeKey = mfdTreeKey;
       this.featureData = new FeatureData();
+
       processNodes();
     }
 
diff --git a/src/main/java/gov/usgs/earthquake/nshmp/model/GridSourcePlanar.java b/src/main/java/gov/usgs/earthquake/nshmp/model/GridSourcePlanar.java
index 6d82e218..c3849d07 100644
--- a/src/main/java/gov/usgs/earthquake/nshmp/model/GridSourcePlanar.java
+++ b/src/main/java/gov/usgs/earthquake/nshmp/model/GridSourcePlanar.java
@@ -4,6 +4,7 @@ import static gov.usgs.earthquake.nshmp.Maths.PI_BY_2;
 import static gov.usgs.earthquake.nshmp.Maths.TO_RADIANS;
 import static gov.usgs.earthquake.nshmp.Maths.TWO_PI;
 import static gov.usgs.earthquake.nshmp.Maths.hypot;
+import static java.lang.Math.abs;
 import static java.lang.Math.min;
 import static java.lang.Math.sin;
 import static java.lang.Math.sqrt;
@@ -182,20 +183,22 @@ class GridSourcePlanar extends PointSource {
 
       // down-dip and up-dip azimuths
       double ddAz = (strikeRad + PI_BY_2) % TWO_PI;
-      double udAz = (strikeRad - PI_BY_2) % TWO_PI;
 
       // down-dip
       double ddΔV = zBor - location.depth;
       double ddΔH = ddΔV / tan(dipRad);
       double ddW = ddΔV / sin(dipRad);
-      LocationVector ddV = LocationVector.create(ddAz, ddΔH, -ddΔV);
+
+      LocationVector ddV = LocationVector.create(ddAz, ddΔH, ddΔV);
       Location ddP = Locations.location(location, ddV);
 
       // up-dip
-      double udΔV = location.depth - zTor;
+      double udΔV = zTor - location.depth;
       double udΔH = udΔV / tan(dipRad);
       double udW = udΔV / sin(dipRad);
-      LocationVector udV = LocationVector.create(udAz, udΔH, udΔV);
+      // in the updip case, udΔH is negative effectively
+      // reversing the downdip azimuth
+      LocationVector udV = LocationVector.create(ddAz, udΔH, udΔV);
       Location udP = Locations.location(location, udV);
 
       this.p1 = Locations.location(udP, svB);
@@ -203,8 +206,8 @@ class GridSourcePlanar extends PointSource {
       this.p3 = Locations.location(ddP, svF);
       this.p4 = Locations.location(ddP, svB);
 
-      this.width = ddW + udW;
-      this.widthH = ddΔH + udΔH;
+      this.width = ddW + abs(udW);
+      this.widthH = ddΔH + abs(udΔH);
     }
 
     @Override
-- 
GitLab