1. Overview & Design Philosophy

This simulator generates engine sound by solving the physical laws of compressible gas flow in real time. The core is a Port‑Hamiltonian System (PHS) that guarantees passivity and numerical stability, even for the large‑amplitude pulses typical of exhaust blowdown. All gas‑carrying pipes are modelled with the full nonlinear Euler equations discretised on a staggered grid.

Core Architecture

Key Design Principles

  1. Hamiltonian – total energy stored in the system $$H = \sum_{\text{pipes}} \sum_{i} E_{\text{tot},i} \;+\; \sum_{\text{volumes}} U_{\text{int}} \;+\; \ldots$$ where each pipe cell’s total energy is \(E_{\text{tot},i} = (\rho e + \frac12 \rho u^2) A_i \Delta x\).
  2. Dirac structure – dynamics $$\dot{\mathbf{x}} = (\mathbf{J} - \mathbf{R}) \nabla H(\mathbf{x}) + \mathbf{B}\,\mathbf{u}_{\text{ext}}, \quad \mathbf{y} = \mathbf{B}^T \nabla H(\mathbf{x}),$$ with \(\mathbf{J}\) skew‑symmetric and \(\mathbf{R} \succeq 0\).
  3. Implicit midpoint rule – A‑stable and passivity‑preserving (symplectic in the conservative limit), preserves the Dirac structure exactly at the discrete level.
  4. Power ports – effort (pressure, force) and flow (mass flow, velocity) conjugate pairs.
  5. Staggered grid – conserved quantities (mass, momentum, total energy) at cell centres; face areas are pre‑computed. All intensive properties (density, pressure, temperature) are derived from the state – never stored independently.
  6. Physical dissipation – viscous friction (Darcy–Weisbach) and heat transfer (Newton cooling) are included in the R matrix, not as ad‑hoc damping.

All components are implemented as C# classes inheriting from Component. The grid spacing dx is chosen to resolve the highest audio frequency (K cells per wavelength) to avoid numerical dispersion. The global PHSWorld assembles the state vector and solves the implicit system at each audio sample (44.1 kHz). Because the Euler equations are fully nonlinear, shock waves are captured without artificial clipping – essential for realistic gunfire‑like pops.