NGen
Loading...
Searching...
No Matches
realization::Bmi_Multi_Formulation Class Referenceabstract

Abstraction of a formulation with multiple backing model object that implements the BMI. More...

#include <Bmi_Multi_Formulation.hpp>

+ Inheritance diagram for realization::Bmi_Multi_Formulation:
+ Collaboration diagram for realization::Bmi_Multi_Formulation:

Public Types

typedef Bmi_Formulation nested_module_type
 
typedef std::shared_ptr< nested_module_typenested_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_typeget_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::GenericDataProviderforcing
 
std::string id
 
polygon_t bounds
 
utils::StreamHandler output
 
std::shared_ptr< HY_Catchmentrealized_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_ptrmodules
 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
 

Detailed Description

Abstraction of a formulation with multiple backing model object that implements the BMI.

Member Typedef Documentation

◆ data_type

template<class DataType , class SelectionType >
using data_access::DataProvider< DataType, SelectionType >::data_type = DataType
inherited

This class provides a generic interface to data services.

◆ nested_module_ptr

◆ nested_module_type

◆ selection_type

template<class DataType , class SelectionType >
using data_access::DataProvider< DataType, SelectionType >::selection_type = SelectionType
inherited

◆ time_step_t

Constructor & Destructor Documentation

◆ Bmi_Multi_Formulation()

realization::Bmi_Multi_Formulation::Bmi_Multi_Formulation ( std::string id,
std::shared_ptr< data_access::GenericDataProvider > forcing_provider,
utils::StreamHandler output_stream )
inline

Minimal constructor for objects initialize using the Formulation_Manager and subsequent calls to create_formulation.

Parameters
id
forcing_config
output_stream

◆ ~Bmi_Multi_Formulation()

virtual realization::Bmi_Multi_Formulation::~Bmi_Multi_Formulation ( )
inlinevirtual

Member Function Documentation

◆ check_output_var_names()

void realization::Bmi_Multi_Formulation::check_output_var_names ( )
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().

◆ config_pattern_substitution()

static void realization::Catchment_Formulation::config_pattern_substitution ( geojson::PropertyMap & properties,
const std::string & key,
const std::string & pattern,
const std::string & replacement )
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.

Parameters
propertiesA reference to the properties config object to be altered.
keyThe key for the configuration property to potentially adjust.
patternThe pattern substring to search for that, when present, should be replaced.
replacementThe replacement substring to potentially insert.

References geojson::String.

Referenced by realization::Formulation_Manager::construct_missing_formulation(), and init_nested_module().

◆ convert_model_time() [1/2]

time_t realization::Bmi_Multi_Formulation::convert_model_time ( const double & model_time) const
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.

Parameters
model_timeThe time value in a model's representation that is to be converted.
Returns
The equivalent epoch time.

Implements realization::Bmi_Formulation.

References convert_model_time(), and get_index_for_primary_module().

Referenced by convert_model_time().

◆ convert_model_time() [2/2]

time_t realization::Bmi_Multi_Formulation::convert_model_time ( const double & model_time,
int module_index ) const
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.

Parameters
model_timeThe time value in a model's representation that is to be converted.
Returns
The equivalent epoch time.

References modules.

◆ create_formulation() [1/2]

void realization::Bmi_Multi_Formulation::create_formulation ( boost::property_tree::ptree & config,
geojson::PropertyMap * global = nullptr )
inlineoverridevirtual

◆ create_formulation() [2/2]

void realization::Bmi_Multi_Formulation::create_formulation ( geojson::PropertyMap properties)
inlineoverridevirtual

◆ create_multi_formulation()

◆ finalize() [1/2]

template<class DataType , class SelectionType >
virtual void data_access::DataProvider< DataType, SelectionType >::finalize ( )
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.

◆ finalize() [2/2]

void realization::Catchment_Formulation::finalize ( )
inlineinherited

Release resources of the given forcing provider.

References realization::Catchment_Formulation::forcing.

◆ get_allow_model_exceed_end_time()

const bool & Bmi_Multi_Formulation::get_allow_model_exceed_end_time ( ) const
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.

Returns
Whether a model may perform updates beyond its end_time.

Implements realization::Bmi_Formulation.

References modules.

◆ get_available_variable_names()

boost::span< const std::string > Bmi_Multi_Formulation::get_available_variable_names ( ) const
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.

Returns
The collection of forcing output property names this instance can provide.
See also
ForcingProvider

Implements data_access::DataProvider< DataType, SelectionType >.

References available_forcings.

