Append to probe and CoM files only when continuing a run - #1867
Append to probe and CoM files only when continuing a run#1867sbryngelson wants to merge 2 commits into
Conversation
s_open_probe_files appends whenever D/probe*_prim.dat already exists. That is right when a run is being continued and wrong when one is being started over, which is what happens every time a case is re-run in place after a parameter change. The second run's rows land on top of the first's, nothing in the file marks the join, and the time column resets partway down. A reader sees one monotonic series and is silently wrong. The two runs need not even share a grid. Append only when t_step_start > 0, or n_start > 0 under cfl_dt. A fresh start replaces the file, which is what every other output MFC writes already does. s_open_com_files had the same pattern and gets the same treatment. examples/2D_probe_rerun runs 20 steps twice in the same directory. Before, the probe file holds 40 rows and its time column runs 0.032386 then 0.000000; after, 20 rows. This produced three separate wrong numbers in one project before it was caught. The worst was a jet whose probe files held a t = 15 run of 4,962 rows followed by a t = 40 run of 13,233, on different grids; read together they manufactured a velocity drop of 0.99 U_j in a single sample, which was time running backwards at the seam and was diagnosed as a physical instability first.
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Fixes probe and center-of-mass (CoM) output files being unintentionally appended when re-running a case “from scratch” in the same directory, which can silently splice multiple runs into one misleading time series.
Changes:
- Determine whether a run is a “fresh start” vs “continuation” and only append for continuations.
- Replace (truncate) existing probe/CoM files on fresh starts to avoid splicing data across separate runs.
- Add a reproducible example (
examples/2D_probe_rerun/) documenting the bug and validation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/simulation/m_data_output.fpp | Add fresh_start gating so probe/CoM files are replaced on fresh runs and appended only on continuations. |
| examples/2D_probe_rerun/case.py | New example case to reproduce the probe append/splice issue by running twice in-place. |
| examples/2D_probe_rerun/README.md | Documentation demonstrating the incorrect behavior before and correct behavior after the fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| integer :: i !< Generic loop iterator | ||
| logical :: fresh_start | ||
|
|
||
| fresh_start = (t_step_start == 0) .or. (cfl_dt .and. n_start == 0) |
| logical :: fresh_start | ||
|
|
||
| fresh_start = (t_step_start == 0) .or. (cfl_dt .and. n_start == 0) |
|
|
||
| MFC appends to D/probe*_prim.dat when the file already exists. That is right when a run is being continued | ||
| and wrong when one is being started over: the second run's rows land on top of the first's, nothing in the | ||
| file marks the join, and the time column simply resets partway down. A reader sees one monotonic series. |
Lines of Code
|
|
Claude Code Review Head SHA: de78f37 Files changed:
Findings:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1867 +/- ##
==========================================
- Coverage 61.26% 61.23% -0.03%
==========================================
Files 84 84
Lines 22330 22340 +10
Branches 3265 3267 +2
==========================================
+ Hits 13680 13681 +1
- Misses 6207 6215 +8
- Partials 2443 2444 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Written with Claude Code.
The bug
s_open_probe_filesappends wheneverD/probe*_prim.datalready exists:Correct when a run is being continued. Wrong when one is being started over — which is what happens every time a case is re-run in place after a parameter change. The second run's rows land on top of the first's, nothing in the file marks the join, and the time column simply resets partway down. A reader sees one monotonic series and is silently wrong.
The two runs need not even share a grid: a case whose resolution changed between runs produces a file whose first half was recorded at different probe locations.
s_open_com_fileshas the same pattern.The fix
Append only when continuing:
t_step_start > 0, orn_start > 0undercfl_dt— the same testm_start_upalready uses to decide whether a run is fresh. A fresh start replaces the file, which is what every other output MFC writes already does.How the validation is obtained
examples/2D_probe_rerun/— a 64×64 case with two probes, 20 steps. Run it twice in the same directory:D/probe1_prim.datThe time column read straight through, before:
Measured with the same binary either side of the change; both runs complete, no failures. The README carries the table and the reasoning.
Why it is worth fixing rather than documenting
This produced three separate wrong numbers in one project before it was noticed. The worst: a jet whose probe files held a t = 15 run of 4,962 rows followed by a t = 40 run of 13,233 — on different grids. Read together they manufactured a velocity drop of 0.99 U_j in a single sample, which was time running backwards at the seam, and which was diagnosed as a physical instability first.
A related symptom is louder: if the probe output format changes between runs, the column count changes partway down and
numpy.loadtxtrefuses the file outright ("the number of columns changed from 11 to 18"). That one announces itself. The time reset does not.Scope
Only affects re-running a case in a directory that already holds probe or CoM output. Restarts are unchanged — they still append, which is the behaviour they need. No golden file moves; the test suite runs each case in a fresh directory.