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
- Nonlinear 1‑D pipes – variable cross‑section, mass, momentum, and energy conservation (Euler equations). Shock waves and temperature variations are naturally reproduced. The pipe is a distributed storage element; its geometric volume contributes to the total gas capacity.
- 0‑D thermodynamic volumes – manifolds described by mass and internal energy; ideal gas law gives pressure and temperature.
- Cylinder – moving piston, combustion heat release (Wiebe function), valve orifice flows, and knock detection.
- Multi‑port junctions – T‑, X‑, and H‑junctions that enforce pressure equality and mass conservation.
- Acoustic radiator (FW‑H) – converts mass flow and force at the exit into far‑field sound pressure, producing bang, crack, and jet noise.
- Outdoor reverberation – ground reflection and feedback delay network (FDN) for the diffuse tail.
Key Design Principles
- 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\).
- 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\).
- Implicit midpoint rule – A‑stable and passivity‑preserving (symplectic in the conservative limit), preserves the Dirac structure exactly at the discrete level.
- Power ports – effort (pressure, force) and flow (mass flow, velocity) conjugate pairs.
- 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.
- 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.