refactor: extract s_write_field helper in post_process s_save_data#1600
refactor: extract s_write_field helper in post_process s_save_data#1600SVS87 wants to merge 4 commits into
Conversation
Collapse the 38 repeated fill->name->write->clear stanzas in s_save_data into calls to a new private helper s_write_field. The helper optionally slices a scalar_field into out%q_sf, writes varname to the database, and clears varname on return. Also fixes the ib_markers block which was missing the varname clear, and moves the elasticity/hyperelasticity varname clear inside the prim_vars_wrt guard where it belongs. Part of MFlowCode#1523
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1600 +/- ##
==========================================
- Coverage 60.51% 60.45% -0.07%
==========================================
Files 83 83
Lines 19905 19852 -53
Branches 2950 2951 +1
==========================================
- Hits 12046 12001 -45
+ Misses 5866 5858 -8
Partials 1993 1993 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
sbryngelson
left a comment
There was a problem hiding this comment.
Reviewed as a behavior-equivalence audit of the refactor. Traced all 38 converted stanzas against their originals:
- Every
src-passing call uses the same field, index expression, andx_beg:x_end,y_beg:y_end,z_beg:z_endslice as the original inline fill (checked the index-bearing ones:mom,vel,Y,alpha_rho_e,tau,xi,alpha,color_function, all qbmmrs/vs/ps/ms(i)). - Every no-
srccall still hasout%q_sfpopulated beforehand by a retained inline slice, ans_derive_*call, or a manual loop — none orphaned. s_write_fieldis a sibling module procedure;outresolves via use-association fromm_data_output(public module var), andname_len/scalar_field/wpfrom their respective modules. ✓- The
varname-clear relocation is inert: every DB write is preceded by a full internalwrite(varname,...), which blank-pads the whole fixed-length scalar, so the clears were always redundant.
Output-neutral, as claimed. One latent (non-blocking) note inline.
| type(scalar_field), intent(in), optional :: src | ||
| integer, intent(in), optional :: x_beg, x_end, y_beg, y_end, z_beg, z_end | ||
|
|
||
| if (present(src)) then |
There was a problem hiding this comment.
Latent interface weakness (non-blocking): the slice is guarded on present(src) only, not on the six bound args. The interface therefore permits a src-without-bounds call — e.g. call s_write_field(varname, t_step, q_cons_vf(k)) — which would dereference non-present optional integers x_beg..z_end (undefined behavior), with no compiler diagnostic. None of the current call sites do this (all pass src and the six bounds together, or omit both), so there's no live bug. Worth either tightening the guard (also assert present(x_beg)) or documenting that src and the bounds are all-or-nothing, to protect future callers.
| !! @param t_step current time step | ||
| !! @param src optional scalar_field to slice into out%q_sf | ||
| !! @param x_beg, x_end, y_beg, y_end, z_beg, z_end output region bounds (required if src present) | ||
|
|
Description
Collapse the 38 repeated fill->name->write->clear stanzas in s_save_data into calls to a new private helper s_write_field. The helper optionally slices a scalar_field into out%q_sf, writes varname to the database, and clears varname on return.
Also fixes the ib_markers block which was missing the varname clear, and moves the elasticity/hyperelasticity varname clear inside the prim_vars_wrt guard where it belongs.
Part of #1523
Type of change (delete unused ones)
Testing
Ran ./mfc.sh test -j 4 locally on Ubuntu/WSL with GNU compiler and MPI. 578 tests passed, 0 failed. Output-neutral by construction — the helper performs the exact same slice, write, and clear in the same order, so database files are bit-identical.
Checklist
Check these like this
[x]to indicate which of the below applies.See the developer guide for full coding standards.
AI code reviews
Reviews are not retriggered automatically. To request a review, comment on the PR:
@claude full review— Claude full review (also triggers on PR open/reopen/ready)claude-full-review— Claude full review via label