generated from NOAA-OWP/owp-open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Layer and DomainLayer Formulation Management #752
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0c4cf7f
feat(config): add layer configuration structure for parsing layer inp…
hellkite500 773f53b
refactor(config): use layer config for layer parsing
hellkite500 481f33b
feat(layers): construct and manage layer formulations
hellkite500 f5e1129
chore: cleanup includes and mark TODO's
hellkite500 19375a7
feat(DomainLayer): Implement a DomainLayer which connects a layer to …
hellkite500 7e8972d
feat(ngen): update layer handling, allows a domain layer to run along…
hellkite500 88f3d23
fix(config): Handle missing layer keys during construction
hellkite500 581e8e5
chore: remove unused/duplicated code
hellkite500 3de3b2b
fix: remove dunder macro guard
hellkite500 291900e
chore: Update doc strings for DomainLayer
hellkite500 9c20b80
fix: pedantic semi-colon removal from namespace code block
hellkite500 cbc73a1
feat: add layer and time context to possible formulation errors
hellkite500 04fda44
chore: fix up typos in doc strings
hellkite500 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#ifndef NGEN_DOMAIN_LAYER | ||
#define NGEN_DOMAIN_LAYER | ||
|
||
#include "Catchment_Formulation.hpp" | ||
#include "Layer.hpp" | ||
#include "State_Exception.hpp" | ||
|
||
namespace ngen | ||
{ | ||
class DomainLayer : public Layer | ||
{ | ||
public: | ||
DomainLayer() = delete; | ||
/** | ||
* @brief Construct a new Domain Layer object. | ||
* | ||
* Unlike HY_Features types, the feature relationship with a DomainLayer is | ||
* indirect. The @p features collection defines features associated | ||
* (e.g. overlapping) with the Domain. The domain must be further queried | ||
* in order to provide specific information at a particular feature, | ||
* e.g. a catchment which this domain overlaps with, or a nexus location | ||
* the domain may contribute to directly/indirectly via the catchment. | ||
* | ||
* A domain layer associated with a set of catchment features will need to have | ||
* outputs of the domain resampled/aggregated to the catchment. | ||
* | ||
* Currently unsupported, but a future extension of the DomainLayer is interactions | ||
* beetween two or more generic DomainLayers, perhaps each with its own internal grid, | ||
* and resampling between the layers would be required similarly to resampling from | ||
* a DomainLayer to the HY_Features catchment domain. | ||
* | ||
* @param desc LayerDescription for the domain layer | ||
* @param s_t Simulation_Time object associated with the domain layer | ||
* @param features collection of HY_Features associated with the domain | ||
* @param idx index of the layer | ||
* @param formulation Formulation associated with the domain | ||
*/ | ||
DomainLayer( | ||
const LayerDescription& desc, | ||
const Simulation_Time& s_t, | ||
feature_type& features, | ||
long idx, | ||
std::shared_ptr<realization::Catchment_Formulation> formulation): | ||
Layer(desc, s_t, features, idx), formulation(formulation) | ||
{ | ||
formulation->write_output("Time Step,""Time,"+formulation->get_output_header_line(",")+"\n"); | ||
} | ||
|
||
/*** | ||
* @brief Run one simulation timestep for this model associated with the domain | ||
* | ||
* A domain layer update simply advances the attached domain formulation(s) in time and records | ||
* the BMI accessible outputs of the domain formulation. Since this is NOT a HY_Features | ||
* concept/class, it doesn't directly associate with HY_Features types (e.g. catchments, nexus, ect) | ||
* | ||
* Any required connection to other components, e.g. providing inputs to a catchment feature, | ||
* is not yet implemented in this class. | ||
*/ | ||
void update_models() override{ | ||
std::string current_timestamp = simulation_time.get_timestamp(output_time_index); | ||
try{ | ||
formulation->get_response(output_time_index, simulation_time.get_output_interval_seconds()); | ||
} | ||
catch(models::external::State_Exception& e){ | ||
std::string msg = e.what(); | ||
msg = msg+" at timestep "+std::to_string(output_time_index) | ||
+" ("+current_timestamp+")" | ||
+" at domain layer "+description.name | ||
+" (layer id: "+std::to_string(description.id)+")"; | ||
throw models::external::State_Exception(msg); | ||
} | ||
std::string output = std::to_string(output_time_index)+","+current_timestamp+","+ | ||
formulation->get_output_line_for_timestep(output_time_index)+"\n"; | ||
formulation->write_output(output); | ||
++output_time_index; | ||
if ( output_time_index < simulation_time.get_total_output_times() ) | ||
{ | ||
simulation_time.advance_timestep(); | ||
} | ||
|
||
} | ||
|
||
private: | ||
std::shared_ptr<realization::Catchment_Formulation> formulation; | ||
}; | ||
} | ||
|
||
#endif // NGEN_DOMAIN_LAYER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#ifndef NGEN_REALIZATION_CONFIG_LAYER_H | ||
#define NGEN_REALIZATION_CONFIG_LAYER_H | ||
|
||
#include <boost/property_tree/ptree.hpp> | ||
|
||
#include "LayerData.hpp" | ||
#include "config.hpp" | ||
|
||
namespace realization{ | ||
namespace config{ | ||
|
||
/** | ||
* @brief Layer configuration information | ||
* | ||
*/ | ||
struct Layer{ | ||
/** | ||
* @brief Construct a new default surface layer | ||
* | ||
* Default layers are surface layers (0) with 3600 second time steps | ||
* | ||
*/ | ||
Layer():descriptor( {"surface layer", "s", 0, 3600 } ){}; | ||
|
||
/** | ||
* @brief Construct a new Layer from a property tree | ||
* | ||
* @param tree | ||
*/ | ||
Layer(const boost::property_tree::ptree& tree):formulation(tree){ | ||
std::vector<std::string> missing_keys; | ||
auto name = tree.get_optional<std::string>("name"); | ||
if(!name) missing_keys.push_back("name"); | ||
auto unit = tree.get<std::string>("time_step_units", "s"); | ||
|
||
auto id = tree.get_optional<int>("id"); | ||
if(!id) missing_keys.push_back("id"); | ||
|
||
auto ts = tree.get_optional<double>("time_step"); | ||
//TODO is time_step required? e.g. need to add to missing_keys? | ||
auto tmp = tree.get_optional<std::string>("domain"); | ||
if(tmp) domain = *tmp; | ||
if(missing_keys.empty()){ | ||
descriptor = {*name, unit, *id, *ts};// ngen::LayerDescription( ); | ||
} | ||
else{ | ||
std::string message = "ERROR: Layer cannot be created; the following parameters are missing or invalid: "; | ||
|
||
for (const auto& missing : missing_keys) { | ||
message += missing; | ||
message += ", "; | ||
} | ||
//pop off the extra ", " | ||
message.pop_back(); | ||
message.pop_back(); | ||
throw std::runtime_error(message); | ||
} | ||
} | ||
|
||
/** | ||
* @brief Get the descriptor associated with this layer configuration | ||
* | ||
* @return const ngen::LayerDescription& | ||
*/ | ||
const ngen::LayerDescription& get_descriptor(){ | ||
return descriptor; | ||
} | ||
|
||
/** | ||
* @brief Determines if the layer has a valid configured formulation | ||
* | ||
* @return true | ||
* @return false | ||
*/ | ||
bool has_formulation(){ | ||
return formulation.has_formulation(); | ||
} | ||
|
||
/** | ||
* @brief Get the domain description | ||
* | ||
* @return const std::string& | ||
*/ | ||
const std::string& get_domain(){ return domain; } | ||
|
||
/** | ||
* @brief The formulation configuration associated with the layer | ||
* | ||
*/ | ||
Config formulation; | ||
private: | ||
std::string domain; | ||
ngen::LayerDescription descriptor; | ||
|
||
}; | ||
|
||
}//end namespace config | ||
}//end namespace realization | ||
#endif //NGEN_REALIZATION_CONFIG_LAYER_H |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is duplicated from
formulation
initialized just above on line 104There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed duplicate in 581e8e5