A full 24-hour day is simulated on a repeating clock. Solar output follows a real daylight
sine curve between sunrise and sunset, scaled down by cloud cover; wind is stochastic — it
wanders around a mean using a smoothed random walk, the way real wind actually behaves rather
than sitting at a constant value. Demand follows a realistic two-peak household curve (morning
and evening), and the battery does honest energy-balance bookkeeping in kWh, not just a dial:
P_solar(t) = C_solar · (1 − cloud) · max(0, sin(π·(t−sunrise)/daylen))
P_wind(t) = C_wind · OU-smoothed random walk, clamped [0,1]
P_load(t) = scale · (base + morningBump(t) + eveningBump(t))
P_net = P_solar + P_wind − P_load
SOC(t+dt) += P_net·dt / E_capacity (efficiency-derated on charge)
SOC clamped to [0%, 100%]
Blackout when P_net < 0 AND battery has no energy left to cover it
- Chart plots solar, wind, total generation, demand and battery SOC over the trailing
24 simulated hours, with a shaded night band.
- Blackout indicator fires the instant demand outruns generation plus whatever the
battery can still discharge — exactly the failure mode real islanded/weak-grid microgrids
are sized to avoid.
- Raise cloud cover or shrink the battery to watch the system tip into blackout during the
evening peak once the sun has set and storage runs out.