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 = 25toEN_LinkPropertyenum - Added
EN_LEAK_EXPAN = 26toEN_LinkPropertyenum - Added
EN_LEAKAGEFLOW = 29toEN_NodePropertyenum
2. C# Wrapper Enums (EpanetWrapper/EpanetEnum.cs)
- Added corresponding leakage constants to C# enums:
EN_LEAK_AREA = 25inEN_LinkPropertyEN_LEAK_EXPAN = 26inEN_LinkPropertyEN_LEAKAGEFLOW = 29inEN_NodeProperty
3. EpanetWrapper Methods (EpanetWrapper/EpanetWrapper/)
EpanetWrapperLinks.cs: Added leakage methods for links:
GetLinkLeakage(int index)- Gets leakage areaGetLinkLeakArea(int index)- Gets leak area propertyGetLinkLeakExpansion(int index)- Gets leak expansion propertySetLinkLeakArea(int index, double value)- Sets leak areaSetLinkLeakExpansion(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:
PipeHydrstable: AddLeakagecolumnJunctionHydrstable: AddLeakageFlowcolumnPipestable: AddLeakAreaandLeakExpansioncolumns
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
- Units: All leakage properties use EPANET's internal units and are converted to user units by the wrapper
- Compatibility: This implementation maintains backward compatibility with existing EPANET models
- Performance: Leakage calculations are performed by the EPANET engine, not the wrapper
- Validation: The FAVAD model implementation follows the specifications provided in the original documentation
Files Modified
EPANET_OWA/include/epanet2_enums.h- Added leakage constantsEpanetWrapper/EpanetEnum.cs- Added C# enum constantsEpanetWrapper/EpanetWrapper/EpanetWrapperLinks.cs- Added link leakage methodsEpanetWrapper/EpanetWrapper/EpanetWrapperNodes.cs- Added node leakage methodEpanetWrapper/ENModelReferenceCodeRemoved.cs- Implemented leakage property retrievalNetworkManager/Builders/ResultsBuilder.cs- Added leakage to results gathering
Files Requiring Updates
- Database model classes (EN2Models project)
- Database migration scripts
- EPANET engine source files (EPANET_OWA/src/)
- Input file parser (EPANET_OWA/src/input*.c)
- 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_LEAKAGEFLOWproperty 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_LEAKAGEFLOWproperty 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_LEAKAGEFLOWproperty works for reservoirs - Implementation: Could add to
ReservoirHydrbut may not be meaningful
Links - Leakage Support
✅ Pipes - YES
- Physical Reality: Pipes are the primary source of leakage in water systems
- EPANET Support:
EN_LEAK_AREAandEN_LEAK_EXPANproperties 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
Recommended Model Implementation
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:
- PipeHydrs table: Add
Leakagecolumn (double) - JunctionHydrs table: Add
LeakageFlowcolumn (double) - Pipes table: Add
LeakAreaandLeakExpansioncolumns (double) - TankHydrs table: Add
LeakageFlowcolumn (double) - if implementing tank leakage - ReservoirHydrs table: Add
LeakageFlowcolumn (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_AREAandEN_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.