[WIP] Nonhydrostatic free surface: CG solver support for IBG and stretched-horizontal grids#5706
Draft
xkykai wants to merge 2 commits into
Draft
[WIP] Nonhydrostatic free surface: CG solver support for IBG and stretched-horizontal grids#5706xkykai wants to merge 2 commits into
xkykai wants to merge 2 commits into
Conversation
…new formulations - Added support for various grid types (XYZ, XY, XZ, YZ) in nonhydrostatic_pressure_solver. - Introduced FreeSurfaceLaplacian and fft_free_surface_preconditioner for improved handling of free surface conditions. - Updated tests to validate pressure solver dispatch for different grid configurations and free surface scenarios.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After meeting and having discussions with @shriyafruitwala on #4740 I think it is straightforward to extend the nonhydrostatic free surface to other grids and setups as well, utilizing the CG solver to either deal with immersed boundaries or stretched grids in non-z directions.
Summary
NonhydrostaticModelsupports an implicit free surface via a Robin (mixed) boundary condition on the 3D pressure Poisson equation. The Robin BC modifies the rigid-lid operator atk = Nz:Azᶜᶜᶠ(i,j,Nz+1) / den * ϕ[i,j,Nz](eliminates the null space, so no gauge condition is needed)Azᶜᶜᶠ(i,j,Nz+1) * g * Δt * η★ / denwhereη★ = η + Δt * w̃andden = g*Δt² + Δzᶠ/2Previously this was handled only by
FourierTridiagonalPoissonSolverwithInhomogeneousFormulation(ZDirection()), which bakes both terms into the direct solve. This PR extends implicit free surface support to grids and configurations where that direct approach is not applicable.Bug fixed: incorrect dispatch for
XZRegularRG/YZRegularRG+ free surfaceThe old dispatch
Union{GridWithFourierTridiagonalSolver, XYZRegularRG} + free_surfaceappliedInhomogeneousFormulation(ZDirection())to allGridWithFourierTridiagonalSolvertypes, which includesXZRegularRG(stretched y) andYZRegularRG(stretched x). This is invalid — those grids have a non-uniform horizontal direction that cannot be handled by FFT in the z-tridiagonal formulation.New cases covered
XYZRegularRGorXYRegularRGFourierTridiagonalPoissonSolver(InhomogeneousFormulation(ZDirection()))XZRegularRG(stretched y)ConjugateGradientPoissonSolverwithFreeSurfaceLaplacian+ FT (HomogNeumann y-dir) preconditionerYZRegularRG(stretched x)ConjugateGradientPoissonSolverwithFreeSurfaceLaplacian+ FT (HomogNeumann x-dir) preconditionerIBGWithFFT(any FFT-compatible underlying)ConjugateGradientPoissonSolverwithFreeSurfaceLaplacian+fft_free_surface_preconditioner(underlying)For IBG cases,
fft_free_surface_preconditionerselects the best available FT preconditioner:InhomogeneousFormulation(ZDirection())when the underlying grid has both x and y uniform (so the preconditioner directly encodes the Robin BC), or HomogeneousNeumann FT otherwise.Key additions
FreeSurfaceLaplacian(callable struct,Solvers/conjugate_gradient_poisson_solver.jl)CG linear operator for the free-surface pressure equation. For each CG iteration it:
ϕ[Nz+1] = ϕ[Nz], preventing theMixedBoundaryConditiononp_Δt(set at model construction from the previous time step) from polluting the operator_symmetric_laplacian_operator!kernel-Az/den * ϕ[Nz]solve_for_pressure!split (CG dispatch,solve_for_pressure.jl)ConjugateGradientPoissonSolvernow has separate dispatches for::Nothing(rigid lid, unchanged) andfree_surface(new). The free-surface dispatch:Az * g * Δt * η★ / denatk = Nzk = Nzviaupdate_fourier_tridiagonal_solver!(guarded against HomogeneousNeumann FT preconditioners and non-FT preconditioners)solve!(pressure, cg_solver, rhs, free_surface, Δt), propagating(free_surface, Δt)through toFreeSurfaceLaplacianDispatch table redesign to avoid Julia method ambiguity
XYRegularRG <: XZRegularRG(a grid with both x and y regular is a subtype of "x regular"). This means mixing union dispatches on the grid type with per-type dispatches on::Nothingvsfree_surfacecreates cross-dimension ambiguities that Julia cannot resolve. The fix is to use per-type dispatches throughout — one method per concrete grid type for each(grid_type, free_surface_type)combination. The same treatment was applied to theDistributedsolver dispatches.Test plan
NonhydrostaticModelconstruction withImplicitFreeSurface()onXYZRegularRG(regression)NonhydrostaticModelconstruction withImplicitFreeSurface()onIBGWithFFT→ usesConjugateGradientPoissonSolverwithFreeSurfaceLaplacianXZRegularRG + ImplicitFreeSurface(blocked by pre-existingmaterialize_free_surfacelimitation: the hydrostaticFFTImplicitFreeSurfaceSolverconstruction insideImplicitFreeSurfacefails for non-uniform-in-horizontal grids before our new pressure solver dispatch is reached)🤖 Generated with Claude Code