Skip to content

Commit

Permalink
Refactor Bmi_Formulation: Share duplicate implementations of scalar g…
Browse files Browse the repository at this point in the history
…et_var_value_as_double
  • Loading branch information
PhilMiller authored and donaldwj committed May 10, 2024
1 parent f943886 commit ecf035d
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 49 deletions.
13 changes: 1 addition & 12 deletions include/realizations/catchment/Bmi_C_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,6 @@ namespace realization {
return (T) outputs[t_index];
}

/**
* 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 actual 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) override;

/**
* Get value for some BMI model variable at a specific index.
*
Expand All @@ -99,6 +87,7 @@ 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
3 changes: 1 addition & 2 deletions include/realizations/catchment/Bmi_Cpp_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ namespace realization {
return (T) outputs[t_index];
}

double get_var_value_as_double(const std::string& var_name) override;

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
2 changes: 1 addition & 1 deletion include/realizations/catchment/Bmi_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ namespace realization {
* @param var_name
* @return
*/
virtual double get_var_value_as_double(const std::string& var_name) = 0;
double get_var_value_as_double(const std::string& var_name);

/**
* Get value for some BMI model variable at a specific index.
Expand Down
3 changes: 1 addition & 2 deletions include/realizations/catchment/Bmi_Fortran_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ namespace realization {
return (time_t) (get_bmi_model()->convert_model_time_to_seconds(model_time));
}

double get_var_value_as_double(const std::string &var_name) override;

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
15 changes: 1 addition & 14 deletions include/realizations/catchment/Bmi_Multi_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,20 +531,6 @@ namespace realization {
*/
void create_multi_formulation(geojson::PropertyMap properties, bool needs_param_validation);

/**
* 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 actual 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) override {
return get_var_value_as_double(0, var_name);
}

/**
* Get value for some BMI model variable at a specific index.
*
Expand Down Expand Up @@ -590,6 +576,7 @@ 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
3 changes: 1 addition & 2 deletions include/realizations/catchment/Bmi_Py_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ namespace realization {

time_t convert_model_time(const double &model_time) override;

double get_var_value_as_double(const std::string &var_name) 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_C_Formulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ std::shared_ptr<Bmi_Adapter> Bmi_C_Formulation::construct_model(const geojson::P
output);
}

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

double Bmi_C_Formulation::get_var_value_as_double(const int& index, const std::string& var_name) {
// TODO: consider different way of handling (and how to document) cases like long double or unsigned long long that
// don't fit or might convert inappropriately
Expand Down
4 changes: 0 additions & 4 deletions src/realizations/catchment/Bmi_Cpp_Formulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ std::shared_ptr<Bmi_Adapter> Bmi_Cpp_Formulation::construct_model(const geojson:
output);
}

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

double Bmi_Cpp_Formulation::get_var_value_as_double(const int& index, const std::string& var_name) {
// TODO: consider different way of handling (and how to document) cases like long double or unsigned long long that
// don't fit or might convert inappropriately
Expand Down
4 changes: 4 additions & 0 deletions src/realizations/catchment/Bmi_Formulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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
4 changes: 0 additions & 4 deletions src/realizations/catchment/Bmi_Fortran_Formulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ std::string Bmi_Fortran_Formulation::get_formulation_type() {
return "bmi_fortran";
}

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

double Bmi_Fortran_Formulation::get_var_value_as_double(const int &index, const std::string &var_name) {
auto model = std::dynamic_pointer_cast<models::bmi::Bmi_Fortran_Adapter>(get_bmi_model());

Expand Down
4 changes: 0 additions & 4 deletions src/realizations/catchment/Bmi_Py_Formulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ std::string Bmi_Py_Formulation::get_formulation_type() {
return "bmi_py";
}

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

double Bmi_Py_Formulation::get_var_value_as_double(const int &index, const std::string &var_name) {
auto model = std::dynamic_pointer_cast<models::bmi::Bmi_Py_Adapter>(get_bmi_model());

Expand Down

0 comments on commit ecf035d

Please sign in to comment.