Skip to content

Derive lift ratios analytically; fix unfair 2-speed comparison#5

Open
featurescript wants to merge 1 commit into
mainfrom
routine/derive-ratios
Open

Derive lift ratios analytically; fix unfair 2-speed comparison#5
featurescript wants to merge 1 commit into
mainfrom
routine/derive-ratios

Conversation

@featurescript

Copy link
Copy Markdown
Contributor

Follow-up to #4. Addresses two reviewer questions: (1) why the algorithms need a G_min/G_max search range, and (2) whether the 2-speed should beat a single gear in the ideal case.

Ratios are now derived, not grid-searched

  • CVT → closed-form per-step optimum G* = (V_oc − I_free·R)·r_eff / (2·Ke·v), clamped to [G_min, G_max]. Verified identical to a 4000-pt brute-force scan (diff 0). Removes the cvt_grid knob.
  • Single gear → golden-section on the convex time(G) curve; the infeasible (can't-lift) region returns a G-decreasing penalty so the search climbs to the feasible side. Removes opt_pts.
  • 2-speed → fair fine pair search whose candidate set always includes the single optimum, so the degenerate pair [G_opt, G_opt] is available. Removes shift_grid.

Why G_min / G_max stay (the answer to "can they be removed?")

They're physical hardware limits, not search bounds. The CVT's mathematically-optimal ratio → ∞ as v → 0 (infinite reduction = infinite stall force), so it must clamp to the largest buildable reduction. Drop G_max and the sim pretends any load is liftable — the UNREACHABLE feasibility finding evaporates. Relabeled in the UI as hardware limits; only the search-resolution knobs (the real artifacts) were removed.

The 2-speed was being judged unfairly

Old code optimized the 2-speed pair on a coarse 8-pt grid while single used 40 pts — so it looked −2.2%, an artifact. An ideal 2-speed is a superset of single-gear policies, so it can't be slower. With the fair search:

t_shift 2-speed Δ vs single shifts
0 (ideal) +4.05% 1
0.05 +0.00% 0
0.10 (default) +0.00% 0

Ideal 2-speed strictly beats single (marginally); any realistic shift dead-time exceeds the one-shift gain, so the optimizer declines to shift and ties single — no more spurious negative. New t_shift sweep variable charts this directly (CVT flat ~+6%, 2-speed +4%→0 by 0.05s). Acceptance test 5 upgraded to assert the full CVT ≤ 2-speed ≤ Single ordering at t_shift=0.

Validation

  • All 9 self-tests pass (incl. new ordering test); closed-form CVT ≡ brute force; energy residual 0.12%; heavy 22 kg single still UNREACHABLE.
  • Default compare + mass-sweep times unchanged at run dt; CVT closed-form matches the CSV (0.378s @ m=1).
  • Drivetrain tab untouched, no console errors.

🤖 Generated with Claude Code

Replaces the grid searches with derived optima and corrects the 2-speed
handicap that made it look worse than a single gear.

Ratios (no more search-resolution knobs):
- CVT: closed-form per-step optimum G* = (V_oc - I_free*R)*r_eff/(2*Ke*v),
  clamped to the physical [G_min,G_max]. Verified identical to a 4000-pt
  brute-force scan (diff 0). Drops cvt_grid.
- Single gear: golden-section on the convex time(G); infeasible region uses
  a G-decreasing penalty so the search climbs to the feasible side. Drops
  opt_pts.
- 2-speed: fair fine pair search whose candidate set always includes the
  single optimum, so the degenerate pair [G_opt,G_opt] is available. This
  guarantees single <= 2-speed <= CVT (a 2-speed is a superset of single-gear
  policies). Drops shift_grid.

Why G_min/G_max stay: they are physical hardware limits, not search bounds.
The CVT's mathematically-optimal ratio -> infinity as v->0, so it MUST clamp
to the largest buildable reduction; without G_max the sim would pretend any
load is liftable and the UNREACHABLE finding disappears. Relabeled in the UI
as hardware limits.

2-speed result, now honest:
- ideal (t_shift=0): shifts once, ~+4% at default mass (strictly beats single)
- realistic (t_shift>=0.05): marginal one-shift gain < clutch dead-time, so
  the optimizer declines to shift and ties single (no more spurious -2.2%)

Adds a t_shift sweep variable to chart the 2-speed benefit vs shift dead-time
(CVT flat ~+6%, 2-speed +4% at 0 -> 0% by 0.05s). Acceptance test 5 upgraded
to assert the full CVT <= 2-speed <= Single ordering at t_shift=0.

All 9 self-tests pass; default compare and mass-sweep times unchanged at run
dt; closed-form CVT == brute force; drivetrain tab untouched.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant