From a8e9b719f9e76d458e7a4114bfe11beffdbe5bec Mon Sep 17 00:00:00 2001 From: KyleKlenk <kyle.c.klenk@gmail.com> Date: Thu, 24 Mar 2022 14:21:57 -0600 Subject: [PATCH] added file settings for hru hooked up csv file functionality --- build/source/actors/HRU.h | 4 ++++ build/source/actors/HRUActor.h | 34 ++++++++++++++++++------------- build/source/actors/Job.h | 2 +- build/source/actors/JobActor.h | 7 ++++--- config/Summa_Actors_Settings.json | 6 +++--- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/build/source/actors/HRU.h b/build/source/actors/HRU.h index 6a7ac6e..eb23f8a 100644 --- a/build/source/actors/HRU.h +++ b/build/source/actors/HRU.h @@ -113,10 +113,12 @@ struct hru_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 */ void Initialize_HRU(stateful_actor<hru_state>* self); + /** Function runs all of the hru time_steps */ @@ -127,4 +129,6 @@ void initalizeTimeVars(stateful_actor<hru_state>* self); void finalizeTimeVars(stateful_actor<hru_state>* self); void deallocateHRUStructures(stateful_actor<hru_state>* self); + +void printOutput(stateful_actor<hru_state>* self); #endif \ No newline at end of file diff --git a/build/source/actors/HRUActor.h b/build/source/actors/HRUActor.h index 04f015a..4036bdf 100644 --- a/build/source/actors/HRUActor.h +++ b/build/source/actors/HRUActor.h @@ -38,6 +38,15 @@ behavior hru_actor(stateful_actor<hru_state>* self, int refGRU, int indxGRU, self->state.timestep = 1; self->state.outputStep = 1; + // Get the settings for the HRU + parseSettings(self, configPath); + // We only want to print this once + if (indxGRU == 1) { + aout(self) << "\nSETTINGS FOR HRU_ACTOR\n"; + aout(self) << "Print Output = " << self->state.printOutput << "\n"; + aout(self) << "Print Output every " << self->state.outputFrequency << " timesteps\n\n"; + } + Initialize_HRU(self); @@ -176,7 +185,7 @@ void parseSettings(stateful_actor<hru_state>* self, std::string configPath) { if (self->state.printOutput) { // get the frequency in number of timesteps we want to print the output - if(HRUActorConfig.find("outputFrequency") != settings.end()) { + if(HRUActorConfig.find("outputFrequency") != HRUActorConfig.end()) { self->state.outputFrequency = HRUActorConfig["outputFrequency"]; } else { aout(self) << "Error finding outputFrequency in JSON File - Reverting to default value\n"; @@ -273,9 +282,6 @@ void Initialize_HRU(stateful_actor<hru_state>* self) { (self->state.initEnd - self->state.initStart).count(); } -/* -** RETURNS 0 on success and -1 on failure -*/ int Run_HRU(stateful_actor<hru_state>* self) { // Housekeeping of the timing variables if(self->state.timestep == 1) { @@ -305,15 +311,12 @@ int Run_HRU(stateful_actor<hru_state>* self) { self->state.forcingEnd = std::chrono::high_resolution_clock::now(); self->state.forcingDuration += self->state.forcingEnd - self->state.forcingStart; - if (self->state.timestep % 50000 == 0) { - aout(self) << self->state.refGRU << ":Accumulated Forcing Time = " << - self->state.forcingDuration << std::endl; - aout(self) << self->state.refGRU << " - Running Timestep = " << self->state.timestep << std::endl; - aout(self) << self->state.refGRU << ":Accumulated Run Physics Time = " << - self->state.runPhysicsDuration << std::endl; - aout(self) << self->state.refGRU << ":Accumulated WriteOutput = " - << self->state.writeOutputDuration << std::endl; + + if (self->state.printOutput && + self->state.timestep % self->state.outputFrequency == 0) { + printOutput(self); } + /********************************************************************** ** RUN_PHYSICS @@ -408,7 +411,6 @@ void initalizeTimeVars(stateful_actor<hru_state>* self) { self->state.writeOutputDuration = self->state.writeOutputEnd - self->state.writeOutputStart; } - void finalizeTimeVars(stateful_actor<hru_state>* self) { self->state.end = std::chrono::high_resolution_clock::now(); @@ -449,5 +451,9 @@ void deallocateHRUStructures(stateful_actor<hru_state>* self) { &self->state.err); } - +void printOutput(stateful_actor<hru_state>* self) { + aout(self) << self->state.refGRU << " - Timestep = " << self->state.timestep << std::endl; + aout(self) << self->state.refGRU << ":Accumulated Run Physics Time = " << + self->state.runPhysicsDuration << std::endl; +} #endif \ No newline at end of file diff --git a/build/source/actors/Job.h b/build/source/actors/Job.h index 004b7c4..9fa617c 100644 --- a/build/source/actors/Job.h +++ b/build/source/actors/Job.h @@ -48,7 +48,7 @@ struct job_state { bool outputCSV; std::string csvOut; std::string csvPath; - std::string successOutputFile = "SuccessHRU"; + std::string successOutputFile; std::string failedOutputFile = "failedHRU"; std::string fileAccessActorStats = "fileAccessActor.csv"; diff --git a/build/source/actors/JobActor.h b/build/source/actors/JobActor.h index d1583af..352449f 100644 --- a/build/source/actors/JobActor.h +++ b/build/source/actors/JobActor.h @@ -26,7 +26,7 @@ behavior job_actor(stateful_actor<job_state>* self, int startGRU, int numGRU, aout(self) << "ERROR WITH JSON SETTINGS FILE!!!\n"; self->quit(); } else { - aout(self) << "SETTINGS FOR JOB_ACTOR\n" << + aout(self) << "\nSETTINGS FOR JOB_ACTOR\n" << "File Manager Path = " << self->state.fileManager << "\n" << "outputCSV = " << self->state.outputCSV << "\n"; if (self->state.outputCSV) { @@ -178,10 +178,11 @@ int parseSettings(stateful_actor<job_state>* self, std::string configPath) { } void initJob(stateful_actor<job_state>* self) { - + std::string success = "Success"; // allows us to build the string if (self->state.outputCSV) { std::ofstream file; - self->state.successOutputFile += std::to_string(self->state.startGRU) += ".csv"; + self->state.successOutputFile = self->state.csvPath += success += + std::to_string(self->state.startGRU) += ".csv"; file.open(self->state.successOutputFile, std::ios_base::out); file << "GRU" << "," << "totalDuration" << "," << "initDuration" << "," << "forcingDuration" << "," << "runPhysicsDuration" << "," << "writeOutputDuration" << diff --git a/config/Summa_Actors_Settings.json b/config/Summa_Actors_Settings.json index 53358e7..5acfcc6 100644 --- a/config/Summa_Actors_Settings.json +++ b/config/Summa_Actors_Settings.json @@ -5,13 +5,13 @@ }, "JobActor": { - "FileManagerPath": "/project/gwf/gwf_cmt/kck540/domain_NorthAmerica/settings/SUMMA/fileManager.txt", + "FileManagerPath": , "outputCSV": false, - "csvPath": "" + "csvPath": }, "HRUActor": { "printOutput": true, - "outputFrequency": 25000 + "outputFrequency": 1000 } } \ No newline at end of file -- GitLab