-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_benchmark_validation.py
More file actions
693 lines (570 loc) · 28.1 KB
/
Copy pathrun_benchmark_validation.py
File metadata and controls
693 lines (570 loc) · 28.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
"""
Quantum Hydraulics -- Benchmark Validation Suite
=================================================
Cross-validates Quantum Hydraulics against published engineering methods
across a range of conditions:
1. Manning's Cross-Check — CW velocity vs Manning's for normal depth
2. Shields Diagram — computed Shields parameters vs published values
3. Neill's Critical Velocity — transport onset comparison
4. HEC-18 Pier Scour — shear amplification vs CSU scour depth
5. Laursen Contraction Scour — constriction shear vs width ratio
These are NOT self-consistency checks. Each benchmark compares against
an INDEPENDENT published method.
Usage:
python run_benchmark_validation.py --verbose
python run_benchmark_validation.py --figures
Exit code 0 = all checks pass, 1 = failure.
"""
import sys
import os
import time
import json
import argparse
import numpy as np
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from quantum_hydraulics.core.hydraulics import HydraulicsEngine
from quantum_hydraulics.integration.swmm_2d import RHO, NU, G
from quantum_hydraulics.integration.swmm_node import SedimentProperties
class CheckResult:
def __init__(self, name, passed, detail):
self.name = name
self.passed = passed
self.detail = detail
def __str__(self):
tag = "PASS" if self.passed else "FAIL"
return f" [{tag}] {self.name}: {self.detail}"
# ══════════════════════════════════════════════════════════════════════════
# 1. MANNING'S CROSS-CHECK
# For normal-depth conditions, CW and Manning should agree within ~25%.
# We solve: given slope, width, ks, Q → find depth (CW) vs depth (Manning).
# ══════════════════════════════════════════════════════════════════════════
def checks_mannings_crosscheck(verbose=False):
results = []
if verbose:
print("\n Benchmark 1: Manning's Equation Cross-Check")
print(" " + "-" * 50)
# Test: given (width, slope, Q, ks), compute velocity at normal depth
# using both CW (our engine) and Manning's (independent).
# Use depths where both methods are self-consistent.
test_cases = [
# (width, depth, slope, ks, description)
(30, 3.0, 0.001, 0.10, "Moderate channel, sand"),
(50, 5.0, 0.002, 0.15, "Wide channel, gravel"),
(20, 4.0, 0.003, 0.20, "Steep channel, cobble"),
(80, 6.0, 0.0008, 0.10, "River, sand"),
(15, 2.5, 0.004, 0.05, "Small steep stream"),
]
errors = []
for w, d, S, ks, desc in test_cases:
A = w * d
P = w + 2 * d
R = A / P
# CW velocity: use HydraulicsEngine to get friction factor
# V_CW from normal depth equation: V = sqrt(8gRS/f)
engine = HydraulicsEngine(
Q=A * 4.0, # dummy Q, we'll use friction factor
width=w, depth=d, slope=S, roughness_ks=ks,
)
f_cw = engine.friction_factor
V_cw = np.sqrt(8.0 * G * R * S / f_cw) if f_cw > 0 else 0
# Manning's V = (1.49/n) * R^(2/3) * S^(1/2)
# Strickler: n = (ks_m)^(1/6) / 21.1, ks_m = ks * 0.3048
ks_m = ks * 0.3048
n = ks_m ** (1.0 / 6.0) / 21.1
V_manning = (1.49 / n) * R ** (2.0 / 3.0) * S ** 0.5
rel_err = abs(V_cw - V_manning) / V_manning if V_manning > 0 else 0
errors.append(rel_err)
if verbose:
print(f" {desc:30s} V_CW={V_cw:.2f} V_Manning={V_manning:.2f} "
f"f={f_cw:.5f} n={n:.4f} err={rel_err:.1%}")
avg_err = np.mean(errors)
max_err = np.max(errors)
results.append(CheckResult(
"Average CW-Manning error < 30%",
avg_err < 0.30,
f"avg={avg_err:.1%} across {len(test_cases)} cases",
))
results.append(CheckResult(
"Max CW-Manning error < 40%",
max_err < 0.40,
f"max={max_err:.1%}",
))
return results, {"errors": errors, "avg": avg_err}
# ══════════════════════════════════════════════════════════════════════════
# 2. SHIELDS DIAGRAM VALIDATION
# Check that Shields parameter at critical shear follows published trends.
# Our tau_c values are empirical (USACE permissible), not pure Shields.
# They should still follow the correct ORDERING.
# ══════════════════════════════════════════════════════════════════════════
def checks_shields_diagram(verbose=False):
results = []
if verbose:
print("\n Benchmark 2: Shields Diagram Validation")
print(" " + "-" * 50)
sediment_types = [
SedimentProperties.fine_sand(),
SedimentProperties.sand(),
SedimentProperties.coarse_sand(),
SedimentProperties.gravel(),
]
thetas = []
for sed in sediment_types:
d_ft = sed.d50_mm / 304.8
theta = sed.critical_shear_psf / ((sed.density_slugs_ft3 - RHO) * G * d_ft)
thetas.append(theta)
u_star_c = np.sqrt(sed.critical_shear_psf / RHO)
Re_star = u_star_c * d_ft / NU
if verbose:
print(f" {sed.name:15s} d50={sed.d50_mm:.2f}mm tau_c={sed.critical_shear_psf:.3f}psf "
f"theta_c={theta:.4f} Re*={Re_star:.0f}")
# Gravel (largest Re*) should have theta closest to 0.047
results.append(CheckResult(
"Gravel theta_c closest to Shields 0.047",
0.03 < thetas[3] < 0.15,
f"theta_c={thetas[3]:.4f}",
))
# The Shields curve is NON-monotonic in grain size: theta_c has a minimum
# near D* ~ 10 (medium/coarse sand), rising in the viscous range (finer)
# and rising again toward the fully-rough plateau (~0.05-0.06) for gravel.
# (The previous check asserted a monotonic decrease -- that only holds up to
# the minimum and is wrong across the sand-to-gravel span. The Soulsby &
# Whitehouse 1997 fit now used for tau_c captures the correct U-shape.)
theta_min = min(thetas)
results.append(CheckResult(
"Shields curve is U-shaped with minimum in the sand range",
thetas[0] > theta_min and thetas[3] > theta_min
and thetas[3] == max(thetas),
f"fine={thetas[0]:.3f}, sand={thetas[1]:.3f}, coarse={thetas[2]:.3f}, "
f"gravel={thetas[3]:.3f} (min={theta_min:.3f})",
))
# Critical shear should increase with grain size (tau_c_gravel > tau_c_sand)
tau_cs = [s.critical_shear_psf for s in sediment_types]
results.append(CheckResult(
"Critical shear increases with grain size",
all(tau_cs[i] < tau_cs[i + 1] for i in range(len(tau_cs) - 1)),
f"tau_c={[f'{t:.3f}' for t in tau_cs]}",
))
return results, {"thetas": thetas}
# ══════════════════════════════════════════════════════════════════════════
# 3. NEILL'S CRITICAL VELOCITY vs QH TRANSPORT ONSET
# Neill: V_c = 6.19 * y^(1/6) * d50_ft^(1/3)
# QH: V_c where tau = tau_c → V_c = sqrt(8*tau_c/(rho*f))
# These use different tau_c bases so won't match exactly, but should
# be in the same order of magnitude and show correct trends.
# ══════════════════════════════════════════════════════════════════════════
def checks_neills_velocity(verbose=False):
results = []
if verbose:
print("\n Benchmark 3: Neill's Critical Velocity")
print(" " + "-" * 50)
test_cases = [
(SedimentProperties.sand(), 4.0),
(SedimentProperties.coarse_sand(), 4.0),
(SedimentProperties.gravel(), 4.0),
]
neills = []
qhs = []
for sed, depth in test_cases:
d50_ft = sed.d50_mm / 304.8
# Neill's critical velocity
V_neill = 6.19 * depth ** (1.0 / 6.0) * d50_ft ** (1.0 / 3.0)
# QH: V where tau = tau_c
# At typical conditions, estimate f ≈ 0.02
f_est = 0.025
V_qh = np.sqrt(8.0 * sed.critical_shear_psf / (RHO * f_est))
neills.append(V_neill)
qhs.append(V_qh)
if verbose:
print(f" {sed.name:15s} V_Neill={V_neill:.2f} V_QH={V_qh:.2f} fps")
# Both should increase with grain size
results.append(CheckResult(
"Neill V_c increases with grain size",
neills[0] < neills[1] < neills[2],
f"sand={neills[0]:.2f} < coarse={neills[1]:.2f} < gravel={neills[2]:.2f}",
))
results.append(CheckResult(
"QH V_c increases with grain size",
qhs[0] < qhs[1] < qhs[2],
f"sand={qhs[0]:.2f} < coarse={qhs[1]:.2f} < gravel={qhs[2]:.2f}",
))
# Both should be positive and physically reasonable (0.5-15 fps)
results.append(CheckResult(
"All critical velocities in reasonable range (0.5-15 fps)",
all(0.5 < v < 15 for v in neills + qhs),
f"Neill: {[f'{v:.2f}' for v in neills]}, QH: {[f'{v:.2f}' for v in qhs]}",
))
return results, {"neills": neills, "qhs": qhs}
# ══════════════════════════════════════════════════════════════════════════
# 4. HEC-18 PIER SCOUR COMPARISON
# CSU: ys/a = 2.0 K1 K2 K3 (y1/a)^0.35 Fr^0.43
# QH: compute shear amplification from constriction hydraulics.
# Both should agree on TREND and CORRELATION, not exact values.
# ══════════════════════════════════════════════════════════════════════════
def checks_hec18_pier_scour(verbose=False):
results = []
if verbose:
print("\n Benchmark 4: HEC-18 Pier Scour (CSU Equation)")
print(" " + "-" * 50)
K1, K2, K3 = 1.0, 1.0, 1.1 # circular, 0-deg, plane bed
test_cases = [
(3.0, 4.0, 2.0, "Small pier, low V"),
(4.0, 4.0, 3.0, "Medium pier, moderate V"),
(6.0, 5.0, 4.0, "Large pier, high V"),
(8.0, 6.0, 5.0, "Large pier, flood V"),
(3.0, 3.0, 6.0, "Wide pier, shallow"),
]
W = 40.0
hec18_depths = []
qh_amps = []
for V, y1, a, desc in test_cases:
Fr = V / np.sqrt(G * y1)
Q = V * W * y1
# HEC-18
ys = 2.0 * K1 * K2 * K3 * a * (y1 / a) ** 0.35 * Fr ** 0.43
ys = min(ys, 2.4 * a)
hec18_depths.append(ys)
# QH: shear amplification from constriction
e_approach = HydraulicsEngine(Q=Q, width=W, depth=y1, slope=0.002, roughness_ks=0.1)
e_pier = HydraulicsEngine(Q=Q, width=W - a, depth=y1, slope=0.002, roughness_ks=0.1)
tau_app = RHO * e_approach.u_star ** 2
tau_pier = RHO * e_pier.u_star ** 2
amp = tau_pier / tau_app if tau_app > 0 else 1.0
qh_amps.append(amp)
if verbose:
print(f" {desc:25s} HEC18={ys:.2f}ft QH_amp={amp:.3f}x Fr={Fr:.3f}")
# Correlation between HEC-18 depth and QH amplification
corr = np.corrcoef(hec18_depths, qh_amps)[0, 1]
results.append(CheckResult(
"QH amplification correlates with HEC-18 (r > 0.5)",
corr > 0.5,
f"Pearson r={corr:.3f}",
))
# QH detects all significant scour cases
for i, (V, y1, a, desc) in enumerate(test_cases):
if hec18_depths[i] > 1.0:
results.append(CheckResult(
f"QH detects scour: {desc}",
qh_amps[i] > 1.01,
f"HEC18={hec18_depths[i]:.2f}ft, QH={qh_amps[i]:.3f}x",
))
# QH amplification increases with pier size (first 4 cases)
results.append(CheckResult(
"QH amplification increases with severity",
qh_amps[1] < qh_amps[2] < qh_amps[3],
f"amps={[f'{a:.3f}' for a in qh_amps[:4]]}",
))
return results, {"hec18": hec18_depths, "qh_amps": qh_amps,
"cases": [c[3] for c in test_cases]}
# ══════════════════════════════════════════════════════════════════════════
# 5. LAURSEN CONTRACTION SCOUR
# Shear amplification at constrictions vs width ratio.
# ══════════════════════════════════════════════════════════════════════════
def checks_laursen_contraction(verbose=False):
results = []
if verbose:
print("\n Benchmark 5: Laursen Contraction Scour")
print(" " + "-" * 50)
W1 = 60.0
y1 = 4.0
V1 = 4.0
Q = V1 * W1 * y1
ratios = [0.9, 0.8, 0.7, 0.6, 0.5]
e_up = HydraulicsEngine(Q=Q, width=W1, depth=y1, slope=0.002, roughness_ks=0.1)
tau_up = RHO * e_up.u_star ** 2
amps = []
laursen_scours = []
for r in ratios:
W2 = W1 * r
e_dn = HydraulicsEngine(Q=Q, width=W2, depth=y1, slope=0.002, roughness_ks=0.1)
tau_dn = RHO * e_dn.u_star ** 2
amp = tau_dn / tau_up
amps.append(amp)
# Laursen: y2/y1 = (W1/W2)^(6/7)
y2 = y1 * (W1 / W2) ** (6.0 / 7.0)
laursen_scours.append(y2 - y1)
if verbose:
print(f" W2/W1={r:.1f} Laursen={y2 - y1:.2f}ft QH_amp={amp:.3f}x")
# Amplification increases monotonically
results.append(CheckResult(
"Shear amplification increases with contraction",
all(amps[i] <= amps[i + 1] for i in range(len(amps) - 1)),
f"amps={[f'{a:.3f}' for a in amps]}",
))
# 50% contraction: substantial amplification
results.append(CheckResult(
"50% contraction > 2x shear amplification",
amps[-1] > 2.0,
f"amp={amps[-1]:.3f}x",
))
# Correlation: QH amplification vs Laursen scour depth
corr = np.corrcoef(laursen_scours, amps)[0, 1]
results.append(CheckResult(
"QH amp correlates with Laursen scour (r > 0.9)",
corr > 0.9,
f"Pearson r={corr:.3f}",
))
return results, {"ratios": ratios, "amps": amps, "laursen": laursen_scours}
# ══════════════════════════════════════════════════════════════════════════
# 6. MELVILLE FLUME DATA — Measured pier scour vs QH vs HEC-18
# Published experimental data from Melville (1984), Ettema (1980),
# Chiew (1984) as compiled in Melville & Coleman (2000).
# This is the ONLY benchmark against actual measured scour depths.
# ══════════════════════════════════════════════════════════════════════════
def checks_melville_design_curve(verbose=False):
"""
Benchmark 6: Melville Design Method Comparison.
Uses the published DIMENSIONLESS Melville (1997) design equation:
ds/b = 2.4 * K_I (deep water, y/b > 2.6)
K_I = V/Vc for V/Vc <= 1 (clear-water)
K_I = 1.0 at threshold (V/Vc = 1)
This is NOT a comparison against measured data points (which would
require exact test IDs and conditions from the original papers).
It compares QH's turbulence-augmented shear against the Melville
design curve's flow-intensity factor K_I across a range of V/Vc.
The purpose is to show that QH's amplification factor tracks the
same trends as Melville's empirically-derived K_I, providing
evidence that the physics captures the right sensitivity.
"""
results = []
if verbose:
print("\n Benchmark 6: Melville Design Curve (Dimensionless)")
print(" " + "-" * 50)
# Melville (1997) design equation for deep water (y/b > 2.6):
# ds_max = 2.4 * b * K_I
# K_I = V/Vc for clear-water (V/Vc <= 1)
# K_I peaks near 1.0 at threshold, dips slightly for live-bed
# Test across V/Vc from 0.3 to 1.5
# Use: b=3 ft, y=10 ft (y/b=3.33 > 2.6), d50=0.5 mm sand
b = 3.0
y = 10.0
W = 40.0
d50_ft = 0.5 / 304.8
# Neill critical velocity for sand at y=10
Vc = 6.19 * y ** (1.0 / 6.0) * d50_ft ** (1.0 / 3.0)
V_over_Vc_values = [0.3, 0.5, 0.7, 0.9, 1.0, 1.2, 1.5]
melville_KI = []
qh_amps = []
for ratio in V_over_Vc_values:
V = ratio * Vc
Q = V * W * y
Fr = V / np.sqrt(G * y)
# Melville K_I
if ratio <= 1.0:
KI = ratio # clear-water: linear increase
else:
KI = 1.0 # live-bed: peaks at threshold (simplified)
melville_KI.append(KI)
# Melville dimensionless scour: ds/b = 2.4 * KI
ds_melville = 2.4 * b * KI
# QH shear amplification
e_app = HydraulicsEngine(Q=Q, width=W, depth=y, slope=0.002, roughness_ks=0.1)
e_pier = HydraulicsEngine(Q=Q, width=W - b, depth=y, slope=0.002, roughness_ks=0.1)
tau_app = RHO * e_app.u_star ** 2
tau_pier = RHO * e_pier.u_star ** 2
amp = tau_pier / tau_app if tau_app > 0 else 1.0
qh_amps.append(amp)
if verbose:
print(f" V/Vc={ratio:.1f} V={V:.2f}fps Melville_KI={KI:.2f} "
f"ds_Melv={ds_melville:.2f}ft QH_amp={amp:.3f}x")
# Checks
# 1. QH amplification is constant across V/Vc (constriction effect is V-independent)
# This is expected: QH measures GEOMETRIC constriction, Melville measures FLOW INTENSITY
# They capture different physics — QH should be additive, not replacing K_I
amp_std = np.std(qh_amps)
results.append(CheckResult(
"QH amplification is consistent across V/Vc",
amp_std < 0.01,
f"amp_range=[{min(qh_amps):.4f}, {max(qh_amps):.4f}], std={amp_std:.4f}",
))
# 2. QH amplification > 1.0 (constriction detected)
results.append(CheckResult(
"QH detects pier constriction (amp > 1.0)",
all(a > 1.0 for a in qh_amps),
f"min_amp={min(qh_amps):.4f}",
))
# 3. Melville K_I increases with V/Vc in clear-water range
cw_KI = [melville_KI[i] for i in range(5)] # V/Vc <= 1.0
results.append(CheckResult(
"Melville K_I increases in clear-water (V/Vc <= 1)",
all(cw_KI[i] <= cw_KI[i + 1] for i in range(len(cw_KI) - 1)),
f"K_I={[f'{k:.2f}' for k in cw_KI]}",
))
# 4. Combined QH*Melville scour estimate increases with V/Vc
combined = [2.4 * b * melville_KI[i] * qh_amps[i] for i in range(5)]
results.append(CheckResult(
"Combined (Melville*QH) scour increases with V/Vc",
all(combined[i] <= combined[i + 1] + 0.01 for i in range(len(combined) - 1)),
f"combined_ds={[f'{c:.2f}' for c in combined]}",
))
return results, {
"v_over_vc": V_over_Vc_values,
"melville_KI": melville_KI,
"qh_amps": qh_amps,
"b": b,
}
# ══════════════════════════════════════════════════════════════════════════
# FIGURES
# ══════════════════════════════════════════════════════════════════════════
def generate_figures(exp_results, output_dir="Benchmark_figures"):
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from quantum_hydraulics.visualization.theme import THEMES
theme = THEMES["light_publication"]
os.makedirs(output_dir, exist_ok=True)
dpi = 300
if "hec18" in exp_results:
r = exp_results["hec18"]
fig, ax = plt.subplots(figsize=(6, 5))
fig.patch.set_facecolor(theme.background)
ax.set_facecolor(theme.background)
ax.scatter(r["hec18"], r["qh_amps"], s=80,
color=theme.accent_primary, edgecolors="black", zorder=5)
for i, c in enumerate(r["cases"]):
ax.annotate(c, (r["hec18"][i], r["qh_amps"][i]),
fontsize=7, ha="left", va="bottom",
xytext=(5, 3), textcoords="offset points")
ax.set_xlabel("HEC-18 Scour Depth (ft)", color=theme.foreground)
ax.set_ylabel("QH Shear Amplification", color=theme.foreground)
ax.set_title("HEC-18 vs Quantum Hydraulics: Pier Scour Correlation",
color=theme.foreground, fontsize=11, weight="bold")
ax.tick_params(colors=theme.foreground)
ax.grid(True, color=theme.grid_color, alpha=theme.grid_alpha)
fig.tight_layout()
path = os.path.join(output_dir, "fig1_hec18_correlation.png")
fig.savefig(path, dpi=dpi, bbox_inches="tight", facecolor=theme.background)
plt.close(fig)
print(f" Saved {path}")
if "contraction" in exp_results:
r = exp_results["contraction"]
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4.5))
fig.patch.set_facecolor(theme.background)
# Left: QH amplification
ax1.set_facecolor(theme.background)
ax1.plot(r["ratios"], r["amps"], "o-", color=theme.accent_primary,
linewidth=2, markersize=8, label="QH shear amp")
theoretical = [(1.0 / ratio) ** 2 for ratio in r["ratios"]]
ax1.plot(r["ratios"], theoretical, "--", color="gray",
linewidth=1.5, label="V$^2$ scaling")
ax1.set_xlabel("W2/W1", color=theme.foreground)
ax1.set_ylabel("Shear Amplification", color=theme.foreground)
ax1.set_title("QH vs V$^2$ Theory", color=theme.foreground, fontsize=10, weight="bold")
ax1.legend(fontsize=8)
ax1.tick_params(colors=theme.foreground)
ax1.grid(True, color=theme.grid_color, alpha=theme.grid_alpha)
ax1.invert_xaxis()
# Right: Laursen scour vs QH amplification
ax2.set_facecolor(theme.background)
ax2.scatter(r["laursen"], r["amps"], s=80,
color=theme.accent_secondary, edgecolors="black")
ax2.set_xlabel("Laursen Scour Depth (ft)", color=theme.foreground)
ax2.set_ylabel("QH Shear Amplification", color=theme.foreground)
ax2.set_title("QH vs Laursen", color=theme.foreground, fontsize=10, weight="bold")
ax2.tick_params(colors=theme.foreground)
ax2.grid(True, color=theme.grid_color, alpha=theme.grid_alpha)
fig.suptitle("Contraction Scour: Cross-Validation",
color=theme.foreground, fontsize=11, weight="bold")
fig.tight_layout()
path = os.path.join(output_dir, "fig2_contraction_validation.png")
fig.savefig(path, dpi=dpi, bbox_inches="tight", facecolor=theme.background)
plt.close(fig)
print(f" Saved {path}")
# Fig 3: Melville design curve — K_I and QH amplification vs V/Vc
if "melville" in exp_results:
r = exp_results["melville"]
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4.5))
fig.patch.set_facecolor(theme.background)
vvc = r["v_over_vc"]
# Left: Melville K_I design curve
ax1.set_facecolor(theme.background)
ax1.plot(vvc, r["melville_KI"], "o-", color=theme.accent_primary,
linewidth=2, markersize=8, label="Melville K$_I$")
ax1.set_xlabel("V / V$_c$", color=theme.foreground)
ax1.set_ylabel("K$_I$ (Flow Intensity Factor)", color=theme.foreground)
ax1.set_title("Melville (1997) Design Curve",
color=theme.foreground, fontsize=10, weight="bold")
ax1.axvline(x=1.0, color="gray", linestyle=":", label="Threshold")
ax1.legend(fontsize=8)
ax1.tick_params(colors=theme.foreground)
ax1.grid(True, color=theme.grid_color, alpha=theme.grid_alpha)
# Right: Combined ds = 2.4*b * K_I * QH_amp
b = r["b"]
ds_melville = [2.4 * b * ki for ki in r["melville_KI"]]
ds_combined = [2.4 * b * ki * amp for ki, amp in zip(r["melville_KI"], r["qh_amps"])]
ax2.set_facecolor(theme.background)
ax2.plot(vvc, ds_melville, "o-", color=theme.accent_primary,
linewidth=2, markersize=8, label="Melville only")
ax2.plot(vvc, ds_combined, "D-", color=theme.accent_secondary,
linewidth=2, markersize=8, label="Melville + QH turbulence")
ax2.set_xlabel("V / V$_c$", color=theme.foreground)
ax2.set_ylabel("Predicted Scour Depth (ft)", color=theme.foreground)
ax2.set_title(f"Scour Depth: Melville vs Melville+QH (b={b:.0f} ft)",
color=theme.foreground, fontsize=10, weight="bold")
ax2.axvline(x=1.0, color="gray", linestyle=":")
ax2.legend(fontsize=8)
ax2.tick_params(colors=theme.foreground)
ax2.grid(True, color=theme.grid_color, alpha=theme.grid_alpha)
fig.tight_layout()
path = os.path.join(output_dir, "fig3_melville_design_curve.png")
fig.savefig(path, dpi=dpi, bbox_inches="tight", facecolor=theme.background)
plt.close(fig)
print(f" Saved {path}")
print(f"\n All figures saved to {output_dir}/")
# ══════════════════════════════════════════════════════════════════════════
# MAIN
# ══════════════════════════════════════════════════════════════════════════
def main():
parser = argparse.ArgumentParser(description="Benchmark Validation Suite")
parser.add_argument("--verbose", "-v", action="store_true")
parser.add_argument("--figures", "-f", action="store_true")
parser.add_argument("--json", action="store_true")
args = parser.parse_args()
print("=" * 72)
print(" QUANTUM HYDRAULICS -- Benchmark Validation Suite")
print(" Cross-validation against published engineering methods")
print("=" * 72)
benchmarks = {
1: ("Manning's Cross-Check", checks_mannings_crosscheck),
2: ("Shields Diagram", checks_shields_diagram),
3: ("Neill's Critical Velocity", checks_neills_velocity),
4: ("HEC-18 Pier Scour", checks_hec18_pier_scour),
5: ("Laursen Contraction Scour", checks_laursen_contraction),
6: ("Melville Design Curve", checks_melville_design_curve),
}
all_checks = []
exp_results = {}
t_total = time.perf_counter()
for num, (name, func) in benchmarks.items():
t0 = time.perf_counter()
checks, raw = func(verbose=args.verbose)
elapsed = time.perf_counter() - t0
all_checks.extend(checks)
if raw:
exp_results[{4: "hec18", 5: "contraction", 6: "melville"}.get(num, str(num))] = raw
if not args.json:
print(f"\n [{num}] {name} ({elapsed:.2f}s)")
for c in checks:
print(c)
total_time = time.perf_counter() - t_total
passed = sum(1 for c in all_checks if c.passed)
total = len(all_checks)
print("\n" + "-" * 72)
if passed == total:
print(f" {passed}/{total} checks passed -- ALL PASS ({total_time:.2f}s)")
else:
failed = [c for c in all_checks if not c.passed]
print(f" {passed}/{total} checks passed -- {total - passed} FAILED")
for c in failed:
print(f" FAIL: {c.name}: {c.detail}")
print("=" * 72)
if args.json:
out = {"passed": passed, "total": total, "all_pass": passed == total,
"checks": [{"name": c.name, "passed": c.passed, "detail": c.detail}
for c in all_checks]}
print(json.dumps(out, indent=2))
if args.figures:
print("\n Generating benchmark figures...")
generate_figures(exp_results)
sys.exit(0 if passed == total else 1)
if __name__ == "__main__":
main()