From f9e78cf8252578d890cf5d09130eda2e21ba36a1 Mon Sep 17 00:00:00 2001 From: "Bryant E. McDonnell" Date: Sun, 11 Jun 2023 14:28:44 -0500 Subject: [PATCH 1/9] Adding Hot Start File save-during-simulation feature --- src/solver/include/toolkit.h | 6 + src/solver/toolkit.c | 40 ++++ tests/solver/CMakeLists.txt | 1 + tests/solver/data/hotstart/Simulation1.inp | 217 +++++++++++++++++++++ tests/solver/data/hotstart/Simulation2.inp | 217 +++++++++++++++++++++ tests/solver/data/hotstart/Simulation3.inp | 217 +++++++++++++++++++++ tests/solver/test_solver.hpp | 1 + tests/solver/test_toolkit_hotstart.cpp | 122 ++++++++++++ 8 files changed, 821 insertions(+) create mode 100644 tests/solver/data/hotstart/Simulation1.inp create mode 100644 tests/solver/data/hotstart/Simulation2.inp create mode 100644 tests/solver/data/hotstart/Simulation3.inp create mode 100644 tests/solver/test_toolkit_hotstart.cpp diff --git a/src/solver/include/toolkit.h b/src/solver/include/toolkit.h index 339dbd09a..0a318c1d9 100644 --- a/src/solver/include/toolkit.h +++ b/src/solver/include/toolkit.h @@ -612,6 +612,12 @@ EXPORT_TOOLKIT int swmm_setOutfallStage(int index, double stage); */ EXPORT_TOOLKIT int swmm_setGagePrecip(int index, double total_precip); +/** + @brief Save hotstart file during simulation + @param hsfile The file name of the hotstart file that user would like to save +*/ +EXPORT_TOOLKIT int swmm_saveHotstart(char *hsfile); + /** @brief Helper function to free memory array allocated in SWMM. @param array The pointer to the array diff --git a/src/solver/toolkit.c b/src/solver/toolkit.c index 83571a97e..d680486a5 100644 --- a/src/solver/toolkit.c +++ b/src/solver/toolkit.c @@ -3096,6 +3096,46 @@ EXPORT_TOOLKIT int swmm_setGagePrecip(int index, double total_precip) return error_code; } +EXPORT_TOOLKIT int DLLEXPORT swmm_saveHotstart(char *hsfile) +/// +/// Input: hotstart file ID name (able to overwrite) +/// Return API Error +/// Purpose: Allows hot start files to be created during a simulation +/// at any time. +{ + int error_code = 0; + // Check if Open + if(swmm_IsOpenFlag() == FALSE) + { + error_code = ERR_TKAPI_INPUTNOTOPEN; + } + // Check if Simulation is Running + else if (swmm_IsStartedFlag() == FALSE) + { + error_code = ERR_TKAPI_SIM_NRUNNING; + } + else + { + // Storing Existing INP set HSFs + TFile tmpHotstart1 = Fhotstart1; + TFile tmpHotstart2 = Fhotstart2; + int _fl1_info = Fhotstart1.mode; + int _fl2_info = Fhotstart2.mode; + // Create info for New HSF + Fhotstart1.mode = NO_FILE; + Fhotstart2.mode = SAVE_FILE; + sstrncpy(Fhotstart2.name, hsfile, MAXFNAME); + // Saving Data + if (hotstart_open()) hotstart_close(); + // Replacing INP set HSFs + Fhotstart2 = tmpHotstart2; + Fhotstart1 = tmpHotstart1; + Fhotstart1.mode = _fl1_info; + Fhotstart2.mode = _fl2_info; + } + return error_code; +} + EXPORT_TOOLKIT void swmm_freeMemory(void *memory) // // Purpose: Frees memory allocated by API calls diff --git a/tests/solver/CMakeLists.txt b/tests/solver/CMakeLists.txt index 021832fbb..0a1bdfe1a 100644 --- a/tests/solver/CMakeLists.txt +++ b/tests/solver/CMakeLists.txt @@ -38,6 +38,7 @@ set(solver_test_srcs test_solver.cpp test_stats.cpp test_inlets_and_drains.cpp + test_toolkit_hotstart.cpp # ADD NEW TEST SUITES TO EXISTING TOOLKIT TEST MODULE ) diff --git a/tests/solver/data/hotstart/Simulation1.inp b/tests/solver/data/hotstart/Simulation1.inp new file mode 100644 index 000000000..3f2639fc3 --- /dev/null +++ b/tests/solver/data/hotstart/Simulation1.inp @@ -0,0 +1,217 @@ +[TITLE] +;;Project Title/Notes +Example 1 + +[OPTIONS] +;;Option Value +FLOW_UNITS CFS +INFILTRATION HORTON +FLOW_ROUTING DYNWAVE +LINK_OFFSETS DEPTH +MIN_SLOPE 0 +ALLOW_PONDING NO +SKIP_STEADY_STATE NO + +START_DATE 01/01/1998 +START_TIME 00:00:00 +REPORT_START_DATE 01/01/1998 +REPORT_START_TIME 00:00:00 +END_DATE 01/02/1998 +END_TIME 12:00:00 +SWEEP_START 1/1 +SWEEP_END 12/31 +DRY_DAYS 5 +REPORT_STEP 01:00:00 +WET_STEP 00:15:00 +DRY_STEP 01:00:00 +ROUTING_STEP 0:01:00 + +INERTIAL_DAMPING PARTIAL +NORMAL_FLOW_LIMITED BOTH +FORCE_MAIN_EQUATION H-W +VARIABLE_STEP 0.75 +LENGTHENING_STEP 0 +MIN_SURFAREA 0 +MAX_TRIALS 0 +HEAD_TOLERANCE 0 +SYS_FLOW_TOL 5 +LAT_FLOW_TOL 5 +;MINIMUM_STEP 0.5 +THREADS 1 + +[FILES] +SAVE HOTSTART INFILE_Simulation1.hsf + +[EVAPORATION] +;;Data Source Parameters +;;-------------- ---------------- +CONSTANT 0.0 +DRY_ONLY NO + +[RAINGAGES] +;;Name Format Interval SCF Source +;;-------------- --------- ------ ------ ---------- +RG1 INTENSITY 1:00 1.0 TIMESERIES TS1 + +[SUBCATCHMENTS] +;;Name Rain Gage Outlet Area %Imperv Width %Slope CurbLen SnowPack +;;-------------- ---------------- ---------------- -------- -------- -------- -------- -------- ---------------- +1 RG1 9 10 50 500 0.01 0 +2 RG1 10 10 50 500 0.01 0 +3 RG1 13 5 50 500 0.01 0 +4 RG1 22 5 50 500 0.01 0 +5 RG1 15 15 50 500 0.01 0 +6 RG1 23 12 10 500 0.01 0 +7 RG1 19 4 10 500 0.01 0 +8 RG1 18 10 10 500 0.01 0 + +[SUBAREAS] +;;Subcatchment N-Imperv N-Perv S-Imperv S-Perv PctZero RouteTo PctRouted +;;-------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- +1 0.001 0.10 0.05 0.05 25 OUTLET +2 0.001 0.10 0.05 0.05 25 OUTLET +3 0.001 0.10 0.05 0.05 25 OUTLET +4 0.001 0.10 0.05 0.05 25 OUTLET +5 0.001 0.10 0.05 0.05 25 OUTLET +6 0.001 0.10 0.05 0.05 25 OUTLET +7 0.001 0.10 0.05 0.05 25 OUTLET +8 0.001 0.10 0.05 0.05 25 OUTLET + +[INFILTRATION] +;;Subcatchment MaxRate MinRate Decay DryTime MaxInfil +;;-------------- ---------- ---------- ---------- ---------- ---------- +1 0.35 0.25 4.14 0.50 0 +2 0.7 0.3 4.14 0.50 0 +3 0.7 0.3 4.14 0.50 0 +4 0.7 0.3 4.14 0.50 0 +5 0.7 0.3 4.14 0.50 0 +6 0.7 0.3 4.14 0.50 0 +7 0.7 0.3 4.14 0.50 0 +8 0.7 0.3 4.14 0.50 0 + +[JUNCTIONS] +;;Name Elevation MaxDepth InitDepth SurDepth Aponded +;;-------------- ---------- ---------- ---------- ---------- ---------- +9 1000 3 0 0 0 +10 995 3 0 0 0 +13 995 3 0 0 0 +14 990 3 0 0 0 +15 987 3 0 0 0 +16 985 3 0 0 0 +17 980 3 0 0 0 +19 1010 3 0 0 0 +20 1005 3 0 0 0 +21 990 3 0 0 0 +22 987 3 0 0 0 +23 990 3 0 0 0 +24 984 3 0 0 0 + +[OUTFALLS] +;;Name Elevation Type Stage Data Gated Route To +;;-------------- ---------- ---------- ---------------- -------- ---------------- +18 975 FREE NO + +[CONDUITS] +;;Name From Node To Node Length Roughness InOffset OutOffset InitFlow MaxFlow +;;-------------- ---------------- ---------------- ---------- ---------- ---------- ---------- ---------- ---------- +1 9 10 400 0.01 0 0 0 0 +4 19 20 200 0.01 0 0 0 0 +5 20 21 200 0.01 0 0 0 0 +6 10 21 400 0.01 0 1 0 0 +7 21 22 300 0.01 1 1 0 0 +8 22 16 300 0.01 0 0 0 0 +10 17 18 400 0.01 0 0 0 0 +11 13 14 400 0.01 0 0 0 0 +12 14 15 400 0.01 0 0 0 0 +13 15 16 400 0.01 0 0 0 0 +14 23 24 400 0.01 0 0 0 0 +15 16 24 100 0.01 0 0 0 0 +16 24 17 400 0.01 0 0 0 0 + +[XSECTIONS] +;;Link Shape Geom1 Geom2 Geom3 Geom4 Barrels Culvert +;;-------------- ------------ ---------------- ---------- ---------- ---------- ---------- ---------- +1 CIRCULAR 1.5 0 0 0 1 +4 CIRCULAR 1 0 0 0 1 +5 CIRCULAR 1 0 0 0 1 +6 CIRCULAR 1 0 0 0 1 +7 CIRCULAR 2 0 0 0 1 +8 CIRCULAR 2 0 0 0 1 +10 CIRCULAR 2 0 0 0 1 +11 CIRCULAR 1.5 0 0 0 1 +12 CIRCULAR 1.5 0 0 0 1 +13 CIRCULAR 1.5 0 0 0 1 +14 CIRCULAR 1 0 0 0 1 +15 CIRCULAR 2 0 0 0 1 +16 CIRCULAR 2 0 0 0 1 + +[POLLUTANTS] +;;Name Units Crain Cgw Crdii Kdecay SnowOnly Co-Pollutant Co-Frac Cdwf Cinit +;;-------------- ------ ---------- ---------- ---------- ---------- ---------- ---------------- ---------- ---------- ---------- +TSS MG/L 0.0 0.0 0 0.0 NO * 0.0 0 0 +Lead UG/L 0.0 0.0 0 0.0 NO TSS 0.2 0 0 + +[LANDUSES] +;; Sweeping Fraction Last +;;Name Interval Available Swept +;;-------------- ---------- ---------- ---------- +Residential +Undeveloped + +[COVERAGES] +;;Subcatchment Land Use Percent +;;-------------- ---------------- ---------- +1 Residential 100.00 +2 Residential 50.00 +2 Undeveloped 50.00 +3 Residential 100.00 +4 Residential 50.00 +4 Undeveloped 50.00 +5 Residential 100.00 +6 Undeveloped 100.00 +7 Undeveloped 100.00 +8 Undeveloped 100.00 + +[LOADINGS] +;;Subcatchment Pollutant Buildup +;;-------------- ---------------- ---------- + +[BUILDUP] +;;Land Use Pollutant Function Coeff1 Coeff2 Coeff3 Per Unit +;;-------------- ---------------- ---------- ---------- ---------- ---------- ---------- +Residential TSS SAT 50 0 2 AREA +Residential Lead NONE 0 0 0 AREA +Undeveloped TSS SAT 100 0 3 AREA +Undeveloped Lead NONE 0 0 0 AREA + +[WASHOFF] +;;Land Use Pollutant Function Coeff1 Coeff2 SweepRmvl BmpRmvl +;;-------------- ---------------- ---------- ---------- ---------- ---------- ---------- +Residential TSS EXP 0.1 1 0 0 +Residential Lead EMC 0 0 0 0 +Undeveloped TSS EXP 0.1 0.7 0 0 +Undeveloped Lead EMC 0 0 0 0 + +[TIMESERIES] +;;Name Date Time Value +;;-------------- ---------- ---------- ---------- +;RAINFALL +TS1 0:00 0.0 +TS1 1:00 0.25 +TS1 2:00 0.5 +TS1 3:00 0.8 +TS1 4:00 0.4 +TS1 5:00 0.1 +TS1 6:00 0.0 +TS1 27:00 0.0 +TS1 28:00 0.4 +TS1 29:00 0.2 +TS1 30:00 0.0 + +[REPORT] +;;Reporting Options +INPUT NO +CONTROLS NO +SUBCATCHMENTS ALL +NODES ALL +LINKS ALL diff --git a/tests/solver/data/hotstart/Simulation2.inp b/tests/solver/data/hotstart/Simulation2.inp new file mode 100644 index 000000000..f6af08f88 --- /dev/null +++ b/tests/solver/data/hotstart/Simulation2.inp @@ -0,0 +1,217 @@ +[TITLE] +;;Project Title/Notes +Example 1 + +[OPTIONS] +;;Option Value +FLOW_UNITS CFS +INFILTRATION HORTON +FLOW_ROUTING DYNWAVE +LINK_OFFSETS DEPTH +MIN_SLOPE 0 +ALLOW_PONDING NO +SKIP_STEADY_STATE NO + +START_DATE 01/01/1998 +START_TIME 00:00:00 +REPORT_START_DATE 01/01/1998 +REPORT_START_TIME 00:00:00 +END_DATE 01/02/1998 +END_TIME 12:00:00 +SWEEP_START 1/1 +SWEEP_END 12/31 +DRY_DAYS 5 +REPORT_STEP 01:00:00 +WET_STEP 00:15:00 +DRY_STEP 01:00:00 +ROUTING_STEP 0:01:00 + +INERTIAL_DAMPING PARTIAL +NORMAL_FLOW_LIMITED BOTH +FORCE_MAIN_EQUATION H-W +VARIABLE_STEP 0.75 +LENGTHENING_STEP 0 +MIN_SURFAREA 0 +MAX_TRIALS 0 +HEAD_TOLERANCE 0 +SYS_FLOW_TOL 5 +LAT_FLOW_TOL 5 +;MINIMUM_STEP 0.5 +THREADS 1 + +[FILES] +SAVE HOTSTART INFILE_Simulation2.hsf + +[EVAPORATION] +;;Data Source Parameters +;;-------------- ---------------- +CONSTANT 0.0 +DRY_ONLY NO + +[RAINGAGES] +;;Name Format Interval SCF Source +;;-------------- --------- ------ ------ ---------- +RG1 INTENSITY 1:00 1.0 TIMESERIES TS1 + +[SUBCATCHMENTS] +;;Name Rain Gage Outlet Area %Imperv Width %Slope CurbLen SnowPack +;;-------------- ---------------- ---------------- -------- -------- -------- -------- -------- ---------------- +1 RG1 9 10 50 500 0.01 0 +2 RG1 10 10 50 500 0.01 0 +3 RG1 13 5 50 500 0.01 0 +4 RG1 22 5 50 500 0.01 0 +5 RG1 15 15 50 500 0.01 0 +6 RG1 23 12 10 500 0.01 0 +7 RG1 19 4 10 500 0.01 0 +8 RG1 18 10 10 500 0.01 0 + +[SUBAREAS] +;;Subcatchment N-Imperv N-Perv S-Imperv S-Perv PctZero RouteTo PctRouted +;;-------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- +1 0.001 0.10 0.05 0.05 25 OUTLET +2 0.001 0.10 0.05 0.05 25 OUTLET +3 0.001 0.10 0.05 0.05 25 OUTLET +4 0.001 0.10 0.05 0.05 25 OUTLET +5 0.001 0.10 0.05 0.05 25 OUTLET +6 0.001 0.10 0.05 0.05 25 OUTLET +7 0.001 0.10 0.05 0.05 25 OUTLET +8 0.001 0.10 0.05 0.05 25 OUTLET + +[INFILTRATION] +;;Subcatchment MaxRate MinRate Decay DryTime MaxInfil +;;-------------- ---------- ---------- ---------- ---------- ---------- +1 0.35 0.25 4.14 0.50 0 +2 0.7 0.3 4.14 0.50 0 +3 0.7 0.3 4.14 0.50 0 +4 0.7 0.3 4.14 0.50 0 +5 0.7 0.3 4.14 0.50 0 +6 0.7 0.3 4.14 0.50 0 +7 0.7 0.3 4.14 0.50 0 +8 0.7 0.3 4.14 0.50 0 + +[JUNCTIONS] +;;Name Elevation MaxDepth InitDepth SurDepth Aponded +;;-------------- ---------- ---------- ---------- ---------- ---------- +9 1000 3 0 0 0 +10 995 3 0 0 0 +13 995 3 0 0 0 +14 990 3 0 0 0 +15 987 3 0 0 0 +16 985 3 0 0 0 +17 980 3 0 0 0 +19 1010 3 0 0 0 +20 1005 3 0 0 0 +21 990 3 0 0 0 +22 987 3 0 0 0 +23 990 3 0 0 0 +24 984 3 0 0 0 + +[OUTFALLS] +;;Name Elevation Type Stage Data Gated Route To +;;-------------- ---------- ---------- ---------------- -------- ---------------- +18 975 FREE NO + +[CONDUITS] +;;Name From Node To Node Length Roughness InOffset OutOffset InitFlow MaxFlow +;;-------------- ---------------- ---------------- ---------- ---------- ---------- ---------- ---------- ---------- +1 9 10 400 0.01 0 0 0 0 +4 19 20 200 0.01 0 0 0 0 +5 20 21 200 0.01 0 0 0 0 +6 10 21 400 0.01 0 1 0 0 +7 21 22 300 0.01 1 1 0 0 +8 22 16 300 0.01 0 0 0 0 +10 17 18 400 0.01 0 0 0 0 +11 13 14 400 0.01 0 0 0 0 +12 14 15 400 0.01 0 0 0 0 +13 15 16 400 0.01 0 0 0 0 +14 23 24 400 0.01 0 0 0 0 +15 16 24 100 0.01 0 0 0 0 +16 24 17 400 0.01 0 0 0 0 + +[XSECTIONS] +;;Link Shape Geom1 Geom2 Geom3 Geom4 Barrels Culvert +;;-------------- ------------ ---------------- ---------- ---------- ---------- ---------- ---------- +1 CIRCULAR 1.5 0 0 0 1 +4 CIRCULAR 1 0 0 0 1 +5 CIRCULAR 1 0 0 0 1 +6 CIRCULAR 1 0 0 0 1 +7 CIRCULAR 2 0 0 0 1 +8 CIRCULAR 2 0 0 0 1 +10 CIRCULAR 2 0 0 0 1 +11 CIRCULAR 1.5 0 0 0 1 +12 CIRCULAR 1.5 0 0 0 1 +13 CIRCULAR 1.5 0 0 0 1 +14 CIRCULAR 1 0 0 0 1 +15 CIRCULAR 2 0 0 0 1 +16 CIRCULAR 2 0 0 0 1 + +[POLLUTANTS] +;;Name Units Crain Cgw Crdii Kdecay SnowOnly Co-Pollutant Co-Frac Cdwf Cinit +;;-------------- ------ ---------- ---------- ---------- ---------- ---------- ---------------- ---------- ---------- ---------- +TSS MG/L 0.0 0.0 0 0.0 NO * 0.0 0 0 +Lead UG/L 0.0 0.0 0 0.0 NO TSS 0.2 0 0 + +[LANDUSES] +;; Sweeping Fraction Last +;;Name Interval Available Swept +;;-------------- ---------- ---------- ---------- +Residential +Undeveloped + +[COVERAGES] +;;Subcatchment Land Use Percent +;;-------------- ---------------- ---------- +1 Residential 100.00 +2 Residential 50.00 +2 Undeveloped 50.00 +3 Residential 100.00 +4 Residential 50.00 +4 Undeveloped 50.00 +5 Residential 100.00 +6 Undeveloped 100.00 +7 Undeveloped 100.00 +8 Undeveloped 100.00 + +[LOADINGS] +;;Subcatchment Pollutant Buildup +;;-------------- ---------------- ---------- + +[BUILDUP] +;;Land Use Pollutant Function Coeff1 Coeff2 Coeff3 Per Unit +;;-------------- ---------------- ---------- ---------- ---------- ---------- ---------- +Residential TSS SAT 50 0 2 AREA +Residential Lead NONE 0 0 0 AREA +Undeveloped TSS SAT 100 0 3 AREA +Undeveloped Lead NONE 0 0 0 AREA + +[WASHOFF] +;;Land Use Pollutant Function Coeff1 Coeff2 SweepRmvl BmpRmvl +;;-------------- ---------------- ---------- ---------- ---------- ---------- ---------- +Residential TSS EXP 0.1 1 0 0 +Residential Lead EMC 0 0 0 0 +Undeveloped TSS EXP 0.1 0.7 0 0 +Undeveloped Lead EMC 0 0 0 0 + +[TIMESERIES] +;;Name Date Time Value +;;-------------- ---------- ---------- ---------- +;RAINFALL +TS1 0:00 0.0 +TS1 1:00 0.25 +TS1 2:00 0.5 +TS1 3:00 0.8 +TS1 4:00 0.4 +TS1 5:00 0.1 +TS1 6:00 0.0 +TS1 27:00 0.0 +TS1 28:00 0.4 +TS1 29:00 0.2 +TS1 30:00 0.0 + +[REPORT] +;;Reporting Options +INPUT NO +CONTROLS NO +SUBCATCHMENTS ALL +NODES ALL +LINKS ALL diff --git a/tests/solver/data/hotstart/Simulation3.inp b/tests/solver/data/hotstart/Simulation3.inp new file mode 100644 index 000000000..c37bec2a0 --- /dev/null +++ b/tests/solver/data/hotstart/Simulation3.inp @@ -0,0 +1,217 @@ +[TITLE] +;;Project Title/Notes +Example 1 + +[OPTIONS] +;;Option Value +FLOW_UNITS CFS +INFILTRATION HORTON +FLOW_ROUTING DYNWAVE +LINK_OFFSETS DEPTH +MIN_SLOPE 0 +ALLOW_PONDING NO +SKIP_STEADY_STATE NO + +START_DATE 01/01/1998 +START_TIME 00:00:00 +REPORT_START_DATE 01/01/1998 +REPORT_START_TIME 00:00:00 +END_DATE 01/02/1998 +END_TIME 12:00:00 +SWEEP_START 1/1 +SWEEP_END 12/31 +DRY_DAYS 5 +REPORT_STEP 01:00:00 +WET_STEP 00:15:00 +DRY_STEP 01:00:00 +ROUTING_STEP 0:01:00 + +INERTIAL_DAMPING PARTIAL +NORMAL_FLOW_LIMITED BOTH +FORCE_MAIN_EQUATION H-W +VARIABLE_STEP 0.75 +LENGTHENING_STEP 0 +MIN_SURFAREA 0 +MAX_TRIALS 0 +HEAD_TOLERANCE 0 +SYS_FLOW_TOL 5 +LAT_FLOW_TOL 5 +;MINIMUM_STEP 0.5 +THREADS 1 + +[FILES] +USE HOTSTART swmm_api_test_after_Simulation1.hsf + +[EVAPORATION] +;;Data Source Parameters +;;-------------- ---------------- +CONSTANT 0.0 +DRY_ONLY NO + +[RAINGAGES] +;;Name Format Interval SCF Source +;;-------------- --------- ------ ------ ---------- +RG1 INTENSITY 1:00 1.0 TIMESERIES TS1 + +[SUBCATCHMENTS] +;;Name Rain Gage Outlet Area %Imperv Width %Slope CurbLen SnowPack +;;-------------- ---------------- ---------------- -------- -------- -------- -------- -------- ---------------- +1 RG1 9 10 50 500 0.01 0 +2 RG1 10 10 50 500 0.01 0 +3 RG1 13 5 50 500 0.01 0 +4 RG1 22 5 50 500 0.01 0 +5 RG1 15 15 50 500 0.01 0 +6 RG1 23 12 10 500 0.01 0 +7 RG1 19 4 10 500 0.01 0 +8 RG1 18 10 10 500 0.01 0 + +[SUBAREAS] +;;Subcatchment N-Imperv N-Perv S-Imperv S-Perv PctZero RouteTo PctRouted +;;-------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- +1 0.001 0.10 0.05 0.05 25 OUTLET +2 0.001 0.10 0.05 0.05 25 OUTLET +3 0.001 0.10 0.05 0.05 25 OUTLET +4 0.001 0.10 0.05 0.05 25 OUTLET +5 0.001 0.10 0.05 0.05 25 OUTLET +6 0.001 0.10 0.05 0.05 25 OUTLET +7 0.001 0.10 0.05 0.05 25 OUTLET +8 0.001 0.10 0.05 0.05 25 OUTLET + +[INFILTRATION] +;;Subcatchment MaxRate MinRate Decay DryTime MaxInfil +;;-------------- ---------- ---------- ---------- ---------- ---------- +1 0.35 0.25 4.14 0.50 0 +2 0.7 0.3 4.14 0.50 0 +3 0.7 0.3 4.14 0.50 0 +4 0.7 0.3 4.14 0.50 0 +5 0.7 0.3 4.14 0.50 0 +6 0.7 0.3 4.14 0.50 0 +7 0.7 0.3 4.14 0.50 0 +8 0.7 0.3 4.14 0.50 0 + +[JUNCTIONS] +;;Name Elevation MaxDepth InitDepth SurDepth Aponded +;;-------------- ---------- ---------- ---------- ---------- ---------- +9 1000 3 0 0 0 +10 995 3 0 0 0 +13 995 3 0 0 0 +14 990 3 0 0 0 +15 987 3 0 0 0 +16 985 3 0 0 0 +17 980 3 0 0 0 +19 1010 3 0 0 0 +20 1005 3 0 0 0 +21 990 3 0 0 0 +22 987 3 0 0 0 +23 990 3 0 0 0 +24 984 3 0 0 0 + +[OUTFALLS] +;;Name Elevation Type Stage Data Gated Route To +;;-------------- ---------- ---------- ---------------- -------- ---------------- +18 975 FREE NO + +[CONDUITS] +;;Name From Node To Node Length Roughness InOffset OutOffset InitFlow MaxFlow +;;-------------- ---------------- ---------------- ---------- ---------- ---------- ---------- ---------- ---------- +1 9 10 400 0.01 0 0 0 0 +4 19 20 200 0.01 0 0 0 0 +5 20 21 200 0.01 0 0 0 0 +6 10 21 400 0.01 0 1 0 0 +7 21 22 300 0.01 1 1 0 0 +8 22 16 300 0.01 0 0 0 0 +10 17 18 400 0.01 0 0 0 0 +11 13 14 400 0.01 0 0 0 0 +12 14 15 400 0.01 0 0 0 0 +13 15 16 400 0.01 0 0 0 0 +14 23 24 400 0.01 0 0 0 0 +15 16 24 100 0.01 0 0 0 0 +16 24 17 400 0.01 0 0 0 0 + +[XSECTIONS] +;;Link Shape Geom1 Geom2 Geom3 Geom4 Barrels Culvert +;;-------------- ------------ ---------------- ---------- ---------- ---------- ---------- ---------- +1 CIRCULAR 1.5 0 0 0 1 +4 CIRCULAR 1 0 0 0 1 +5 CIRCULAR 1 0 0 0 1 +6 CIRCULAR 1 0 0 0 1 +7 CIRCULAR 2 0 0 0 1 +8 CIRCULAR 2 0 0 0 1 +10 CIRCULAR 2 0 0 0 1 +11 CIRCULAR 1.5 0 0 0 1 +12 CIRCULAR 1.5 0 0 0 1 +13 CIRCULAR 1.5 0 0 0 1 +14 CIRCULAR 1 0 0 0 1 +15 CIRCULAR 2 0 0 0 1 +16 CIRCULAR 2 0 0 0 1 + +[POLLUTANTS] +;;Name Units Crain Cgw Crdii Kdecay SnowOnly Co-Pollutant Co-Frac Cdwf Cinit +;;-------------- ------ ---------- ---------- ---------- ---------- ---------- ---------------- ---------- ---------- ---------- +TSS MG/L 0.0 0.0 0 0.0 NO * 0.0 0 0 +Lead UG/L 0.0 0.0 0 0.0 NO TSS 0.2 0 0 + +[LANDUSES] +;; Sweeping Fraction Last +;;Name Interval Available Swept +;;-------------- ---------- ---------- ---------- +Residential +Undeveloped + +[COVERAGES] +;;Subcatchment Land Use Percent +;;-------------- ---------------- ---------- +1 Residential 100.00 +2 Residential 50.00 +2 Undeveloped 50.00 +3 Residential 100.00 +4 Residential 50.00 +4 Undeveloped 50.00 +5 Residential 100.00 +6 Undeveloped 100.00 +7 Undeveloped 100.00 +8 Undeveloped 100.00 + +[LOADINGS] +;;Subcatchment Pollutant Buildup +;;-------------- ---------------- ---------- + +[BUILDUP] +;;Land Use Pollutant Function Coeff1 Coeff2 Coeff3 Per Unit +;;-------------- ---------------- ---------- ---------- ---------- ---------- ---------- +Residential TSS SAT 50 0 2 AREA +Residential Lead NONE 0 0 0 AREA +Undeveloped TSS SAT 100 0 3 AREA +Undeveloped Lead NONE 0 0 0 AREA + +[WASHOFF] +;;Land Use Pollutant Function Coeff1 Coeff2 SweepRmvl BmpRmvl +;;-------------- ---------------- ---------- ---------- ---------- ---------- ---------- +Residential TSS EXP 0.1 1 0 0 +Residential Lead EMC 0 0 0 0 +Undeveloped TSS EXP 0.1 0.7 0 0 +Undeveloped Lead EMC 0 0 0 0 + +[TIMESERIES] +;;Name Date Time Value +;;-------------- ---------- ---------- ---------- +;RAINFALL +TS1 0:00 0.0 +TS1 1:00 0.25 +TS1 2:00 0.5 +TS1 3:00 0.8 +TS1 4:00 0.4 +TS1 5:00 0.1 +TS1 6:00 0.0 +TS1 27:00 0.0 +TS1 28:00 0.4 +TS1 29:00 0.2 +TS1 30:00 0.0 + +[REPORT] +;;Reporting Options +INPUT NO +CONTROLS NO +SUBCATCHMENTS ALL +NODES ALL +LINKS ALL diff --git a/tests/solver/test_solver.hpp b/tests/solver/test_solver.hpp index e45e477b4..538c2ce74 100644 --- a/tests/solver/test_solver.hpp +++ b/tests/solver/test_solver.hpp @@ -17,6 +17,7 @@ extern "C" { #include "swmm5.h" #include "toolkit.h" +#include "../headers.h" // Allows checking values directly in SWMM's data model. } // Add shared data paths here diff --git a/tests/solver/test_toolkit_hotstart.cpp b/tests/solver/test_toolkit_hotstart.cpp new file mode 100644 index 000000000..f83e69174 --- /dev/null +++ b/tests/solver/test_toolkit_hotstart.cpp @@ -0,0 +1,122 @@ +/* + * test_toolkitAPI_hotstart.cpp + * + * Created: 07/29/2019 + * Updated: 06/11/2023 + * Author: Bryant E. McDonnell and Jeff Sadler + * + * Unit testing mechanics for the hotstart API using Boost Test. + */ + +#include +#include "test_solver.hpp" +#include +#include + +#define HOTSTART_SWMM_SAVE_NORMAL "./hotstart/INFILE_Simulation1.hsf" +#define HOTSTART_API_SAVE_DURING_SIM1 "./hotstart/swmm_api_test_during_Simulation1.hsf" +#define HOTSTART_API_SAVE_AFTER_SIM1 "./hotstart/swmm_api_test_after_Simulation1.hsf" +#define HOTSTART_SWMM_SAVE_SIM2 "./hotstart/INFILE_Simulation2.hsf" + +#define ERR_NONE 0 + +BOOST_AUTO_TEST_SUITE(test_save_hotstart) + +// Testing Run Simulation and Generate Hot Start File using Model (as normal) +// and save a hot start file using the API swmm_saveHotstart() +// +// TEST #1 - Making and Comparing Hot Start Files. +// In this test 2 simulations will be performed. One simulation will +// create hot start files at various time and the second simulation will +// end at the +// +// Start Simulation 1 +// This simulation will produce 3 hot start files: +// 1. API hotstart File at 1056 Steps into the model ~= 1998-1-1 2:59:58 +// (HSF Name: HOTSTART_API_SAVE_DURING_SIM1) +// 2. API created hotstart file at the end of the run +// (HSF Name: HOTSTART_API_SAVE_AFTER_SIM1) +// 3. Normal SWMM [FILES] Generated HSF +// (HSF Name: HOTSTART_SWMM_SAVE_NORMAL) +// +// Start Simulation 2 +// This simulation will end at 1056 Steps into a simulation. +// (HSF Name: HOTSTART_SWMM_SAVE_SIM2 +// +// The follwing comparisons will be made from these artifacts +// 1. HOTSTART_SWMM_SAVE_NORMAL Should == HOTSTART_API_SAVE +// 2. HOTSTART_API_SAVE_DURING_SIM1 Should == HOTSTART_SWMM_SAVE_SIM2 + +BOOST_AUTO_TEST_CASE(save_hotstart_file){ + int error, step_ind; + int number_of_nodes; + int y, m, d, h, mn, s; + double elapsedTime = 0.0; + + // Start Simulation 1 + swmm_open((char *)"hotstart/Simulation1.inp", + (char *)"hotstart/Simulation1.rpt", + (char *)"hotstart/Simulation1.out"); + swmm_start(1); + step_ind = 0; + do + { + error = swmm_step(&elapsedTime); + step_ind += 1; + if (step_ind == 1056) + { + swmm_saveHotstart((char *) HOTSTART_API_SAVE_DURING_SIM1); + } + }while (elapsedTime != 0 && !error); + BOOST_CHECK_EQUAL(ERR_NONE, error); + // Save New Hotstart File at the End of the Simulation + error = swmm_saveHotstart((char *) HOTSTART_API_SAVE_AFTER_SIM1); + BOOST_CHECK_EQUAL(ERR_NONE, error); + swmm_end(); + swmm_report(); + swmm_close(); + + // Start Simulation 2 + swmm_open((char *)"hotstart/Simulation2.inp", + (char *)"hotstart/Simulation2.rpt", + (char *)"hotstart/Simulation2.out"); + swmm_start(0); + step_ind = 0; + elapsedTime = 0.0; + do + { + error = swmm_step(&elapsedTime); + step_ind += 1; + }while (step_ind < 1056 && !error); + BOOST_CHECK_EQUAL(ERR_NONE, error); + swmm_end(); + swmm_close(); + + std::ifstream ifs1(HOTSTART_SWMM_SAVE_NORMAL); + std::ifstream ifs2(HOTSTART_API_SAVE_AFTER_SIM1); + std::istream_iterator b1(ifs1), e1; + std::istream_iterator b2(ifs2), e2; + //iterate over the two hotstart files and check all of them + BOOST_CHECK_EQUAL_COLLECTIONS(b1, e1, b2, e2); + + // Diff the three hot start files that come from the model. + std::ifstream ifsbench_1998(HOTSTART_SWMM_SAVE_SIM2); + std::ifstream ifs1_1998(HOTSTART_API_SAVE_DURING_SIM1); + std::istream_iterator bench_1998(ifsbench_1998), ebench_1998; + std::istream_iterator b_1998(ifs1_1998), e_1998; + // iterate over hotstart files and check all of them + BOOST_CHECK_EQUAL_COLLECTIONS(bench_1998, ebench_1998, b_1998, e_1998); + + // Testing USE the new generated hotstart file + // Start Simulation 3 + swmm_open((char *)"hotstart/Simulation3.inp", + (char *)"hotstart/Simulation3.rpt", + (char *)"hotstart/Simulation3.out"); + swmm_start(0); + error = swmm_step(&elapsedTime); + BOOST_CHECK_EQUAL(ERR_NONE, error); + swmm_end(); + swmm_close(); +} + +BOOST_AUTO_TEST_SUITE_END() From b99ef3ffe5ac1d62c1554cb575ad8e2fb7dd1239 Mon Sep 17 00:00:00 2001 From: "Bryant E. McDonnell" Date: Sun, 11 Jun 2023 15:00:06 -0500 Subject: [PATCH 2/9] Added some precision tests --- tests/solver/test_toolkit_hotstart.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/solver/test_toolkit_hotstart.cpp b/tests/solver/test_toolkit_hotstart.cpp index f83e69174..2676017c2 100644 --- a/tests/solver/test_toolkit_hotstart.cpp +++ b/tests/solver/test_toolkit_hotstart.cpp @@ -49,9 +49,11 @@ BOOST_AUTO_TEST_SUITE(test_save_hotstart) BOOST_AUTO_TEST_CASE(save_hotstart_file){ int error, step_ind; + int index; int number_of_nodes; int y, m, d, h, mn, s; double elapsedTime = 0.0; + double read_val, set_val; // Start Simulation 1 swmm_open((char *)"hotstart/Simulation1.inp", @@ -113,6 +115,18 @@ BOOST_AUTO_TEST_CASE(save_hotstart_file){ (char *)"hotstart/Simulation3.rpt", (char *)"hotstart/Simulation3.out"); swmm_start(0); + // Iterate over nodes before stepping + error = swmm_countObjects(SM_NODE, &number_of_nodes); + for (index=0; index Date: Sun, 11 Jun 2023 15:18:45 -0500 Subject: [PATCH 3/9] Updated macos runner and attempting to fix windows build --- .github/workflows/build-test.yml | 12 ++++++------ tests/solver/test_toolkit_hotstart.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index c224b9e7d..598e7aaa6 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -20,7 +20,7 @@ jobs: strategy: fail-fast: false matrix: - os: [windows-2022, ubuntu-20.04, macos-10.15] + os: [windows-2022, ubuntu-20.04, macos-13.4] requirements: [requirements-swmm.txt] include: - os: windows-2022 @@ -58,9 +58,9 @@ jobs: shell: bash working-directory: ./ci-tools/linux - - os: macos-10.15 + - os: macos-13.4 sys_pkgs: brew install libomp #boost - boost_platform_version: 10.15 + boost_platform_version: 13.4 boost_toolsit: clang build_unit_test: make.zsh -t -g "Xcode" build_reg_test: make.zsh -g "Xcode" @@ -111,11 +111,11 @@ jobs: # install boost on mac and linux - name: Install required system packages on mac and linux run: ${{ matrix.sys_pkgs }} - if: ${{ runner.os == 'macOS' }} + if: ${{ runner.os == 'macOS' }} # boost takes a while to install on windows, so try to cache - name: Install boost - # if: ${{runner.os == 'Windows'}} + # if: ${{runner.os == 'Windows'}} uses: MarkusJx/install-boost@v2.4.4 id: install-boost with: @@ -123,7 +123,7 @@ jobs: # A list of supported versions can be found here: # https://github.com/MarkusJx/prebuilt-boost/blob/main/versions-manifest.json boost_version: 1.81.0 - link: shared + link: shared # OPTIONAL: Specify a custon install location # boost_install_dir: C:\some_directory # OPTIONAL: Specify a platform version diff --git a/tests/solver/test_toolkit_hotstart.cpp b/tests/solver/test_toolkit_hotstart.cpp index 2676017c2..19267dfe2 100644 --- a/tests/solver/test_toolkit_hotstart.cpp +++ b/tests/solver/test_toolkit_hotstart.cpp @@ -13,10 +13,10 @@ #include #include -#define HOTSTART_SWMM_SAVE_NORMAL "./hotstart/INFILE_Simulation1.hsf" -#define HOTSTART_API_SAVE_DURING_SIM1 "./hotstart/swmm_api_test_during_Simulation1.hsf" -#define HOTSTART_API_SAVE_AFTER_SIM1 "./hotstart/swmm_api_test_after_Simulation1.hsf" -#define HOTSTART_SWMM_SAVE_SIM2 "./hotstart/INFILE_Simulation2.hsf" +#define HOTSTART_SWMM_SAVE_NORMAL "hotstart/INFILE_Simulation1.hsf" +#define HOTSTART_API_SAVE_DURING_SIM1 "hotstart/swmm_api_test_during_Simulation1.hsf" +#define HOTSTART_API_SAVE_AFTER_SIM1 "hotstart/swmm_api_test_after_Simulation1.hsf" +#define HOTSTART_SWMM_SAVE_SIM2 "hotstart/INFILE_Simulation2.hsf" #define ERR_NONE 0 From 1c9b473df61d80818c817a25f2830ff151741347 Mon Sep 17 00:00:00 2001 From: "Bryant E. McDonnell" Date: Sun, 11 Jun 2023 16:48:23 -0500 Subject: [PATCH 4/9] Since reconfigured test to use public api functions. Never going to touch cmake again --- tests/solver/data/hotstart/Simulation3.inp | 2 +- tests/solver/test_solver.hpp | 1 - tests/solver/test_toolkit_hotstart.cpp | 30 +++++++++++++++------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/tests/solver/data/hotstart/Simulation3.inp b/tests/solver/data/hotstart/Simulation3.inp index c37bec2a0..e7c2eea28 100644 --- a/tests/solver/data/hotstart/Simulation3.inp +++ b/tests/solver/data/hotstart/Simulation3.inp @@ -40,7 +40,7 @@ LAT_FLOW_TOL 5 THREADS 1 [FILES] -USE HOTSTART swmm_api_test_after_Simulation1.hsf +USE HOTSTART swmm_api_test_during_Simulation1.hsf [EVAPORATION] ;;Data Source Parameters diff --git a/tests/solver/test_solver.hpp b/tests/solver/test_solver.hpp index 538c2ce74..e45e477b4 100644 --- a/tests/solver/test_solver.hpp +++ b/tests/solver/test_solver.hpp @@ -17,7 +17,6 @@ extern "C" { #include "swmm5.h" #include "toolkit.h" -#include "../headers.h" // Allows checking values directly in SWMM's data model. } // Add shared data paths here diff --git a/tests/solver/test_toolkit_hotstart.cpp b/tests/solver/test_toolkit_hotstart.cpp index 19267dfe2..ac259b529 100644 --- a/tests/solver/test_toolkit_hotstart.cpp +++ b/tests/solver/test_toolkit_hotstart.cpp @@ -51,7 +51,6 @@ BOOST_AUTO_TEST_CASE(save_hotstart_file){ int error, step_ind; int index; int number_of_nodes; - int y, m, d, h, mn, s; double elapsedTime = 0.0; double read_val, set_val; @@ -115,19 +114,32 @@ BOOST_AUTO_TEST_CASE(save_hotstart_file){ (char *)"hotstart/Simulation3.rpt", (char *)"hotstart/Simulation3.out"); swmm_start(0); + error = swmm_step(&elapsedTime); // Iterate over nodes before stepping error = swmm_countObjects(SM_NODE, &number_of_nodes); + // Known Values + std::vector hotstart_vals {0.0046, + 3.0, + 3.0, + 0.0117, + 0.0, + 0.0, + 0.0, + 0.0105, + 0.0, + 0.1209, + 0.0, + 0.0, + 0.0484, + 0.0}; + for (index=0; index Date: Fri, 16 Jun 2023 19:44:26 -0400 Subject: [PATCH 5/9] Added swmm_useHotstart() (for Abhi ;-) ) --- src/solver/include/toolkit.h | 12 +- src/solver/include/toolkit_error.h | 1 + src/solver/include/toolkit_errors.txt | 1 + src/solver/toolkit.c | 49 +++- .../hotstart/Simulation1_use_hot_start.inp | 215 ++++++++++++++++++ tests/solver/data/hotstart/Simulation3.inp | 2 +- .../data/hotstart/use_hot_start_test.hsf | Bin 0 -> 2059 bytes tests/solver/test_solver.hpp | 9 + tests/solver/test_toolkit.cpp | 18 ++ tests/solver/test_toolkit_hotstart.cpp | 101 +++++++- 10 files changed, 395 insertions(+), 13 deletions(-) create mode 100644 tests/solver/data/hotstart/Simulation1_use_hot_start.inp create mode 100644 tests/solver/data/hotstart/use_hot_start_test.hsf diff --git a/src/solver/include/toolkit.h b/src/solver/include/toolkit.h index 0a318c1d9..83e6e227d 100644 --- a/src/solver/include/toolkit.h +++ b/src/solver/include/toolkit.h @@ -612,11 +612,19 @@ EXPORT_TOOLKIT int swmm_setOutfallStage(int index, double stage); */ EXPORT_TOOLKIT int swmm_setGagePrecip(int index, double total_precip); +/** + @brief Use/override a hotstart file before the simulation starts. + @param hsfile The file name of the hot start file that the user would like to use. + @return Error code +*/ +EXPORT_TOOLKIT int swmm_useHotstart(const char *hsfile); + /** @brief Save hotstart file during simulation - @param hsfile The file name of the hotstart file that user would like to save + @param hsfile The file name of the hotstart file that the user would like to save. + @return Error code */ -EXPORT_TOOLKIT int swmm_saveHotstart(char *hsfile); +EXPORT_TOOLKIT int swmm_saveHotstart(const char *hsfile); /** @brief Helper function to free memory array allocated in SWMM. diff --git a/src/solver/include/toolkit_error.h b/src/solver/include/toolkit_error.h index 3f58128ec..29ead3b3f 100644 --- a/src/solver/include/toolkit_error.h +++ b/src/solver/include/toolkit_error.h @@ -14,6 +14,7 @@ enum ToolkitErrorType { ERR_TKAPI_UNDEFINED_LID = 2010, ERR_TKAPI_MEMORY = 2011, ERR_TKAPI_NO_INLET = 2012, + ERR_TKAPI_SIM_RUNNING = 2013, TKMAXERRMSG = 3000 }; diff --git a/src/solver/include/toolkit_errors.txt b/src/solver/include/toolkit_errors.txt index 4a9dd1f8e..1349f5a4b 100644 --- a/src/solver/include/toolkit_errors.txt +++ b/src/solver/include/toolkit_errors.txt @@ -13,3 +13,4 @@ ERR(2009, "\n API Key Error: Invalid Lid Unit Index") ERR(2010, "\n API Key Error: Undefined Subcatchment Lid") ERR(2011, "\n API Key Error: No memory allocated for return value") ERR(2012, "\n API Key Error: Specified link is not assigned an inlet") +ERR(2013, "\n API Key Error: Simulation Already Started or Running.") diff --git a/src/solver/toolkit.c b/src/solver/toolkit.c index d680486a5..fdc97f592 100644 --- a/src/solver/toolkit.c +++ b/src/solver/toolkit.c @@ -3096,7 +3096,35 @@ EXPORT_TOOLKIT int swmm_setGagePrecip(int index, double total_precip) return error_code; } -EXPORT_TOOLKIT int DLLEXPORT swmm_saveHotstart(char *hsfile) +EXPORT_TOOLKIT int DLLEXPORT swmm_useHotstart(const char *hsfile) +/// +/// Input: hotstart file ID name (able to overwrite) +/// Return API Error +/// Purpose: Allows selecting a HSF to use +{ + int error_code = 0; + // Check if Open + if(swmm_IsOpenFlag() == FALSE) + { + error_code = ERR_TKAPI_INPUTNOTOPEN; + } + // Check if Simulation is Running + else if (swmm_IsStartedFlag() == TRUE) + { + error_code = ERR_TKAPI_SIM_RUNNING; + } + else + { + // Fhotstart1 is the file to to be read + char fl_name[MAXFNAME]; + sstrncpy(fl_name, hsfile, MAXFNAME); + Fhotstart1.mode = USE_FILE; + sstrncpy(Fhotstart1.name, addAbsolutePath(fl_name), MAXFNAME); + } + return error_code; +} + +EXPORT_TOOLKIT int DLLEXPORT swmm_saveHotstart(const char *hsfile) /// /// Input: hotstart file ID name (able to overwrite) /// Return API Error @@ -3126,12 +3154,19 @@ EXPORT_TOOLKIT int DLLEXPORT swmm_saveHotstart(char *hsfile) Fhotstart2.mode = SAVE_FILE; sstrncpy(Fhotstart2.name, hsfile, MAXFNAME); // Saving Data - if (hotstart_open()) hotstart_close(); - // Replacing INP set HSFs - Fhotstart2 = tmpHotstart2; - Fhotstart1 = tmpHotstart1; - Fhotstart1.mode = _fl1_info; - Fhotstart2.mode = _fl2_info; + if (hotstart_open()) + { + hotstart_close(); + // Replacing INP set HSFs + Fhotstart2 = tmpHotstart2; + Fhotstart1 = tmpHotstart1; + Fhotstart1.mode = _fl1_info; + Fhotstart2.mode = _fl2_info; + } + else + { + error_code = ERR_HOTSTART_FILE_OPEN; + } } return error_code; } diff --git a/tests/solver/data/hotstart/Simulation1_use_hot_start.inp b/tests/solver/data/hotstart/Simulation1_use_hot_start.inp new file mode 100644 index 000000000..d3aba0d0b --- /dev/null +++ b/tests/solver/data/hotstart/Simulation1_use_hot_start.inp @@ -0,0 +1,215 @@ +[TITLE] +;;Project Title/Notes +Example 1 + +[OPTIONS] +;;Option Value +FLOW_UNITS CFS +INFILTRATION HORTON +FLOW_ROUTING DYNWAVE +LINK_OFFSETS DEPTH +MIN_SLOPE 0 +ALLOW_PONDING NO +SKIP_STEADY_STATE NO + +START_DATE 01/01/1998 +START_TIME 00:00:00 +REPORT_START_DATE 01/01/1998 +REPORT_START_TIME 00:00:00 +END_DATE 01/02/1998 +END_TIME 12:00:00 +SWEEP_START 1/1 +SWEEP_END 12/31 +DRY_DAYS 5 +REPORT_STEP 01:00:00 +WET_STEP 00:15:00 +DRY_STEP 01:00:00 +ROUTING_STEP 0:00:01 + +INERTIAL_DAMPING PARTIAL +NORMAL_FLOW_LIMITED BOTH +FORCE_MAIN_EQUATION H-W +VARIABLE_STEP 0.75 +LENGTHENING_STEP 0 +MIN_SURFAREA 0 +MAX_TRIALS 0 +HEAD_TOLERANCE 0 +SYS_FLOW_TOL 5 +LAT_FLOW_TOL 5 +;MINIMUM_STEP 0.5 +THREADS 1 + + +[EVAPORATION] +;;Data Source Parameters +;;-------------- ---------------- +CONSTANT 0.0 +DRY_ONLY NO + +[RAINGAGES] +;;Name Format Interval SCF Source +;;-------------- --------- ------ ------ ---------- +RG1 INTENSITY 1:00 1.0 TIMESERIES TS1 + +[SUBCATCHMENTS] +;;Name Rain Gage Outlet Area %Imperv Width %Slope CurbLen SnowPack +;;-------------- ---------------- ---------------- -------- -------- -------- -------- -------- ---------------- +1 RG1 9 10 50 500 0.01 0 +2 RG1 10 10 50 500 0.01 0 +3 RG1 13 5 50 500 0.01 0 +4 RG1 22 5 50 500 0.01 0 +5 RG1 15 15 50 500 0.01 0 +6 RG1 23 12 10 500 0.01 0 +7 RG1 19 4 10 500 0.01 0 +8 RG1 18 10 10 500 0.01 0 + +[SUBAREAS] +;;Subcatchment N-Imperv N-Perv S-Imperv S-Perv PctZero RouteTo PctRouted +;;-------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- +1 0.001 0.10 0.05 0.05 25 OUTLET +2 0.001 0.10 0.05 0.05 25 OUTLET +3 0.001 0.10 0.05 0.05 25 OUTLET +4 0.001 0.10 0.05 0.05 25 OUTLET +5 0.001 0.10 0.05 0.05 25 OUTLET +6 0.001 0.10 0.05 0.05 25 OUTLET +7 0.001 0.10 0.05 0.05 25 OUTLET +8 0.001 0.10 0.05 0.05 25 OUTLET + +[INFILTRATION] +;;Subcatchment MaxRate MinRate Decay DryTime MaxInfil +;;-------------- ---------- ---------- ---------- ---------- ---------- +1 0.35 0.25 4.14 0.50 0 +2 0.7 0.3 4.14 0.50 0 +3 0.7 0.3 4.14 0.50 0 +4 0.7 0.3 4.14 0.50 0 +5 0.7 0.3 4.14 0.50 0 +6 0.7 0.3 4.14 0.50 0 +7 0.7 0.3 4.14 0.50 0 +8 0.7 0.3 4.14 0.50 0 + +[JUNCTIONS] +;;Name Elevation MaxDepth InitDepth SurDepth Aponded +;;-------------- ---------- ---------- ---------- ---------- ---------- +9 1000 3 0 0 0 +10 995 3 0 0 0 +13 995 3 0 0 0 +14 990 3 0 0 0 +15 987 3 0 0 0 +16 985 3 0 0 0 +17 980 3 0 0 0 +19 1010 3 0 0 0 +20 1005 3 0 0 0 +21 990 3 0 0 0 +22 987 3 0 0 0 +23 990 3 0 0 0 +24 984 3 0 0 0 + +[OUTFALLS] +;;Name Elevation Type Stage Data Gated Route To +;;-------------- ---------- ---------- ---------------- -------- ---------------- +18 975 FREE NO + +[CONDUITS] +;;Name From Node To Node Length Roughness InOffset OutOffset InitFlow MaxFlow +;;-------------- ---------------- ---------------- ---------- ---------- ---------- ---------- ---------- ---------- +1 9 10 400 0.01 0 0 0 0 +4 19 20 200 0.01 0 0 0 0 +5 20 21 200 0.01 0 0 0 0 +6 10 21 400 0.01 0 1 0 0 +7 21 22 300 0.01 1 1 0 0 +8 22 16 300 0.01 0 0 0 0 +10 17 18 400 0.01 0 0 0 0 +11 13 14 400 0.01 0 0 0 0 +12 14 15 400 0.01 0 0 0 0 +13 15 16 400 0.01 0 0 0 0 +14 23 24 400 0.01 0 0 0 0 +15 16 24 100 0.01 0 0 0 0 +16 24 17 400 0.01 0 0 0 0 + +[XSECTIONS] +;;Link Shape Geom1 Geom2 Geom3 Geom4 Barrels Culvert +;;-------------- ------------ ---------------- ---------- ---------- ---------- ---------- ---------- +1 CIRCULAR 1.5 0 0 0 1 +4 CIRCULAR 1 0 0 0 1 +5 CIRCULAR 1 0 0 0 1 +6 CIRCULAR 1 0 0 0 1 +7 CIRCULAR 2 0 0 0 1 +8 CIRCULAR 2 0 0 0 1 +10 CIRCULAR 2 0 0 0 1 +11 CIRCULAR 1.5 0 0 0 1 +12 CIRCULAR 1.5 0 0 0 1 +13 CIRCULAR 1.5 0 0 0 1 +14 CIRCULAR 1 0 0 0 1 +15 CIRCULAR 2 0 0 0 1 +16 CIRCULAR 2 0 0 0 1 + +[POLLUTANTS] +;;Name Units Crain Cgw Crdii Kdecay SnowOnly Co-Pollutant Co-Frac Cdwf Cinit +;;-------------- ------ ---------- ---------- ---------- ---------- ---------- ---------------- ---------- ---------- ---------- +TSS MG/L 0.0 0.0 0 0.0 NO * 0.0 0 0 +Lead UG/L 0.0 0.0 0 0.0 NO TSS 0.2 0 0 + +[LANDUSES] +;; Sweeping Fraction Last +;;Name Interval Available Swept +;;-------------- ---------- ---------- ---------- +Residential +Undeveloped + +[COVERAGES] +;;Subcatchment Land Use Percent +;;-------------- ---------------- ---------- +1 Residential 100.00 +2 Residential 50.00 +2 Undeveloped 50.00 +3 Residential 100.00 +4 Residential 50.00 +4 Undeveloped 50.00 +5 Residential 100.00 +6 Undeveloped 100.00 +7 Undeveloped 100.00 +8 Undeveloped 100.00 + +[LOADINGS] +;;Subcatchment Pollutant Buildup +;;-------------- ---------------- ---------- + +[BUILDUP] +;;Land Use Pollutant Function Coeff1 Coeff2 Coeff3 Per Unit +;;-------------- ---------------- ---------- ---------- ---------- ---------- ---------- +Residential TSS SAT 50 0 2 AREA +Residential Lead NONE 0 0 0 AREA +Undeveloped TSS SAT 100 0 3 AREA +Undeveloped Lead NONE 0 0 0 AREA + +[WASHOFF] +;;Land Use Pollutant Function Coeff1 Coeff2 SweepRmvl BmpRmvl +;;-------------- ---------------- ---------- ---------- ---------- ---------- ---------- +Residential TSS EXP 0.1 1 0 0 +Residential Lead EMC 0 0 0 0 +Undeveloped TSS EXP 0.1 0.7 0 0 +Undeveloped Lead EMC 0 0 0 0 + +[TIMESERIES] +;;Name Date Time Value +;;-------------- ---------- ---------- ---------- +;RAINFALL +TS1 0:00 0.0 +TS1 1:00 0.25 +TS1 2:00 0.5 +TS1 3:00 0.8 +TS1 4:00 0.4 +TS1 5:00 0.1 +TS1 6:00 0.0 +TS1 27:00 0.0 +TS1 28:00 0.4 +TS1 29:00 0.2 +TS1 30:00 0.0 + +[REPORT] +;;Reporting Options +INPUT NO +CONTROLS NO +SUBCATCHMENTS ALL +NODES ALL +LINKS ALL diff --git a/tests/solver/data/hotstart/Simulation3.inp b/tests/solver/data/hotstart/Simulation3.inp index e7c2eea28..f0521e5a0 100644 --- a/tests/solver/data/hotstart/Simulation3.inp +++ b/tests/solver/data/hotstart/Simulation3.inp @@ -24,7 +24,7 @@ DRY_DAYS 5 REPORT_STEP 01:00:00 WET_STEP 00:15:00 DRY_STEP 01:00:00 -ROUTING_STEP 0:01:00 +ROUTING_STEP 0:00:01 INERTIAL_DAMPING PARTIAL NORMAL_FLOW_LIMITED BOTH diff --git a/tests/solver/data/hotstart/use_hot_start_test.hsf b/tests/solver/data/hotstart/use_hot_start_test.hsf new file mode 100644 index 0000000000000000000000000000000000000000..d57d38ed52d9ea631440eed1181b84aded5e5b22 GIT binary patch literal 2059 zcmWFz_w_Z^_3#e~4si?$G2vifU|<4bJ|O0WvVj!C?Ry&*p8U{YZ~7u(k4t5z{iZXg zN_ZYmv0v&hy>Iym7KegW3vNZ9+2sIIOAL@~U-Mt?h@L~$rLdV#=WsZn>$#rs=IphF zr5NJK>KdvZ;+2P~1*t=K|G8+D=Ra5`*xypiU&PqV;_xfzwlVXrtwfmzGIzzn($9Sh ztsUOZI&$cSlo*D-#n0Z_?^~3LAr8_D10Z*upIt7qtE0#PCWeg$sk`}~Y2NdwGW%*1 zpT{S*Hrq?2PrqTYqTl|v)ta}9}=9 ztNopjmK-_7KKqnS&J!1kPO#sa*5-X=5+BLw=l0ESh6m5-In+MXj!s{S8UB%d^8Xs` z8wk1!*+010Ab%>kZ0$RBBFFyqjJ#)QrSec>D z3~(s)c#@c8riIs?_}taul9cBt(2iF>$o*w2Gn8wO$J&2d{V(fSV}-riT=BG?$Nlz~ zzF70!^gU0q`&;wW->;qE?_i<2Q?=Vc6R-XF+;4cQaa+*NJiPir?w5L#an|~5rhT|x z^4^u-YwgP}&G=*~J;DCfg+GEE-4982zveTJjt2n&4lAxLzsVp?e)u2Q3`bUUf-%k2N0E_F0m?BbC2 zWwjkB+)O{0I!-*~;!tzR&Hns^5(kysGDjH|SBK|riS{7*FrCGY_dA;$OoAf8{09GR zj>b19I>;un+4{DGW%Eyh)n~Tvc6`e^&7rEq z+#Y0q-S2~rGxTRWJl&dUm!hO*e^7AFoy@csKzkePMPAo9tqS#WysT4cH_eR) ztWN(+y;J02A4hNdMGp5)LiCD#TJ2cT*XagvFIe6hn)o)EBDeSewbOnX;{w{KPL+y4oI#lFmMc50s) hotstart_vals {0.0046, + 3.0, + 3.0, + 0.0117, + 0.0, + 0.0, + 0.0, + 0.0105, + 0.0, + 0.1209, + 0.0, + 0.0, + 0.0484, + 0.0}; + + for (index=0; index Date: Fri, 16 Jun 2023 19:52:54 -0400 Subject: [PATCH 6/9] Cleaning unreferenced variable warnings --- tests/solver/test_toolkit_hotstart.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/solver/test_toolkit_hotstart.cpp b/tests/solver/test_toolkit_hotstart.cpp index f0f3fdbe4..754da0bac 100644 --- a/tests/solver/test_toolkit_hotstart.cpp +++ b/tests/solver/test_toolkit_hotstart.cpp @@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE(save_hotstart_file){ int index; int number_of_nodes; double elapsedTime = 0.0; - double read_val, set_val; + double set_val; // Start Simulation 1 swmm_open((char *)"hotstart/Simulation1.inp", @@ -148,11 +148,8 @@ BOOST_AUTO_TEST_CASE(save_hotstart_file){ BOOST_AUTO_TEST_CASE(use_hotstart_bad_file){ // Testing USE a bad hotstart file - int error, step_ind; - int index; - int number_of_nodes; + int error; double elapsedTime = 0.0; - double read_val, set_val; char fkid[] = "bad_hsf.hsf"; swmm_open((char *)"hotstart/Simulation1_use_hot_start.inp", @@ -168,10 +165,7 @@ BOOST_AUTO_TEST_CASE(use_hotstart_bad_file){ BOOST_AUTO_TEST_CASE(save_hotstart_file_fail){ int error, step_ind; - int index; - int number_of_nodes; double elapsedTime = 0.0; - double read_val, set_val; // Start Simulation 1 swmm_open((char *)"hotstart/Simulation1_use_hot_start.inp", @@ -197,11 +191,11 @@ BOOST_AUTO_TEST_CASE(save_hotstart_file_fail){ BOOST_AUTO_TEST_CASE(use_hotstart_file){ // Testing USE the new generated hotstart file - int error, step_ind; + int error; int index; int number_of_nodes; double elapsedTime = 0.0; - double read_val, set_val; + double set_val; char fkid[] = "use_hot_start_test.hsf"; swmm_open((char *)"hotstart/Simulation1_use_hot_start.inp", From dbe7ace21bea308e71702cff3cac9235367976d3 Mon Sep 17 00:00:00 2001 From: "Bryant E. McDonnell" Date: Mon, 26 Jun 2023 21:00:31 -0800 Subject: [PATCH 7/9] Simplified to a single function with enumerator to select --- src/solver/include/toolkit.h | 22 ++-- src/solver/include/toolkit_enums.h | 6 ++ src/solver/toolkit.c | 144 ++++++++++++------------- tests/solver/test_toolkit.cpp | 8 +- tests/solver/test_toolkit_hotstart.cpp | 10 +- 5 files changed, 92 insertions(+), 98 deletions(-) diff --git a/src/solver/include/toolkit.h b/src/solver/include/toolkit.h index 83e6e227d..bffc8b53c 100644 --- a/src/solver/include/toolkit.h +++ b/src/solver/include/toolkit.h @@ -99,6 +99,14 @@ EXPORT_TOOLKIT int swmm_getSimulationAnalysisSetting(SM_SimOption type, int *val */ EXPORT_TOOLKIT int swmm_getSimulationParam(SM_SimSetting type, double *value); +/** + @brief Use/override a hotstart file before the simulation starts. + @param type The property type code (see @ref SM_HotStart) + @param hsfile The file name of the hot start file that the user would like to use. + @return Error code +*/ +EXPORT_TOOLKIT int swmm_hotstart(SM_HotStart type, const char *hsfile); + /** @brief Gets Object Count @param type Option code (see @ref SM_ObjectType) @@ -612,20 +620,6 @@ EXPORT_TOOLKIT int swmm_setOutfallStage(int index, double stage); */ EXPORT_TOOLKIT int swmm_setGagePrecip(int index, double total_precip); -/** - @brief Use/override a hotstart file before the simulation starts. - @param hsfile The file name of the hot start file that the user would like to use. - @return Error code -*/ -EXPORT_TOOLKIT int swmm_useHotstart(const char *hsfile); - -/** - @brief Save hotstart file during simulation - @param hsfile The file name of the hotstart file that the user would like to save. - @return Error code -*/ -EXPORT_TOOLKIT int swmm_saveHotstart(const char *hsfile); - /** @brief Helper function to free memory array allocated in SWMM. @param array The pointer to the array diff --git a/src/solver/include/toolkit_enums.h b/src/solver/include/toolkit_enums.h index 651743b37..47d2b57b5 100644 --- a/src/solver/include/toolkit_enums.h +++ b/src/solver/include/toolkit_enums.h @@ -92,6 +92,12 @@ typedef enum { SM_LATFLOWTOL = 13 /**< Tolerance for steady nodal inflow */ } SM_SimSetting; +/// Hot Start File Manager +typedef enum { + SM_HOTSTART_USE = 0, /**< Use Hotstart File */ + SM_HOTSTART_SAVE = 1 /**< Save Hotstart File */ +} SM_HotStart; + /// Node property codes typedef enum { SM_INVERTEL = 0, /**< Invert Elevation */ diff --git a/src/solver/toolkit.c b/src/solver/toolkit.c index fdc97f592..a99bfb67e 100644 --- a/src/solver/toolkit.c +++ b/src/solver/toolkit.c @@ -412,6 +412,75 @@ EXPORT_TOOLKIT int swmm_getSimulationParam(SM_SimSetting type, double *value) return error_code; } +EXPORT_TOOLKIT int DLLEXPORT swmm_hotstart(SM_HotStart type, const char *hsfile) +/// +/// Input: type = Hotstart option USE/SAVE (SM_HotStart) +/// hotstart = file ID name (able to overwrite) +/// Return API Error +/// Purpose: Allows selecting a HSF to use or save +{ + int error_code = 0; + // Check if Open + if(swmm_IsOpenFlag() == FALSE) + { + error_code = ERR_TKAPI_INPUTNOTOPEN; + } + // Check if Simulation is Started + else if (swmm_IsStartedFlag() == TRUE && type == SM_HOTSTART_USE) + { + error_code = ERR_TKAPI_SIM_RUNNING; + } + // Check if Simulation is NOT started + else if (swmm_IsStartedFlag() == FALSE && type == SM_HOTSTART_SAVE) + { + error_code = ERR_TKAPI_SIM_NRUNNING; + } + else + { + switch(type) + { + case SM_HOTSTART_USE: + { + // Fhotstart1 is the file to to be read + char fl_name[MAXFNAME]; + sstrncpy(fl_name, hsfile, MAXFNAME); + Fhotstart1.mode = USE_FILE; + sstrncpy(Fhotstart1.name, addAbsolutePath(fl_name), MAXFNAME); + break; + } + case SM_HOTSTART_SAVE: + { + // Storing Existing INP set HSFs + TFile tmpHotstart1 = Fhotstart1; + TFile tmpHotstart2 = Fhotstart2; + int _fl1_info = Fhotstart1.mode; + int _fl2_info = Fhotstart2.mode; + // Create info for New HSF + Fhotstart1.mode = NO_FILE; + Fhotstart2.mode = SAVE_FILE; + sstrncpy(Fhotstart2.name, hsfile, MAXFNAME); + // Saving Data + if (hotstart_open()) + { + hotstart_close(); + // Replacing INP set HSFs + Fhotstart2 = tmpHotstart2; + Fhotstart1 = tmpHotstart1; + Fhotstart1.mode = _fl1_info; + Fhotstart2.mode = _fl2_info; + } + else + { + error_code = ERR_HOTSTART_FILE_OPEN; + } + break; + } + default: error_code = ERR_TKAPI_OUTBOUNDS; break; + } + } + return error_code; +} + EXPORT_TOOLKIT int swmm_countObjects(SM_ObjectType type, int *count) /// /// Input: type = object type (Based on SM_ObjectType enum) @@ -3096,81 +3165,6 @@ EXPORT_TOOLKIT int swmm_setGagePrecip(int index, double total_precip) return error_code; } -EXPORT_TOOLKIT int DLLEXPORT swmm_useHotstart(const char *hsfile) -/// -/// Input: hotstart file ID name (able to overwrite) -/// Return API Error -/// Purpose: Allows selecting a HSF to use -{ - int error_code = 0; - // Check if Open - if(swmm_IsOpenFlag() == FALSE) - { - error_code = ERR_TKAPI_INPUTNOTOPEN; - } - // Check if Simulation is Running - else if (swmm_IsStartedFlag() == TRUE) - { - error_code = ERR_TKAPI_SIM_RUNNING; - } - else - { - // Fhotstart1 is the file to to be read - char fl_name[MAXFNAME]; - sstrncpy(fl_name, hsfile, MAXFNAME); - Fhotstart1.mode = USE_FILE; - sstrncpy(Fhotstart1.name, addAbsolutePath(fl_name), MAXFNAME); - } - return error_code; -} - -EXPORT_TOOLKIT int DLLEXPORT swmm_saveHotstart(const char *hsfile) -/// -/// Input: hotstart file ID name (able to overwrite) -/// Return API Error -/// Purpose: Allows hot start files to be created during a simulation -/// at any time. -{ - int error_code = 0; - // Check if Open - if(swmm_IsOpenFlag() == FALSE) - { - error_code = ERR_TKAPI_INPUTNOTOPEN; - } - // Check if Simulation is Running - else if (swmm_IsStartedFlag() == FALSE) - { - error_code = ERR_TKAPI_SIM_NRUNNING; - } - else - { - // Storing Existing INP set HSFs - TFile tmpHotstart1 = Fhotstart1; - TFile tmpHotstart2 = Fhotstart2; - int _fl1_info = Fhotstart1.mode; - int _fl2_info = Fhotstart2.mode; - // Create info for New HSF - Fhotstart1.mode = NO_FILE; - Fhotstart2.mode = SAVE_FILE; - sstrncpy(Fhotstart2.name, hsfile, MAXFNAME); - // Saving Data - if (hotstart_open()) - { - hotstart_close(); - // Replacing INP set HSFs - Fhotstart2 = tmpHotstart2; - Fhotstart1 = tmpHotstart1; - Fhotstart1.mode = _fl1_info; - Fhotstart2.mode = _fl2_info; - } - else - { - error_code = ERR_HOTSTART_FILE_OPEN; - } - } - return error_code; -} - EXPORT_TOOLKIT void swmm_freeMemory(void *memory) // // Purpose: Frees memory allocated by API calls diff --git a/tests/solver/test_toolkit.cpp b/tests/solver/test_toolkit.cpp index 3ee5e2c68..b6a35d062 100644 --- a/tests/solver/test_toolkit.cpp +++ b/tests/solver/test_toolkit.cpp @@ -42,9 +42,9 @@ BOOST_AUTO_TEST_CASE(model_not_open) { //Project error = swmm_getObjectIndex(SM_NODE, id, &index); BOOST_CHECK_EQUAL(error, ERR_TKAPI_INPUTNOTOPEN); - error = swmm_useHotstart(id); + error = swmm_hotstart(SM_HOTSTART_USE, id); BOOST_CHECK_EQUAL(error, ERR_TKAPI_INPUTNOTOPEN); - error = swmm_saveHotstart(id); + error = swmm_hotstart(SM_HOTSTART_SAVE, id); BOOST_CHECK_EQUAL(error, ERR_TKAPI_INPUTNOTOPEN); //Gage @@ -118,7 +118,7 @@ BOOST_FIXTURE_TEST_CASE(sim_before_start, FixtureBeforeStart_TKAPI) { int error; char fakehsf[] = "FakeHSF.hsf"; - error = swmm_saveHotstart(fakehsf); + error = swmm_hotstart(SM_HOTSTART_SAVE, fakehsf); BOOST_CHECK_EQUAL(error, ERR_TKAPI_SIM_NRUNNING); } @@ -128,7 +128,7 @@ BOOST_FIXTURE_TEST_CASE(sim_started_check, FixtureBeforeStep) { char fakehsf[] = "FakeHSF.hsf"; //Project - error = swmm_useHotstart(fakehsf); + error = swmm_hotstart(SM_HOTSTART_USE, fakehsf); BOOST_CHECK_EQUAL(error, ERR_TKAPI_SIM_RUNNING); //Subcatchment error = swmm_setSubcatchParam(0, SM_WIDTH, 1); diff --git a/tests/solver/test_toolkit_hotstart.cpp b/tests/solver/test_toolkit_hotstart.cpp index 754da0bac..7b0ab0aac 100644 --- a/tests/solver/test_toolkit_hotstart.cpp +++ b/tests/solver/test_toolkit_hotstart.cpp @@ -67,13 +67,13 @@ BOOST_AUTO_TEST_CASE(save_hotstart_file){ step_ind += 1; if (step_ind == 1056) { - error = swmm_saveHotstart((char *) HOTSTART_API_SAVE_DURING_SIM1); + error = swmm_hotstart(SM_HOTSTART_SAVE, (char *) HOTSTART_API_SAVE_DURING_SIM1); BOOST_CHECK_EQUAL(ERR_NONE, error); } }while (elapsedTime != 0 && !error); BOOST_CHECK_EQUAL(ERR_NONE, error); // Save New Hotstart File at the End of the Simulation - error = swmm_saveHotstart((char *) HOTSTART_API_SAVE_AFTER_SIM1); + error = swmm_hotstart(SM_HOTSTART_SAVE, (char *) HOTSTART_API_SAVE_AFTER_SIM1); BOOST_CHECK_EQUAL(ERR_NONE, error); swmm_end(); swmm_report(); @@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(use_hotstart_bad_file){ swmm_open((char *)"hotstart/Simulation1_use_hot_start.inp", (char *)"hotstart/Simulation1_use_hot_start_fail.rpt", (char *)"hotstart/Simulation1_use_hot_start_fail.out"); - error = swmm_useHotstart(fkid); + error = swmm_hotstart(SM_HOTSTART_USE, fkid); BOOST_CHECK_EQUAL(ERR_NONE, error); error = swmm_start(0); BOOST_CHECK_EQUAL(ERR_HOTSTART_FILE_OPEN, error); @@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(save_hotstart_file_fail){ step_ind += 1; if (step_ind == 2) { - error = swmm_saveHotstart((char *) ""); + error = swmm_hotstart(SM_HOTSTART_SAVE, (char *) ""); BOOST_CHECK_EQUAL(ERR_HOTSTART_FILE_OPEN, error); } }while (elapsedTime != 0 && !error); @@ -201,7 +201,7 @@ BOOST_AUTO_TEST_CASE(use_hotstart_file){ swmm_open((char *)"hotstart/Simulation1_use_hot_start.inp", (char *)"hotstart/Simulation1_use_hot_start.rpt", (char *)"hotstart/Simulation1_use_hot_start.out"); - error = swmm_useHotstart(fkid); + error = swmm_hotstart(SM_HOTSTART_USE, fkid); BOOST_CHECK_EQUAL(ERR_NONE, error); error = swmm_start(0); BOOST_CHECK_EQUAL(ERR_NONE, error); From 53bcb8f2282a3e8178b063139de9dadd59a8c6f7 Mon Sep 17 00:00:00 2001 From: "Bryant E. McDonnell" Date: Mon, 26 Jun 2023 21:02:46 -0800 Subject: [PATCH 8/9] Strip trailing white space --- src/solver/toolkit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/solver/toolkit.c b/src/solver/toolkit.c index a99bfb67e..eb9fab49f 100644 --- a/src/solver/toolkit.c +++ b/src/solver/toolkit.c @@ -440,7 +440,7 @@ EXPORT_TOOLKIT int DLLEXPORT swmm_hotstart(SM_HotStart type, const char *hsfile) switch(type) { case SM_HOTSTART_USE: - { + { // Fhotstart1 is the file to to be read char fl_name[MAXFNAME]; sstrncpy(fl_name, hsfile, MAXFNAME); @@ -460,7 +460,7 @@ EXPORT_TOOLKIT int DLLEXPORT swmm_hotstart(SM_HotStart type, const char *hsfile) Fhotstart2.mode = SAVE_FILE; sstrncpy(Fhotstart2.name, hsfile, MAXFNAME); // Saving Data - if (hotstart_open()) + if (hotstart_open()) { hotstart_close(); // Replacing INP set HSFs From 836ee804d8b3c3799160cc55ec15e9f174c53123 Mon Sep 17 00:00:00 2001 From: "Bryant E. McDonnell" Date: Wed, 12 Jul 2023 09:27:21 -0400 Subject: [PATCH 9/9] Addressing Comments --- src/solver/toolkit.c | 4 ++-- tests/solver/test_toolkit_hotstart.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/solver/toolkit.c b/src/solver/toolkit.c index eb9fab49f..3bac99911 100644 --- a/src/solver/toolkit.c +++ b/src/solver/toolkit.c @@ -412,7 +412,7 @@ EXPORT_TOOLKIT int swmm_getSimulationParam(SM_SimSetting type, double *value) return error_code; } -EXPORT_TOOLKIT int DLLEXPORT swmm_hotstart(SM_HotStart type, const char *hsfile) +EXPORT_TOOLKIT int swmm_hotstart(SM_HotStart type, const char *hsfile) /// /// Input: type = Hotstart option USE/SAVE (SM_HotStart) /// hotstart = file ID name (able to overwrite) @@ -445,7 +445,7 @@ EXPORT_TOOLKIT int DLLEXPORT swmm_hotstart(SM_HotStart type, const char *hsfile) char fl_name[MAXFNAME]; sstrncpy(fl_name, hsfile, MAXFNAME); Fhotstart1.mode = USE_FILE; - sstrncpy(Fhotstart1.name, addAbsolutePath(fl_name), MAXFNAME); + sstrncpy(Fhotstart1.name, fl_name, MAXFNAME); break; } case SM_HOTSTART_SAVE: diff --git a/tests/solver/test_toolkit_hotstart.cpp b/tests/solver/test_toolkit_hotstart.cpp index 7b0ab0aac..617c17269 100644 --- a/tests/solver/test_toolkit_hotstart.cpp +++ b/tests/solver/test_toolkit_hotstart.cpp @@ -196,7 +196,7 @@ BOOST_AUTO_TEST_CASE(use_hotstart_file){ int number_of_nodes; double elapsedTime = 0.0; double set_val; - char fkid[] = "use_hot_start_test.hsf"; + char fkid[] = "hotstart/use_hot_start_test.hsf"; swmm_open((char *)"hotstart/Simulation1_use_hot_start.inp", (char *)"hotstart/Simulation1_use_hot_start.rpt",