Skip to content

Support the 111 case in the FFT Poisson solver (#449) - #497

Open
ia267 wants to merge 6 commits into
mainfrom
449_poisson_111
Open

ia267 wants to merge 6 commits into
mainfrom
449_poisson_111

Conversation

@ia267

@ia267 ia267 commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Closes #449.

Adds the 111 case, where x, y and z are all non-periodic, to the FFT Poisson solver on the OMP and CUDA backends. The wind_turbine case can now have free-slip walls in y and z.

Poisson 111

Like Incompact3d's poisson_11x, 111 reuses the whole 110 path. The z direction is folded before the transform and unfolded after it, in the copies that already hold z whole:

  • OMP: a z_dst map in the r_tr transposes.
  • CUDA: a fold_z flag in transpose_xyz_to_zxy / transpose_zxy_to_xyz and unpack_110_yslab / pack_110_yslab.

The solver types are renamed omp_poisson_11x_t and cuda_poisson_11x_t. fft_bc_is_11x replaces the == '110' checks.

The real-to-complex transform of a folded line gives C_k − i·C_{N−k}. So the imaginary part of the modified wavenumbers has to use the mirrored z mode N−k. waves_set is rebuilt from 1D factors per spectral direction (spectral_line, interp_transfer), with one loop for all cases. The existing cases are unchanged: analytic errors are identical to main, and other differences are at 1e-13 round-off.

111 costs the same as 110. On a 256³ grid with the CUDA backend, a solve takes 14.3 ms vs 14.4 ms on 1 GPU and 77.6 ms vs 77.3 ms on 2 GPUs.

Fixes found on the way (separate commits)

  • Generic decomposition dropped vertices (08e286e8). It used global_vert_dims / nproc_dir, so a non-divisible count lost points, and a split non-periodicdirection could not have uniform cells. A 2-GPU ddd run failed with MPI "Message truncated". It now splits cells as 2decomp does, with the extra vertex on the last rank. test_mesh now expects the same split from both decompositions.
  • CUDA Y_FACE used the unpadded z stride (f2f22feb). On cell fields withnon-periodic z, the top y face was written to the wrong groups. Vertex fields and periodic z were not affected.

Walls in z (aa37baf2, a2c7c80b)

  • field_set_face now supports Z_FACE on OMP, CUDA and OMP_TGT. It stamps only on the first or last z rank, and only for Dirichlet.
  • x_slice_weighted_sum takes optional z weights. The outflow flux balance from#440 now uses trapezoid weights in both y and z.
  • wind_turbine accepts Neumann (free-slip) y and z boundaries. It sets v = 0 on the y walls and w = 0 on the z walls, and uses the weighted outlet balance. Y walls currently require nproc_dir(2) = 1.
  • examples/wind_turbine_alm now uses these walls on the 641×129×321 grid, matching the two_turbines setup it reproduces (addde8e5). Before, it was periodicin y and z on 641×128×320.

Tests

  • test_poisson_bc has two new 111 cases, ddd (65×65×129) and ddd_odd (82×82×82). They run on 1 and 2 ranks, plus a y-split run on OMP.
    • Poisson error is 1.58e-8, identical on both backends and on 1 and 2 ranks.
    • Round trips are at 1e-14 or better.
  • test_boundary_planes now runs with z walls on 1 and 2 ranks. It covers the z-weighted sum and Z_FACE on vertex and cell fields.
  • ctest: OMP 78/78, CUDA 170/170.

OMP_TGT has no FFT Poisson solver, so 111 is not available there. The OMP_TGT Z_FACE and z-weight kernels were not compiled or run, because no OMP_TGT build was available.

Validation: two turbines with y and z walls vs Incompact3d

The case is the two_turbines ALM example on a 641×129×321 grid with free-slip y and z walls, run for 10,000 steps on 2 GPUs. The reference is unmodified Incompact3d with the same walls. Divergence stays at about 5e-12 throughout.

Mean loads over t = 1–2 s, compared with Incompact3d. The noise column is how much Incompact3d's own loads change when the z walls are removed.

thrust power noise (thrust / power)
Turbine 1 +0.02% +0.07% +0.01% / +0.03%
Turbine 2 +0.21% −0.93% +0.09% / −0.41%

Turbine 2's torque is small (about −0.23 N·m), so −0.93% is a difference of 0.002 N·m.

Wake profiles of mean u and u′ within one rotor diameter of the axis:

  • Behind turbine 1 the RMS difference is 0.02–0.31% of U∞.
  • Behind turbine 2 it is 0.8–2.3% of U∞. Incompact3d's own runs with and withoutz walls differ by 0.7–1.8% at the same stations.

Both differences are the size of the sampling noise of a 1 s average.

Notes for reviewers

  • The outlet mass correction intentionally differs from Incompact3d's plain mean. With walls, a plain mean leaves a uniform divergence that the projection cannotremove; an earlier y-wall run sat at about 6e-4.
  • The CUDA X_FACE kernel has the same stride pattern as the old Y_FACE kernel. It is only called on vertex fields, where it is correct, so it is left unchanged.

decomposition_generic gave every rank global_vert_dims/nproc_dir vertices,
which silently drops the remainder when the count does not divide. A
non-periodic direction has one vertex more than cells, so its vertices and
its cells can never both divide by the rank count: a non-periodic direction
split over ranks (the CUDA backend, which never uses 2decomp) always lost
vertices or held unequal cells. 129 z vertices on 2 ranks gave 64 cells on
rank 0 and 63 on rank 1, 127 instead of 128.

split_points now splits each direction the way decomp_2d_init does with the
periodicity flags: the cells as evenly as possible, the remainder on the last
ranks, and the extra vertex of a non-periodic direction on the last rank. A
non-periodic direction of P*m cells gives every rank m cells, and both
decompositions hand a rank the same range. A periodic direction whose count
divides is split as before.

test_mesh pinned the old generic split ([4, 4, 4, 4] vertices for 15 cells
on 4 ranks); both decompositions now give [3, 4, 4, 5].
Non-periodic x, y and z now run on the OpenMP and CUDA backends, on one rank
and on several. As in Incompact3d's poisson_11x, 110 and 111 share one
solver type per backend (omp_poisson_11x_t, cuda_poisson_11x_t), with the
same (nz/2+1, nx, ny) spectral layout, plans, buffers and spectral kernels.
111 differs in three places:

- z is folded (odd entries ascending, even descending) so that the r2c
  transform along z stands in for a cosine transform. The fold rides in the
  copies that already move z into and out of the transform buffer: the z
  transpose on one rank, the z-pencil (OpenMP) or the cuFFTMp Y-slab unpack
  and pack (CUDA) on several. A 111 solve costs the same as a 110 one.
- az, bz take the half-angle form of a non-periodic direction, which
  wave_numbers already gives.
- The imaginary part of waves takes the mirrored z mode N - k: the r2c of the
  folded line, after the half-shift twiddle, holds C_k - i C_{N-k}.

waves_set builds waves from the 1D factors of each spectral dimension
instead of one 3D loop nest per layout: the expression is symmetric in the
directions, so one loop serves every case, and the mirrored mode is a
per-dimension detail. stretching_matrix shares the interpolation transfer
function. On the existing cases the analytic errors of test_poisson_bc are
unchanged and the other checks move by round-off only.

FFT_BC_111 and fft_bc_is_11x classify the case for the CUDA helpers and
x3d2-memcheck, which treat it as 110. The CUDA case on several ranks needs
the z cell count to divide by the rank count.

test_poisson_bc gains ddd and ddd_odd, on one rank for both backends, and
ddd on two ranks with a z split (both) and a y split (OpenMP). Its mode test
now removes the mean of its right-hand side, which is not zero with odd cell
counts in x and in a non-periodic z.
field_set_y_face located the top face at group b + (ny - 1)/SZ*nz with nz
the z count of the field's own data_loc. The DIR_X group stride is the
padded z count of the allocator. On a non-periodic z, a cell field holds one
z station fewer than vertices on the last rank, so its top y face went to
the wrong groups there. The launch still covers the field's own z stations,
and only the stride changes. Vertex fields, and periodic z, were not
affected. The OpenMP backend already used the padded stride.

test_boundary_planes runs its cell-field Y_FACE check on a non-periodic z
from the next commit, which is what exposed this.
Free-slip z walls need the impermeability stamp w = 0 on the z faces and
an outlet flow-rate balance weighted along z, as #440 weighted it along y.

field_set_face now sets Z_FACE on the OpenMP, CUDA and OpenMP-target
backends. Unlike y, z is decomposed, so a face is set only by the rank that
holds it, the first or the last along z (z_face_owned, shared by the three
backends), and on a cell field the top face is its last local z station.
A non-Dirichlet bc_start or bc_end leaves that face alone, as for Y_FACE.

x_slice_weighted_sum takes optional z_weights, a weight per local z
station on top of the y weights (z_weight_line gives 1 when absent), and
outflow_flow_rate_correction passes them through.

test_boundary_planes splits z over the ranks with free-slip walls and runs
on one and on two ranks. It checks both Z_FACE planes, the Neumann bottom,
a cell field, and the z-weighted sum.
Incompact3d's two_turbines example has free-slip walls in y and z
(ncly1 = nclyn = nclz1 = nclzn = 1), which the 111 Poisson case now
supports. BC_y and BC_z may each be 'periodic' or 'neumann' at both ends.

apply_BC follows Incompact3d's pre_correc: Dirichlet inflow and convective
outflow on the x faces, then v = 0 on the y walls and w = 0 on the z walls,
stamped last so they win on the edges. The outlet mass correction balances
the flow rates as the discrete divergence sees them, with trapezoid weights
along a walled direction (outflow_flow_rate_correction), in place of the
plain mean over the planes. For periodic y and z every weight is 1 and the
correction is the plain mean as before. With walls the plain mean, which
Incompact3d uses, leaves a uniform divergence that the Neumann-x projection
cannot remove (about 6e-4 in the y-wall two_turbines run). The weighted one
keeps div(u) at round-off.

y walls need y not decomposed: field_set_face stamps the local y planes.
The two_turbines setup it reproduces has free-slip walls in y and z.
With the 111 Poisson solver and wall support in wind_turbine, the
example now uses the same boundaries and grid (641 x 129 x 321).
@ia267 ia267 added this to the Version 0.1.0 milestone Nov 22, 2026
@ia267
ia267 requested a review from kaanolgu November 22, 2026 06:59
@ia267 ia267 self-assigned this Nov 22, 2026
@ia267 ia267 added the enhancement New feature or request label Nov 22, 2026
@ia267
ia267 marked this pull request as ready for review November 22, 2026 07:00

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.

FFT Poisson solver: support the 111 case (non-periodic x, y and z)

1 participant