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

#include <Bmi_C_Formulation.hpp>

+ Inheritance diagram for realization::Bmi_C_Formulation:
+ Collaboration diagram for realization::Bmi_C_Formulation:

Public Types

typedef long time_step_t
 
using data_type = DataType
 This class provides a generic interface to data services.
 
using selection_type = SelectionType
 

Public Member Functions

 Bmi_C_Formulation (std::string id, std::shared_ptr< data_access::GenericDataProvider > forcing_provider, utils::StreamHandler output_stream)
 
std::string get_formulation_type () const override
 
bool is_bmi_input_variable (const std::string &var_name) const override
 
bool is_bmi_output_variable (const std::string &var_name) const override
 
void create_formulation (boost::property_tree::ptree &config, geojson::PropertyMap *global=nullptr) override
 
void create_formulation (geojson::PropertyMap properties) override
 
boost::span< const std::string > get_available_variable_names () const override
 Get the collection of forcing output property names this instance can provide.
 
std::vector< double > get_output_values_for_timestep (int timestep) override
 Get the output variable values for the given time step, one per output column and positionally aligned with get_output_fields.
 
std::vector< utils::OutputFieldget_output_fields () const override
 Get this formulation's output fields (header name + units) in output order.
 
double get_response (time_step_t t_index, time_step_t t_delta) override
 Get the model response for a time step.
 
void update (time_step_t t_index, time_step_t t_delta) override
 
time_t get_variable_time_begin (const std::string &variable_name)
 Get the inclusive beginning of the period of time over which this instance can provide data for this forcing.
 
long get_data_start_time () const override
 Get the inclusive beginning of the period of time over which this instance can provide data for this forcing.
 
long get_data_stop_time () const override
 Return the last valid time for which data from the requested variable can be requested.
 
long record_duration () const override
 Return the stride in the time dimension.
 
const double get_model_current_time () const override
 Get the current time for the backing BMI model in its native format and units.
 
const double get_model_end_time () const override
 Get the end time for the backing BMI model in its native format and units.
 
const std::vector< std::string > & get_required_parameters () const override
 
const std::string & get_config_mapped_variable_name (const std::string &model_var_name) const override
 When possible, translate a variable name for a BMI model to an internally recognized name.
 
size_t get_ts_index_for_time (const time_t &epoch_time) const override
 Get the index of the forcing time step that contains the given point in time.
 
std::vector< double > get_values (const CatchmentAggrDataSelector &selector, data_access::ReSampleMethod m=SUM) override
 Get the 1D values of a forcing property for an arbitrary time period, converting units if needed.
 
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.
 
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.
 
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.
 
bool is_input_variable_metadata_cached () const
 Test whether set_model_inputs_prior_to_update caches and reuses input variable metadata.
 
bool is_property_sum_over_time_step (const std::string &name) const override
 Get whether a property's per-time-step values are each an aggregate sum over the entire time step.
 
const std::vector< std::string > get_bmi_input_variables () const override
 
const std::vector< std::string > get_bmi_output_variables () const override
 
virtual void check_mass_balance (const int &iteration, const int &total_steps, const std::string &timestamp) const override
 
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_variable_names () const
 Get the names of variables in formulation output.
 
void set_output_precision (int precision)
 Set the precision of output values when converted to text.
 
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
 

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

std::shared_ptr< models::bmi::Bmi_Adapterconstruct_model (const geojson::PropertyMap &properties) override
 Construct model and its shared pointer, potentially supplying input variable values from config.
 
time_t convert_model_time (const double &model_time) const override
 Convert a time value from the model to an epoch time in seconds.
 
template<class T , class O >
get_var_value_as (time_step_t t_index, const std::string &var_name)
 Get a value, converted to specified type, for an output variable at a time step.
 
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.
 
bool is_model_initialized () const override
 Test whether backing model has run BMI Initialize.
 
void get_bmi_output_var_name (const std::string &name, std::string &bmi_var_name) const
 Get correct BMI variable name, which may be the output or something mapped to this output.
 
void determine_model_time_offset ()
 Determine and set the offset time of the model in seconds, compared to forcing data.
 
const bool & get_allow_model_exceed_end_time () const override
 Get whether a model may perform updates beyond its end_time.
 
const std::string & get_bmi_init_config () const
 
std::shared_ptr< models::bmi::Bmi_Adapterget_bmi_model () const
 Get the backing model object implementing the BMI.
 
const time_t & get_bmi_model_start_time_forcing_offset_s () const override
 
void inner_create_formulation (geojson::PropertyMap properties, bool needs_param_validation)
 Universal logic applied when creating a BMI-backed formulation from NGen config.
 
void set_initial_bmi_parameters (geojson::PropertyMap properties)
 Check configuration properties for model_params and attempt to set them in the bmi model.
 
bool is_bmi_model_time_step_fixed () const override
 Test whether backing model has fixed time step size.
 
void set_allow_model_exceed_end_time (bool allow_exceed_end)
 
void set_bmi_init_config (const std::string &init_config)
 
void set_bmi_model (std::shared_ptr< models::bmi::Bmi_Adapter > model)
 Set the backing model object implementing the BMI.
 
void set_bmi_model_start_time_forcing_offset_s (const time_t &offset_s)
 
void set_bmi_model_time_step_fixed (bool is_fix_time_step)
 
virtual void set_model_initialized (bool is_initialized)
 Set whether the backing model object has been initialize using the BMI standard Initialize function.
 
void set_model_inputs_prior_to_update (const double &model_time, time_step_t t_delta)
 Set BMI input variable values for the model appropriately prior to calling its BMIupdate()``.
 
void set_cache_input_var_metadata (bool cache_input_var_metadata)
 Set member variable indicating whether set_model_inputs_prior_to_update should store and reuse 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)
 
boost::span< const std::string > get_output_header_field_names () const
 The configured/derived output header (display) field names, positionally parallel to get_output_variable_names – header i is the output name for variable i.
 
void set_output_variable_names (const std::vector< std::string > &out_var_names)
 Set the names of variables in formulation output.
 
const std::string & get_catchment_id () const override
 
void set_catchment_id (std::string cat_id) override
 
geojson::PropertyMap interpret_parameters (boost::property_tree::ptree &config, geojson::PropertyMap *global=nullptr)
 
void validate_parameters (geojson::PropertyMap options)
 

Protected Attributes

time_step_t last_model_response_delta = 0
 The delta of the last model update execution (typically, this is time step size).
 
time_t last_model_response_start_time = 0
 The epoch time of the model at the beginning of its last update.
 
