OpenSWMM Engine  6.0.0-alpha.3
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.3)
Loading...
Searching...
No Matches
Climate.hpp
Go to the documentation of this file.
1
19
20#ifndef OPENSWMM_CLIMATE_HPP
21#define OPENSWMM_CLIMATE_HPP
22
23namespace openswmm {
24
26
27namespace climate {
28
29// ============================================================================
30// Constants
31// ============================================================================
32
33constexpr double MM_PER_INCH = 25.40;
34
35// ============================================================================
36// Evaporation method
37// ============================================================================
38
39enum class EvapMethod : int {
44 PAN = 4
45};
46
47// ============================================================================
48// 7-day temperature moving average (for Hargreaves ET)
49// ============================================================================
50
51struct MovingAvg7 {
52 double ta[7] = {};
53 double tr[7] = {};
54 int front = 0;
55 int count = 0;
56
58 void push(double t_avg, double t_range);
59
61 double avg_temp() const;
62
64 double avg_range() const;
65};
66
67// ============================================================================
68// Daily climate state (scalar — broadcast to all subcatchments)
69// ============================================================================
70
72 double temperature = 70.0;
73 double temp_range = 0.0;
74 double evap_rate = 0.0;
75 double wind_speed = 0.0;
76 double humidity = 50.0;
77
78 // Source/default bases (pre-forcing). The per-step source lookup writes
79 // these; forcing then resolves effective values on top. Keeping them
80 // separate lets a one-shot/cleared forcing revert to the data source (or
81 // default) even when no source overwrites the value each step.
82 double temperature_src = 70.0;
83 double wind_speed_src = 0.0;
84
85 // Derived values
86 double gamma = 0.0;
87 double ea = 0.0;
88
89 // Hargreaves parameters
90 double latitude = 0.0;
91
92 // Site elevation for psychrometric constant (matching legacy Temp.elev)
93 double elev = 0.0;
94
95 // Monthly evaporation table (for MONTHLY method)
96 double monthly_evap[12] = {};
97
98 // EVAPRATE unit-conversion factor (in/day US or mm/day SI → ft/sec) for the
99 // project's unit system. Set at init; MONTHLY uses it so SI models convert
100 // mm/day correctly (defaults to the US factor for back-compatibility).
101 double evaprate_ucf = 1036800.0;
102
103 // Monthly adjustment factors
104 double adjust_evap[12] = {1,1,1,1,1,1,1,1,1,1,1,1};
105 double adjust_temp[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
106 double adjust_rain[12] = {1,1,1,1,1,1,1,1,1,1,1,1};
107 double adjust_hydcon[12] = {1,1,1,1,1,1,1,1,1,1,1,1};
108
110
111 // Monthly adjustment for infiltration capacity (scales f0/fmin/Ks)
112 // @see Legacy: InfilFactor (set from hydcon adjustment pattern)
113 double infil_factor = 1.0;
114
115 // 7-day moving average for Hargreaves ET (matching legacy TMovAve Tma)
117
118 // Recovery factor for infiltration models
119 // @see Legacy: Evap.recoveryFactor (set from recovery adjustment pattern)
120 double recovery_factor = 1.0;
121
122 // Resolved timeseries/pattern indices (set at init, -1 = none)
123 int temp_ts_index = -1;
124 int evap_ts_index = -1;
126
127 // Sub-daily sinusoidal temperature interpolation (Gap #9)
128 // Valid only when temperature comes from a daily min/max source.
129 // @see Legacy: setTemp() / updateTempTimes() in climate.c
130 double tmin_daily = 0.0;
131 double tmax_daily = 0.0;
132 double prev_tmax = 0.0;
133 double hrsr = 6.0;
134 double hrss = 15.0;
135 double hrday = 10.5;
136 double dhrdy = -9.0;
137 double dydif = 15.0;
138 double dtlong = 0.0;
139 bool has_minmax = false;
140 int last_temp_doy = -1;
141};
142
143// ============================================================================
144// Functions
145// ============================================================================
146
156double hargreaves(double latitude, int day_of_year, double t_avg, double t_range);
157
165void updateDailyClimate(ClimateState& state, int day_of_year, int month);
166
177void updateTempTimes(ClimateState& state, int doy);
178
195double getSubdailyTemp(const ClimateState& state, double hour);
196
209void batchDistributeEvap(double evap_rate, const double* ponded_depth,
210 double* evap_out, int n, double dt);
211
212} // namespace climate
213} // namespace openswmm
214
215#endif // OPENSWMM_CLIMATE_HPP
Definition Climate.cpp:18
double getSubdailyTemp(const ClimateState &state, double hour)
Compute sub-daily temperature using a three-zone sinusoidal model.
Definition Climate.cpp:193
void updateDailyClimate(ClimateState &state, int day_of_year, int month)
Update daily climate state.
Definition Climate.cpp:89
constexpr double MM_PER_INCH
Definition Climate.hpp:33
EvapMethod
Definition Climate.hpp:39
@ TIMESERIES
Definition Climate.hpp:42
@ CONSTANT
Definition Climate.hpp:40
@ TEMPERATURE
Hargreaves method.
Definition Climate.hpp:43
@ MONTHLY
Definition Climate.hpp:41
@ PAN
Definition Climate.hpp:44
void updateTempTimes(ClimateState &state, int doy)
Update sunrise/sunset parameters for sub-daily temperature interpolation.
Definition Climate.cpp:162
void batchDistributeEvap(double evap_rate, const double *ponded_depth, double *evap_out, int n, double dt)
Batch distribute evaporation to all subcatchments.
Definition Climate.cpp:148
double hargreaves(double latitude, int day_of_year, double t_avg, double t_range)
Compute Hargreaves evapotranspiration.
Definition Climate.cpp:51
Definition NodeCoupling.cpp:15
Central, reentrant simulation context.
Definition SimulationContext.hpp:292
Definition Climate.hpp:71
double ea
Saturation vapor pressure.
Definition Climate.hpp:87
double latitude
Latitude (degrees)
Definition Climate.hpp:90
double adjust_hydcon[12]
Infiltration conductivity multipliers.
Definition Climate.hpp:107
int temp_ts_index
Temperature timeseries table index.
Definition Climate.hpp:123
MovingAvg7 temp_ma
Definition Climate.hpp:116
bool has_minmax
True when tmin_daily/tmax_daily are valid.
Definition Climate.hpp:139
double recovery_factor
Definition Climate.hpp:120
double wind_speed_src
Source/default wind speed (mph)
Definition Climate.hpp:83
double infil_factor
Definition Climate.hpp:113
double evaprate_ucf
Definition Climate.hpp:101
double hrsr
Sunrise hour (time of min temp), 0-24.
Definition Climate.hpp:133
double dydif
24 + hrsr - hrss (hours from max to next min)
Definition Climate.hpp:137
double adjust_evap[12]
Definition Climate.hpp:104
double dtlong
Longitude correction (hrs); 0 = solar time.
Definition Climate.hpp:138
double elev
Site elevation above sea level (ft)
Definition Climate.hpp:93
EvapMethod evap_method
Definition Climate.hpp:109
double hrss
Sunset-3 hour (time of max temp), 0-24.
Definition Climate.hpp:134
double temperature_src
Source/default air temperature (deg F)
Definition Climate.hpp:82
double tmax_daily
Current day's maximum temperature (deg F)
Definition Climate.hpp:131
double hrday
Mid-hour between hrsr and hrss.
Definition Climate.hpp:135
double monthly_evap[12]
Definition Climate.hpp:96
int recovery_pat_index
Recovery pattern index in ctx.patterns.
Definition Climate.hpp:125
double humidity
Relative humidity (%)
Definition Climate.hpp:76
double wind_speed
Wind speed (mph) — effective (post-forcing)
Definition Climate.hpp:75
int last_temp_doy
Day-of-year when hrsr/hrss were last computed.
Definition Climate.hpp:140
double temp_range
Daily temperature range (deg F)
Definition Climate.hpp:73
double dhrdy
hrsr - hrss (negative)
Definition Climate.hpp:136
double gamma
Psychrometric constant.
Definition Climate.hpp:86
double prev_tmax
Previous day's maximum temperature (deg F)
Definition Climate.hpp:132
double adjust_temp[12]
Definition Climate.hpp:105
double evap_rate
Evaporation rate (ft/sec)
Definition Climate.hpp:74
double adjust_rain[12]
Definition Climate.hpp:106
double temperature
Air temperature (deg F) — effective (post-forcing)
Definition Climate.hpp:72
int evap_ts_index
Evaporation timeseries table index.
Definition Climate.hpp:124
double tmin_daily
Current day's minimum temperature (deg F)
Definition Climate.hpp:130
Definition Climate.hpp:51
void push(double t_avg, double t_range)
Push a new day's values into the buffer.
Definition Climate.cpp:26
double tr[7]
Daily temp ranges (deg F)
Definition Climate.hpp:53
double avg_range() const
Current moving average of temperature range.
Definition Climate.cpp:40
int count
Number of values stored (max 7)
Definition Climate.hpp:55
int front
Circular buffer write index.
Definition Climate.hpp:54
double ta[7]
Daily average temps (deg F)
Definition Climate.hpp:52
double avg_temp() const
Current moving average of temperature.
Definition Climate.cpp:33