◆ get_bmi_input_variables()

const std::vector< std::string > realization::Bmi_Multi_Formulation::get_bmi_input_variables ( ) const
inlineoverridevirtual

Get the input variables of the first nested BMI model.

Returns
The input variables of the first nested BMI model.

Implements realization::Bmi_Formulation.

References modules.

◆ get_bmi_main_output_var()

const std::string & realization::Bmi_Formulation::get_bmi_main_output_var ( ) const
inlineinherited

◆ get_bmi_model_start_time_forcing_offset_s()

const time_t & Bmi_Multi_Formulation::get_bmi_model_start_time_forcing_offset_s ( ) const
overridevirtual

Implements realization::Bmi_Formulation.

References modules.

◆ get_bmi_output_variables()

const std::vector< std::string > realization::Bmi_Multi_Formulation::get_bmi_output_variables ( ) const
inlineoverridevirtual

Get the output variables of the last nested BMI model.

Returns
The output variables of the last nested BMI model.

Implements realization::Bmi_Formulation.

References modules.

◆ get_catchment_id()

std::string realization::Catchment_Formulation::get_catchment_id ( ) const
inlineoverrideprotectedvirtualinherited

◆ get_config_mapped_variable_name() [1/3]

const std::string & Bmi_Multi_Formulation::get_config_mapped_variable_name ( const std::string & model_var_name) const
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).

Parameters
model_var_nameThe BMI variable name to translate so its purpose is recognized internally.
Returns
Either the translated equivalent variable name, or the provided name if there is not a mapping entry.
See also
get_config_mapped_variable_name(string, bool, bool)
get_config_mapped_variable_name(string, shared_ptr, shared_ptr)

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).

Parameters
model_var_nameThe BMI variable name to translate so its purpose is recognized internally.
Returns
Either the translated equivalent variable name, or the provided name if there is not a mapping entry.
See also
get_config_mapped_variable_name(string, shared_ptr, shared_ptr)

Implements realization::Bmi_Formulation.

References get_config_mapped_variable_name().

Referenced by get_config_mapped_variable_name().

◆ get_config_mapped_variable_name() [2/3]

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.

Parameters
model_var_nameThe BMI variable name to translate so its purpose is recognized internally.
check_firstWhether an input variable mapping for the first module should sought.
check_lastWhether an output variable mapping for the last module should sought.
Returns
Either the translated equivalent variable name, or the provided name if there is not a mapping entry.

References is_bmi_input_variable(), and modules.

◆ get_config_mapped_variable_name() [3/3]

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.

Parameters
output_var_nameThe output variable to be translated.
out_moduleThe module having the output variable.
in_moduleThe module needing a translation of output_var_name to one of its input variable names.
Returns
Either the translated equivalent variable name, or the provided name if there is not a mapping entry.

◆ get_data_start_time()

long realization::Bmi_Multi_Formulation::get_data_start_time ( ) const
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.

Returns
The inclusive beginning of the period of time over which this instance can provide this data.

Implements data_access::DataProvider< DataType, SelectionType >.

References get_variable_time_begin().

◆ get_data_stop_time()

long realization::Bmi_Multi_Formulation::get_data_stop_time ( ) const
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.

Returns
The exclusive ending of the period of time over which this instance can provide this data.

Implements data_access::DataProvider< DataType, SelectionType >.

References get_variable_time_end().

◆ get_formulation_type()

std::string realization::Bmi_Multi_Formulation::get_formulation_type ( ) const
inlineoverridevirtual

◆ get_id()

std::string realization::Formulation::get_id ( ) const
inlineinherited

◆ get_index_for_primary_module()

int realization::Bmi_Multi_Formulation::get_index_for_primary_module ( ) const
inline

Get the index of the primary module.

Returns
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().

◆ get_model_current_time()

const double realization::Bmi_Multi_Formulation::get_model_current_time ( ) const
inlineoverridevirtual

Get the current time for the primary nested BMI model in its native format and units.

Returns
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().

◆ get_model_end_time()

const double realization::Bmi_Multi_Formulation::get_model_end_time ( ) const
inlineoverridevirtual

Get the end time for the primary nested BMI model in its native format and units.

Returns
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.

◆ get_model_start_time()

const double realization::Bmi_Multi_Formulation::get_model_start_time ( )
inline

Get the end time for the primary nested BMI model in its native format and units.

Returns
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().

◆ get_model_type_name()

std::string realization::Bmi_Formulation::get_model_type_name ( ) const
inlineinherited

