NGen
|
Abstraction of a formulation with multiple backing model object that implements the BMI. More...
#include <Bmi_Multi_Formulation.hpp>
Public Types | |
typedef Bmi_Formulation | nested_module_type |
typedef std::shared_ptr< nested_module_type > | nested_module_ptr |
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_Multi_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 . | |
virtual | ~Bmi_Multi_Formulation () |
time_t | convert_model_time (const double &model_time) const override |
Convert a time value from the model to an epoch time in seconds. | |
time_t | convert_model_time (const double &model_time, int module_index) const |
Convert a time value from the model to an epoch time in seconds. | |
void | create_formulation (boost::property_tree::ptree &config, geojson::PropertyMap *global=nullptr) override |
void | create_formulation (geojson::PropertyMap properties) override |
const bool & | get_allow_model_exceed_end_time () const override |
Get whether a model may perform updates beyond its end_time . | |
boost::span< const std::string > | get_available_variable_names () const override |
Get the collection of forcing output property names this instance can provide. | |
const std::vector< std::string > | get_bmi_input_variables () const override |
Get the input variables of the first nested BMI model. | |
const time_t & | get_bmi_model_start_time_forcing_offset_s () const override |
const std::vector< std::string > | get_bmi_output_variables () const override |
Get the output variables of the last nested BMI model. | |
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. | |
const std::string & | get_config_mapped_variable_name (const std::string &model_var_name, bool check_first, bool check_last) const |
When possible, translate a variable name for the first or last BMI model to an internally recognized name. | |
const std::string & | get_config_mapped_variable_name (const std::string &output_var_name, const std::shared_ptr< Bmi_Formulation > &out_module, const std::shared_ptr< Bmi_Formulation > &in_module) const |
When possible, translate the name of an output variable for one BMI model to an input variable for another. | |
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. | |
time_t | get_variable_time_begin (const std::string &variable_name) const |
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 |
Get the exclusive ending of the period of time over which this instance can provide data for this forcing. | |
time_t | get_variable_time_end (const std::string &variable_name) const |
Get the exclusive ending of the period of time over which this instance can provide data for this forcing. | |
long | record_duration () const override |
Return the stride in the time dimension. | |
std::string | get_formulation_type () const override |
const double | get_model_current_time () const override |
Get the current time for the primary nested BMI model in its native format and units. | |
const double | get_model_end_time () const override |
Get the end time for the primary nested BMI model in its native format and units. | |
const double | get_model_start_time () |
Get the end time for the primary nested BMI model in its native format and units. | |
std::string | get_output_line_for_timestep (int timestep, std::string delimiter) override |
Get a formatted line of output values for the given time step as a delimited string. | |
double | get_response (time_step_t t_index, time_step_t t_delta) override |
Execute the backing model formulation for the given time step, where it is of the specified size, and return the response output. | |
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. | |
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. | |
std::vector< double > | get_values (const CatchmentAggrDataSelector &selector, data_access::ReSampleMethod m) override |
bool | is_bmi_input_variable (const std::string &var_name) const override |
bool | is_bmi_model_time_step_fixed () const override |
Test whether all backing models have fixed time step size. | |
bool | is_bmi_output_variable (const std::string &var_name) const override |
bool | is_model_initialized () const override |
Test whether all backing models have been initialize using the BMI standard Initialize function. | |
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. | |
bool | is_time_step_beyond_end_time (time_step_t t_index) |
Get whether this time step goes beyond this formulations (i.e., any of it's modules') end time. | |
int | get_index_for_primary_module () const |
Get the index of the primary module. | |
void | set_index_for_primary_module (int index) |
Set the index of the primary module. | |
void | check_output_var_names () |
Check that the output variable names in the global bmi_multi are valid names. | |
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. | |
const std::vector< std::string > & | get_required_parameters () const override |
void | set_output_precision (int precision) |
Set the precision of output values when converted to text. | |
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. | |
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 | create_multi_formulation (geojson::PropertyMap properties, bool needs_param_validation) |
Creating a multi-BMI-module formulation from NGen config. | |
double | get_var_value_as_double (const int &index, const std::string &var_name) override |
Get value for some BMI model variable at a specific index. | |
void | init_deferred_associations () |
Initialize the deferred associations with the providers in deferredProviders. | |
template<class T > | |
std::shared_ptr< T > | init_nested_module (int mod_index, std::string identifier, geojson::PropertyMap properties) |
Initialize a nested formulation from the given properties and update multi formulation metadata. | |
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::map< std::string, std::shared_ptr< data_access::GenericDataProvider > > | availableData |
A mapping of data properties to their providers. | |
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 Member Functions | |
template<class T > | |
void | setup_nested_deferred_provider (const std::string &bmi_input_var_name, const std::string &framework_output_name, std::shared_ptr< T > mod, int mod_index) |
Setup a deferred provider for a nested module, tracking the class as needed. | |
Private Attributes | |
std::vector< std::string > | available_forcings |
The set of available "forcings" (output variables, plus their mapped aliases) this instance can provide. | |
std::map< std::string, double > | default_output_values |
Any configured default values for outputs, keyed by framework alias (or var name if this is globally unique). | |
std::vector< std::shared_ptr< data_access::OptionalWrappedDataProvider > > | deferredProviders |
A collection of wrappers to nested formulations providing some output to an earlier nested formulation. | |
std::vector< int > | deferredProviderModuleIndices |
The module indices for the modules associated with each item in deferredProviders. | |
bool | is_out_vars_from_last_mod = false |
Whether the Bmi_Formulation::output_variable_names value is just the analogous value from this instance's final nested module. | |
std::vector< nested_module_ptr > | modules |
The nested BMI modules composing this multi-module formulation, in their order of execution. | |
std::vector< std::string > | module_types |
std::vector< std::shared_ptr< std::map< std::string, std::string > > > | module_variable_maps |
Per-module maps (ordered as in modules) of configuration-mapped names to BMI variable names. | |
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. | |
int | primary_module_index = -1 |
The index of the "primary" nested module, used when functionality is deferred to a particular module's behavior. | |
friend | Bmi_Multi_Formulation_Test |
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_Cpp_Multi_Array_Test |
Abstraction of a formulation with multiple backing model object that implements the BMI.
|
inherited |
This class provides a generic interface to data services.
std::shared_ptr<nested_module_type> realization::Bmi_Multi_Formulation::nested_module_ptr |
|
inherited |
|
inherited |
|
inline |
Minimal constructor for objects initialize using the Formulation_Manager and subsequent calls to create_formulation
.
id | |
forcing_config | |
output_stream |
|
inlinevirtual |
|
inline |
Check that the output variable names in the global bmi_multi are valid names.
References availableData, realization::Bmi_Formulation::get_output_variable_names(), and is_out_vars_from_last_mod.
Referenced by create_multi_formulation().
|
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 init_nested_module().
|
inlineoverridevirtual |
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.
For this type, this function will behave in the same manner as the analogous function of the current "primary" nested formulation, which is found in the instance's ordered collection of nested module formulations at the index returned by get_index_for_primary_module.
model_time | The time value in a model's representation that is to be converted. |
Implements realization::Bmi_Formulation.
References convert_model_time(), and get_index_for_primary_module().
Referenced by convert_model_time().
|
inline |
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.
For this type, this function will behave in the same manner as the analogous function of nested formulation found at the provided index within the instance's ordered collection of nested module formulations.
model_time | The time value in a model's representation that is to be converted. |
References modules.
|
inlineoverridevirtual |
Implements realization::Catchment_Formulation.
References create_multi_formulation(), and realization::Formulation::interpret_parameters().
|
inlineoverridevirtual |
Implements realization::Catchment_Formulation.
References create_multi_formulation().
|
protected |
Creating a multi-BMI-module formulation from NGen config.
properties | |
needs_param_validation |
References geojson::JSONProperty::as_real_number(), geojson::JSONProperty::as_string(), geojson::JSONProperty::at(), available_forcings, availableData, check_output_var_names(), default_output_values, realization::Catchment_Formulation::forcing, realization::Catchment_Formulation::get_catchment_id(), get_formulation_type(), realization::Bmi_Formulation::get_output_variable_names(), init_deferred_associations(), is_out_vars_from_last_mod, module_types, module_variable_maps, modules, primary_module_index, realization::Bmi_Formulation::set_bmi_main_output_var(), 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().
|
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.
|
overridevirtual |
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 modules.
|
overridevirtual |
Get the collection of forcing output property names this instance can provide.
For this type, this is the collection of the names/aliases of the BMI output variables for nested modules; i.e., the config-mapped alias for the variable when set in the realization config, or just the name when no alias was included in the configuration.
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.
Implements data_access::DataProvider< DataType, SelectionType >.
References available_forcings.
|
inlineoverridevirtual |
Get the input variables of the first nested BMI model.
Implements realization::Bmi_Formulation.
References modules.
|
inlineinherited |
References realization::Bmi_Formulation::bmi_main_output_var.
Referenced by realization::Bmi_Module_Formulation::get_response(), and get_response().
|
overridevirtual |
Implements realization::Bmi_Formulation.
References modules.
|
inlineoverridevirtual |
Get the output variables of the last nested BMI model.
Implements realization::Bmi_Formulation.
References modules.
|
inlineoverrideprotectedvirtualinherited |
Implements HY_CatchmentRealization.
References realization::Catchment_Formulation::cat_id.
Referenced by create_multi_formulation(), get_value(), get_values(), get_var_value_as_double(), and realization::Bmi_Module_Formulation::set_model_inputs_prior_to_update().
|
overridevirtual |
When possible, translate a variable name for a BMI model to an internally recognized name.
Because of the implementation of this type, this function can only translate variable names for input or output variables of either the first or last nested BMI module. In cases when this is not possible, it will return the original parameter.
The function will only check input variable names for the first module and output variable names for the last module. Further, it will always check the first module first, returning if it finds a translation. Only then will it check the last module. This can be controlled by using the overloaded function get_config_mapped_variable_name(string, bool, bool).
To perform a similar translation between modules, see the overloaded function get_config_mapped_variable_name(string, shared_ptr, shared_ptr).
model_var_name | The BMI variable name to translate so its purpose is recognized internally. |
Because of the implementation of this type, this function can only translate variable names for input or output variables of either the first or last nested BMI module. In cases when this is not possible, it will return the original parameter.
The function will check the first module first, returning if it finds a translation. Only then will it check the last module.
To perform a similar translation between modules, see the overloaded function get_config_mapped_variable_name(string, shared_ptr, shared_ptr).
model_var_name | The BMI variable name to translate so its purpose is recognized internally. |
Implements realization::Bmi_Formulation.
References get_config_mapped_variable_name().
Referenced by get_config_mapped_variable_name().
const std::string & Bmi_Multi_Formulation::get_config_mapped_variable_name | ( | const std::string & | model_var_name, |
bool | check_first, | ||
bool | check_last ) const |
When possible, translate a variable name for the first or last BMI model to an internally recognized name.
Because of the implementation of this type, this function can only translate variable names for input or output variables of either the first or last nested BMI module. In cases when this is not possible, it will return the original parameter.
The function can only check input variable names for the first module and output variable names for the last module. Parameters control whether each is actually checked. When both are true
, it will always check the first module first, returning if it finds a translation without checking the last.
model_var_name | The BMI variable name to translate so its purpose is recognized internally. |
check_first | Whether an input variable mapping for the first module should sought. |
check_last | Whether an output variable mapping for the last module should sought. |
References is_bmi_input_variable(), and modules.
const std::string & Bmi_Multi_Formulation::get_config_mapped_variable_name | ( | const std::string & | output_var_name, |
const std::shared_ptr< Bmi_Formulation > & | out_module, | ||
const std::shared_ptr< Bmi_Formulation > & | in_module ) const |
When possible, translate the name of an output variable for one BMI model to an input variable for another.
This function behaves similarly to get_config_mapped_variable_name(string), except that is performs the translation between modules (rather than between a module and the framework). As such, it is designed for translation between two sequential models, although this is not a requirement for valid execution.
The function will first request the mapping for the parameter name from the outputting module, which will either return a mapped name or the original param. It will check if the returned value is one of the advertised BMI input variable names of the inputting module; if so, it returns that name. Otherwise, it proceeds.
The function then iterates through all the BMI input variable names for the inputting module. If it finds any that maps to either the original parameter or the mapped name from the outputting module, it returns it.
If neither of those find a mapping, then the original parameter is returned.
Note that if this is not an output variable name of the outputting module, the function treats this as a no-mapping condition and returns the parameter.
output_var_name | The output variable to be translated. |
out_module | The module having the output variable. |
in_module | The module needing a translation of output_var_name to one of its input variable names. |
|
inlineoverridevirtual |
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.
Implements data_access::DataProvider< DataType, SelectionType >.
References get_variable_time_begin().
|
inlineoverridevirtual |
Get the exclusive ending 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.
Implements data_access::DataProvider< DataType, SelectionType >.
References get_variable_time_end().
|
inlineoverridevirtual |
Implements realization::Formulation.
Referenced by create_multi_formulation(), get_value(), get_values(), get_variable_time_begin(), get_variable_time_end(), is_property_sum_over_time_step(), and record_duration().
|
inlineinherited |
References realization::Formulation::id.
|
inline |
Get the index of the primary module.
References primary_module_index.
Referenced by convert_model_time(), get_model_current_time(), get_model_end_time(), get_model_start_time(), and get_response().
|
inlineoverridevirtual |
Get the current time for the primary nested BMI model in its native format and units.
Implements realization::Bmi_Formulation.
References get_index_for_primary_module(), and modules.
Referenced by get_response(), and get_var_value_as_double().
|
inlineoverridevirtual |
Get the end time for the primary nested BMI model in its native format and units.
Implements realization::Bmi_Formulation.
References get_index_for_primary_module(), and modules.
|
inline |
Get the end time for the primary nested BMI model in its native format and units.
References get_index_for_primary_module(), and modules.
Referenced by get_var_value_as_double().
|
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 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. |
Implements realization::Catchment_Formulation.
References realization::Bmi_Formulation::get_output_variable_names(), get_var_value_as_double(), is_out_vars_from_last_mod, modules, next_time_step_index, and realization::Bmi_Formulation::output_text_stream.
|
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 check_output_var_names(), create_multi_formulation(), realization::Bmi_Module_Formulation::get_output_line_for_timestep(), get_output_line_for_timestep(), and realization::Bmi_Module_Formulation::inner_create_formulation().
|
inlineoverridevirtualinherited |
Implements realization::Catchment_Formulation.
Reimplemented in realization::Bmi_Module_Formulation.
References realization::Bmi_Formulation::REQUIRED_PARAMETERS.
|
overridevirtual |
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 realization::Catchment_Formulation.
References realization::Bmi_Formulation::get_bmi_main_output_var(), get_index_for_primary_module(), get_model_current_time(), is_time_step_beyond_end_time(), modules, and next_time_step_index.
|
inlineoverridevirtual |
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 realization::Bmi_Module_Formulation::set_model_inputs_prior_to_update().
|
inlineoverride |
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.
For this type, the availableData map contains available properties and either the external forcing provider or the internal nested module that provides that output property. That member is set during creation, within the create_multi_formulation function. This function implementation simply defers to the function of the same name in the appropriate nested forcing provider.
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 availableData, realization::Catchment_Formulation::get_catchment_id(), CatchmentAggrDataSelector::get_duration_secs(), get_formulation_type(), CatchmentAggrDataSelector::get_init_time(), CatchmentAggrDataSelector::get_output_units(), and CatchmentAggrDataSelector::get_variable_name().
|
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().
|
inlineoverride |
|
inlineoverrideprotectedvirtual |
Get value for some BMI model variable at a specific index.
Function gets the value for a provided variable, retrieving the variable array from the backing model of the appropriate nested formulation. The function then 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` corresponds to a BMI variable for some nested module. 3. `var_name` is sufficient to identify what value needs to be retrieved 4. the type for output variable allows the value to be cast to a `double` appropriately
Item 3. here can be inferred from 2. for non-multi formulations. For multi formulations, this means the provided var_name
must either be a unique BMI variable name among all nested module, or a unique mapped alias to a specific variable in a specific module.
It falls to users of this function (i.e., other functions) to ensure these assumptions hold before invoking.
index | |
var_name |
Implements realization::Bmi_Formulation.
References availableData, realization::Catchment_Formulation::get_catchment_id(), get_model_current_time(), get_model_start_time(), and record_duration().
Referenced by get_output_line_for_timestep().
|
inline |
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.
References availableData, realization::Catchment_Formulation::forcing, and get_formulation_type().
Referenced by get_data_start_time().
|
inline |
Get the exclusive ending 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.
References availableData, realization::Catchment_Formulation::forcing, and get_formulation_type().
Referenced by get_data_stop_time().
|
inlineprotected |
Initialize the deferred associations with the providers in deferredProviders.
During nested formulation creation, when a nested formulation requires as input some output expected from soon-to-be-created (i.e., later in execution order) formulation (e.g., in a look-back scenario to an earlier time step), then a deferred provider gets registered with the nested module and has a reference added to the deferredProviders member. This function goes through all such the deferred providers, ensures there is something available that can serve as the backing wrapped provider, and associates them.
References availableData, deferredProviderModuleIndices, and deferredProviders.
Referenced by create_multi_formulation().
|
inlineprotected |
Initialize a nested formulation from the given properties and update multi formulation metadata.
This function creates a new formulation, processes the mapping of BMI variables, and adds outputs to the outer module's provideable data items.
Note that it is VERY IMPORTANT that properties
argument`` is provided by value, as this copy is potentially updated to perform per-feature pattern substitution for certain property element values.
T | The particular type for the nested formulation object. |
mod_index | The index for the new formulation in this instance's collection of nested formulations. |
identifier | The id of for the represented feature. |
properties | A COPY of the nested module config properties for the nested formulation of interest. |
References availableData, realization::Catchment_Formulation::config_pattern_substitution(), module_variable_maps, HY_CatchmentArea::output, and setup_nested_deferred_provider().
|
inlineprotectedinherited |
References realization::Formulation::validate_parameters().
Referenced by realization::Bmi_Module_Formulation::create_formulation(), and create_formulation().
|
overridevirtual |
Implements realization::Bmi_Formulation.
References modules.
Referenced by get_config_mapped_variable_name().
|
overridevirtual |
Test whether all backing models have fixed time step size.
Implements realization::Bmi_Formulation.
References modules.
|
overridevirtual |
Implements realization::Bmi_Formulation.
References modules.
|
overridevirtual |
Test whether all backing models have been initialize using the BMI standard Initialize
function.
Initialize
function. Implements realization::Bmi_Formulation.
References modules.
|
inlineoverridevirtual |
Get whether a property's per-time-step values are each an aggregate sum over the entire time step.
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.
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.
name | The name of the forcing property for which the current value is desired. |
Reimplemented from data_access::DataProvider< DataType, SelectionType >.
References availableData, and get_formulation_type().
bool Bmi_Multi_Formulation::is_time_step_beyond_end_time | ( | time_step_t | t_index | ) |
Get whether this time step goes beyond this formulations (i.e., any of it's modules') end time.
Get whether this time step goes beyond this formulation's (i.e., any of it's modules') end time.
t_index | The time step index in question. |
Referenced by get_response().
|
inlineoverridevirtual |
Return the stride in the time dimension.
Implements data_access::DataProvider< DataType, SelectionType >.
References availableData, and get_formulation_type().
Referenced by get_var_value_as_double().
|
inlineprotectedinherited |
|
inlineoverrideprotectedvirtualinherited |
Implements HY_CatchmentRealization.
References realization::Catchment_Formulation::cat_id.
Referenced by realization::Catchment_Formulation::Catchment_Formulation(), and realization::Catchment_Formulation::Catchment_Formulation().
|
inline |
Set the index of the primary module.
Note that this function does not alter the state of the class, or produce an error, if the index is out of range.
index | The index for the module. |
References modules, and primary_module_index.
|
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 create_multi_formulation(), and realization::Bmi_Module_Formulation::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(), create_multi_formulation(), and realization::Bmi_Module_Formulation::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 create_multi_formulation(), and realization::Bmi_Module_Formulation::inner_create_formulation().
|
inlineprivate |
Setup a deferred provider for a nested module, tracking the class as needed.
Create an optional wrapped provider for use with a nested module and some required variable it needs provided. Track this and the index of the nested modules in the member collections necessary for later initializing associations to backing providers that were originally deferred. Then, assign the created deferred wrapper provider as the provider for the variable in the nested module.
T |
bmi_input_var_name | The name of the required input variable a nested module needs provided. |
framework_output_name | The framework alias of the required output variable that will be provided to the aforementioned input variable (which may be the same as bmi_input_var_name ). |
mod | The nested module requiring a deferred wrapped provider for a variable. |
mod_index | The index of the given nested module in the ordering of all this instance's nested modules. |
References default_output_values, deferredProviderModuleIndices, and deferredProviders.
Referenced by init_nested_module().
|
inlineprotectedinherited |
|
inlineinherited |
References HY_CatchmentArea::output.
Referenced by ngen::DomainLayer::DomainLayer(), and ngen::DomainLayer::update_models().
|
friend |
|
private |
The set of available "forcings" (output variables, plus their mapped aliases) this instance can provide.
Referenced by create_multi_formulation(), and get_available_variable_names().
|
protected |
A mapping of data properties to their providers.
Keys for the data properties are unique, name-like identifiers. These could be a BMI output variable name for a module, or a configuration-mapped alias of such a variable. The intent is for any module needing any input data to also have either an input variable name or input variable name mapping identical to one of these keys (and though ordering is important at a higher level, it is not handled directly by this member).
Referenced by check_output_var_names(), create_multi_formulation(), get_value(), get_values(), get_var_value_as_double(), get_variable_time_begin(), get_variable_time_end(), init_deferred_associations(), init_nested_module(), is_property_sum_over_time_step(), and record_duration().
|
privateinherited |
|
private |
|
protectedinherited |
|
privateinherited |
|
private |
Any configured default values for outputs, keyed by framework alias (or var name if this is globally unique).
Referenced by create_multi_formulation(), and setup_nested_deferred_provider().
|
private |
The module indices for the modules associated with each item in deferredProviders.
E.g., the value in this vector at index 0
is the index of a module within modules. That module is what required the deferred provider in the deferredProviders collection at its index 0
.
Referenced by init_deferred_associations(), and setup_nested_deferred_provider().
|
private |
A collection of wrappers to nested formulations providing some output to an earlier nested formulation.
During formulation creation, when a nested formulation requires as input some output from a later formulation (e.g., in a look-back scenario to an earlier time step), then an "optimistic" wrapper gets put into place. It assumes that the necessary provider will be available and associated once all nested formulations have been created. This member tracks these so that this deferred association can be done.
Referenced by init_deferred_associations(), and setup_nested_deferred_provider().
|
protectedinherited |
|
protectedinherited |
Referenced by realization::Formulation::get_id().
|
protectedinherited |
|
private |
Whether the Bmi_Formulation::output_variable_names value is just the analogous value from this instance's final nested module.
Referenced by check_output_var_names(), create_multi_formulation(), and get_output_line_for_timestep().
|
privateinherited |
|
private |
Referenced by create_multi_formulation().
|
private |
Per-module maps (ordered as in modules) of configuration-mapped names to BMI variable names.
Referenced by create_multi_formulation(), and init_nested_module().
|
private |
The nested BMI modules composing this multi-module formulation, in their order of execution.
Referenced by convert_model_time(), create_multi_formulation(), get_allow_model_exceed_end_time(), get_bmi_input_variables(), get_bmi_model_start_time_forcing_offset_s(), get_bmi_output_variables(), get_config_mapped_variable_name(), get_model_current_time(), get_model_end_time(), get_model_start_time(), get_output_line_for_timestep(), get_response(), is_bmi_input_variable(), is_bmi_model_time_step_fixed(), is_bmi_output_variable(), is_model_initialized(), and set_index_for_primary_module().
|
private |
Index value (0-based) of the time step that will be processed by the next update of the model.
Referenced by get_output_line_for_timestep(), and get_response().
|
staticprivateinherited |
|
protectedinherited |
Referenced by init_nested_module(), HY_CatchmentArea::set_output_stream(), and HY_CatchmentArea::write_output().
|
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 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().
|
private |
The index of the "primary" nested module, used when functionality is deferred to a particular module's behavior.
Referenced by create_multi_formulation(), get_index_for_primary_module(), and set_index_for_primary_module().
|
protectedinherited |
|
staticprivateinherited |
Referenced by realization::Bmi_Formulation::get_required_parameters().