Simulator design (draft for discussion)

Source: Doug's Part Four, 2026-11-24. Related notes: rule-curves.md, authorities.md, research-data-map.md. Nothing here is built yet. Items marked Q are questions for Doug.

1. The idea in one paragraph

The user picks a historical date. The simulator rebuilds that water year from October 1 up to the date, using the research database, and draws it: lake level, inflow, releases, snowpack, river flows. From that date forward the user takes over. They set the snowpack, the Boysen and Buffalo Bill releases, the expected inflow and the Afterbay release, and watch the lake and river respond day by day through September 30.

The simulator serves two audiences:

Audience (decided by Doug, 2026-11-24)

The simulator is for Doug, members of the Bighorn River Alliance, students, and possibly Reclamation staff. So:

2. The two halves of the timeline

History (Oct 1 → chosen date) Simulation (chosen date → Sep 30)
Source Database, read-only Simulator mass balance
Lake elevation bhr_fb_por Computed from storage on bhr_capacity
Inflow bhr_in_por User scenario (section 3)
Gains below Boysen and Buffalo Bill bhr_gain_por (= inflow − Boysen − Buffalo Bill releases) User scenario
Boysen + Buffalo Bill release Derived: bhr_in_por − bhr_gain_por (combined only; see the data gaps) User sliders
Afterbay / river release bhr_qrd_por, total bhr_qd_por, canal bhr_qj_por User, or the simulated operator (section 4)
Snowpack bhr_se_por (basin SWE, inches), bhr_nrcs_wteq (25 SNOTEL sites) User scenario
Downstream St. Xavier, Yellowstone gauges (USGS) Routed from the release

A vertical "today" line marks the chosen date. Everything left of it is fact; everything right of it is the scenario. What actually happened after the date is drawn as a reference line. That is the best teaching device we have: "you did X, Reclamation did Y." Setting (decided by Doug, 2026-11-24): Actual history is Show / Faint / Hide, with Faint as the default. Hide turns a past year into a blind exercise. It applies to every chart, and it has no effect after today in the current water year.

Mass balance (daily). S[t] = S[t−1] + (inflow − dam release − canal − evaporation) × 1.98347

3. Scenario inputs (from the chosen date forward)

Doug's list

  1. Snow water equivalent (decided by Doug, 2026-11-24).
    • Show a small line chart of the 30-year average basin SWE only, in inches, Oct–Sep. The average peaks at 13.3 in. on April 10 (bhr_swe_30y_avg, 365 days) and melts out by early July. This is the same view as the SWE card in Doug's iosBighorn app.
    • The user clicks a point on the chart to predict this year's peak: a date and a depth in inches.
    • The simulator reshapes the rest of the average curve to pass through that point. Accumulation scales up to the peak, and melt follows the average recession, shifted to the chosen date.
    • Source: bhr_swe_30y_avg. Check which 30-year window it covers before building.
    • Open: how the predicted peak feeds the inflow. My proposal is to suggest an April–July inflow volume from a peak-SWE-vs-inflow regression on 1978–2025 (bhr_se_por against bhr_in_por). The user can accept it or override it. To confirm with Doug.
  2. Upstream flows (decided by Doug, 2026-11-24). Phased:
    • Now: one combined "Boysen + Buffalo Bill" release, from boyr_qd_por + bbr_qriv_por (since 2026-11-28; before that it was derived as bhr_in_por − bhr_gain_por, which also counted the Heart Mountain Canal draw). Oct–Mar is a steady winter release (Boysen 750 + Buffalo Bill 375 cfs by default, Doug 2026-11-29); Apr–Sep the user sets the combined release by month, or leaves a month blank to follow the pattern.
    • Kane and Lovell (Bighorn River at Kane, USGS 06279500; Shoshone River near Lovell, 06285100) carry the majority of the lake's inflow: the dam releases plus the gains above the gauges. They are not the releases themselves (Doug, 2026-11-28). They could later split the inflow into "at Kane and Lovell" and "local below them".
    • Later option: set Boysen and Buffalo Bill separately (both histories are loaded), with their capacity tables for an upstream-reservoir view.
  3. Bighorn Lake inflow. The rule: inflow ≥ Boysen + Buffalo Bill releases, because gains can't go negative over a season. Entered either as:
    • an April–July (or remaining-season) volume, shaped by a historical hydrograph the user picks (a wet year, a dry year, or "like 2011"), or
    • a gain volume added on top of the upstream releases.
  4. Afterbay release. Either the user drives it (manual mode) or the simulated operator follows the criteria (auto mode). See section 4.

Suggested additions

  1. Rule-curve set: 2020 no-encroachment (default), 2012 or 2010.
  2. Starting conditions override, for "what if the lake had been 5 ft lower on April 1?"
  3. Forecast vs. reality (decided by Doug, 2026-11-24).
    • The simulated operator uses the forecast as it stood on each date: April 1, April 15, May 1, May 15 and June 1, plus the Feb/Mar forecasts for the winter adjustments. There is no perfect-foresight option.
    • The user predicts how wrong that forecast is with a percentage adjustment (for example −20% … +40%). The inflow that actually arrives in the scenario is forecast × (1 + adjustment), shaped by the chosen hydrograph.
    • So the operator plans on the official number while the user decides what nature delivers. For calibration: 2011's actual April–July inflow was 184% of the April 1 forecast (+84%), and 2015's was 228% (+128%). 2025's was 90% (−10%).
    • Where no historical forecast exists for the chosen date, the user enters the forecast. The SWE-based suggestion (item 1) pre-fills it.
    • For past years with "Actual history" on, the simulator also shows what the adjustment really turned out to be (actual ÷ forecast − 1).
  4. Storm events. Drop a rain-on-snow or rain event onto a day: extra volume over N days. This is the late-May 2011 case.
  5. Yellowstone condition. Use the historical Yellowstone flows, or scale them, to drive Corps hold-backs once the lake is in the flood pool (see authorities.md).
  6. Ramp limit: 500 cfs/day by default, up to 2,000.
  7. Constraints the user can toggle:
    • minimum river flow (e.g. 1,500 / 2,000 / 2,500 cfs);
    • maximum release before spill;
    • October 31 target band;
    • Horseshoe Bend lake-level wishes (e.g. boat ramp usable above X ft).
  8. Canal diversion (bhr_qj_por): historical by default, editable.
  9. Evaporation: monthly default; small but real in August–September.

4. Operator modes

Mode Who sets the Afterbay release
Manual The user, day by day or as a schedule
Auto (Reclamation) Simulated operator. Uses the Nov–Mar formula and risk sharing, and the Apr–Jul rule curves with RiverWare-style targeting (Apr 30 → minimum → end of May → July fill). Also applies low-flow operations below minimum fill, and the ramp limit
Auto + Corps Same as Auto, plus Corps control above 3640 ft: hold back when the Yellowstone is high, evacuate when it isn't
Coach The user sets releases while the simulator shows what Auto would have done, and flags rule-curve departures, flood-pool entry and missed targets

Coach mode is the educational heart: learners make decisions and get immediate, explained feedback.

Decided by Doug (2026-11-24): build all of the modes, Manual, Auto and Coach. For any past water year, Coach compares the user's run against two references:

Only the current water year has no "actual" after today.

5. Outputs and graphics

Main chart. Lake elevation with:

Flows panel. Inflow, Boysen + Buffalo Bill, gains, Afterbay release, St. Xavier, and optionally Glendive.

Snow panel. The 30-year average SWE curve with the user's predicted peak, as above. Doug asked for the average only, so no clutter from other years.

Status strip (per day):

Scorecard at the end of a run:

Biology overlays. Thresholds tied to flow and temperature: spawning (redds in spawn), side-channel dewatering, gas supersaturation when spilling. To be defined with the criteria (see the TODO list).

Print (decided by Doug, 2026-11-24). Nothing is saved. Instead, the user prints. The workflow is: select a date, change parameters, print, repeat.

6. Ensemble forecast (deferred)

The idea:

  1. Take today's state: SWE, soil moisture proxy, lake, upstream reservoirs.
  2. Run the rest of the season under every historical year's inflow pattern (≈ 1967–2025), scaled to the current snowpack.
  3. Plot the spread as percentile bands (10/50/90) for inflow volume, lake level and release.

