NGen
|
Abstraction of a formulation with a single backing model object that implements the BMI. More...
#include <Bmi_Module_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_Module_Formulation (std::string id, std::shared_ptr< data_access::GenericDataProvider > forcing_provider, utils::StreamHandler output_stream) | |
Minimal constructor for objects initialize using the Formulation_Manager and subsequent calls to create_formulation . | |
~Bmi_Module_Formulation () override=default | |
void | create_formulation (boost::property_tree::ptree &config, geojson::PropertyMap *global=nullptr) override |
void | create_formulation (geojson::PropertyMap properties) override |
boost::span< const std::string > | get_available_variable_names () const override |
Get the collection of forcing output property names this instance can provide. | |
std::string | get_output_line_for_timestep (int timestep, std::string delimiter) override |
Get a delimited string with all the output variable values for the given time step. | |
double | get_response (time_step_t t_index, time_step_t t_delta) override |
Get the model response for a time step. | |
time_t | get_variable_time_begin (const std::string &variable_name) |
Get the inclusive beginning of the period of time over which this instance can provide data for this forcing. | |
long | get_data_start_time () const override |
Get the inclusive beginning of the period of time over which this instance can provide data for this forcing. | |
long | get_data_stop_time () const override |
Return the last valid time for which data from the requested variable can be requested. | |
long | record_duration () const override |
Return the stride in the time dimension. | |
const double | get_model_current_time () const override |
Get the current time for the backing BMI model in its native format and units. | |
const double | get_model_end_time () const override |
Get the end time for the backing BMI model in its native format and units. | |
const std::vector< std::string > & | get_required_parameters () const override |
const std::string & | get_config_mapped_variable_name (const std::string &model_var_name) const override |
When possible, translate a variable name for a BMI model to an internally recognized name. | |
size_t | get_ts_index_for_time (const time_t &epoch_time) const override |
Get the index of the forcing time step that contains the given point in time. | |
std::vector< double > | get_values (const CatchmentAggrDataSelector &selector, data_access::ReSampleMethod m=SUM) override |
Get the 1D values of a forcing property for an arbitrary time period, converting units if needed. | |
double | get_value (const CatchmentAggrDataSelector &selector, data_access::ReSampleMethod m) override |
Get the value of a forcing property for an arbitrary time period, converting units if needed. | |
bool | is_bmi_input_variable (const std::string &var_name) const override |
bool | is_bmi_output_variable (const std::string &var_name) const override |
bool | is_property_sum_over_time_step (const std::string &name) const override |
Get whether a property's per-time-step values are each an aggregate sum over the entire time step. | |
const std::vector< std::string > | get_bmi_input_variables () const override |
const std::vector< std::string > | get_bmi_output_variables () const override |
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. | |
const std::string & | get_bmi_main_output_var () const |
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. | |
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. | |
void | finalize () |
Release resources of the given forcing provider. | |
virtual void | finalize () |
Release any resources that should not be held as the run is shutting down. | |
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 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. | |
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 | |
void | get_bmi_output_var_name (const std::string &name, std::string &bmi_var_name) |
Get correct BMI variable name, which may be the output or something mapped to this output. | |
virtual std::shared_ptr< models::bmi::Bmi_Adapter > | construct_model (const geojson::PropertyMap &properties)=0 |
Construct model and its shared pointer, potentially supplying input variable values from config. | |
void | determine_model_time_offset () |
Determine and set the offset time of the model in seconds, compared to forcing data. | |
const bool & | get_allow_model_exceed_end_time () const override |
Get whether a model may perform updates beyond its end_time . | |
const std::string & | get_bmi_init_config () const |
std::shared_ptr< models::bmi::Bmi_Adapter > | get_bmi_model () const |
Get the backing model object implementing the BMI. | |
const time_t & | get_bmi_model_start_time_forcing_offset_s () const override |
void | inner_create_formulation (geojson::PropertyMap properties, bool needs_param_validation) |
Universal logic applied when creating a BMI-backed formulation from NGen config. | |
void | set_initial_bmi_parameters (geojson::PropertyMap properties) |
Check configuration properties for model_params and attempt to set them in the bmi model. | |
bool | is_bmi_model_time_step_fixed () const override |
Test whether backing model has fixed time step size. | |
bool | is_model_initialized () const override |
Test whether the backing model object has been initialize using the BMI standard Initialize function. | |
void | set_allow_model_exceed_end_time (bool allow_exceed_end) |
void | set_bmi_init_config (const std::string &init_config) |
void | set_bmi_model (std::shared_ptr< models::bmi::Bmi_Adapter > model) |
Set the backing model object implementing the BMI. | |
void | set_bmi_model_start_time_forcing_offset_s (const time_t &offset_s) |
void | set_bmi_model_time_step_fixed (bool is_fix_time_step) |
virtual void | set_model_initialized (bool is_initialized) |
Set whether the backing model object has been initialize using the BMI standard Initialize function. | |
void | set_model_inputs_prior_to_update (const double &model_init_time, time_step_t t_delta) |
Set BMI input variable values for the model appropriately prior to calling its BMI update()``. | |
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 | |
time_step_t | last_model_response_delta = 0 |
The delta of the last model update execution (typically, this is time step size). | |
time_t | last_model_response_start_time = 0 |
The epoch time of the model at the beginning of its last update. | |
std::map< std::string, std::shared_ptr< data_access::GenericDataProvider > > | input_forcing_providers |
int | next_time_step_index = 0 |
Index value (0-based) of the time step that will be processed by the next update of the model. | |
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 | |
bool | allow_model_exceed_end_time = false |
Whether model Update calls are allowed and handled in some way by the backing model for time steps after the model's end_time . | |
std::vector< std::string > | available_forcings |
The set of available "forcings" (output variables, plus their mapped aliases) that the model can provide. | |
std::string | bmi_init_config |
std::shared_ptr< models::bmi::Bmi_Adapter > | bmi_model |
bool | bmi_model_time_step_fixed = true |
Whether backing model has fixed time step size. | |
time_t | bmi_model_start_time_forcing_offset_s |
The offset, converted to seconds, from the model's start time to the start time of the initial forcing time step. | |
std::map< std::string, std::string > | bmi_var_names_map |
A configured mapping of BMI model variable names to standard names for use inside the framework. | |
bool | model_initialized = false |
std::vector< std::string > | OPTIONAL_PARAMETERS |
std::vector< std::string > | REQUIRED_PARAMETERS |
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 |
Friends | |
class | Bmi_Multi_Formulation |
class | ::Bmi_Formulation_Test |
class | ::Bmi_C_Formulation_Test |
class | ::Bmi_Multi_Formulation_Test |
class | ::Bmi_Cpp_Formulation_Test |
class | ::Bmi_Cpp_Multi_Array_Test |
Abstraction of a formulation with a single backing model object that implements the BMI.
|
inherited |
This class provides a generic interface to data services.
|
inherited |
|
inherited |
|
inline |
Minimal constructor for objects initialize using the Formulation_Manager and subsequent calls to create_formulation
.
id | |
forcing_provider | |
output_stream |
|
overridedefault |
|
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().
|
protectedpure virtual |
Construct model and its shared pointer, potentially supplying input variable values from config.
Construct a model (and a shared pointer to it), checking whether additional input variable values are present in the configuration properties and need to be used during model construction.
properties | Configuration properties for the formulation, potentially containing values for input variables |
Implemented in realization::Bmi_C_Formulation, and realization::Bmi_Cpp_Formulation.
Referenced by inner_create_formulation().
|
pure virtualinherited |
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 determine_model_time_offset(), and set_model_inputs_prior_to_update().
|
overridevirtual |
Implements realization::Catchment_Formulation.
References inner_create_formulation(), and realization::Formulation::interpret_parameters().
|
overridevirtual |
Implements realization::Catchment_Formulation.
References inner_create_formulation().
|
protected |
Determine and set the offset time of the model in seconds, compared to forcing data.
BMI models frequently have their model start time be set to 0. As such, to know what the forcing time is compared to the model time, an offset value is needed. This becomes important in situations when the size of the time steps for forcing data versus model execution are not equal. This method will determine and set this value.
References realization::Bmi_Formulation::convert_model_time(), realization::Catchment_Formulation::forcing, get_bmi_model(), and set_bmi_model_start_time_forcing_offset_s().
Referenced by inner_create_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.
|
overrideprotectedvirtual |
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
. Implements realization::Bmi_Formulation.
References allow_model_exceed_end_time.
Referenced by get_response().
|
overridevirtual |
Get the collection of forcing output property names this instance can provide.
This is part of the ForcingProvider interface. This interface must be implemented for items of this type to be usable as "forcing" providers for situations when some other object needs to receive as an input (i.e., one of its forcings) a data property output from this object.
For this type, this is the collection of BMI output variables, plus any aliases included in the formulation config's output variable mapping.
Implements data_access::DataProvider< DataType, SelectionType >.
References available_forcings.
Referenced by get_value(), and get_values().
|
protected |
References bmi_init_config.
Referenced by realization::Bmi_C_Formulation::construct_model(), and realization::Bmi_Cpp_Formulation::construct_model().
|
overridevirtual |
Implements realization::Bmi_Formulation.
References get_bmi_model(), and bmi::Bmi::GetInputVarNames().
Referenced by is_bmi_input_variable().
|
inlineinherited |
References realization::Bmi_Formulation::bmi_main_output_var.
Referenced by get_response(), and realization::Bmi_Multi_Formulation::get_response().
|
protected |
Get the backing model object implementing the BMI.
References bmi_model.
Referenced by realization::Bmi_C_Formulation::convert_model_time(), realization::Bmi_Cpp_Formulation::convert_model_time(), determine_model_time_offset(), get_bmi_input_variables(), get_bmi_output_var_name(), get_bmi_output_variables(), get_data_start_time(), get_model_current_time(), get_model_end_time(), get_response(), get_value(), get_values(), realization::Bmi_C_Formulation::get_var_value_as(), realization::Bmi_Cpp_Formulation::get_var_value_as(), realization::Bmi_C_Formulation::get_var_value_as_double(), realization::Bmi_Cpp_Formulation::get_var_value_as_double(), inner_create_formulation(), realization::Bmi_C_Formulation::is_bmi_input_variable(), realization::Bmi_Cpp_Formulation::is_bmi_input_variable(), realization::Bmi_C_Formulation::is_bmi_output_variable(), realization::Bmi_Cpp_Formulation::is_bmi_output_variable(), realization::Bmi_C_Formulation::is_model_initialized(), realization::Bmi_Cpp_Formulation::is_model_initialized(), set_initial_bmi_parameters(), and set_model_inputs_prior_to_update().
|
overrideprotectedvirtual |
Implements realization::Bmi_Formulation.
References bmi_model_start_time_forcing_offset_s.
Referenced by set_model_inputs_prior_to_update().
|
protected |
Get correct BMI variable name, which may be the output or something mapped to this output.
name | |
bmi_var_name |
References bmi_var_names_map, get_bmi_model(), and bmi::Bmi::GetOutputVarNames().
Referenced by get_value(), and get_values().
|
overridevirtual |
Implements realization::Bmi_Formulation.
References get_bmi_model(), and bmi::Bmi::GetOutputVarNames().
Referenced by is_bmi_output_variable().
|
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 set_model_inputs_prior_to_update().
|
overridevirtual |
When possible, translate a variable name for a BMI model to an internally recognized name.
Translate some BMI variable name to something recognized in some internal context for use within NGen. Do this according to the map of variable names supplied in the external formulation config. If no mapping for the given variable name was configured, return the variable name itself.
For example, perhaps a BMI model has the input variable "RAIN_RATE." Configuring this variable name to map to "precip_rate" will allow the formulation to understand that this particular forcing field should be used to set the model's "RAIN_RATE" variable.
model_var_name | The BMI variable name to translate so its purpose is recognized internally. |
Implements realization::Bmi_Formulation.
References bmi_var_names_map.
Referenced by set_model_inputs_prior_to_update().
|
overridevirtual |
Get the inclusive beginning of the period of time over which this instance can provide data for this forcing.
This is part of the DataProvider interface. This interface must be implemented for items of this type to be usable as "forcing" providers for situations when some other object needs to receive as an input (i.e., one of its forcings) a data property output from this object.
Implements data_access::DataProvider< DataType, SelectionType >.
References get_bmi_model(), and bmi::Bmi::GetStartTime().
|
overridevirtual |
Return the last valid time for which data from the requested variable can be requested.
Implements data_access::DataProvider< DataType, SelectionType >.
|
pure virtualinherited |
Implemented in realization::Bmi_C_Formulation, realization::Bmi_Cpp_Formulation, and realization::Bmi_Multi_Formulation.
Referenced by get_response(), get_value(), get_values(), and realization::Formulation::validate_parameters().
|
inlineinherited |
References realization::Formulation::id.
|
overridevirtual |
Get the current time for the backing BMI model in its native format and units.
Implements realization::Bmi_Formulation.
References get_bmi_model(), and bmi::Bmi::GetCurrentTime().
|
overridevirtual |
Get the end time for the backing BMI model in its native format and units.
Implements realization::Bmi_Formulation.
References get_bmi_model(), and bmi::Bmi::GetEndTime().
|
inlineinherited |
Get the name of the specific type of the backing model object.
References realization::Bmi_Formulation::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().
|
inlineinherited |
Get the values making up the header line from get_output_header_line(), but organized as a vector of strings.
References realization::Bmi_Formulation::output_header_fields.
Referenced by realization::Bmi_Formulation::get_output_header_line().
|
inlineoverridevirtualinherited |
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 realization::Bmi_Formulation::get_output_header_fields().
|
overridevirtual |
Get a delimited string with all the output variable values for the given time step.
This method is useful for preparing calculated data in a representation useful for output files, such as CSV files.
The resulting string contains only the calculated output values for the time step, and not the time step index 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.
The default delimiter is a comma.
Implementations will throw invalid_argument
exceptions if data for the provided time step parameter is not accessible. Note that, for this type, only the last processed time step is accessible, because formulations do not save results from previous time steps. This also has the consequence of there being no valid set of arguments before a least one call to get_response has been made.
timestep | The time step for which data is desired. |
Implements realization::Catchment_Formulation.
References realization::Bmi_Formulation::get_output_variable_names(), realization::Bmi_Formulation::get_var_value_as_double(), and next_time_step_index.
|
inlineprotectedinherited |
References realization::Bmi_Formulation::output_precision.
|
inlineinherited |
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 realization::Bmi_Formulation::output_variable_names.
Referenced by realization::Bmi_Multi_Formulation::check_output_var_names(), realization::Bmi_Multi_Formulation::create_multi_formulation(), get_output_line_for_timestep(), realization::Bmi_Multi_Formulation::get_output_line_for_timestep(), and inner_create_formulation().
|
overridevirtual |
Reimplemented from realization::Bmi_Formulation.
References REQUIRED_PARAMETERS.
|
overridevirtual |
Get the model response for a time step.
Get the model response for the provided time step, executing the backing model formulation one or more times as needed.
Function assumes the backing model has been fully initialized an that any additional input values have been applied.
The function throws an error if the index of a previously processed time step is supplied, except if it is the last processed time step. In that case, the appropriate value is returned as described below, but without executing any model update.
Assuming updating to the implied time is valid for the model, the function executes one or more model updates to process future time steps for the necessary indexes. Multiple time steps updates occur when the given future time step index is not the next time step index to be processed. Regardless, all processed time steps have the size supplied in t_delta
.
However, it is possible to provide t_index
and t_delta
values that would result in the aggregate updates taking the model's time beyond its end_time
value. In such cases, if the formulation config indicates this model is not allow to exceed its set end_time
, the function does not update the model and throws an error.
The function will return the value of the primary output variable (see get_bmi_main_output_var()
) for the given time step after the model has been updated to that point. The type returned will always be a double
, with other numeric types being cast if necessary.
The BMI spec requires for variable values to be passed to/from models via as arrays. This function essentially treats the variable array reference as if it were just a raw pointer and returns the 0
-th array value.
t_index | The index of the time step for which to run model calculations. |
d_delta_s | The duration, in seconds, of the time step for which to run model calculations. |
Implements realization::Catchment_Formulation.
References models::bmi::Bmi_Adapter::convert_seconds_to_model_time(), get_allow_model_exceed_end_time(), realization::Bmi_Formulation::get_bmi_main_output_var(), get_bmi_model(), realization::Formulation::get_formulation_type(), realization::Bmi_Formulation::get_var_value_as_double(), bmi::Bmi::GetCurrentTime(), next_time_step_index, set_model_inputs_prior_to_update(), bmi::Bmi::Update(), and bmi::Bmi::UpdateUntil().
|
overridevirtual |
Get the index of the forcing time step that contains the given point in time.
This is part of the ForcingProvider interface. This interface must be implemented for items of this type to be usable as "forcing" providers for situations when some other object needs to receive as an input (i.e., one of its forcings) a data property output from this object.
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. |
Implements data_access::DataProvider< DataType, SelectionType >.
|
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 set_model_inputs_prior_to_update().
|
override |
Get the value of a forcing property for an arbitrary time period, converting units if needed.
This is part of the ForcingProvider interface. This interface must be implemented for items of this type to be usable as "forcing" providers for situations when some other object needs to receive as an input (i.e., one of its forcings) a data property output from this object.
An std::out_of_range exception should be thrown if the data for the time period is not available.
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. |
References get_available_variable_names(), get_bmi_model(), get_bmi_output_var_name(), UnitsHelper::get_converted_value(), CatchmentAggrDataSelector::get_duration_secs(), realization::Formulation::get_formulation_type(), CatchmentAggrDataSelector::get_init_time(), CatchmentAggrDataSelector::get_output_units(), realization::Bmi_Formulation::get_var_value_as_double(), CatchmentAggrDataSelector::get_variable_name(), and bmi::Bmi::GetVarUnits().
|
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 set_model_inputs_prior_to_update().
|
override |
Get the 1D values of a forcing property for an arbitrary time period, converting units if needed.
output_name | The name of the forcing property of interest. |
init_time | The epoch time (in seconds) of the start of the time period. |
duration_s | 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. |
std::runtime_error | output_name is not one of the available outputs of this provider instance. |
References UnitsHelper::convert_values(), get_available_variable_names(), get_bmi_model(), get_bmi_output_var_name(), CatchmentAggrDataSelector::get_duration_secs(), realization::Formulation::get_formulation_type(), CatchmentAggrDataSelector::get_init_time(), CatchmentAggrDataSelector::get_output_units(), CatchmentAggrDataSelector::get_variable_name(), models::bmi::GetValue(), bmi::Bmi::GetVarUnits(), and logging::warning().
|
pure virtualinherited |
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 get_output_line_for_timestep(), get_response(), and get_value().
time_t realization::Bmi_Module_Formulation::get_variable_time_begin | ( | const std::string & | variable_name | ) |
Get the inclusive beginning of the period of time over which this instance can provide data for this forcing.
This is part of the ForcingProvider interface. This interface must be implemented for items of this type to be usable as "forcing" providers for situations when some other object needs to receive as an input (i.e., one of its forcings) a data property output from this object.
|
protected |
Universal logic applied when creating a BMI-backed formulation from NGen config.
This performs all the necessary steps to initialize this formulation from provided configuration properties. It is written in such a way that it can be used in appropriately crafted nested calls from both public create_formulation
implementations, thus allowing the primary formulation initialization logic to be centralized and not duplicated.
properties | |
needs_param_validation |
References available_forcings, bmi_var_names_map, construct_model(), determine_model_time_offset(), get_bmi_model(), realization::Bmi_Formulation::get_output_variable_names(), models::bmi::Bmi_Adapter::is_model_initialized(), model_initialized, set_allow_model_exceed_end_time(), set_bmi_init_config(), realization::Bmi_Formulation::set_bmi_main_output_var(), set_bmi_model(), set_bmi_model_time_step_fixed(), set_initial_bmi_parameters(), realization::Bmi_Formulation::set_model_type_name(), realization::Bmi_Formulation::set_output_header_fields(), realization::Bmi_Formulation::set_output_precision(), realization::Bmi_Formulation::set_output_variable_names(), and realization::Formulation::validate_parameters().
Referenced by create_formulation(), and create_formulation().
|
inlineprotectedinherited |
References realization::Formulation::validate_parameters().
Referenced by create_formulation(), and realization::Bmi_Multi_Formulation::create_formulation().
|
overridevirtual |
Implements realization::Bmi_Formulation.
References get_bmi_input_variables(), and realization::is_var_name_in_collection().
|
overrideprotectedvirtual |
Test whether backing model has fixed time step size.
Implements realization::Bmi_Formulation.
References bmi_model_time_step_fixed.
Referenced by realization::Bmi_C_Formulation::construct_model(), and realization::Bmi_Cpp_Formulation::construct_model().
|
overridevirtual |
Implements realization::Bmi_Formulation.
References get_bmi_output_variables(), and realization::is_var_name_in_collection().
|
overrideprotectedvirtual |
Test whether the backing model object has been initialize using the BMI standard Initialize
function.
Initialize
function. Implements realization::Bmi_Formulation.
References model_initialized.
|
overridevirtual |
Get whether a property's per-time-step values are each an aggregate sum over the entire time step.
This is part of the ForcingProvider interface. This interface must be implemented for items of this type to be usable as "forcing" providers for situations when some other object needs to receive as an input (i.e., one of its forcings) a data property output from this object.
Certain properties, like rain fall, are aggregated sums over an entire time step. Others, such as pressure, are not such sums and instead something else like an instantaneous reading or an average value.
It may be the case that forcing data is needed for some discretization different than the forcing time step. This aspect must be known in such cases to perform the appropriate value interpolation.
For instances of this type, all output forcings fall under this category.
name | The name of the forcing property for which the current value is desired. |
true
for this type. Reimplemented from data_access::DataProvider< DataType, SelectionType >.
|
overridevirtual |
Return the stride in the time dimension.
Implements data_access::DataProvider< DataType, SelectionType >.
|
protected |
References allow_model_exceed_end_time.
Referenced by inner_create_formulation().
|
protected |
References bmi_init_config.
Referenced by inner_create_formulation().
|
inlineprotectedinherited |
|
protected |
Set the backing model object implementing the BMI.
model | Shared pointer to the BMI model. |
References bmi_model.
Referenced by inner_create_formulation().
|
protected |
References bmi_model_start_time_forcing_offset_s.
Referenced by determine_model_time_offset().
|
protected |
References bmi_model_time_step_fixed.
Referenced by inner_create_formulation().
|
inlineoverrideprotectedvirtualinherited |
Implements HY_CatchmentRealization.
References realization::Catchment_Formulation::cat_id.
Referenced by realization::Catchment_Formulation::Catchment_Formulation(), and realization::Catchment_Formulation::Catchment_Formulation().
|
protected |
Check configuration properties for model_params
and attempt to set them in the bmi model.
This checks for a key named model_params
in the parsed properties, and for each property it will attempt to call SetValue
using the property's key as the BMI variable and the property's value as the value to set.
This function should only be called once bmi_model
is properly constructed. If bmi_model
is a nullptr, this function becomes a no-op.
References models::bmi::Bmi_Adapter::get_analogous_cxx_type(), get_bmi_model(), geojson::get_propertytype_name(), realization::get_values_as_type(), bmi::Bmi::GetVarItemsize(), bmi::Bmi::GetVarNbytes(), geojson::List, geojson::Natural, geojson::Real, bmi::Bmi::SetValue(), and logging::warning().
Referenced by inner_create_formulation().
|
protectedvirtual |
Set whether the backing model object has been initialize using the BMI standard Initialize
function.
is_initialized | Whether model object has been initialize using the BMI standard Initialize . |
References model_initialized.
|
protected |
Set BMI input variable values for the model appropriately prior to calling its BMI
update()``.
model_initial_time | The model's time prior to the update, in its internal units and representation. |
t_delta | The size of the time step over which the formulation is going to update the model, which might be different than the model's internal time step. |
References realization::Bmi_Formulation::convert_model_time(), realization::Catchment_Formulation::forcing, models::bmi::Bmi_Adapter::get_analogous_cxx_type(), get_bmi_model(), get_bmi_model_start_time_forcing_offset_s(), realization::Catchment_Formulation::get_catchment_id(), get_config_mapped_variable_name(), data_access::DataProvider< DataType, SelectionType >::get_value(), realization::get_value_as_type(), data_access::DataProvider< DataType, SelectionType >::get_values(), realization::get_values_as_type(), bmi::Bmi::GetInputVarNames(), bmi::Bmi::GetVarItemsize(), bmi::Bmi::GetVarNbytes(), input_forcing_providers, and bmi::Bmi::SetValue().
Referenced by get_response().
|
inlineprotectedvirtualinherited |
Set the name of the specific type of the backing model object.
type_name | The name of the backing model object's type. |
References realization::Bmi_Formulation::model_type_name.
Referenced by realization::Bmi_Multi_Formulation::create_multi_formulation(), and inner_create_formulation().
|
inlineprotectedinherited |
|
inlineinherited |
Set the precision of output values when converted to text.
precision | The desired precision, as a number of decimal places. |
References realization::Bmi_Formulation::output_precision, and realization::Bmi_Formulation::output_text_stream.
Referenced by realization::Bmi_Formulation::Bmi_Formulation(), realization::Bmi_Multi_Formulation::create_multi_formulation(), and inner_create_formulation().
|
inlineinherited |
References HY_CatchmentArea::output.
|
inlineprotectedinherited |
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 realization::Bmi_Formulation::output_variable_names.
Referenced by realization::Bmi_Multi_Formulation::create_multi_formulation(), and inner_create_formulation().
|
inlineprotectedinherited |
|
inlineinherited |
References HY_CatchmentArea::output.
Referenced by ngen::DomainLayer::DomainLayer(), and ngen::DomainLayer::update_models().
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
private |
Whether model Update
calls are allowed and handled in some way by the backing model for time steps after the model's end_time
.
Referenced by get_allow_model_exceed_end_time(), and set_allow_model_exceed_end_time().
|
private |
The set of available "forcings" (output variables, plus their mapped aliases) that the model can provide.
Referenced by get_available_variable_names(), and inner_create_formulation().
|
private |
Referenced by get_bmi_init_config(), and set_bmi_init_config().
|
privateinherited |
|
private |
Referenced by get_bmi_model(), and set_bmi_model().
|
private |
The offset, converted to seconds, from the model's start time to the start time of the initial forcing time step.
Referenced by get_bmi_model_start_time_forcing_offset_s(), and set_bmi_model_start_time_forcing_offset_s().
|
private |
Whether backing model has fixed time step size.
Referenced by is_bmi_model_time_step_fixed(), and set_bmi_model_time_step_fixed().
|
private |
A configured mapping of BMI model variable names to standard names for use inside the framework.
Referenced by get_bmi_output_var_name(), get_config_mapped_variable_name(), and inner_create_formulation().
|
protectedinherited |
|
privateinherited |
|
protectedinherited |
Referenced by realization::Bmi_Multi_Formulation::create_multi_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 set_model_inputs_prior_to_update().
|
protectedinherited |
Referenced by realization::Formulation::get_id().
|
protectedinherited |
|
protected |
Referenced by set_model_inputs_prior_to_update().
|
protected |
The delta of the last model update execution (typically, this is time step size).
|
protected |
The epoch time of the model at the beginning of its last update.
|
private |
Referenced by inner_create_formulation(), is_model_initialized(), and set_model_initialized().
|
privateinherited |
|
protected |
Index value (0-based) of the time step that will be processed by the next update of the model.
A formulation time step for BMI types can be thought of as the execution of a call to any of the functions of the underlying BMI model that advance the model (either update
or update_until
). This member stores the ordinal index of the next time step to be executed. Except in the initial formulation state, this will be one greater than the index of the last executed time step.
E.g., on initialization, before any calls to get_response, this value will be 0
. After a call to get_response (assuming 0
as the passed t_index
argument), time step 0
will be processed, and this member would be incremented by 1, thus making it 1
.
The member serves as an implicit marker of how many time steps have been processed so far. Knowing this is required to maintain valid behavior in certain things, such as get_response (we may want to process multiple time steps forward to a particular index other than the next, but it would not be valid to receive a t_index
earlier than the last processed time step) and get_output_line_for_timestep (because formulations do not save results from previous time steps, only the results from the last processed time step can be used to generate output).
Referenced by get_output_line_for_timestep(), and get_response().
|
private |
|
protectedinherited |
|
privateinherited |
Output header field strings corresponding to the variables output by the realization, as defined in output_variable_names
.
Referenced by realization::Bmi_Formulation::get_output_header_fields(), and realization::Bmi_Formulation::set_output_header_fields().
|
privateinherited |
The degree of precision in output values when converting to text.
Referenced by realization::Bmi_Formulation::get_output_precision(), and realization::Bmi_Formulation::set_output_precision().
|
protectedinherited |
Object to help with converting numeric output values to text.
Referenced by realization::Bmi_Multi_Formulation::get_output_line_for_timestep(), and realization::Bmi_Formulation::set_output_precision().
|
privateinherited |
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 realization::Bmi_Formulation::get_output_variable_names(), and realization::Bmi_Formulation::set_output_variable_names().
|
protectedinherited |
|
private |
Referenced by get_required_parameters().