From 1dc985e118d019a66af8ff6e8b8525345f1cf785 Mon Sep 17 00:00:00 2001 From: Phil Miller Date: Tue, 7 May 2024 11:23:42 -0400 Subject: [PATCH] Remove scalar overload of get_var_value_as_double 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. --- include/realizations/catchment/Bmi_C_Formulation.hpp | 1 - .../realizations/catchment/Bmi_Cpp_Formulation.hpp | 1 - include/realizations/catchment/Bmi_Formulation.hpp | 12 ------------ .../catchment/Bmi_Fortran_Formulation.hpp | 1 - .../realizations/catchment/Bmi_Multi_Formulation.hpp | 1 - .../realizations/catchment/Bmi_Py_Formulation.hpp | 1 - src/realizations/catchment/Bmi_Formulation.cpp | 4 ---- .../catchment/Bmi_Module_Formulation.cpp | 6 +++--- src/realizations/catchment/Bmi_Multi_Formulation.cpp | 6 +++--- .../catchments/Bmi_C_Formulation_Test.cpp | 2 +- test/realizations/catchments/Bmi_C_Pet_IT.cpp | 2 +- .../catchments/Bmi_Cpp_Formulation_Test.cpp | 2 +- .../catchments/Bmi_Cpp_Multi_Array_Test.cpp | 2 +- .../catchments/Bmi_Fortran_Formulation_Test.cpp | 2 +- .../catchments/Bmi_Multi_Formulation_Test.cpp | 4 ++-- .../catchments/Bmi_Py_Formulation_Test.cpp | 2 +- 16 files changed, 14 insertions(+), 35 deletions(-) diff --git a/include/realizations/catchment/Bmi_C_Formulation.hpp b/include/realizations/catchment/Bmi_C_Formulation.hpp index 64823cff19..fd0f010ef8 100644 --- a/include/realizations/catchment/Bmi_C_Formulation.hpp +++ b/include/realizations/catchment/Bmi_C_Formulation.hpp @@ -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``. diff --git a/include/realizations/catchment/Bmi_Cpp_Formulation.hpp b/include/realizations/catchment/Bmi_Cpp_Formulation.hpp index 42c951e6b0..b8d0dd7f8c 100644 --- a/include/realizations/catchment/Bmi_Cpp_Formulation.hpp +++ b/include/realizations/catchment/Bmi_Cpp_Formulation.hpp @@ -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; diff --git a/include/realizations/catchment/Bmi_Formulation.hpp b/include/realizations/catchment/Bmi_Formulation.hpp index 56fb1a0e85..e6a4495c31 100644 --- a/include/realizations/catchment/Bmi_Formulation.hpp +++ b/include/realizations/catchment/Bmi_Formulation.hpp @@ -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. * diff --git a/include/realizations/catchment/Bmi_Fortran_Formulation.hpp b/include/realizations/catchment/Bmi_Fortran_Formulation.hpp index 7c72004e8a..8570b87e22 100644 --- a/include/realizations/catchment/Bmi_Fortran_Formulation.hpp +++ b/include/realizations/catchment/Bmi_Fortran_Formulation.hpp @@ -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; diff --git a/include/realizations/catchment/Bmi_Multi_Formulation.hpp b/include/realizations/catchment/Bmi_Multi_Formulation.hpp index 5f6d9cb594..afd75d87ab 100644 --- a/include/realizations/catchment/Bmi_Multi_Formulation.hpp +++ b/include/realizations/catchment/Bmi_Multi_Formulation.hpp @@ -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. diff --git a/include/realizations/catchment/Bmi_Py_Formulation.hpp b/include/realizations/catchment/Bmi_Py_Formulation.hpp index 501a97e5d7..644648c208 100644 --- a/include/realizations/catchment/Bmi_Py_Formulation.hpp +++ b/include/realizations/catchment/Bmi_Py_Formulation.hpp @@ -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``. diff --git a/src/realizations/catchment/Bmi_Formulation.cpp b/src/realizations/catchment/Bmi_Formulation.cpp index 015d3810c4..008add30a1 100644 --- a/src/realizations/catchment/Bmi_Formulation.cpp +++ b/src/realizations/catchment/Bmi_Formulation.cpp @@ -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 Bmi_Formulation::OPTIONAL_PARAMETERS = { BMI_REALIZATION_CFG_PARAM_OPT__FORCING_FILE, BMI_REALIZATION_CFG_PARAM_OPT__VAR_STD_NAMES, diff --git a/src/realizations/catchment/Bmi_Module_Formulation.cpp b/src/realizations/catchment/Bmi_Module_Formulation.cpp index b64ca20a38..57ce360a83 100644 --- a/src/realizations/catchment/Bmi_Module_Formulation.cpp +++ b/src/realizations/catchment/Bmi_Module_Formulation.cpp @@ -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; } @@ -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) { @@ -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); diff --git a/src/realizations/catchment/Bmi_Multi_Formulation.cpp b/src/realizations/catchment/Bmi_Multi_Formulation.cpp index a9734c6385..2bce6e6af6 100644 --- a/src/realizations/catchment/Bmi_Multi_Formulation.cpp +++ b/src/realizations/catchment/Bmi_Multi_Formulation.cpp @@ -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(); } @@ -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) { diff --git a/test/realizations/catchments/Bmi_C_Formulation_Test.cpp b/test/realizations/catchments/Bmi_C_Formulation_Test.cpp index 65073b214e..162bde0e94 100644 --- a/test/realizations/catchments/Bmi_C_Formulation_Test.cpp +++ b/test/realizations/catchments/Bmi_C_Formulation_Test.cpp @@ -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) { diff --git a/test/realizations/catchments/Bmi_C_Pet_IT.cpp b/test/realizations/catchments/Bmi_C_Pet_IT.cpp index 3455312d91..70568781f9 100644 --- a/test/realizations/catchments/Bmi_C_Pet_IT.cpp +++ b/test/realizations/catchments/Bmi_C_Pet_IT.cpp @@ -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; diff --git a/test/realizations/catchments/Bmi_Cpp_Formulation_Test.cpp b/test/realizations/catchments/Bmi_Cpp_Formulation_Test.cpp index a7b6d407dc..9898fd6f0c 100644 --- a/test/realizations/catchments/Bmi_Cpp_Formulation_Test.cpp +++ b/test/realizations/catchments/Bmi_Cpp_Formulation_Test.cpp @@ -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) { diff --git a/test/realizations/catchments/Bmi_Cpp_Multi_Array_Test.cpp b/test/realizations/catchments/Bmi_Cpp_Multi_Array_Test.cpp index f572933a5b..36aa2b783f 100644 --- a/test/realizations/catchments/Bmi_Cpp_Multi_Array_Test.cpp +++ b/test/realizations/catchments/Bmi_Cpp_Multi_Array_Test.cpp @@ -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 nested = std::static_pointer_cast(formulation.modules[mod_index]); - return nested->get_var_value_as_double(var_name); + return nested->get_var_value_as_double(0, var_name); } template diff --git a/test/realizations/catchments/Bmi_Fortran_Formulation_Test.cpp b/test/realizations/catchments/Bmi_Fortran_Formulation_Test.cpp index 3808db35e2..7b4b4eeb73 100644 --- a/test/realizations/catchments/Bmi_Fortran_Formulation_Test.cpp +++ b/test/realizations/catchments/Bmi_Fortran_Formulation_Test.cpp @@ -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) { diff --git a/test/realizations/catchments/Bmi_Multi_Formulation_Test.cpp b/test/realizations/catchments/Bmi_Multi_Formulation_Test.cpp index a9775a7b48..19241eb8fd 100644 --- a/test/realizations/catchments/Bmi_Multi_Formulation_Test.cpp +++ b/test/realizations/catchments/Bmi_Multi_Formulation_Test.cpp @@ -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 nested = std::static_pointer_cast(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){ @@ -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) { diff --git a/test/realizations/catchments/Bmi_Py_Formulation_Test.cpp b/test/realizations/catchments/Bmi_Py_Formulation_Test.cpp index 7ca6252564..73c46bcdb5 100644 --- a/test/realizations/catchments/Bmi_Py_Formulation_Test.cpp +++ b/test/realizations/catchments/Bmi_Py_Formulation_Test.cpp @@ -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) {