From 5f5b3d1344127fc4435706a509e9104b868fa8e5 Mon Sep 17 00:00:00 2001
From: Burgholzer <Robert.Burgholzer@deq.virginia.gov>
Date: Fri, 12 Jul 2024 14:53:46 -0400
Subject: [PATCH] sedtrn vars centralized, and added finish_model function stub

---
 src/hsp2/hsp2/SEDTRN.py                             | 10 +++++++---
 src/hsp2/hsp2/om.py                                 |  8 ++++++++
 src/hsp2/hsp2/state.py                              |  2 +-
 tests/testcbp/HSP2results/JL1_6562_6560.simple.json |  2 +-
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/hsp2/hsp2/SEDTRN.py b/src/hsp2/hsp2/SEDTRN.py
index b8886081..aa85a323 100644
--- a/src/hsp2/hsp2/SEDTRN.py
+++ b/src/hsp2/hsp2/SEDTRN.py
@@ -95,8 +95,8 @@ def sedtrn(io_manager, siminfo, uci, ts, state):
 	state_paths = state['state_paths']
 	op_tokens = state['op_tokens']
 	# Aggregate the list of all SEDTRN end point dependencies
-	ep_list = ['RSED4', 'RSED5', 'RSED6']
-	model_exec_list = model_domain_dependencies(state, state_info['domain'], ep_list)
+	ep_list = sedtrn_state_vars()
+	model_exec_list = model_domain_dependencies(state, state_info['domain'], ep_list, True)
 	model_exec_list = asarray(model_exec_list, dtype="i8") # format for use in 
 	#######################################################################################
 
@@ -1015,4 +1015,8 @@ def expand_SEDTRN_masslinks(flags, uci, dat, recs):
 		rec['TMEMSB2'] = dat.TMEMSB2
 		rec['SVOL'] = dat.SVOL
 		recs.append(rec)
-	return recs
\ No newline at end of file
+	return recs
+
+def sedtrn_state_vars():
+	sedtrn_state = ["RSED4","RSED5","RSED6"]
+	return(sedtrn_state)
\ No newline at end of file
diff --git a/src/hsp2/hsp2/om.py b/src/hsp2/hsp2/om.py
index 97d30e37..468ee43d 100644
--- a/src/hsp2/hsp2/om.py
+++ b/src/hsp2/hsp2/om.py
@@ -538,6 +538,14 @@ def step_model(model_exec_list, op_tokens, state_ix, dict_ix, ts_ix, step):
     return 
 
 
+@njit
+def finish_model(model_exec_list, op_tokens, state_ix, dict_ix, ts_ix):
+    for i in model_exec_list:
+        if op_tokens[i][0] == 12:
+            # register type data (like broadcast accumulators) 
+            end_model_link(op_tokens[i], state_ix, ts_ix)
+    return
+
 
 @njit
 def step_one(op_tokens, ops, state_ix, dict_ix, ts_ix, step, debug = 0):
diff --git a/src/hsp2/hsp2/state.py b/src/hsp2/hsp2/state.py
index 84c31bce..8acff9ce 100644
--- a/src/hsp2/hsp2/state.py
+++ b/src/hsp2/hsp2/state.py
@@ -149,7 +149,7 @@ def state_load_dynamics_hsp2(state, io_manager, siminfo):
 
 def hydr_init_ix(state, domain):
     # get a list of keys for all hydr state variables
-    hydr_state = ["DEP","IVOL","O1","O2","O3", "O4", "O5","OVOL1","OVOL2","OVOL3","PRSUPY","RO","ROVOL","SAREA","TAU","USTAR","VOL","VOLEV"]
+    hydr_state = hydr_state_vars()
     hydr_ix = Dict.empty(key_type=types.unicode_type, value_type=types.int64)
     for i in hydr_state:
         #var_path = f'{domain}/{i}'
diff --git a/tests/testcbp/HSP2results/JL1_6562_6560.simple.json b/tests/testcbp/HSP2results/JL1_6562_6560.simple.json
index a70e9e4c..ca14a304 100644
--- a/tests/testcbp/HSP2results/JL1_6562_6560.simple.json
+++ b/tests/testcbp/HSP2results/JL1_6562_6560.simple.json
@@ -14,7 +14,7 @@
             "left_path": "[parent]/O2",
             "right_path": "[parent]/wd_cfs",
             "link_type": 5,
-            "comments": "The use of [parent] is useful in that it will insure that we create a variable if it doesn't exist.  If the system already created O2 (it should) we would not need this.  But it does not, so we do."
+            "comments": "The use of [parent] is necessary in that it will insure that we create a variable if it doesn't exist.  If the system already created O2 (it should) we would not need this.  But it does not, so we do."
         }
     }
 }