From e127ccf077f471b6c12ab4beddd613b456a686cb Mon Sep 17 00:00:00 2001
From: Peter Powers <pmpowers@usgs.gov>
Date: Sun, 31 Jan 2021 14:50:31 -0700
Subject: [PATCH] grid model loader copies path-based rate-tree for reuse

---
 .../java/gov/usgs/earthquake/nshmp/model/ModelLoader.java  | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/main/java/gov/usgs/earthquake/nshmp/model/ModelLoader.java b/src/main/java/gov/usgs/earthquake/nshmp/model/ModelLoader.java
index f8c6756a..8a93b27a 100644
--- a/src/main/java/gov/usgs/earthquake/nshmp/model/ModelLoader.java
+++ b/src/main/java/gov/usgs/earthquake/nshmp/model/ModelLoader.java
@@ -868,7 +868,12 @@ abstract class ModelLoader {
 
         /* Expect one or more geojson polygon files. */
         data.gridFeatureMap(ModelFiles.readGridFeatures(dir).orElseThrow());
-        LogicTree<Path> rateTree = data.gridRateTree().orElseThrow();
+
+        /*
+         * Path based gridRateTree may be used on multiple branches; we
+         * therefore need to use a copy because graph won't support edge reuse.
+         */
+        LogicTree<Path> rateTree = MfdTrees.copy(data.gridRateTree().orElseThrow());
         treeBuilder.addBranches(branch, rateTree);
 
         for (Branch<Path> rateBranch : rateTree) {
-- 
GitLab