-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce gauge condition in preconditioners for ConjugateGradientPoiss…
…onSolver (#3802) * Reorganize utils and enforce gauge condition * Fix formatting issue * Some small improvements * PreconditionedCGSolver -> CGSolver * Change to conjugate gradient solver * Move ConjugateGradientPoissonSolver to Solvers * More improvments * Import ConjugateGradientPoissonSolver * Bugfixes * Bugfix * Fix function signature plus notation update * Missed a spot
- Loading branch information
Showing
13 changed files
with
199 additions
and
181 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,91 @@ | ||
using Oceananigans.Operators | ||
using Oceananigans.Solvers: FFTBasedPoissonSolver, FourierTridiagonalPoissonSolver, solve! | ||
using Oceananigans.DistributedComputations: DistributedFFTBasedPoissonSolver | ||
using Oceananigans.Grids: XDirection, YDirection, ZDirection | ||
using Oceananigans.Grids: XDirection, YDirection, ZDirection, inactive_cell | ||
using Oceananigans.Solvers: FFTBasedPoissonSolver, FourierTridiagonalPoissonSolver | ||
using Oceananigans.Solvers: ConjugateGradientPoissonSolver | ||
using Oceananigans.Solvers: solve! | ||
|
||
##### | ||
##### Calculate the right-hand-side of the non-hydrostatic pressure Poisson equation. | ||
##### | ||
|
||
@kernel function calculate_pressure_source_term_fft_based_solver!(rhs, grid, Δt, U★) | ||
@kernel function _compute_source_term!(rhs, grid, Δt, Ũ) | ||
i, j, k = @index(Global, NTuple) | ||
@inbounds rhs[i, j, k] = divᶜᶜᶜ(i, j, k, grid, U★.u, U★.v, U★.w) / Δt | ||
active = !inactive_cell(i, j, k, grid) | ||
δ = divᶜᶜᶜ(i, j, k, grid, Ũ.u, Ũ.v, Ũ.w) | ||
@inbounds rhs[i, j, k] = active * δ / Δt | ||
end | ||
|
||
@kernel function calculate_pressure_source_term_fourier_tridiagonal_solver!(rhs, grid, Δt, U★, ::XDirection) | ||
@kernel function _fourier_tridiagonal_source_term!(rhs, ::XDirection, grid, Δt, Ũ) | ||
i, j, k = @index(Global, NTuple) | ||
@inbounds rhs[i, j, k] = Δxᶜᶜᶜ(i, j, k, grid) * divᶜᶜᶜ(i, j, k, grid, U★.u, U★.v, U★.w) / Δt | ||
active = !inactive_cell(i, j, k, grid) | ||
δ = divᶜᶜᶜ(i, j, k, grid, Ũ.u, Ũ.v, Ũ.w) | ||
@inbounds rhs[i, j, k] = active * Δxᶜᶜᶜ(i, j, k, grid) * δ / Δt | ||
end | ||
|
||
@kernel function calculate_pressure_source_term_fourier_tridiagonal_solver!(rhs, grid, Δt, U★, ::YDirection) | ||
@kernel function _fourier_tridiagonal_source_term!(rhs, ::YDirection, grid, Δt, Ũ) | ||
i, j, k = @index(Global, NTuple) | ||
@inbounds rhs[i, j, k] = Δyᶜᶜᶜ(i, j, k, grid) * divᶜᶜᶜ(i, j, k, grid, U★.u, U★.v, U★.w) / Δt | ||
active = !inactive_cell(i, j, k, grid) | ||
δ = divᶜᶜᶜ(i, j, k, grid, Ũ.u, Ũ.v, Ũ.w) | ||
@inbounds rhs[i, j, k] = active * Δyᶜᶜᶜ(i, j, k, grid) * δ / Δt | ||
end | ||
|
||
@kernel function calculate_pressure_source_term_fourier_tridiagonal_solver!(rhs, grid, Δt, U★, ::ZDirection) | ||
@kernel function _fourier_tridiagonal_source_term!(rhs, ::ZDirection, grid, Δt, Ũ) | ||
i, j, k = @index(Global, NTuple) | ||
@inbounds rhs[i, j, k] = Δzᶜᶜᶜ(i, j, k, grid) * divᶜᶜᶜ(i, j, k, grid, U★.u, U★.v, U★.w) / Δt | ||
active = !inactive_cell(i, j, k, grid) | ||
δ = divᶜᶜᶜ(i, j, k, grid, Ũ.u, Ũ.v, Ũ.w) | ||
@inbounds rhs[i, j, k] = active * Δzᶜᶜᶜ(i, j, k, grid) * δ / Δt | ||
end | ||
|
||
##### | ||
##### Solve for pressure | ||
##### | ||
|
||
function solve_for_pressure!(pressure, solver::DistributedFFTBasedPoissonSolver, Δt, U★) | ||
function compute_source_term!(pressure, solver::DistributedFFTBasedPoissonSolver, Δt, Ũ) | ||
rhs = solver.storage.zfield | ||
arch = architecture(solver) | ||
grid = solver.local_grid | ||
|
||
launch!(arch, grid, :xyz, calculate_pressure_source_term_fft_based_solver!, | ||
rhs, grid, Δt, U★) | ||
|
||
# Solve pressure Poisson equation for pressure, given rhs | ||
solve!(pressure, solver) | ||
|
||
return pressure | ||
launch!(arch, grid, :xyz, _compute_source_term!, rhs, grid, Δt, Ũ) | ||
return nothing | ||
end | ||
|
||
function solve_for_pressure!(pressure, solver::FFTBasedPoissonSolver, Δt, U★) | ||
|
||
# Calculate right hand side: | ||
rhs = solver.storage | ||
function compute_source_term!(pressure, solver::DistributedFourierTridiagonalPoissonSolver, Δt, Ũ) | ||
rhs = solver.storage.zfield | ||
arch = architecture(solver) | ||
grid = solver.grid | ||
|
||
launch!(arch, grid, :xyz, calculate_pressure_source_term_fft_based_solver!, | ||
rhs, grid, Δt, U★) | ||
|
||
# Solve pressure Poisson given for pressure, given rhs | ||
solve!(pressure, solver, rhs) | ||
|
||
grid = solver.local_grid | ||
tdir = solver.batched_tridiagonal_solver.tridiagonal_direction | ||
launch!(arch, grid, :xyz, _fourier_tridiagonal_source_term!, rhs, tdir, grid, Δt, Ũ) | ||
return nothing | ||
end | ||
|
||
function solve_for_pressure!(pressure, solver::DistributedFourierTridiagonalPoissonSolver, Δt, U★) | ||
|
||
# Calculate right hand side: | ||
rhs = solver.storage.zfield | ||
function compute_source_term!(pressure, solver::FourierTridiagonalPoissonSolver, Δt, Ũ) | ||
rhs = solver.source_term | ||
arch = architecture(solver) | ||
grid = solver.local_grid | ||
|
||
launch!(arch, grid, :xyz, calculate_pressure_source_term_fourier_tridiagonal_solver!, | ||
rhs, grid, Δt, U★, solver.batched_tridiagonal_solver.tridiagonal_direction) | ||
|
||
# Pressure Poisson rhs, scaled by the spacing in the stretched direction at ᶜᶜᶜ, is stored in solver.source_term: | ||
solve!(pressure, solver) | ||
|
||
grid = solver.grid | ||
tdir = solver.batched_tridiagonal_solver.tridiagonal_direction | ||
launch!(arch, grid, :xyz, _fourier_tridiagonal_source_term!, rhs, tdir, grid, Δt, Ũ) | ||
return nothing | ||
end | ||
|
||
function solve_for_pressure!(pressure, solver::FourierTridiagonalPoissonSolver, Δt, U★) | ||
|
||
# Calculate right hand side: | ||
rhs = solver.source_term | ||
function compute_source_term!(pressure, solver::FFTBasedPoissonSolver, Δt, Ũ) | ||
rhs = solver.storage | ||
arch = architecture(solver) | ||
grid = solver.grid | ||
launch!(arch, grid, :xyz, _compute_source_term!, rhs, grid, Δt, Ũ) | ||
return nothing | ||
end | ||
|
||
launch!(arch, grid, :xyz, calculate_pressure_source_term_fourier_tridiagonal_solver!, | ||
rhs, grid, Δt, U★, solver.batched_tridiagonal_solver.tridiagonal_direction) | ||
##### | ||
##### Solve for pressure | ||
##### | ||
|
||
# Pressure Poisson rhs, scaled by the spacing in the stretched direction at ᶜᶜᶜ, is stored in solver.source_term: | ||
function solve_for_pressure!(pressure, solver, Δt, Ũ) | ||
compute_source_term!(pressure, solver, Δt, Ũ) | ||
solve!(pressure, solver) | ||
return pressure | ||
end | ||
|
||
return nothing | ||
function solve_for_pressure!(pressure, solver::ConjugateGradientPoissonSolver, Δt, Ũ) | ||
rhs = solver.right_hand_side | ||
grid = solver.grid | ||
arch = architecture(grid) | ||
launch!(arch, grid, :xyz, _compute_source_term!, rhs, grid, Δt, Ũ) | ||
return solve!(pressure, solver.conjugate_gradient_solver, rhs) | ||
end | ||
|
This file contains 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
This file contains 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
Oops, something went wrong.