OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
SubcatchData.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_ENGINE_SUBCATCH_DATA_HPP
35#define OPENSWMM_ENGINE_SUBCATCH_DATA_HPP
36
37#include <vector>
38#include <string>
39#include <cstdint>
40#include <algorithm>
41#include <limits>
42
43namespace openswmm {
44
45// ============================================================================
46// SubcatchData — SoA layout
47// ============================================================================
48
58
59 // -----------------------------------------------------------------------
60 // Static properties — set at parse time
61 // -----------------------------------------------------------------------
62
69 std::vector<int> outlet_node;
70
75 std::vector<int> outlet_subcatch;
76
82 std::vector<std::string> outlet_name;
83
91 std::vector<std::string> snowpack_name;
92
100 std::vector<std::string> gage_name;
101
106 std::vector<int> gage;
107
112 std::vector<double> area;
113
118 std::vector<double> width;
119
124 std::vector<double> slope;
125
130 std::vector<double> curb_length;
131
142 std::vector<double> rain_scale_factor;
143
156 std::vector<double> snow_scale_factor;
157
162 std::vector<double> frac_imperv;
163
168 std::vector<double> frac_imperv_no_store;
169
183 std::vector<double> pct_zero;
184
189 std::vector<double> n_imperv;
190
195 std::vector<double> n_perv;
196
201 std::vector<double> ds_imperv;
202
207 std::vector<double> ds_perv;
208
209 // -----------------------------------------------------------------------
210 // Inter-subarea routing (from [SUBAREAS] section)
211 // -----------------------------------------------------------------------
212
220 std::vector<int> subarea_routing;
221
228 std::vector<double> pct_routed;
229
230 // -----------------------------------------------------------------------
231 // Infiltration parameters (per subcatchment)
232 // -----------------------------------------------------------------------
233
235 std::vector<int> infil_model;
236
238 std::vector<double> infil_p1;
240 std::vector<double> infil_p2;
242 std::vector<double> infil_p3;
244 std::vector<double> infil_p4;
246 std::vector<double> infil_p5;
247
248 // -----------------------------------------------------------------------
249 // State variables — updated each timestep
250 // -----------------------------------------------------------------------
251
256 std::vector<double> runoff;
257
262 std::vector<double> rainfall;
263
268 std::vector<double> evap_loss;
269
274 std::vector<double> infil_loss;
275
280 std::vector<double> ponded_depth;
281
291 std::vector<double> old_ponded_depth;
292
302 std::vector<double> washoff_vout1;
303
308 std::vector<double> gw_flow;
309
314 std::vector<double> snow_depth;
315
320 std::vector<double> lid_drain_flow;
321
322 // -----------------------------------------------------------------------
323 // Previous-step state
324 // -----------------------------------------------------------------------
325
327 std::vector<double> old_runoff;
328
330 std::vector<double> old_gw_flow;
331
333 std::vector<double> old_snow_depth;
334
336 std::vector<double> old_lid_drain_flow;
337
338 // -----------------------------------------------------------------------
339 // Runon coupling — subcatch-to-subcatch routing
340 // -----------------------------------------------------------------------
341
344 std::vector<double> runon_inflow;
345
347 std::vector<double> old_runon_inflow;
348
355 std::vector<double> runon_rate;
356
360 std::vector<double> outfall_runon_vol;
361
362 // -----------------------------------------------------------------------
363 // Groundwater surface water head coupling
364 // -----------------------------------------------------------------------
365
368 std::vector<double> gw_sw_head;
369
371 std::vector<double> gw_node_avail_flow;
372
379 std::vector<double> gw_max_infil_vol;
380
381 // -----------------------------------------------------------------------
382 // Quality washoff output
383 // -----------------------------------------------------------------------
384
387 std::vector<double> washoff_load;
388
389 // -----------------------------------------------------------------------
390 // Per-subcatch quality state — flat 2D: [subcatch * n_pollutants + pollutant]
391 // -----------------------------------------------------------------------
392
398 std::vector<double> conc;
399
401 std::vector<double> conc_old;
402
409 std::vector<double> ponded_qual;
410
421 std::vector<double> runon_qual_rate;
426 std::vector<double> lid_drain_runon_qual;
427
438 std::vector<double> subarea_runoff_rate;
439
452 std::vector<double> init_loading;
453
456
457 // -----------------------------------------------------------------------
458 // Per-object INP comment
459 // -----------------------------------------------------------------------
460
466 std::vector<std::string> comments;
467
474 std::vector<std::string> tags;
475
476 // -----------------------------------------------------------------------
477 // Report flag — per-object output filter
478 // -----------------------------------------------------------------------
479
482 std::vector<char> rpt_flag;
483
484 // -----------------------------------------------------------------------
485 // Cumulative statistics
486 // -----------------------------------------------------------------------
487
492 std::vector<double> stat_precip_vol;
493 std::vector<double> stat_runon_vol;
494 std::vector<double> stat_gw_time;
495 std::vector<double> stat_evap_vol;
496 std::vector<double> stat_infil_vol;
497 std::vector<double> stat_imperv_vol;
498 std::vector<double> stat_perv_vol;
499
504 std::vector<double> stat_runoff_vol;
505
510 std::vector<double> stat_max_runoff;
511
512 // Gap #63: Per-subcatch groundwater statistics (accumulated each GW step)
513 std::vector<double> stat_gw_infil_vol;
514 std::vector<double> stat_gw_upper_evap_vol;
515 std::vector<double> stat_gw_lower_evap_vol;
516 std::vector<double> stat_gw_deep_perc_vol;
517 std::vector<double> stat_gw_flow_vol;
518 std::vector<double> stat_gw_max_flow;
519 std::vector<double> stat_gw_sum_theta;
520 std::vector<double> stat_gw_sum_depth;
521 std::vector<double> stat_gw_final_theta;
522 std::vector<double> stat_gw_final_depth;
523 std::vector<long> stat_gw_steps;
524
525 // -----------------------------------------------------------------------
526 // Groundwater parameters (from [GROUNDWATER] section)
527 // -----------------------------------------------------------------------
528
530 std::vector<int> gw_aquifer;
531
533 std::vector<int> gw_node;
534
536 std::vector<double> gw_surf_elev;
537
539 std::vector<double> gw_a1;
540
542 std::vector<double> gw_b1;
543
545 std::vector<double> gw_a2;
546
548 std::vector<double> gw_b2;
549
551 std::vector<double> gw_a3;
552
554 std::vector<double> gw_tw;
555
562 std::vector<double> gw_hstar;
563
565 std::vector<double> gw_bot_elev;
566
568 std::vector<double> gw_wt_elev;
569
571 std::vector<double> gw_upper_moist;
572
573 // -----------------------------------------------------------------------
574 // Snowpack assignment (index into SnowpackStore, -1 = none)
575 // -----------------------------------------------------------------------
576
578 std::vector<int> snowpack;
579
587 std::vector<double> snow_net_imperv;
588
596 std::vector<double> snow_net_perv;
597
617 std::vector<double> snow_melt_imperv;
618
620 std::vector<double> snow_melt_perv;
621
635 std::vector<double> snow_melt_age_imperv;
636
638 std::vector<double> snow_melt_age_perv;
639
647 std::vector<double> total_lid_area_ft2;
648
656 std::vector<double> lid_return_to_perv_cfs;
657
666 std::vector<double> lid_drain_runon_cfs;
667
668 // -----------------------------------------------------------------------
669 // Cumulative pollutant washoff loads — flat 2D: [subcatch * n_pollutants + pollutant]
670 // -----------------------------------------------------------------------
671
676 std::vector<double> total_load;
677
680
691 void resize_total_load(int n_sc, int n_poll) {
693 total_load.assign(static_cast<std::size_t>(n_sc) * static_cast<std::size_t>(n_poll), 0.0);
694 }
695
696 // -----------------------------------------------------------------------
697 // Land-use coverage — flat 2D: [subcatch * n_landuses + landuse]
698 // -----------------------------------------------------------------------
699
704 std::vector<double> coverage;
705
708
714 std::vector<double> sweep_last_swept;
718 std::vector<unsigned char> sweep_now;
723 std::vector<double> sweep_last_date;
724
730 void resize_coverage(int n_sc, int n_lu) {
731 coverage_n_landuses = n_lu;
732 auto sz = static_cast<std::size_t>(n_sc) * static_cast<std::size_t>(n_lu);
733 coverage.assign(sz, 0.0);
734 sweep_last_swept.assign(sz, 0.0);
735 }
736
737 // -----------------------------------------------------------------------
738 // Capacity management
739 // -----------------------------------------------------------------------
740
746 int count() const noexcept { return static_cast<int>(area.size()); }
747
760 void resize(int n) {
761 const auto un = static_cast<std::size_t>(n);
762
763 outlet_node.assign(un, -1);
764 outlet_subcatch.assign(un, -1);
765 outlet_name.resize(un);
766 snowpack_name.resize(un);
767 gage_name.resize(un);
768 gage.assign(un, -1);
769 area.assign(un, 0.0);
770 width.assign(un, 0.0);
771 slope.assign(un, 0.0);
772 curb_length.assign(un, 0.0);
773 rain_scale_factor.assign(un, 1.0);
774 snow_scale_factor.assign(un, 1.0);
775 frac_imperv.assign(un, 0.0);
776 frac_imperv_no_store.assign(un, 0.0);
777 pct_zero.assign(un, 0.0);
778 subarea_runoff_rate.assign(un, 0.0);
779 n_imperv.assign(un, 0.013);
780 n_perv.assign(un, 0.1);
781 ds_imperv.assign(un, 0.0);
782 ds_perv.assign(un, 0.0);
783 subarea_routing.assign(un, 0); // TO_OUTLET
784 pct_routed.assign(un, 0.0);
785
786 infil_model.assign(un, 0);
787 infil_p1.assign(un, 0.0);
788 infil_p2.assign(un, 0.0);
789 infil_p3.assign(un, 0.0);
790 infil_p4.assign(un, 0.0);
791 infil_p5.assign(un, 0.0);
792
793 runoff.assign(un, 0.0);
794 rainfall.assign(un, 0.0);
795 evap_loss.assign(un, 0.0);
796 infil_loss.assign(un, 0.0);
797 ponded_depth.assign(un, 0.0);
798 old_ponded_depth.assign(un, 0.0);
799 washoff_vout1.assign(un, 0.0);
800 gw_flow.assign(un, 0.0);
801 snow_depth.assign(un, 0.0);
802 lid_drain_flow.assign(un, 0.0);
803 old_runoff.assign(un, 0.0);
804 old_gw_flow.assign(un, 0.0);
805 old_snow_depth.assign(un, 0.0);
806 old_lid_drain_flow.assign(un, 0.0);
807 runon_inflow.assign(un, 0.0);
808 old_runon_inflow.assign(un, 0.0);
809 runon_rate.assign(un, 0.0);
810 outfall_runon_vol.assign(un, 0.0);
811 gw_sw_head.assign(un, 0.0);
812 gw_node_avail_flow.assign(un, 0.0);
813 gw_max_infil_vol.assign(un, std::numeric_limits<double>::max());
814
815 comments.assign(un, std::string{});
816 tags.assign(un, std::string{});
817
818 rpt_flag.assign(un, 0);
819
820 stat_precip_vol.assign(un, 0.0);
821 stat_gw_time.assign(un, 0.0);
822 stat_runon_vol.assign(un, 0.0);
823 stat_evap_vol.assign(un, 0.0);
824 stat_infil_vol.assign(un, 0.0);
825 stat_imperv_vol.assign(un, 0.0);
826 stat_perv_vol.assign(un, 0.0);
827 stat_runoff_vol.assign(un, 0.0);
828 stat_max_runoff.assign(un, 0.0);
829 stat_gw_infil_vol.assign(un, 0.0);
830 stat_gw_upper_evap_vol.assign(un, 0.0);
831 stat_gw_lower_evap_vol.assign(un, 0.0);
832 stat_gw_deep_perc_vol.assign(un, 0.0);
833 stat_gw_flow_vol.assign(un, 0.0);
834 stat_gw_max_flow.assign(un, 0.0);
835 stat_gw_sum_theta.assign(un, 0.0);
836 stat_gw_sum_depth.assign(un, 0.0);
837 stat_gw_final_theta.assign(un, 0.0);
838 stat_gw_final_depth.assign(un, 0.0);
839 stat_gw_steps.assign(un, 0L);
840
841 gw_aquifer.assign(un, -1);
842 gw_node.assign(un, -1);
843 gw_surf_elev.assign(un, 0.0);
844 gw_a1.assign(un, 0.0);
845 gw_b1.assign(un, 0.0);
846 gw_a2.assign(un, 0.0);
847 gw_b2.assign(un, 0.0);
848 gw_a3.assign(un, 0.0);
849 gw_tw.assign(un, 0.0);
850 gw_hstar.assign(un, -1.0e10); // constants::MISSING
851 gw_bot_elev.assign(un, -1.0e10);
852 gw_wt_elev.assign(un, -1.0e10);
853 gw_upper_moist.assign(un, -1.0e10);
854 snowpack.assign(un, -1);
855 snow_net_imperv.assign(un, -1.0);
856 snow_net_perv.assign(un, -1.0);
857 snow_melt_imperv.assign(un, -1.0);
858 snow_melt_perv.assign(un, -1.0);
859 snow_melt_age_imperv.assign(un, -1.0);
860 snow_melt_age_perv.assign(un, -1.0);
861 total_lid_area_ft2.assign(un, 0.0);
862 lid_return_to_perv_cfs.assign(un, 0.0);
863 lid_drain_runon_cfs.assign(un, 0.0);
864 }
865
875 void grow_to(int n) {
876 if (n <= count())
877 return;
878 const auto un = static_cast<std::size_t>(n);
879 auto g = [&](auto& vec, auto def) { vec.resize(un, def); };
880 g(outlet_node, -1);
881 g(outlet_subcatch, -1);
882 outlet_name.resize(un);
883 snowpack_name.resize(un);
884 gage_name.resize(un);
885 g(gage, -1);
886 g(area, 0.0);
887 g(width, 0.0);
888 g(slope, 0.0);
889 g(curb_length, 0.0);
890 g(rain_scale_factor, 1.0);
891 g(snow_scale_factor, 1.0);
892 g(frac_imperv, 0.0);
893 g(frac_imperv_no_store, 0.0);
894 g(pct_zero, 0.0);
895 g(subarea_runoff_rate, 0.0);
896 g(n_imperv, 0.013);
897 g(n_perv, 0.1);
898 g(ds_imperv, 0.0);
899 g(ds_perv, 0.0);
900 g(subarea_routing, 0);
901 g(pct_routed, 0.0);
902 g(infil_model, 0);
903 g(infil_p1, 0.0);
904 g(infil_p2, 0.0);
905 g(infil_p3, 0.0);
906 g(infil_p4, 0.0);
907 g(infil_p5, 0.0);
908 g(runoff, 0.0);
909 g(rainfall, 0.0);
910 g(evap_loss, 0.0);
911 g(infil_loss, 0.0);
912 g(ponded_depth, 0.0);
913 g(old_ponded_depth, 0.0);
914 g(washoff_vout1, 0.0);
915 g(gw_flow, 0.0);
916 g(snow_depth, 0.0);
917 g(lid_drain_flow, 0.0);
918 g(old_runoff, 0.0);
919 g(old_gw_flow, 0.0);
920 g(old_snow_depth, 0.0);
921 g(old_lid_drain_flow, 0.0);
922 g(runon_inflow, 0.0);
923 g(old_runon_inflow, 0.0);
924 g(runon_rate, 0.0);
925 g(gw_sw_head, 0.0);
926 g(gw_node_avail_flow, 0.0);
927 g(gw_max_infil_vol, std::numeric_limits<double>::max());
928 g(outfall_runon_vol, 0.0);
929 comments.resize(un, std::string{});
930 tags.resize(un, std::string{});
931
932 g(rpt_flag, static_cast<char>(0));
933 g(stat_precip_vol, 0.0);
934 g(stat_gw_time, 0.0);
935 g(stat_runon_vol, 0.0);
936 g(stat_evap_vol, 0.0);
937 g(stat_infil_vol, 0.0);
938 g(stat_imperv_vol, 0.0);
939 g(stat_perv_vol, 0.0);
940 g(stat_runoff_vol, 0.0);
941 g(stat_max_runoff, 0.0);
942 g(stat_gw_infil_vol, 0.0);
945 g(stat_gw_deep_perc_vol, 0.0);
946 g(stat_gw_flow_vol, 0.0);
947 g(stat_gw_max_flow, 0.0);
948 g(stat_gw_sum_theta, 0.0);
949 g(stat_gw_sum_depth, 0.0);
950 g(stat_gw_final_theta, 0.0);
951 g(stat_gw_final_depth, 0.0);
952 stat_gw_steps.resize(un, 0L);
953 g(gw_aquifer, -1);
954 g(gw_node, -1);
955 g(gw_surf_elev, 0.0);
956 g(gw_a1, 0.0);
957 g(gw_b1, 0.0);
958 g(gw_a2, 0.0);
959 g(gw_b2, 0.0);
960 g(gw_a3, 0.0);
961 g(gw_tw, 0.0);
962 g(gw_hstar, -1.0e10);
963 g(gw_bot_elev, -1.0e10);
964 g(gw_wt_elev, -1.0e10);
965 g(gw_upper_moist, -1.0e10);
966 g(snowpack, -1);
967 g(snow_net_imperv, -1.0);
968 g(snow_net_perv, -1.0);
969 g(snow_melt_imperv, -1.0);
970 g(snow_melt_perv, -1.0);
971 g(snow_melt_age_imperv, -1.0);
972 g(snow_melt_age_perv, -1.0);
973 g(total_lid_area_ft2, 0.0);
975 g(lid_drain_runon_cfs, 0.0);
976 // Note: conc, conc_old, ponded_qual, washoff_load handled by resize_quality()
977 // Note: coverage, total_load handled separately
978 }
979
1001 void reserve_to(int n) {
1002 if (n <= 0)
1003 return;
1004 const auto un = static_cast<std::size_t>(n);
1005 if (outlet_node.capacity() >= un)
1006 return;
1007 auto r = [&](auto& vec) { vec.reserve(un); };
1008 r(outlet_node);
1009 r(outlet_subcatch);
1010 r(gage);
1011 r(area);
1012 r(width);
1013 r(slope);
1014 r(curb_length);
1017 r(frac_imperv);
1019 r(pct_zero);
1021 r(n_imperv);
1022 r(n_perv);
1023 r(ds_imperv);
1024 r(ds_perv);
1025 r(subarea_routing);
1026 r(pct_routed);
1027 r(infil_model);
1028 r(infil_p1);
1029 r(infil_p2);
1030 r(infil_p3);
1031 r(infil_p4);
1032 r(infil_p5);
1033 r(runoff);
1034 r(rainfall);
1035 r(evap_loss);
1036 r(infil_loss);
1037 r(ponded_depth);
1038 r(gw_flow);
1039 r(snow_depth);
1040 r(lid_drain_flow);
1041 r(old_runoff);
1042 r(old_gw_flow);
1043 r(old_snow_depth);
1045 r(runon_inflow);
1047 r(runon_rate);
1048 r(gw_sw_head);
1052 r(rpt_flag);
1053 r(stat_precip_vol);
1054 r(stat_gw_time);
1055 r(stat_runon_vol);
1056 r(stat_evap_vol);
1057 r(stat_infil_vol);
1058 r(stat_imperv_vol);
1059 r(stat_perv_vol);
1060 r(stat_runoff_vol);
1061 r(stat_max_runoff);
1072 r(gw_aquifer);
1073 r(gw_node);
1074 r(gw_surf_elev);
1075 r(gw_a1);
1076 r(gw_b1);
1077 r(gw_a2);
1078 r(gw_b2);
1079 r(gw_a3);
1080 r(gw_tw);
1081 r(gw_hstar);
1082 r(gw_bot_elev);
1083 r(gw_wt_elev);
1084 r(gw_upper_moist);
1085 r(snowpack);
1086 r(snow_net_imperv);
1087 r(snow_net_perv);
1089 r(snow_melt_perv);
1095 r(outlet_name);
1096 r(gage_name);
1097 r(comments);
1098 r(tags);
1099 r(stat_gw_steps);
1100 }
1101
1113 void erase_at(int idx) {
1114 const auto ui = static_cast<std::size_t>(idx);
1115 auto e = [&](auto& v) {
1116 if (ui < v.size())
1117 v.erase(v.begin() + static_cast<std::ptrdiff_t>(idx));
1118 };
1119
1120 e(outlet_node);
1121 e(outlet_subcatch);
1122 e(outlet_name);
1123 e(gage);
1124 e(area);
1125 e(width);
1126 e(slope);
1127 e(curb_length);
1130 e(frac_imperv);
1132 e(pct_zero);
1134 e(n_imperv);
1135 e(n_perv);
1136 e(ds_imperv);
1137 e(ds_perv);
1138 e(subarea_routing);
1139 e(pct_routed);
1140
1141 e(infil_model);
1142 e(infil_p1);
1143 e(infil_p2);
1144 e(infil_p3);
1145 e(infil_p4);
1146 e(infil_p5);
1147
1148 e(runoff);
1149 e(rainfall);
1150 e(evap_loss);
1151 e(infil_loss);
1152 e(ponded_depth);
1153 e(gw_flow);
1154 e(snow_depth);
1155 e(lid_drain_flow);
1156 e(old_runoff);
1157 e(old_gw_flow);
1158 e(old_snow_depth);
1160 e(runon_inflow);
1162 e(runon_rate);
1164 e(gw_sw_head);
1167 e(comments);
1168 e(tags);
1169 e(rpt_flag);
1170
1171 e(stat_precip_vol);
1172 e(stat_gw_time);
1173 e(stat_runon_vol);
1174 e(stat_evap_vol);
1175 e(stat_infil_vol);
1176 e(stat_imperv_vol);
1177 e(stat_perv_vol);
1178 e(stat_runoff_vol);
1179 e(stat_max_runoff);
1190 e(stat_gw_steps);
1191
1192 e(gw_aquifer);
1193 e(gw_node);
1194 e(gw_surf_elev);
1195 e(gw_a1);
1196 e(gw_b1);
1197 e(gw_a2);
1198 e(gw_b2);
1199 e(gw_a3);
1200 e(gw_tw);
1201 e(gw_hstar);
1202 e(gw_bot_elev);
1203 e(gw_wt_elev);
1204 e(gw_upper_moist);
1205 e(snowpack);
1206 e(snow_net_imperv);
1207 e(snow_net_perv);
1209 e(snow_melt_perv);
1215
1216 // Flat 2D quality arrays: [sc * np + p]
1217 if (conc_n_pollutants > 0) {
1218 const auto np = static_cast<std::size_t>(conc_n_pollutants);
1219 const auto base = ui * np;
1220 auto erase2d = [&](auto& v) {
1221 if (base + np <= v.size())
1222 v.erase(v.begin() + static_cast<std::ptrdiff_t>(base),
1223 v.begin() + static_cast<std::ptrdiff_t>(base + np));
1224 };
1225 erase2d(conc);
1226 erase2d(conc_old);
1227 erase2d(init_loading);
1228 erase2d(ponded_qual);
1229 erase2d(runon_qual_rate);
1230 erase2d(lid_drain_runon_qual);
1231 erase2d(washoff_load);
1232 }
1233
1234 // Flat 2D total load: [sc * np + p]
1235 if (total_load_n_pollutants > 0) {
1236 const auto np = static_cast<std::size_t>(total_load_n_pollutants);
1237 const auto base = ui * np;
1238 if (base + np <= total_load.size())
1239 total_load.erase(total_load.begin() + static_cast<std::ptrdiff_t>(base),
1240 total_load.begin() + static_cast<std::ptrdiff_t>(base + np));
1241 }
1242
1243 // Flat 2D coverage/sweep matrices: [sc * n_lu + lu]
1244 if (coverage_n_landuses > 0) {
1245 const auto nlu = static_cast<std::size_t>(coverage_n_landuses);
1246 const auto base = ui * nlu;
1247 auto erase2d = [&](auto& v) {
1248 if (base + nlu <= v.size())
1249 v.erase(v.begin() + static_cast<std::ptrdiff_t>(base),
1250 v.begin() + static_cast<std::ptrdiff_t>(base + nlu));
1251 };
1252 erase2d(coverage);
1253 erase2d(sweep_last_swept);
1254 }
1255 }
1256
1268 void resize_quality(int n_pollutants) {
1269 conc_n_pollutants = n_pollutants;
1270 if (n_pollutants > 0) {
1271 auto total = static_cast<std::size_t>(count()) * static_cast<std::size_t>(n_pollutants);
1272 conc.assign(total, 0.0);
1273 conc_old.assign(total, 0.0);
1274 init_loading.assign(total, 0.0);
1275 ponded_qual.assign(total, 0.0);
1276 runon_qual_rate.assign(total, 0.0);
1277 lid_drain_runon_qual.assign(total, 0.0);
1278 washoff_load.assign(total, 0.0);
1279 }
1280 }
1281
1290 void resize_washoff_load(int n_pollutants) {
1291 if (n_pollutants > 0) {
1292 washoff_load.assign(
1293 static_cast<std::size_t>(count()) * static_cast<std::size_t>(n_pollutants), 0.0);
1294 }
1295 }
1296
1301 outlet_node.shrink_to_fit();
1302 outlet_subcatch.shrink_to_fit();
1303 outlet_name.shrink_to_fit();
1304 gage.shrink_to_fit();
1305 area.shrink_to_fit();
1306 width.shrink_to_fit();
1307 slope.shrink_to_fit();
1308 curb_length.shrink_to_fit();
1309 rain_scale_factor.shrink_to_fit();
1310 snow_scale_factor.shrink_to_fit();
1311 frac_imperv.shrink_to_fit();
1312 frac_imperv_no_store.shrink_to_fit();
1313 pct_zero.shrink_to_fit();
1314 subarea_runoff_rate.shrink_to_fit();
1315 n_imperv.shrink_to_fit();
1316 n_perv.shrink_to_fit();
1317 ds_imperv.shrink_to_fit();
1318 ds_perv.shrink_to_fit();
1319 subarea_routing.shrink_to_fit();
1320 pct_routed.shrink_to_fit();
1321
1322 infil_model.shrink_to_fit();
1323 infil_p1.shrink_to_fit();
1324 infil_p2.shrink_to_fit();
1325 infil_p3.shrink_to_fit();
1326 infil_p4.shrink_to_fit();
1327 infil_p5.shrink_to_fit();
1328
1329 runoff.shrink_to_fit();
1330 rainfall.shrink_to_fit();
1331 evap_loss.shrink_to_fit();
1332 infil_loss.shrink_to_fit();
1333 ponded_depth.shrink_to_fit();
1334 gw_flow.shrink_to_fit();
1335 snow_depth.shrink_to_fit();
1336 lid_drain_flow.shrink_to_fit();
1337 old_runoff.shrink_to_fit();
1338 old_gw_flow.shrink_to_fit();
1339 old_snow_depth.shrink_to_fit();
1340 old_lid_drain_flow.shrink_to_fit();
1341 runon_inflow.shrink_to_fit();
1342 old_runon_inflow.shrink_to_fit();
1343 runon_rate.shrink_to_fit();
1344 outfall_runon_vol.shrink_to_fit();
1345 gw_sw_head.shrink_to_fit();
1346 gw_node_avail_flow.shrink_to_fit();
1347 gw_max_infil_vol.shrink_to_fit();
1348
1349 comments.shrink_to_fit();
1350 tags.shrink_to_fit();
1351
1352 rpt_flag.shrink_to_fit();
1353
1354 stat_precip_vol.shrink_to_fit();
1355 stat_gw_time.shrink_to_fit();
1356 stat_runon_vol.shrink_to_fit();
1357 stat_evap_vol.shrink_to_fit();
1358 stat_infil_vol.shrink_to_fit();
1359 stat_imperv_vol.shrink_to_fit();
1360 stat_perv_vol.shrink_to_fit();
1361 stat_runoff_vol.shrink_to_fit();
1362 stat_max_runoff.shrink_to_fit();
1363
1364 gw_aquifer.shrink_to_fit();
1365 gw_node.shrink_to_fit();
1366 gw_surf_elev.shrink_to_fit();
1367 gw_a1.shrink_to_fit();
1368 gw_b1.shrink_to_fit();
1369 gw_a2.shrink_to_fit();
1370 gw_b2.shrink_to_fit();
1371 gw_a3.shrink_to_fit();
1372 gw_tw.shrink_to_fit();
1373 gw_hstar.shrink_to_fit();
1374 gw_bot_elev.shrink_to_fit();
1375 gw_wt_elev.shrink_to_fit();
1376 gw_upper_moist.shrink_to_fit();
1377 snowpack.shrink_to_fit();
1378 snow_net_imperv.shrink_to_fit();
1379 snow_net_perv.shrink_to_fit();
1380 snow_melt_imperv.shrink_to_fit();
1381 snow_melt_perv.shrink_to_fit();
1382 snow_melt_age_imperv.shrink_to_fit();
1383 snow_melt_age_perv.shrink_to_fit();
1384
1385 conc.shrink_to_fit();
1386 conc_old.shrink_to_fit();
1387 ponded_qual.shrink_to_fit();
1388 runon_qual_rate.shrink_to_fit();
1389 lid_drain_runon_qual.shrink_to_fit();
1390 washoff_load.shrink_to_fit();
1391 total_load.shrink_to_fit();
1392 coverage.shrink_to_fit();
1393 sweep_last_swept.shrink_to_fit();
1394 }
1395
1403 void save_state() noexcept {
1404 std::copy(runoff.begin(), runoff.end(), old_runoff.begin());
1405 std::copy(runon_inflow.begin(), runon_inflow.end(), old_runon_inflow.begin());
1406 std::copy(conc.begin(), conc.end(), conc_old.begin());
1407 std::copy(ponded_depth.begin(), ponded_depth.end(), old_ponded_depth.begin());
1408 }
1409
1418 void reset_state() noexcept {
1419 std::fill(runoff.begin(), runoff.end(), 0.0);
1420 std::fill(rainfall.begin(), rainfall.end(), 0.0);
1421 std::fill(snow_net_imperv.begin(), snow_net_imperv.end(), -1.0);
1422 std::fill(snow_net_perv.begin(), snow_net_perv.end(), -1.0);
1423 std::fill(snow_melt_imperv.begin(), snow_melt_imperv.end(), -1.0);
1424 std::fill(snow_melt_perv.begin(), snow_melt_perv.end(), -1.0);
1425 std::fill(snow_melt_age_imperv.begin(), snow_melt_age_imperv.end(), -1.0);
1426 std::fill(snow_melt_age_perv.begin(), snow_melt_age_perv.end(), -1.0);
1427 std::fill(evap_loss.begin(), evap_loss.end(), 0.0);
1428 std::fill(infil_loss.begin(), infil_loss.end(), 0.0);
1429 std::fill(ponded_depth.begin(), ponded_depth.end(), 0.0);
1430 std::fill(old_runoff.begin(), old_runoff.end(), 0.0);
1431 std::fill(old_gw_flow.begin(), old_gw_flow.end(), 0.0);
1432 std::fill(snow_depth.begin(), snow_depth.end(), 0.0);
1433 std::fill(old_snow_depth.begin(), old_snow_depth.end(), 0.0);
1434 std::fill(lid_drain_flow.begin(), lid_drain_flow.end(), 0.0);
1435 std::fill(old_lid_drain_flow.begin(), old_lid_drain_flow.end(), 0.0);
1436 std::fill(runon_inflow.begin(), runon_inflow.end(), 0.0);
1437 std::fill(old_runon_inflow.begin(), old_runon_inflow.end(), 0.0);
1438 std::fill(runon_rate.begin(), runon_rate.end(), 0.0);
1439 std::fill(gw_sw_head.begin(), gw_sw_head.end(), 0.0);
1440 std::fill(gw_node_avail_flow.begin(), gw_node_avail_flow.end(), 0.0);
1441 std::fill(washoff_load.begin(), washoff_load.end(), 0.0);
1442 std::fill(conc.begin(), conc.end(), 0.0);
1443 std::fill(conc_old.begin(), conc_old.end(), 0.0);
1444 }
1445};
1446
1447} /* namespace openswmm */
1448
1449#endif /* OPENSWMM_ENGINE_SUBCATCH_DATA_HPP */
Definition ExchangeLaw.hpp:60
Structure-of-Arrays storage for all subcatchments.
Definition SubcatchData.hpp:57
std::vector< int > gage
Rain gage index for this subcatchment.
Definition SubcatchData.hpp:106
std::vector< double > total_lid_area_ft2
Total LID area for this subcatchment (ft²).
Definition SubcatchData.hpp:647
void reset_state() noexcept
Clear the subcatchment dynamic arrays visited here.
Definition SubcatchData.hpp:1418
std::vector< int > infil_model
Infiltration model: 0=HORTON, 1=MOD_HORTON, 2=GREEN_AMPT, 3=MOD_GREEN_AMPT, 4=CURVE_NUMBER.
Definition SubcatchData.hpp:235
std::vector< double > old_snow_depth
Snow depth at the previous runoff evaluation (for interpolation).
Definition SubcatchData.hpp:333
std::vector< double > gw_b2
Groundwater flow exponent B2.
Definition SubcatchData.hpp:548
std::vector< double > snow_net_perv
Snow-modified net precipitation for pervious subarea (ft/sec).
Definition SubcatchData.hpp:596
std::vector< double > stat_gw_infil_vol
Cumulative infiltration to GW (ft³)
Definition SubcatchData.hpp:513
std::vector< std::string > snowpack_name
Snow pack name string for deferred resolution.
Definition SubcatchData.hpp:91
std::vector< double > stat_runon_vol
Cumulative received runon volume (ft3).
Definition SubcatchData.hpp:493
int total_load_n_pollutants
Number of pollutants in total_load matrix.
Definition SubcatchData.hpp:679
std::vector< double > outfall_runon_vol
Gap #28: accumulated outfall-routed volume (ft³) between runoff steps.
Definition SubcatchData.hpp:360
std::vector< double > stat_precip_vol
Total precipitation volume (project volume units).
Definition SubcatchData.hpp:492
std::vector< double > gw_surf_elev
Surface elevation for groundwater calculations.
Definition SubcatchData.hpp:536
std::vector< double > gw_sw_head
Surface water head at GW receiving node (project length units).
Definition SubcatchData.hpp:368
std::vector< double > init_loading
The [LOADINGS] initial surface buildup, mass per unit AREA.
Definition SubcatchData.hpp:452
void resize_quality(int n_pollutants)
Set the pollutant stride and replace positive-sized quality arrays.
Definition SubcatchData.hpp:1268
std::vector< double > slope
Average slope of catchment (fraction).
Definition SubcatchData.hpp:124
std::vector< double > infil_p1
Infiltration param 1: f0 (Horton), suction (GA), CN (CN).
Definition SubcatchData.hpp:238
std::vector< double > old_gw_flow
GW flow at the previous runoff evaluation (for interpolation).
Definition SubcatchData.hpp:330
std::vector< int > snowpack
Snowpack index for this subcatchment (-1 = none).
Definition SubcatchData.hpp:578
std::vector< std::string > gage_name
Rain gage name string for deferred resolution.
Definition SubcatchData.hpp:100
std::vector< double > gw_tw
[GROUNDWATER] Dsw: fixed surface-water depth (project length units, 0 = live node depth).
Definition SubcatchData.hpp:554
std::vector< double > old_ponded_depth
Ponded depth at the START of the runoff step (project length).
Definition SubcatchData.hpp:291
std::vector< double > evap_loss
Current evaporation loss rate (project length/time units).
Definition SubcatchData.hpp:268
std::vector< double > gw_wt_elev
[GROUNDWATER] Wgw: initial water-table elevation override; MISSING = the aquifer's.
Definition SubcatchData.hpp:568
std::vector< double > old_runoff
Runoff at the previous timestep.
Definition SubcatchData.hpp:327
std::vector< double > gw_node_avail_flow
Available node flow for GW negative flow limit (cfs/ft2).
Definition SubcatchData.hpp:371
std::vector< double > stat_infil_vol
Cumulative infiltration volume (ft3)
Definition SubcatchData.hpp:496
std::vector< double > gw_flow
Groundwater outflow rate (project flow units).
Definition SubcatchData.hpp:308
std::vector< double > stat_evap_vol
Cumulative evaporation volume (ft3)
Definition SubcatchData.hpp:495
std::vector< double > lid_drain_flow
Total LID drain outflow (cfs) over the current runoff step.
Definition SubcatchData.hpp:320
std::vector< double > stat_gw_sum_theta
Time integral of upper-zone theta (seconds)
Definition SubcatchData.hpp:519
std::vector< unsigned char > sweep_now
Definition SubcatchData.hpp:718
std::vector< double > snow_melt_imperv
The MELT-ONLY part of snow_net_imperv (ft/sec).
Definition SubcatchData.hpp:617
std::vector< double > stat_perv_vol
Cumulative pervious runoff volume (ft3)
Definition SubcatchData.hpp:498
std::vector< double > snow_scale_factor
Subcatchment-level snowfall scale factor (default 1.0 = no scaling).
Definition SubcatchData.hpp:156
void reserve_to(int n)
Reserve capacity for n subcatchments without changing count().
Definition SubcatchData.hpp:1001
std::vector< double > area
Subcatchment area (project area units).
Definition SubcatchData.hpp:112
std::vector< double > gw_a3
Groundwater flow coefficient A3.
Definition SubcatchData.hpp:551
std::vector< double > old_lid_drain_flow
LID drain outflow at the previous runoff evaluation (for interpolation).
Definition SubcatchData.hpp:336
std::vector< int > outlet_subcatch
Index of the subcatch that receives overflow (-1 if none).
Definition SubcatchData.hpp:75
std::vector< double > gw_hstar
[GROUNDWATER] Egwt: threshold groundwater table elevation (project length units) below which no later...
Definition SubcatchData.hpp:562
int coverage_n_landuses
Number of landuses stored in the coverage and sweep matrices.
Definition SubcatchData.hpp:707
std::vector< std::string > comments
Object comment from the INP file (';'-prefixed lines immediately above this subcatchment's data row),...
Definition SubcatchData.hpp:466
std::vector< double > stat_gw_upper_evap_vol
Cumulative upper zone evap (ft³)
Definition SubcatchData.hpp:514
std::vector< double > old_runon_inflow
Previous-step runon inflow (for interpolation).
Definition SubcatchData.hpp:347
std::vector< double > stat_runoff_vol
Total runoff volume (project volume units).
Definition SubcatchData.hpp:504
std::vector< double > n_imperv
Manning's n for impervious area.
Definition SubcatchData.hpp:189
std::vector< double > lid_drain_runon_cfs
LID drain flow routed to a target subcatchment (CFS).
Definition SubcatchData.hpp:666
std::vector< double > n_perv
Manning's n for pervious area.
Definition SubcatchData.hpp:195
std::vector< double > infil_p4
Infiltration param 4: dry time (Horton), 0 (GA/CN).
Definition SubcatchData.hpp:244
void resize_coverage(int n_sc, int n_lu)
Resize the coverage and sweep matrices.
Definition SubcatchData.hpp:730
std::vector< double > lid_return_to_perv_cfs
LID surface return flow to pervious area (CFS).
Definition SubcatchData.hpp:656
std::vector< std::string > tags
Per-object tag from the INP [TAGS] section.
Definition SubcatchData.hpp:474
std::vector< double > runon_qual_rate
Incoming run-on pollutant mass RATE per (subcatch, pollutant), mg/sec.
Definition SubcatchData.hpp:421
std::vector< double > runon_inflow
Runoff inflow from upstream subcatchments (project flow units).
Definition SubcatchData.hpp:344
std::vector< double > runon_rate
Legacy Subcatch.runon: the run-on as a depth rate (ft/s).
Definition SubcatchData.hpp:355
std::vector< double > rain_scale_factor
Subcatchment-level rainfall scale factor (default 1.0 = no scaling).
Definition SubcatchData.hpp:142
std::vector< double > stat_gw_final_theta
Upper-zone theta at last GW step.
Definition SubcatchData.hpp:521
std::vector< double > gw_a2
Groundwater flow coefficient A2.
Definition SubcatchData.hpp:545
std::vector< double > stat_gw_lower_evap_vol
Cumulative lower zone evap (ft³)
Definition SubcatchData.hpp:515
int conc_n_pollutants
Number of pollutants in the quality arrays.
Definition SubcatchData.hpp:455
std::vector< std::string > outlet_name
Outlet name string for deferred resolution.
Definition SubcatchData.hpp:82
std::vector< double > stat_gw_deep_perc_vol
Cumulative deep percolation (ft³)
Definition SubcatchData.hpp:516
std::vector< double > snow_melt_age_imperv
S2b — WATER AGE of the meltwater in snow_melt_imperv (sec).
Definition SubcatchData.hpp:635
std::vector< double > stat_imperv_vol
Cumulative impervious runoff volume (ft3)
Definition SubcatchData.hpp:497
std::vector< double > ponded_qual
Ponded surface water quality mass per (subcatch, pollutant).
Definition SubcatchData.hpp:409
std::vector< double > pct_routed
Fraction of runoff routed between subareas (0–1).
Definition SubcatchData.hpp:228
std::vector< double > infil_p2
Infiltration param 2: fmin (Horton), conductivity (GA), unused (CN).
Definition SubcatchData.hpp:240
std::vector< double > snow_melt_age_perv
S2b — water age of the meltwater in snow_melt_perv (sec). See above.
Definition SubcatchData.hpp:638
std::vector< double > sweep_last_date
Definition SubcatchData.hpp:723
std::vector< double > stat_gw_max_flow
Peak lateral GW outflow (CFS)
Definition SubcatchData.hpp:518
std::vector< double > gw_a1
Groundwater flow coefficient A1.
Definition SubcatchData.hpp:539
void resize(int n)
Replace the base subcatchment store with a requested row count.
Definition SubcatchData.hpp:760
std::vector< double > stat_gw_final_depth
Water table elevation at last GW step (ft)
Definition SubcatchData.hpp:522
std::vector< double > snow_net_imperv
Snow-modified net precipitation for impervious subareas (ft/sec).
Definition SubcatchData.hpp:587
std::vector< double > ds_perv
Depression storage depth for pervious area (project length units).
Definition SubcatchData.hpp:207
std::vector< double > width
Width of overland flow path (project length units).
Definition SubcatchData.hpp:118
std::vector< double > infil_loss
Current infiltration loss rate (project length/time units).
Definition SubcatchData.hpp:274
std::vector< double > lid_drain_runon_qual
Definition SubcatchData.hpp:426
std::vector< double > frac_imperv_no_store
Fraction of impervious area with no depression storage (0–1).
Definition SubcatchData.hpp:168
std::vector< double > gw_upper_moist
[GROUNDWATER] Umc: initial upper-zone moisture override; MISSING = the aquifer's.
Definition SubcatchData.hpp:571
std::vector< double > conc_old
Previous-step quality in subcatchment runoff.
Definition SubcatchData.hpp:401
int count() const noexcept
Count subcatchment rows from the area column.
Definition SubcatchData.hpp:746
void erase_at(int idx)
Erase one subcatchment row from the columns visited by this helper.
Definition SubcatchData.hpp:1113
std::vector< double > gw_max_infil_vol
Gap #40: max infiltration volume (ft) upper GW zone can accept next step.
Definition SubcatchData.hpp:379
void resize_total_load(int n_sc, int n_poll)
Replace cumulative subcatchment pollutant-load storage.
Definition SubcatchData.hpp:691
std::vector< char > rpt_flag
Whether this subcatchment is included in report/output (0=no, 1=yes).
Definition SubcatchData.hpp:482
std::vector< double > washoff_vout1
This runoff step's PRE-LID outflow volume, ft³ (legacy vOut1).
Definition SubcatchData.hpp:302
std::vector< int > gw_aquifer
Aquifer index for this subcatchment (-1 = none).
Definition SubcatchData.hpp:530
std::vector< int > outlet_node
Index of the drain-to node or subcatchment.
Definition SubcatchData.hpp:69
void grow_to(int n)
Extend base subcatchment columns while preserving existing prefixes.
Definition SubcatchData.hpp:875
std::vector< double > gw_bot_elev
[GROUNDWATER] Ebot: aquifer bottom elevation override; MISSING = the aquifer's.
Definition SubcatchData.hpp:565
std::vector< double > runoff
Current total runoff flow rate (project flow units).
Definition SubcatchData.hpp:256
void shrink_to_fit()
Release excess vector capacity accumulated during parsing.
Definition SubcatchData.hpp:1300
std::vector< double > coverage
Coverage fraction per (subcatchment x landuse).
Definition SubcatchData.hpp:704
std::vector< double > snow_depth
Area-weighted snow pack SWE depth (ft), end of runoff step.
Definition SubcatchData.hpp:314
std::vector< double > stat_max_runoff
Maximum reported runoff rate (project flow units).
Definition SubcatchData.hpp:510
std::vector< double > infil_p5
Infiltration param 5: max infil (Horton), 0 (GA/CN).
Definition SubcatchData.hpp:246
std::vector< long > stat_gw_steps
Step count for GW averages.
Definition SubcatchData.hpp:523
std::vector< double > stat_gw_time
Elapsed groundwater time (seconds).
Definition SubcatchData.hpp:494
std::vector< double > rainfall
Current total rainfall depth rate (project length/time units).
Definition SubcatchData.hpp:262
std::vector< double > washoff_load
Washoff mass rate per (subcatch, pollutant) (mass/sec).
Definition SubcatchData.hpp:387
std::vector< double > ponded_depth
Current total ponded depth over subcatchment (project length units).
Definition SubcatchData.hpp:280
void save_state() noexcept
Snapshot runoff-step discharge, run-on, concentration and ponded depth.
Definition SubcatchData.hpp:1403
std::vector< double > snow_melt_perv
The melt-only part of snow_net_perv (ft/sec). See above.
Definition SubcatchData.hpp:620
std::vector< double > frac_imperv
Fraction of area that is impervious (0–1).
Definition SubcatchData.hpp:162
std::vector< int > gw_node
Receiving node index for groundwater flow (-1 = none).
Definition SubcatchData.hpp:533
std::vector< double > gw_b1
Groundwater flow exponent B1.
Definition SubcatchData.hpp:542
std::vector< double > infil_p3
Infiltration param 3: decay (Horton), initial deficit (GA), drying time (CN).
Definition SubcatchData.hpp:242
std::vector< double > sweep_last_swept
Gap #34: days since last swept per (subcatch x landuse).
Definition SubcatchData.hpp:714
std::vector< double > total_load
Total washoff load per (subcatchment x pollutant) (mass units).
Definition SubcatchData.hpp:676
std::vector< double > ds_imperv
Depression storage depth for impervious area (project length units).
Definition SubcatchData.hpp:201
std::vector< int > subarea_routing
Inter-subarea routing mode.
Definition SubcatchData.hpp:220
void resize_washoff_load(int n_pollutants)
Zero the washoff-load matrix for a positive pollutant count.
Definition SubcatchData.hpp:1290
std::vector< double > stat_gw_sum_depth
Time integral of water table elevation (ft-seconds)
Definition SubcatchData.hpp:520
std::vector< double > stat_gw_flow_vol
Cumulative lateral GW outflow (ft³)
Definition SubcatchData.hpp:517
std::vector< double > subarea_runoff_rate
Area-averaged subarea runoff RATE, ft/sec — legacy's subcatch_getRunoff return value (runoff / area).
Definition SubcatchData.hpp:438
std::vector< double > conc
Current quality concentration in subcatchment runoff.
Definition SubcatchData.hpp:398
std::vector< double > pct_zero
The AUTHORED [SUBAREAS] PctZero column, in percent.
Definition SubcatchData.hpp:183
std::vector< double > curb_length
Total curb length (project length units).
Definition SubcatchData.hpp:130