Skip to content

Commit 2e5b21d

Browse files
authored
Merge pull request #389 from OpenWaterAnalytics/init_inlet_api
2 parents b4ddb51 + 8e3a171 commit 2e5b21d

11 files changed

+862
-32
lines changed

src/solver/include/toolkit.h

+30
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "../enums.h"
2626
#include "../datetime.h"
2727
#include "../lid.h"
28+
#include "../inlet.h"
2829

2930
#ifdef __cplusplus
3031
extern "C" {
@@ -312,6 +313,24 @@ EXPORT_TOOLKIT int swmm_getLinkParam(int index, SM_LinkProperty param, double *v
312313
*/
313314
EXPORT_TOOLKIT int swmm_setLinkParam(int index, SM_LinkProperty param, double value);
314315

316+
/**
317+
@brief Get a property value for the inlets of a specified link.
318+
@param index The index of a link
319+
@param Param The property type code (See @ref SM_InletProperty)
320+
@param[out] value The value of the inlet's property
321+
@return Error code
322+
*/
323+
EXPORT_TOOLKIT int swmm_getInletParam(int index, SM_InletProperty param, double *value);
324+
325+
/**
326+
@brief Set a property value for the inlets of a specified link.
327+
@param index The index of a link
328+
@param Param The property type code (See @ref SM_InletProperty)
329+
@param value The new value of the inlet's property
330+
@return Error code
331+
*/
332+
EXPORT_TOOLKIT int swmm_setInletParam(int index, SM_InletProperty param, double value);
333+
315334
/**
316335
@brief Get a property value for specified subcatchment.
317336
@param index The index of a subcatchment
@@ -421,6 +440,17 @@ EXPORT_TOOLKIT int swmm_setLinkPollut(int index, SM_LinkPollut type, int polluta
421440
*/
422441
EXPORT_TOOLKIT int swmm_getLinkResult(int index, SM_LinkResult type, double *result);
423442

443+
/**
444+
@brief Gets results for the inlets of a specified link.
445+
@param index The index of a link with inlets
446+
@param type The result type code (See @ref SM_InletResult)
447+
@param result Pollutant index to set
448+
@param[out] result The result of the inlet's property
449+
@return Error code
450+
*/
451+
EXPORT_TOOLKIT int swmm_getInletResult(int index, SM_InletResult type, double *result);
452+
453+
424454
/**
425455
@brief Gets pollutant values for a specified link.
426456
@param index The index of a link

src/solver/include/toolkit_enums.h

+16
Original file line numberDiff line numberDiff line change
@@ -275,5 +275,21 @@ typedef enum {
275275
SM_STORAGEDRAIN = 29, /**< Underdrain flow rate layer */
276276
} SM_LidResult;
277277

278+
typedef enum {
279+
SM_INLETNUMINLETS = 0,
280+
SM_INLETCLOGFACTOR = 1,
281+
SM_INLETFLOWLIMIT = 2,
282+
SM_INLETLOCALDEPRESS = 3,
283+
SM_INLETLOCALWIDTH = 4
284+
} SM_InletProperty;
285+
286+
typedef enum {
287+
SM_INLETFLOWFACTOR = 0,
288+
SM_INLETFLOWCAPTURE = 1,
289+
SM_INLETBACKFLOW = 2,
290+
SM_INLETBACKFLOWRATIO = 3,
291+
292+
} SM_InletResult;
293+
278294

279295
#endif /* TOOLKIT_ENUMS_H_ */

src/solver/include/toolkit_error.h

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum ToolkitErrorType {
1313
ERR_TKAPI_LIDUNIT_INDEX = 2009,
1414
ERR_TKAPI_UNDEFINED_LID = 2010,
1515
ERR_TKAPI_MEMORY = 2011,
16+
ERR_TKAPI_NO_INLET = 2012,
1617

1718
TKMAXERRMSG = 3000
1819
};

src/solver/include/toolkit_errors.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ ERR(2008, "\n API Key Error: Invalid Pattern Index")
1212
ERR(2009, "\n API Key Error: Invalid Lid Unit Index")
1313
ERR(2010, "\n API Key Error: Undefined Subcatchment Lid")
1414
ERR(2011, "\n API Key Error: No memory allocated for return value")
15+
ERR(2012, "\n API Key Error: Specified link is not assigned an inlet")

src/solver/inlet.c

+1-32
Original file line numberDiff line numberDiff line change
@@ -70,38 +70,7 @@ typedef struct
7070
} TInletDesign;
7171

7272

73-
// Inlet performance statistics
74-
typedef struct
75-
{
76-
int flowPeriods; // # periods with approach flow
77-
int capturePeriods; // # periods with captured flow
78-
int backflowPeriods; // # periods with backflow
79-
double peakFlow; // peak flow seen by inlet (cfs)
80-
double peakFlowCapture; // capture efficiency at peak flow
81-
double avgFlowCapture; // average capture efficiency
82-
double bypassFreq; // frequency of bypass flow
83-
} TInletStats;
84-
85-
// Inlet list object
86-
struct TInlet
87-
{
88-
int linkIndex; // index of conduit link with the inlet
89-
int designIndex; // index of inlet's design
90-
int nodeIndex; // index of node receiving captured flow
91-
int numInlets; // # inlets on each side of street or in channel
92-
int placement; // whether inlet is on-grade or on-sag
93-
double clogFactor; // fractional degree of inlet clogging
94-
double flowLimit; // inlet flow restriction (cfs)
95-
double localDepress; // local gutter depression (ft)
96-
double localWidth; // local depression width (ft)
97-
98-
double flowFactor; // flow = flowFactor * (flow spread)^2.67
99-
double flowCapture; // captured flow rate (cfs)
100-
double backflow; // backflow from capture node (cfs)
101-
double backflowRatio; // inlet backflow / capture node overflow
102-
TInletStats stats; // inlet performance statistics
103-
TInlet * nextInlet; // next inlet in list
104-
};
73+
// OWA EDIT - TInlet and TInletStats struct defs moved to inlet.h to be shared by toolkit.c
10574

10675
// Shared inlet variables
10776
TInletDesign * InletDesigns; // array of available inlet designs

src/solver/inlet.h

+35
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,39 @@ void inlet_adjustQualOutflows();
2727
void inlet_writeStatsReport();
2828
double inlet_capturedFlow(int link);
2929

30+
// OWA EDIT ##################################################################################
31+
// TInlet and TInletStats struct defs moved to inlet.h to be shared by toolkit.c
32+
typedef struct
33+
{
34+
int flowPeriods; // # periods with approach flow
35+
int capturePeriods; // # periods with captured flow
36+
int backflowPeriods; // # periods with backflow
37+
double peakFlow; // peak flow seen by inlet (cfs)
38+
double peakFlowCapture; // capture efficiency at peak flow
39+
double avgFlowCapture; // average capture efficiency
40+
double bypassFreq; // frequency of bypass flow
41+
} TInletStats;
42+
43+
// Inlet list object
44+
struct TInlet
45+
{
46+
int linkIndex; // index of conduit link with the inlet
47+
int designIndex; // index of inlet's design
48+
int nodeIndex; // index of node receiving captured flow
49+
int numInlets; // # inlets on each side of street or in channel
50+
int placement; // whether inlet is on-grade or on-sag
51+
double clogFactor; // fractional degree of inlet clogging
52+
double flowLimit; // inlet flow restriction (cfs)
53+
double localDepress; // local gutter depression (ft)
54+
double localWidth; // local depression width (ft)
55+
56+
double flowFactor; // flow = flowFactor * (flow spread)^2.67
57+
double flowCapture; // captured flow rate (cfs)
58+
double backflow; // backflow from capture node (cfs)
59+
double backflowRatio; // inlet backflow / capture node overflow
60+
TInletStats stats; // inlet performance statistics
61+
TInlet * nextInlet; // next inlet in list
62+
};
63+
// ###########################################################################################
64+
3065
#endif

src/solver/toolkit.c

+142
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,148 @@ EXPORT_TOOLKIT int swmm_setLinkParam(int index, SM_LinkProperty param, double va
806806
return error_code;
807807
}
808808

