From 2bd3b36c13e2afe5ef82343bcb4aca4499ef8a6b Mon Sep 17 00:00:00 2001
From: KyleKlenk <kyle.c.klenk@gmail.com>
Date: Thu, 26 Oct 2023 15:15:30 -0600
Subject: [PATCH] Ensured backward compatibility with V3 Summa

---
 build/CMakeLists.txt                          |  9 +--------
 build/source/actors/hru_actor/hru_actor.cpp   | 19 ++++++-------------
 .../source/actors/hru_actor/hru_modelRun.f90  |  5 ++++-
 3 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt
index a554c4f..4152b68 100644
--- a/build/CMakeLists.txt
+++ b/build/CMakeLists.txt
@@ -85,13 +85,6 @@ set(HOOKUP_DIR ${F_MASTER}/build/source/hookup)
 set(NETCDF_DIR ${F_MASTER}/build/source/netcdf)
 set(NOAHMP_DIR ${F_MASTER}/build/source/noah-mp)
 
-# Define directories for source files that might be replaced by actors (identical if not using actors)
-set(SUB_DRIVER_DIR ${PARENT_DIR}/build/source/driver)
-set(SUB_DSHARE_DIR ${PARENT_DIR}/build/source/dshare)
-set(SUB_ENGINE_DIR ${PARENT_DIR}/build/source/engine)
-set(SUB_HOOKUP_DIR ${PARENT_DIR}/build/source/hookup)
-set(SUB_NETCDF_DIR ${PARENT_DIR}/build/source/netcdf)
-
 # Define Actors specific directories
 set(ACTORS_DIR ${PARENT_DIR}/build/source/actors)
 set(FILE_ACCESS_DIR ${ACTORS_DIR}/file_access_actor)
@@ -144,7 +137,7 @@ set(UTILMS
 
 # NetCDF routines
 set(NETCDF
-    ${FILE_ACCESS_DIR}/def_output.f90
+    ${NETCDF_DIR}/def_output.f90
     ${NETCDF_DIR}/netcdf_util.f90
     ${NETCDF_DIR}/read_icond.f90)
 
diff --git a/build/source/actors/hru_actor/hru_actor.cpp b/build/source/actors/hru_actor/hru_actor.cpp
index 4939a6f..dec18f1 100644
--- a/build/source/actors/hru_actor/hru_actor.cpp
+++ b/build/source/actors/hru_actor/hru_actor.cpp
@@ -1,12 +1,5 @@
 #include "hru_actor.hpp"
 
-// Compiler set flag for sundials
-#ifdef SUNDIALS_ACTIVE
-    bool sundials_active = true;
-#else
-    bool sundials_active = false;
-#endif
-
 namespace caf {
 
 behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU,
@@ -67,13 +60,12 @@ behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU,
                 err = Run_HRU(self); // Simulate a Timestep
                 if (err != 0) {
                 
-                    if (sundials_active) {
+#ifdef SUNDIALS_ACTIVE                        
                         get_sundials_tolerances(self->state.hru_data, &self->state.rtol, &self->state.atol);
                         self->send(self->state.parent, err_atom_v, self, self->state.rtol, self->state.atol);
-                    } else {
+#else                        
                         self->send(self->state.parent, hru_error::run_physics_unhandleable, self);
-                    }
-
+#endif
 
                     self->quit();
                     return;
@@ -147,9 +139,10 @@ void Initialize_HRU(stateful_actor<hru_state>* self) {
         self->quit();
         return;
     }
-
+#ifdef SUNDIALS_ACTIVE
     if (self->state.hru_actor_settings.rel_tol > 0 && self->state.hru_actor_settings.abs_tol > 0)
-        set_sundials_tolerances(self->state.hru_data, &self->state.hru_actor_settings.rel_tol, &self->state.hru_actor_settings.abs_tol);            
+        set_sundials_tolerances(self->state.hru_data, &self->state.hru_actor_settings.rel_tol, &self->state.hru_actor_settings.abs_tol);
+#endif           
 }
 
 int Run_HRU(stateful_actor<hru_state>* self) {
diff --git a/build/source/actors/hru_actor/hru_modelRun.f90 b/build/source/actors/hru_actor/hru_modelRun.f90
index 7e53b11..efd4687 100644
--- a/build/source/actors/hru_actor/hru_modelRun.f90
+++ b/build/source/actors/hru_actor/hru_modelRun.f90
@@ -69,8 +69,10 @@ USE mDecisions_module,only:&               ! look-up values for LAI decisions
 implicit none
 private
 public::runPhysics
+#ifdef SUNDIALS_ACTIVE
 public::get_sundials_tolerances
 public::set_sundials_tolerances
+#endif
 contains
 
 ! Runs the model physics for an HRU
@@ -349,6 +351,7 @@ end subroutine runPhysics
 ! *******************************************************************************************
 ! *** get_sundials_tolerances
 ! *******************************************************************************************
+#ifdef SUNDIALS_ACTIVE
 subroutine get_sundials_tolerances(handle_hru_data, rtol, atol) bind(C, name='get_sundials_tolerances')
   USE var_lookup,only: iLookPARAM
   implicit none
@@ -407,6 +410,6 @@ subroutine set_sundials_tolerances(handle_hru_data, rtol, atol) bind(C, name='se
   hru_data%mparStruct%var(iLookPARAM%absTolMatric)%dat(1) = atol 
   hru_data%mparStruct%var(iLookPARAM%absTolAquifr)%dat(1) = atol 
 end subroutine set_sundials_tolerances
-
+#endif
 
 end module summa_modelRun
-- 
GitLab