Saturday, December 28, 2024

SWMM5 inflow.c Summary

Below is a step-by-step explanation of the inflow.c file in EPA SWMM5. This file manages any external (direct) or dry-weather flow (DWF) inflows assigned to nodes in the drainage network. It covers:

  • Direct/External Inflows: e.g., time series flows or concentrations added directly to a node.
  • Dry-Weather Flows (DWF): e.g., constant or pattern-based baseline inflows for a node (like average daily sewage flows).

1. Overview of inflow.c

EPA SWMM5 allows you to specify additional inflows entering a drainage system node, beyond normal subcatchment runoff. They can be:

  1. External inflows:

    • Typically from time series, e.g., industrial wastewater discharges or other user-defined flows.
    • Can be flows, or pollutant concentrations/mass loads.
  2. Dry Weather Flows (DWF):

    • Typically average flows that vary by monthly/daily/hourly patterns.
    • E.g., base sanitary flows in a network.

The inflow.c file implements reading and storing these inflows, plus computing their actual flow/concentration at a given time step.


2. Data Structures

2.1 TExtInflow

typedef struct ExtInflow {
    int    param;        // -1 for FLOW or pollutant index
    int    type;         // type of inflow: FLOW_INFLOW, CONCEN_INFLOW, MASS_INFLOW
    int    tSeries;      // index of time series for inflow
    double cFactor;      // units conversion factor
    double sFactor;      // scaling factor
    double baseline;     // baseline inflow value
    int    basePat;      // baseline time pattern
    struct ExtInflow* next;
}  TExtInflow;
  • param: Which inflow parameter is assigned (either flow or pollutant). If -1, it’s FLOW; otherwise it’s a pollutant index.
  • type: Tells if it’s FLOW_INFLOW, CONCEN_INFLOW, or MASS_INFLOW.
  • tSeries: Index of a time series controlling the inflow variation over time.
  • cFactor, sFactor: Additional conversion and scaling factors.
  • baseline and basePat: A constant baseline inflow plus an optional time pattern multiplier.
  • Linked together in a linked list via next.

2.2 TDwfInflow

typedef struct DwfInflow {
    int     param;                // -1 for FLOW or pollutant index
    double  avgValue;             // average baseline DWF
    int     patterns[4];          // up to 4 pattern indexes
    struct  DwfInflow* next;
} TDwfInflow;
  • For dry-weather flow:
    • param = -1 for flow, otherwise pollutant index.
    • avgValue = average DWF. For flow, it’s eventually converted to user’s flow units.
    • patterns = monthly/daily/hourly/weekend patterns. The code sorts them by pattern type for speed.

3. Reading Inflow Inputs

3.1 inflow_readExtInflow()

int inflow_readExtInflow(char* tok[], int ntoks)
  • Parses a line of input data describing an external (direct) inflow.
  • Data line format:
    1. nodeID
    2. FLOW | pollutID
    3. tSeriesID (time series name, could be blank)
    4. (optional) CONCEN/MASS for pollutant, plus numeric fields:
      • A unitsFactor if MASS,
      • A scaleFactor,
      • A baseline,
      • A basePat (pattern).
  • If the parameter is FLOW, then param=-1; otherwise, it’s the pollutant index.
  • If it’s mass inflow, an additional factor in cf (conversion factor) is read.
  • This eventually calls inflow_setExtInflow() to create or update the TExtInflow object and link it into the node’s list of external inflows.

Key: The code sets:

  • Type = FLOW_INFLOW, CONCEN_INFLOW, or MASS_INFLOW.
  • Time Series reference.
  • Baseline flow or concentration.
  • Optional time pattern.

3.2 inflow_setExtInflow()

int inflow_setExtInflow(int j, int param, int type, int tseries, int basePat,
                        double cf, double baseline, double sf)
  • Actually allocates (or re-uses) a TExtInflow struct for a node j.
  • Fills in the parameters for external inflow:
    • param, type, tseries, cFactor, sFactor, baseline, basePat.
  • Returns 0 if success, or error code otherwise.

3.3 inflow_readDwfInflow()

int inflow_readDwfInflow(char* tok[], int ntoks)
  • Reads a line describing dry weather flow for a node.
  • Format:
    1. nodeID
    2. FLOW or pollutant name
    3. avgValue
    4. Up to 4 pattern IDs
  • Identifies the node, the param (flow or pollut index), the average value.
  • Finds up to 4 pattern references.
  • Creates a TDwfInflow object and attaches it to Node[j].dwfInflow.

4. Managing Inflow Lists

4.1 Deleting Inflows

  • inflow_deleteExtInflows(int j): frees the linked list of external inflows on node j.
  • inflow_deleteDwfInflows(int j): frees the linked list of dry-weather inflows on node j.

These are typically called at the end of a run or if the user re-initializes objects.


5. Computing Inflow Rates

During a simulation step, SWMM needs to compute the actual inflow from these data. Two main calls:

  1. inflow_getExtInflow(): for external inflows
  2. inflow_getDwfInflow(): for dry-weather flows

5.1 inflow_getExtInflow()

double inflow_getExtInflow(TExtInflow* inflow, DateTime aDate)
  • For a given date/time, returns the current external inflow.
  • Steps:
    • Possibly apply the baseline pattern multiplier (monthly/daily/hourly/weekend).
    • If time series is present, lookup the time series value at aDate and scale it.
    • Then combine those plus the conversion factor: flow or conc.=cFactor×(TimeSeriesValue×sFactor+baseline)\text{flow or conc.} = cFactor \times (\text{TimeSeriesValue} \times sFactor + baseline)

5.2 inflow_getDwfInflow()

double inflow_getDwfInflow(TDwfInflow* inflow, int month, int day, int hour)
  • For the current time’s month, day, hour, it collects pattern multipliers from up to 4 patterns:
    • monthly,
    • daily,
    • hourly,
    • weekend hourly.
  • A final factor f is then multiplied by inflow->avgValue.
  • Returns that product as the current DWF for the parameter (flow or pollutant).

5.3 Pattern Lookups

getPatternFactor(int p, int month, int day, int hour)

  • Takes pattern index p plus the current date/time, returns the pattern factor.
  • The code checks if pattern type is monthly/daily/hourly/weekend, picks the right factor from the pattern array. If out of range, defaults to 1.0.

6. Dry-Weather Flow Patterns

inflow_initDwfPattern(int j)

  • Initializes the Pattern[j] object with all factors = 1.0, no ID. Called when a Time Pattern is first created.

inflow_readDwfPattern(char* tok[], int ntoks)

  • Reads lines defining a pattern’s values.
  • Sets the pattern type = monthly/daily/hourly/weekend, then reads the numeric factors for up to 24 slots (for hourly) or 12 slots (monthly), etc.

7. Summary

  1. Reading Inputs:

    • External inflows from lines containing node, pollutant, time series, scaling, baseline, etc.
    • DWF inflows from lines containing node, pollutant, average value, up to 4 patterns.
  2. Managing Node Inflow Lists:

    • Each node has a linked list of TExtInflow objects and a linked list of TDwfInflow objects.
    • inflow_delete...() frees them.
  3. Using Patterns:

    • Patterns can adjust baseline or time series inflow by monthly/daily/hourly/weekend multipliers.
  4. Computing Inflows:

    • External inflows use inflow_getExtInflow() => time series + baseline pattern.
    • DWF inflows use inflow_getDwfInflow() => average flow + pattern multipliers.

In short, inflow.c parses inflow inputs and manages their time-dependent retrieval so that SWMM’s hydraulic/quality engine can incorporate these flows and pollutant loads at each node in each time step.


No comments:

A comprehensive explanation of how minimum travel distance relates to link length in InfoSewer

In hydraulic modeling of sewer networks, the minimum travel distance is a fundamental parameter that affects how accurately the model can si...