OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
Climate.hpp
Go to the documentation of this file.
1
20#ifndef OPENSWMM_CLIMATE_HPP
21#define OPENSWMM_CLIMATE_HPP
22
23namespace openswmm {
24
25struct SimulationContext;
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 {
40 CONSTANT = 0,
41 MONTHLY = 1,
42 TIMESERIES = 2,
43 TEMPERATURE = 3,
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 // Derived values
79 double gamma = 0.0;
80 double ea = 0.0;
81
82 // Hargreaves parameters
83 double latitude = 0.0;
84
85 // Site elevation for psychrometric constant (matching legacy Temp.elev)
86 double elev = 0.0;
87
88 // Monthly evaporation table (for MONTHLY method)
89 double monthly_evap[12] = {};
90
91 // Monthly adjustment factors
92 double adjust_evap[12] = {1,1,1,1,1,1,1,1,1,1,1,1};
93 double adjust_temp[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
94 double adjust_rain[12] = {1,1,1,1,1,1,1,1,1,1,1,1};
95 double adjust_hydcon[12] = {1,1,1,1,1,1,1,1,1,1,1,1};
96
98
99 // Monthly adjustment for infiltration capacity (scales f0/fmin/Ks)
100 // @see Legacy: InfilFactor (set from hydcon adjustment pattern)
101 double infil_factor = 1.0;
102
103 // 7-day moving average for Hargreaves ET (matching legacy TMovAve Tma)
105
106 // Recovery factor for infiltration models
107 // @see Legacy: Evap.recoveryFactor (set from recovery adjustment pattern)
108 double recovery_factor = 1.0;
109
110 // Resolved timeseries/pattern indices (set at init, -1 = none)
111 int temp_ts_index = -1;
112 int evap_ts_index = -1;
114
115 // Sub-daily sinusoidal temperature interpolation (Gap #9)
116 // Valid only when temperature comes from a daily min/max source.
117 // @see Legacy: setTemp() / updateTempTimes() in climate.c
118 double tmin_daily = 0.0;
119 double tmax_daily = 0.0;
120 double prev_tmax = 0.0;
121 double hrsr = 6.0;
122 double hrss = 15.0;
123 double hrday = 10.5;
124 double dhrdy = -9.0;
125 double dydif = 15.0;
126 double dtlong = 0.0;
127 bool has_minmax = false;
128 int last_temp_doy = -1;
129};
130
131// ============================================================================
132// Functions
133// ============================================================================
134
144double hargreaves(double latitude, int day_of_year, double t_avg, double t_range);
145
153void updateDailyClimate(ClimateState& state, int day_of_year, int month);
154
165void updateTempTimes(ClimateState& state, int doy);
166
183double getSubdailyTemp(const ClimateState& state, double hour);
184
197void batchDistributeEvap(double evap_rate, const double* ponded_depth,
198 double* evap_out, int n, double dt);
199
200} // namespace climate
201} // namespace openswmm
202
203#endif // OPENSWMM_CLIMATE_HPP
double getSubdailyTemp(const ClimateState &state, double hour)
Compute sub-daily temperature using a three-zone sinusoidal model.
Definition Climate.cpp:191
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
@ TEMPERATURE
Hargreaves method.
void updateTempTimes(ClimateState &state, int doy)
Update sunrise/sunset parameters for sub-daily temperature interpolation.
Definition Climate.cpp:160
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:146
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
Definition Climate.hpp:71
double ea
Saturation vapor pressure.
Definition Climate.hpp:80
double latitude
Latitude (degrees)
Definition Climate.hpp:83
double adjust_hydcon[12]
Infiltration conductivity multipliers.
Definition Climate.hpp:95
int temp_ts_index
Temperature timeseries table index.
Definition Climate.hpp:111
MovingAvg7 temp_ma
Definition Climate.hpp:104
bool has_minmax
True when tmin_daily/tmax_daily are valid.
Definition Climate.hpp:127
double recovery_factor
Definition Climate.hpp:108
double infil_factor
Definition Climate.hpp:101
double hrsr
Sunrise hour (time of min temp), 0-24.
Definition Climate.hpp:121
double dydif
24 + hrsr - hrss (hours from max to next min)
Definition Climate.hpp:125
double adjust_evap[12]
Definition Climate.hpp:92
double dtlong
Longitude correction (hrs); 0 = solar time.
Definition Climate.hpp:126
double elev
Site elevation above sea level (ft)
Definition Climate.hpp:86
EvapMethod evap_method
Definition Climate.hpp:97
double hrss
Sunset-3 hour (time of max temp), 0-24.
Definition Climate.hpp:122
double tmax_daily
Current day's maximum temperature (deg F)
Definition Climate.hpp:119
double hrday
Mid-hour between hrsr and hrss.
Definition Climate.hpp:123
double monthly_evap[12]
Definition Climate.hpp:89
int recovery_pat_index
Recovery pattern index in ctx.patterns.
Definition Climate.hpp:113
double humidity
Relative humidity (%)
Definition Climate.hpp:76
double wind_speed
Wind speed (mph)
Definition Climate.hpp:75
int last_temp_doy
Day-of-year when hrsr/hrss were last computed.
Definition Climate.hpp:128
double temp_range
Daily temperature range (deg F)
Definition Climate.hpp:73
double dhrdy
hrsr - hrss (negative)
Definition Climate.hpp:124
double gamma
Psychrometric constant.
Definition Climate.hpp:79
double prev_tmax
Previous day's maximum temperature (deg F)
Definition Climate.hpp:120
double adjust_temp[12]
Definition Climate.hpp:93
double evap_rate
Evaporation rate (ft/sec)
Definition Climate.hpp:74
double adjust_rain[12]
Definition Climate.hpp:94
double temperature
Air temperature (deg F)
Definition Climate.hpp:72
int evap_ts_index
Evaporation timeseries table index.
Definition Climate.hpp:112
double tmin_daily
Current day's minimum temperature (deg F)
Definition Climate.hpp:118
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