OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
NegativeSources.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
35
36#ifndef OPENSWMM_QUALITY_NEGATIVE_SOURCES_HPP
37#define OPENSWMM_QUALITY_NEGATIVE_SOURCES_HPP
38
39#include <string>
40
42
43namespace openswmm {
44namespace quality {
45
60inline void bookNegativeSourceClamp(SimulationContext& ctx, int node, int p,
61 double shortfall) {
62 auto& st = ctx.negsrc;
63 st.clamp_events += 1;
64 st.shortfall_mass += shortfall;
65 // The negative request was booked (signed) into qual_routing_ex_in by
66 // the loaders; the unmet part did not actually leave the water, so it
67 // is returned to the row. v1 scope: EXTERNAL_INFLOW and the API flux
68 // are the admitted negative pathways, and both book into ex_in —
69 // negative DWF/GW/RDII concentrations remain out of scope, recorded.
70 if (p >= 0 &&
71 static_cast<std::size_t>(p) <
73 ctx.mass_balance.qual_routing_ex_in[static_cast<std::size_t>(p)] +=
74 shortfall;
75 if (!st.first_clamp_recorded) {
76 st.first_clamp_recorded = true;
77 st.first_node = node;
78 }
79}
80
84 auto& st = ctx.negsrc;
85 st.age_clamp_events += 1;
86 if (!st.first_clamp_recorded) {
87 st.first_clamp_recorded = true;
88 st.first_node = node;
89 }
90}
91
118inline void bookNegativeCellSourceClamp(SimulationContext& ctx, int conduit,
119 double shortfall) {
120 auto& st = ctx.negsrc;
121 st.clamp_events += 1;
122 st.shortfall_mass += shortfall;
123 if (!st.first_clamp_recorded) {
124 st.first_clamp_recorded = true;
125 st.first_node = conduit;
126 }
127}
128
132 const auto& st = ctx.negsrc;
133 if (st.clamp_events == 0 && st.age_clamp_events == 0) return;
134 ctx.warnings.push_back(
135 "D-NS1 summary: extraction exceeded available mass " +
136 std::to_string(st.clamp_events) + " time(s) (unmet extraction " +
137 std::to_string(st.shortfall_mass) + " internal mass units)" +
138 (st.age_clamp_events > 0
139 ? ", water-age extraction clamped " +
140 std::to_string(st.age_clamp_events) + " time(s)"
141 : std::string()) +
142 ", first at element index " + std::to_string(st.first_node) +
143 ". Extraction clamps ROUTINELY while the system fills, when elements "
144 "are near-empty; a nonzero count is not by itself a modelling error. "
145 "Node-seam clamps are ledgered (the ledger carries the mass actually "
146 "removed); ARD cell-source clamps are counted only — see "
147 "bookNegativeCellSourceClamp.");
148}
149
150} // namespace quality
151} // namespace openswmm
152
153#endif // OPENSWMM_QUALITY_NEGATIVE_SOURCES_HPP
The central, reentrant simulation context for the new engine.
Definition Node.cpp:38
Definition NegativeSources.hpp:44
void summarizeNegativeSourceClamps(SimulationContext &ctx)
Definition NegativeSources.hpp:131
void bookNegativeAgeClamp(SimulationContext &ctx, int node)
Definition NegativeSources.hpp:83
void bookNegativeSourceClamp(SimulationContext &ctx, int node, int p, double shortfall)
Book one pollutant-row clamp: count it and un-book the shortfall from the external-extraction ledger ...
Definition NegativeSources.hpp:60
void bookNegativeCellSourceClamp(SimulationContext &ctx, int conduit, double shortfall)
P1.4: book one ARD cell-source clamp. Counted, NOT ledgered — and the reason is structural,...
Definition NegativeSources.hpp:118
Definition NodeCoupling.cpp:16
std::vector< double > qual_routing_ex_in
External (interface file) quality mass inflow.
Definition SimulationContext.hpp:1155
long clamp_events
pollutant clamps, all engines
Definition SimulationContext.hpp:1296
long age_clamp_events
age-row clamps
Definition SimulationContext.hpp:1298
Central, reentrant simulation context.
Definition SimulationContext.hpp:353
struct openswmm::SimulationContext::MassBalance mass_balance
struct openswmm::SimulationContext::NegativeSourceStats negsrc
std::vector< std::string > warnings
Accumulated warning messages written to report file.
Definition SimulationContext.hpp:998