Skip to content

Commit

Permalink
Merge pull request #472 from rarutter/hold_output
Browse files Browse the repository at this point in the history
When running a region with many concurrent batches, outputting at every year timestep creates a bottleneck in the run. Output at the monthly timestep is correspondingly worse.

This branch implements holding output data for a subset of our output options (specifically the outputs required for the Four Basins run, plus a few extra). Outputs for all combinations of timestep and granularity were identical to those from the current master branch for all timestep and granularity combinations.

Note that if outputs are specified for which holding is not implemented the entire run will be slowed.

The default time to hold is 1 year, so the model will behave as historically expected for yearly outputs. Monthly outputs will be held until the end of the year timestep.
  • Loading branch information
tobeycarman authored Dec 2, 2021
2 parents d09ec14 + a2a157a commit 1ad4053
Show file tree
Hide file tree
Showing 7 changed files with 978 additions and 211 deletions.
3 changes: 2 additions & 1 deletion config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"output_nc_eq": 0,
"output_nc_sp": 1,
"output_nc_tr": 1,
"output_nc_sc": 1
"output_nc_sc": 1,
"output_interval": 1
},

// Define storage locations for json files generated and used
Expand Down
2 changes: 1 addition & 1 deletion config/output_spec.csv
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ DRIVINGTAIR,Input driving air temperature data,degree_C,invalid,invalid,,invalid
DRIVINGVAPO,Input driving vapor pressure,hPa,invalid,invalid,,invalid,invalid,invalid,float,
DWDC,Dead woody debris C,g/m2/time,,,invalid,invalid,invalid,invalid,double,
DWDN,Dead woody debris N,g/m2/time,,,invalid,invalid,invalid,invalid,double,
DWDRH,Dead woody debris HR,g/m2/time,,,invalid,invalid,invalid,invalid,double,
EET,Actual ET,mm/m2/time,,,,,invalid,invalid,
FRONTSDEPTH,Depth of fronts,mm,,,,invalid,invalid,,double,
FRONTSTYPE,Front types,unitless,,,,invalid,invalid,,int,
Expand Down Expand Up @@ -108,5 +109,4 @@ VWCMINEB,VWC middle mineral,m3/m3,,,,invalid,invalid,invalid,double,
VWCMINEC,VWC bottom mineral,m3/m3,,,,invalid,invalid,invalid,double,
VWCSHLW,VWC in fibrous layer,m3/m3,,,,invalid,invalid,invalid,double,
WATERTAB,Water table depth below surface,m,,,,invalid,invalid,invalid,double,
WDRH,Dead woody debris HR,g/m2/time,,,invalid,invalid,invalid,invalid,double,
YSD,Years since last disturbance,Years,,invalid,invalid,invalid,invalid,invalid,int,
1 change: 1 addition & 0 deletions include/ModelData.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ModelData {
bool nc_sp;
bool nc_tr;
bool nc_sc;
int output_interval; //How many years to store for output

// Maps holding data about variables to be output at specific timesteps
// C++11 would allow the use of unordered_maps, which have a faster
Expand Down
91 changes: 91 additions & 0 deletions include/OutputHolder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

/* When running a region with many concurrent batches, outputting at every
* year timestep creates a bottleneck in the run. Output at the monthly
* timestep is correspondingly worse.
*
* This class is a basic repository for output data to be held until
* outputting is triggered based on the user's specifications.
* */


#ifndef OUTPUTHOLDER_H
#define OUTPUTHOLDER_H

#include "temconst.h"
#include "layerconst.h"

class OutputHolder{
public:

// OutputHolder();
// ~OutputHolder();

void clear();

int months_held;
int years_held;

std::vector<int> ysd_for_output;

std::vector<double> ald_for_output;
std::vector<double> burnsoic_for_output;
std::vector<double> burnthick_for_output;
std::vector<double> burnveg2airc_for_output;
std::vector<double> burnveg2deadc_for_output;
std::vector<double> burnveg2soiabvc_for_output;
std::vector<double> burnveg2soiblwc_for_output;
std::vector<double> deadc_for_output;
std::vector<double> deepc_for_output;
std::vector<double> dwdc_for_output;
std::vector<double> dwdrh_for_output;
std::vector<double> minec_for_output;
std::vector<double> qdrain_for_output;
std::vector<double> qinfil_for_output;
std::vector<double> qrunoff_for_output;
std::vector<double> shlwc_for_output;
std::vector<double> snowthick_for_output;
std::vector<double> swe_for_output;
std::vector<double> watertab_for_output;

//Variables by layer
std::vector<double> rh_tot_for_output;
std::vector<std::array<double, MAX_SOI_LAY>> rh_for_output;

std::vector<std::array<double, MAX_SOI_LAY>> tlayer_for_output;
std::vector<std::array<double, MAX_SOI_LAY>> vwclayer_for_output;

//Variables by PFT
std::vector<double> eet_tot_for_output;
std::vector<std::array<double, NUM_PFT>> eet_for_output;

std::vector<double> pet_tot_for_output;
std::vector<std::array<double, NUM_PFT>> pet_for_output;

std::vector<double> trans_tot_for_output;
std::vector<std::array<double, NUM_PFT>> trans_for_output;

//Variables by PFT and Compartment both
std::vector<double> gpp_tot_for_output;
std::vector<std::array<double, NUM_PFT_PART>> gpp_part_for_output;
std::vector<std::array<double, NUM_PFT>> gpp_pft_for_output;
std::vector<std::array<std::array<double, NUM_PFT>, NUM_PFT_PART>> gpp_for_output;

std::vector<double> ltrfalc_tot_for_output;
std::vector<std::array<double, NUM_PFT_PART>> ltrfalc_part_for_output;
std::vector<std::array<double, NUM_PFT>> ltrfalc_pft_for_output;
std::vector<std::array<std::array<double, NUM_PFT>, NUM_PFT_PART>> ltrfalc_for_output;

std::vector<double> npp_tot_for_output;
std::vector<std::array<double, NUM_PFT_PART>> npp_part_for_output;
std::vector<std::array<double, NUM_PFT>> npp_pft_for_output;
std::vector<std::array<std::array<double, NUM_PFT>, NUM_PFT_PART>> npp_for_output;

std::vector<double> vegc_tot_for_output;
std::vector<std::array<double, NUM_PFT_PART>> vegc_part_for_output;
std::vector<std::array<double, NUM_PFT>> vegc_pft_for_output;
std::vector<std::array<std::array<double, NUM_PFT>, NUM_PFT_PART>> vegc_for_output;

};


#endif /* OUTPUTHOLDER_H */
11 changes: 7 additions & 4 deletions include/Runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "CalController.h"
#include "ArgHandler.h"
#include "util_structs.h"
#include "OutputHolder.h"

using namespace std;

Expand Down Expand Up @@ -61,9 +62,9 @@ class Runner {
void output_debug_daily_drivers(int iy, boost::filesystem::path p);

//void output_netCDF(int year, boost::filesystem::path p);
void output_netCDF_monthly(int year, int month, std::string stage);
void output_netCDF_yearly(int year, std::string stage);
void output_netCDF(std::map<std::string, OutputSpec> &outputs, int year, int month, std::string stage);
void output_netCDF_monthly(int year, int month, std::string stage, int endyr);
void output_netCDF_yearly(int year, std::string stage, int endyr);
void output_netCDF(std::map<std::string, OutputSpec> &outputs, int year, int month, std::string stage, int endyr);


template<typename PTYPE>
Expand Down Expand Up @@ -95,7 +96,9 @@ class Runner {

deque<RestartData> mlyres;

void monthly_output(const int year, const int month, const std::string& runstage);
OutputHolder outhold;

void monthly_output(const int year, const int month, const std::string& runstage, int endyr);
void yearly_output(const int year, const std::string& stage, const int startyr, const int endyr);

};
Expand Down
1 change: 1 addition & 0 deletions src/ModelData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ ModelData::ModelData(Json::Value controldata):force_cmt(-1) {
nc_sp = controldata["IO"]["output_nc_sp"].asBool();
nc_tr = controldata["IO"]["output_nc_tr"].asBool();
nc_sc = controldata["IO"]["output_nc_sc"].asBool();
output_interval = controldata["IO"]["output_interval"].asInt();

pid_tag = controldata["calibration-IO"]["pid_tag"].asString();
caldata_tree_loc = controldata["calibration-IO"]["caldata_tree_loc"].asString();
Expand Down
Loading

0 comments on commit 1ad4053

Please sign in to comment.