◆ get_output_header_fields()

const std::vector< std::string > & realization::Bmi_Formulation::get_output_header_fields ( ) const
inlineinherited

Get the values making up the header line from get_output_header_line(), but organized as a vector of strings.

Returns
The values making up the header line from get_output_header_line() organized as a vector.

References realization::Bmi_Formulation::output_header_fields.

Referenced by realization::Bmi_Formulation::get_output_header_line().

◆ get_output_header_line()

std::string realization::Bmi_Formulation::get_output_header_line ( std::string delimiter) const
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.

Returns
An appropriate header line for this type.

Reimplemented from realization::Catchment_Formulation.

References realization::Bmi_Formulation::get_output_header_fields().

◆ get_output_line_for_timestep()

std::string Bmi_Multi_Formulation::get_output_line_for_timestep ( int timestep,
std::string delimiter )
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.

Parameters
timestepThe time step for which data is desired.
delimiterThe value delimiter for the string.
Returns
A delimited string with all the output variable values for the given time step.

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.

◆ get_output_precision()

int realization::Bmi_Formulation::get_output_precision ( )
inlineprotectedinherited

◆ get_output_variable_names()

const std::vector< std::string > & realization::Bmi_Formulation::get_output_variable_names ( ) const
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.

Returns

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().

◆ get_required_parameters()

const std::vector< std::string > & realization::Bmi_Formulation::get_required_parameters ( ) const
inlineoverridevirtualinherited

◆ get_response()

double Bmi_Multi_Formulation::get_response ( time_step_t t_index,
time_step_t t_delta )
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.

Parameters
t_indexThe index of the time step for which to run model calculations.
t_deltaThe duration, in seconds, of the time step for which to run model calculations.
Returns
The response output of the model for this time step.

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.

◆ get_ts_index_for_time()

size_t realization::Bmi_Multi_Formulation::get_ts_index_for_time ( const time_t & epoch_time) const
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.

Parameters
epoch_timeThe point in time, as a seconds-based epoch time.
Returns
The index of the forcing time step that contains the given point in time.
Exceptions
std::out_of_rangeIf the given point is not in any time step.

Implements data_access::DataProvider< DataType, SelectionType >.

◆ get_value() [1/2]

template<class DataType , class SelectionType >
virtual data_type data_access::DataProvider< DataType, SelectionType >::get_value ( const selection_type & selector,
ReSampleMethod m = SUM )
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.

Parameters
selectorData required to establish what subset of the stored data should be accessed
mHow data is to be resampled if there is a mismatch in data alignment or repeat rate
Returns
The value of the forcing property for the described time period, with units converted if needed.
Exceptions
std::out_of_rangeIf 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().

◆ get_value() [2/2]

double realization::Bmi_Multi_Formulation::get_value ( const CatchmentAggrDataSelector & selector,
data_access::ReSampleMethod m )
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.

Parameters
output_nameThe name of the forcing property of interest.
init_time_epochThe epoch time (in seconds) of the start of the time period.
duration_secondsThe length of the time period, in seconds.
output_unitsThe expected units of the desired output value.
Returns
The value of the forcing property for the described time period, with units converted if needed.
Exceptions
std::out_of_rangeIf 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().

◆ get_values() [1/2]

template<class DataType , class SelectionType >
virtual std::vector< data_type > data_access::DataProvider< DataType, SelectionType >::get_values ( const selection_type & selector,
ReSampleMethod m = SUM )
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>

Parameters
output_nameThe name of the forcing property of interest.
init_time_epochThe epoch time (in seconds) of the start of the time period.
duration_secondsThe length of the time period, in seconds.
output_unitsThe expected units of the desired output value.
Returns
std::vector<double> The vector of values of the forcing property for the described time period, with units converted if needed.
Exceptions
std::out_of_rangeIf 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().

◆ get_values() [2/2]

◆ get_var_value_as_double()

double realization::Bmi_Multi_Formulation::get_var_value_as_double ( const int & index,
const std::string & var_name )
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.

Parameters
index
var_name
Returns

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().

◆ get_variable_time_begin()

time_t realization::Bmi_Multi_Formulation::get_variable_time_begin ( const std::string & variable_name) const
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.

Returns
The inclusive beginning of the period of time over which this instance can provide this data.

References availableData, realization::Catchment_Formulation::forcing, and get_formulation_type().

Referenced by get_data_start_time().

◆ get_variable_time_end()

time_t realization::Bmi_Multi_Formulation::get_variable_time_end ( const std::string & variable_name) const
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.

