Saturday, January 21, 2023

SWMM 5.2.2 Code for LID Function swaleFluxRates

This code defines a function called "swaleFluxRates" which computes the flux rates for a vegetative swale LID. The function takes in a vector of storage levels (x) and a vector of flux rates (f) as inputs and does not return any outputs. The function starts by initializing several variables such as depth, topWidth, botWidth, length, surfInflow, surfWidth, surfArea, flowArea, lidArea, hydRadius, slope, volume, dVdT, dStore, and xDepth.

The function first retrieves the state variable of the surface water depth from the work vector, and limits it to the thickness of the surface layer. It then calculates the depression storage depth and the bottom width of the swale using the top width and the side slope. It then calculates the length of the swale and the surface area of the current ponded depth.

The function then calculates the wet volume and effective depth, the surface inflow into the swale, the evaporation rate, the infiltration rate to the native soil, and the surface outflow. If the depth is below the depression storage, the surface outflow is set to 0.0, otherwise, the function modifies the flow area to remove the depression storage and calculates the hydraulic radius using the Manning equation.

Then the function calculates the net flux rate (dV/dt) in cubic feet per second and assigns it to the SurfaceInflow and SurfaceOutflow.

Here is a table summarizing the variables and their descriptions in the code:

VariableDescription
depthdepth of surface water in swale (ft)
topWidthtop width of full swale (ft)
botWidthbottom width of swale (ft)
lengthlength of swale (ft)
surfInflowinflow rate to swale (cfs)
surfWidthtop width at current water depth (ft)
surfAreasurface area of current water depth (ft^2)
flowAreax-section flow area (ft^2)
lidAreasurface area of full swale (ft^2)
hydRadiushydraulic radius for current depth (ft)
slopeslope of swale side wall (run/rise)
volumeswale volume at current water depth (ft^3)
dVdTchange in volume w.r.t. time (cfs)
dStoredepression storage depth (ft)
xDepthdepth above depression storage (ft)
theLidProc->surface.thicknessthickness of the surface layer
theLidUnit->fullWidthfull width of the swale
theLidProc->surface.sideSlopeside slope of the sw
VariableDescription
SurfaceInflowinflow rate into the surface layer (cfs)
EvapRaterate of evaporation from the surface layer (cfs)
SurfaceInfilinfiltration rate into the native soil from the surface layer (cfs)
SurfaceOutflowoutflow rate from the surface layer (cfs)
theLidProc->surface.alphacoefficient used in the Manning equation
theLidProc->surface.voidFracvoid fraction of the swale


Note that this function is specific for swale LID, and it computes the flux rates based on the storage level and the LID properties. It calculates the depression storage, the bottom width, the length, the top width, the surface area, the flow area, the wet volume, the effective depth, the surface inflow, the evaporation rate, the infiltration rate, and the surface outflow.



