NGen
Loading...
Searching...
No Matches
mass_balance.hpp
1/*
2Author: Nels Frazier
3Copyright (C) 2025 Lynker
4------------------------------------------------------------------------
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16------------------------------------------------------------------------
17Version 0.3
18Implement is_supported()
19Re-align members for more better memory layout/padding
20Update docstrings
21
22Version 0.2
23Conform to updated protocol interface
24Removed integration and error exceptions in favor of ProtocolError
25
26Version 0.1
27Interface of the BMI mass balance protocol
28*/
29#pragma once
30
31#include <nonstd/expected.hpp>
32#include <protocol.hpp>
33
34namespace models {
35namespace bmi {
36namespace protocols {
37using nonstd::expected;
39constexpr const char* const INPUT_MASS_NAME = "ngen::mass_in";
40constexpr const char* const OUTPUT_MASS_NAME = "ngen::mass_out";
41constexpr const char* const STORED_MASS_NAME = "ngen::mass_stored";
42constexpr const char* const LEAKED_MASS_NAME = "ngen::mass_leaked";
43
45// The top level object key which will contain the map of configuration options
46constexpr const char* const CONFIGURATION_KEY = "mass_balance";
47// Configuration option keys
48constexpr const char* const TOLERANCE_KEY = "tolerance";
49constexpr const char* const FATAL_KEY = "fatal";
50constexpr const char* const CHECK_KEY = "check";
51constexpr const char* const FREQUENCY_KEY = "frequency";
52
61 public:
69 NgenMassBalance(const ModelPtr& model, const Properties& properties);
70
77
78 virtual ~NgenMassBalance() override;
79
80 private:
96 auto run(const ModelPtr& model, const Context& ctx) const
97 -> expected<void, ProtocolError> override;
98
105 nsel_NODISCARD auto check_support(const ModelPtr& model)
106 -> expected<void, ProtocolError> override;
107
133 auto initialize(const ModelPtr& model, const Properties& properties)
134 -> expected<void, ProtocolError> override;
135
142 bool is_supported() const override final;
143
144 private:
145 double tolerance;
146 // How often (in time steps) to check mass balance
148 // Whether the protocol is supported by the model, false by default
149 bool supported = false;
150 // Configurable options/values
151 bool check;
153};
154
155} // namespace protocols
156} // namespace bmi
157} // namespace models
Definition protocol.hpp:110
Definition mass_balance.hpp:53
nsel_NODISCARD auto check_support(const ModelPtr &model) -> expected< void, ProtocolError > override
Check if the mass balance protocol is supported by the model.
Definition mass_balance.cpp:97
auto run(const ModelPtr &model, const Context &ctx) const -> expected< void, ProtocolError > override
Run the mass balance protocol.
Definition mass_balance.cpp:47
bool is_fatal
Definition mass_balance.hpp:152
bool supported
Definition mass_balance.hpp:149
double tolerance
Definition mass_balance.hpp:145
bool check
Definition mass_balance.hpp:151
bool is_supported() const override final
Whether the protocol is supported by the model.
Definition mass_balance.cpp:193
NgenMassBalance()
Construct a new, default Ngen Mass Balance object.
Definition mass_balance.cpp:41
int frequency
Definition mass_balance.hpp:147
auto initialize(const ModelPtr &model, const Properties &properties) -> expected< void, ProtocolError > override
Check the model for support and initialize the mass balance protocol from the given properties.
Definition mass_balance.cpp:141
Definition deserialization.hpp:40
constexpr const char *const FREQUENCY_KEY
Definition mass_balance.hpp:51
constexpr const char *const CHECK_KEY
Definition mass_balance.hpp:50
constexpr const char *const STORED_MASS_NAME
Definition mass_balance.hpp:41
constexpr const char *const LEAKED_MASS_NAME
Definition mass_balance.hpp:42
std::shared_ptr< models::bmi::Bmi_Adapter > ModelPtr
Definition protocol.hpp:107
geojson::PropertyMap Properties
Definition protocol.hpp:108
constexpr const char *const OUTPUT_MASS_NAME
Definition mass_balance.hpp:40
constexpr const char *const FATAL_KEY
Definition mass_balance.hpp:49
constexpr const char *const CONFIGURATION_KEY
Configuration keys for defining configurable properties of the protocol.
Definition mass_balance.hpp:46
constexpr const char *const INPUT_MASS_NAME
Mass balance variable names.
Definition mass_balance.hpp:39
constexpr const char *const TOLERANCE_KEY
Definition mass_balance.hpp:48
Definition AbstractCLibBmiAdapter.hpp:6
Definition protocol.hpp:100