Skip to content

refactor: extract s_write_field helper in post_process s_save_data#1600

Merged
sbryngelson merged 8 commits into
MFlowCode:masterfrom
SVS87:refactor/write-field-helper
Jun 25, 2026
Merged

refactor: extract s_write_field helper in post_process s_save_data#1600
sbryngelson merged 8 commits into
MFlowCode:masterfrom
SVS87:refactor/write-field-helper

Conversation

@SVS87

@SVS87 SVS87 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

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)

  • Bug fix
  • Refactor

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.

  • I added or updated tests for new behavior
  • I updated documentation if user-facing behavior changed

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)
  • Or add label claude-full-review — Claude full review via label

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
@SVS87 SVS87 requested a review from sbryngelson as a code owner June 15, 2026 08:02
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.42%. Comparing base (05eda2d) to head (78508fe).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/post_process/m_start_up.fpp 88.88% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1600      +/-   ##
==========================================
- Coverage   60.48%   60.42%   -0.07%     
==========================================
  Files          83       83              
  Lines       19888    19835      -53     
  Branches     2951     2952       +1     
==========================================
- Hits        12030    11985      -45     
+ Misses       5864     5856       -8     
  Partials     1994     1994              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sbryngelson sbryngelson marked this pull request as draft June 15, 2026 12:44
@SVS87 SVS87 marked this pull request as ready for review June 19, 2026 06:50
@sbryngelson sbryngelson marked this pull request as draft June 20, 2026 05:59
@SVS87 SVS87 marked this pull request as ready for review June 21, 2026 05:34
@sbryngelson sbryngelson marked this pull request as draft June 22, 2026 15:27

@sbryngelson sbryngelson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and x_beg:x_end,y_beg:y_end,z_beg:z_end slice as the original inline fill (checked the index-bearing ones: mom, vel, Y, alpha_rho_e, tau, xi, alpha, color_function, all qbmm rs/vs/ps/ms(i)).
  • Every no-src call still has out%q_sf populated beforehand by a retained inline slice, an s_derive_* call, or a manual loop — none orphaned.
  • s_write_field is a sibling module procedure; out resolves via use-association from m_data_output (public module var), and name_len/scalar_field/wp from their respective modules. ✓
  • The varname-clear relocation is inert: every DB write is preceded by a full internal write(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.

Comment thread src/post_process/m_start_up.fpp
Comment thread src/post_process/m_start_up.fpp Outdated
@sbryngelson sbryngelson marked this pull request as ready for review June 24, 2026 18:24
Copilot AI review requested due to automatic review settings June 24, 2026 18:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.

Refactors s_save_data in post-process startup to reduce duplicated “slice → write → clear” sequences by introducing a helper routine, while also fixing a missing varname clear in the ib_markers output path and tightening variable clearing for elasticity/hyperelasticity.

Changes:

  • Extract repeated output logic into a new helper subroutine s_write_field.
  • Replace many manual out%q_sf slice + write + varname clear stanzas with calls to s_write_field.
  • Fix ib_markers to clear varname consistently and adjust clearing placement for elasticity/hyperelasticity to be inside prim_vars_wrt guards.

Comment on lines +664 to +675
impure subroutine s_write_field(varname, t_step, src, x_beg, x_end, y_beg, y_end, z_beg, z_end)

character(LEN=name_len), intent(inout) :: varname
integer, intent(in) :: t_step
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
@:ASSERT(present(x_beg) .and. present(x_end) .and. present(y_beg) .and. present(y_end) .and. present(z_beg) &
& .and. present(z_end), "s_write_field: src requires all six output bounds")
out%q_sf(:,:,:) = src%sf(x_beg:x_end,y_beg:y_end,z_beg:z_end)
end if
Comment on lines +672 to +673
@:ASSERT(present(x_beg) .and. present(x_end) .and. present(y_beg) .and. present(y_end) .and. present(z_beg) &
& .and. present(z_end), "s_write_field: src requires all six output bounds")
@github-actions

Copy link
Copy Markdown

Claude Code Review

Head SHA: 78508fe

Files changed:

  • 1
  • src/post_process/m_start_up.fpp

Findings

Precision discipline: real(..., wp) used for stp storage field

src/post_process/m_start_up.fpp — ib_markers conversion hunk:

-                     & -offset_z%beg:p + offset_z%end))
+                     & -offset_z%beg:p + offset_z%end), wp)

out%q_sf is a scalar_field%sf, which uses stp per project convention. The conversion real(ib_markers%sf(...), wp) produces a wp-precision value that is then stored into the stp field. In --mixed precision mode (wp=double, stp=half) this silently materialises a double-precision intermediate that is truncated to half on assignment — real(..., stp) is the correct form. The old code (real(...) without kind) was already wrong for the same reason; this change picks the wrong explicit kind.

Fix: real(ib_markers%sf(...), stp).

@sbryngelson sbryngelson merged commit 9906fa6 into MFlowCode:master Jun 25, 2026
82 checks passed
fahnab666 pushed a commit to fahnab666/mfc-nabid that referenced this pull request Jul 6, 2026
…FlowCode#1600)

Co-authored-by: Spencer Bryngelson <sbryngelson@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants