Skip to content

Set the IBM mask file in the input file and check its shape (#456) - #457

Open
ia267 wants to merge 5 commits into
mainfrom
456_ibm_file_input
Open

ia267 wants to merge 5 commits into
mainfrom
456_ibm_file_input

Conversation

@ia267

@ia267 ia267 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #456. Closes #481.

Problem

Since #290 the IBM mask file name is built from the periodicity of each direction (ibm_000.bp, ibm_100.bp, ...). Users have to work out the suffix and rename the generated ibm.bp by hand. The suffix also never checks the file: a mask made for a different grid is read without complaint, and the run carries on with a wrong mask until it diverges (#481).

Changes

  • ibm_file in &solver_params (default 'ibm.bp') names the mask file. The suffix logic is removed from src/module/ibm.f90.
    &solver_params
      ibm_on = T
      ibm_file = 'cylinder.bp'
    /
  • Shape check on load. New reader_session%read_shape() returns the global shape of a 3D variable without reading it (ADIOS2: adios2_variable_shape; the dummy backend reports the usual "recompile with ADIOS2" error). If ep1 doesn't match the mesh's global vertex dims, the run stops:
    ERROR: IBM mask in bad.bp is 65 x 32 x 16 but the mesh has 64 x 32 x 16 vertices. Regenerate the mask for this grid.
    
    A mask written from Python in C order has the shape [nz, ny, nx] in the file. ADIOS2 reverses the shape and the selection for a Fortran reader, so the check compares x, y, z with x, y, z whichever language wrote the mask. The comment in init now says this.
  • x3d2-memcheck (merged from main, Add x3d2-memcheck: estimate and measure the GPU memory a case run needs #326) used the removed suffix helper to look for the mask. It now checks the file that ibm_file names, and docs/source/user/memcheck.rst says so.
  • ADIOS2 writer fix. write_data for an integer(i8) scalar defined the variable as integer4 and then wrote 8 bytes, so ADIOS2 stopped every callwith a type mismatch. Nothing in src wrote an i8 scalar, so this went unnoticed until the new test wrote iibm. It now defines integer8, which is what the i8 reader already expected.
  • examples/cylinder: the rename table is removed from the readme, input.x3d sets ibm_file, and the readme now points to x3d2-tools.
  • Docs: new "Immersed Boundary" section in docs/source/user/input_file.rst covering ibm_on and ibm_file.

New test: test_ibm_mask_read

Until now no test read an IBM mask from a file. tests/unit/test_ibm_mask_read.f90 writes its own mask, so it needs no data files and no Python:

  • Grid: 37 x 35 x 6·nranks with a Dirichlet x boundary, split over the ranks in z. Each direction has a different size, and none is a multiple of SZ, so the padded copy in init is used.
  • Mask: each rank writes its own slab with the x3d2 writer. Every point holds a value made from its global index, i + 100 j + 10000 k, so a wrong offset, a swapped axis or a bad padded copy gives a wrong value. The values are exact in single precision too.
  • Read check: ibm_t reads the mask, and every rank copies ep1 back from the device and compares each point with the index pattern.
  • Mismatch check: the mismatch variant writes one point more in x and must stop with the shape error. As with the other abort tests, ctest checks the output (PASS_REGULAR_EXPRESSION / FAIL_REGULAR_EXPRESSION), not the exit code, which depends on the MPI launcher.
  • Registration: both variants run on every backend in an ADIOS2 build (test_ibm_mask_read_<backend>_<np> and ..._mismatch), next to the other ADIOS2 I/O tests. Each one writes to a file named after its executable, so ctest -j runs don't share a mask.

To check the test can fail, I set the read offsets in init to zero: ranks 1 to 3 then fail with 7770 points of ep1 are wrong.

Testing

GNU + ADIOS2 Debug build (-Werror), OpenMP backend, a 64×32×16 TGV with ibm_on, using masks written the same way as x3d2-tools (shape=[nz, ny, nx]):

Case Result
Matching mask, 1 rank runs; ibm snapshot field equals the input mask exactly
Matching mask, 2 ranks runs; ibm snapshot field equals the input mask exactly
65×32×16 mask stops with the error above
No ibm_file, no ibm.bp stops with IBM file not found: ibm.bp

After merging main, NVHPC 25.3 Release builds:

Build ctest
OpenMP 73/73 pass
CUDA (cc80), with x3d2-memcheck 161/161 pass
CUDA (cc80) + ADIOS2 176/176 pass, including the four test_ibm_mask_read tests (OMP and CUDA, 4 ranks)

The cylinder case (257×128×32, mask written from Python) on the CUDA + ADIOS2 build runs on 1 and 2 ranks. With dims_global set to 257×128×64 it stops with IBM mask in ibm_100.bp is 257 x 128 x 32 but the mesh has 257 x 128 x 64 vertices.

fprettify (--config .fprettify.ini --recursive src, as in CI) and on the new test: no changes.

Notes

  • The check compares sizes only. A mask for the same dims_global with different BCs has the same shape but a different spacing (L/n vs L/(n−1)), so it isn't caught. The old suffix didn't catch that either. Catching it would needx3d2-tools to store the spacing or BCs in the file.
  • Existing ibm_XYZ.bp files still work: set ibm_file to that name.
  • The mismatch test stops before it can delete its mask, so it leaves a small .bp file in the build's tests/ directory.

The IBM mask file name was built from the periodicity of each direction
(ibm_000.bp, ibm_100.bp, ...), so users had to rename the generated file
to match their BCs. The suffix never checked the contents either: a mask
made for another grid was read without complaint.

- Add ibm_file to &solver_params (default 'ibm.bp') and drop the suffix.
- Add reader_session%read_shape, which returns the global shape of a 3D
  variable without reading it, and use it to stop with a clear error when
  the mask size differs from the mesh's vertex count.
- Update examples/cylinder and document ibm_on/ibm_file.
@ia267
ia267 marked this pull request as draft October 29, 2026 08:29
@ia267 ia267 self-assigned this Oct 30, 2026
@ia267 ia267 added the enhancement New feature or request label Oct 30, 2026
@kaanolgu

Copy link
Copy Markdown
Collaborator

This PR also closes #481

Resolve the conflict in src/module/ibm.f90: keep the ibm_file argument
of ibm_t's init and drop ibm_mask_filename, which main added for
x3d2-memcheck (#326). x3d2-memcheck now checks solver_cfg%ibm_file for
the mask file, and its docs say so.
write_data for an integer(i8) scalar defined the variable as integer4
and then put an 8-byte value, so ADIOS2 rejected every call with a type
mismatch. Nothing in src wrote an i8 scalar, so it went unnoticed; the
i8 reader already expects integer8, which is what Python writes for the
iibm of an IBM mask.
test_ibm_mask_read writes a mask whose every point holds its global
index, reads it through ibm_t on a grid split over the ranks and checks
each point of ep1. The mismatch variant writes a mask one point too big
in x and must stop with the shape error. Both run on every backend with
ADIOS2.

Reword the comment on the mask layout in ibm_t: ADIOS2 reverses the
shape of a C-order file for a Fortran reader, so x3d2 reverses nothing
itself.
@ia267
ia267 marked this pull request as ready for review November 19, 2026 12:50
@ia267 ia267 added this to the Version 0.1.0 milestone Nov 19, 2026
@ia267
ia267 requested a review from kaanolgu November 19, 2026 12:52

@kaanolgu kaanolgu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The CI tests pass on this branch, apart from the known test_penta_omp_4 failure in the Debug builds (#468). I also ran the cylinder on this branch and on main with OpenMP on 1 and 2 ranks and with CUDA on 1 GPU. The enstrophy history agrees with main bit for bit, restarts work, and a missing or wrong-size mask stops all ranks with a clear message

deallocate (mask)
call MPI_Barrier(MPI_COMM_WORLD, ierr)

ibm = ibm_t(backend, mesh, runtime%host_allocator, trim(mask_file))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In the mismatch run, ibm_t stops all ranks here, so the rm -rf at the end does not run. Each run then leaves test_ibm_mask_read_omp_4_mismatch.bp in the build tree. Could a CTest cleanup fixture with cmake -E remove_directory remove the file instead? The fixture also runs after an abort, and the test then does not call a shell

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, done in c6e6d75. Each run of test_ibm_mask_read now has a <test>_cleanup test (FIXTURES_CLEANUP) that runs cmake -E remove_directory on its .bp, so the mask is removed after the mismatch abort too, and the test no longer calls a shell. I used remove_directory rather than -E rm -rf because our minimum CMake is 3.13. Checked locally: no .bp left after ctest -R ibm_mask, or after running the mismatch test on its own.

The mismatch run of test_ibm_mask_read stops in ibm_t before its rm -rf,
so it left <test name>.bp in the build tree. A cleanup test per run now
removes the file with cmake -E remove_directory. ctest runs it after the
test whether that passed, failed or aborted, and adds it when only the
test itself is selected. The test no longer calls a shell.
@ia267
ia267 requested a review from kaanolgu November 20, 2026 16:46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IBM mask is read without a check of its size against the grid Add IBM mask as an input parameter

2 participants