Wall-Distance-Conditioned Stable Stencils for Flow Surrogates on Unseen Geometries

Neural surrogates for fluid simulation are fast but brittle. When they meet a pipe shape or obstacle they were not trained on, the errors reported on CFDBench exceed 300%. When they are run forward step after step, a Fourier Neural Operator's error on that benchmark grows about 1,000-fold. A separate line of work goes the other way. It writes a classical finite-difference update as a convolution whose weights are physical coefficients such as velocity and diffusivity, and it clamps those weights so the update cannot blow up. That approach beats neural solvers by one to two orders of magnitude, but only on uniform, box-shaped domains with coefficients that are constant in space.

This note proposes to combine the two. We keep the stable numerical update and let its coefficients vary from point to point. A small network predicts those coefficients from two inputs: each point's position relative to the walls, given as a signed distance to the nearest boundary, and a short space-time window of recent flow. Geometry then enters only through the coefficients of an update that is stable by construction. It does not enter through free-form feature maps. The bet is that this is what lets a surrogate carry what it learned about boundary layers to new shapes, while staying stable over long rollouts.

Core Claim

Translation-invariant convolutions must infer "I am near a wall" from local flow patterns. Absolute coordinate channels tell the network where it is, but not where it is relative to the geometry, so they overfit to training positions. We claim that the right place for coordinate awareness in a physics surrogate is the coefficient field of a stability-constrained discretization, conditioned on boundary-relative coordinates. The update at each step is

$$u^{n+1} = u^n + \Delta t\,\big[-a_\theta(\xi)\cdot\nabla_h u^n + \nu_\theta(\xi)\,\nabla_h^2 u^n + s_\theta(\xi)\big], \qquad \xi = \big(d_w,\ \nabla d_w,\ u^{n-K:n}\big),$$

The symbols are as follows. $u^n$ is the flow field at step $n$. $\nabla_h$ and $\nabla_h^2$ are fixed, mask-aware finite-difference gradient and Laplacian stencils that apply no-slip ghost values at walls. $d_w$ is the signed distance to the nearest wall and $\nabla d_w$ its direction. $u^{n-K:n}$ is the last $K$ frames. $a_\theta$, $\nu_\theta$ and $s_\theta$ are a per-point advection correction, a per-point effective viscosity and a small bounded source term, all produced by a network with parameters $\theta$.

Following DeepFDM, each coefficient passes through a scaled sigmoid. This enforces the local stability limits $|a_\theta|\Delta t/\Delta x \le C$ and $\nu_\theta\Delta t/\Delta x^2 \le 1/4$. The second limit is the standard 2D forward-Euler diffusion bound. The limits hold at every point, not just globally.

For incompressible cases, a fixed number of differentiable Jacobi iterations projects the velocity onto a divergence-free field on the masked domain. This supplies the domain-wide pressure coupling that purely local methods lack.

The coefficient network is a shallow spatiotemporal convolutional network: 3D kernels over $(x, y, t)$, in the homogeneous $3\times3\times3$ style of C3D. Its input is the $K$-frame window with distance channels appended. The time axis lets it infer effective, history-dependent coefficients, such as a local eddy viscosity near separating flow. A single snapshot cannot reveal these.

Relation to Prior Work

The motivating evidence comes from benchmarks. CFDBench evaluates FNO, U-Net and DeepONet on cavity, tube, dam-break and cylinder flows. It gives them binary obstacle masks and uniform operating-condition channels, and still finds errors up to 300% on unseen geometries and parameters. It also finds the "identity trap", in which a step-by-step model learns to copy the previous frame. PDEBench supplies boundary, conservation and spectral error metrics. It restricts itself to rectangular grids, which is why we need CFDBench for geometry shift.

The method is supplied by Numerical PDE solvers outperform neural PDE solvers. There, DeepFDM implements finite differences as convolutions with sigmoid-bounded coefficients and reports sub-1% out-of-distribution relative error, against roughly 10% for FNO and U-Net. We reuse its stability clamp. We depart from it by making coefficients spatially varying and geometry-conditioned, by working on masked, non-rectangular domains, and by adding a pressure projection. The authors name these as limits of their approach.

Coordinate conditioning comes from CoordConv, which appends normalized position channels so that convolutions can reason about absolute location. It gives a dramatic gain on coordinate mapping but only +0.04% on ImageNet. That split warns us that coordinates help only when the task genuinely depends on position. In image restoration and depth estimation, position-dependent corrections are routine: under-display camera restoration and PLADE-Net both do this. There, though, the position dependence is tied to a fixed sensor. Ours must be tied to a geometry that changes between training and test, which is why we use wall distance rather than raw $(x,y)$.

FlowForge constrains the design. Its staged local rollouts are strong across CFDBench, PDEBench and BubbleML, but its purely local context is poorly suited to domain-wide pressure coupling such as lid-driven cavity. Our local stencil plus explicit projection is meant to cover both regimes.

