Skip to content

Commit

Permalink
add initial inlet control api functions
Browse files Browse the repository at this point in the history
  • Loading branch information
karosc committed Mar 28, 2023
1 parent b4ddb51 commit 8e3a171
Show file tree
Hide file tree
Showing 11 changed files with 862 additions and 32 deletions.
30 changes: 30 additions & 0 deletions src/solver/include/toolkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "../enums.h"
#include "../datetime.h"
#include "../lid.h"
#include "../inlet.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -312,6 +313,24 @@ EXPORT_TOOLKIT int swmm_getLinkParam(int index, SM_LinkProperty param, double *v
*/
EXPORT_TOOLKIT int swmm_setLinkParam(int index, SM_LinkProperty param, double value);

/**
@brief Get a property value for the inlets of a specified link.
@param index The index of a link
@param Param The property type code (See @ref SM_InletProperty)
@param[out] value The value of the inlet's property
@return Error code
*/
EXPORT_TOOLKIT int swmm_getInletParam(int index, SM_InletProperty param, double *value);

/**
@brief Set a property value for the inlets of a specified link.
@param index The index of a link
@param Param The property type code (See @ref SM_InletProperty)
@param value The new value of the inlet's property
@return Error code
*/
EXPORT_TOOLKIT int swmm_setInletParam(int index, SM_InletProperty param, double value);

/**
@brief Get a property value for specified subcatchment.
@param index The index of a subcatchment
Expand Down Expand Up @@ -421,6 +440,17 @@ EXPORT_TOOLKIT int swmm_setLinkPollut(int index, SM_LinkPollut type, int polluta
*/
EXPORT_TOOLKIT int swmm_getLinkResult(int index, SM_LinkResult type, double *result);

/**
@brief Gets results for the inlets of a specified link.
@param index The index of a link with inlets
@param type The result type code (See @ref SM_InletResult)
@param result Pollutant index to set
@param[out] result The result of the inlet's property
@return Error code
*/
EXPORT_TOOLKIT int swmm_getInletResult(int index, SM_InletResult type, double *result);


/**
@brief Gets pollutant values for a specified link.
@param index The index of a link
Expand Down
16 changes: 16 additions & 0 deletions src/solver/include/toolkit_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,21 @@ typedef enum {
SM_STORAGEDRAIN = 29, /**< Underdrain flow rate layer */
} SM_LidResult;

typedef enum {
SM_INLETNUMINLETS = 0,
SM_INLETCLOGFACTOR = 1,
SM_INLETFLOWLIMIT = 2,
SM_INLETLOCALDEPRESS = 3,
SM_INLETLOCALWIDTH = 4
} SM_InletProperty;

typedef enum {
SM_INLETFLOWFACTOR = 0,
SM_INLETFLOWCAPTURE = 1,
SM_INLETBACKFLOW = 2,
SM_INLETBACKFLOWRATIO = 3,

} SM_InletResult;


#endif /* TOOLKIT_ENUMS_H_ */
1 change: 1 addition & 0 deletions src/solver/include/toolkit_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum ToolkitErrorType {
ERR_TKAPI_LIDUNIT_INDEX = 2009,
ERR_TKAPI_UNDEFINED_LID = 2010,
ERR_TKAPI_MEMORY = 2011,
ERR_TKAPI_NO_INLET = 2012,

TKMAXERRMSG = 3000
};
1 change: 1 addition & 0 deletions src/solver/include/toolkit_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ ERR(2008, "\n API Key Error: Invalid Pattern Index")
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")
33 changes: 1 addition & 32 deletions src/solver/inlet.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,38 +70,7 @@ typedef struct
} TInletDesign;


// Inlet performance statistics
typedef struct
{
int flowPeriods; // # periods with approach flow
int capturePeriods; // # periods with captured flow
int backflowPeriods; // # periods with backflow
double peakFlow; // peak flow seen by inlet (cfs)
double peakFlowCapture; // capture efficiency at peak flow
double avgFlowCapture; // average capture efficiency
double bypassFreq; // frequency of bypass flow
} TInletStats;

// Inlet list object
struct TInlet
{
int linkIndex; // index of conduit link with the inlet
int designIndex; // index of inlet's design
int nodeIndex; // index of node receiving captured flow
int numInlets; // # inlets on each side of street or in channel
int placement; // whether inlet is on-grade or on-sag
double clogFactor; // fractional degree of inlet clogging
double flowLimit; // inlet flow restriction (cfs)
double localDepress; // local gutter depression (ft)
double localWidth; // local depression width (ft)

double flowFactor; // flow = flowFactor * (flow spread)^2.67
double flowCapture; // captured flow rate (cfs)
double backflow; // backflow from capture node (cfs)
double backflowRatio; // inlet backflow / capture node overflow
TInletStats stats; // inlet performance statistics
TInlet * nextInlet; // next inlet in list
};
// OWA EDIT - TInlet and TInletStats struct defs moved to inlet.h to be shared by toolkit.c

// Shared inlet variables
TInletDesign * InletDesigns; // array of available inlet designs
Expand Down
35 changes: 35 additions & 0 deletions src/solver/inlet.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,39 @@ void inlet_adjustQualOutflows();
void inlet_writeStatsReport();
double inlet_capturedFlow(int link);

// OWA EDIT ##################################################################################
// TInlet and TInletStats struct defs moved to inlet.h to be shared by toolkit.c
typedef struct
{
int flowPeriods; // # periods with approach flow
int capturePeriods; // # periods with captured flow
int backflowPeriods; // # periods with backflow
double peakFlow; // peak flow seen by inlet (cfs)
double peakFlowCapture; // capture efficiency at peak flow
double avgFlowCapture; // average capture efficiency
double bypassFreq; // frequency of bypass flow
} TInletStats;

