diff --git a/include/forcing/DeferredWrappedProvider.hpp b/include/forcing/DeferredWrappedProvider.hpp index d82984ac69..5ffd86674a 100644 --- a/include/forcing/DeferredWrappedProvider.hpp +++ b/include/forcing/DeferredWrappedProvider.hpp @@ -137,7 +137,7 @@ namespace data_access { } // Confirm this will provide everything needed - const vector &available = provider->get_available_variable_names(); + const std::vector &available = provider->get_available_variable_names(); for (const std::string &requiredName : providedOutputs) { if (std::find(available.begin(), available.end(), requiredName) == available.end()) { setMessage = "Given provider does not provide the required " + requiredName; diff --git a/include/forcing/OptionalWrappedDataProvider.hpp b/include/forcing/OptionalWrappedDataProvider.hpp index 61843f4af6..1ca37330fd 100644 --- a/include/forcing/OptionalWrappedDataProvider.hpp +++ b/include/forcing/OptionalWrappedDataProvider.hpp @@ -69,7 +69,7 @@ namespace data_access { msg += ", " + providedOutputs[i]; } msg += "])"; - throw runtime_error(msg); + throw std::runtime_error(msg); } } } @@ -105,7 +105,7 @@ namespace data_access { def_it++; } msg += "])"; - throw runtime_error(msg); + throw std::runtime_error(msg); } } // Assuming the mapping is valid, set it for the instance @@ -199,11 +199,11 @@ namespace data_access { // Balk if not in this instance's collection of outputs if (find(providedOutputs.begin(), providedOutputs.end(), output_name) == providedOutputs.end()) { - throw runtime_error("Unknown output " + output_name + " requested from wrapped provider"); + throw std::runtime_error("Unknown output " + output_name + " requested from wrapped provider"); } // Balk if this instance is not ready if (!isReadyToProvideData()) { - throw runtime_error("Cannot get value for " + output_name + throw std::runtime_error("Cannot get value for " + output_name + " from optional wrapped provider before it is ready"); } diff --git a/include/realizations/catchment/AbstractCLibBmiAdapter.hpp b/include/realizations/catchment/AbstractCLibBmiAdapter.hpp index a723bee021..0eea6ed911 100644 --- a/include/realizations/catchment/AbstractCLibBmiAdapter.hpp +++ b/include/realizations/catchment/AbstractCLibBmiAdapter.hpp @@ -26,7 +26,7 @@ namespace models { * @param registration_func The name for the @see bmi_registration_function. * @param output The output stream handler. */ - AbstractCLibBmiAdapter(const string &type_name, std::string library_file_path, std::string bmi_init_config, + AbstractCLibBmiAdapter(const std::string &type_name, std::string library_file_path, std::string bmi_init_config, std::string forcing_file_path, bool allow_exceed_end, bool has_fixed_time_step, std::string registration_func, utils::StreamHandler output) : Bmi_Adapter(type_name, std::move(bmi_init_config), std::move(forcing_file_path), @@ -91,7 +91,7 @@ namespace models { if (!utils::FileChecker::file_is_readable(bmi_lib_file)) { //Try alternative extension... size_t idx = bmi_lib_file.rfind("."); - if(idx == string::npos){ + if(idx == std::string::npos){ idx = bmi_lib_file.length()-1; } std::string alt_bmi_lib_file; diff --git a/include/realizations/catchment/Bmi_Adapter.hpp b/include/realizations/catchment/Bmi_Adapter.hpp index d11678c3e1..ea06a729f8 100644 --- a/include/realizations/catchment/Bmi_Adapter.hpp +++ b/include/realizations/catchment/Bmi_Adapter.hpp @@ -9,8 +9,6 @@ #include "State_Exception.hpp" #include "StreamHandler.hpp" -using namespace std; - namespace models { namespace bmi { /** @@ -21,7 +19,7 @@ namespace models { class Bmi_Adapter : public ::bmi::Bmi { public: - Bmi_Adapter(string model_name, string bmi_init_config, string forcing_file_path, bool allow_exceed_end, + Bmi_Adapter(std::string model_name, std::string bmi_init_config, std::string forcing_file_path, bool allow_exceed_end, bool has_fixed_time_step, utils::StreamHandler output) : model_name(std::move(model_name)), bmi_init_config(std::move(bmi_init_config)), @@ -37,7 +35,7 @@ namespace models { if (!utils::FileChecker::file_is_readable(this->bmi_init_config)) { init_exception_msg = "Cannot create and initialize " + this->model_name + " using unreadable file '" + this->bmi_init_config + "'"; - throw runtime_error(init_exception_msg); + throw std::runtime_error(init_exception_msg); } } @@ -93,7 +91,7 @@ namespace models { * @param time_convert_factor A reference to set to the determined conversion factor. */ void acquire_time_conversion_factor(double &time_convert_factor) { - string time_units = GetTimeUnits(); + std::string time_units = GetTimeUnits(); if (time_units == "s" || time_units == "sec" || time_units == "second" || time_units == "seconds") time_convert_factor = 1.0; else if (time_units == "m" || time_units == "min" || time_units == "minute" || @@ -104,7 +102,7 @@ namespace models { else if (time_units == "d" || time_units == "day" || time_units == "days") time_convert_factor = 86400.0; else - throw runtime_error( + throw std::runtime_error( "Invalid model time step units ('" + time_units + "') in " + model_name + "."); } @@ -177,7 +175,7 @@ namespace models { // If there was previous init attempt but w/ failure exception, throw runtime error and include previous // message if (model_initialized && !init_exception_msg.empty()) { - throw runtime_error( + throw std::runtime_error( "Previous " + model_name + " init attempt had exception: \n\t" + init_exception_msg); } // If there was previous init attempt w/ (implicitly) no exception on previous attempt, just return @@ -187,7 +185,7 @@ namespace models { else if (!utils::FileChecker::file_is_readable(bmi_init_config)) { init_exception_msg = "Cannot initialize " + model_name + " using unreadable file '" + bmi_init_config + "'"; - throw runtime_error(init_exception_msg); + throw std::runtime_error(init_exception_msg); } else { try { @@ -198,7 +196,7 @@ namespace models { acquire_time_conversion_factor(bmi_model_time_convert_factor); } // Record the exception message before re-throwing to handle subsequent function calls properly - catch (exception& e) { + catch (std::exception& e) { // Make sure this is set to 'true' after this function call finishes model_initialized = true; throw e; @@ -224,9 +222,9 @@ namespace models { * @throws models::external::State_Exception If `initialize()` in nested model is not successful. * @throws runtime_error If already initialized but using a different file than the passed argument. */ - void Initialize(string config_file) override { + void Initialize(std::string config_file) override { if (config_file != bmi_init_config && model_initialized) { - throw runtime_error( + throw std::runtime_error( "Model init previously attempted; cannot change config from " + bmi_init_config + " to " + config_file); } @@ -243,7 +241,7 @@ namespace models { throw e; } catch (std::exception &e) { - throw runtime_error(e.what()); + throw std::runtime_error(e.what()); } } @@ -270,28 +268,28 @@ namespace models { /** Whether model ``Update`` calls are allowed and handled in some way by the backing model. */ bool allow_model_exceed_end_time = false; /** Path (as a string) to the BMI config file for initializing the backing model (empty if none). */ - string bmi_init_config; + std::string bmi_init_config; /** Pointer to backing BMI model instance. */ - shared_ptr bmi_model = nullptr; + std::shared_ptr bmi_model = nullptr; /** Whether this particular model has a time step size that cannot be changed internally or externally. */ bool bmi_model_has_fixed_time_step = true; /** Conversion factor for converting values for model time in model's unit type to equivalent in seconds. */ double bmi_model_time_convert_factor; /** Pointer to stored time step size value of backing model, if it is fixed and has been retrieved. */ - shared_ptr bmi_model_time_step_size = nullptr; + std::shared_ptr bmi_model_time_step_size = nullptr; /** Whether this particular model implementation directly reads input data from the forcing file. */ bool bmi_model_uses_forcing_file; - string forcing_file_path; + std::string forcing_file_path; /** Message from an exception (if encountered) on the first attempt to initialize the backing model. */ - string init_exception_msg; + std::string init_exception_msg; /** Pointer to collection of input variable names for backing model, used by ``GetInputVarNames()``. */ - shared_ptr> input_var_names; + std::shared_ptr> input_var_names; /** Whether the backing model has been initialized yet, which is always initially ``false``. */ bool model_initialized = false; - string model_name; + std::string model_name; utils::StreamHandler output; /** Pointer to collection of output variable names for backing model, used by ``GetOutputVarNames()``. */ - shared_ptr> output_var_names; + std::shared_ptr> output_var_names; /** * Construct the backing BMI model object, then call its BMI-native ``Initialize()`` function. diff --git a/include/realizations/catchment/Bmi_C_Adapter.hpp b/include/realizations/catchment/Bmi_C_Adapter.hpp index 70d0bff30f..f6f4d70e91 100755 --- a/include/realizations/catchment/Bmi_C_Adapter.hpp +++ b/include/realizations/catchment/Bmi_C_Adapter.hpp @@ -36,7 +36,7 @@ namespace models { * @param registration_func The name for the @see bmi_registration_function. * @param output The output stream handler. */ - explicit Bmi_C_Adapter(const string &type_name, std::string library_file_path, std::string forcing_file_path, + explicit Bmi_C_Adapter(const std::string &type_name, std::string library_file_path, std::string forcing_file_path, bool allow_exceed_end, bool has_fixed_time_step, const std::string& registration_func, utils::StreamHandler output); @@ -53,7 +53,7 @@ namespace models { * @param registration_func The name for the @see bmi_registration_function. * @param output The output stream handler. */ - Bmi_C_Adapter(const string &type_name, std::string library_file_path, std::string bmi_init_config, + Bmi_C_Adapter(const std::string &type_name, std::string library_file_path, std::string bmi_init_config, std::string forcing_file_path, bool allow_exceed_end, bool has_fixed_time_step, std::string registration_func, utils::StreamHandler output); @@ -81,7 +81,7 @@ namespace models { * @param output The output stream handler. * @param do_initialization Whether initialization should be performed during construction or deferred. */ - Bmi_C_Adapter(const string &type_name, std::string library_file_path, std::string bmi_init_config, + Bmi_C_Adapter(const std::string &type_name, std::string library_file_path, std::string bmi_init_config, std::string forcing_file_path, bool allow_exceed_end, bool has_fixed_time_step, std::string registration_func, utils::StreamHandler output, bool do_initialization); @@ -124,7 +124,7 @@ namespace models { finalizeForCAdapter(); } - string GetComponentName() override; + std::string GetComponentName() override; /** * Get the backing model's current time. diff --git a/include/realizations/catchment/Bmi_Cpp_Adapter.hpp b/include/realizations/catchment/Bmi_Cpp_Adapter.hpp index 24adc6c79a..e805b2e39f 100644 --- a/include/realizations/catchment/Bmi_Cpp_Adapter.hpp +++ b/include/realizations/catchment/Bmi_Cpp_Adapter.hpp @@ -134,7 +134,7 @@ namespace models { finalizeForCppAdapter(); } - string GetComponentName() override; + std::string GetComponentName() override; /** * Get the backing model's current time. diff --git a/include/realizations/catchment/Bmi_Module_Formulation.hpp b/include/realizations/catchment/Bmi_Module_Formulation.hpp index ca0720b66e..3bf2d67f62 100644 --- a/include/realizations/catchment/Bmi_Module_Formulation.hpp +++ b/include/realizations/catchment/Bmi_Module_Formulation.hpp @@ -71,7 +71,7 @@ namespace realization { * @see ForcingProvider */ //const vector &get_available_forcing_outputs() { - const vector &get_available_variable_names() override { + const std::vector &get_available_variable_names() override { if (is_model_initialized() && available_forcings.empty()) { for (const std::string &output_var_name : get_bmi_model()->GetOutputVarNames()) { available_forcings.push_back(output_var_name); @@ -97,7 +97,7 @@ namespace realization { */ time_t get_variable_time_begin(const std::string &variable_name) { // TODO: come back and implement if actually necessary for this type; for now don't use - throw runtime_error("Bmi_Modular_Formulation does not yet implement get_variable_time_begin"); + throw std::runtime_error("Bmi_Modular_Formulation does not yet implement get_variable_time_begin"); } /** @@ -126,16 +126,16 @@ namespace realization { //time_t get_forcing_output_time_end(const std::string &output_name) { time_t get_variable_time_end(const std::string &varibale_name) { // TODO: come back and implement if actually necessary for this type; for now don't use - throw runtime_error("Bmi_Module_Formulation does not yet implement get_variable_time_end"); + throw std::runtime_error("Bmi_Module_Formulation does not yet implement get_variable_time_end"); } long get_data_stop_time() override { // TODO: come back and implement if actually necessary for this type; for now don't use - throw runtime_error("Bmi_Module_Formulation does not yet implement get_data_stop_time"); + throw std::runtime_error("Bmi_Module_Formulation does not yet implement get_data_stop_time"); } long record_duration() override { - throw runtime_error("Bmi_Module_Formulation does not yet implement record_duration"); + throw std::runtime_error("Bmi_Module_Formulation does not yet implement record_duration"); } /** @@ -156,7 +156,7 @@ namespace realization { return get_bmi_model()->GetEndTime(); } - const vector &get_required_parameters() override { + const std::vector &get_required_parameters() override { return REQUIRED_PARAMETERS; } @@ -197,7 +197,7 @@ namespace realization { */ size_t get_ts_index_for_time(const time_t &epoch_time) override { // TODO: come back and implement if actually necessary for this type; for now don't use - throw runtime_error("Bmi_Singular_Formulation does not yet implement get_ts_index_for_time"); + throw std::runtime_error("Bmi_Singular_Formulation does not yet implement get_ts_index_for_time"); } /** @@ -222,7 +222,7 @@ namespace realization { //const std::vector forcing_outputs = get_available_forcing_outputs(); const std::vector forcing_outputs = get_available_variable_names(); if (std::find(forcing_outputs.begin(), forcing_outputs.end(), output_name) == forcing_outputs.end()) { - throw runtime_error(get_formulation_type() + " received invalid output forcing name " + output_name); + throw std::runtime_error(get_formulation_type() + " received invalid output forcing name " + output_name); } // TODO: do this, or something better, later; right now, just assume anything using this as a provider is // consistent with times @@ -291,7 +291,7 @@ namespace realization { //const std::vector forcing_outputs = get_available_forcing_outputs(); const std::vector forcing_outputs = get_available_variable_names(); if (std::find(forcing_outputs.begin(), forcing_outputs.end(), output_name) == forcing_outputs.end()) { - throw runtime_error(get_formulation_type() + " received invalid output forcing name " + output_name); + throw std::runtime_error(get_formulation_type() + " received invalid output forcing name " + output_name); } // TODO: do this, or something better, later; right now, just assume anything using this as a provider is // consistent with times @@ -363,11 +363,11 @@ namespace realization { return true; } - const vector get_bmi_input_variables() override { + const std::vector get_bmi_input_variables() override { return get_bmi_model()->GetInputVarNames(); } - const vector get_bmi_output_variables() override { + const std::vector get_bmi_output_variables() override { return get_bmi_model()->GetOutputVarNames(); } @@ -449,7 +449,7 @@ namespace realization { return allow_model_exceed_end_time; } - const string &get_bmi_init_config() const { + const std::string &get_bmi_init_config() const { return bmi_init_config; } @@ -462,7 +462,7 @@ namespace realization { return bmi_model; } - const string &get_forcing_file_path() const override { + const std::string &get_forcing_file_path() const override { return forcing_file_path; } @@ -733,7 +733,7 @@ namespace realization { allow_model_exceed_end_time = allow_exceed_end; } - void set_bmi_init_config(const string &init_config) { + void set_bmi_init_config(const std::string &init_config) { bmi_init_config = init_config; } @@ -763,7 +763,7 @@ namespace realization { bmi_using_forcing_file = uses_forcing_file; } - void set_forcing_file_path(const string &forcing_path) { + void set_forcing_file_path(const std::string &forcing_path) { forcing_file_path = forcing_path; } diff --git a/include/realizations/catchment/Bmi_Multi_Formulation.hpp b/include/realizations/catchment/Bmi_Multi_Formulation.hpp index b42496cfa5..0a30479892 100644 --- a/include/realizations/catchment/Bmi_Multi_Formulation.hpp +++ b/include/realizations/catchment/Bmi_Multi_Formulation.hpp @@ -126,7 +126,7 @@ namespace realization { * * @return The input variables of the first nested BMI model. */ - const std::vector get_bmi_input_variables() override { + const std::vector get_bmi_input_variables() override { return modules[0]->get_bmi_input_variables(); } @@ -137,7 +137,7 @@ namespace realization { * * @return The output variables of the last nested BMI model. */ - const std::vector get_bmi_output_variables() override { + const std::vector get_bmi_output_variables() override { return modules.back()->get_bmi_output_variables(); } @@ -258,7 +258,7 @@ namespace realization { } // If not found ... if (availableData.empty() || availableData.find(var_name) == availableData.end()) { - throw runtime_error(get_formulation_type() + " cannot get output time for unknown \"" + variable_name + "\""); + throw std::runtime_error(get_formulation_type() + " cannot get output time for unknown \"" + variable_name + "\""); } return availableData[var_name]->get_data_start_time(); } @@ -310,7 +310,7 @@ namespace realization { } // If not found ... if (availableData.empty() || availableData.find(var_name) == availableData.end()) { - throw runtime_error(get_formulation_type() + " cannot get output time for unknown \"" + variable_name + "\""); + throw std::runtime_error(get_formulation_type() + " cannot get output time for unknown \"" + variable_name + "\""); } return availableData[var_name]->get_data_stop_time(); } @@ -334,7 +334,7 @@ namespace realization { // If not found ... if (availableData.empty() || availableData.find(var_name) == availableData.end()) { - throw runtime_error(get_formulation_type() + " cannot get output record duration for unknown \"" + var_name + "\""); + throw std::runtime_error(get_formulation_type() + " cannot get output record duration for unknown \"" + var_name + "\""); } return availableData[var_name]->record_duration(); } @@ -389,7 +389,7 @@ namespace realization { */ size_t get_ts_index_for_time(const time_t &epoch_time) override { // TODO: come back and implement if actually necessary for this type; for now don't use - throw runtime_error("Bmi_Multi_Formulation does not yet implement get_ts_index_for_time"); + throw std::runtime_error("Bmi_Multi_Formulation does not yet implement get_ts_index_for_time"); } /** @@ -422,7 +422,7 @@ namespace realization { // If not found ... if (availableData.empty() || availableData.find(output_name) == availableData.end()) { - throw runtime_error(get_formulation_type() + " cannot get output value for unknown " + output_name + SOURCE_LOC); + throw std::runtime_error(get_formulation_type() + " cannot get output value for unknown " + output_name + SOURCE_LOC); } return availableData[output_name]->get_value(CatchmentAggrDataSelector(this->get_catchment_id(),output_name, init_time, duration_s, output_units), m); } @@ -435,7 +435,7 @@ namespace realization { std::string output_units = selector.get_output_units(); if (availableData.empty() || availableData.find(output_name) == availableData.end()) { - throw runtime_error(get_formulation_type() + " cannot get output values for unknown " + output_name + SOURCE_LOC); + throw std::runtime_error(get_formulation_type() + " cannot get output values for unknown " + output_name + SOURCE_LOC); } return availableData[output_name]->get_values(CatchmentAggrDataSelector(this->get_catchment_id(),output_name, init_time, duration_s, output_units), m); } @@ -480,7 +480,7 @@ namespace realization { */ bool is_property_sum_over_time_step(const std::string &name) override { if (availableData.empty() || availableData.find(name) == availableData.end()) { - throw runtime_error( + throw std::runtime_error( get_formulation_type() + " cannot get whether unknown property " + name + " is summation"); } return availableData[name]->is_property_sum_over_time_step(name); diff --git a/include/realizations/catchment/Bmi_Py_Adapter.hpp b/include/realizations/catchment/Bmi_Py_Adapter.hpp index afc99fe67d..1cd91ab5ba 100644 --- a/include/realizations/catchment/Bmi_Py_Adapter.hpp +++ b/include/realizations/catchment/Bmi_Py_Adapter.hpp @@ -246,7 +246,7 @@ namespace models { } else if (py_type_name == "float" && item_size == sizeof(long double)) { return "long double"; } else { - throw runtime_error( + throw std::runtime_error( "(Bmi_Py_Adapter) Failed determining analogous C++ type for Python model '" + py_type_name + "' type with size " + std::to_string(item_size) + " bytes."); } @@ -266,7 +266,7 @@ namespace models { } else if (cxx_type_name == "float" || cxx_type_name == "double" || cxx_type_name == "long double") { return "double"; } else { - throw runtime_error("(Bmi_Py_Adapter) Failed determining analogous built-in Python type for C++ '" + + throw std::runtime_error("(Bmi_Py_Adapter) Failed determining analogous built-in Python type for C++ '" + cxx_type_name + "' type"); } } @@ -303,7 +303,7 @@ namespace models { } } - throw runtime_error("(Bmi_Py_Adapter) Failed determining analogous Python dtype for C++ '" + + throw std::runtime_error("(Bmi_Py_Adapter) Failed determining analogous Python dtype for C++ '" + cxx_type_name + "' type with size " + std::to_string(item_size) + " bytes."); } @@ -419,7 +419,7 @@ namespace models { void get_value_at_indices(const std::string& name, void *dest, int *inds, int count, bool is_all_indices) { std::string val_type = GetVarType(name); size_t val_item_size = (size_t)GetVarItemsize(name); - std::vector in_v = GetInputVarNames(); + std::vector in_v = GetInputVarNames(); // The available types and how they are handled here should match what is in SetValueAtIndices if (val_type == "int" && val_item_size == sizeof(short)) @@ -439,7 +439,7 @@ namespace models { get_via_numpy_array(name, dest, inds, count, val_item_size, is_all_indices); } else - throw runtime_error( + throw std::runtime_error( "(Bmi_Py_Adapter) Failed attempt to GET values of BMI variable '" + name + "' from '" + model_name + "' model: model advertises unsupported combination of type (" + val_type + ") and size (" + std::to_string(val_item_size) + ")."); @@ -636,9 +636,9 @@ namespace models { /** A binding to the Python numpy package/module. */ py::object np; /** A pointer to a string with the parent package name of the Python type referenced by ``py_bmi_type_ref``. */ - shared_ptr bmi_type_py_module_name; + std::shared_ptr bmi_type_py_module_name; /** A pointer to a string with the simple name of the Python type referenced by ``py_bmi_type_ref``. */ - shared_ptr bmi_type_py_class_name; + std::shared_ptr bmi_type_py_class_name; /** * Construct the backing BMI model object, then call its BMI-native ``Initialize()`` function. @@ -655,11 +655,11 @@ namespace models { return; try { separate_package_and_simple_name(); - std::vector moduleComponents = {*bmi_type_py_module_name, *bmi_type_py_class_name}; + std::vector moduleComponents = {*bmi_type_py_module_name, *bmi_type_py_class_name}; // This is a class object for the BMI module Python class py::object bmi_py_class = utils::ngenPy::InterpreterUtil::getPyModule(moduleComponents); // This is the actual backing model object - bmi_model = make_shared(bmi_py_class()); + bmi_model = std::make_shared(bmi_py_class()); bmi_model->attr("initialize")(bmi_init_config); } catch (std::runtime_error& e){ //Catch specific exception types so the type/message don't get erased @@ -706,7 +706,7 @@ namespace models { get_and_copy_grid_array(name, grid, dest, shape[rank-index-1], "float"); return; }else{ - throw runtime_error("GetGrid coordinates not yet implemented for Python BMI adapter for grid type "+grid_type); + throw std::runtime_error("GetGrid coordinates not yet implemented for Python BMI adapter for grid type "+grid_type); } } @@ -721,7 +721,7 @@ namespace models { */ inline void separate_package_and_simple_name() { if (!model_initialized) { - std::vector split_name; + std::vector split_name; std::string delimiter = "."; std::string name_string = bmi_type_py_full_name; @@ -737,7 +737,7 @@ namespace models { + "'; expected format is ."); } // What's left should be the class name - bmi_type_py_class_name = make_shared(name_string); + bmi_type_py_class_name = std::make_shared(name_string); //split_name.pop_back(); // And then the split name should contain the module // TODO: going to need to look at this again in the future; right now, assuming the format @@ -745,7 +745,7 @@ namespace models { // module, but the current logic is going to interpret any complex parent module name as a single // top-level namespace package; e.g., ngen.namespacepackage.model works if ngen.namespacepackage is // a namespace package, but there would be problems with something like ngenpkg.innermodule1.model. - bmi_type_py_module_name = make_shared(boost::algorithm::join(split_name, delimiter)); + bmi_type_py_module_name = std::make_shared(boost::algorithm::join(split_name, delimiter)); } } diff --git a/include/realizations/catchment/Bmi_Py_Formulation.hpp b/include/realizations/catchment/Bmi_Py_Formulation.hpp index 27b31f78fb..c524dca2c8 100644 --- a/include/realizations/catchment/Bmi_Py_Formulation.hpp +++ b/include/realizations/catchment/Bmi_Py_Formulation.hpp @@ -23,9 +23,9 @@ namespace realization { Bmi_Py_Formulation(std::string id, std::shared_ptr forcing, utils::StreamHandler output_stream); - const vector get_bmi_input_variables() override; + const std::vector get_bmi_input_variables() override; - const vector get_bmi_output_variables() override; + const std::vector get_bmi_output_variables() override; std::string get_formulation_type() override; @@ -51,7 +51,7 @@ namespace realization { * @param timestep The time step for which data is desired. * @return A delimited string with all the output variable values for the given time step. */ - string get_output_line_for_timestep(int timestep, std::string delimiter) override; + std::string get_output_line_for_timestep(int timestep, std::string delimiter) override; /** * Get the model response for a time step. @@ -89,19 +89,19 @@ namespace realization { */ double get_response(time_step_t t_index, time_step_t t_delta) override; - bool is_bmi_input_variable(const string &var_name) override; + bool is_bmi_input_variable(const std::string &var_name) override; - bool is_bmi_output_variable(const string &var_name) override; + bool is_bmi_output_variable(const std::string &var_name) override; protected: - shared_ptr construct_model(const geojson::PropertyMap &properties) override; + std::shared_ptr construct_model(const geojson::PropertyMap &properties) override; time_t convert_model_time(const double &model_time) override; - double get_var_value_as_double(const string &var_name) override; + double get_var_value_as_double(const std::string &var_name) override; - double get_var_value_as_double(const int &index, const string &var_name) override; + double get_var_value_as_double(const int &index, const std::string &var_name) override; /** * Test whether backing model has run BMI ``Initialize``. diff --git a/src/realizations/catchment/Bmi_C_Adapter.cpp b/src/realizations/catchment/Bmi_C_Adapter.cpp index 1f050e4649..60f63c5b4f 100755 --- a/src/realizations/catchment/Bmi_C_Adapter.cpp +++ b/src/realizations/catchment/Bmi_C_Adapter.cpp @@ -19,7 +19,7 @@ using namespace models::bmi; * @param registration_func The name for the @see bmi_registration_function. * @param output The output stream handler. */ -Bmi_C_Adapter::Bmi_C_Adapter(const string &type_name, std::string library_file_path, std::string forcing_file_path, +Bmi_C_Adapter::Bmi_C_Adapter(const std::string &type_name, std::string library_file_path, std::string forcing_file_path, bool allow_exceed_end, bool has_fixed_time_step, const std::string& registration_func, utils::StreamHandler output) : Bmi_C_Adapter(type_name, std::move(library_file_path), "", std::move(forcing_file_path), @@ -38,7 +38,7 @@ Bmi_C_Adapter::Bmi_C_Adapter(const string &type_name, std::string library_file_p * @param registration_func The name for the @see bmi_registration_function. * @param output The output stream handler. */ -Bmi_C_Adapter::Bmi_C_Adapter(const string &type_name, std::string library_file_path, std::string bmi_init_config, +Bmi_C_Adapter::Bmi_C_Adapter(const std::string &type_name, std::string library_file_path, std::string bmi_init_config, std::string forcing_file_path, bool allow_exceed_end, bool has_fixed_time_step, std::string registration_func, utils::StreamHandler output) : Bmi_C_Adapter(type_name, std::move(library_file_path), std::move(bmi_init_config), @@ -67,7 +67,7 @@ Bmi_C_Adapter::Bmi_C_Adapter(const string &type_name, std::string library_file_p * @param output The output stream handler. * @param do_initialization Whether initialization should be performed during construction or deferred. */ -Bmi_C_Adapter::Bmi_C_Adapter(const string &type_name, std::string library_file_path, std::string bmi_init_config, +Bmi_C_Adapter::Bmi_C_Adapter(const std::string &type_name, std::string library_file_path, std::string bmi_init_config, std::string forcing_file_path, bool allow_exceed_end, bool has_fixed_time_step, std::string registration_func, utils::StreamHandler output, bool do_initialization) : AbstractCLibBmiAdapter(type_name, library_file_path, std::move(bmi_init_config), std::move(forcing_file_path), allow_exceed_end, @@ -96,7 +96,7 @@ Bmi_C_Adapter::Bmi_C_Adapter(const string &type_name, std::string library_file_p model_initialized = true; throw e; } - catch (exception& e) { + catch (std::exception& e) { // Make sure this is set to 'true' after this function call finishes model_initialized = true; throw e; @@ -135,7 +135,7 @@ Bmi_C_Adapter::Bmi_C_Adapter(Bmi_C_Adapter &adapter) : model_name(adapter.model_ Bmi_C_Adapter::Bmi_C_Adapter(Bmi_C_Adapter &&adapter) noexcept : AbstractCLibBmiAdapter(std::move(adapter)) { } -string Bmi_C_Adapter::GetComponentName() { +std::string Bmi_C_Adapter::GetComponentName() { char component_name[BMI_MAX_COMPONENT_NAME]; if (bmi_model->get_component_name(bmi_model.get(), component_name) != BMI_SUCCESS) { throw std::runtime_error(model_name + " failed to get model component name."); @@ -267,7 +267,7 @@ std::string Bmi_C_Adapter::GetGridType(int grid_id) { char gridtype_c_str[BMI_MAX_TYPE_NAME]; int success = bmi_model->get_grid_type(bmi_model.get(), grid_id, gridtype_c_str); if (success != BMI_SUCCESS) { - throw std::runtime_error(model_name + " failed to get grid type for grid ID " + to_string(grid_id) + "."); + throw std::runtime_error(model_name + " failed to get grid type for grid ID " + std::to_string(grid_id) + "."); } return std::string(gridtype_c_str); } @@ -276,7 +276,7 @@ int Bmi_C_Adapter::GetGridRank(int grid_id) { int gridrank; int success = bmi_model->get_grid_rank(bmi_model.get(), grid_id, &gridrank); if (success != BMI_SUCCESS) { - throw std::runtime_error(model_name + " failed to get grid rank for grid ID " + to_string(grid_id) + "."); + throw std::runtime_error(model_name + " failed to get grid rank for grid ID " + std::to_string(grid_id) + "."); } return gridrank; } @@ -285,7 +285,7 @@ int Bmi_C_Adapter::GetGridSize(int grid_id) { int gridsize; int success = bmi_model->get_grid_size(bmi_model.get(), grid_id, &gridsize); if (success != BMI_SUCCESS) { - throw std::runtime_error(model_name + " failed to get grid size for grid ID " + to_string(grid_id) + "."); + throw std::runtime_error(model_name + " failed to get grid size for grid ID " + std::to_string(grid_id) + "."); } return gridsize; } diff --git a/src/realizations/catchment/Bmi_C_Formulation.cpp b/src/realizations/catchment/Bmi_C_Formulation.cpp index fb0d2328ec..5a5ec2a389 100644 --- a/src/realizations/catchment/Bmi_C_Formulation.cpp +++ b/src/realizations/catchment/Bmi_C_Formulation.cpp @@ -188,7 +188,7 @@ bool Bmi_C_Formulation::is_bmi_input_variable(const std::string &var_name) { return std::any_of(names.cbegin(), names.cend(), [var_name](const std::string &s){ return var_name == s; }); } -bool Bmi_C_Formulation::is_bmi_output_variable(const string &var_name) { +bool Bmi_C_Formulation::is_bmi_output_variable(const std::string &var_name) { const std::vector names = get_bmi_model()->GetOutputVarNames(); return std::any_of(names.cbegin(), names.cend(), [var_name](const std::string &s){ return var_name == s; }); } diff --git a/src/realizations/catchment/Bmi_Cpp_Adapter.cpp b/src/realizations/catchment/Bmi_Cpp_Adapter.cpp index f94d11c414..50eead33ce 100644 --- a/src/realizations/catchment/Bmi_Cpp_Adapter.cpp +++ b/src/realizations/catchment/Bmi_Cpp_Adapter.cpp @@ -48,7 +48,7 @@ Bmi_Cpp_Adapter::Bmi_Cpp_Adapter(const std::string& type_name, std::string libra throw e; } catch (...) { - const std::exception_ptr& e = current_exception(); + const std::exception_ptr& e = std::current_exception(); // Make sure this is set to 'true' after this function call finishes //TODO: This construct may not be necessary for the C++ adapter because the shared_ptr has a lambda set up to destroy the model? model_initialized = true; diff --git a/src/realizations/catchment/Bmi_Cpp_Formulation.cpp b/src/realizations/catchment/Bmi_Cpp_Formulation.cpp index b29065afdb..34d5400b6f 100644 --- a/src/realizations/catchment/Bmi_Cpp_Formulation.cpp +++ b/src/realizations/catchment/Bmi_Cpp_Formulation.cpp @@ -187,7 +187,7 @@ bool Bmi_Cpp_Formulation::is_bmi_input_variable(const std::string &var_name) { return std::any_of(names.cbegin(), names.cend(), [var_name](const std::string &s){ return var_name == s; }); } -bool Bmi_Cpp_Formulation::is_bmi_output_variable(const string &var_name) { +bool Bmi_Cpp_Formulation::is_bmi_output_variable(const std::string &var_name) { const std::vector names = get_bmi_model()->GetOutputVarNames(); return std::any_of(names.cbegin(), names.cend(), [var_name](const std::string &s){ return var_name == s; }); } diff --git a/src/realizations/catchment/Bmi_Py_Formulation.cpp b/src/realizations/catchment/Bmi_Py_Formulation.cpp index 9f7d905ac7..e52f2ffa17 100644 --- a/src/realizations/catchment/Bmi_Py_Formulation.cpp +++ b/src/realizations/catchment/Bmi_Py_Formulation.cpp @@ -36,11 +36,11 @@ time_t realization::Bmi_Py_Formulation::convert_model_time(const double &model_t return (time_t) (get_bmi_model()->convert_model_time_to_seconds(model_time)); } -const vector Bmi_Py_Formulation::get_bmi_input_variables() { +const std::vector Bmi_Py_Formulation::get_bmi_input_variables() { return get_bmi_model()->GetInputVarNames(); } -const vector Bmi_Py_Formulation::get_bmi_output_variables() { +const std::vector Bmi_Py_Formulation::get_bmi_output_variables() { return get_bmi_model()->GetOutputVarNames(); } @@ -48,7 +48,7 @@ std::string Bmi_Py_Formulation::get_formulation_type() { return "bmi_py"; } -string Bmi_Py_Formulation::get_output_line_for_timestep(int timestep, std::string delimiter) { +std::string Bmi_Py_Formulation::get_output_line_for_timestep(int timestep, std::string delimiter) { // TODO: something must be added to store values if more than the current time step is wanted // TODO: if such a thing is added, it should probably be configurable to turn it off if (timestep != (next_time_step_index - 1)) { @@ -113,12 +113,12 @@ double Bmi_Py_Formulation::get_response(time_step_t t_index, time_step_t t_delta return get_var_value_as_double( get_bmi_main_output_var()); } -double Bmi_Py_Formulation::get_var_value_as_double(const string &var_name) { +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 string &var_name) { - string val_type = get_bmi_model()->GetVarType(var_name); +double Bmi_Py_Formulation::get_var_value_as_double(const int &index, const std::string &var_name) { + std::string val_type = get_bmi_model()->GetVarType(var_name); size_t val_item_size = (size_t)get_bmi_model()->GetVarItemsize(var_name); //void *dest; @@ -168,12 +168,12 @@ double Bmi_Py_Formulation::get_var_value_as_double(const int &index, const strin " as double: no logic for converting variable type " + val_type); } -bool Bmi_Py_Formulation::is_bmi_input_variable(const string &var_name) { +bool Bmi_Py_Formulation::is_bmi_input_variable(const std::string &var_name) { const std::vector names = get_bmi_model()->GetInputVarNames(); return std::any_of(names.cbegin(), names.cend(), [var_name](const std::string &s){ return var_name == s; }); } -bool Bmi_Py_Formulation::is_bmi_output_variable(const string &var_name) { +bool Bmi_Py_Formulation::is_bmi_output_variable(const std::string &var_name) { const std::vector names = get_bmi_model()->GetOutputVarNames(); return std::any_of(names.cbegin(), names.cend(), [var_name](const std::string &s){ return var_name == s; }); } diff --git a/test/realizations/catchments/Bmi_Py_Adapter_Test.cpp b/test/realizations/catchments/Bmi_Py_Adapter_Test.cpp index 35a3f402c7..9ce706f710 100644 --- a/test/realizations/catchments/Bmi_Py_Adapter_Test.cpp +++ b/test/realizations/catchments/Bmi_Py_Adapter_Test.cpp @@ -185,7 +185,7 @@ void Bmi_Py_Adapter_Test::TearDownTestSuite() { * @param file_basename The basename of the desired file. * @return The path (as a string) of the first found existing file, or empty string of no existing file was found. */ -std::string Bmi_Py_Adapter_Test::file_search(const vector &parent_dir_options, const string &file_basename) { +std::string Bmi_Py_Adapter_Test::file_search(const std::vector &parent_dir_options, const std::string &file_basename) { // Build vector of paths by building combinations of the path and basename options std::vector path_possibilities(parent_dir_options.size()); for (int i = 0; i < parent_dir_options.size(); ++i) @@ -204,8 +204,8 @@ std::string Bmi_Py_Adapter_Test::file_search(const vector &parent_d * @param file_basename The collection of possible basenames for a sought file. * @return The path (as a string) of the first found existing file, or empty string of no existing file was found. */ -std::string Bmi_Py_Adapter_Test::file_search(const vector &parent_dir_options, - const vector &file_basenames) { +std::string Bmi_Py_Adapter_Test::file_search(const std::vector &parent_dir_options, + const std::vector &file_basenames) { std::string foundPathForBasename; for (const std::string &basename : file_basenames) { foundPathForBasename = file_search(parent_dir_options, basename); diff --git a/test/realizations/catchments/Bmi_Py_Formulation_Test.cpp b/test/realizations/catchments/Bmi_Py_Formulation_Test.cpp index f65d287228..9def1547b1 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 { return formulation.get_model_type_name(); } - static double get_friend_var_value_as_double(Bmi_Py_Formulation& formulation, const string& var_name) { + 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); } @@ -303,7 +303,7 @@ void Bmi_Py_Formulation_Test::generate_realization_config(int ex_idx) { * @param file_basename The basename of the desired file. * @return The path (as a string) of the first found existing file, or empty string of no existing file was found. */ -std::string Bmi_Py_Formulation_Test::file_search(const vector &parent_dir_options, const string &file_basename) { +std::string Bmi_Py_Formulation_Test::file_search(const std::vector &parent_dir_options, const std::string &file_basename) { // Build vector of paths by building combinations of the path and basename options std::vector path_possibilities(parent_dir_options.size()); for (int i = 0; i < parent_dir_options.size(); ++i) @@ -322,8 +322,8 @@ std::string Bmi_Py_Formulation_Test::file_search(const vector &pare * @param file_basename The collection of possible basenames for a sought file. * @return The path (as a string) of the first found existing file, or empty string of no existing file was found. */ -std::string Bmi_Py_Formulation_Test::file_search(const vector &parent_dir_options, - const vector &file_basenames) { +std::string Bmi_Py_Formulation_Test::file_search(const std::vector &parent_dir_options, + const std::vector &file_basenames) { std::string foundPathForBasename; for (const std::string &basename : file_basenames) { foundPathForBasename = file_search(parent_dir_options, basename);