The C3D spatiotemporal convolution work (Learning Spatiotemporal Features with 3D Convolutional Networks) and its dense encoder-decoder extension (Voxel2Voxel) show that 3D kernels extract motion without hand-built features. Here they play a deliberately minor role: reading history into coefficients, not predicting the flow directly.

Research Program

We will build the solver in stages, each tested before adding the next. The first stage is a mask-aware stencil library with ghost-cell no-slip walls and a differentiable Jacobi projection. The second is the coefficient network. The third is the local stability clamp. All three are trained end to end on short unrolls of 8 to 16 steps, with the loss on the unrolled states, so the model cannot profit from copying the previous frame.

The analysis half asks whether the learned $\nu_\theta(d_w)$ and $a_\theta(d_w)$ collapse onto a shared profile across geometries when plotted against wall distance. Such a profile would be a learned near-wall correction, and its existence is the mechanism we claim. If they do not collapse, the transfer we hope for has no reason to occur.

Baselines

The naive reference point is persistence: predict that the next frame equals the current one. This is exactly the identity trap. Any model whose long-rollout error is not clearly below persistence has learned nothing about transport.

The strongest existing methods are the CFDBench baselines and FlowForge. For U-Net and FNO, CFDBench reports only qualitative magnitudes in the material we have: errors up to 300% under geometry and parameter shift, and a 1,000-fold error growth for FNO in step-by-step rollout. We will retrain both on our splits rather than rely on those figures. For FlowForge, which ranks best or second-best in RMSE on 10 of 11 datasets, no reported result found on Lacuna for per-dataset RMSE. We will rerun it from its description on identical splits.

DeepFDM with constant, global coefficients on the same masked stencils is the closest method baseline. Its reported advantage is sub-1% versus roughly 10% out-of-distribution relative error on 1D parametric PDEs. It isolates whether spatially varying, geometry-conditioned coefficients add anything beyond stable discretization alone.

Two ablations target the key ingredient. The first swaps the signed-distance inputs for absolute CoordConv $(x, y)$ channels. The second replaces the 3D spatiotemporal coefficient network with a 2D single-frame one.

All models get the same training cases, the same parameter budget within a factor of two, and the same GPU-hour budget. Each model gets the same hyperparameter search, for example 20 trials. Beating a baseline means lower mean relative error on held-out geometries over three seeds, and lower error at the final rollout step, with non-overlapping seed ranges.

Why not just…?

Why not just append signed-distance and coordinate channels to a U-Net? This is the most serious threat, because it is cheap and commonly done. Its weakness is that nothing stops a free-form network from drifting into instability or copying frames. CFDBench's mask channels did not prevent large errors, although binary masks carry less information than distance fields. We run exactly this model, with identical inputs, as a baseline. If it matches us on held-out geometries at long horizons, the stencil structure is not earning its place and we would report that.

Why not just predict whole future blocks with a 3D convolutional encoder-decoder plus coordinate channels? This is the obvious intersection idea. Block prediction avoids per-step compounding only inside the block, and it still gives no stability or conservation guarantee between blocks. The 3D memory cost also caps the window at around 16 frames, as in Voxel2Voxel. We include it as a baseline and compare divergence error and error at 10 times the block length.

Why not just use DeepFDM with learned constant coefficients? On periodic, box-shaped PDEBench problems this may well tie us, and we expect it to. The question is wall-bounded, geometry-shifted flow, where a single viscosity cannot represent near-wall behavior. The constant-coefficient baseline measures exactly this gap.

Why not just add a PDE-residual penalty to the loss? Soft penalties are known to create conflicting, stiff gradients (Learning a Neural Solver for Parametric PDEs to Enhance Physics-Informed Methods). PDEBench found such models trailing FNO and U-Net. A penalty also gives no stability guarantee at inference time. We add the residual penalty to the U-Net baseline as a variant, not as a separate method.

Proposed Experiments

The main testbed is CFDBench's tube, dam-break and cylinder tasks, split by geometry, so that test obstacle shapes and tube profiles never appear in training. Lid-driven cavity serves as the domain-wide pressure-coupling test. Metrics are relative error at 1, 10 and 100 steps, divergence error as a proxy for mass conservation, and PDEBench-style boundary RMSE computed over a band of cells near walls. PDEBench's 2D diffusion-reaction and compressible Navier-Stokes cases act as a rectangular-domain sanity check, where we expect only parity with the strongest baseline.

Four checks decide the outcome. First, on held-out geometries at 100 steps, our model must beat the distance-channel U-Net. Second, the signed-distance version must beat the absolute-coordinate version under geometry shift but not in-distribution; this is the predicted signature of coordinate overfitting. Third, removing the Jacobi projection should hurt substantially on cavity and little on tube flow; if it does not, the domain-wide-coupling story is wrong. Fourth, the learned coefficients should collapse onto a common profile in wall distance across held-out geometries. If the first check fails, the idea is refuted in its current form.