This is the ESP method NRCS and the River Forecast Centers use. A first version needs nothing beyond what's already in the database. Doing it well needs research into snowpack-to-runoff relationships by month. Deferred, per Doug.

7. Data gaps that affect this design

8. Build order (proposal)

Revised 2026-11-24 after Doug's six answers:

Where we are (2026-11-25): steps 1–4 are built and committed. Step 5, Corps mode, is built (section 12), uncommitted. The Yellowstone data is in the Research Library (usgs_<gauge>_por, 2026-11-25).

  1. History view. ✅ Built 2026-11-24: /simulate and /api/water-year.
    • Date picker; rebuild Oct 1 → date from the database.
    • Lake and river charts with pool zones.
    • Actual-history line, Show / Faint / Hide.
    • Print layout.
    • Usable on its own as a teaching tool.
  2. Manual simulation. ✅ Built 2026-11-25. See section 9.
    • Mass balance on bhr_capacity.
    • SWE peak click, forecast and % adjustment, inflow shaping.
    • Combined upstream release.
    • User-set Afterbay schedule with the ramp limit.
  3. Auto (Reclamation) operator. ✅ Built 2026-11-25. See section 10.
    • Nov–Mar formula, rule curves (2020 default), low-flow operations.
    • Validated against WY2010, 2011 and 2018 actuals (and 2015, 2017, 2021, 2023, 2026).
  4. Coach mode and scorecard. ✅ Built 2026-11-25. See section 11. Your run vs. the rules vs. what actually happened.
  5. Corps mode. ✅ Built 2026-11-25. See section 12. Flood-pool control with Yellowstone-keyed holds.
  6. Data work that unlocks more, which can run in parallel with steps 2–5:
    • Kane and Lovell _por tables;
    • historical forecasts from 2009 on;
    • Yellowstone gauges;
    • upstream capacity tables.
  7. Ensemble forecast (deferred).
  8. Backward solver. ✅ Built 2026-11-25 (section 14). From Doug's 2009 simulator.
  9. Solve several months at once. ✅ Built 2026-11-25 (section 15). Original note: Let the user mark which months the solver may change (or give each month a minimum and maximum release), and find a schedule of monthly releases that reaches the aim: the 2009 simulator's twelve monthly boxes with a Lookup button. The steady-release solver can't hit a target like 3640 ft on Jul 31 in a normal year, which needs less water out now and more later. Likely an optimizer over the monthly releases (smoothest schedule that meets the aim), bounded by the ramp limit and river minimums.
  10. Ensemble ("What are the odds?"). ✅ Built 2026-11-25 (section 16, plan in ensemble-plan.md). TODO: consider a hindcast coverage bar (for example 10-90% bands covering 70-90% of real outcomes); weight by the lake level as well as snowpack; a Web Worker if the sample grows.

9. How the manual simulation works (step 2)

Code: public/js/sim-engine.js (the model) and public/js/simulate.js (the controls). The model runs in the browser from the day after the chosen date to Sep 30.

Water balance

Inflow

Boysen + Buffalo Bill

Afterbay release

Results and print

Forecast story

A one-line plain-language summary above the forecast table, for students: "A steady slide, from 105% to 42% of average", "A steady climb, from 101% to 256% of average. The water that came was 84% more than the April 1 forecast" (2011). In Hide mode it covers only the forecasts known on the chosen date.

10. The auto (Reclamation) operator (step 3)

Code: makeOperator in public/js/sim-engine.js; the rule curves come from /api/rule-curves (managers/rule-curve-manager.ts, built from the three data/rule-curves-*.json files). Choose Auto under Afterbay release. The rule-curve set defaults to the one in force that year (WY ≤ 2011: 2010; 2012–2019: 2012; 2020 on: 2020 no-encroachment), or the user picks one. The rule curve the operator is following is drawn as a dotted line on the lake chart.

The rules, as coded

It follows the 2018 RiverWare review's description of the criteria (rule-curves.md, "How the RiverWare model applies the curves"):

