Skip to content
Snippets Groups Projects
Commit cb67e9ed authored by KyleKlenk's avatar KyleKlenk
Browse files

Added configuration file input to HRUActor

parent ae950bad
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include <sys/resource.h> #include <sys/resource.h>
#include <chrono> #include <chrono>
#include <iostream> #include <iostream>
#include "json.hpp"
using namespace caf; using namespace caf;
struct hru_state { struct hru_state {
...@@ -76,6 +78,9 @@ struct hru_state { ...@@ -76,6 +78,9 @@ struct hru_state {
int forcingStep = 1; // index of current time step in current forcing file 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 iFile = 1; // index of current forcing file from forcing file list
int dt_init_factor = 1; // factor of dt_init (coupled_em) int dt_init_factor = 1; // factor of dt_init (coupled_em)
bool printOutput;
int outputFrequency;
// Julian Day variables // Julian Day variables
double fracJulDay; double fracJulDay;
...@@ -101,6 +106,13 @@ struct hru_state { ...@@ -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 Function to initalize the HRU for running
*/ */
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#define HRUActor_H_ #define HRUActor_H_
#include "HRU.h" #include "HRU.h"
using json = nlohmann::json;
/** /**
* @brief HRU Actor is reponsible for carrying out the computation component of SUMMA * @brief HRU Actor is reponsible for carrying out the computation component of SUMMA
...@@ -12,7 +14,8 @@ ...@@ -12,7 +14,8 @@
* @param parent * @param parent
* @return behavior * @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) { caf::actor file_access_actor, int outputStrucSize, caf::actor parent) {
// Timing Information // Timing Information
self->state.start = std::chrono::high_resolution_clock::now(); 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, ...@@ -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) // OutputStructure Size (how many timesteps we can compute before we need to write)
self->state.outputStrucSize = outputStrucSize; self->state.outputStrucSize = outputStrucSize;
// init counters // initialize counters
self->state.timestep = 1; self->state.timestep = 1;
self->state.outputStep = 1; self->state.outputStep = 1;
...@@ -154,6 +157,41 @@ behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU, ...@@ -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) { void Initialize_HRU(stateful_actor<hru_state>* self) {
self->state.initStart = std::chrono::high_resolution_clock::now(); self->state.initStart = std::chrono::high_resolution_clock::now();
// aout(self) << "Initalizing HRU" << std::endl; // aout(self) << "Initalizing HRU" << std::endl;
...@@ -376,13 +414,6 @@ void finalizeTimeVars(stateful_actor<hru_state>* self) { ...@@ -376,13 +414,6 @@ void finalizeTimeVars(stateful_actor<hru_state>* self) {
self->state.end = std::chrono::high_resolution_clock::now(); self->state.end = std::chrono::high_resolution_clock::now();
self->state.duration += std::chrono::duration_cast<std::chrono::seconds> self->state.duration += std::chrono::duration_cast<std::chrono::seconds>
(self->state.end - self->state.start).count(); (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) { void deallocateHRUStructures(stateful_actor<hru_state>* self) {
......
...@@ -212,7 +212,8 @@ void initJob(stateful_actor<job_state>* self) { ...@@ -212,7 +212,8 @@ void initJob(stateful_actor<job_state>* self) {
void initalizeGRU(stateful_actor<job_state>* self) { void initalizeGRU(stateful_actor<job_state>* self) {
int startGRU = self->state.GRUList.size() + self->state.startGRU; int startGRU = self->state.GRUList.size() + self->state.startGRU;
int indexGRU = self->state.GRUList.size() + 1; // Fortran reference starts at 1 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.outputStrucSize, self);
self->state.GRUList.push_back(new GRUinfo(startGRU, indexGRU, gru, self->state.GRUList.push_back(new GRUinfo(startGRU, indexGRU, gru,
self->state.dt_init_start_factor, self->state.maxRunAttempts)); self->state.dt_init_start_factor, self->state.maxRunAttempts));
...@@ -235,7 +236,8 @@ void restartFailures(stateful_actor<job_state>* self) { ...@@ -235,7 +236,8 @@ void restartFailures(stateful_actor<job_state>* self) {
gru->updateFailed(); gru->updateFailed();
self->send(self->state.file_access_actor, reset_outputCounter_v, gru->getIndxGRU()); self->send(self->state.file_access_actor, reset_outputCounter_v, gru->getIndxGRU());
gru->updateDt_init(); 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); self->state.outputStrucSize, self);
gru->updateGRU(newGRU); gru->updateGRU(newGRU);
gru->updateCurrentAttempt(); gru->updateCurrentAttempt();
......
...@@ -8,5 +8,10 @@ ...@@ -8,5 +8,10 @@
"FileManagerPath": "/project/gwf/gwf_cmt/kck540/domain_NorthAmerica/settings/SUMMA/fileManager.txt", "FileManagerPath": "/project/gwf/gwf_cmt/kck540/domain_NorthAmerica/settings/SUMMA/fileManager.txt",
"outputCSV": false, "outputCSV": false,
"csvPath": "" "csvPath": ""
},
"HRUActor": {
"printOutput": true,
"outputFrequency": 25000
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment