Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pressure solver algorithm involves two superfluous fields #2126

Closed
glwagner opened this issue Dec 18, 2021 · 4 comments
Closed

Pressure solver algorithm involves two superfluous fields #2126

glwagner opened this issue Dec 18, 2021 · 4 comments

Comments

@glwagner
Copy link
Member

It appears that we allocate memory for a few more 3D arrays than needed in order to calculate pressure in NonhydrostaticModel. We currently allocate 3 arrays: one for hydrostatic pressure, one for non-hydrostatic pressure, and a third array with Complex{Float64} elements that's used for in-place FFTs while solving the pressure Poisson equation.

For our algorithm to be correct, however, we only need one array with Complex{Float64} elements. This array can than be used as scratch space when calculating the hydrostatic pressure and computing hydrostatic pressure gradients. It will then be overwritten when calculating the nonhydrostatic pressure component.

The distinction between the solver field with Complex{Float64} elements and the nonhydrostatic pressure is just that the nonhydrostatic pressure is real, which we enforce when copying it over:

@kernel function copy_real_component!(ϕ, ϕc)
i, j, k = @index(Global, NTuple)
@inbounds ϕ[i, j, k] = real(ϕc[i, j, k])
end

However, we could just as easily extract the real component when computing the pressure gradient:

@kernel function _pressure_correct_velocities!(U, grid, Δt, pNHS)
i, j, k = @index(Global, NTuple)
@inbounds U.u[i, j, k] -= ∂xᶠᶜᵃ(i, j, k, grid, pNHS) * Δt
@inbounds U.v[i, j, k] -= ∂yᶜᶠᵃ(i, j, k, grid, pNHS) * Δt
@inbounds U.w[i, j, k] -= ∂zᵃᵃᶠ(i, j, k, grid, pNHS) * Δt
end

@glwagner
Copy link
Member Author

cc @tomchor

@tomchor
Copy link
Collaborator

tomchor commented Dec 18, 2021

Nice catch. Does this only happen for the fft-based solver?

@glwagner
Copy link
Member Author

All of the pressure solvers require storage arrays whose memory space can, in principle, be reused to hold either the hydrostatic or non-hydrostatic pressure.

The main detriment is that one of the pressure fields has to be overwritten. In our algorithm I think that means it would no longer be possible to output the nonhydrostatic pressure component.

@glwagner
Copy link
Member Author

I'm closing this issue because I'm judging that it's not of current, timely relevance to Oceananigans development. If you would like to make it a higher priority or if you think the issue was closed in error please feel free to re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants