Skip to main content

EpanetWrapper Functional Specifications

Overview

EpanetWrapper provides a managed interface to EPANET's native functions, enabling .NET applications to interact with the EPANET simulation engine. It handles memory management, error handling, and provides type-safe access to EPANET functionality.

Core Functionality

1. EPANET Integration

  • Interface with EPANET native functions
  • Manage EPANET project lifecycle
  • Handle memory allocation and cleanup
  • Provide error handling and translation

2. Simulation Control

  • Initialize hydraulic simulations
  • Manage water quality analysis
  • Control simulation time steps
  • Process simulation results

3. Resource Management

  • Handle native resource allocation
  • Manage memory cleanup
  • Track resource state
  • Implement disposal patterns

Functional Requirements

Project Management

  1. Project Creation

    • Create EPANET project
    • Initialize project state
    • Set project parameters
    • Handle project cleanup
  2. File Management

    • Load input files
    • Handle report files
    • Manage output files
    • Process MSX files
  3. State Management

    • Track project state
    • Monitor hydraulic state
    • Track quality state
    • Handle state transitions

Simulation Control

  1. Hydraulic Simulation

    • Initialize hydraulic solver
    • Execute hydraulic calculations
    • Process hydraulic results
    • Manage hydraulic state
  2. Water Quality Simulation

    • Initialize quality solver
    • Execute quality calculations
    • Process quality results
    • Manage quality state
  3. Time Step Control

    • Calculate next hydraulic step
    • Determine quality time step
    • Manage simulation time
    • Handle time synchronization

Resource Management

  1. Memory Management

    • Allocate native resources
    • Track resource usage
    • Clean up resources
    • Handle disposal
  2. Error Handling

    • Translate EPANET errors
    • Log error messages
    • Implement recovery
    • Maintain error state
  3. State Tracking

    • Monitor project state
    • Track solver state
    • Handle state transitions
    • Manage cleanup

Interface Requirements

EPANET Interface

  1. Function Wrapping

    • Declare P/Invoke functions
    • Handle parameter marshaling
    • Manage return values
    • Process error codes
  2. Type Safety

    • Provide type-safe methods
    • Handle parameter validation
    • Manage type conversion
    • Ensure data integrity
  3. Error Handling

    • Translate error codes
    • Provide error messages
    • Implement recovery
    • Log errors

Resource Interface

  1. Resource Management

    • Implement IDisposable
    • Handle cleanup
    • Track resources
    • Manage state
  2. Memory Management

    • Allocate memory
    • Track usage
    • Clean up resources
    • Handle disposal

Performance Requirements

Execution Performance

  1. Native Calls

    • Optimize P/Invoke
    • Minimize marshaling
    • Reduce overhead
    • Improve performance
  2. Memory Usage

    • Efficient allocation
    • Proper cleanup
    • Resource tracking
    • Memory optimization

Integration Requirements

External Systems

  1. EPANET Integration

    • Interface with EPANET
    • Handle native calls
    • Manage resources
    • Process results
  2. Logging Integration

    • Log operations
    • Track errors
    • Record state
    • Monitor performance