# Calculation Algorithms

WEAP calculates a water and pollution mass balance for every node and link in the system on a monthly time step. Water is dispatched to meet instream, consumptive and hydropower requirements, subject to demand priorities, supply preferences, mass balance and other constraints. Point loads of pollution into receiving bodies of water are computed, and instream water quality concentrations are calculated.

WEAP operates on a monthly time step, from the first month of the Current Accounts year through the last month of the last scenario year. Each month is independent of the previous month, except for reservoir and aquifer storage, and catchment soil moisture levels (soil moisture method only). Thus, all of the water entering the system in a month (e.g., headflow, groundwater recharge, or runoff into reaches) is either stored in an aquifer, reservoir or catchment, or leaves the system by the end of the month (e.g., outflow from end of river, demand site consumption, reservoir or river reach evaporation, transmission and return flow link losses). Because the time scale is relatively long (monthly), all flows are assumed to occur instantaneously. Thus, a demand site can withdraw water from the river, consume some, return the rest to a wastewater treatment plant that treats it and returns it to the river. This return flow is available for use in the same month by downstream demands.

Each month the calculations follow this order:

1. Annual demand and monthly supply requirements for each demand site and flow requirement.  Catchment potential evapotranspiration, snow accumulation, and runoff and infiltration, assuming no irrigation inflow (yet).

2. Inflows and outflows of water for every node and link in the system. This includes calculating withdrawals from supply sources to meet demand, and dispatching reservoirs. This step is solved by a linear program (LP), which attempts to optimize coverage of demand site and instream flow requirements, subject to demand priorities, supply preferences, mass balance and other constraints.

3. If a MODFLOW model is linked, WEAP results (groundwater pumping and recharge, and river stage) will be loaded into the MODFLOW input files, MODFLOW will be run for one timestep, and MODFLOW results  (cell heads, and flows between surface and groundwater) will be read into WEAP.