Returns
The exclusive ending of the period of time over which this instance can provide this data.

References availableData, realization::Catchment_Formulation::forcing, and get_formulation_type().

Referenced by get_data_stop_time().

◆ init_deferred_associations()

void realization::Bmi_Multi_Formulation::init_deferred_associations ( )
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().

◆ init_nested_module()

template<class T >
std::shared_ptr< T > realization::Bmi_Multi_Formulation::init_nested_module ( int mod_index,
std::string identifier,
geojson::PropertyMap properties )
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.

Template Parameters
TThe particular type for the nested formulation object.
Parameters
mod_indexThe index for the new formulation in this instance's collection of nested formulations.
identifierThe id of for the represented feature.
propertiesA COPY of the nested module config properties for the nested formulation of interest.
Returns

References availableData, realization::Catchment_Formulation::config_pattern_substitution(), module_variable_maps, HY_CatchmentArea::output, and setup_nested_deferred_provider().

◆ interpret_parameters()

geojson::PropertyMap realization::Formulation::interpret_parameters ( boost::property_tree::ptree & config,
geojson::PropertyMap * global = nullptr )
inlineprotectedinherited

◆ is_bmi_input_variable()

bool Bmi_Multi_Formulation::is_bmi_input_variable ( const std::string & var_name) const
overridevirtual

◆ is_bmi_model_time_step_fixed()

bool Bmi_Multi_Formulation::is_bmi_model_time_step_fixed ( ) const
overridevirtual

Test whether all backing models have fixed time step size.

Returns
Whether all backing models has fixed time step size.

Implements realization::Bmi_Formulation.

References modules.

◆ is_bmi_output_variable()

bool Bmi_Multi_Formulation::is_bmi_output_variable ( const std::string & var_name) const
overridevirtual

Implements realization::Bmi_Formulation.

References modules.

◆ is_model_initialized()

bool Bmi_Multi_Formulation::is_model_initialized ( ) const
overridevirtual

Test whether all backing models have been initialize using the BMI standard Initialize function.

Returns
Whether all backing models have been initialize using the BMI standard Initialize function.

Implements realization::Bmi_Formulation.

References modules.

◆ is_property_sum_over_time_step()

bool realization::Bmi_Multi_Formulation::is_property_sum_over_time_step ( const std::string & name) const
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.

Parameters
nameThe name of the forcing property for which the current value is desired.
Returns
Whether the property's value is an aggregate sum.

Reimplemented from data_access::DataProvider< DataType, SelectionType >.

References availableData, and get_formulation_type().

◆ is_time_step_beyond_end_time()

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.

Parameters
t_indexThe time step index in question.
Returns
Whether this time step goes beyond this formulations (i.e., any of it's modules') end time.

Referenced by get_response().

◆ record_duration()

long realization::Bmi_Multi_Formulation::record_duration ( ) const
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().

◆ set_bmi_main_output_var()

void realization::Bmi_Formulation::set_bmi_main_output_var ( const std::string & main_output_var)
inlineprotectedinherited

◆ set_catchment_id()

void realization::Catchment_Formulation::set_catchment_id ( std::string cat_id)
inlineoverrideprotectedvirtualinherited

◆ set_index_for_primary_module()

void realization::Bmi_Multi_Formulation::set_index_for_primary_module ( int index)
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.

Parameters
indexThe index for the module.

References modules, and primary_module_index.

◆ set_model_type_name()

virtual void realization::Bmi_Formulation::set_model_type_name ( std::string type_name)
inlineprotectedvirtualinherited

Set the name of the specific type of the backing model object.

Parameters
type_nameThe 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().

◆ set_output_header_fields()

void realization::Bmi_Formulation::set_output_header_fields ( const std::vector< std::string > & output_headers)
inlineprotectedinherited

◆ set_output_precision()

void realization::Bmi_Formulation::set_output_precision ( int precision)
inlineinherited

Set the precision of output values when converted to text.

Parameters
precisionThe 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().

◆ set_output_stream()

void HY_CatchmentArea::set_output_stream ( std::string file_path)
inlineinherited

◆ set_output_variable_names()

void realization::Bmi_Formulation::set_output_variable_names ( const std::vector< std::string > & out_var_names)
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.

Parameters
out_var_namesthe 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().

◆ setup_nested_deferred_provider()

template<class T >
void realization::Bmi_Multi_Formulation::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 )
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.

Template Parameters
T
Parameters
bmi_input_var_nameThe name of the required input variable a nested module needs provided.
framework_output_nameThe 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).
modThe nested module requiring a deferred wrapped provider for a variable.
mod_indexThe 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().