809+
EXPORT_TOOLKIT int swmm_getInletParam(int index, SM_InletProperty param, double *value)
810+
///
811+
/// Input: index = Index of the link with desired inlet
812+
/// param = Parameter desired (Based on enum SM_InletProperty)
813+
/// Output: value = value to be output
814+
/// Return: API Error
815+
/// Purpose: Gets Link Parameter
816+
{
817+
int error_code = 0;
818+
*value = 0;
819+
TInlet* inlet;
820+
821+
// Check if Open
822+
if(swmm_IsOpenFlag() == FALSE)
823+
{
824+
error_code = ERR_TKAPI_INPUTNOTOPEN;
825+
}
826+
// Check if object index is within bounds
827+
else if (index < 0 || index >= Nobjects[LINK])
828+
{
829+
error_code = ERR_TKAPI_OBJECT_INDEX;
830+
}
831+
else
832+
{
833+
inlet = Link[index].inlet;
834+
if (inlet)
835+
{
836+
switch(param)
837+
{
838+
case SM_INLETNUMINLETS:
839+
*value = (double)inlet->numInlets; break;
840+
case SM_INLETCLOGFACTOR:
841+
*value = (1 - inlet->clogFactor) * 100; break;
842+
case SM_INLETFLOWLIMIT:
843+
*value = inlet->flowLimit * UCF(FLOW); break;
844+
case SM_INLETLOCALDEPRESS:
845+
*value = inlet->localDepress * UCF(LENGTH); break;
846+
case SM_INLETLOCALWIDTH:
847+
*value = inlet->localWidth * UCF(LENGTH); break;
848+
default: error_code = ERR_TKAPI_OUTBOUNDS; break;
849+
}
850+
}
851+
852+
else
853+
{
854+
error_code = ERR_TKAPI_NO_INLET;
855+
}
856+
}
857+
return error_code;
858+
};
859+
860+
EXPORT_TOOLKIT int swmm_setInletParam(int index, SM_InletProperty param, double value)
861+
///
862+
/// Input: index = Index of link with desired inlets
863+
/// param = Parameter desired (Based on enum SM_InletProperty)
864+
/// value = value to be assigned
865+
/// Return: API Error
866+
/// Purpose: Sets Inlet Parameter
867+
{
868+
int error_code = 0;
869+
TInlet* inlet;
870+
// Check if Open
871+
if(swmm_IsOpenFlag() == FALSE)
872+
{
873+
error_code = ERR_TKAPI_INPUTNOTOPEN;
874+
}
875+
// Check if object index is within bounds
876+
else if (index < 0 || index >= Nobjects[LINK])
877+
{
878+
error_code = ERR_TKAPI_OBJECT_INDEX;
879+
}
880+
else
881+
{
882+
inlet = Link[index].inlet;
883+
if (inlet)
884+
{
885+
switch(param)
886+
{
887+
case SM_INLETCLOGFACTOR:
888+
inlet->clogFactor = 1.0 - (value / 100.); break;
889+
case SM_INLETFLOWLIMIT:
890+
inlet->flowLimit = value / UCF(FLOW); break;
891+
default: error_code = ERR_TKAPI_OUTBOUNDS; break;
892+
}
893+
}
894+
895+
else
896+
{
897+
error_code = ERR_TKAPI_NO_INLET;
898+
}
899+
}
900+
return error_code;
901+
}
902+
903+
EXPORT_TOOLKIT int swmm_getInletResult(int index, SM_InletResult type, double *result)
904+
///
905+
/// Input: index = Index of the link with desired inlet
906+
/// param = Parameter desired (Based on enum SM_InletProperty)
907+
/// Output: value = value to be output
908+
/// Return: API Error
909+
/// Purpose: Gets Link Parameter
910+
{
911+
int error_code = 0;
912+
*result = 0;
913+
TInlet* inlet;
914+
915+
// Check if Open
916+
if(swmm_IsOpenFlag() == FALSE)
917+
{
918+
error_code = ERR_TKAPI_INPUTNOTOPEN;
919+
}
920+
// Check if object index is within bounds
921+
else if (index < 0 || index >= Nobjects[LINK])
922+
{
923+
error_code = ERR_TKAPI_OBJECT_INDEX;
924+
}
925+
else
926+
{
927+
inlet = Link[index].inlet;
928+
if (inlet)
929+
{
930+
switch(type)
931+
{
932+
case SM_INLETFLOWFACTOR:
933+
*result = inlet->flowFactor; break;
934+
case SM_INLETFLOWCAPTURE:
935+
*result = inlet->flowCapture * UCF(FLOW); break;
936+
case SM_INLETBACKFLOW:
937+
*result = inlet->backflow * UCF(FLOW); break;
938+
case SM_INLETBACKFLOWRATIO:
939+
*result = inlet->backflowRatio; break;
940+
default: error_code = ERR_TKAPI_OUTBOUNDS; break;
941+
}
942+
}
943+
944+
else
945+
{
946+
error_code = ERR_TKAPI_NO_INLET;
947+
}
948+
}
949+
return error_code;
950+
};
809951

810952
EXPORT_TOOLKIT int swmm_getSubcatchParam(int index, SM_SubcProperty param, double *value)
811953
///

tests/solver/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ set(solver_test_srcs
3737
test_toolkit.cpp
3838
test_solver.cpp
3939
test_stats.cpp
40+
test_inlets_and_drains.cpp
4041
# ADD NEW TEST SUITES TO EXISTING TOOLKIT TEST MODULE
4142
)
4243

0 commit comments

Comments
 (0)