This code is part of a function called "lidproc_saveResults" that updates the mass balance for an LID (Low Impact Development) unit and saves the current flux rates to a LID report file.
The function takes in two inputs: a pointer to the LID unit and two units conversion factors for rainfall rate and rainfall depth. It does not return any output.
First, the function calculates the total evaporation rate and total volume stored in the LID unit. Then, it updates the mass balance totals using the updateWaterBalance function, passing in various inflow, outflow, and storage parameters.
Next, the function checks if the LID unit is in a dry state by comparing the values of these parameters to a minimum flow threshold (MINFLOW). If it is in a dry state, it sets the variable "isDry" to true. If the LID unit is not in a dry state, it sets the global variable "HasWetLids" to true.
Then, if the LID unit has a report file, the function converts the rate results to the original units (in/hr or mm/hr) and storage results to the original units (in or mm) using the conversion factors passed in. It then writes the current results to a string, which is saved between reporting periods.
If the current LID state is wet but the previous state was dry for more than one period, the function writes the saved previous results to the report file, marking the end of a dry period.
Variable Name | Original Units | ucf | Calculation |
---|
SURF_INFLOW | in/hr or mm/hr | ucfRainfall | SurfaceInflow*ucf |
TOTAL_EVAP | in/hr or mm/hr | ucfRainfall | totalEvap*ucf |
SURF_INFIL | in/hr or mm/hr | ucfRainfall | SurfaceInfil*ucf |
PAVE_PERC | in/hr or mm/hr | ucfRainfall | PavePerc*ucf |
SOIL_PERC | in/hr or mm/hr | ucfRainfall | SoilPerc*ucf |
STOR_EXFIL | in/hr or mm/hr | ucfRainfall | StorageExfil*ucf |
SURF_OUTFLOW | in/hr or mm/hr | ucfRainfall | SurfaceOutflow*ucf |
STOR_DRAIN | in/hr or mm/hr | ucfRainfall | StorageDrain*ucf |
SURF_DEPTH | in or mm | ucfRainDepth | theLidUnit->surfaceDepth*ucf |
PAVE_DEPTH | in or mm | ucfRainDepth | theLidUnit->paveDepth*ucf |
SOIL_MOIST | | | theLidUnit->soilMoisture |
STOR_DEPTH | in or mm | ucfRainDepth | theLidUnit->storageDepth*ucf |
Note: ucf is the units conversion factor variable. The original units are assumed to be in/hr or mm/hr for rate results, and in or mm for storage results.
void lidproc_saveResults(TLidUnit* lidUnit, double ucfRainfall, double ucfRainDepth)
//
// Purpose: updates the mass balance for an LID unit and saves
// current flux rates to the LID report file.
// Input: lidUnit = ptr. to LID unit
// ucfRainfall = units conversion factor for rainfall rate
// ucfDepth = units conversion factor for rainfall depth
// Output: none
//
{
double ucf; // units conversion factor
double totalEvap; // total evaporation rate (ft/s)
double totalVolume; // total volume stored in LID (ft)
double rptVars[MAX_RPT_VARS]; // array of reporting variables
int isDry = FALSE; // true if current state of LID is dry
char timeStamp[TIME_STAMP_SIZE + 1]; // date/time stamp
double elapsedHrs; // elapsed hours
//... find total evap. rate and stored volume
totalEvap = SurfaceEvap + PaveEvap + SoilEvap + StorageEvap;
totalVolume = SurfaceVolume + PaveVolume + SoilVolume + StorageVolume;
//... update mass balance totals
updateWaterBalance(theLidUnit, SurfaceInflow, totalEvap, StorageExfil,
SurfaceOutflow, StorageDrain, totalVolume);
//... check if dry-weather conditions hold
if ( SurfaceInflow < MINFLOW &&
SurfaceOutflow < MINFLOW &&
StorageDrain < MINFLOW &&
StorageExfil < MINFLOW &&
totalEvap < MINFLOW
) isDry = TRUE;
//... update status of HasWetLids
if ( !isDry ) HasWetLids = TRUE;
//... write results to LID report file
if ( lidUnit->rptFile )
{
//... convert rate results to original units (in/hr or mm/hr)
ucf = ucfRainfall;
rptVars[SURF_INFLOW] = SurfaceInflow*ucf;
rptVars[TOTAL_EVAP] = totalEvap*ucf;
rptVars[SURF_INFIL] = SurfaceInfil*ucf;
rptVars[PAVE_PERC] = PavePerc*ucf;
rptVars[SOIL_PERC] = SoilPerc*ucf;
rptVars[STOR_EXFIL] = StorageExfil*ucf;
rptVars[SURF_OUTFLOW] = SurfaceOutflow*ucf;
rptVars[STOR_DRAIN] = StorageDrain*ucf;
//... convert storage results to original units (in or mm)
ucf = ucfRainDepth;
rptVars[SURF_DEPTH] = theLidUnit->surfaceDepth*ucf;
rptVars[PAVE_DEPTH] = theLidUnit->paveDepth*ucf;
rptVars[SOIL_MOIST] = theLidUnit->soilMoisture;
rptVars[STOR_DEPTH] = theLidUnit->storageDepth*ucf;
//... if the current LID state is wet but the previous state was dry
// for more than one period then write the saved previous results
// to the report file thus marking the end of a dry period
if ( !isDry && theLidUnit->rptFile->wasDry > 1)
{
fprintf(theLidUnit->rptFile->file, "%s",
theLidUnit->rptFile->results);
}
//... write the current results to a string which is saved between
// reporting periods
elapsedHrs = NewRunoffTime / 1000.0 / 3600.0;
datetime_getTimeStamp(
M_D_Y, getDateTime(NewRunoffTime), TIME_STAMP_SIZE, timeStamp);
snprintf(theLidUnit->rptFile->results, sizeof(theLidUnit->rptFile->results),
"\n%20s\t %8.3f\t %8.3f\t %8.4f\t %8.3f\t %8.3f\t %8.3f\t %8.3f\t"
"%8.3f\t %8.3f\t %8.3f\t %8.3f\t %8.3f\t %8.3f",
timeStamp, elapsedHrs, rptVars[0], rptVars[1], rptVars[2],
rptVars[3], rptVars[4], rptVars[5], rptVars[6], rptVars[7],
rptVars[8], rptVars[9], rptVars[10], rptVars[11]);
//... if the current LID state is dry
if ( isDry )
{
//... if the previous state was wet then write the current
// results to file marking the start of a dry period
if ( theLidUnit->rptFile->wasDry == 0 )
{
fprintf(theLidUnit->rptFile->file, "%s",
theLidUnit->rptFile->results);
}
//... increment the number of successive dry periods
theLidUnit->rptFile->wasDry++;
}
//... if the current LID state is wet
else
{
//... write the current results to the report file
fprintf(theLidUnit->rptFile->file, "%s",
theLidUnit->rptFile->results);
//... re-set the number of successive dry periods to 0
theLidUnit->rptFile->wasDry = 0;
}
}
No comments:
Post a Comment