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
43
44namespace inflow {
45
46// ============================================================================
47// Pattern types
48// ============================================================================
49
50constexpr int MONTHLY_PATTERN = 0;
51constexpr int DAILY_PATTERN = 1;
52constexpr int HOURLY_PATTERN = 2;
53constexpr int WEEKEND_PATTERN = 3;
54
55// ============================================================================
56// Per-node external inflow definition (SoA)
57// ============================================================================
58
62enum class ExtInflowKind : int {
63 FLOW = 0,
64 CONCEN = 1,
65 MASS = 2,
71 AGE = 3,
77};
78
80 int count = 0;
81 std::vector<int> node_idx;
82 std::vector<int> ts_idx;
83 std::vector<int> base_pat_idx;
84 std::vector<double> baseline;
85 std::vector<double> scale_factor;
86 std::vector<double> conv_factor;
89 std::vector<int> kind;
93 std::vector<int> pollut_idx;
94
95 void resize(int n);
96};
97
98// ============================================================================
99// Per-node dry weather flow definition (SoA)
100// ============================================================================
101
103 int count = 0;
104 std::vector<int> node_idx;
105 std::vector<double> avg_value;
106 std::vector<int> pat_monthly;
107 std::vector<int> pat_daily;
108 std::vector<int> pat_hourly;
109 std::vector<int> pat_weekend;
113 std::vector<uint8_t> is_flow;
115 std::vector<int> pollut_idx;
118 std::vector<int> msx_idx;
119
120 void resize(int n);
121};
122
123// ============================================================================
124// Time pattern table (12 monthly, 7 daily, 24 hourly values)
125// ============================================================================
126
128 int type = 0;
129 double factors[24] = {};
130};
131
132// ============================================================================
133// Inflow solver
134// ============================================================================
135
137public:
138 void init(SimulationContext& ctx);
139
152 void refreshPatterns(const SimulationContext& ctx);
153
167 void computeAll(SimulationContext& ctx, double current_date, double dt);
168
169private:
170 ExtInflowSoA ext_inflows_;
171 DwfInflowSoA dwf_inflows_;
172 std::vector<TimePattern> patterns_;
173
175 double getPatternFactor(int pat_idx, int month, int day, int hour) const;
176};
177
178} // namespace inflow
179} // namespace openswmm
180
181#endif // OPENSWMM_INFLOW_HPP
Definition Inflow.hpp:136
void init(SimulationContext &ctx)
Definition Inflow.cpp:101
void computeAll(SimulationContext &ctx, double current_date, double dt)
Compute all external + DWF inflows and add to node lateral flow.
Definition Inflow.cpp:333
void refreshPatterns(const SimulationContext &ctx)
Re-copy time-pattern factors from the context into the solver's per-step lookup cache.
Definition Inflow.cpp:86
Definition Inflow.cpp:41
constexpr int WEEKEND_PATTERN
Definition Inflow.hpp:53
constexpr int MONTHLY_PATTERN
Definition Inflow.hpp:50
constexpr int HOURLY_PATTERN
Definition Inflow.hpp:52
constexpr int DAILY_PATTERN
Definition Inflow.hpp:51
ExtInflowKind
Definition Inflow.hpp:62
@ FLOW
Volumetric inflow (constituent FLOW)
Definition Inflow.hpp:63
@ AGE
Definition Inflow.hpp:71
@ MSX_MASS
Definition Inflow.hpp:76
@ CONCEN
Pollutant concentration; mass rate = value * node flow.
Definition Inflow.hpp:64
@ MSX_CONCEN
Definition Inflow.hpp:75
@ MASS
Definition Inflow.hpp:65
Definition NodeCoupling.cpp:16
Central, reentrant simulation context.
Definition SimulationContext.hpp:353
Definition Inflow.hpp:102
void resize(int n)
Definition Inflow.cpp:58
int count
Definition Inflow.hpp:103
std::vector< int > node_idx
Which node.
Definition Inflow.hpp:104
std::vector< double > avg_value
Average DWF value.
Definition Inflow.hpp:105
std::vector< int > msx_idx
Definition Inflow.hpp:118
std::vector< int > pat_weekend
Definition Inflow.hpp:109
std::vector< uint8_t > is_flow
Definition Inflow.hpp:113
std::vector< int > pat_hourly
Hourly pattern index (-1 = none)
Definition Inflow.hpp:108
std::vector< int > pollut_idx
Pollutant index for a non-FLOW row (-1 when FLOW or unmatched).
Definition Inflow.hpp:115
std::vector< int > pat_monthly
Monthly pattern index (-1 = none)
Definition Inflow.hpp:106
std::vector< int > pat_daily
Daily pattern index (-1 = none)
Definition Inflow.hpp:107
Definition Inflow.hpp:79
std::vector< int > ts_idx
Timeseries index (-1 = none)
Definition Inflow.hpp:82
int count
Definition Inflow.hpp:80
std::vector< int > pollut_idx
Definition Inflow.hpp:93
void resize(int n)
Definition Inflow.cpp:45
std::vector< double > scale_factor
Timeseries scaling factor.
Definition Inflow.hpp:85
std::vector< double > conv_factor
Definition Inflow.hpp:86
std::vector< int > node_idx
Which node this inflow applies to.
Definition Inflow.hpp:81
std::vector< int > base_pat_idx
Baseline pattern index (-1 = none)
Definition Inflow.hpp:83
std::vector< double > baseline
Constant baseline value.
Definition Inflow.hpp:84
std::vector< int > kind
Definition Inflow.hpp:89
Definition Inflow.hpp:127
int type
0=monthly, 1=daily, 2=hourly, 3=weekend
Definition Inflow.hpp:128
double factors[24]
Up to 24 factors (monthly=12, daily=7, hourly=24)
Definition Inflow.hpp:129