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
32#include <string>
33#include <exception>
34#include <protocol.hpp>
35#include <nonstd/expected.hpp>
36
37namespace models{ namespace bmi{ namespace protocols{
38 using nonstd::expected;
40 constexpr const char* const INPUT_MASS_NAME = "ngen::mass_in";
41 constexpr const char* const OUTPUT_MASS_NAME = "ngen::mass_out";
42 constexpr const char* const STORED_MASS_NAME = "ngen::mass_stored";
43 constexpr const char* const LEAKED_MASS_NAME = "ngen::mass_leaked";
44
46 //The top level object key which will contain the map of configuration options
47 constexpr const char* const CONFIGURATION_KEY = "mass_balance";
48 //Configuration option keys
49 constexpr const char* const TOLERANCE_KEY = "tolerance";
50 constexpr const char* const FATAL_KEY = "fatal";
51 constexpr const char* const CHECK_KEY = "check";
52 constexpr const char* const FREQUENCY_KEY = "frequency";
53
62 public:
63
71 NgenMassBalance(const ModelPtr& model, const Properties& properties);
72
79
80 virtual ~NgenMassBalance() override;
81
82 private:
83
99 auto run(const ModelPtr& model, const Context& ctx) const -> expected<void, ProtocolError> override;
100
107 nsel_NODISCARD auto check_support(const ModelPtr& model) -> expected<void, ProtocolError> override;
108
133 auto initialize(const ModelPtr& model, const Properties& properties) -> expected<void, ProtocolError> override;
134
141 bool is_supported() const override final;
142
143 private:
144 double tolerance;
145 // How often (in time steps) to check mass balance
147 // Whether the protocol is supported by the model, false by default
148 bool supported = false;
149 // Configurable options/values
150 bool check;
152 };
153
154}}}
155
Definition protocol.hpp:92
Definition mass_balance.hpp:54
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:91
auto run(const ModelPtr &model, const Context &ctx) const -> expected< void, ProtocolError > override
Run the mass balance protocol.
Definition mass_balance.cpp:39
bool is_fatal
Definition mass_balance.hpp:151
bool supported
Definition mass_balance.hpp:148
double tolerance
Definition mass_balance.hpp:144
bool check
Definition mass_balance.hpp:150
bool is_supported() const override final
Whether the protocol is supported by the model.
Definition mass_balance.cpp:191
NgenMassBalance()
Construct a new, default Ngen Mass Balance object.
Definition mass_balance.cpp:35
int frequency
Definition mass_balance.hpp:146
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:138
Definition bmi.hpp:16
constexpr const char *const FREQUENCY_KEY
Definition mass_balance.hpp:52
constexpr const char *const CHECK_KEY
Definition mass_balance.hpp:51
constexpr const char *const STORED_MASS_NAME
Definition mass_balance.hpp:42
constexpr const char *const LEAKED_MASS_NAME
Definition mass_balance.hpp:43
std::shared_ptr< models::bmi::Bmi_Adapter > ModelPtr
Definition protocol.hpp:89
geojson::PropertyMap Properties
Definition protocol.hpp:90
constexpr const char *const OUTPUT_MASS_NAME
Definition mass_balance.hpp:41
constexpr const char *const FATAL_KEY
Definition mass_balance.hpp:50
constexpr const char *const CONFIGURATION_KEY
Configuration keys for defining configurable properties of the protocol.
Definition mass_balance.hpp:47
constexpr const char *const INPUT_MASS_NAME
Mass balance variable names.
Definition mass_balance.hpp:40
constexpr const char *const TOLERANCE_KEY
Definition mass_balance.hpp:49
Definition AbstractCLibBmiAdapter.hpp:6
Definition protocol.hpp:82