Showing posts with label SWMM 5.2.2 Code for LID Function trenchFluxRates. Show all posts
Showing posts with label SWMM 5.2.2 Code for LID Function trenchFluxRates. Show all posts

Saturday, January 21, 2023

SWMM 5.2.2 Code for LID Function trenchFluxRates

This code is a function called "trenchFluxRates" that calculates flux rates from the layers of an infiltration trench LID. It takes in two input arrays, "x" and "f", which represent the vector of storage levels and the vector of flux rates, respectively. The function uses several intermediate variables, including "availVolume" and "maxRate". It also makes use of several properties of the storage layer, such as "storageThickness" and "storageVoidFrac".

The code first retrieves the moisture levels from the input vector "x" and converts them to volumes. It then calculates the ET rates and nominal storage inflow, as well as the exfiltration rate out of the storage layer. The code also checks for underdrain flow and limits the exfiltration rate and underdrain flow by available volume. The storage inflow is limited to not exceed the storage layer capacity. Finally, the function finds the net fluxes for each layer and stores them in the output array "f".

A table of the variables used in this function and their descriptions is as follows:

Variable NameDescription
x[SURF], x[STOR]Input vector of storage levels
f[SURF], f[STOR], f[SOIL]Output vector of flux rates
surfaceDepthMoisture level variable for the surface layer
storageDepthMoisture level variable for the storage layer
availVolumeIntermediate variable for available volume
maxRateIntermediate variable for maximum rate
storageThicknessProperty of the storage layer representing its thickness
storageVoidFracProperty of the storage layer representing its void fraction
SurfaceVolumeConverted surface moisture level to volume
SoilVolumeConverted soil moisture level to volume
StorageVolumeConverted storage moisture level to volume
SurfaceInflowRate of inflow to the surface layer
SurfaceEvapRate of evaporation from the surface layer
SurfaceOutflowRate of outflow from the surface layer
StorageInflowRate of inflow to the storage layer
StorageEvapRate of evaporation from the storage layer
StorageExfilRate of exfiltration from the storage layer
StorageDrainRate of underdrain flow from the storage layer
TstepTime step
theLidProcPointer to LID process data

void trenchFluxRates(double x[], double f[])
//
//  Purpose: computes flux rates from the layers of an infiltration trench LID.
//  Input:   x = vector of storage levels
//  Output:  f = vector of flux rates
//
{
    // Moisture level variables
    double surfaceDepth;
    double storageDepth;

    // Intermediate variables
    double availVolume;
    double maxRate;

    // Storage layer properties
    double storageThickness = theLidProc->storage.thickness;
    double storageVoidFrac = theLidProc->storage.voidFrac;

    //... retrieve moisture levels from input vector
    surfaceDepth = x[SURF];
    storageDepth = x[STOR];

    //... convert moisture levels to volumes
    SurfaceVolume = surfaceDepth * theLidProc->surface.voidFrac;
    SoilVolume = 0.0;
    StorageVolume = storageDepth * storageVoidFrac;

    //... get ET rates
    availVolume = (storageThickness - storageDepth) * storageVoidFrac;
    getEvapRates(SurfaceVolume, 0.0, 0.0, StorageVolume, 1.0);

    //... no storage evap if surface ponded
    if ( surfaceDepth > 0.0 ) StorageEvap = 0.0;

    //... nominal storage inflow
    StorageInflow = SurfaceInflow + SurfaceVolume / Tstep;

    //... exfiltration rate out of storage layer
   StorageExfil = getStorageExfilRate();

    //... underdrain flow rate
    StorageDrain = 0.0;
    if ( theLidProc->drain.coeff > 0.0 )
    {
        StorageDrain = getStorageDrainRate(storageDepth, 0.0, 0.0, surfaceDepth);
    }

    //... limit storage exfiltration by available storage volume
    maxRate = StorageInflow - StorageEvap + storageDepth*storageVoidFrac/Tstep;
    StorageExfil = MIN(StorageExfil, maxRate);
    StorageExfil = MAX(StorageExfil, 0.0);

    //... limit underdrain flow by volume above drain offset
    if ( StorageDrain > 0.0 )
    {
        maxRate = -StorageExfil - StorageEvap;
        if (storageDepth >= storageThickness ) maxRate += StorageInflow;
        if ( theLidProc->drain.offset <= storageDepth )
        {
            maxRate += (storageDepth - theLidProc->drain.offset) *
                       storageVoidFrac/Tstep;
        }
        maxRate = MAX(maxRate, 0.0);
        StorageDrain = MIN(StorageDrain, maxRate);
    }

    //... limit storage inflow to not exceed storage layer capacity
    maxRate = (storageThickness - storageDepth)*storageVoidFrac/Tstep +
              StorageExfil + StorageEvap + StorageDrain;
    StorageInflow = MIN(StorageInflow, maxRate);

    //... equate surface infil to storage inflow
    SurfaceInfil = StorageInflow;

    //... find surface outflow rate
    SurfaceOutflow = getSurfaceOutflowRate(surfaceDepth);

    // ... find net fluxes for each layer
    f[SURF] = SurfaceInflow - SurfaceEvap - StorageInflow - SurfaceOutflow /
              theLidProc->surface.voidFrac;;
    f[STOR] = (StorageInflow - StorageEvap - StorageExfil - StorageDrain) /
              theLidProc->storage.voidFrac;
    f[SOIL] = 0.0;
}

AI Rivers of Wisdom about ICM SWMM

Here's the text "Rivers of Wisdom" formatted with one sentence per line: [Verse 1] 🌊 Beneath the ancient oak, where shadows p...