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

Integrate finite volume operators #529

Merged
merged 39 commits into from
Nov 27, 2019

Conversation

ali-ramadhan
Copy link
Member

@ali-ramadhan ali-ramadhan commented Nov 11, 2019

This PR integrates the finite volume operators introduced in PR #283. This includes merging closure_operators.jl into Oceananigans.Operators. All tests pass but there's quite a bit of cleanup to be done.

@glwagner This PR affects a lot of code you've written so we should probably work on merging this PR together. Now that tests pass we can focus on cleanup.

I still need to convert the biharmonic operators and leith_enstrophy_diffusivity.jl closure to finite volume. I'll also add a test for Leith.

There are regression tests for constant diffusivty, Smagorinsky, and AMD, but not for other closures, so we should probably be careful that closures with no regression test remain unchanged.

Some comments:

  1. The norm functions defined in velocity_tracer_gradients.jl https://github.com/climate-machine/Oceananigans.jl/blob/2bb32015e64bff830f2233d588360ccc6b8605b4/src/TurbulenceClosures/velocity_tracer_gradients.jl#L130-L154 all make use of functions like Δᶠx_ffc but they are defined in an @eval loop in in verstappen_anisotropic_minimum_dissipation.jl. We should probably make it clearer that these functions are closure-specific.

  2. In smagorinsky_lilly.jl, the κ_∂x_c, κ_∂y_c, and κ_∂z_c functions use ℑxᶠᵃᵃ(i, j, k, grid, νₑ, closure) however I'm pretty sure we can just use ℑxᶠᵃᵃ(i, j, k, grid, νₑ) here. If so, we can get rid of the ℑxᶠᵃᵃ(i, j, k, grid::AG{FT}, c, args...) function definitions.

  3. Certain functions are shared between turbulence closures, e.g. ΣᵢⱼΣᵢⱼᶜᶜᶜ is used by both smagorinsky_lilly.jl and blasius_smagorinsky.jl. Should they be moved to closure_operators.jl?

  4. Also, VAMD uses Δᶠxᶜᶜᶜ for the filter widths while Rozema AMD uses Δx (which looks like the regular Δx used by Oceananigans.Operators). We should probably change all filter widths to use Δᶠ.

  5. Smagorinsky-Lilly uses Δᶠ_ccc for filter widths. Switching to Δᶠᶜᶜᶜ is probably a bad idea as is denotes face. Should we change them to Δᶠxᶜᶜᶜ = Δᶠyᶜᶜᶜ = Δᶠzᶜᶜᶜ = Δᶠ_ccc?

  6. I could never find a symbol like \cdot for divergences that can be used in function names. What do you think of renaming function names like ∇_κ_∇c to div_κ_∇c?

  7. is used in a lot of places in the AbstractOperators module. They should probably be changed to for consistency, but since it's all local to AbstractOperators, I'm leave the decision to @glwagner.

Some changes we need to make for vertically stretched grids:

  • I initially thought that we might need apply_z_top_bc! and apply_z_bottom_bc! to use ΔzC or ΔzF based on the field, but this would only apply to w for which you cannot use flux boundary conditions for z, so maybe it can always just use ΔzF (spacing between faces) and we can keep the one version.
  • Same comment as above for _fill_top_halo! and _fill_bottom_halo!.

I'll release v0.16 once this is merged as JULES.jl depends on these finite volume operators.

Possibly redundant. Will discuss in PR.
@ali-ramadhan ali-ramadhan added cleanup 🧹 Paying off technical debt numerics 🧮 So things don't blow up and boil the lobsters alive labels Nov 11, 2019
@ali-ramadhan
Copy link
Member Author

@glwagner Do you think you'll have some time to review this PR this week?

It affects a lot of code you've written and is a bit of a bottleneck as it refactors a lot of the existing code.

@codecov
Copy link

codecov bot commented Nov 26, 2019

Codecov Report

Merging #529 into master will increase coverage by 5.04%.
The diff coverage is 72.35%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #529      +/-   ##
==========================================
+ Coverage    62.6%   67.65%   +5.04%     
==========================================
  Files          70       69       -1     
  Lines        2054     1954     -100     
==========================================
+ Hits         1286     1322      +36     
+ Misses        768      632     -136
Impacted Files Coverage Δ
src/AbstractOperations/unary_operations.jl 86.66% <ø> (ø) ⬆️
src/Operators/areas_and_volumes.jl 100% <ø> (+100%) ⬆️
src/Oceananigans.jl 75% <ø> (ø) ⬆️
src/TimeSteppers/TimeSteppers.jl 74.35% <ø> (ø) ⬆️
src/Operators/difference_operators.jl 65.21% <ø> (+65.21%) ⬆️
src/Operators/Operators.jl 100% <ø> (ø) ⬆️
src/AbstractOperations/AbstractOperations.jl 33.33% <ø> (ø) ⬆️
src/AbstractOperations/function_fields.jl 25% <ø> (ø) ⬆️
src/AbstractOperations/grid_validation.jl 75% <ø> (ø) ⬆️
src/TurbulenceClosures/TurbulenceClosures.jl 33.33% <ø> (ø) ⬆️
... and 37 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2bb3201...b73e099. Read the comment docs.

@ali-ramadhan ali-ramadhan changed the title [WIP] Integrate finite volume operators Integrate finite volume operators Nov 26, 2019
Copy link
Member

@glwagner glwagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! My only concern is the name of viscous and diffusive flux divergence functions. We should make sure these names are non-confusing in the case of tensor diffusivities and viscosities.

+ closure.νv * ∂z²_aaf(i, j, k, grid, U.w)
)
@inline ∂ⱼ_2ν_Σ₃ⱼ(i, j, k, grid, closure::ConstantAnisotropicDiffusivity, U, args...) =
div_ν∇w(i, j, k, grid, closure.νh, closure.νh, closure.νv, U.w)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused by this notation. We have a tensor diffusivity here, which means we cannot write this operator as "the divergence of ν∇w". Why is this name for the operator preferred, when it does not correctly reflect the mathematical operation? Is there some kind of benefit to this shorthand? I feel the explicit original versions are easier to read and understand.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. Originally I just wanted to get rid of things like ∇_κ∇c as it looked like a "gradient of a gradient". Indeed div_ν∇w is quite specific so I'll change them to use names like ∂ⱼνᵢⱼ∂ᵢw.


which will end up at the location `ccf`.
"""
@inline function div_ν∇w(i, j, k, grid, νˣ, νʸ, νᶻ, w)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the name of this function is confusing. The operation is represents is

∂ⱼ νᵢⱼ ∂ᵢ w

where νᵢⱼ is a diagonal tensor. However, the notation div_ν∇w, implies, at least to me, the divergence of a scalar (isotropic) diffusivity times the gradient of vertical velocity.

Maybe we don't have to resolve this here, but we should be careful that the names of our functions clearly reflect the mathematical objects they implement.

src/TurbulenceClosures/viscous_dissipation_operators.jl Outdated Show resolved Hide resolved
src/TurbulenceClosures/viscous_dissipation_operators.jl Outdated Show resolved Hide resolved
src/TurbulenceClosures/viscous_dissipation_operators.jl Outdated Show resolved Hide resolved
@ali-ramadhan ali-ramadhan merged commit 0f33075 into master Nov 27, 2019
@ali-ramadhan ali-ramadhan deleted the ar/integrate-finite-volume-operators branch November 27, 2019 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup 🧹 Paying off technical debt numerics 🧮 So things don't blow up and boil the lobsters alive
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants