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

Minor changes to Forcings Engine Data Provider for derived implementations #851

Merged
Merged
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
28 changes: 24 additions & 4 deletions include/forcing/ForcingsEngineDataProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,33 @@ struct ForcingsEngineDataProvider
var_output_names_ = bmi_->GetOutputVarNames();
}

std::string ensure_variable(std::string name, const std::string& suffix = "_ELEMENT") const
{
// TODO: use get_available_var_names() once const
auto vars = boost::span<const std::string>{var_output_names_};

if (std::find(vars.begin(), vars.end(), name) != vars.end()) {
return name;
}

auto suffixed_name = std::move(name) + suffix;
if (std::find(vars.begin(), vars.end(), suffixed_name) != vars.end()) {
return suffixed_name;
}

throw std::runtime_error{
"ForcingsEngineDataProvider: neither variable `"
+ suffixed_name.substr(0, suffixed_name.size() - suffix.size())
+ "` nor `" + suffixed_name + "` exist."
};
}

//! Forcings Engine instance
std::shared_ptr<models::bmi::Bmi_Py_Adapter> bmi_ = nullptr;

//! Output variable names
std::vector<std::string> var_output_names_{};

private:
//! Initialization config file path
std::string init_;

//! Calendar time for simulation beginning
clock_type::time_point time_begin_{};

Expand All @@ -212,6 +229,9 @@ struct ForcingsEngineDataProvider

//! Duration of a single simulation tick
clock_type::duration time_step_{};

//! Initialization config file path
std::string init_;
};

} // namespace data_access
Expand Down
Loading