std::map< std::string, std::shared_ptr< data_access::GenericDataProvider > > input_forcing_providers
 
int next_time_step_index = 0
 Index value (0-based) of the time step that will be processed by the next update of the model.
 
std::shared_ptr< std::ostringstream > output_text_stream
 Object to help with converting numeric output values to text.
 
std::shared_ptr< data_access::GenericDataProviderforcing
 
std::string id
 
polygon_t bounds
 
utils::StreamHandler output
 
std::shared_ptr< HY_Catchmentrealized_catchment
 
unsigned long id_number
 

Private Member Functions

void do_bmi_sets_from_stored_metadata (const time_t &src_data_start, const time_step_t &t_delta)
 Set BMI input variables before `BMI update, using saved metadata rather than re-fetching or re-calculating.
 
void do_bmi_sets_with_full_refetch (const time_t &src_data_start, const time_step_t &t_delta)
 Set BMI input variables before `BMI update, re-fetching and re-calculating required metadata each time.
 
std::shared_ptr< data_access::GenericDataProvider > & get_provider_for_input_var (const std::string &var_name, const std::string &mapped_alias)
 Get the appropriate data provider to set inputs for this BMI variable.
 
void initialize_bmi_input_var_metadata ()
 Initialize the metadata as needed for do_bmi_sets_from_stored_metadata.
 
void perform_set (const time_t &src_data_start, const time_step_t &t_delta, const std::shared_ptr< data_access::GenericDataProvider > &provider, const Bmi_Var_Details *var_details) const
 Do the action of retrieving data and setting values for an input variable ahead of advancing the model.
 

Private Attributes

std::unique_ptr< std::vector< Bmi_Var_Details * > > bmi_input_var_details
 BMI input variables details for this instance, cached to improve compute performance when setting values prior to updates.
 
std::unique_ptr< std::vector< std::shared_ptr< data_access::GenericDataProvider > > > bmi_input_providers
 Vector of data providers for BMI input vars, with the provider at an index corresponding to the var in bmi_input_var_details at the same index.
 
models::bmi::protocols::NgenBmiProtocols bmi_protocols
 
bool allow_model_exceed_end_time = false
 Whether model Update calls are allowed and handled in some way by the backing model for time steps after the model's end_time.
 
std::vector< std::string > available_forcings
 The set of available "forcings" (output variables, plus their mapped aliases) that the model can provide.
 
std::string bmi_init_config
 
std::shared_ptr< models::bmi::Bmi_Adapterbmi_model
 
bool bmi_model_time_step_fixed = true
 Whether backing model has fixed time step size.
 
time_t bmi_model_start_time_forcing_offset_s
 The offset, converted to seconds, from the model's start time to the start time of the initial forcing time step.
 
std::map< std::string, std::string > bmi_var_names_map
 A configured mapping of BMI model variable names to standard names for use inside the framework.
 
bool model_initialized = false
 
std::vector< std::string > OPTIONAL_PARAMETERS
 
std::vector< std::string > REQUIRED_PARAMETERS
 
bool cache_input_variable_metadata = false
 Whether set_model_inputs_prior_to_update should store and reuse metadata.
 
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 std::set< Bmi_Var_Detailsknown_bmi_input_vars
 BMI input variables details for all instances, cached to improve compute performance when setting values prior to updates.
 

Friends

class ::Bmi_Formulation_Test
 
class ::Bmi_C_Formulation_Test
 
class ::Bmi_C_Pet_IT
 

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.

◆ selection_type

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

◆ time_step_t

Constructor & Destructor Documentation

◆ Bmi_C_Formulation()

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

Member Function Documentation

◆ check_mass_balance()

virtual void realization::Bmi_Module_Formulation::check_mass_balance ( const int & iteration,
const int & total_steps,
const std::string & timestamp ) const
inlineoverridevirtualinherited

◆ config_pattern_substitution()

void realization::Catchment_Formulation::config_pattern_substitution ( geojson::PropertyMap & properties,
const std::string & key,
const std::string & pattern,
const std::string & replacement )
staticinherited

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_formulation_from_config(), realization::Formulation_Manager::construct_missing_formulation(), and realization::Bmi_Multi_Formulation::init_nested_module().

◆ construct_model()

std::shared_ptr< Bmi_Adapter > Bmi_C_Formulation::construct_model ( const geojson::PropertyMap & properties)
overrideprotectedvirtual

Construct model and its shared pointer, potentially supplying input variable values from config.

Construct model and its shared pointer.

Construct a model (and a shared pointer to it), checking whether additional input variable values are present in the configuration properties and need to be used during model construction.

Parameters
propertiesConfiguration properties for the formulation, potentially containing values for input variables
Returns
A shared pointer to a newly constructed model adapter object
Parameters
propertiesConfiguration properties for the formulation.
Returns
A shared pointer to a newly constructed model adapter object.

Implements realization::Bmi_Module_Formulation.

References realization::Bmi_Module_Formulation::get_bmi_init_config(), realization::Bmi_Formulation::get_model_type_name(), and realization::Bmi_Module_Formulation::is_bmi_model_time_step_fixed().

◆ convert_model_time()

time_t realization::Bmi_C_Formulation::convert_model_time ( const double & model_time) const
inlineoverrideprotectedvirtual

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.

Parameters
model_time
Returns

Implements realization::Bmi_Formulation.

References models::bmi::Bmi_Adapter::convert_model_time_to_seconds(), and realization::Bmi_Module_Formulation::get_bmi_model().

◆ create_formulation() [1/2]

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

◆ create_formulation() [2/2]

void realization::Bmi_Module_Formulation::create_formulation ( geojson::PropertyMap properties)
overridevirtualinherited

◆ determine_model_time_offset()

void realization::Bmi_Module_Formulation::determine_model_time_offset ( )
protectedinherited

Determine and set the offset time of the model in seconds, compared to forcing data.

BMI models frequently have their model start time be set to 0. As such, to know what the forcing time is compared to the model time, an offset value is needed. This becomes important in situations when the size of the time steps for forcing data versus model execution are not equal. This method will determine and set this value.

References realization::Bmi_Formulation::convert_model_time(), realization::Catchment_Formulation::forcing, realization::Bmi_Module_Formulation::get_bmi_model(), and realization::Bmi_Module_Formulation::set_bmi_model_start_time_forcing_offset_s().

Referenced by realization::Bmi_Module_Formulation::inner_create_formulation().

◆ do_bmi_sets_from_stored_metadata()

