Skip to main content

EPANET Leakage Implementation Summary

Overview

This document summarizes the implementation of leakage calculations in the EPANET results gathering system based on the FAVAD model specifications provided.

Completed Implementation

1. EPANET API Constants (EPANET_OWA/include/epanet2_enums.h)

  • Added EN_LEAK_AREA = 25 to EN_LinkProperty enum
  • Added EN_LEAK_EXPAN = 26 to EN_LinkProperty enum
  • Added EN_LEAKAGEFLOW = 29 to EN_NodeProperty enum

2. C# Wrapper Enums (EpanetWrapper/EpanetEnum.cs)

  • Added corresponding leakage constants to C# enums:
    • EN_LEAK_AREA = 25 in EN_LinkProperty
    • EN_LEAK_EXPAN = 26 in EN_LinkProperty
    • EN_LEAKAGEFLOW = 29 in EN_NodeProperty

3. EpanetWrapper Methods (EpanetWrapper/EpanetWrapper/)

  • EpanetWrapperLinks.cs: Added leakage methods for links:

    • GetLinkLeakage(int index) - Gets leakage area
    • GetLinkLeakArea(int index) - Gets leak area property
    • GetLinkLeakExpansion(int index) - Gets leak expansion property
    • SetLinkLeakArea(int index, double value) - Sets leak area
    • SetLinkLeakExpansion(int index, double value) - Sets leak expansion
  • EpanetWrapperNodes.cs: Added leakage method for nodes:

    • GetNodeLeakageFlow(int i) - Gets computed leakage flow at node

4. Model Integration (EpanetWrapper/ENModelReferenceCodeRemoved.cs)

  • Implemented leakage property retrieval in GetLinkByIndex() method
  • Implemented leakage coefficient retrieval in GetPipeByIndex() method:
    • pipe.LeakArea - Leak area (sq mm per 100 units of pipe length)
    • pipe.LeakExpansion - Leak expansion rate (sq mm per unit of pressure head)

5. Results Builder Integration (NetworkManager/Builders/ResultsBuilder.cs)

  • PipeHydr Results: Added result.Leakage = wrapper.GetLinkLeakage(pipe.Index)
  • JunctionHydr Results: Added result.LeakageFlow = wrapper.GetNodeLeakageFlow(junc.Index)

FAVAD Model Implementation

The implementation follows the FAVAD (Fixed and Variable Area Discharge) model:

Formula

Ql = Cd * Ao * (H^0.5) * (1 + m*H)^0.5

Where:

  • Cd = discharge coefficient (handled by EPANET engine)
  • Ao = area of cracks under zero pressure conditions (EN_LEAK_AREA)
  • H = pressure head (computed by EPANET)
  • m = rate at which crack area expands as pressure increases (EN_LEAK_EXPAN)

Property Definitions

  • Leak Area (EN_LEAK_AREA): Area of leak openings in square millimeters per 100 units of pipe length
  • Leak Expansion (EN_LEAK_EXPAN): Rate of leak expansion in square millimeters per unit of pressure head (ft or m)
  • Leakage Flow (EN_LEAKAGEFLOW): Computed leakage flow rate at nodes

Required Next Steps

1. Database Model Updates

The following model classes need to be updated to include leakage properties:

PipeHydr Model

public class PipeHydr
{
// ... existing properties
public double Leakage { get; set; } // Leakage flow rate
}

JunctionHydr Model

public class JunctionHydr
{
// ... existing properties
public double LeakageFlow { get; set; } // Leakage flow at junction
}

Pipe Model

public class Pipe
{
// ... existing properties
public double LeakArea { get; set; } // Leak area property
public double LeakExpansion { get; set; } // Leak expansion property
}

2. Database Migration

Create Entity Framework migration to add leakage columns to database tables:

  • PipeHydrs table: Add Leakage column
  • JunctionHydrs table: Add LeakageFlow column
  • Pipes table: Add LeakArea and LeakExpansion columns

3. EPANET Engine Integration

The EPANET engine (EPANET_OWA) needs to be updated to:

  • Implement the FAVAD model calculations in the hydraulic solver
  • Store leakage results in the output file
  • Handle leakage property setting and retrieval

4. Input File Support

Update EPANET input file parser to handle leakage properties in the [PIPES] section:

[PIPES]
;ID Node1 Node2 Length Diameter Roughness MinorLoss LeakArea LeakExpansion
PIPE1 NODE1 NODE2 1000 12 130 0 0.1 0.001

5. Testing and Validation

  • Test leakage property setting and retrieval
  • Validate FAVAD model calculations
  • Test results gathering and storage
  • Verify database persistence

Usage Example

Setting Leakage Properties

// Set leak area for a pipe
wrapper.SetLinkLeakArea(pipeIndex, 0.1); // 0.1 sq mm per 100 units

// Set leak expansion for a pipe
wrapper.SetLinkLeakExpansion(pipeIndex, 0.001); // 0.001 sq mm per unit head

Retrieving Leakage Results

// Get leakage flow for a pipe
double pipeLeakage = wrapper.GetLinkLeakage(pipeIndex);

// Get leakage flow at a junction
double nodeLeakage = wrapper.GetNodeLeakageFlow(nodeIndex);

// Get leakage properties for a pipe
double leakArea = wrapper.GetLinkLeakArea(pipeIndex);
double leakExpansion = wrapper.GetLinkLeakExpansion(pipeIndex);

Integration Points

Energy Calculations

Leakage flows should be included in energy balance calculations:

  • Leakage energy = Ql H Dt where Ql is leakage flow, H is head, Dt is time step

Results Storage

Leakage results are stored in the same pattern as other hydraulic results:

  • Link leakage stored in PipeHydr.Leakage
  • Node leakage stored in JunctionHydr.LeakageFlow

Notes

  1. Units: All leakage properties use EPANET's internal units and are converted to user units by the wrapper
  2. Compatibility: This implementation maintains backward compatibility with existing EPANET models
  3. Performance: Leakage calculations are performed by the EPANET engine, not the wrapper
  4. Validation: The FAVAD model implementation follows the specifications provided in the original documentation

Files Modified

  1. EPANET_OWA/include/epanet2_enums.h - Added leakage constants
  2. EpanetWrapper/EpanetEnum.cs - Added C# enum constants
  3. EpanetWrapper/EpanetWrapper/EpanetWrapperLinks.cs - Added link leakage methods
  4. EpanetWrapper/EpanetWrapper/EpanetWrapperNodes.cs - Added node leakage method
  5. EpanetWrapper/ENModelReferenceCodeRemoved.cs - Implemented leakage property retrieval
  6. NetworkManager/Builders/ResultsBuilder.cs - Added leakage to results gathering

Files Requiring Updates

  1. Database model classes (EN2Models project)
  2. Database migration scripts
  3. EPANET engine source files (EPANET_OWA/src/)
  4. Input file parser (EPANET_OWA/src/input*.c)
  5. Output file handling (EPANET_OWA/src/outfile/)

Model Support for Leakage

Nodes - LeakageFlow Support

Junctions - YES

  • Physical Reality: Junctions can have leakage from connecting pipes
  • EPANET Support: EN_LEAKAGEFLOW property works for all node types
  • Implementation: Already implemented in JunctionHydr

Tanks - YES

  • Physical Reality: Tanks can have leakage from walls, connections, or overflow
  • EPANET Support: EN_LEAKAGEFLOW property works for tanks
  • Implementation: Should add to TankHydr

⚠️ Reservoirs - TECHNICALLY YES, but...

  • Physical Reality: Reservoirs typically have minimal leakage (they're usually large bodies of water)
  • EPANET Support: EN_LEAKAGEFLOW property works for reservoirs
  • Implementation: Could add to ReservoirHydr but may not be meaningful

Pipes - YES

  • Physical Reality: Pipes are the primary source of leakage in water systems
  • EPANET Support: EN_LEAK_AREA and EN_LEAK_EXPAN properties designed for pipes
  • Implementation: Already implemented in PipeHydr

Pumps - NO

  • Physical Reality: Pumps themselves don't typically leak (they're sealed mechanical devices)
  • EPANET Support: Leakage properties don't apply to pumps
  • Implementation: Don't add to PumpHydr

Valves - NO

  • Physical Reality: Valves are designed to be leak-tight when closed
  • EPANET Support: Leakage properties don't apply to valves
  • Implementation: Don't add to ValveHydr

High Priority (Essential)

// Node Results
public class JunctionHydr { public double LeakageFlow { get; set; } }
public class TankHydr { public double LeakageFlow { get; set; } }

// Link Results
public class PipeHydr { public double Leakage { get; set; } }

// Network Definition
public class Pipe {
public double LeakArea { get; set; }
public double LeakExpansion { get; set; }
}

Medium Priority (Optional)

public class ReservoirHydr { public double LeakageFlow { get; set; } }

Don't Implement

// Don't add leakage to these - not physically meaningful
public class PumpHydr { /* no leakage */ }
public class ValveHydr { /* no leakage */ }

Database Tables to Update

You'll need to add columns to these database tables:

  1. PipeHydrs table: Add Leakage column (double)
  2. JunctionHydrs table: Add LeakageFlow column (double)
  3. Pipes table: Add LeakArea and LeakExpansion columns (double)
  4. TankHydrs table: Add LeakageFlow column (double) - if implementing tank leakage
  5. ReservoirHydrs table: Add LeakageFlow column (double) - if implementing reservoir leakage

EPANET API Behavior

The EPANET API treats leakage differently:

  • EN_LEAKAGEFLOW: Available for ALL node types (junctions, tanks, reservoirs)
  • EN_LEAK_AREA and EN_LEAK_EXPAN: Only meaningful for pipes (PIPE and CVPIPE link types)

Summary

Add LeakageFlow to:

  • JunctionHydr ✅ (already done)
  • TankHydr ✅ (recommended)
  • ReservoirHydr ⚠️ (optional, low priority)

Add Leakage to:

  • PipeHydr ✅ (already done)

Don't add leakage to:

  • PumpHydr ❌ (not physically meaningful)
  • ValveHydr ❌ (not physically meaningful)

The FAVAD model is specifically designed for pipe leakage, which is why the leakage properties only apply to pipes, while the computed leakage flow can be retrieved at any node.