-
Notifications
You must be signed in to change notification settings - Fork 190
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
Changes to naming in the TurbulenceClosures
module
#2752
Conversation
We could also just change the signature of the |
Yeah I like that idea. Also, is there anything that keeps us from passing |
There is no adapt method for the model. I don't know how it would play to send the whole model to the GPU. We might have some parameter space issue |
@inline function calc_nonlinear_κᶜᶜᶜ(i, j, k, grid, closure::SmagorinskyLilly, buoyancy, U, C, ::Val{tracer_index}) where {tracer_index} | ||
νₑ = calc_nonlinear_νᶜᶜᶜ(i, j, k, grid, closure, buoyancy, U, C) | ||
|
||
@inbounds Pr = closure.Pr[tracer_index] | ||
|
||
return νₑ / Pr | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure this is needed, κₑ
is given as a BinaryOperation
so calculating νₑ
should be enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thinking here is that it'd be good to unify the interface across models. I was also planning on creating dispatches of this function for ScalarDiffusivity()
and tuple closures. It'd make things like these easier (in Oceanostics): https://github.com/tomchor/Oceanostics.jl/blob/29a544d3decd833d9f86da05b66a7392197c3b93/src/Oceanostics.jl#L25-L39
For example, as a user, I don't know what function I should use to get the diffusivities and viscosities that works for different closures. As far as I know there isn't one. This is my attempt to get us closer.
Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I agree, but I would also leave that calc_nonlinear_κᶜᶜᶜ
is used to calculate the diffusivity while κᶜᶜᶜ
is used to retrieve the diffusivity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unity may be a good goal, but we shouldn't add code until the moment we need it / without tests.
I was thinking we could change Based on @glwagner's comments I was also going to remove the extra definition of However, I noticed this breaks some internal functions. Before I go ahead and fix those, I wanted to check if this changed is desirable from the developers' perspective. @glwagner @simone-silvestri what do you guys think? |
Why introduce a vector? What does it represent? (The diagonal elements of a hypothetical viscosity tensor, which is defined implicitly?) How would it be used? |
In cases where the viscosity is a tuple, it would return the correct viscosities/diffusivities in each direction. For example in a case like the snippet below
using Using the same code in the master branch returns one number ( |
I see. It would be nice to have this as a user API convenience, but then to be complete we must include all the other entries of the tensor. It might get a bit tedious when you want to include isopycnal diffusivities like |
I think the other tensor entries are much less frequently needed, so I'd propose we start only with the simple stuff and add the rest when needed. I was also thinking that for inner-working purposes it's best to keep the current |
Why is a vector that represents the diagonal elements of a hypothetical viscosity tensor useful? |
Because I think most of the tuple closures used are But most of the reason for my attempted changes to julia> grid = RectilinearGrid(size=(4, 4, 4), extent=(1, 1, 1));
julia> closure = (HorizontalScalarDiffusivity(ν=1), VerticalScalarDiffusivity(ν=2));
julia> model = NonhydrostaticModel(grid=grid, closure=closure);
julia> using Oceananigans.TurbulenceClosures: viscosity
julia> viscosity(model.closure, model.diffusivity_fields)
3.0 Maybe the best way to move forward isn't to change |
I think what I'm asking is what you envision using this vector for. I don't see the purpose of it. One could just as easily inspect each closure in the tuple individually to see what the viscosity for each closure type is. This method is unambiguous and more general than developing a "vector abstraction" for the diagonal components of a viscosity tensor. That said, I agree that the output of The main use case envisioned is when you have two When the closure tuple involves multiple We also need to deal with the case where the closure tuple contains non-scalar-diffusivity closures. To design an abstraction, I think we should start with a use case, which can help us develop requirements for the abstraction. Once we have requirements, we can implement something minimal and simple that's easy to reason with and that will generalize to more complicated use cases we may want to consider in the future (hopefully). |
I agree with this. I'll revert |
I wonder if we should return a tuple instead, and let the user compute the sum if that's valid? Eg viscosity(diffusivities, closure_tuple) # returns a tuple
# For users who know this is valid:
nu = sum(viscosity(diffusivities, closure_tuple)) |
I like this idea! It's implemented right now. @glwagner @simone-silvestri Let me know if there's anything left to adjust in this PR |
@@ -17,7 +17,7 @@ import Oceananigans.TurbulenceClosures: | |||
calculate_nonlinear_viscosity!, | |||
viscosity, | |||
with_tracers, | |||
calc_νᶜᶜᶜ, | |||
calc_nonlinear_νᶜᶜᶜ, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rationale was to differentiate from calc_νᶜᶜᶜ()
from νᶜᶜᶜ()
, which at first seem to do the same thing. That said, I'm okay with other names. What would you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we even need separate calc_νᶜᶜᶜ()
and νᶜᶜᶜ()
if they do the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. I always assumed there was a reason to separate them. If we can use only one of them and get rid of the other, I'm all for it.
src/TurbulenceClosures/abstract_scalar_biharmonic_diffusivity_closure.jl
Outdated
Show resolved
Hide resolved
src/TurbulenceClosures/turbulence_closure_implementations/leith_enstrophy_diffusivity.jl
Outdated
Show resolved
Hide resolved
I think some of the changes here are positive. However, I don't see the point of changing |
Thanks for the review. I'm relatively agnostic about what we call things. Mostly I'd just like to make this module more readable. |
I think the main issue here is that there is too much code, reflecting the fact that an interface for defining closures has emerged over time rather than being designed from the ground up. It could possibly benefit from a rethink. It's not as much an issue of the names of things in my opinion. |
src/TurbulenceClosures/turbulence_closure_implementations/leith_enstrophy_diffusivity.jl
Outdated
Show resolved
Hide resolved
src/TurbulenceClosures/turbulence_closure_implementations/smagorinsky_lilly.jl
Outdated
Show resolved
Hide resolved
…h_enstrophy_diffusivity.jl Co-authored-by: Gregory L. Wagner <wagner.greg@gmail.com>
@glwagner this almost became stale but I think it's ready to review and possibly merge. It doesn't re-work the code like you suggest here, but it does make the functions more easily understandable on first pass by being more verbose. It also changes the behavior of Finally it also changes the function This PR used to also remove a fallback that was a bit problematic because it silently returned zero diffusivity values for closures like Smagorinsky, but it seems some other PR got around to that first before merging this one :) |
Ok, I will review! Except, tests are failing? Also should we merge main? |
Thanks! And yeah there was a typo in my last commit but it should be fixed as tests should be passing. I also merged main in commit 479056a (yesterday) so we should be good regarding that. |
@glwagner Tests are passing now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
This PR will rename some variables and funcitons in the
TurbulenceClosures
module to make things more clear.It will also remove the fallback dispatch ofcalc_ κᶜᶜᶜ()
and definecalc_ κᶜᶜᶜ()
at least for the Smagorisnky-Lilly closure.It also changes the behavior of
viscosity()
to return a tuple when given a tuple, instead ofsum
ming all the viscosities in the tuple. This avoids misuse by unattentive users who have a tuple with different-formulation-viscosities (for example horizontal and vertical formulations). (This comment provides an example.)Closes #2751
CC @simone-silvestri