Skip to content

Commit

Permalink
add funcs to open and close an opening
Browse files Browse the repository at this point in the history
  • Loading branch information
lrntct committed Feb 23, 2018
1 parent 64bc148 commit 164ced1
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/toolkitAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,22 @@ int DLLEXPORT swmm_setOutfallStage(int index, double stage);
int DLLEXPORT swmm_setNodeOpening(int nodeID, int idx, int oType, double A,
double l, double Co, double Cfw, double Csw);

/**
@brief Open an opening that was previously closed.
@param nodeID The index of a node
@param idx The index of an opening
@return Error code
*/
int DLLEXPORT swmm_openOpening(int nodeID, int idx);

/**
@brief Close an opening.
@param nodeID The index of a node
@param idx The index of an opening
@return Error code
*/
int DLLEXPORT swmm_closeOpening(int nodeID, int idx);

/**
@brief Remove an opening from a node.
@param nodeID The index of a node
Expand Down
64 changes: 64 additions & 0 deletions src/coupling.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ void coupling_findNodeInflow(int j, double tStep)
opening = Node[j].coverOpening;
while ( opening )
{
// --- do nothing if not coupled
if ( opening->couplingType == NO_COUPLING ) continue;
// --- compute types and inflows
opening_findCouplingType(opening, crestElev, nodeHead, overlandHead);
opening_findCouplingInflow(opening, crestElev, nodeHead, overlandHead);
Expand Down Expand Up @@ -160,6 +162,68 @@ int coupling_isNodeCoupled(int j)

//=============================================================================

int coupling_closeOpening(int j, int idx)
//
// Input: j = node index
// idx = opening index
// Output: Error code
// Purpose: Close an opening
//
{
int errcode = 0;
TCoverOpening* opening; // opening object

// --- Find the opening
opening = Node[j].coverOpening;
while ( opening )
{
if ( opening->ID == idx ) break;
opening = opening->next;
}
// --- if opening doesn't exist, return an error
if ( opening == NULL )
{
return(ERR_API_OBJECT_INDEX);
}

// --- Close the opening
opening->couplingType = NO_COUPLING;
return 0;
}

//=============================================================================

int coupling_openOpening(int j, int idx)
//
// Input: j = node index
// idx = opening index
// Output: Error code
// Purpose: Open an opening
//
{
int errcode = 0;
TCoverOpening* opening; // opening object

// --- Find the opening
opening = Node[j].coverOpening;
while ( opening )
{
if ( opening->ID == idx ) break;
opening = opening->next;
}
// --- if opening doesn't exist, return an error
if ( opening == NULL )
{
return(ERR_API_OBJECT_INDEX);
}

// --- Open the opening
opening->couplingType = NO_COUPLING_FLOW;
return 0;
}

//=============================================================================

void coupling_adjustInflows(int j, double inflowAdjustingFactor)
//
// Input: j = node index
Expand Down
2 changes: 2 additions & 0 deletions src/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ void node_getResults(int node, double wt, float x[]);
int coupling_setOpening(int j, int idx, int oType, double A, double l,
double Co, double Cfw, double Csw);
int coupling_countOpenings(int j);
int coupling_openOpening(int j, int idx);
int coupling_closeOpening(int j, int idx);
void coupling_deleteOpening(int j, int idx);
int coupling_isNodeCoupled(int j);
void coupling_execute(double tStep);
Expand Down
52 changes: 52 additions & 0 deletions src/toolkitAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,58 @@ int DLLEXPORT swmm_getNodeIsCoupled(int nodeID, int *iscoupled)
if(swmm_IsOpenFlag() == FALSE) return(ERR_API_INPUTNOTOPEN);
// Check if object index is within bounds
if (nodeID < 0 || nodeID >= Nobjects[NODE]) return(ERR_API_OBJECT_INDEX);

*iscoupled = coupling_isNodeCoupled(nodeID);

return(0);
}


int DLLEXPORT swmm_closeOpening(int nodeID, int idx)
//
// Input: nodeID = Index of desired node
// Return: API error
// Purpose: Close an opening.
{
int errcode = 0;

// Check if Open
if (swmm_IsOpenFlag() == FALSE)
{
errcode = ERR_API_INPUTNOTOPEN;
}
// Check if object index is within bounds
else if (nodeID < 0 || nodeID >= Nobjects[NODE])
{
errcode = ERR_API_OBJECT_INDEX;
}

// Close the opening
errcode = coupling_closeOpening(nodeID, idx);
return errcode;
}


int DLLEXPORT swmm_openOpening(int nodeID, int idx)
//
// Input: nodeID = Index of desired node
// Return: API error
// Purpose: Open an opening.
{
int errcode = 0;

// Check if Open
if (swmm_IsOpenFlag() == FALSE)
{
errcode = ERR_API_INPUTNOTOPEN;
}
// Check if object index is within bounds
else if (nodeID < 0 || nodeID >= Nobjects[NODE])
{
errcode = ERR_API_OBJECT_INDEX;
}

// Close the opening
errcode = coupling_closeOpening(nodeID, idx);
return errcode;
}

0 comments on commit 164ced1

Please sign in to comment.