diff --git a/build/source/actors/HRU.h b/build/source/actors/HRU.h index dfd48c31a01f6ed62bc90462f4eb084a11c8e74f..6a7ac6e0a54bbdf1e4593c48c192b2d53b772191 100644 --- a/build/source/actors/HRU.h +++ b/build/source/actors/HRU.h @@ -12,6 +12,8 @@ #include <sys/resource.h> #include <chrono> #include <iostream> +#include "json.hpp" + using namespace caf; struct hru_state { @@ -76,6 +78,9 @@ struct hru_state { int forcingStep = 1; // index of current time step in current forcing file int iFile = 1; // index of current forcing file from forcing file list int dt_init_factor = 1; // factor of dt_init (coupled_em) + bool printOutput; + int outputFrequency; + // Julian Day variables double fracJulDay; @@ -101,6 +106,13 @@ struct hru_state { }; +/** + * @brief Get the settings from the settings JSON file + * + * @param self Actor State + * @param configPath Path to the directory that contains the settings file + */ +void parseSettings(stateful_actor<hru_state>* self, std::string configPath); /** Function to initalize the HRU for running */ diff --git a/build/source/actors/HRUActor.h b/build/source/actors/HRUActor.h index a1ed5d5b0e12e164497dab0a269b7402ebae2d61..04f015a37fa380f17bf239207190c8528f95c8ea 100644 --- a/build/source/actors/HRUActor.h +++ b/build/source/actors/HRUActor.h @@ -2,6 +2,8 @@ #define HRUActor_H_ #include "HRU.h" +using json = nlohmann::json; + /** * @brief HRU Actor is reponsible for carrying out the computation component of SUMMA @@ -12,7 +14,8 @@ * @param parent * @return behavior */ -behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU, +behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU, + std::string configPath, caf::actor file_access_actor, int outputStrucSize, caf::actor parent) { // Timing Information self->state.start = std::chrono::high_resolution_clock::now(); @@ -31,7 +34,7 @@ behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU, // OutputStructure Size (how many timesteps we can compute before we need to write) self->state.outputStrucSize = outputStrucSize; - // init counters + // initialize counters self->state.timestep = 1; self->state.outputStep = 1; @@ -154,6 +157,41 @@ behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU, *********************************************************************************************************/ } +void parseSettings(stateful_actor<hru_state>* self, std::string configPath) { + json settings; + std::string SummaActorsSettings = "/Summa_Actors_Settings.json"; + std::ifstream settings_file(configPath + SummaActorsSettings); + settings_file >> settings; + settings_file.close(); + + if (settings.find("HRUActor") != settings.end()) { + json HRUActorConfig = settings["HRUActor"]; + // find if we want to print output to stdout + if (HRUActorConfig.find("printOutput") != HRUActorConfig.end()) { + self->state.printOutput = HRUActorConfig["printOutput"]; + } else { + aout(self) << "Error finding printOutput in JSON File - Reverting to default value\n"; + self->state.printOutput = true; + } + + if (self->state.printOutput) { + // get the frequency in number of timesteps we want to print the output + if(HRUActorConfig.find("outputFrequency") != settings.end()) { + self->state.outputFrequency = HRUActorConfig["outputFrequency"]; + } else { + aout(self) << "Error finding outputFrequency in JSON File - Reverting to default value\n"; + self->state.outputFrequency = 10000; + } + } + } else { + aout(self) << "Error finding HRUActor in JSON File - Reverting to default values for HRUs\n"; + self->state.printOutput = true; + self->state.outputFrequency = 10000; + } + + +} + void Initialize_HRU(stateful_actor<hru_state>* self) { self->state.initStart = std::chrono::high_resolution_clock::now(); // aout(self) << "Initalizing HRU" << std::endl; @@ -376,13 +414,6 @@ void finalizeTimeVars(stateful_actor<hru_state>* self) { self->state.end = std::chrono::high_resolution_clock::now(); self->state.duration += std::chrono::duration_cast<std::chrono::seconds> (self->state.end - self->state.start).count(); - - // // Output the timing information - // aout(self) << "DONE:" << self->state.refGRU << ":duration = " << self->state.duration << std::endl; - // aout(self) << "DONE:" << self->state.refGRU << ":initDuration = " << self->state.initDuration << std::endl; - // aout(self) << "DONE:" << self->state.refGRU << ":forcingDuration = " << self->state.forcingDuration.count() << std::endl; - // aout(self) << "DONE:" << self->state.refGRU << ":runPhysicsDuration = " << self->state.runPhysicsDuration.count() << std::endl; - // aout(self) << "DONE:" << self->state.refGRU << ":writeOutputDuration = " << self->state.writeOutputDuration.count() << std::endl; } void deallocateHRUStructures(stateful_actor<hru_state>* self) { diff --git a/build/source/actors/JobActor.h b/build/source/actors/JobActor.h index f2d9e06bb0143cf4573b8961b7fc3d5aa380eb04..d1583af44732d7e207fc153746a17f15ce1d15dd 100644 --- a/build/source/actors/JobActor.h +++ b/build/source/actors/JobActor.h @@ -212,7 +212,8 @@ void initJob(stateful_actor<job_state>* self) { void initalizeGRU(stateful_actor<job_state>* self) { int startGRU = self->state.GRUList.size() + self->state.startGRU; int indexGRU = self->state.GRUList.size() + 1; // Fortran reference starts at 1 - auto gru = self->spawn(hru_actor, startGRU, indexGRU, self->state.file_access_actor, + auto gru = self->spawn(hru_actor, startGRU, indexGRU, + self->state.configPath, self->state.file_access_actor, self->state.outputStrucSize, self); self->state.GRUList.push_back(new GRUinfo(startGRU, indexGRU, gru, self->state.dt_init_start_factor, self->state.maxRunAttempts)); @@ -235,7 +236,8 @@ void restartFailures(stateful_actor<job_state>* self) { gru->updateFailed(); self->send(self->state.file_access_actor, reset_outputCounter_v, gru->getIndxGRU()); gru->updateDt_init(); - auto newGRU = self->spawn(hru_actor, gru->getRefGRU(), gru->getIndxGRU(), self->state.file_access_actor, + auto newGRU = self->spawn(hru_actor, gru->getRefGRU(), gru->getIndxGRU(), + self->state.configPath,self->state.file_access_actor, self->state.outputStrucSize, self); gru->updateGRU(newGRU); gru->updateCurrentAttempt(); diff --git a/config/Summa_Actors_Settings.json b/config/Summa_Actors_Settings.json index 1c21859423d1397a9897d55eb2234f836c79dee4..53358e70c7be469bfac5aa27ea658c3d0a1b2719 100644 --- a/config/Summa_Actors_Settings.json +++ b/config/Summa_Actors_Settings.json @@ -8,5 +8,10 @@ "FileManagerPath": "/project/gwf/gwf_cmt/kck540/domain_NorthAmerica/settings/SUMMA/fileManager.txt", "outputCSV": false, "csvPath": "" + }, + + "HRUActor": { + "printOutput": true, + "outputFrequency": 25000 } } \ No newline at end of file