void swaleFluxRates(double x[], double f[])
//
//  Purpose: computes flux rates from a vegetative swale LID.
//  Input:   x = vector of storage levels
//  Output:  f = vector of flux rates
//
{
    double depth;            // depth of surface water in swale (ft)
    double topWidth;         // top width of full swale (ft)
    double botWidth;         // bottom width of swale (ft)
    double length;           // length of swale (ft)
    double surfInflow;       // inflow rate to swale (cfs)
    double surfWidth;        // top width at current water depth (ft)
    double surfArea;         // surface area of current water depth (ft2)
    double flowArea;         // x-section flow area (ft2)
    double lidArea;          // surface area of full swale (ft2)
    double hydRadius;        // hydraulic radius for current depth (ft)
    double slope;            // slope of swale side wall (run/rise)
    double volume;           // swale volume at current water depth (ft3)
    double dVdT;             // change in volume w.r.t. time (cfs)
    double dStore;           // depression storage depth (ft)
    double xDepth;           // depth above depression storage (ft)

    //... retrieve state variable from work vector
    depth = x[SURF];
    depth = MIN(depth, theLidProc->surface.thickness);

    //... depression storage depth
    dStore = 0.0;

    //... get swale's bottom width
    //    (0.5 ft minimum to avoid numerical problems)
    slope = theLidProc->surface.sideSlope;
    topWidth = theLidUnit->fullWidth;
    topWidth = MAX(topWidth, 0.5);
    botWidth = topWidth - 2.0 * slope * theLidProc->surface.thickness;
    if ( botWidth < 0.5 )
    {
        botWidth = 0.5;
        slope = 0.5 * (topWidth - 0.5) / theLidProc->surface.thickness;
    }

    //... swale's length
    lidArea = theLidUnit->area;
    length = lidArea / topWidth;

    //... top width, surface area and flow area of current ponded depth
    surfWidth = botWidth + 2.0 * slope * depth;
    surfArea = length * surfWidth;
    flowArea = (depth * (botWidth + slope * depth)) *
               theLidProc->surface.voidFrac;

    //... wet volume and effective depth
    volume = length * flowArea;

    //... surface inflow into swale (cfs)
    surfInflow = SurfaceInflow * lidArea;

    //... ET rate in cfs
    SurfaceEvap = EvapRate * surfArea;
    SurfaceEvap = MIN(SurfaceEvap, volume/Tstep);

    //... infiltration rate to native soil in cfs
    StorageExfil = SurfaceInfil * surfArea;

    //... no surface outflow if depth below depression storage
    xDepth = depth - dStore;
    if ( xDepth <= ZERO ) SurfaceOutflow = 0.0;

    //... otherwise compute a surface outflow
    else
    {
        //... modify flow area to remove depression storage,
        flowArea -= (dStore * (botWidth + slope * dStore)) *
                     theLidProc->surface.voidFrac;
        if ( flowArea < ZERO ) SurfaceOutflow = 0.0;
        else
        {
            //... compute hydraulic radius
            botWidth = botWidth + 2.0 * dStore * slope;
            hydRadius = botWidth + 2.0 * xDepth * sqrt(1.0 + slope*slope);
            hydRadius = flowArea / hydRadius;

            //... use Manning Eqn. to find outflow rate in cfs
            SurfaceOutflow = theLidProc->surface.alpha * flowArea *
                             pow(hydRadius, 2./3.);
        }
    }

    //... net flux rate (dV/dt) in cfs
    dVdT = surfInflow - SurfaceEvap - StorageExfil - SurfaceOutflow;

    //... when full, any net positive inflow becomes spillage
    if ( depth == theLidProc->surface.thickness && dVdT > 0.0 )
    {
        SurfaceOutflow += dVdT;
        dVdT = 0.0;
    }

    //... convert flux rates to ft/s
    SurfaceEvap /= lidArea;
    StorageExfil /= lidArea;
    SurfaceOutflow /= lidArea;
    f[SURF] = dVdT / surfArea;
    f[SOIL] = 0.0;
    f[STOR] = 0.0;

    //... assign values to layer volumes
    SurfaceVolume = volume / lidArea;
    SoilVolume = 0.0;
    StorageVolume = 0.0;
}

SWMM 5.2.2 Code for LID Function barrelFluxRates

This code defines a function called "barrelFluxRates" which computes the flux rates for a rain barrel LID. The function takes in a vector of storage levels (x) and a vector of flux rates (f) as inputs and does not return any outputs. The function starts by initializing three variables, "storageDepth", "head" and "maxValue" to 0.0. Then it assigns the value of 0.0 to the SurfaceVolume, SoilVolume, and assigns the value of storageDepth to the StorageVolume. The function then initializes the SurfaceInfil, SurfaceOutflow, and StorageDrain to 0.0.

The function then checks if the drain delay is 0.0 or if the dry time is greater than or equal to the drain delay, if it is, it calculates the head and if the head is greater than 0.0, it calculates the StorageDrain using the getStorageDrainRate function, and limits the StorageDrain to the maxValue which is equal to the head divided by the time step.

The function then limits the StorageInflow to the available storage by calculating the maxValue and comparing it to the SurfaceInflow. The SurfaceInfil is then assigned the value of StorageInflow.

Finally, the function assigns the values to the layer flux rates. The SurfaceInflow minus StorageInflow is assigned to f[SURF], the StorageInflow minus StorageDrain is assigned to f[STOR], and 0.0 is assigned to f[SOIL].

