Skip to content

Commit

Permalink
Merge pull request #93 from bemcdonnell/outfallloadfix
Browse files Browse the repository at this point in the history
Node Total Inflow Volume
  • Loading branch information
bemcdonnell authored Sep 20, 2017
2 parents 8e81d00 + a781aa4 commit 2655e99
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ double massbal_getFlowError(void);
int massbal_getRoutingFlowTotal(TRoutingTotals *routingTot); // For API
int massbal_getRunoffTotal(TRunoffTotals *runoffTot); // For API
double massbal_getTotalArea(void); // For API
int massbal_getNodeTotalInflow(int index, double *value); // For API

//-----------------------------------------------------------------------------
// Simulation Statistics Methods
Expand Down
26 changes: 26 additions & 0 deletions src/massbal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,4 +1150,30 @@ double massbal_getTotalArea(void)
// Purpose: Used for Toolkit API Unit Conversion
{
return TotalArea;
}

int massbal_getNodeTotalInflow(int index, double *value)
//
// Input: NodeIndex
// Output: Volume
// Return: Error
// Purpose: Used for ToolkitAPI to pull total Node Inflow.
{
int errorcode = 0;

// Check if Open
if (swmm_IsOpenFlag() == FALSE)
{
errorcode = ERR_API_INPUTNOTOPEN;
}
// Check if Simulation is Running
else if (swmm_IsStartedFlag() == FALSE)
{
errorcode = ERR_API_SIM_NRUNNING;
}
else
{
*value = NodeInflow[index];
}
return errorcode;
}
40 changes: 36 additions & 4 deletions src/toolkitAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ int DLLEXPORT swmm_getNodeStats(int index, TNodeStats *nodeStats)
if (errorcode == 0)
{
// Current Average Depth
nodeStats->avgDepth *= (UCF(LENGTH) / StepCount);
nodeStats->avgDepth *= (UCF(LENGTH) / (double)StepCount);
// Current Maximum Depth
nodeStats->maxDepth *= UCF(LENGTH);
// Current Maximum Lateral Inflow
Expand All @@ -800,6 +800,24 @@ int DLLEXPORT swmm_getNodeStats(int index, TNodeStats *nodeStats)
return (errorcode);
}

int DLLEXPORT swmm_getNodeTotalInflow(int index, double *value)
//
// Input: Node Index
// Output: Node Total inflow Volume.
// Return: API Error
// Purpose: Get Node Total Inflow Volume.
{

int errorcode = massbal_getNodeTotalInflow(index, value);

if (errorcode == 0)
{
*value *= UCF(VOLUME);
}

return(errorcode);
}

int DLLEXPORT swmm_getStorageStats(int index, TStorageStats *storageStats)
//
// Output: Storage Node Stats Structure (TStorageStats)
Expand All @@ -813,7 +831,7 @@ int DLLEXPORT swmm_getStorageStats(int index, TStorageStats *storageStats)
// Initial Volume
storageStats->initVol *= UCF(VOLUME);
// Current Average Volume
storageStats->avgVol *= (UCF(VOLUME) / StepCount);
storageStats->avgVol *= (UCF(VOLUME) / (double)StepCount);
// Current Maximum Volume
storageStats->maxVol *= UCF(VOLUME);
// Current Maximum Flow
Expand Down Expand Up @@ -841,7 +859,14 @@ int DLLEXPORT swmm_getOutfallStats(int index, TOutfallStats *outfallStats)
if (errorcode == 0)
{
// Current Average Flow
outfallStats->avgFlow *= (UCF(FLOW) / StepCount);
if ( outfallStats->totalPeriods > 0 )
{
outfallStats->avgFlow *= (UCF(FLOW) / (double)outfallStats->totalPeriods);
}
else
{
outfallStats->avgFlow *= 0.0;
}
// Current Maximum Flow
outfallStats->maxFlow *= UCF(FLOW);
// Convert Mass Units
Expand Down Expand Up @@ -922,7 +947,14 @@ int DLLEXPORT swmm_getPumpStats(int index, TPumpStats *pumpStats)
// Cumulative Minimum Flow
pumpStats->minFlow *= UCF(FLOW);
// Cumulative Average Flow
pumpStats->avgFlow *= (UCF(FLOW) / StepCount);
if (pumpStats->totalPeriods > 0)
{
pumpStats->avgFlow *= (UCF(FLOW) / (double)pumpStats->totalPeriods);
}
else
{
pumpStats->avgFlow *= 0.0;
}
// Cumulative Maximum Flow
pumpStats->maxFlow *= UCF(FLOW);
// Cumulative Pumping Volume
Expand Down
1 change: 1 addition & 0 deletions src/toolkitAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ int DLLEXPORT swmm_setSimulationDateTime(int timetype, char *dtimestr);
int DLLEXPORT swmm_getCurrentDateTimeStr(char *dtimestr);

int DLLEXPORT swmm_getNodeStats(int index, TNodeStats *nodeStats);
int DLLEXPORT swmm_getNodeTotalInflow(int index, double *value);
int DLLEXPORT swmm_getStorageStats(int index, TStorageStats *storageStats);
int DLLEXPORT swmm_getOutfallStats(int index, TOutfallStats *outfallStats);
void DLLEXPORT swmm_freeOutfallStats(TOutfallStats *outfallStats);
Expand Down

0 comments on commit 2655e99

Please sign in to comment.