NGen
Loading...
Searching...
No Matches
Formulation.hpp
1#ifndef FORMULATION_H
2#define FORMULATION_H
3
4#include <memory>
5#include <string>
6#include <map>
7#include <exception>
8#include <vector>
9
10#include "JSONProperty.hpp"
11#include "GenericDataProvider.hpp"
12#include "utilities/output/CatchmentOutputsMgr.hpp" // utils::OutputField
13
14#include <boost/property_tree/ptree.hpp>
15#include <boost/algorithm/string.hpp>
16
17namespace realization {
18
27 public:
28 typedef long time_step_t;
29
30 Formulation(const std::string& id, std::shared_ptr<data_access::GenericDataProvider> forcing);
31 Formulation(const std::string& id);
32
33 virtual ~Formulation(){};
34
35 virtual std::string get_formulation_type() const = 0;
36
37 // TODO: to truly make this properly generalized (beyond catchments, and to some degree even in that
38 // context) a more complex type for the entirety of the response/output is needed, perhaps with independent
39 // access functions
40
41 // TODO: a reference to the actual time of the initial time step is needed
42
43 // TODO: a reference to the last calculated time step is needed
44
45 // TODO: a mapping of previously calculated time steps to the size/delta of each is needed (unless we
46 // introduce a way to enforce immutable time step delta values for an object)
47
48 // TODO: a convenience method for getting the actual time of calculated time steps (at least the last)
49
88
90 std::string get_id() const {
91 return this->id;
92 }
93
94 virtual void create_formulation(boost::property_tree::ptree &config, geojson::PropertyMap *global = nullptr) = 0;
95 virtual void create_formulation(geojson::PropertyMap properties) = 0;
96
97 virtual void check_mass_balance(const int& iteration, const int& total_steps, const std::string& timestamp) const = 0;
98
109 virtual void checkpoint_state(const int& iteration, const int& total_steps, const std::string& timestamp) const = 0;
110
117 virtual void update(time_step_t t_index, time_step_t t_delta) = 0;
118
140 virtual double get_response(time_step_t t_index, time_step_t t_delta) = 0;
141
152 virtual std::vector<utils::OutputField> get_output_fields() const = 0;
153
162 virtual std::vector<double> get_output_values_for_timestep(int timestep) = 0;
163
167 void finalize();
168
170 const std::string& get_feature_id() const {
171 return this->feature_id;
172 }
173
180 void set_feature_id(const std::string& feature_id) {
181 this->feature_id = feature_id;
182 }
184
185 protected:
186
187 virtual const std::vector<std::string>& get_required_parameters() const = 0;
188 geojson::PropertyMap interpret_parameters(boost::property_tree::ptree &config, geojson::PropertyMap *global = nullptr);
190
192 std::string id;
193
194 std::shared_ptr<data_access::GenericDataProvider> forcing;
195
196 private:
198 std::string feature_id;
199 };
200
201}
202#endif // FORMULATION_H
A model attached to a feature: what is run for that feature, and what it emits.
Definition Formulation.hpp:26
std::string get_id() const
See Identity.
Definition Formulation.hpp:90
virtual std::vector< utils::OutputField > get_output_fields() const =0
Get this formulation's output fields – name plus metadata (units, ...) – in the same order as the val...
virtual std::string get_formulation_type() const =0
virtual double get_response(time_step_t t_index, time_step_t t_delta)=0
Execute the backing model formulation for the given time step, where it is of the specified size,...
virtual ~Formulation()
Definition Formulation.hpp:33
virtual void create_formulation(geojson::PropertyMap properties)=0
See Identity.
void validate_parameters(geojson::PropertyMap options)
Definition Formulation.cpp:52
void set_feature_id(const std::string &feature_id)
Associate this formulation with a feature other than the one it is named for.
Definition Formulation.hpp:180
virtual void create_formulation(boost::property_tree::ptree &config, geojson::PropertyMap *global=nullptr)=0
See Identity.
virtual void update(time_step_t t_index, time_step_t t_delta)=0
Advance the backing model formulation through the given time step.
geojson::PropertyMap interpret_parameters(boost::property_tree::ptree &config, geojson::PropertyMap *global=nullptr)
Definition Formulation.cpp:32
std::string id
This formulation's locator; see get_id.
Definition Formulation.hpp:192
const std::string & get_feature_id() const
The feature whose data this model reads and produces; see Identity.
Definition Formulation.hpp:170
virtual void checkpoint_state(const int &iteration, const int &total_steps, const std::string &timestamp) const =0
Invoke the state-save side of the ngen BMI Serialization Protocol.
std::shared_ptr< data_access::GenericDataProvider > forcing
Definition Formulation.hpp:194
virtual void check_mass_balance(const int &iteration, const int &total_steps, const std::string &timestamp) const =0
See Identity.
std::string feature_id
This formulation's subject; see get_feature_id.
Definition Formulation.hpp:198
void finalize()
Release resources of the given forcing provider.
Definition Formulation.cpp:24
virtual const std::vector< std::string > & get_required_parameters() const =0
virtual std::vector< double > get_output_values_for_timestep(int timestep)=0
Get the output values for the given time step, positionally aligned with get_output_fields.
Formulation(const std::string &id, std::shared_ptr< data_access::GenericDataProvider > forcing)
Definition Formulation.cpp:14
long time_step_t
Definition Formulation.hpp:28
std::map< std::string, JSONProperty > PropertyMap
Shorthand for a mapping between strings and properties.
Definition JSONProperty.hpp:21
Definition HY_CatchmentRealization.hpp:13