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
71inline void bookNegativeSourceClamp(SimulationContext& ctx, int node, int p, double shortfall) {
72 auto& st = ctx.negsrc;
73 st.clamp_events += 1;
74 st.shortfall_mass += shortfall;
75 // The negative request was booked (signed) into qual_routing_ex_in by
76 // the loaders; the unmet part did not actually leave the water, so it
77 // is returned to the row. v1 scope: EXTERNAL_INFLOW and the API flux
78 // are the admitted negative pathways, and both book into ex_in —
79 // negative DWF/GW/RDII concentrations remain out of scope, recorded.
80 if (p >= 0 && static_cast<std::size_t>(p) < ctx.mass_balance.qual_routing_ex_in.size())
81 ctx.mass_balance.qual_routing_ex_in[static_cast<std::size_t>(p)] += shortfall;
82 if (!st.first_clamp_recorded) {
83 st.first_clamp_recorded = true;
84 st.first_node = node;
85 }
86}
87
100 auto& st = ctx.negsrc;
101 st.age_clamp_events += 1;
102 if (!st.first_clamp_recorded) {
103 st.first_clamp_recorded = true;
104 st.first_node = node;
105 }
106}
107
137inline void bookNegativeCellSourceClamp(SimulationContext& ctx, int conduit, double shortfall) {
138 auto& st = ctx.negsrc;
139 st.clamp_events += 1;
140 st.shortfall_mass += shortfall;
141 if (!st.first_clamp_recorded) {
142 st.first_clamp_recorded = true;
143 st.first_node = conduit;
144 }
145}
146
160 const auto& st = ctx.negsrc;
161 if (st.clamp_events == 0 && st.age_clamp_events == 0)
162 return;
163 ctx.warnings.push_back(
164 "D-NS1 summary: extraction exceeded available mass " + std::to_string(st.clamp_events) +
165 " time(s) (unmet extraction " + std::to_string(st.shortfall_mass) +
166 " internal mass units)" +
167 (st.age_clamp_events > 0
168 ? ", water-age extraction clamped " + std::to_string(st.age_clamp_events) + " time(s)"
169 : std::string()) +
170 ", first at element index " + std::to_string(st.first_node) +
171 ". Extraction clamps ROUTINELY while the system fills, when elements "
172 "are near-empty; a nonzero count is not by itself a modelling error. "
173 "Node-seam clamps are ledgered (the ledger carries the mass actually "
174 "removed); ARD cell-source clamps are counted only — see "
175 "bookNegativeCellSourceClamp.");
176}
177
178} // namespace quality
179} // namespace openswmm
180
181#endif // OPENSWMM_QUALITY_NEGATIVE_SOURCES_HPP
The central, reentrant simulation context for the new engine.
Definition Node.cpp:38
Definition ConservativeMixing.cpp:8
void summarizeNegativeSourceClamps(SimulationContext &ctx)
End-of-run summary (pushed once by SWMMEngine::end when anything clamped; gates read ctx....
Definition NegativeSources.hpp:159
void bookNegativeAgeClamp(SimulationContext &ctx, int node)
Age-row clamp: counted, not ledgered (no age row until A2c) and not warned per-clamp (see bookNegativ...
Definition NegativeSources.hpp:99
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:71
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:137
Definition ExchangeLaw.hpp:60
std::vector< double > qual_routing_ex_in
External (interface file) quality mass inflow.
Definition SimulationContext.hpp:1328
long clamp_events
pollutant clamps, all engines
Definition SimulationContext.hpp:1489
long age_clamp_events
age-row clamps
Definition SimulationContext.hpp:1491
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
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:1107