◆ validate_parameters()

◆ write_output()

void HY_CatchmentArea::write_output ( std::string out)
inlineinherited

Friends And Related Symbol Documentation

◆ ::Bmi_Cpp_Multi_Array_Test

friend class ::Bmi_Cpp_Multi_Array_Test
friend

Member Data Documentation

◆ available_forcings

std::vector<std::string> realization::Bmi_Multi_Formulation::available_forcings
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().

◆ availableData

std::map<std::string, std::shared_ptr<data_access::GenericDataProvider> > realization::Bmi_Multi_Formulation::availableData
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().

◆ bmi_main_output_var

std::string realization::Bmi_Formulation::bmi_main_output_var
privateinherited

◆ Bmi_Multi_Formulation_Test

friend realization::Bmi_Multi_Formulation::Bmi_Multi_Formulation_Test
private

◆ bounds

polygon_t HY_CatchmentArea::bounds
protectedinherited

◆ cat_id

std::string realization::Catchment_Formulation::cat_id
privateinherited

◆ default_output_values

std::map<std::string, double> realization::Bmi_Multi_Formulation::default_output_values
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().

◆ deferredProviderModuleIndices

std::vector<int> realization::Bmi_Multi_Formulation::deferredProviderModuleIndices
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().

◆ deferredProviders

std::vector<std::shared_ptr<data_access::OptionalWrappedDataProvider> > realization::Bmi_Multi_Formulation::deferredProviders
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().

◆ forcing

◆ id

std::string realization::Formulation::id
protectedinherited

◆ id_number

unsigned long HY_CatchmentRealization::id_number
protectedinherited

◆ is_out_vars_from_last_mod

bool realization::Bmi_Multi_Formulation::is_out_vars_from_last_mod = false
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().

◆ model_type_name

std::string realization::Bmi_Formulation::model_type_name
privateinherited

◆ module_types

std::vector<std::string> realization::Bmi_Multi_Formulation::module_types
private

◆ module_variable_maps

std::vector<std::shared_ptr<std::map<std::string, std::string> > > realization::Bmi_Multi_Formulation::module_variable_maps
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().

◆ modules

◆ next_time_step_index

int realization::Bmi_Multi_Formulation::next_time_step_index = 0
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().

◆ OPTIONAL_PARAMETERS

const std::vector< std::string > realization::Bmi_Formulation::OPTIONAL_PARAMETERS
staticprivateinherited
Initial value:
= {
BMI_REALIZATION_CFG_PARAM_OPT__USES_FORCINGS
BMI_REALIZATION_CFG_PARAM_OPT__FORCING_FILE,
BMI_REALIZATION_CFG_PARAM_OPT__VAR_STD_NAMES,
BMI_REALIZATION_CFG_PARAM_OPT__OUT_VARS,
BMI_REALIZATION_CFG_PARAM_OPT__OUT_HEADER_FIELDS,
BMI_REALIZATION_CFG_PARAM_OPT__ALLOW_EXCEED_END,
BMI_REALIZATION_CFG_PARAM_OPT__FIXED_TIME_STEP,
BMI_REALIZATION_CFG_PARAM_OPT__LIB_FILE
}

◆ output

◆ output_header_fields

std::vector<std::string> realization::Bmi_Formulation::output_header_fields
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().

◆ output_precision

int realization::Bmi_Formulation::output_precision
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().

◆ output_text_stream

std::shared_ptr<std::ostringstream> realization::Bmi_Formulation::output_text_stream
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().

◆ output_variable_names

std::vector<std::string> realization::Bmi_Formulation::output_variable_names
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().

◆ primary_module_index

int realization::Bmi_Multi_Formulation::primary_module_index = -1
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().

◆ realized_catchment

std::shared_ptr<HY_Catchment> HY_CatchmentRealization::realized_catchment
protectedinherited

◆ REQUIRED_PARAMETERS

const std::vector< std::string > realization::Bmi_Formulation::REQUIRED_PARAMETERS
staticprivateinherited
Initial value:
= {
BMI_REALIZATION_CFG_PARAM_REQ__INIT_CONFIG,
BMI_REALIZATION_CFG_PARAM_REQ__MAIN_OUT_VAR,
BMI_REALIZATION_CFG_PARAM_REQ__MODEL_TYPE,
}

Referenced by realization::Bmi_Formulation::get_required_parameters().


The documentation for this class was generated from the following files: