EpanetWrapper Design Documentation
Architecture Overview
EpanetWrapper is designed as a .NET wrapper for EPANET's native functions, providing a managed interface to the EPANET simulation engine. It implements the IDisposable pattern for proper resource management and provides a type-safe interface to EPANET's functionality.
Technical Specifications
- Target Framework: .NET 8.0
- Platform: x64
- Architecture: Class Library
Component Architecture
Core Components
Native Interface Layer
- P/Invoke declarations
- Memory management
- Error handling
- Type conversions
Simulation Control
- Hydraulic solver interface
- Water quality solver interface
- Network topology management
- Results collection
Resource Management
- Memory allocation
- Resource cleanup
- Error recovery
- Performance optimization
Dependencies
Internal Project References
- HTLogger (Internal logging system)
Native Dependencies
- EPANET native libraries (epanet2.dll)
Class Structure
Main Class: EpanetWrapper
public partial class EpanetWrapper : IDisposable
{
// Properties
public string InputFile { get; private set; }
public string MsxFile { get; private set; }
public string ReportFile { get; private set; }
public string OutputFile { get; private set; }
public IntPtr Project { get; private set; }
public bool IsOpen { get; private set; }
public bool IsOpenH { get; private set; }
public bool IsOpenQ { get; private set; }
public HTLogger Logger { get; private set; }
// Core Methods
public bool Startup(bool doQuality, string msxFile)
public bool RunNextHQ(bool doQuality, ref long t, ref long timeToNextHydraulicEvent, ref long qt, ref long qstep)
public void Dispose()
}
Data Flow Architecture
Initialization Flow
Simulation Flow
Memory Management
- Implements IDisposable pattern
- Proper cleanup of native resources
- Memory leak prevention
- Resource state tracking
Error Handling
- EPANET error code translation
- Exception management
- Error logging
- Recovery procedures
Performance Considerations
- Native call optimization
- Memory usage optimization
- Resource management
- Thread safety
Integration Architecture
- Clean interface design
- Type-safe method calls
- Resource lifecycle management
- Error propagation
Future Architecture Considerations
- Additional EPANET features
- Performance optimizations
- Memory management improvements
- Error handling enhancements