Period What the operator does
Nov–Mar One steady winter release, recomputed on the 1st of each month, that reaches 3617 ft on Mar 31. Risk sharing: if under 2,000 cfs, aim at 3615 ft and clamp to 1,500–2,000; if over 2,500, aim at 3619 ft with at least 2,500.
Feb–Mar, big year If the forecast is at or above the upper-quartile (UQ) curve volume, draft toward the Apr 30 rule-curve level instead.
Apr–Jul Interpolate the rule curve for the forecast in effect (storage between the two bracketing curves, by volume, per the spreadsheet) and release to be on it a week ahead. From June 1, release at least the steady flow that fills to 3640 ft on Jul 31 according to the forecast. Floor 2,000 cfs, cap 15,000 cfs.
Apr–Jul, dry year Below minimum fill: low-flow operations, a steady 1,500–2,000 cfs aiming at 3640 ft on Jul 31.
Aug–Oct Reach 3637.5 ft (middle of 3635–3640) on Oct 31, if that allows at least 2,500 cfs. Otherwise release for 3617 ft next Mar 31, clamped to 1,500–2,000 cfs.
Any day If the coming week would carry the lake over 3640 ft, release enough to hold it.
Above 3640 ft The Corps is in control (step 5). For now the operator drains to 3639.5 ft within a week, up to 15,000 cfs.

Validation: full water years, What happened inflow, Auto releases

Water year Curves Peak, auto vs. actual (ft) Days above 3640, auto vs. actual Sep 30, auto vs. actual (ft)
2010 2010 3640.4 vs. 3645.6 15 vs. 40 3637.5 vs. 3630.1
2011 2010 3641.1 vs. 3655.0 28 vs. 97 3636.8 vs. 3640.3
2015 2012 3642.8 vs. 3647.8 38 vs. 51 3638.0 vs. 3635.7
2017 2012 3640.8 vs. 3647.0 24 vs. 39 3637.1 vs. 3639.5
2018 2012 3640.3 vs. 3645.3 12 vs. 55 3636.7 vs. 3634.1
2021 2020 3635.0 vs. 3633.6 0 vs. 0 3631.4 vs. 3626.7
2023 2020 3641.5 vs. 3647.7 24 vs. 41 3637.1 vs. 3638.3
2026 2020 3633.3 vs. 3633.4 0 vs. 0 3624.7 vs. 3624.2

Ideas noted for later

11. Coach mode and the scorecard (step 4)

Code: scorecard and coach in public/js/sim-engine.js; rendered by renderResults and renderCoach in public/js/simulate.js.

Coach

Scorecard

One row each for your run (or Auto / Replay), the rules (when coaching) and what happened (follows Show / Faint / Hide). Counted from the day after the chosen date:

Group Columns
Lake Highest (date), days above 3640 ft, Jul 31, Sep 30, Horseshoe Bend ramp usable (share of May 15–Sep 15 days at or above 3617 ft)
River Lowest and highest (dates), days below 2,000 cfs, days above 8,000 cfs
Power Energy (GWh, estimate) and spill (af)

12. Corps mode (step 5)

Controller. On each simulated day, if the lake starts the day above 3640 ft the Corps is in control (controller: "COE"); otherwise Reclamation ("BOR"). It applies to My schedule and Auto runs, not to What happened. A tick strip along the bottom of the lake chart shows the Corps days. A Flood pool box in the scenario holds the settings; turning it off restores the old behavior (the Auto operator drains the pool within a week).

Top of joint use under My schedule. If the schedule would carry the lake above 3640 ft, the release follows the inflow to hold it at 3640 ft (ramping up to 2,000 cfs/day), as Reclamation does before the Corps steps in. Without it the Corps took over at 3640.05 ft, evacuated for a day and handed back, and the schedule ramped down again: a saw-tooth river every few days (Doug, 2026-11-29). The Corps still takes over when the inflow outruns the ramp. It looks two weeks ahead (the steady release that keeps the lake at or below 3640 ft on each of the next 14 days), so the release starts rising while the lake is still filling: without that it jumped from the schedule to the full inflow in a few days and overshot (Doug, 2026-11-29, a spike to 8,200 cfs in mid-June).

