OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
Inflow.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
33
34#ifndef OPENSWMM_INFLOW_HPP
35#define OPENSWMM_INFLOW_HPP
36
37#include <cstdint>
38#include <vector>
39
40namespace openswmm {
41
43class SWMMEngine;
44
45namespace inflow {
46
47// ============================================================================
48// Pattern types
49// ============================================================================
50
51constexpr int MONTHLY_PATTERN = 0;
52constexpr int DAILY_PATTERN = 1;
53constexpr int HOURLY_PATTERN = 2;
54constexpr int WEEKEND_PATTERN = 3;
55
56// ============================================================================
57// Per-node external inflow definition (SoA)
58// ============================================================================
59
63enum class ExtInflowKind : int {
64 FLOW = 0,
65 CONCEN = 1,
66 MASS = 2,
72 AGE = 3,
78};
79
81 int count = 0;
82 std::vector<int> node_idx;
83 std::vector<int> ts_idx;
84 std::vector<int> base_pat_idx;
85 std::vector<double> baseline;
86 std::vector<double> scale_factor;
87 std::vector<double> conv_factor;
90 std::vector<int> kind;
94 std::vector<int> pollut_idx;
95
103 void resize(int n);
104};
105
106// ============================================================================
107// Per-node dry weather flow definition (SoA)
108// ============================================================================
109
111 int count = 0;
112 std::vector<int> node_idx;
113 std::vector<double> avg_value;
114 std::vector<int> pat_monthly;
115 std::vector<int> pat_daily;
116 std::vector<int> pat_hourly;
117 std::vector<int> pat_weekend;
121 std::vector<uint8_t> is_flow;
123 std::vector<int> pollut_idx;
126 std::vector<int> msx_idx;
127
135 void resize(int n);
136};
137
138// ============================================================================
139// Time pattern table (12 monthly, 7 daily, 24 hourly values)
140// ============================================================================
141
143 int type = 0;
144 double factors[24] = {};
145};
146
147// ============================================================================
148// Inflow solver
149// ============================================================================
150
156public:
173 void init(SimulationContext& ctx);
174
183 void refreshPatterns(const SimulationContext& ctx);
184
205 void computeAll(SimulationContext& ctx, double current_date, double dt);
206
207private:
209 ExtInflowSoA ext_inflows_;
210 DwfInflowSoA dwf_inflows_;
211 std::vector<TimePattern> patterns_;
212
221 double getPatternFactor(int pat_idx, int month, int day, int hour) const;
222};
223
224} // namespace inflow
225} // namespace openswmm
226
227#endif // OPENSWMM_INFLOW_HPP
Owned resolved inflow definitions and pattern lookup cache. Serialize init/refresh/compute with model...
Definition Inflow.hpp:155
void init(SimulationContext &ctx)
Rebuild external/DWF row caches, bindings and unit conversions from the model.
Definition Inflow.cpp:130
void computeAll(SimulationContext &ctx, double current_date, double dt)
Add resolved external/DWF water and quality rates to routing input channels.
Definition Inflow.cpp:435
void refreshPatterns(const SimulationContext &ctx)
Copy current pattern types/factors into private fixed-width runtime rows.
Definition Inflow.cpp:114
friend class openswmm::SWMMEngine
Definition Inflow.hpp:208
double getPatternFactor(int p, int month, int day, int hour)
Computes time pattern multiplier for a specific point in time.
Definition inflow.c:472
Definition Inflow.cpp:41
constexpr int WEEKEND_PATTERN
Definition Inflow.hpp:54
constexpr int MONTHLY_PATTERN
Definition Inflow.hpp:51
constexpr int HOURLY_PATTERN
Definition Inflow.hpp:53
constexpr int DAILY_PATTERN
Definition Inflow.hpp:52
ExtInflowKind
Definition Inflow.hpp:63
@ FLOW
Volumetric inflow (constituent FLOW)
Definition Inflow.hpp:64
@ AGE
Definition Inflow.hpp:72
@ MSX_MASS
Definition Inflow.hpp:77
@ CONCEN
Pollutant concentration; mass rate = value * node flow.
Definition Inflow.hpp:65
@ MSX_CONCEN
Definition Inflow.hpp:76
@ MASS
Definition Inflow.hpp:66
Definition ExchangeLaw.hpp:60
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
Definition Inflow.hpp:110
void resize(int n)
Reset every DWF row to unresolved/default values.
Definition Inflow.cpp:81
int count
Definition Inflow.hpp:111
std::vector< int > node_idx
Which node.
Definition Inflow.hpp:112
std::vector< double > avg_value
Average DWF value.
Definition Inflow.hpp:113
std::vector< int > msx_idx
Definition Inflow.hpp:126
std::vector< int > pat_weekend
Definition Inflow.hpp:117
std::vector< uint8_t > is_flow
Definition Inflow.hpp:121
std::vector< int > pat_hourly
Hourly pattern index (-1 = none)
Definition Inflow.hpp:116
std::vector< int > pollut_idx
Pollutant index for a non-FLOW row (-1 when FLOW or unmatched).
Definition Inflow.hpp:123
std::vector< int > pat_monthly
Monthly pattern index (-1 = none)
Definition Inflow.hpp:114
std::vector< int > pat_daily
Daily pattern index (-1 = none)
Definition Inflow.hpp:115
Definition Inflow.hpp:80
std::vector< int > ts_idx
Timeseries index (-1 = none)
Definition Inflow.hpp:83
int count
Definition Inflow.hpp:81
std::vector< int > pollut_idx
Definition Inflow.hpp:94
void resize(int n)
Reset every external-inflow row to unresolved/default values.
Definition Inflow.cpp:68
std::vector< double > scale_factor
Timeseries scaling factor.
Definition Inflow.hpp:86
std::vector< double > conv_factor
Definition Inflow.hpp:87
std::vector< int > node_idx
Which node this inflow applies to.
Definition Inflow.hpp:82
std::vector< int > base_pat_idx
Baseline pattern index (-1 = none)
Definition Inflow.hpp:84
std::vector< double > baseline
Constant baseline value.
Definition Inflow.hpp:85
std::vector< int > kind
Definition Inflow.hpp:90
Definition Inflow.hpp:142
int type
0=monthly, 1=daily, 2=hourly, 3=weekend
Definition Inflow.hpp:143
double factors[24]
Up to 24 factors (monthly=12, daily=7, hourly=24)
Definition Inflow.hpp:144