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

Using znode instead of znodes inside kernels #104

Closed
navidcy opened this issue May 27, 2023 · 1 comment · Fixed by #107
Closed

Using znode instead of znodes inside kernels #104

navidcy opened this issue May 27, 2023 · 1 comment · Fixed by #107

Comments

@navidcy
Copy link
Collaborator

navidcy commented May 27, 2023

zᶜ = znodes(grid, Center(), Center(), Center())
zᶠ = znodes(grid, Center(), Center(), Face())
∫chlʳ = @inbounds (zᶠ[grid.Nz + 1] - zᶜ[grid.Nz]) * (P[i, j, grid.Nz] * Rᶜₚ / r) ^
∫chlᵇ = @inbounds (zᶠ[grid.Nz + 1] - zᶜ[grid.Nz]) * (P[i, j, grid.Nz] * Rᶜₚ / r) ^ eᵇ
# first point below surface
@inbounds PAR[i, j, grid.Nz] = PAR⁰ * (exp(kʳ * zᶜ[grid.Nz] - χʳ * ∫chlʳ) + exp(kᵇ * zᶜ[grid.Nz] - χᵇ * ∫chlᵇ)) / 2
@inbounds for k in grid.Nz-1:-1:1
∫chlʳ += (zᶜ[k + 1] - zᶠ[k + 1]) * (P[i, j, k+1] * Rᶜₚ / r) ^+ (zᶠ[k + 1] - zᶜ[k]) * (P[i, j, k] * Rᶜₚ / r) ^
∫chlᵇ += (zᶜ[k + 1] - zᶠ[k + 1]) * (P[i, j, k+1] * Rᶜₚ / r) ^ eᵇ + (zᶠ[k + 1] - zᶜ[k]) * (P[i, j, k] * Rᶜₚ / r) ^ eᵇ
PAR[i, j, k] = PAR⁰ * (exp(kʳ * zᶜ[k] - χʳ * ∫chlʳ) + exp(kᵇ * zᶜ[k] - χᵇ * ∫chlᵇ)) / 2
end

Here, I think it'd be much more efficient if instead of, e.g.,

zᶜ = znodes(grid, Center(), Center(), Center()) 
zᶜ[k + 1]
using Oceananigans.Grids: znode
znode(i, j, k+1, grid, Center(), Center(), Center())

The former create a whole array and selects a value from it. The latter just gets the value needed from the grid.

@navidcy
Copy link
Collaborator Author

navidcy commented May 29, 2023

Actually this might not be an issue. But definitely some bounds checking are missing here.

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

Successfully merging a pull request may close this issue.

1 participant