-
Notifications
You must be signed in to change notification settings - Fork 189
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
Remove Tullio dependency; take #2 and implement universally accurate CFL time-scale #3037
Changes from 9 commits
e5b424d
67e92ef
a1b549d
786e8d2
d694462
3c8d844
5508269
e31abbb
8b12c59
0230734
0b90834
3d2fb59
0c2472b
f0e33fe
5cc4332
e689081
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,31 +83,6 @@ DiffusiveCFL(Δt) = CFL(Δt, cell_diffusion_timescale) | |
##### Accurate CFL via reduction | ||
##### | ||
|
||
using CUDA, CUDAKernels, KernelAbstractions, Tullio | ||
|
||
using Oceananigans.Models | ||
using Oceananigans.Grids: halo_size | ||
using Oceananigans.Operators: Δxᶠᶜᶜ, Δyᶜᶠᶜ, Δzᶜᶜᶠ | ||
|
||
accurate_cell_advection_timescale(model) = accurate_cell_advection_timescale(model.grid, model.velocities) | ||
|
||
function accurate_cell_advection_timescale(grid, velocities) | ||
Nx, Ny, Nz = size(grid) | ||
Hx, Hy, Hz = halo_size(grid) | ||
|
||
is = 1+Hx:Nx+Hx | ||
js = 1+Hy:Ny+Hy | ||
ks = 1+Hz:Nz+Hz | ||
|
||
u = view(velocities.u.data.parent, is, js, ks) | ||
v = view(velocities.v.data.parent, is, js, ks) | ||
w = view(velocities.w.data.parent, is, js, ks) | ||
|
||
min_timescale = minimum( | ||
@tullio (min) timescale[k] := 1 / ( abs(u[i, j, k]) / Δxᶠᶜᶜ(i, j, k, grid) | ||
+ abs(v[i, j, k]) / Δyᶜᶠᶜ(i, j, k, grid) | ||
+ abs(w[i, j, k]) / Δzᶜᶜᶠ(i, j, k, grid)) | ||
) | ||
using Oceananigans.Advection: cell_advection_timescale | ||
navidcy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return min_timescale | ||
end | ||
accurate_cell_advection_timescale(model) = cell_advection_timescale(model.grid, model.velocities) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we would keep the function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree!
glwagner marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
is this the proper way to compute CFL? I'll trust you on that... That's like the geometric mean of the timescales in each direction?
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.
Imagine a 2D situation, we start from
$$\frac{\partial c}{\partial t} = u\frac{\partial c}{\partial x} + v\frac{\partial c}{\partial y}$$
$$|u|\frac{\Delta t}{\Delta x} + |v|\frac{\Delta t}{\Delta y} < CFL (\text{ maximum 1 })$$
$$\Delta t / \tau < CFL$$
$$\tau = \left(\frac{|u|}{\Delta x} + \frac{|v|}{\Delta y} \right)^{-1}$$
We have advection in x and y, by extension from the 1D CFL condition we can approximate the CFL condition as
This means that
where
The extension to 3D includes also the advection in z
This is just a choice, as to account for diagonal motion probably you can get away with a square root of 2 somewhere. But it is the usual definition of the CFL condition
https://en.wikipedia.org/wiki/Courant%E2%80%93Friedrichs%E2%80%93Lewy_condition
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.
Sounds good! Why don't we include all this in the docstring of the
cell_advection
?