void realization::Bmi_Module_Formulation::do_bmi_sets_from_stored_metadata ( const time_t & src_data_start,
const time_step_t & t_delta )
privateinherited

Set BMI input variables before `BMI update, using saved metadata rather than re-fetching or re-calculating.

This is one of two available execution paths used by set_model_inputs_prior_to_update for the bulk of its behavior. Certain metadata details about a BMI input variable must be available in order for the framework to execute a set_value call: e.g., the data provider that is the correct source of input values, the analogous C++ type, the number of items, etc. In this execution option, that data is obtained once and stored for subsequent reuse, optimizing compute at each time step a bit at the expense of memory.

References to objects containing these details are stored within the bmi_input_var_details vector, populated on the first call to this function. These are actually pointers to objects contained within the known_bmi_input_vars static member variable.

An important consideration is that this function is not strictly safe relying only on guarantees provided by BMI. Nothing within the BMI spec guarantees that, for example, a variable will not change the number of items it contains. It is therefore possible, in general, for stored data to become stale for a properly implemented BMI module. In practice, however, any selected module's implementation details and behavior will be known by the user, so users can elect to only use this execution path for set_model_inputs_prior_to_update when the BMI module itself guarantees such data cannot become stale.

Parameters
src_data_startThe start time (in seconds) to use when retrieving data from the appropriate provider to use for setting the model's variables.
t_deltaThe size of the time step over which the formulation is going to update the model, which might be different than the model's internal time step.

References realization::Bmi_Module_Formulation::bmi_input_providers, realization::Bmi_Module_Formulation::bmi_input_var_details, realization::Bmi_Module_Formulation::initialize_bmi_input_var_metadata(), and realization::Bmi_Module_Formulation::perform_set().

Referenced by realization::Bmi_Module_Formulation::set_model_inputs_prior_to_update().

◆ do_bmi_sets_with_full_refetch()

void realization::Bmi_Module_Formulation::do_bmi_sets_with_full_refetch ( const time_t & src_data_start,
const time_step_t & t_delta )
privateinherited

Set BMI input variables before `BMI update, re-fetching and re-calculating required metadata each time.

This is one of two available execution paths used by set_model_inputs_prior_to_update for the bulk of its behavior. Certain metadata details about a BMI input variable must be available in order for the framework to execute a set_value call: e.g., the data provider that is the correct source of input values, the analogous C++ type, the number of items, etc. In this execution option, that data is freshly obtained

  • either recalculated, redetermined, or refetched from the BMI module itself - on every call to this method. This results in less efficient compute but also reduced memory usage.

An important consideration is that this function provides an execution option that is strictly safe relying only on guarantees provided by BMI. Nothing within the BMI spec guarantees that, for example, a variable will not change the number of items it contains. If a configured module does (or may) change input variable metadata, or if it is possible for a module to change the set of input variables, then this execution path for set_model_inputs_prior_to_update should be selected.

BMI module. In practice, however, any selected module's implementation details and behavior will be known by the user, so users can elect to only use this execution path for set_model_inputs_prior_to_update when the BMI module itself guarantees such data cannot become stale. better memory and safe for no guarantees

Parameters
src_data_startThe start time (in seconds) to use when retrieving data from the appropriate provider to use for setting the model's variables.
t_deltaThe size of the time step over which the formulation is going to update the model, which might be different than the model's internal time step.

References realization::Bmi_Module_Formulation::get_bmi_model(), realization::Bmi_Module_Formulation::get_config_mapped_variable_name(), realization::Bmi_Module_Formulation::get_provider_for_input_var(), bmi::Bmi::GetVarItemsize(), and realization::Bmi_Module_Formulation::perform_set().

Referenced by realization::Bmi_Module_Formulation::set_model_inputs_prior_to_update().

◆ 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 ( )
inherited

Release resources of the given forcing provider.

References realization::Catchment_Formulation::forcing.

◆ get_allow_model_exceed_end_time()

const bool & realization::Bmi_Module_Formulation::get_allow_model_exceed_end_time ( ) const
overrideprotectedvirtualinherited

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 realization::Bmi_Module_Formulation::allow_model_exceed_end_time.

Referenced by realization::Bmi_Module_Formulation::update().

◆ get_available_variable_names()

boost::span< const std::string > realization::Bmi_Module_Formulation::get_available_variable_names ( ) const
overridevirtualinherited

Get the collection of forcing output property names this instance can provide.

This is part of the ForcingProvider interface. This interface must be implemented for items of this type to be usable as "forcing" providers for situations when some other object needs to receive as an input (i.e., one of its forcings) a data property output from this object.

For this type, this is the collection of BMI output variables, plus any aliases included in the formulation config's output variable mapping.

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

Implements data_access::DataProvider< DataType, SelectionType >.

References realization::Bmi_Module_Formulation::available_forcings.

Referenced by realization::Bmi_Module_Formulation::get_value(), and realization::Bmi_Module_Formulation::get_values().

◆ get_bmi_init_config()

const std::string & realization::Bmi_Module_Formulation::get_bmi_init_config ( ) const
protectedinherited

◆ get_bmi_input_variables()

const std::vector< std::string > realization::Bmi_Module_Formulation::get_bmi_input_variables ( ) const
overridevirtualinherited

◆ get_bmi_main_output_var()

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

◆ get_bmi_model()

std::shared_ptr< models::bmi::Bmi_Adapter > realization::Bmi_Module_Formulation::get_bmi_model ( ) const
protectedinherited

Get the backing model object implementing the BMI.

Returns
Shared pointer to the backing model object that implements the BMI.

References realization::Bmi_Module_Formulation::bmi_model.

Referenced by convert_model_time(), realization::Bmi_Cpp_Formulation::convert_model_time(), realization::Bmi_Module_Formulation::determine_model_time_offset(), realization::Bmi_Module_Formulation::do_bmi_sets_with_full_refetch(), realization::Bmi_Module_Formulation::get_bmi_input_variables(), realization::Bmi_Module_Formulation::get_bmi_output_var_name(), realization::Bmi_Module_Formulation::get_bmi_output_variables(), realization::Bmi_Module_Formulation::get_data_start_time(), realization::Bmi_Module_Formulation::get_model_current_time(), realization::Bmi_Module_Formulation::get_model_end_time(), realization::Bmi_Module_Formulation::get_output_fields(), realization::Bmi_Module_Formulation::get_value(), realization::Bmi_Module_Formulation::get_values(), get_var_value_as(), realization::Bmi_Cpp_Formulation::get_var_value_as(), get_var_value_as_double(), realization::Bmi_Cpp_Formulation::get_var_value_as_double(), realization::Bmi_Module_Formulation::initialize_bmi_input_var_metadata(), realization::Bmi_Module_Formulation::inner_create_formulation(), is_bmi_input_variable(), realization::Bmi_Cpp_Formulation::is_bmi_input_variable(), is_bmi_output_variable(), realization::Bmi_Cpp_Formulation::is_bmi_output_variable(), is_model_initialized(), realization::Bmi_Cpp_Formulation::is_model_initialized(), realization::Bmi_Module_Formulation::perform_set(), realization::Bmi_Module_Formulation::set_initial_bmi_parameters(), and realization::Bmi_Module_Formulation::update().

◆ get_bmi_model_start_time_forcing_offset_s()

const time_t & realization::Bmi_Module_Formulation::get_bmi_model_start_time_forcing_offset_s ( ) const
overrideprotectedvirtualinherited

◆ get_bmi_output_var_name()

void realization::Bmi_Module_Formulation::get_bmi_output_var_name ( const std::string & name,
std::string & bmi_var_name ) const
protectedinherited

Get correct BMI variable name, which may be the output or something mapped to this output.

Parameters
name
bmi_var_name

References realization::Bmi_Module_Formulation::bmi_var_names_map, realization::Bmi_Module_Formulation::get_bmi_model(), and bmi::Bmi::GetOutputVarNames().

Referenced by realization::Bmi_Module_Formulation::get_value(), and realization::Bmi_Module_Formulation::get_values().

◆ get_bmi_output_variables()

const std::vector< std::string > realization::Bmi_Module_Formulation::get_bmi_output_variables ( ) const
overridevirtualinherited

◆ get_catchment_id()

◆ get_config_mapped_variable_name()

const std::string & realization::Bmi_Module_Formulation::get_config_mapped_variable_name ( const std::string & model_var_name) const
overridevirtualinherited

When possible, translate a variable name for a BMI model to an internally recognized name.

Translate some BMI variable name to something recognized in some internal context for use within NGen. Do this according to the map of variable names supplied in the external formulation config. If no mapping for the given variable name was configured, return the variable name itself.

For example, perhaps a BMI model has the input variable "RAIN_RATE." Configuring this variable name to map to "precip_rate" will allow the formulation to understand that this particular forcing field should be used to set the model's "RAIN_RATE" variable.

Parameters
model_var_nameThe BMI variable name to translate so its purpose is recognized internally.
Returns
Either the internal equivalent variable name, or the provided name if there is not a mapping entry.

Implements realization::Bmi_Formulation.

References realization::Bmi_Module_Formulation::bmi_var_names_map.

Referenced by realization::Bmi_Module_Formulation::do_bmi_sets_with_full_refetch(), and realization::Bmi_Module_Formulation::initialize_bmi_input_var_metadata().

◆ get_data_start_time()

long realization::Bmi_Module_Formulation::get_data_start_time ( ) const
overridevirtualinherited

Get the inclusive beginning of the period of time over which this instance can provide data for this forcing.

This is part of the DataProvider interface. This interface must be implemented for items of this type to be usable as "forcing" providers for situations when some other object needs to receive as an input (i.e., one of its forcings) a data property output from this object.

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

Implements data_access::DataProvider< DataType, SelectionType >.

References realization::Bmi_Module_Formulation::get_bmi_model(), and bmi::Bmi::GetStartTime().

◆ get_data_stop_time()

long realization::Bmi_Module_Formulation::get_data_stop_time ( ) const
overridevirtualinherited

Return the last valid time for which data from the requested variable can be requested.

Implements data_access::DataProvider< DataType, SelectionType >.

◆ get_formulation_type()

std::string Bmi_C_Formulation::get_formulation_type ( ) const
overridevirtual

◆ get_id()

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

◆ get_model_current_time()

const double realization::Bmi_Module_Formulation::get_model_current_time ( ) const
overridevirtualinherited

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

Returns
The current time for the backing BMI model in its native format and units.

Implements realization::Bmi_Formulation.

References realization::Bmi_Module_Formulation::get_bmi_model(), and bmi::Bmi::GetCurrentTime().

◆ get_model_end_time()

const double realization::Bmi_Module_Formulation::get_model_end_time ( ) const
overridevirtualinherited

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

Returns
The end time for the backing BMI model in its native format and units.

Implements realization::Bmi_Formulation.

References realization::Bmi_Module_Formulation::get_bmi_model(), and bmi::Bmi::GetEndTime().

◆ get_model_type_name()

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

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

Returns
The name of the backing model object's type.

References realization::Bmi_Formulation::model_type_name.

Referenced by construct_model(), realization::Bmi_Cpp_Formulation::construct_model(), get_var_value_as_double(), and realization::Bmi_Cpp_Formulation::get_var_value_as_double().

◆ get_output_fields()

std::vector< utils::OutputField > realization::Bmi_Module_Formulation::get_output_fields ( ) const
inlineoverridevirtualinherited

Get this formulation's output fields (header name + units) in output order.

Units come straight from the backing BMI model (GetVarUnits) per output variable; std::nullopt when the model reports none (GetVarUnits fails / BMI_FAILURE) rather than failing the run.

Implements realization::Catchment_Formulation.

References realization::Bmi_Module_Formulation::get_bmi_model(), realization::Bmi_Formulation::get_output_header_field_names(), realization::Bmi_Formulation::get_output_variable_names(), and bmi::Bmi::GetVarUnits().

◆ get_output_header_field_names()

boost::span< const std::string > realization::Bmi_Formulation::get_output_header_field_names ( ) const
inlineprotectedinherited

The configured/derived output header (display) field names, positionally parallel to get_output_variable_names – header i is the output name for variable i.

A concrete subclass uses these as each column's output_name when building get_output_fields.

References realization::Bmi_Formulation::output_header_fields.

Referenced by realization::Bmi_Module_Formulation::get_output_fields(), and realization::Bmi_Multi_Formulation::get_output_fields().

◆ get_output_precision()

int realization::Bmi_Formulation::get_output_precision ( )
inlineprotectedinherited

◆ get_output_values_for_timestep()

std::vector< double > realization::Bmi_Module_Formulation::get_output_values_for_timestep ( int timestep)
overridevirtualinherited

Get the output variable values for the given time step, one per output column and positionally aligned with get_output_fields.

The values are the model's calculated outputs for the time step; the time step index itself is not included.

Only the last processed time step is accessible, because formulations do not save results from previous time steps; there is thus no valid time step before at least one call to update has been made. Throws std::invalid_argument if timestep is not the current (last processed) time step.

Parameters
timestepThe time step for which data is desired.
Returns
The output values for the given time step, one per output column.

Implements realization::Catchment_Formulation.

References realization::Catchment_Formulation::get_catchment_id(), realization::Bmi_Formulation::get_output_variable_names(), realization::Bmi_Module_Formulation::get_value(), realization::Bmi_Module_Formulation::next_time_step_index, and logging::warning().

◆ get_output_variable_names()

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

◆ get_provider_for_input_var()

std::shared_ptr< data_access::GenericDataProvider > & realization::Bmi_Module_Formulation::get_provider_for_input_var ( const std::string & var_name,
const std::string & mapped_alias )
privateinherited

Get the appropriate data provider to set inputs for this BMI variable.

Get the appropriate data provider for setting values for this BMI variable from input_forcing_providers.

Parameters
var_nameThe BMI variable name as retrievable directly via BMI.
mapped_aliasThe framework's internal mapped alias for this variable.
Returns
The appropriate data provider

References realization::Catchment_Formulation::forcing, and realization::Bmi_Module_Formulation::input_forcing_providers.

Referenced by realization::Bmi_Module_Formulation::do_bmi_sets_with_full_refetch(), and realization::Bmi_Module_Formulation::initialize_bmi_input_var_metadata().

◆ get_required_parameters()

const std::vector< std::string > & realization::Bmi_Module_Formulation::get_required_parameters ( ) const
overridevirtualinherited

◆ get_response()

double realization::Bmi_Module_Formulation::get_response ( time_step_t t_index,
time_step_t t_delta )
overridevirtualinherited

Get the model response for a time step.

Get the model response for the provided time step, executing the backing model formulation one or more times as needed.

Function assumes the backing model has been fully initialized an that any additional input values have been applied.

The function throws an error if the index of a previously processed time step is supplied, except if it is the last processed time step. In that case, the appropriate value is returned as described below, but without executing any model update.

Assuming updating to the implied time is valid for the model, the function executes one or more model updates to process future time steps for the necessary indexes. Multiple time steps updates occur when the given future time step index is not the next time step index to be processed. Regardless, all processed time steps have the size supplied in t_delta.

However, it is possible to provide t_index and t_delta values that would result in the aggregate updates taking the model's time beyond its end_time value. In such cases, if the formulation config indicates this model is not allow to exceed its set end_time, the function does not update the model and throws an error.

The function will return the value of the primary output variable (see get_bmi_main_output_var()) for the given time step after the model has been updated to that point. The type returned will always be a double, with other numeric types being cast if necessary.

The BMI spec requires for variable values to be passed to/from models via as arrays. This function essentially treats the variable array reference as if it were just a raw pointer and returns the 0-th array value.

Parameters
t_indexThe index of the time step for which to run model calculations.
d_delta_sThe duration, in seconds, of the time step for which to run model calculations.
Returns
The total discharge of the model for the given time step.

Implements realization::Catchment_Formulation.

References realization::Bmi_Formulation::get_bmi_main_output_var(), realization::Catchment_Formulation::get_catchment_id(), realization::Bmi_Module_Formulation::get_value(), UnitsHelper::unit_conversion_exception::provider_model_name, UnitsHelper::unit_conversion_exception::provider_var_name, UnitsHelper::record_unit_conversion_fault(), UnitsHelper::unit_conversion_exception::unconverted_values, realization::Bmi_Module_Formulation::update(), and logging::warning().

◆ get_ts_index_for_time()

size_t realization::Bmi_Module_Formulation::get_ts_index_for_time ( const time_t & epoch_time) const
overridevirtualinherited

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

◆ get_value() [2/2]

double realization::Bmi_Module_Formulation::get_value ( const CatchmentAggrDataSelector & selector,
data_access::ReSampleMethod m )
overrideinherited

Get the value of a forcing property for an arbitrary time period, converting units if needed.

This is part of the ForcingProvider interface. This interface must be implemented for items of this type to be usable as "forcing" providers for situations when some other object needs to receive as an input (i.e., one of its forcings) a data property output from this object.

An std::out_of_range exception should be thrown if the data for the time period is not available.

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.
See also
ForcingProvider::get_value

References realization::Bmi_Module_Formulation::get_available_variable_names(), realization::Bmi_Module_Formulation::get_bmi_model(), realization::Bmi_Module_Formulation::get_bmi_output_var_name(), UnitsHelper::get_converted_value(), realization::Formulation::get_formulation_type(), models::bmi::Bmi_Adapter::get_model_name(), CatchmentAggrDataSelector::get_output_units(), realization::Bmi_Module_Formulation::get_var_value_as_double(), CatchmentAggrDataSelector::get_variable_name(), bmi::Bmi::GetVarUnits(), UnitsHelper::unit_conversion_exception::provider_model_name, and UnitsHelper::unit_conversion_exception::provider_var_name.

Referenced by realization::Bmi_Module_Formulation::get_output_values_for_timestep(), and realization::Bmi_Module_Formulation::get_response().

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

◆ get_values() [2/2]

std::vector< double > realization::Bmi_Module_Formulation::get_values ( const CatchmentAggrDataSelector & selector,
data_access::ReSampleMethod m = SUM )
overrideinherited

Get the 1D values of a forcing property for an arbitrary time period, converting units if needed.

Parameters
output_nameThe name of the forcing property of interest.
init_timeThe epoch time (in seconds) of the start of the time period.
duration_sThe length of the time period, in seconds.
output_unitsThe expected units of the desired output value.
Returns
std::vector<double> The 1D 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.
std::runtime_erroroutput_name is not one of the available outputs of this provider instance.

References UnitsHelper::convert_values(), realization::Bmi_Module_Formulation::get_available_variable_names(), realization::Bmi_Module_Formulation::get_bmi_model(), realization::Bmi_Module_Formulation::get_bmi_output_var_name(), realization::Formulation::get_formulation_type(), models::bmi::Bmi_Adapter::get_model_name(), CatchmentAggrDataSelector::get_output_units(), CatchmentAggrDataSelector::get_variable_name(), models::bmi::GetValue(), bmi::Bmi::GetVarUnits(), UnitsHelper::unit_conversion_exception::provider_model_name, UnitsHelper::unit_conversion_exception::provider_var_name, and UnitsHelper::unit_conversion_exception::unconverted_values.

◆ get_var_value_as()

template<class T , class O >
T realization::Bmi_C_Formulation::get_var_value_as ( time_step_t t_index,
const std::string & var_name )
inlineprotected

Get a value, converted to specified type, for an output variable at a time step.

Function gets the value for a provided output variable at a provided time step index, and returns the value converted to some particular type specified by the template param.

The function makes several assumptions:

1. `t_index` is a time step that has already been processed for the model
2. `var_name` is in the set of valid output variable names for the model
3. it is possible to either implicitly or explicitly convert (i.e., cast) the output value to the
   template parameter type (or it is already of that type)
4. conversions do not lead to invalid (e.g., runtime errors) or unexpected (e.g., loss of precision)
   behavior

It falls to users (functions) of this function to ensure these assumptions hold before invoking.

Template Parameters
TThe type that should be returned, and to which the BMI variable value should be cast.
Parameters
t_indexThe index of some already-processed time step for which a variable value is being requested
var_nameThe name of the variable for which a value is being requested
Returns

References realization::Bmi_Module_Formulation::get_bmi_model(), and models::bmi::GetValue().

◆ get_var_value_as_double()

double Bmi_C_Formulation::get_var_value_as_double ( const int & index,
const std::string & var_name )
overrideprotectedvirtual

Get value for some BMI model variable at a specific index.

Function gets the value for a provided variable, returned from the backing model as an array, and returns the specific value at the desired index cast as a double type.

The function makes several assumptions:

1. `index` is within array bounds
2. `var_name` is in the set of valid variable names for the model
3. the type for output variable allows the value to be cast to a `double` appropriately

It falls to user (functions) of this function to ensure these assumptions hold before invoking.

Parameters
index
var_name
Returns

Implements realization::Bmi_Module_Formulation.

References realization::Bmi_Module_Formulation::get_bmi_model(), and realization::Bmi_Formulation::get_model_type_name().

◆ get_variable_time_begin()

time_t realization::Bmi_Module_Formulation::get_variable_time_begin ( const std::string & variable_name)
inherited

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.

◆ initialize_bmi_input_var_metadata()

◆ inner_create_formulation()

void realization::Bmi_Module_Formulation::inner_create_formulation ( geojson::PropertyMap properties,
bool needs_param_validation )
protectedinherited

Universal logic applied when creating a BMI-backed formulation from NGen config.

This performs all the necessary steps to initialize this formulation from provided configuration properties. It is written in such a way that it can be used in appropriately crafted nested calls from both public create_formulation implementations, thus allowing the primary formulation initialization logic to be centralized and not duplicated.

Parameters
properties
needs_param_validation

References realization::Bmi_Module_Formulation::available_forcings, realization::Bmi_Module_Formulation::bmi_protocols, realization::Bmi_Module_Formulation::bmi_var_names_map, realization::Bmi_Module_Formulation::construct_model(), realization::Bmi_Module_Formulation::determine_model_time_offset(), realization::Bmi_Module_Formulation::get_bmi_model(), realization::Bmi_Formulation::get_output_variable_names(), models::bmi::Bmi_Adapter::is_model_initialized(), realization::Bmi_Module_Formulation::model_initialized, realization::Bmi_Module_Formulation::set_allow_model_exceed_end_time(), realization::Bmi_Module_Formulation::set_bmi_init_config(), realization::Bmi_Formulation::set_bmi_main_output_var(), realization::Bmi_Module_Formulation::set_bmi_model(), realization::Bmi_Module_Formulation::set_bmi_model_time_step_fixed(), realization::Bmi_Module_Formulation::set_cache_input_var_metadata(), realization::Bmi_Module_Formulation::set_initial_bmi_parameters(), realization::Bmi_Formulation::set_model_type_name(), realization::Bmi_Formulation::set_output_header_fields(), realization::Bmi_Formulation::set_output_precision(), realization::Bmi_Formulation::set_output_variable_names(), and realization::Formulation::validate_parameters().

Referenced by realization::Bmi_Module_Formulation::create_formulation(), and realization::Bmi_Module_Formulation::create_formulation().

◆ interpret_parameters()

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

◆ is_bmi_input_variable()

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

◆ is_bmi_model_time_step_fixed()

bool realization::Bmi_Module_Formulation::is_bmi_model_time_step_fixed ( ) const
overrideprotectedvirtualinherited

Test whether backing model has fixed time step size.

Returns
Whether backing model has fixed time step size.

Implements realization::Bmi_Formulation.

References realization::Bmi_Module_Formulation::bmi_model_time_step_fixed.

Referenced by construct_model(), and realization::Bmi_Cpp_Formulation::construct_model().

◆ is_bmi_output_variable()

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

◆ is_input_variable_metadata_cached()

bool realization::Bmi_Module_Formulation::is_input_variable_metadata_cached ( ) const
inherited

Test whether set_model_inputs_prior_to_update caches and reuses input variable metadata.

See cache_input_variable_metadata and set_cache_input_var_metadata for details.

Returns
Whether input variable metadata is cached and reused across time steps, rather than re-fetched.

References realization::Bmi_Module_Formulation::cache_input_variable_metadata.

◆ is_model_initialized()

bool Bmi_C_Formulation::is_model_initialized ( ) const
overrideprotectedvirtual

Test whether backing model has run BMI Initialize.

Test whether the backing model object has been initialize using the BMI standard Initialize function.

This overrides the super class implementation and checks the model directly. As such, the associated setter does not serve any purpose.

Returns
Whether backing model object has been initialize using the BMI standard Initialize function.

Implements realization::Bmi_Formulation.

References realization::Bmi_Module_Formulation::get_bmi_model().

◆ is_property_sum_over_time_step()

bool realization::Bmi_Module_Formulation::is_property_sum_over_time_step ( const std::string & name) const
overridevirtualinherited

Get whether a property's per-time-step values are each an aggregate sum over the entire time step.

This is part of the ForcingProvider interface. This interface must be implemented for items of this type to be usable as "forcing" providers for situations when some other object needs to receive as an input (i.e., one of its forcings) a data property output from this object.

Certain properties, like rain fall, are aggregated sums over an entire time step. Others, such as pressure, are not such sums and instead something else like an instantaneous reading or an average value.

It may be the case that forcing data is needed for some discretization different than the forcing time step. This aspect must be known in such cases to perform the appropriate value interpolation.

For instances of this type, all output forcings fall under this category.

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

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

◆ perform_set()

void realization::Bmi_Module_Formulation::perform_set ( const time_t & src_data_start,
const time_step_t & t_delta,
const std::shared_ptr< data_access::GenericDataProvider > & provider,
const Bmi_Var_Details * var_details ) const
privateinherited

Do the action of retrieving data and setting values for an input variable ahead of advancing the model.

Parameters
src_data_startThe start time (in seconds) to use when retrieving data from the appropriate provider to use for setting the model's variables.
t_deltaThe size of the time step over which the formulation is going to update the model, which might be different than the model's internal time step.
providerThe data provider from which to source the data to use to set the variable.
var_detailsVariable details struct containing the remainder of information required (e.g., var name).

References realization::Bmi_Module_Formulation::get_bmi_model(), realization::Catchment_Formulation::get_catchment_id(), realization::Bmi_Var_Details::get_cpp_type(), realization::Bmi_Var_Details::get_mapped_alias(), models::bmi::Bmi_Adapter::get_model_name(), realization::Bmi_Var_Details::get_name(), realization::Bmi_Var_Details::get_num_items(), realization::Bmi_Var_Details::get_units(), realization::get_value_as_type(), realization::get_values_as_type(), UnitsHelper::unit_conversion_exception::provider_model_name, UnitsHelper::unit_conversion_exception::provider_var_name, UnitsHelper::record_unit_conversion_fault(), bmi::Bmi::SetValue(), UnitsHelper::unit_conversion_exception::unconverted_values, and logging::warning().

Referenced by realization::Bmi_Module_Formulation::do_bmi_sets_from_stored_metadata(), and realization::Bmi_Module_Formulation::do_bmi_sets_with_full_refetch().

◆ record_duration()

long realization::Bmi_Module_Formulation::record_duration ( ) const
overridevirtualinherited

Return the stride in the time dimension.

Implements data_access::DataProvider< DataType, SelectionType >.

◆ set_allow_model_exceed_end_time()

void realization::Bmi_Module_Formulation::set_allow_model_exceed_end_time ( bool allow_exceed_end)
protectedinherited

◆ set_bmi_init_config()

void realization::Bmi_Module_Formulation::set_bmi_init_config ( const std::string & init_config)
protectedinherited

◆ set_bmi_main_output_var()

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

◆ set_bmi_model()

void realization::Bmi_Module_Formulation::set_bmi_model ( std::shared_ptr< models::bmi::Bmi_Adapter > model)
protectedinherited

Set the backing model object implementing the BMI.

Parameters
modelShared pointer to the BMI model.

References realization::Bmi_Module_Formulation::bmi_model.

Referenced by realization::Bmi_Module_Formulation::inner_create_formulation().

◆ set_bmi_model_start_time_forcing_offset_s()

void realization::Bmi_Module_Formulation::set_bmi_model_start_time_forcing_offset_s ( const time_t & offset_s)
protectedinherited

◆ set_bmi_model_time_step_fixed()

void realization::Bmi_Module_Formulation::set_bmi_model_time_step_fixed ( bool is_fix_time_step)
protectedinherited

◆ set_cache_input_var_metadata()

void realization::Bmi_Module_Formulation::set_cache_input_var_metadata ( bool cache_input_var_metadata)
protectedinherited

Set member variable indicating whether set_model_inputs_prior_to_update should store and reuse metadata.

Set the cache_input_variable_metadata member variable, which indicates whether set_model_inputs_prior_to_update should store and reuse metadata, as opposed to refreshing such data each time set_model_inputs_prior_to_update is called.

Parameters
cache_input_var_metadataWhether set_model_inputs_prior_to_update should store and reuse metadata

References realization::Bmi_Module_Formulation::cache_input_variable_metadata.

Referenced by realization::Bmi_Module_Formulation::inner_create_formulation().

◆ set_catchment_id()

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

◆ set_initial_bmi_parameters()

void realization::Bmi_Module_Formulation::set_initial_bmi_parameters ( geojson::PropertyMap properties)
protectedinherited

Check configuration properties for model_params and attempt to set them in the bmi model.

This checks for a key named model_params in the parsed properties, and for each property it will attempt to call SetValue using the property's key as the BMI variable and the property's value as the value to set.

This function should only be called once bmi_model is properly constructed. If bmi_model is a nullptr, this function becomes a no-op.

References models::bmi::Bmi_Adapter::get_analogous_cxx_type(), realization::Bmi_Module_Formulation::get_bmi_model(), geojson::get_propertytype_name(), realization::get_values_as_type(), bmi::Bmi::GetVarItemsize(), bmi::Bmi::GetVarNbytes(), geojson::List, geojson::Natural, geojson::Real, bmi::Bmi::SetValue(), and logging::warning().

Referenced by realization::Bmi_Module_Formulation::inner_create_formulation().

◆ set_model_initialized()

void realization::Bmi_Module_Formulation::set_model_initialized ( bool is_initialized)
protectedvirtualinherited

Set whether the backing model object has been initialize using the BMI standard Initialize function.

Parameters
is_initializedWhether model object has been initialize using the BMI standard Initialize.

References realization::Bmi_Module_Formulation::model_initialized.

◆ set_model_inputs_prior_to_update()

void realization::Bmi_Module_Formulation::set_model_inputs_prior_to_update ( const double & model_time,
time_step_t t_delta )
protectedinherited

Set BMI input variable values for the model appropriately prior to calling its BMIupdate()``.

Depending on the value of cache_input_variable_metadata (false by default, but which can be controlled using set_cache_input_var_metadata), this will defer most of its execution to a call either to do_bmi_sets_from_stored_metadata or do_bmi_sets_with_full_refetch.

Parameters
model_timeThe model's time prior to the update, in its internal units and representation.
t_deltaThe size of the time step over which the formulation is going to update the model, which might be different than the model's internal time step.

References realization::Bmi_Module_Formulation::cache_input_variable_metadata, realization::Bmi_Formulation::convert_model_time(), realization::Bmi_Module_Formulation::do_bmi_sets_from_stored_metadata(), realization::Bmi_Module_Formulation::do_bmi_sets_with_full_refetch(), and realization::Bmi_Module_Formulation::get_bmi_model_start_time_forcing_offset_s().

Referenced by realization::Bmi_Module_Formulation::update().

◆ 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 realization::Bmi_Multi_Formulation::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_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 realization::Bmi_Multi_Formulation::create_multi_formulation(), and realization::Bmi_Module_Formulation::inner_create_formulation().

◆ update()

◆ validate_parameters()

Friends And Related Symbol Documentation

◆ ::Bmi_C_Formulation_Test

friend class ::Bmi_C_Formulation_Test
friend

◆ ::Bmi_C_Pet_IT

friend class ::Bmi_C_Pet_IT
friend

◆ ::Bmi_Formulation_Test

friend class ::Bmi_Formulation_Test
friend

Member Data Documentation

◆ allow_model_exceed_end_time

bool realization::Bmi_Module_Formulation::allow_model_exceed_end_time = false
privateinherited

Whether model Update calls are allowed and handled in some way by the backing model for time steps after the model's end_time.

Referenced by realization::Bmi_Module_Formulation::get_allow_model_exceed_end_time(), and realization::Bmi_Module_Formulation::set_allow_model_exceed_end_time().

◆ available_forcings

std::vector<std::string> realization::Bmi_Module_Formulation::available_forcings
privateinherited

The set of available "forcings" (output variables, plus their mapped aliases) that the model can provide.

Referenced by realization::Bmi_Module_Formulation::get_available_variable_names(), and realization::Bmi_Module_Formulation::inner_create_formulation().

◆ bmi_init_config

std::string realization::Bmi_Module_Formulation::bmi_init_config
privateinherited

◆ bmi_input_providers

std::unique_ptr<std::vector<std::shared_ptr<data_access::GenericDataProvider> > > realization::Bmi_Module_Formulation::bmi_input_providers
privateinherited

Vector of data providers for BMI input vars, with the provider at an index corresponding to the var in bmi_input_var_details at the same index.

As with bmi_input_var_details, these should be populated during the first call to do_bmi_sets_from_stored_metadata via a nested call to initialize_bmi_input_var_metadata.

Referenced by realization::Bmi_Module_Formulation::do_bmi_sets_from_stored_metadata(), and realization::Bmi_Module_Formulation::initialize_bmi_input_var_metadata().

◆ bmi_input_var_details

std::unique_ptr<std::vector<Bmi_Var_Details*> > realization::Bmi_Module_Formulation::bmi_input_var_details
privateinherited

BMI input variables details for this instance, cached to improve compute performance when setting values prior to updates.

This will hold cached details on input variables needed by this instance during do_bmi_sets_from_stored_metadata at each time step. It will be populated lazily on the first time step, via a nested call to initialize_bmi_input_var_metadata.

These should be pointers to Bmi_Var_Details instances in known_bmi_input_vars.

Referenced by realization::Bmi_Module_Formulation::do_bmi_sets_from_stored_metadata(), and realization::Bmi_Module_Formulation::initialize_bmi_input_var_metadata().

◆ bmi_main_output_var

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

◆ bmi_model

std::shared_ptr<models::bmi::Bmi_Adapter> realization::Bmi_Module_Formulation::bmi_model
privateinherited

◆ bmi_model_start_time_forcing_offset_s

time_t realization::Bmi_Module_Formulation::bmi_model_start_time_forcing_offset_s
privateinherited

The offset, converted to seconds, from the model's start time to the start time of the initial forcing time step.

Referenced by realization::Bmi_Module_Formulation::get_bmi_model_start_time_forcing_offset_s(), and realization::Bmi_Module_Formulation::set_bmi_model_start_time_forcing_offset_s().

◆ bmi_model_time_step_fixed

bool realization::Bmi_Module_Formulation::bmi_model_time_step_fixed = true
privateinherited

◆ bmi_protocols

◆ bmi_var_names_map

std::map<std::string, std::string> realization::Bmi_Module_Formulation::bmi_var_names_map
privateinherited

◆ bounds

polygon_t HY_CatchmentArea::bounds
protectedinherited

◆ cache_input_variable_metadata

bool realization::Bmi_Module_Formulation::cache_input_variable_metadata = false
privateinherited

◆ cat_id

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

◆ forcing

◆ id

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

◆ id_number

unsigned long HY_CatchmentRealization::id_number
protectedinherited

◆ input_forcing_providers

std::map<std::string, std::shared_ptr<data_access::GenericDataProvider> > realization::Bmi_Module_Formulation::input_forcing_providers
protectedinherited

◆ known_bmi_input_vars

std::set< Bmi_Var_Details > realization::Bmi_Module_Formulation::known_bmi_input_vars
staticprivateinherited

BMI input variables details for all instances, cached to improve compute performance when setting values prior to updates.

Referenced by realization::Bmi_Module_Formulation::initialize_bmi_input_var_metadata().

◆ last_model_response_delta

time_step_t realization::Bmi_Module_Formulation::last_model_response_delta = 0
protectedinherited

The delta of the last model update execution (typically, this is time step size).

◆ last_model_response_start_time

time_t realization::Bmi_Module_Formulation::last_model_response_start_time = 0
protectedinherited

The epoch time of the model at the beginning of its last update.

◆ model_initialized

◆ model_type_name

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

◆ next_time_step_index

int realization::Bmi_Module_Formulation::next_time_step_index = 0
protectedinherited

Index value (0-based) of the time step that will be processed by the next update of the model.

A formulation time step for BMI types can be thought of as the execution of a call to any of the functions of the underlying BMI model that advance the model (either update or update_until). This member stores the ordinal index of the next time step to be executed. Except in the initial formulation state, this will be one greater than the index of the last executed time step.

E.g., on initialization, before any calls to get_response, this value will be 0. After a call to get_response (assuming 0 as the passed t_index argument), time step 0 will be processed, and this member would be incremented by 1, thus making it 1.

The member serves as an implicit marker of how many time steps have been processed so far. Knowing this is required to maintain valid behavior in certain things, such as get_response (we may want to process multiple time steps forward to a particular index other than the next, but it would not be valid to receive a t_index earlier than the last processed time step) and get_output_values_for_timestep (because formulations do not save results from previous time steps, only the results from the last processed time step can be used to generate output).

Referenced by realization::Bmi_Module_Formulation::get_output_values_for_timestep(), and realization::Bmi_Module_Formulation::update().

◆ OPTIONAL_PARAMETERS

std::vector<std::string> realization::Bmi_Module_Formulation::OPTIONAL_PARAMETERS
privateinherited
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__OUTPUT_PRECISION,
BMI_REALIZATION_CFG_PARAM_OPT__ALLOW_EXCEED_END,
BMI_REALIZATION_CFG_PARAM_OPT__FIXED_TIME_STEP,
BMI_REALIZATION_CFG_PARAM_OPT__LIB_FILE
}

◆ output

utils::StreamHandler HY_CatchmentArea::output
protectedinherited

◆ 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_field_names(), 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 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().

◆ realized_catchment

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

◆ REQUIRED_PARAMETERS

std::vector<std::string> realization::Bmi_Module_Formulation::REQUIRED_PARAMETERS
privateinherited
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_Module_Formulation::get_required_parameters().


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