Skip to content

Commit

Permalink
Remove scalar overload of get_var_value_as_double
Browse files Browse the repository at this point in the history
The baked-in assumption that the requested variable was the sole
element of its array was troublesome. In PR review, Donald suggested
it was time to get rid of it.
  • Loading branch information
PhilMiller authored and donaldwj committed May 10, 2024
1 parent ecf035d commit 1dc985e
Show file tree
Hide file tree
Showing 16 changed files with 14 additions and 35 deletions.
1 change: 0 additions & 1 deletion include/realizations/catchment/Bmi_C_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ namespace realization {
* @return
*/
double get_var_value_as_double(const int& index, const std::string& var_name) override;
using Bmi_Formulation::get_var_value_as_double;

/**
* Test whether backing model has run BMI ``Initialize``.
Expand Down
1 change: 0 additions & 1 deletion include/realizations/catchment/Bmi_Cpp_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ namespace realization {
}

double get_var_value_as_double(const int& index, const std::string& var_name) override;
using Bmi_Formulation::get_var_value_as_double;

bool is_model_initialized() override;

Expand Down
12 changes: 0 additions & 12 deletions include/realizations/catchment/Bmi_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,6 @@ namespace realization {
*output_text_stream << std::setprecision(output_precision);
}

/**
* Get value for some BMI model variable.
*
* This function assumes that the given variable, while returned by the model within an array per the BMI spec,
* is actually a single, scalar value. Thus, it returns what is at index 0 of the array reference.
*
* @param index
* @param var_name
* @return
*/
double get_var_value_as_double(const std::string& var_name);

/**
* Get value for some BMI model variable at a specific index.
*
Expand Down
1 change: 0 additions & 1 deletion include/realizations/catchment/Bmi_Fortran_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ namespace realization {
}

double get_var_value_as_double(const int &index, const std::string &var_name) override;
using Bmi_Formulation::get_var_value_as_double;

friend class Bmi_Multi_Formulation;

Expand Down
1 change: 0 additions & 1 deletion include/realizations/catchment/Bmi_Multi_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ namespace realization {
// TODO: look at adjusting defs to move this function up in class hierarchy (or at least add TODO there)
}
}
using Bmi_Formulation::get_var_value_as_double;

/**
* Initialize the deferred associations with the providers in @ref deferredProviders.
Expand Down
1 change: 0 additions & 1 deletion include/realizations/catchment/Bmi_Py_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ namespace realization {
time_t convert_model_time(const double &model_time) override;

double get_var_value_as_double(const int &index, const std::string &var_name) override;
using Bmi_Formulation::get_var_value_as_double;

/**
* Test whether backing model has run BMI ``Initialize``.
Expand Down
4 changes: 0 additions & 4 deletions src/realizations/catchment/Bmi_Formulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

namespace realization
{
double Bmi_Formulation::get_var_value_as_double(const std::string& var_name) {
return this->get_var_value_as_double(0, var_name);
}

const std::vector<std::string> Bmi_Formulation::OPTIONAL_PARAMETERS = {
BMI_REALIZATION_CFG_PARAM_OPT__FORCING_FILE,
BMI_REALIZATION_CFG_PARAM_OPT__VAR_STD_NAMES,
Expand Down
6 changes: 3 additions & 3 deletions src/realizations/catchment/Bmi_Module_Formulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace realization {
std::string output_str;

for (const std::string& name : get_output_variable_names()) {
output_str += (output_str.empty() ? "" : ",") + std::to_string(get_var_value_as_double(name));
output_str += (output_str.empty() ? "" : ",") + std::to_string(get_var_value_as_double(0, name));
}
return output_str;
}
Expand Down Expand Up @@ -75,7 +75,7 @@ namespace realization {
// TODO: again, consider whether we should store any historic response, ts_delta, or other var values
next_time_step_index++;
}
return get_var_value_as_double( get_bmi_main_output_var());
return get_var_value_as_double(0, get_bmi_main_output_var());
}

time_t Bmi_Module_Formulation::get_variable_time_begin(const std::string &variable_name) {
Expand Down Expand Up @@ -201,7 +201,7 @@ namespace realization {
if( !bmi_var_name.empty() )
{
//Get forcing value from BMI variable
double value = get_var_value_as_double(bmi_var_name);
double value = get_var_value_as_double(0, bmi_var_name);

// Convert units
std::string native_units = get_bmi_model()->GetVarUnits(bmi_var_name);
Expand Down
6 changes: 3 additions & 3 deletions src/realizations/catchment/Bmi_Multi_Formulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ std::string Bmi_Multi_Formulation::get_output_line_for_timestep(int timestep, st
if (output_var_names.empty()) { return ""; }

// Do the first separately, without the leading comma
*output_text_stream << get_var_value_as_double(output_var_names[0]);
*output_text_stream << get_var_value_as_double(0, output_var_names[0]);

// Do the rest with a leading comma
for (int i = 1; i < output_var_names.size(); ++i) {
*output_text_stream << delimiter << get_var_value_as_double(output_var_names[i]);
*output_text_stream << delimiter << get_var_value_as_double(0, output_var_names[i]);
}
return output_text_stream->str();
}
Expand Down Expand Up @@ -391,7 +391,7 @@ double Bmi_Multi_Formulation::get_response(time_step_t t_index, time_step_t t_de
}
}

return modules[index]->get_var_value_as_double(get_bmi_main_output_var());
return modules[index]->get_var_value_as_double(0, get_bmi_main_output_var());
}

bool Bmi_Multi_Formulation::is_bmi_input_variable(const std::string &var_name) {
Expand Down
2 changes: 1 addition & 1 deletion test/realizations/catchments/Bmi_C_Formulation_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Bmi_C_Formulation_Test : public ::testing::Test {
}

static double get_friend_var_value_as_double(Bmi_C_Formulation& formulation, const std::string& var_name) {
return formulation.get_var_value_as_double(var_name);
return formulation.get_var_value_as_double(0, var_name);
}

static time_t parse_forcing_time(const std::string& date_time_str) {
Expand Down
2 changes: 1 addition & 1 deletion test/realizations/catchments/Bmi_C_Pet_IT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Bmi_C_Pet_IT : public ::testing::Test {
}

static double get_friend_var_value_as_double(Bmi_C_Formulation& formulation, const string& var_name) {
return formulation.get_var_value_as_double(var_name);
return formulation.get_var_value_as_double(0, var_name);
}

void SetUp() override;
Expand Down
2 changes: 1 addition & 1 deletion test/realizations/catchments/Bmi_Cpp_Formulation_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Bmi_Cpp_Formulation_Test : public ::testing::Test {
}

static double get_friend_var_value_as_double(Bmi_Cpp_Formulation& formulation, const std::string& var_name) {
return formulation.get_var_value_as_double(var_name);
return formulation.get_var_value_as_double(0, var_name);
}

static time_t parse_forcing_time(const std::string& date_time_str) {
Expand Down
2 changes: 1 addition & 1 deletion test/realizations/catchments/Bmi_Cpp_Multi_Array_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Bmi_Cpp_Multi_Array_Test : public ::testing::Test {
static double get_friend_nested_var_value(const Bmi_Multi_Formulation& formulation, const int mod_index,
const std::string& var_name) {
std::shared_ptr<N> nested = std::static_pointer_cast<N>(formulation.modules[mod_index]);
return nested->get_var_value_as_double(var_name);
return nested->get_var_value_as_double(0, var_name);
}

template <class N, class M>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Bmi_Fortran_Formulation_Test : public ::testing::Test {
}

static double get_friend_var_value_as_double(Bmi_Fortran_Formulation& formulation, const std::string& var_name) {
return formulation.get_var_value_as_double(var_name);
return formulation.get_var_value_as_double(0, var_name);
}

static std::string get_friend_output_header_line(Bmi_Fortran_Formulation& formulation, std::string delim) {
Expand Down
4 changes: 2 additions & 2 deletions test/realizations/catchments/Bmi_Multi_Formulation_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Bmi_Multi_Formulation_Test : public ::testing::Test {
static double get_friend_nested_var_value(const Bmi_Multi_Formulation& formulation, const int mod_index,
const std::string& var_name) {
std::shared_ptr<N> nested = std::static_pointer_cast<N>(formulation.modules[mod_index]);
return nested->get_var_value_as_double(var_name);
return nested->get_var_value_as_double(0, var_name);
}

static std::string get_friend_catchment_id(Bmi_Multi_Formulation& formulation){
Expand Down Expand Up @@ -121,7 +121,7 @@ class Bmi_Multi_Formulation_Test : public ::testing::Test {

/*
static double get_friend_var_value_as_double(Bmi_Multi_Formulation& formulation, const string& var_name) {
return formulation.get_var_value_as_double(var_name);
return formulation.get_var_value_as_double(0, var_name);
}
static time_t parse_forcing_time(const std::string& date_time_str) {
Expand Down
2 changes: 1 addition & 1 deletion test/realizations/catchments/Bmi_Py_Formulation_Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Bmi_Py_Formulation_Test : public ::testing::Test {
}

static double get_friend_var_value_as_double(Bmi_Py_Formulation& formulation, const std::string& var_name) {
return formulation.get_var_value_as_double(var_name);
return formulation.get_var_value_as_double(0, var_name);
}

static time_t parse_forcing_time(const std::string& date_time_str) {
Expand Down

0 comments on commit 1dc985e

Please sign in to comment.