Skip to content

Commit 14e0a0a

Browse files
committed
WIP API and bindings unit testing; cleaning up #204, #162, #163, #184, #180
1 parent 8e3dca2 commit 14e0a0a

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

src/solver/lid.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,8 @@ double getImpervAreaRunoff(int j)
17891789
{
17901790
q *= Subcatch[j].subArea[IMPERV0].fOutlet;
17911791
}
1792-
nonLidArea = max(0.0, Subcatch[j].area - Subcatch[j].lidArea);
1792+
nonLidArea = Subcatch[j].area - Subcatch[j].lidArea;
1793+
nonLidArea = 0.0 < nonLidArea ? 0.0 : nonLidArea;
17931794
return q * nonLidArea;
17941795
}
17951796

src/solver/qualrout.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ void findNodeQual(int j)
250250

251251
// --- Calculate bounded externally provided api pollutant flux and update mass balance
252252
// --- Positive fluxes are added in the addExternalInflows function in routing.c (This really needs to be refactored for consistency)
253-
cOut = min(cIn, max(0.0, -Node[j].apiExtQualMassFlux[p] / qNode));
253+
cOut = -Node[j].apiExtQualMassFlux[p] / qNode;
254+
cOut = cOut < 0.0 ? 0.0 : cOut > cIn ? cIn : cOut;
254255
cIn -= cOut;
255256
massbal_addOutflowQual(p, cOut * qNode, FALSE);
256257

src/solver/subcatch.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,8 @@ double subcatch_getRunoff(int j, double tStep)
675675
// --- find volume of inflow to non-LID portion of subcatchment as existing
676676
// ponded water + any runon volume from upstream areas;
677677
// rainfall and snowmelt will be added as each sub-area is analyzed
678-
nonLidArea = max(0.0, Subcatch[j].area - Subcatch[j].lidArea);
678+
nonLidArea = Subcatch[j].area - Subcatch[j].lidArea;
679+
nonLidArea = nonLidArea < 0.0 ? 0.0 : nonLidArea;
679680
vRunon = Subcatch[j].runon * tStep * nonLidArea;
680681
Vinflow = vRunon + subcatch_getDepth(j) * nonLidArea;
681682

src/solver/surfqual.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ void surfqual_getBuildup(int j, double tStep)
128128
newBuildup = MAX(newBuildup, oldBuildup);
129129

130130
//--- add bounded building from external API
131-
newBuildup = max(0.0, newBuildup + Subcatch[j].apiExtBuildup[p] * area);
131+
newBuildup = newBuildup + Subcatch[j].apiExtBuildup[p] * area;
132+
newBuildup = newBuildup < 0.0 ? 0.0 : newBuildup;
132133

133134
Subcatch[j].landFactor[i].buildup[p] = newBuildup;
134135
massbal_updateLoadingTotals(BUILDUP_LOAD, p,

src/solver/swmm5.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ double getSubcatchValue(int property, int index, int subIndex)
17351735
case swmm_SUBCATCH_POLLUTANT_PONDED_CONCENTRATION:
17361736
if (subIndex < 0 || subIndex >= Nobjects[POLLUT])
17371737
return ERR_API_OBJECT_INDEX;
1738-
return subcatch->pondedQual[subIndex] / (subcatch_getDepth(index) * max(0.0, subcatch->area - subcatch->lidArea) * UCF(LANDAREA));
1738+
return subcatch->pondedQual[subIndex] / (subcatch_getDepth(index) * MAX(0.0, subcatch->area - subcatch->lidArea) * UCF(LANDAREA));
17391739

17401740
case swmm_SUBCATCH_POLLUTANT_TOTAL_LOAD:
17411741
if (subIndex < 0 || subIndex >= Nobjects[POLLUT])
@@ -2255,7 +2255,7 @@ int setSystemValue(int property, double value)
22552255
// Output: returns an error code
22562256
// Purpose: sets the value of a system property.
22572257
{
2258-
int y, m, d, h, min, s;
2258+
int y, m, d, h, mm, s;
22592259

22602260
if (IsStartedFlag)
22612261
return ERR_API_NOT_ENDED;
@@ -2265,9 +2265,9 @@ int setSystemValue(int property, double value)
22652265
case swmm_STARTDATE:
22662266
StartDateTime = value;
22672267
datetime_decodeDate(value, &y, &m, &d);
2268-
datetime_decodeTime(value, &h, &min, &s);
2268+
datetime_decodeTime(value, &h, &mm, &s);
22692269
StartDate = datetime_encodeDate(y, m, d);
2270-
StartTime = datetime_encodeTime(h, min, s);
2270+
StartTime = datetime_encodeTime(h, mm, s);
22712271
TotalDuration = floor((EndDate - StartDate) * SECperDAY + (EndTime - StartTime) * SECperDAY);
22722272
// convert total duration to milliseconds
22732273
TotalDuration *= 1000.0;
@@ -2293,23 +2293,23 @@ int setSystemValue(int property, double value)
22932293
case swmm_ENDDATE:
22942294
EndDateTime = value;
22952295
datetime_decodeDate(value, &y, &m, &d);
2296-
datetime_decodeTime(value, &h, &min, &s);
2296+
datetime_decodeTime(value, &h, &mm, &s);
22972297
EndDate = datetime_encodeDate(y, m, d);
2298-
EndTime = datetime_encodeTime(h, min, s);
2298+
EndTime = datetime_encodeTime(h, mm, s);
22992299
TotalDuration = floor((EndDate - StartDate) * SECperDAY + (EndTime - StartTime) * SECperDAY);
23002300
// convert total duration to milliseconds
23012301
TotalDuration *= 1000.0;
23022302
return 0;
23032303
case swmm_REPORTSTART:
23042304
ReportStart = value;
23052305
datetime_decodeDate(value, &y, &m, &d);
2306-
datetime_decodeTime(value, &h, &min, &s);
2306+
datetime_decodeTime(value, &h, &mm, &s);
23072307
ReportStartDate = datetime_encodeDate(y, m, d);
2308-
ReportStartTime = datetime_encodeTime(h, min, s);
2308+
ReportStartTime = datetime_encodeTime(h, mm, s);
23092309
return 0;
23102310
case swmm_NUMTHREADS:
23112311
// possible over allocation of threads but we trust the user to know what they are doing. Limit to max threads.
2312-
NumThreads = max(1, min((int)value, omp_get_max_threads()));
2312+
NumThreads = MAX(1, MIN((int)value, omp_get_max_threads()));
23132313
return 0;
23142314
case swmm_SURCHARGEMETHOD:
23152315
if (value >= EXTRAN && value <= SLOT)

tests/solver/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# Test solver api
1111
add_executable(
12-
test_solver
12+
test_solver_api
1313
test_solver_api.cpp
1414
)
1515

0 commit comments

Comments
 (0)