// Inlet list object
struct TInlet
{
int linkIndex; // index of conduit link with the inlet
int designIndex; // index of inlet's design
int nodeIndex; // index of node receiving captured flow
int numInlets; // # inlets on each side of street or in channel
int placement; // whether inlet is on-grade or on-sag
double clogFactor; // fractional degree of inlet clogging
double flowLimit; // inlet flow restriction (cfs)
double localDepress; // local gutter depression (ft)
double localWidth; // local depression width (ft)

double flowFactor; // flow = flowFactor * (flow spread)^2.67
double flowCapture; // captured flow rate (cfs)
double backflow; // backflow from capture node (cfs)
double backflowRatio; // inlet backflow / capture node overflow
TInletStats stats; // inlet performance statistics
TInlet * nextInlet; // next inlet in list
};
// ###########################################################################################

#endif
142 changes: 142 additions & 0 deletions src/solver/toolkit.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,148 @@ EXPORT_TOOLKIT int swmm_setLinkParam(int index, SM_LinkProperty param, double va
return error_code;
}

EXPORT_TOOLKIT int swmm_getInletParam(int index, SM_InletProperty param, double *value)
///
/// Input: index = Index of the link with desired inlet
/// param = Parameter desired (Based on enum SM_InletProperty)
/// Output: value = value to be output
/// Return: API Error
/// Purpose: Gets Link Parameter
{
int error_code = 0;
*value = 0;
TInlet* inlet;

// Check if Open
if(swmm_IsOpenFlag() == FALSE)
{
error_code = ERR_TKAPI_INPUTNOTOPEN;
}
// Check if object index is within bounds
else if (index < 0 || index >= Nobjects[LINK])
{
error_code = ERR_TKAPI_OBJECT_INDEX;
}
else
{
inlet = Link[index].inlet;
if (inlet)
{
switch(param)
{
case SM_INLETNUMINLETS:
*value = (double)inlet->numInlets; break;
case SM_INLETCLOGFACTOR:
*value = (1 - inlet->clogFactor) * 100; break;
case SM_INLETFLOWLIMIT:
*value = inlet->flowLimit * UCF(FLOW); break;
case SM_INLETLOCALDEPRESS:
*value = inlet->localDepress * UCF(LENGTH); break;
case SM_INLETLOCALWIDTH:
*value = inlet->localWidth * UCF(LENGTH); break;
default: error_code = ERR_TKAPI_OUTBOUNDS; break;
}
}

else
{
error_code = ERR_TKAPI_NO_INLET;
}
}
return error_code;
};

EXPORT_TOOLKIT int swmm_setInletParam(int index, SM_InletProperty param, double value)
///
/// Input: index = Index of link with desired inlets
/// param = Parameter desired (Based on enum SM_InletProperty)
/// value = value to be assigned
/// Return: API Error
/// Purpose: Sets Inlet Parameter
{
int error_code = 0;
TInlet* inlet;
// Check if Open
if(swmm_IsOpenFlag() == FALSE)
{
error_code = ERR_TKAPI_INPUTNOTOPEN;
}
// Check if object index is within bounds
else if (index < 0 || index >= Nobjects[LINK])
{
error_code = ERR_TKAPI_OBJECT_INDEX;
}
else
{
inlet = Link[index].inlet;
if (inlet)
{
switch(param)
{
case SM_INLETCLOGFACTOR:
inlet->clogFactor = 1.0 - (value / 100.); break;
case SM_INLETFLOWLIMIT:
inlet->flowLimit = value / UCF(FLOW); break;
default: error_code = ERR_TKAPI_OUTBOUNDS; break;
}
}

else
{
error_code = ERR_TKAPI_NO_INLET;
}
}
return error_code;
}

EXPORT_TOOLKIT int swmm_getInletResult(int index, SM_InletResult type, double *result)
///
/// Input: index = Index of the link with desired inlet
/// param = Parameter desired (Based on enum SM_InletProperty)
/// Output: value = value to be output
/// Return: API Error
/// Purpose: Gets Link Parameter
{
int error_code = 0;
*result = 0;
TInlet* inlet;

// Check if Open
if(swmm_IsOpenFlag() == FALSE)
{
error_code = ERR_TKAPI_INPUTNOTOPEN;
}
// Check if object index is within bounds
else if (index < 0 || index >= Nobjects[LINK])
{
error_code = ERR_TKAPI_OBJECT_INDEX;
}
else
{
inlet = Link[index].inlet;
if (inlet)
{
switch(type)
{
case SM_INLETFLOWFACTOR:
*result = inlet->flowFactor; break;
case SM_INLETFLOWCAPTURE:
*result = inlet->flowCapture * UCF(FLOW); break;
case SM_INLETBACKFLOW:
*result = inlet->backflow * UCF(FLOW); break;
case SM_INLETBACKFLOWRATIO:
*result = inlet->backflowRatio; break;
default: error_code = ERR_TKAPI_OUTBOUNDS; break;
}
}

else
{
error_code = ERR_TKAPI_NO_INLET;
}
}
return error_code;
};

EXPORT_TOOLKIT int swmm_getSubcatchParam(int index, SM_SubcProperty param, double *value)
///
Expand Down
1 change: 1 addition & 0 deletions tests/solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set(solver_test_srcs
test_toolkit.cpp
test_solver.cpp
test_stats.cpp
test_inlets_and_drains.cpp
# ADD NEW TEST SUITES TO EXISTING TOOLKIT TEST MODULE
)

Expand Down

0 comments on commit 8e3a171

Please sign in to comment.