VariableDescription
SurfaceVolumeThe volume of water in the surface layer
SoilVolumeThe volume of water in the soil layer
StorageVolumeThe volume of water in the storage layer
SurfaceInfilThe infiltration rate into the surface layer
SurfaceOutflowThe outflow rate from the surface layer
StorageDrainThe drainage rate from the storage layer
StorageInflowThe inflow rate into the storage layer
SurfaceInflowThe inflow rate into the surface layer
theLidProc->drain.delayThe delay time before drainage begins from the storage layer
theLidUnit->dryTimeThe time since the last rain
theLidProc->drain.offsetThe offset for determining the head for drainage
theLidProc->storage.thicknessThe thickness of the storage layer
TstepThe change in time step

Note that this function is specific for rain barrel LID, and it computes the flux rates based on the storage level and the LID properties.



void barrelFluxRates(double x[], double f[])
//
//  Purpose: computes flux rates for a rain barrel LID.
//  Input:   x = vector of storage levels
//  Output:  f = vector of flux rates
//
{
    double storageDepth = x[STOR];
    double head;
    double maxValue;

    //... assign values to layer volumes
    SurfaceVolume = 0.0;
    SoilVolume = 0.0;
    StorageVolume = storageDepth;

    //... initialize flows
    SurfaceInfil = 0.0;
    SurfaceOutflow = 0.0;
    StorageDrain = 0.0;

    //... compute outflow if time since last rain exceeds drain delay
    //    (dryTime is updated in lid.evalLidUnit at each time step)
    if ( theLidProc->drain.delay == 0.0 ||
        theLidUnit->dryTime >= theLidProc->drain.delay )
    {
        head = storageDepth - theLidProc->drain.offset;
        if ( head > 0.0 )
        {
            StorageDrain = getStorageDrainRate(storageDepth, 0.0, 0.0, 0.0);
            maxValue = (head/Tstep);
            StorageDrain = MIN(StorageDrain, maxValue);
        }
    }

    //... limit inflow to available storage
    StorageInflow = SurfaceInflow;
    maxValue = (theLidProc->storage.thickness - storageDepth) / Tstep +
        StorageDrain;
    StorageInflow = MIN(StorageInflow, maxValue);
    SurfaceInfil = StorageInflow;

    //... assign values to layer flux rates
    f[SURF] = SurfaceInflow - StorageInflow;
    f[STOR] = StorageInflow - StorageDrain;
    f[SOIL] = 0.0;
}

SWMM 5.2.2 Code for LID Function getSurfaceOutflowRate

This code defines a function called "getSurfaceOutflowRate" which calculates the outflow rate from a LID's surface layer. The function takes in a depth of ponded water on the surface layer (in feet) and returns the outflow from the surface layer (in feet per second) as output. The function starts by initializing two variables, "delta" and "outflow", to 0.0. Then, it checks if the depth of ponded water is below the storage depth and if it is, it immediately returns 0.0.

Otherwise, the function calculates the outflow from overland flow Manning equation, which is the product of surface layer's alpha, the fifth root of delta, full width of the LID, and the area of the LID. The function also checks if the outflow is greater than the change in time step and if it is, it limits the outflow to the change in time step.

VariableDescription
deltaThe difference between the depth of ponded water and the thickness of the surface layer
outflowThe outflow rate from the surface layer
theLidProc->surface.thicknessThe thickness of the surface layer
theLidProc->surface.alphaThe alpha value used in the overland flow Manning equation
theLidUnit->fullWidthThe full width of the LID
theLidUnit->areaThe area of the LID
TstepThe change in time step

Note that this function should not be applied to swales or rain barrels.



double getSurfaceOutflowRate(double depth)
//
//  Purpose: computes outflow rate from a LID's surface layer.
//  Input:   depth = depth of ponded water on surface layer (ft)
//  Output:  returns outflow from surface layer (ft/s)
//
//  Note: this function should not be applied to swales or rain barrels.
//
{
    double delta;
    double outflow;

    //... no outflow if ponded depth below storage depth
    delta = depth - theLidProc->surface.thickness;
    if ( delta < 0.0 ) return 0.0;

    //... compute outflow from overland flow Manning equation
    outflow = theLidProc->surface.alpha * pow(delta, 5.0/3.0) *
              theLidUnit->fullWidth / theLidUnit->area;
    outflow = MIN(outflow, delta / Tstep);
    return outflow;
}

InfoSWMM: A 2030 AI-Assisted Study Guide

  InfoSWMM: A 2030 AI-Assisted Study Guide delete   InfoSWMM: A 2030 AI-Assisted Study Guide A comprehensive study guide for someone in 2030...