The release. For each day the Corps is in control (makeCorpsHold, corpsRelease in sim-engine.js):

  1. For each gauge, base = flow at the gauge travel_days later − the recorded Afterbay release that day. That is everything the Bighorn's own release is not (the Yellowstone and the Bighorn's tributaries). It is scaled by the Yellowstone % setting. Travel days come from data/yellowstone-gauges.json; when the estimate is fractional, the larger base of the two neighboring days is used.
  2. headroom = limit − base, with the limit the NWS action flow (else minor) at that gauge, or the minor flow if chosen.
  3. The release is the smallest headroom, held between the hold floor (3,500 cfs) and the evacuation rate: 9,000 cfs at 3640 ft, plus 1,000 cfs per foot above it, up to 15,000.
  4. Within a foot of the top of the flood pool (3656 ft), dam safety overrides everything: 15,000 cfs.
  5. The optional Missouri cap limits the release last, except under dam safety. The default is none; Doug will ask Reclamation what, if anything, it is.
  6. Ramp: the Corps ramp is 2,000 cfs/day each way (the Reclamation ramp does not apply).
  7. Past the latest data there are no Yellowstone records, so the Corps just evacuates at its rate (a note says so).

Where the numbers come from.

Checks (the lake starts in the flood pool, What happened inflow, Auto release; simulated peak vs. the real one):

Year Simulated peak Real peak Days above 3640 (sim / real)
2011 3656.4 (action) 3655.0 45 / 97
2018 3646.4 3645.3 32 / 55
2023 3650.6 3647.7 37 / 41
2015 3646.7 3647.8 25 / 51
2019 3643.2 3648.1 32 / 48
2009 3644.9 3647.9 30 / 97

Not built. Hold decisions use today's Yellowstone flow, not a forecast of it; the real Corps surely looks ahead. A user-set Yellowstone hydrograph for future years (the record is the only source now). Mid-month forecasts.

13. Estimated mid-month forecasts

Reclamation's annual reports and monthly plans have no April 15 or May 15 forecast, and I found no public source (2026-11-25). Doug's call: compute our own and mark them as estimated. Reclamation does revise its plans when the weather turns unexpectedly, which is why its plans carry minimum, median and maximum cases.

Method (addEstimates in history-manager.ts): the 1st-of-month forecast is moved by the change in basin snowpack (% of the 30-year average) between the 1st and the 15th: estimate = forecast x (1 + w x (SWE% on the 15th / SWE% on the 1st - 1)), w = 0.8 for April 15 and 0.57 for May 15, limited to +/-25% and, when Reclamation's plan has a minimum and maximum for that forecast, held within them (only WY2026 on file so far).

How good is it? Not very, and the UI says so. Tested against the actual runoff over 41-48 years (leave-one-out):

Forecast alone With the snowpack change
Apr 15 (Apr-Jul volume) 339k af mean error 333k
May 15 (May-Jul volume) 245k af 221k

In the simulator. A box under Inflow ("Use estimated mid-month forecasts", on by default) switches them on or off. They feed the forecast-based inflow, the Auto operator's weekly decisions and the forecast table, where they are italic and tagged "est.". The story line above the table ignores them.

Reclamation's minimum and maximum plans (extracted 2026-11-25). The monthly plans are public PDFs (the live page has February 2020 to January 2023; older ones are in the Wayback Machine). ops/extract-monthly-plans.py reads the January-June plans for 2012-2023 and writes data/forecast-plans.json: for each plan the minimum, median and maximum inflow volume for its forecast period, and each scenario's monthly inflow through July. The same minimum and maximum are in data/forecasts-yellowtail.json (*MinAf, *MaxAf), so the estimate is now held to Reclamation's range in those years.

Does following the plans' scenarios help? Doug's idea: see which of Reclamation's three cases the real inflow is tracking, and lean the forecast that way. I tested it on the April plans, 2012-2022 (10 years, since the monthly detail exists for them): put the inflow of April 1-14 against each scenario's April inflow, then move the forecast toward the maximum or minimum accordingly. It did worse than the forecast alone (mean error 531k af against 388k), and the snowpack nudge was about the same as the forecast (383k). Early-April inflow is too noisy to say which case the year is in. So the range is used to hold the estimate, not to steer it. A larger sample or a better signal (the real basin precipitation and snowpack reports Reclamation reads) would be needed.

14. The backward solver ("Aim for")

From Doug's Spring 2009 talk to the Friends of the Bighorn River (doug_haacke_reservoir_simulator.pdf on Reclamation's Issues Group 2009 page): that simulator had a "Sep 30 lake elevation, Lookup" box that worked out the releases to reach a target. The simulator here only ran forward, so this adds it.

What it does. In the Afterbay release box, "Aim for [ft] on [date] Solve" finds the steady river release, from the day after the chosen date, that leaves the lake at that elevation at the end of that date (SimEngine.solveSteady, bisection on the forward run, usually under 20 ms). Because it runs the real simulation, the ramp limit, canal, capacity table, Corps mode and the chosen inflow all count. It then sets "My schedule" to that release (steps between the start and the aim date are replaced, later steps kept), draws a ring on the lake chart where you asked the lake to be, and states the release and the monthly average river release. You then edit the schedule to see how the lake and the river respond.

What it can't do.

15. The monthly solver

Build order item 9. The same "Aim for [ft] on [date] Solve" button now solves month by month, with the 2009 simulator's monthly boxes under the schedule ("River release by month", one box per month from the day after the chosen date to Sep 30).

Using it. Type a release in any month box and that month is yours: it stays as you set it. Months you leave blank (and months the last solve filled, shown in italics) are solved. Press Solve and the solver finds releases for those months that put the lake at the aim on the aim date; the schedule is set to the result, so the lake and river charts show it. Typing in a box edits the schedule directly (one step on the first day of the month; blank removes the month's steps). Months after the aim date keep whatever they had.

How it solves (SimEngine.solveMonthly, a few milliseconds):

  1. Smoothest first. All solved months get the same release, found by bisection on the forward run. While solving, the Corps is switched off, so the lake responds smoothly to the releases; the answer is then re-run with the real settings.
  2. If that path would carry the lake over 3640 ft on the way (the Corps would take over and the schedule would stop mattering), it solves in two parts. First, month by month, the smallest release that still lets the lake be held under 3640, assuming the most is released in every later month (the ramp limit makes this a real constraint: the release can't be raised at once, so it has to be started in time). Then the same extra amount is added to every solved month until the aim is met. Raising every release lowers the lake all along the way, so it still stays under. That gives the "less now, more in the runoff, less after" shape a person would pick.
  3. Fishery floor. Solved months stay at or above 1,500 cfs unless the aim can't be reached that way; then it retries lower and says so.
  4. Honest about what can't be done. If even no release, or 15,000 cfs, can't reach the aim, or the aim can't be reached without passing 3640 ft on the way, it says why. In the second case it still shows the closest schedule.

Examples (April 1, 2021, April 1 forecast): aim 3625 ft on Sep 30 gives a steady 3,160 cfs, as before. Aim 3638 ft on Jul 31 (which a steady release can't do) gives Apr 1,570 · May 1,910 · Jun 6,370 · Jul 2,360. Aim 3640 ft on Jul 31 can't be met: the closest that stays under 3640 is 3639.3 ft, because monthly steps can't follow the runoff exactly. With June fixed at 5,000 cfs, aim 3630 ft on Sep 30 gives 2,650 cfs in every other month.

Limits. Monthly steps (a release can't change inside a month except by hand in the schedule list, and the solver replaces such steps in the months it solves). The release it prefers is the smoothest, not the best for fish or power: there's no objective beyond hitting the aim and staying under 3640. The ceiling is 3640 ft (or the aim, if higher); a different ceiling isn't offered. Not built: choosing which months may change by a range, or optimizing for river flow targets.

16. The ensemble ("What are the odds?")

Build order item 10. A card under the lake chart runs the chosen date's scenario against every other water year's weather and reports the range of outcomes and the odds. The plan, decisions and test results are in ensemble-plan.md (sections 12 and 13); this is what shipped.

Reclamation's operating plan (Operations Outlook)

Added 2026-11-29 at Doug's request. Each Yellowtail Monthly Plan has an OPERATIONS OUTLOOK: for the median, minimum and maximum inflow cases, monthly Boysen and Buffalo Bill releases, tributary gain, lake inflow, river release and end-of-month storage and elevation, from the plan's month to March (spring plans run further). scripts/import-operating-plans.py pulls them into data/operating-outlooks.json; /api/water-year returns the plan in effect (latest issued on or before the date, within two months, still covering a later month).