Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing catchment id to CatchmentAggrDataSelector #480

Merged
merged 2 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/realizations/catchment/Simple_Lumped_Model_Realization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,37 @@ double Simple_Lumped_Model_Realization::calc_et()
* @param d_delta_s The duration, in seconds, of the time step for which to run model calculations.
* @return The total discharge for this time step.
*/
double Simple_Lumped_Model_Realization::get_response(time_step_t t, time_step_t dt)
double Simple_Lumped_Model_Realization::get_response(time_step_t t_index, time_step_t t_delta_s)
{
//TODO input_et = this->forcing.get_et(t)
double precip;
time_t t_unix = this->forcing->get_data_start_time() + (t * 3600);
try {
precip = this->forcing->get_value(CatchmentAggrDataSelector("","precip_rate", t_unix, dt, "")); // classic forcing object/format
//Checking the time step used is consistent with that provided in forcing data
time_t t_delta = this->forcing->record_duration();
if (t_delta != t_delta_s) { //Checking the time step used is consistent with that provided in forcing data
throw std::invalid_argument("Getting response using insonsistent time step with provided forcing data");
}
//Negative t_index is not allowed
if (t_index < 0) {
throw std::invalid_argument("Getting response of negative time step in Tshirt C Realization is not allowed.");
}
catch (const std::exception& e){
precip = this->forcing->get_value(CatchmentAggrDataSelector("",CSDMS_STD_NAME_LIQUID_EQ_PRECIP_RATE, t_unix, dt, "")); // CsvPerFeatureForcingProvider

time_t start_time = this->forcing->get_data_start_time();
time_t stop_time = this->forcing->get_data_stop_time();
time_t t_current = start_time + t_index * t_delta_s;
//Ensure model run does not exceed the end time of forcing
if (t_current > stop_time) {
throw std::invalid_argument("Getting response beyond time with available forcing.");
}
add_time(t+1, params.n);

double precip;
precip = this->forcing->get_value(CatchmentAggrDataSelector(this->id, CSDMS_STD_NAME_LIQUID_EQ_PRECIP_RATE, t_current, t_delta_s, ""), data_access::SUM);
add_time(t_index+1, params.n);
//FIXME should this run "daily" or hourly (t) which should really be dt
//Do we keep an "internal dt" i.e. this->dt and reconcile with t?
//hymod_kernel::run(68400.0, params, state[t], state[t+1], fluxes[t], precip, et_params);

pdm03_struct params_copy = get_et_params();
hymod_kernel::run(dt, params, state[t], state[t+1], fluxes[t], precip*dt, &params_copy);
return fluxes[t].slow_flow_meters_per_second + fluxes[t].runoff_meters_per_second;
hymod_kernel::run(t_delta_s, params, state[t_index], state[t_index+1], fluxes[t_index], precip*t_delta_s, &params_copy);
return fluxes[t_index].slow_flow_meters_per_second + fluxes[t_index].runoff_meters_per_second;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/realizations/catchment/Tshirt_C_Realization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,10 @@ double Tshirt_C_Realization::get_response(time_step_t t_index, time_step_t t_del
if (t_current > stop_time) {
throw std::invalid_argument("Getting response beyond time with available forcing.");
}

double precip;
const std::string forcing_name = CSDMS_STD_NAME_LIQUID_EQ_PRECIP_RATE;
precip = this->forcing->get_value(CatchmentAggrDataSelector("",CSDMS_STD_NAME_LIQUID_EQ_PRECIP_RATE, t_current, t_delta_s, ""), data_access::SUM);
precip = this->forcing->get_value(CatchmentAggrDataSelector(this->catchment_id, CSDMS_STD_NAME_LIQUID_EQ_PRECIP_RATE, t_current, t_delta_s, ""), data_access::SUM);
int response_result = run_formulation_for_timestep(precip, t_delta_s);
// TODO: check t_index is the next expected time step to be calculated

Expand Down
3 changes: 2 additions & 1 deletion src/realizations/catchment/Tshirt_Realization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ double Tshirt_Realization::get_response(time_step_t t_index, time_step_t t_delta
if (t_current > stop_time) {
throw std::invalid_argument("Getting response beyond time with available forcing.");
}

double precip;
const std::string forcing_name = CSDMS_STD_NAME_LIQUID_EQ_PRECIP_RATE;
precip = this->forcing->get_value(CatchmentAggrDataSelector("",CSDMS_STD_NAME_LIQUID_EQ_PRECIP_RATE, t_current, t_delta_s, ""), data_access::SUM);
precip = this->forcing->get_value(CatchmentAggrDataSelector(this->catchment_id, CSDMS_STD_NAME_LIQUID_EQ_PRECIP_RATE, t_current, t_delta_s, ""), data_access::SUM);
//FIXME should this run "daily" or hourly (t) which should really be dt
//Do we keep an "internal dt" i.e. this->dt and reconcile with t?
int error = model->run(t_index, precip * t_delta_s / 1000, get_et_params_ptr());
Expand Down