Skip to content

xm_periodic/ym_periodic: loneeqn halo copy uses loop variable after the loop (out-of-range plane) #344

Description

@mvreeuwijk

Found by the #330 audit, still present on master.

In xm_periodic (src/modboundary.f90; same pattern in ym_periodic), the one-equation-model halo copy sits AFTER the do m = 1, ih loop ends but still indexes with m:

do m = 1, ih
   u0(ib - m, :, :) = u0(ie + 1 - m, :, :)
   ...
end do

if (loneeqn) then
   e120(ib - m, :, :) = e120(ie + 1 - m, :, :)   ! m == ih + 1 here
   ...
end if

After the loop Fortran leaves m = ih + 1, so e120/e12m copy a single plane one past the intended halo range instead of planes 1..ih — wrong periodic BCs for the one-equation SGS model and an out-of-bounds access when the halo width is ih (with ih = 1 it touches ib-2/ie+2). Fix: move the loneeqn block inside the loop.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions