NGen
|
Abstraction of formulation with backing model object(s) that implements the BMI. More...
#include <Bmi_Formulation.hpp>
Public Types | |
typedef long | time_step_t |
using | data_type = DataType |
This class provides a generic interface to data services. | |
using | selection_type = SelectionType |
Public Member Functions | |
Bmi_Formulation (std::string id, std::shared_ptr< data_access::GenericDataProvider > forcing, utils::StreamHandler output_stream) | |
Minimal constructor for objects initialized using the Formulation_Manager and subsequent calls to create_formulation . | |
virtual | ~Bmi_Formulation () |
virtual time_t | convert_model_time (const double &model_time) const =0 |
Convert a time value from the model to an epoch time in seconds. | |
virtual const bool & | get_allow_model_exceed_end_time () const =0 |
Get whether a model may perform updates beyond its end_time . | |
virtual const std::vector< std::string > | get_bmi_input_variables () const =0 |
const std::string & | get_bmi_main_output_var () const |
virtual const time_t & | get_bmi_model_start_time_forcing_offset_s () const =0 |
virtual const std::vector< std::string > | get_bmi_output_variables () const =0 |
virtual const std::string & | get_config_mapped_variable_name (const std::string &model_var_name) const =0 |
When possible, translate a variable name for a BMI model to an internally recognized name. | |
virtual const double | get_model_current_time () const =0 |
Get the current time for the backing BMI model in its native format and units. | |
virtual const double | get_model_end_time () const =0 |
Get the end time for the backing BMI model in its native format and units. | |
std::string | get_model_type_name () const |
Get the name of the specific type of the backing model object. | |
const std::vector< std::string > & | get_output_header_fields () const |
Get the values making up the header line from get_output_header_line(), but organized as a vector of strings. | |
std::string | get_output_header_line (std::string delimiter) const override |
Get a header line appropriate for a file made up of entries from this type's implementation of get_output_line_for_timestep . | |
const std::vector< std::string > & | get_output_variable_names () const |
Get the names of variables in formulation output. | |
const std::vector< std::string > & | get_required_parameters () const override |
virtual bool | is_bmi_input_variable (const std::string &var_name) const =0 |
virtual bool | is_bmi_model_time_step_fixed () const =0 |
Test whether backing model has fixed time step size. | |
virtual bool | is_bmi_output_variable (const std::string &var_name) const =0 |
virtual bool | is_model_initialized () const =0 |
Test whether the backing model has been initialize using the BMI standard Initialize function. | |
void | set_output_precision (int precision) |
Set the precision of output values when converted to text. | |
virtual double | get_var_value_as_double (const int &index, const std::string &var_name)=0 |
Get value for some BMI model variable at a specific index. | |
virtual std::string | get_output_line_for_timestep (int timestep, std::string delimiter=DEFAULT_FORMULATION_OUTPUT_DELIMITER)=0 |
Get a formatted line of output values for the given time step as a delimited string. | |
virtual double | get_response (time_step_t t_index, time_step_t t_delta) override=0 |
Execute the backing model formulation for the given time step, where it is of the specified size, and return the response output. | |
void | create_formulation (boost::property_tree::ptree &config, geojson::PropertyMap *global=nullptr) override=0 |
void | create_formulation (geojson::PropertyMap properties) override=0 |
void | finalize () |
Release resources of the given forcing provider. | |
virtual std::string | get_formulation_type () const =0 |
std::string | get_id () const |
void | set_output_stream (std::string file_path) |
void | write_output (std::string out) |
virtual void | finalize () |
Release any resources that should not be held as the run is shutting down. | |
virtual boost::span< const std::string > | get_available_variable_names () const =0 |
Return the variables that are accessable by this data provider. | |
virtual long | get_data_start_time () const =0 |
Return the first valid time for which data from the request variable can be requested. | |
virtual long | get_data_stop_time () const =0 |
Return the last valid time for which data from the requested variable can be requested. | |
virtual long | record_duration () const =0 |
Return the stride in the time dimension. | |
virtual size_t | get_ts_index_for_time (const time_t &epoch_time) const =0 |
Get the index of the data time step that contains the given point in time. | |
virtual data_type | get_value (const selection_type &selector, ReSampleMethod m=SUM)=0 |
Get the value of a forcing property for an arbitrary time period, converting units if needed. | |
virtual std::vector< data_type > | get_values (const selection_type &selector, ReSampleMethod m=SUM)=0 |
Get the values of a forcing property for an arbitrary time period, converting units if needed. | |
virtual bool | is_property_sum_over_time_step (const std::string &name) const |
Static Public Member Functions | |
static void | config_pattern_substitution (geojson::PropertyMap &properties, const std::string &key, const std::string &pattern, const std::string &replacement) |
Perform in-place substitution on the given config property item, if the item and the pattern are present. | |
Protected Member Functions | |
int | get_output_precision () |
void | set_bmi_main_output_var (const std::string &main_output_var) |
virtual void | set_model_type_name (std::string type_name) |
Set the name of the specific type of the backing model object. | |
void | set_output_header_fields (const std::vector< std::string > &output_headers) |
void | set_output_variable_names (const std::vector< std::string > &out_var_names) |
Set the names of variables in formulation output. | |
std::string | get_catchment_id () const override |
void | set_catchment_id (std::string cat_id) override |
geojson::PropertyMap | interpret_parameters (boost::property_tree::ptree &config, geojson::PropertyMap *global=nullptr) |
void | validate_parameters (geojson::PropertyMap options) |
Protected Attributes | |
std::shared_ptr< std::ostringstream > | output_text_stream |
Object to help with converting numeric output values to text. | |
std::shared_ptr< data_access::GenericDataProvider > | forcing |
std::string | id |
polygon_t | bounds |
utils::StreamHandler | output |
std::shared_ptr< HY_Catchment > | realized_catchment |
unsigned long | id_number |
Private Attributes | |
std::string | bmi_main_output_var |
std::string | model_type_name |
std::vector< std::string > | output_header_fields |
Output header field strings corresponding to the variables output by the realization, as defined in output_variable_names . | |
std::vector< std::string > | output_variable_names |
Names of the variables to include in the output from this formulation, which will be some ordered subset of the BMI module output variables accessible to the instance. | |
int | output_precision |
The degree of precision in output values when converting to text. | |
std::string | cat_id |
Static Private Attributes | |
static const std::vector< std::string > | OPTIONAL_PARAMETERS |
static const std::vector< std::string > | REQUIRED_PARAMETERS |
Friends | |
class | ::Bmi_Formulation_Test |
class | ::Bmi_C_Formulation_Test |
Abstraction of formulation with backing model object(s) that implements the BMI.
|
inherited |
This class provides a generic interface to data services.
|
inherited |
|
inherited |
|
inline |
Minimal constructor for objects initialized using the Formulation_Manager and subsequent calls to create_formulation
.
id | |
forcing | |
output_stream |
References set_output_precision().
|
inlinevirtual |
|
inlinestaticinherited |
Perform in-place substitution on the given config property item, if the item and the pattern are present.
Any and all instances of the substring pattern
are replaced by replacement
, if key
maps to a present string-type property value.
properties | A reference to the properties config object to be altered. |
key | The key for the configuration property to potentially adjust. |
pattern | The pattern substring to search for that, when present, should be replaced. |
replacement | The replacement substring to potentially insert. |
References geojson::String.
Referenced by realization::Formulation_Manager::construct_missing_formulation(), and realization::Bmi_Multi_Formulation::init_nested_module().
|
pure virtual |
Convert a time value from the model to an epoch time in seconds.
Model time values are typically (though not always) 0-based totals count upward as time progresses. The units are not necessarily seconds. This performs the necessary lookup and conversion for such units, and then shifts the value appropriately for epoch time representation.
model_time |
Implemented in realization::Bmi_C_Formulation, realization::Bmi_Cpp_Formulation, and realization::Bmi_Multi_Formulation.
Referenced by realization::Bmi_Module_Formulation::determine_model_time_offset(), and realization::Bmi_Module_Formulation::set_model_inputs_prior_to_update().
|
overridepure virtualinherited |
Implements realization::Formulation.
Implemented in realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
|
overridepure virtualinherited |
Implements realization::Formulation.
Implemented in realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
|
inlinevirtualinherited |
Release any resources that should not be held as the run is shutting down.
In particular, this should be called before MPI_Finalize()
Reimplemented in data_access::WrappedDataProvider.
|
inlineinherited |
Release resources of the given forcing provider.
References realization::Catchment_Formulation::forcing.
|
pure virtual |
Get whether a model may perform updates beyond its end_time
.
Get whether model Update
calls are allowed and handled in some way by the backing model for time steps after the model's end_time
. Implementations of this type should use this function to safeguard against entering either an invalid or otherwise undesired state as a result of attempting to process a model beyond its available data.
As mentioned, even for models that are capable of validly handling processing beyond end time, it may be desired that they do not for some reason (e.g., the way they account for the lack of input data leads to valid but incorrect results for a specific application). Because of this, whether models are allowed to process beyond their end time is configuration-based.
end_time
. Implemented in realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
|
pure virtualinherited |
Return the variables that are accessable by this data provider.
Implemented in CsvPerFeatureForcingProvider, data_access::DeferredWrappedProvider, data_access::WrappedDataProvider, NullForcingProvider, realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
Referenced by data_access::WrappedDataProvider::get_available_variable_names(), data_access::OptionalWrappedDataProvider::isSuppliedByProvider(), and data_access::DeferredWrappedProvider::setWrappedProvider().
|
pure virtual |
Implemented in realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
|
inline |
References bmi_main_output_var.
Referenced by realization::Bmi_Module_Formulation::get_response(), and realization::Bmi_Multi_Formulation::get_response().
|
pure virtual |
Implemented in realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
|
pure virtual |
Implemented in realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
|
inlineoverrideprotectedvirtualinherited |
Implements HY_CatchmentRealization.
References realization::Catchment_Formulation::cat_id.
Referenced by realization::Bmi_Multi_Formulation::create_multi_formulation(), realization::Bmi_Multi_Formulation::get_value(), realization::Bmi_Multi_Formulation::get_values(), realization::Bmi_Multi_Formulation::get_var_value_as_double(), and realization::Bmi_Module_Formulation::set_model_inputs_prior_to_update().
|
pure virtual |
When possible, translate a variable name for a BMI model to an internally recognized name.
model_var_name | The BMI variable name to translate so its purpose is recognized internally. |
Implemented in realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
|
pure virtualinherited |
Return the first valid time for which data from the request variable can be requested.
Implemented in CsvPerFeatureForcingProvider, data_access::WrappedDataProvider, NullForcingProvider, realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
Referenced by data_access::WrappedDataProvider::get_data_start_time().
|
pure virtualinherited |
Return the last valid time for which data from the requested variable can be requested.
Implemented in CsvPerFeatureForcingProvider, data_access::WrappedDataProvider, NullForcingProvider, realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
Referenced by data_access::WrappedDataProvider::get_data_stop_time().
|
pure virtualinherited |
Implemented in realization::Bmi_C_Formulation, realization::Bmi_Cpp_Formulation, and realization::Bmi_Multi_Formulation.
Referenced by realization::Bmi_Module_Formulation::get_response(), realization::Bmi_Module_Formulation::get_value(), realization::Bmi_Module_Formulation::get_values(), and realization::Formulation::validate_parameters().
|
inlineinherited |
References realization::Formulation::id.
|
pure virtual |
Get the current time for the backing BMI model in its native format and units.
Implemented in realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
|
pure virtual |
Get the end time for the backing BMI model in its native format and units.
Implemented in realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
|
inline |
Get the name of the specific type of the backing model object.
References model_type_name.
Referenced by realization::Bmi_C_Formulation::construct_model(), realization::Bmi_Cpp_Formulation::construct_model(), realization::Bmi_C_Formulation::get_var_value_as_double(), and realization::Bmi_Cpp_Formulation::get_var_value_as_double().
|
inline |
Get the values making up the header line from get_output_header_line(), but organized as a vector of strings.
References output_header_fields.
Referenced by get_output_header_line().
|
inlineoverridevirtual |
Get a header line appropriate for a file made up of entries from this type's implementation of get_output_line_for_timestep
.
Note that like the output generating function, this line does not include anything for time step.
Reimplemented from realization::Catchment_Formulation.
References get_output_header_fields().
|
pure virtualinherited |
Get a formatted line of output values for the given time step as a delimited string.
This method is useful for preparing calculated data in a representation useful for output files, such as CSV files.
The resulting string will contain calculated values for applicable output variables for the particular formulation, as determined for the given time step. However, the string will not contain any representation of the time step itself.
An empty string is returned if the time step value is not in the range of valid time steps for which there are calculated values for all variables.
timestep | The time step for which data is desired. |
delimiter | The value delimiter for the string. |
Implemented in realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
Referenced by ngen::DomainLayer::update_models().
|
inlineprotected |
References output_precision.
|
inline |
Get the names of variables in formulation output.
Get the names of the variables to include in the output from this formulation, which should be some ordered subset of the BMI module output variables accessible to this instance.
References output_variable_names.
Referenced by realization::Bmi_Multi_Formulation::check_output_var_names(), realization::Bmi_Multi_Formulation::create_multi_formulation(), realization::Bmi_Module_Formulation::get_output_line_for_timestep(), realization::Bmi_Multi_Formulation::get_output_line_for_timestep(), and realization::Bmi_Module_Formulation::inner_create_formulation().
|
inlineoverridevirtual |
Implements realization::Catchment_Formulation.
Reimplemented in realization::Bmi_Module_Formulation.
References REQUIRED_PARAMETERS.
|
overridepure virtualinherited |
Execute the backing model formulation for the given time step, where it is of the specified size, and return the response output.
Any inputs and additional parameters must be made available as instance members.
Types should clearly document the details of their particular response output.
t_index | The index of the time step for which to run model calculations. |
t_delta | The duration, in seconds, of the time step for which to run model calculations. |
Implements HY_CatchmentRealization.
Implemented in realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
Referenced by ngen::DomainLayer::update_models().
|
pure virtualinherited |
Get the index of the data time step that contains the given point in time.
An std::out_of_range exception should be thrown if the time is not in any time step.
epoch_time | The point in time, as a seconds-based epoch time. |
std::out_of_range | If the given point is not in any time step. |
Implemented in CsvPerFeatureForcingProvider, data_access::WrappedDataProvider, NullForcingProvider, realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
Referenced by data_access::WrappedDataProvider::get_ts_index_for_time().
|
pure virtualinherited |
Get the value of a forcing property for an arbitrary time period, converting units if needed.
An std::out_of_range exception should be thrown if the data for the time period is not available.
selector | Data required to establish what subset of the stored data should be accessed |
m | How data is to be resampled if there is a mismatch in data alignment or repeat rate |
std::out_of_range | If data for the time period is not available. |
Referenced by data_access::WrappedDataProvider::get_value(), and realization::Bmi_Module_Formulation::set_model_inputs_prior_to_update().
|
pure virtualinherited |
Get the values of a forcing property for an arbitrary time period, converting units if needed.
An std::out_of_range exception should be thrown if the data for the time period is not available.
If a provider doesn't implement this function, then by default, get_values will be a simple proxy to get_value with the result wrapped in a std::vector<double>
output_name | The name of the forcing property of interest. |
init_time_epoch | The epoch time (in seconds) of the start of the time period. |
duration_seconds | The length of the time period, in seconds. |
output_units | The expected units of the desired output value. |
std::out_of_range | If data for the time period is not available. |
Referenced by data_access::WrappedDataProvider::get_values(), and realization::Bmi_Module_Formulation::set_model_inputs_prior_to_update().
|
pure virtual |
Get value for some BMI model variable at a specific index.
Function gets the value for a provided variable, returned from the backing model as an array, and returns the specific value at the desired index cast as a double type.
The function makes several assumptions:
1. `index` is within array bounds 2. `var_name` is in the set of valid variable names for the model 3. the type for output variable allows the value to be cast to a `double` appropriately
It falls to user (functions) of this function to ensure these assumptions hold before invoking.
index | |
var_name |
Implemented in realization::Bmi_C_Formulation, realization::Bmi_Cpp_Formulation, and realization::Bmi_Multi_Formulation.
Referenced by realization::Bmi_Module_Formulation::get_output_line_for_timestep(), realization::Bmi_Module_Formulation::get_response(), and realization::Bmi_Module_Formulation::get_value().
|
inlineprotectedinherited |
|
pure virtual |
|
pure virtual |
Test whether backing model has fixed time step size.
Implemented in realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
|
pure virtual |
|
pure virtual |
Test whether the backing model has been initialize using the BMI standard Initialize
function.
Initialize
function. Implemented in realization::Bmi_C_Formulation, realization::Bmi_Cpp_Formulation, realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
|
inlinevirtualinherited |
|
pure virtualinherited |
Return the stride in the time dimension.
Implemented in CsvPerFeatureForcingProvider, data_access::WrappedDataProvider, NullForcingProvider, realization::Bmi_Module_Formulation, and realization::Bmi_Multi_Formulation.
Referenced by data_access::WrappedDataProvider::record_duration().
|
inlineprotected |
|
inlineoverrideprotectedvirtualinherited |
Implements HY_CatchmentRealization.
References realization::Catchment_Formulation::cat_id.
Referenced by realization::Catchment_Formulation::Catchment_Formulation(), and realization::Catchment_Formulation::Catchment_Formulation().
|
inlineprotectedvirtual |
Set the name of the specific type of the backing model object.
type_name | The name of the backing model object's type. |
References model_type_name.
Referenced by realization::Bmi_Multi_Formulation::create_multi_formulation(), and realization::Bmi_Module_Formulation::inner_create_formulation().
|
inlineprotected |
|
inline |
Set the precision of output values when converted to text.
precision | The desired precision, as a number of decimal places. |
References output_precision, and output_text_stream.
Referenced by Bmi_Formulation(), realization::Bmi_Multi_Formulation::create_multi_formulation(), and realization::Bmi_Module_Formulation::inner_create_formulation().
|
inlineinherited |
References HY_CatchmentArea::output.
|
inlineprotected |
Set the names of variables in formulation output.
Set the names of the variables to include in the output from this formulation, which should be some ordered subset of the output variables from the model.
out_var_names | the names of variables in formulation output, in the order they should appear. |
References output_variable_names.
Referenced by realization::Bmi_Multi_Formulation::create_multi_formulation(), and realization::Bmi_Module_Formulation::inner_create_formulation().
|
inlineprotectedinherited |
References realization::Formulation::get_formulation_type(), and realization::Formulation::get_required_parameters().
Referenced by realization::Bmi_Multi_Formulation::create_multi_formulation(), realization::Bmi_Module_Formulation::inner_create_formulation(), and realization::Formulation::interpret_parameters().
|
inlineinherited |
References HY_CatchmentArea::output.
Referenced by ngen::DomainLayer::DomainLayer(), and ngen::DomainLayer::update_models().
|
friend |
|
friend |
|
private |
Referenced by get_bmi_main_output_var(), and set_bmi_main_output_var().
|
protectedinherited |
|
privateinherited |
|
protectedinherited |
Referenced by realization::Bmi_Multi_Formulation::create_multi_formulation(), realization::Bmi_Module_Formulation::determine_model_time_offset(), realization::Catchment_Formulation::finalize(), realization::Bmi_Multi_Formulation::get_variable_time_begin(), realization::Bmi_Multi_Formulation::get_variable_time_end(), and realization::Bmi_Module_Formulation::set_model_inputs_prior_to_update().
|
protectedinherited |
Referenced by realization::Formulation::get_id().
|
protectedinherited |
|
private |
Referenced by get_model_type_name(), and set_model_type_name().
|
staticprivate |
|
protectedinherited |
|
private |
Output header field strings corresponding to the variables output by the realization, as defined in output_variable_names
.
Referenced by get_output_header_fields(), and set_output_header_fields().
|
private |
The degree of precision in output values when converting to text.
Referenced by get_output_precision(), and set_output_precision().
|
protected |
Object to help with converting numeric output values to text.
Referenced by realization::Bmi_Multi_Formulation::get_output_line_for_timestep(), and set_output_precision().
|
private |
Names of the variables to include in the output from this formulation, which will be some ordered subset of the BMI module output variables accessible to the instance.
Referenced by get_output_variable_names(), and set_output_variable_names().
|
protectedinherited |
|
staticprivate |
Referenced by get_required_parameters().