OpenFOAM VOF sampling: half-cell plane offsets, a flux-balance check that caught a units bug, and editing endTime mid-run
Context: multiphaseInterFoam (OpenFOAM 8) spray cases, sampled with a surfaces function object (cuttingPlane, surfaceFormat raw, interpolate false) every 5 microseconds. Mixing and coverage were post-processed in numpy.
1. Put cutting planes half a cell off the mesh faces (z = z_target + dx/2). A plane that coincides with a layer of cell faces can give degenerate or duplicated cut polygons. Half a cell off, every cut cell gives one dx-by-dx polygon at its centre, which maps straight onto an index grid: i = floor((x - x0)/dx).
2. Always check the time-mean flux through each plane against the injected mass flow: sum(rho_phase * alpha_phase * Uz) * dx^2 over the plane, divided by the inlet mass flow. It should be about 1.0 once the spray is steady. Mine first came out 0.00, with NaN mixing efficiencies and wall fractions of 1.00. The cause: the case metadata stored dx in metres while the post script assumed millimetres for cell area and for bin sizes such as 0.25 mm bins and 0.5 mm wall bands. After the fix the ratio was 0.96 to 1.02 at every plane. Keep one unit for geometry in metadata, and name the variable with its unit (dx_m).
3. Shortening a running case: with runTimeModifiable yes, editing endTime in the case-root system/controlDict takes effect at the next time step, in parallel runs too. Before cutting runs short, average a finished case over two windows (0.2-0.3 ms against 0.2-0.4 ms). Here the metrics agreed within a few per cent, which saved about 25% of compute on the remaining cases.
4. Shell gotcha in the driver: in zsh, for vm in "a b" "c d"; do set -- $vm; ... does not word-split $vm. So $2 was empty and gcloud compute scp --zone $2 printed its help, which is easy to miss in tail output. Use ${=vm} in zsh, or call each host explicitly.
5. Resolution caveat for cold-flow impinging-jet VOF at about 7 cells across the smallest hole: the sheet forms and fans out correctly, but it stays a thin coherent sheet without resolved droplet breakup. Use it to compare layouts, not for absolute atomisation.