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

Fix compute_dt when using IGG #215

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 14 additions & 39 deletions src/Utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ macro unpack(x)
end
end

"""
compute_dt(S::JustRelax.StokesArrays, args...)

Compute the time step `dt` for the simulation.
"""
function compute_dt(S::JustRelax.StokesArrays, args...)
return compute_dt(backend(S), S, args...)
end
Expand All @@ -423,51 +428,21 @@ function compute_dt(::CPUBackendTrait, S::JustRelax.StokesArrays, args...)
return _compute_dt(S, args...)
end

"""
compute_dt(S::JustRelax.StokesArrays, di)

Compute the time step `dt` for the velocity field `S.V` for a regular grid with grid spacing `di`.
"""
@inline _compute_dt(S::JustRelax.StokesArrays, di) = _compute_dt(@velocity(S), di, Inf)

"""
compute_dt(S::JustRelax.StokesArrays, di, dt_diff)
@inline _compute_dt(S::JustRelax.StokesArrays, di) =
_compute_dt(@velocity(S), di, Inf, maximum)

Compute the time step `dt` for the velocity field `S.V` and the diffusive maximum time step
`dt_diff` for a regular gridwith grid spacing `di`.
"""
@inline _compute_dt(S::JustRelax.StokesArrays, di, dt_diff) =
_compute_dt(@velocity(S), di, dt_diff)
_compute_dt(@velocity(S), di, dt_diff, maximum)

@inline function _compute_dt(V::NTuple, di, dt_diff)
n = inv(length(V) + 0.1)
dt_adv = mapreduce(x -> x[1] * inv(maximum(abs.(x[2]))), min, zip(di, V)) * n
return min(dt_diff, dt_adv)
end
"""
compute_dt(S::JustRelax.StokesArrays, di, igg)

Compute the time step `dt` for the velocity field `S.V` for a regular gridwith grid spacing `di`.
The implicit global grid variable `I` implies that the time step is calculated globally and not
separately on each block.
"""
@inline _compute_dt(S::JustRelax.StokesArrays, di, I::IGG) =
_compute_dt(@velocity(S), di, Inf, I::IGG)
@inline _compute_dt(S::JustRelax.StokesArrays, di, dt_diff, ::IGG) =
_compute_dt(@velocity(S), di, dt_diff, maximum_mpi)

"""
compute_dt(S::JustRelax.StokesArrays, di, dt_diff)

Compute the time step `dt` for the velocity field `S.V` and the diffusive maximum time step
`dt_diff` for a regular gridwith grid spacing `di`. The implicit global grid variable `I`
implies that the time step is calculated globally and not separately on each block.
"""
@inline function _compute_dt(S::JustRelax.StokesArrays, di, dt_diff, I::IGG)
return _compute_dt(@velocity(S), di, dt_diff, I::IGG)
end
@inline _compute_dt(S::JustRelax.StokesArrays, di, ::IGG) =
_compute_dt(@velocity(S), di, Inf, maximum_mpi)

@inline function _compute_dt(V::NTuple, di, dt_diff, I::IGG)
@inline function _compute_dt(V::NTuple, di, dt_diff, max_fun::F) where {F<:Function}
n = inv(length(V) + 0.1)
dt_adv = mapreduce(x -> x[1] * inv(maximum_mpi(abs.(x[2]))), max, zip(di, V)) * n
dt_adv = mapreduce(x -> x[1] * inv(max_fun(abs.(x[2]))), max, zip(di, V)) * n
return min(dt_diff, dt_adv)
end

Expand Down