OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
massbal.c File Reference

Runoff, routing, and pollutant continuity accounting. More...

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "headers.h"
Include dependency graph for massbal.c:

Macros

#define _CRT_SECURE_NO_DEPRECATE
 

Functions

double massbal_getBuildup (int p)
 Computes current total buildup of a pollutant over study area.
 
double massbal_getStorage (char isFinalStorage)
 Computes total system storage (nodes + links) filled.
 
double massbal_getStoredMass (int p)
 Computes mass of pollutant stored in conveyance network.
 
double massbal_getLoadingError ()
 Finalize surface pollutant loading totals and their continuity errors.
 
double massbal_getGwaterError ()
 Compute the signed groundwater continuity error from accumulated totals.
 
double massbal_getQualError ()
 Finalize routed pollutant mass totals and select the largest absolute error.
 
int massbal_open ()
 Opens and initializes mass balance continuity checking.
 
void massbal_close ()
 Frees memory used by mass balance system.
 
void massbal_report ()
 Reports mass balance results.
 
void massbal_updateRunoffTotals (int flowType, double v)
 Updates runoff totals after current time step.
 
void massbal_updateGwaterTotals (double vInfil, double vUpperEvap, double vLowerEvap, double vLowerPerc, double vGwater)
 Updates groundwater totals after current time step.
 
void massbal_initTimeStepTotals ()
 Initializes routing totals for current time step.
 
void massbal_addInflowFlow (int type, double q)
 Adds flow inflow to routing totals for current time step.
 
void massbal_updateLoadingTotals (int type, int p, double w)
 Adds inflow mass loading to loading totals for current time step.
 
void massbal_addInflowQual (int type, int pollutIndex, double w)
 Adds quality inflow to routing totals for current time step.
 
void massbal_addOutflowFlow (double q, int isFlooded)
 Adds flow outflow over current time step to routing totals.
 
void massbal_addOutflowQual (int p, double w, int isFlooded)
 Adds pollutant outflow over current time step to routing totals.
 
void massbal_addReactedMass (int pollutIndex, double w)
 Adds mass reacted during current time step to routing totals.
 
void massbal_addSeepageLoss (int pollutIndex, double w)
 Adds mass lost to seepage during current time step to routing totals.
 
void massbal_addToFinalStorage (int pollutIndex, double w)
 Adds mass remaining on dry surface to routing totals.
 
void massbal_addNodeLosses (double evapLoss, double seepLoss)
 Adds node losses over current time step to routing totals.
 
void massbal_addLinkLosses (double evapLoss, double seepLoss)
 Adds link losses over current time step to routing totals.
 
void massbal_updateRoutingTotals (double tStep)
 Updates overall routing totals with totals from current time step.
 
void massbal_getSysFlows (double f, double sysFlows[])
 Retrieves time-weighted average of old and new system flows.
 
double massbal_getRunoffError ()
 Compute the signed surface runoff continuity error from accumulated totals.
 
double massbal_getFlowError ()
 Compute the signed flow routing continuity error from accumulated totals.
 
double massbal_getStepFlowError ()
 Computes flow routing mass balance error at current time step.
 

Variables

TRunoffTotals RunoffTotals
 
TLoadingTotals * LoadingTotals
 
TGwaterTotals GwaterTotals
 
TRoutingTotals FlowTotals
 
TRoutingTotals * QualTotals
 
TRoutingTotals StepFlowTotals
 
TRoutingTotals OldStepFlowTotals
 
TRoutingTotals * StepQualTotals
 
double * NodeInflow
 
double * NodeOutflow
 
double TotalArea
 

Detailed Description

Runoff, routing, and pollutant continuity accounting.

Author
Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com (OpenSWMM maintenance and extensions)
License
Apache-2.0 for OpenSWMM contributions; original EPA SWMM provenance is retained.

Macro Definition Documentation

◆ _CRT_SECURE_NO_DEPRECATE

#define _CRT_SECURE_NO_DEPRECATE

Function Documentation

◆ massbal_getBuildup()

double massbal_getBuildup ( int p)

Computes current total buildup of a pollutant over study area.

Parameters
[in]pPollutant index.
Returns
Total pollutant buildup (lbs or kg).
Here is the caller graph for this function:

◆ massbal_getGwaterError()

double massbal_getGwaterError ( void )

Compute the signed groundwater continuity error from accumulated totals.

Returns
Percent discrepancy, positive for excess inflow and negative for excess outflow; a difference below one cubic foot returns TINY.
Postcondition
Updates GwaterTotals.finalStorage and pctError and the corresponding global error value. Recomputes final groundwater volume over all subcatchments.
Precondition
The global model and mass-balance totals are initialized; values use internal cubic-foot volume accounting, not report-scaled totals.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ massbal_getLoadingError()

double massbal_getLoadingError ( void )

Finalize surface pollutant loading totals and their continuity errors.

Returns
Largest signed pctError starting from zero, so all-negative errors produce zero; zero also results when no pollutants exist. Differences below 0.001 mass units produce TINY.
Postcondition
Adds remaining buildup to each finalLoad, computes percent errors, and converts COUNT-pollutant totals in place to log10 reporting values.
Note
This is a finalization operation, not an idempotent query: repeated calls add final buildup again and may transform COUNT totals repeatedly.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ massbal_getQualError()

double massbal_getQualError ( void )

Finalize routed pollutant mass totals and select the largest absolute error.

Returns
Signed percent error with the greatest absolute magnitude among pollutants, or zero when there are none. Tiny absolute mass discrepancies below 0.001 produce TINY.
Postcondition
Adds current stored mass to QualTotals[].finalStorage, sets pctError and QualError, and converts totals in place to lb/kg or log10 count reporting units.
Note
Call once during finalization. Repeated calls add storage and apply reporting conversions again; this is not an idempotent accessor.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ massbal_getStorage()

double massbal_getStorage ( char isFinalStorage)

Computes total system storage (nodes + links) filled.

Parameters
[in]isFinalStorageTRUE if at final time period.
Returns
Storage volume used (ft3).
Here is the caller graph for this function:

◆ massbal_getStoredMass()

double massbal_getStoredMass ( int p)

Computes mass of pollutant stored in conveyance network.

Parameters
[in]pPollutant index.
Returns
Mass of pollutant.
Here is the caller graph for this function:

◆ massbal_getSysFlows()

void massbal_getSysFlows ( double f,
double sysFlows[] )

Retrieves time-weighted average of old and new system flows.

Parameters
[in]fTime weighting factor.
[out]sysFlowsArray of total system flows.
Here is the call graph for this function:

Variable Documentation

◆ FlowTotals

TRoutingTotals FlowTotals

◆ GwaterTotals

TGwaterTotals GwaterTotals

◆ LoadingTotals

TLoadingTotals* LoadingTotals

◆ NodeInflow

double* NodeInflow

◆ NodeOutflow

double* NodeOutflow

◆ OldStepFlowTotals

TRoutingTotals OldStepFlowTotals

◆ QualTotals

TRoutingTotals* QualTotals

◆ RunoffTotals

TRunoffTotals RunoffTotals

◆ StepFlowTotals

TRoutingTotals StepFlowTotals

◆ StepQualTotals

TRoutingTotals* StepQualTotals

◆ TotalArea

double TotalArea