OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
Gage.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_GAGE_HPP
35#define OPENSWMM_GAGE_HPP
36
38#include <cstddef>
39#include <vector>
40
41namespace openswmm {
42
44struct Table;
45
51namespace gage {
52
53// ============================================================================
54// Constants
55// ============================================================================
56
57constexpr double ONE_SECOND = 1.1574074e-5;
58constexpr int MAXPASTRAIN = 48;
59
60// ============================================================================
61// Rain type codes
62// ============================================================================
63
64enum class RainType : int { INTENSITY = 0, VOLUME = 1, CUMULATIVE = 2 };
65
66// ============================================================================
67// Per-gage state
68// ============================================================================
69
70struct GageState {
71 double rainfall = 0.0;
72 double snowfall = 0.0;
73 double total_precip = 0.0;
74 double rain_accum = 0.0;
75 double api_rainfall = -1.0;
76 double snow_factor = 1.0;
77 double scale_factor = 1.0;
78 double units_factor = 1.0;
79 double adjust_factor = 1.0;
80 double rain_interval = 0.0;
82
83 double past_rain[MAXPASTRAIN] = {};
84 double past_rain_accum = 0.0;
85 double past_rain_interval = 0.0;
86};
87
88// ============================================================================
89// Functions
90// ============================================================================
91
101double convertRainfall(double raw_value, GageState& state);
102
103// ---------------------------------------------------------------------------
104// Shared rainfall resolution
105// ---------------------------------------------------------------------------
106//
107// The sequence "pick the gage's series -> apply the rain-type transform ->
108// apply units factor -> apply scale factor" is needed by the routing update,
109// by report rainfall, and by the swmm_gage_get_rainfall_series C API. Three
110// private copies would drift, so the pieces that are genuinely common live
111// here. (getReportRainfall deliberately does NOT apply the CUMULATIVE delta —
112// see its comment — so it composes these itself rather than calling
113// convertGageValue.)
114
122const Table* gageRainSeries(const SimulationContext& ctx, int gage_idx);
123
130bool gageIsUsed(const SimulationContext& ctx, int gage_idx);
131
140double gageNextRainDate(const SimulationContext& ctx, int gage_idx, double t);
141
142// Read-only forecast for held surface-process forcing. Adjacent records
143// with the same converted rate are one interval; gaps still end rainfall.
144// Unlike the legacy runoff clock this uses the exact interval start.
155double gageNextRateChange(const SimulationContext& ctx, int gage_idx, double date, double limit);
156
163double gageUnitsFactor(const SimulationContext& ctx, int gage_idx);
164
171int gageSeriesRainType(const SimulationContext& ctx, int gage_idx);
172
186double convertGageValue(double raw, int rain_type, double interval_sec, double& cumul_accum,
187 double units_factor, double scale_factor);
188
193 double rainfall = 0.0;
194 double snowfall = 0.0;
195};
196
207PrecipSplit splitPrecip(const SimulationContext& ctx, std::size_t sub);
208
217void updatePastRain(GageState& state, int time_step);
218
225void updatePastRain(SimulationContext& ctx, int time_step);
226
232double getPastRain(const GageState& state, int hours);
233
246void updateAllGages(SimulationContext& ctx, double current_time);
247
256double getReportRainfall(const SimulationContext& ctx, int gage_idx, double report_date);
257
267double getReportRainfallFromSeries(const SimulationContext& ctx, int gage_idx, double report_date);
268
269} // namespace gage
270} // namespace openswmm
271
272#endif // OPENSWMM_GAGE_HPP
Structure-of-Arrays (SoA) storage for subcatchments.
Rain records, accepted runoff-clock state and read-only report lookups. Context routines require alig...
Definition Gage.cpp:38
constexpr double ONE_SECOND
One second in days.
Definition Gage.hpp:57
double getReportRainfall(const SimulationContext &ctx, int gage_idx, double report_date)
Query rainfall using the most recently advanced runoff-gage state.
Definition Gage.cpp:638
void updateAllGages(SimulationContext &ctx, double current_time)
Advance used gage record state and publish current effective rainfall.
Definition Gage.cpp:483
double getReportRainfallFromSeries(const SimulationContext &ctx, int gage_idx, double report_date)
Query report-time source records independently of a later runoff cursor.
Definition Gage.cpp:642
double getPastRain(const GageState &state, int hours)
Sum completed hourly depth buckets, excluding the current partial hour.
Definition Gage.cpp:168
void updatePastRain(GageState &state, int time_step)
Accumulate a standalone gage's held intensity into completed-hour history.
Definition Gage.cpp:154
double gageUnitsFactor(const SimulationContext &ctx, int gage_idx)
Return the source-storage-to-project rainfall depth multiplier.
Definition Gage.cpp:206
double convertGageValue(double raw, int rain_type, double interval_sec, double &cumul_accum, double units_factor, double scale_factor)
Transform one source record and apply units then scale factors.
Definition Gage.cpp:223
double gageNextRainDate(const SimulationContext &ctx, int gage_idx, double t)
Read the next runoff-clock rainfall boundary from cached gage state.
Definition Gage.cpp:434
double gageNextRateChange(const SimulationContext &ctx, int j, double date, double limit)
Forecast the end of the current held rain rate without changing source state.
Definition Gage.cpp:453
RainType
Definition Gage.hpp:64
@ INTENSITY
Definition Gage.hpp:64
@ VOLUME
Definition Gage.hpp:64
@ CUMULATIVE
Definition Gage.hpp:64
PrecipSplit splitPrecip(const SimulationContext &ctx, std::size_t sub)
Split a subcatchment's current gage intensity into internal rain and snow.
Definition Gage.cpp:69
int gageSeriesRainType(const SimulationContext &ctx, int gage_idx)
Select the transform appropriate to resolved source storage.
Definition Gage.cpp:198
const Table * gageRainSeries(const SimulationContext &ctx, int gage_idx)
Borrow the actual resolved source table for a gage.
Definition Gage.cpp:182
constexpr int MAXPASTRAIN
Max past hours tracked.
Definition Gage.hpp:58
double convertRainfall(double raw_value, GageState &state)
Transform one raw rain record with standalone GageState factors.
Definition Gage.cpp:40
bool gageIsUsed(const SimulationContext &ctx, int gage_idx)
Test whether the model or enabled rainfall mesh consumes a gage.
Definition Gage.cpp:244
Definition ExchangeLaw.hpp:60
Central, reentrant simulation context.
Definition SimulationContext.hpp:390
Definition TableData.hpp:154
Definition Gage.hpp:70
double rain_interval
Rain recording interval (seconds)
Definition Gage.hpp:80
double past_rain_interval
Seconds in the current partial hour (0..3600)
Definition Gage.hpp:85
double rainfall
Current intensity (project in/hr or mm/hr)
Definition Gage.hpp:71
double past_rain_accum
Accumulator for current hour.
Definition Gage.hpp:84
double scale_factor
Rainfall scaling factor (1.0 = no scaling)
Definition Gage.hpp:77
double snow_factor
Snow catch factor.
Definition Gage.hpp:76
double adjust_factor
Monthly/seasonal adjustment factor.
Definition Gage.hpp:79
double past_rain[MAXPASTRAIN]
Past hourly rainfall totals.
Definition Gage.hpp:83
double total_precip
rainfall + snowfall
Definition Gage.hpp:73
RainType rain_type
Definition Gage.hpp:81
double snowfall
Current snow intensity (project in/hr or mm/hr)
Definition Gage.hpp:72
double api_rainfall
API-overridden rainfall (-1 = no override)
Definition Gage.hpp:75
double rain_accum
Cumulative rain accumulator (for CUMULATIVE type)
Definition Gage.hpp:74
double units_factor
Unit conversion factor.
Definition Gage.hpp:78
Result of splitting a gage's precipitation for one subcatchment.
Definition Gage.hpp:192
double snowfall
Snowfall (ft/sec, internal units)
Definition Gage.hpp:194
double rainfall
Rainfall (ft/sec, internal units)
Definition Gage.hpp:193