Commit c2c4d1f
Fix broken LagrangianAveraged DynamicSmagorinsky regression tests (#5506)
* Fix broken LagrangianAveraged DynamicSmagorinsky regression tests
Two bugs prevented the regression test from exercising the Lagrangian-
averaged dynamic Smagorinsky closure at all:
1. Duplicate nested `for` loop in `test_nonhydrostatic_regression.jl`
caused the inner loop to shadow the outer one, running each closure
16 times instead of 4 (with no effect on correctness, since the
inner variable always won).
2. `ocean_large_eddy_simulation_regression_test.jl` restores model
state via direct `.=` assignment rather than `set!`, so
`initialize_closure_fields!` was never called with the loaded
velocities. For LagrangianAveraging this left 𝒥ᴹᴹ = 0, which
permanently disables the closure (ϵ = 0 → 𝒥ᴹᴹ never accumulates).
Now calls `initialize_closure_fields!` after state is loaded so the
closure is properly bootstrapped from the checkpoint velocities.
Note: the LagrangianDynamicSmagorinsky regression test will correctly
fail until reference data is regenerated with the fixed code.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* comment out tests we're not testing
* better fix
* Restore previous_compute_time Ref for bit-exact LagAvg DynamicSmag regression
The regression test loader previously only restored `Field`-typed leaves
in `model.closure_fields`, skipping the `previous_compute_time::RefValue`
scalar. After `set!(model, ...)`, that Ref was left at `clock.time = 0`
(because `model.clock.time` is updated only later). At the first time
step from the loaded checkpoint, `Δt_lagrangian = clock.time - 0` was
catastrophically large, making `ϵ ≈ 1` in `_lagrangian_average_LM_MM!`
and effectively discarding the carefully-restored 𝒥 history.
Extends the closure-restoration loop to also copy `Base.RefValue` leaves,
so `previous_compute_time` is set to the value from the checkpoint. With
this, the LagrangianAveragedDynamicSmagorinsky regression test reproduces
the reference iteration to machine epsilon (~1e-15) over 10 time steps.
Also:
- Auto-detect new (`simulation/model/...`) vs legacy (root) checkpoint
paths in `get_fields_from_checkpoint`.
- Add `load_interior(data, target_size)` helper that auto-detects how
many halo layers are saved and unwraps OffsetArrays — removes the
brittle hardcoded `[2:end-1, 2:end-1, 2:end-1]` slicing.
- Return `closure_fields` (and `pNHS`, harmlessly) from
`get_fields_from_checkpoint`.
- Fix the regression-data-generation block (which had a stale
`simulation.stop_iteration = ...` referring to a `simulation` that
was never constructed) so it can be uncommented to regenerate
reference data.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* force redownload of the data if the files have changed sizes
* make it work on GPU
* uncomment temporarily commented out regions
* remove unnused function
* Make rayleigh_benard regression's get_fields_from_checkpoint destructure explicit
`get_fields_from_checkpoint` now returns 5 values (`solution, Gⁿ, G⁻,
closure_fields, pNHS`). Rayleigh-Bénard only needs the first three;
Julia's destructuring iterates and silently discards extras, so the
old `solution, Gⁿ, G⁻ = get_fields_from_checkpoint(...)` works, but
it's not self-documenting. Bind the unused values to `_` so the call
site explicitly shows that two extras are being ignored.
Addresses Copilot review comment on #5506.
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Gregory L. Wagner <wagner.greg@gmail.com>1 parent 707cf9e commit c2c4d1f
4 files changed
Lines changed: 129 additions & 57 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
50 | 64 | | |
51 | 65 | | |
52 | | - | |
53 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
54 | 71 | | |
55 | 72 | | |
56 | 73 | | |
| |||
Lines changed: 77 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
5 | 21 | | |
6 | 22 | | |
7 | 23 | | |
| |||
73 | 89 | | |
74 | 90 | | |
75 | 91 | | |
76 | | - | |
| 92 | + | |
77 | 93 | | |
78 | 94 | | |
79 | 95 | | |
| |||
93 | 109 | | |
94 | 110 | | |
95 | 111 | | |
96 | | - | |
| 112 | + | |
97 | 113 | | |
98 | 114 | | |
99 | 115 | | |
100 | 116 | | |
101 | 117 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
125 | 137 | | |
126 | 138 | | |
127 | 139 | | |
| |||
135 | 147 | | |
136 | 148 | | |
137 | 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 | + | |
138 | 184 | | |
139 | 185 | | |
140 | 186 | | |
| |||
148 | 194 | | |
149 | 195 | | |
150 | 196 | | |
151 | | - | |
| 197 | + | |
152 | 198 | | |
153 | 199 | | |
154 | 200 | | |
155 | 201 | | |
156 | 202 | | |
157 | 203 | | |
158 | 204 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
164 | 210 | | |
165 | 211 | | |
166 | 212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
| 159 | + | |
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | | - | |
15 | | - | |
16 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
19 | | - | |
| 23 | + | |
20 | 24 | | |
21 | | - | |
22 | | - | |
23 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | | - | |
| 30 | + | |
27 | 31 | | |
28 | | - | |
29 | | - | |
30 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
31 | 35 | | |
32 | 36 | | |
33 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
34 | 48 | | |
35 | 49 | | |
36 | 50 | | |
37 | 51 | | |
38 | 52 | | |
39 | 53 | | |
40 | 54 | | |
41 | | - | |
| 55 | + | |
42 | 56 | | |
43 | 57 | | |
44 | 58 | | |
| |||
70 | 84 | | |
71 | 85 | | |
72 | 86 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | 87 | | |
78 | 88 | | |
79 | 89 | | |
80 | 90 | | |
81 | | - | |
82 | | - | |
83 | | - | |
| 91 | + | |
| 92 | + | |
84 | 93 | | |
85 | 94 | | |
86 | 95 | | |
| |||
0 commit comments