Skip to content

post_process: extract shared Lagrangian-bubble restart-header read (and name the 5x disp offset) #1519

@sbryngelson

Description

@sbryngelson

The two Lagrangian-bubble output routines in src/post_process/m_data_output.fpps_write_lag_bubbles_results_to_text (lines 711–861) and s_write_lag_bubbles_to_formatted_database_file (864–1068) — share a byte-identical MPI-IO restart-header read block, plus a hand-copied header-offset expression.

1. Identical restart-header read (~28 lines, duplicated)

Lines 750–777 (text reader) and 909–936 (Silo reader) are identical: open the restart file on MPI_COMM_SELF, read file_tot_part / file_time / file_dt / file_num_procs, four MPI_BCASTs, allocate proc_bubble_counts, reopen/seek/read the per-proc counts, broadcast:

call MPI_FILE_OPEN(MPI_COMM_SELF, file_loc, MPI_MODE_RDONLY, mpi_info_int, ifile, ierr)
call MPI_FILE_READ(ifile, file_tot_part, 1, MPI_INTEGER, status, ierr)
call MPI_FILE_READ(ifile, file_time, 1, mpi_p, status, ierr)
call MPI_FILE_READ(ifile, file_dt, 1, mpi_p, status, ierr)
call MPI_FILE_READ(ifile, file_num_procs, 1, MPI_INTEGER, status, ierr)
...4× MPI_BCAST...
allocate (proc_bubble_counts(file_num_procs))
...reopen, MPI_FILE_SEEK, MPI_FILE_READ(proc_bubble_counts), close, MPI_BCAST...

→ extract s_read_lag_restart_header(file_loc, file_tot_part, file_time, file_dt, file_num_procs, proc_bubble_counts) and call it from both routines.

2. Header-offset expression copied 5×

disp = int(sizeof(file_tot_part) + 2*sizeof(file_time) + sizeof(file_num_procs), MPI_OFFSET_KIND)

appears at lines 770 and 929 (base form), and with + file_num_procs*sizeof(proc_bubble_counts(1)) at 791, 968, 1027 — five copies, all in agreement.
→ replace with a single small f_lag_header_offset(...) function (or compute once).

Where the routines legitimately diverge (and should stay separate): after the shared header, the text reader reads all particles on rank 0 and writes an ASCII table; the Silo reader computes a per-rank subarray and writes a Silo point-mesh. Keep the extraction scoped to the header read only — note that the post-header MPI_FILE_SET_VIEW uses mpi_info_null in one routine and mpi_info_int in the other, so don't over-unify.

Risk: low. This is input-side code motion of an identical block; as long as the helper returns the same values, file output is unchanged. Exercised by the Lagrangian-bubble regression tests (./mfc.sh test --only Lagrange and the lagrange_shbubcollapse example) — a header-read regression would corrupt downstream void-fraction output and trip the NaN/Inf / D/ golden checks.


Filed from a repo-wide code-cleanliness review; verified against master @ 40dde5e.

Code references

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions