Skip to content

Commit

Permalink
WIP API and bindings unit testing; cleaning up #204, #162, #163, #184,
Browse files Browse the repository at this point in the history
  • Loading branch information
cbuahin committed Dec 22, 2024
1 parent 8e3dca2 commit 14e0a0a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/solver/lid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,8 @@ double getImpervAreaRunoff(int j)
{
q *= Subcatch[j].subArea[IMPERV0].fOutlet;
}
nonLidArea = max(0.0, Subcatch[j].area - Subcatch[j].lidArea);
nonLidArea = Subcatch[j].area - Subcatch[j].lidArea;
nonLidArea = 0.0 < nonLidArea ? 0.0 : nonLidArea;
return q * nonLidArea;
}

Expand Down
3 changes: 2 additions & 1 deletion src/solver/qualrout.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ void findNodeQual(int j)

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

Expand Down
3 changes: 2 additions & 1 deletion src/solver/subcatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,8 @@ double subcatch_getRunoff(int j, double tStep)
// --- find volume of inflow to non-LID portion of subcatchment as existing
// ponded water + any runon volume from upstream areas;
// rainfall and snowmelt will be added as each sub-area is analyzed
nonLidArea = max(0.0, Subcatch[j].area - Subcatch[j].lidArea);
nonLidArea = Subcatch[j].area - Subcatch[j].lidArea;
nonLidArea = nonLidArea < 0.0 ? 0.0 : nonLidArea;
vRunon = Subcatch[j].runon * tStep * nonLidArea;
Vinflow = vRunon + subcatch_getDepth(j) * nonLidArea;

Expand Down
3 changes: 2 additions & 1 deletion src/solver/surfqual.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ void surfqual_getBuildup(int j, double tStep)
newBuildup = MAX(newBuildup, oldBuildup);

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

Subcatch[j].landFactor[i].buildup[p] = newBuildup;
massbal_updateLoadingTotals(BUILDUP_LOAD, p,
Expand Down
18 changes: 9 additions & 9 deletions src/solver/swmm5.c
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ double getSubcatchValue(int property, int index, int subIndex)
case swmm_SUBCATCH_POLLUTANT_PONDED_CONCENTRATION:
if (subIndex < 0 || subIndex >= Nobjects[POLLUT])
return ERR_API_OBJECT_INDEX;
return subcatch->pondedQual[subIndex] / (subcatch_getDepth(index) * max(0.0, subcatch->area - subcatch->lidArea) * UCF(LANDAREA));
return subcatch->pondedQual[subIndex] / (subcatch_getDepth(index) * MAX(0.0, subcatch->area - subcatch->lidArea) * UCF(LANDAREA));

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

if (IsStartedFlag)
return ERR_API_NOT_ENDED;
Expand All @@ -2265,9 +2265,9 @@ int setSystemValue(int property, double value)
case swmm_STARTDATE:
StartDateTime = value;
datetime_decodeDate(value, &y, &m, &d);
datetime_decodeTime(value, &h, &min, &s);
datetime_decodeTime(value, &h, &mm, &s);
StartDate = datetime_encodeDate(y, m, d);
StartTime = datetime_encodeTime(h, min, s);
StartTime = datetime_encodeTime(h, mm, s);
TotalDuration = floor((EndDate - StartDate) * SECperDAY + (EndTime - StartTime) * SECperDAY);
// convert total duration to milliseconds
TotalDuration *= 1000.0;
Expand All @@ -2293,23 +2293,23 @@ int setSystemValue(int property, double value)
case swmm_ENDDATE:
EndDateTime = value;
datetime_decodeDate(value, &y, &m, &d);
datetime_decodeTime(value, &h, &min, &s);
datetime_decodeTime(value, &h, &mm, &s);
EndDate = datetime_encodeDate(y, m, d);
EndTime = datetime_encodeTime(h, min, s);
EndTime = datetime_encodeTime(h, mm, s);
TotalDuration = floor((EndDate - StartDate) * SECperDAY + (EndTime - StartTime) * SECperDAY);
// convert total duration to milliseconds
TotalDuration *= 1000.0;
return 0;
case swmm_REPORTSTART:
ReportStart = value;
datetime_decodeDate(value, &y, &m, &d);
datetime_decodeTime(value, &h, &min, &s);
datetime_decodeTime(value, &h, &mm, &s);
ReportStartDate = datetime_encodeDate(y, m, d);
ReportStartTime = datetime_encodeTime(h, min, s);
ReportStartTime = datetime_encodeTime(h, mm, s);
return 0;
case swmm_NUMTHREADS:
// possible over allocation of threads but we trust the user to know what they are doing. Limit to max threads.
NumThreads = max(1, min((int)value, omp_get_max_threads()));
NumThreads = MAX(1, MIN((int)value, omp_get_max_threads()));
return 0;
case swmm_SURCHARGEMETHOD:
if (value >= EXTRAN && value <= SLOT)
Expand Down
2 changes: 1 addition & 1 deletion tests/solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Test solver api
add_executable(
test_solver
test_solver_api
test_solver_api.cpp
)

Expand Down

0 comments on commit 14e0a0a

Please sign in to comment.