Skip to content

Commit

Permalink
fix compute_dt when passing IGG
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-de-montserrat committed Aug 12, 2024
1 parent b9d2729 commit 40e46e7
Showing 1 changed file with 11 additions and 40 deletions.
51 changes: 11 additions & 40 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,17 @@ 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)

@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)

"""
compute_dt(S::JustRelax.StokesArrays, di, dt_diff)
_compute_dt(@velocity(S), di, dt_diff, 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`. 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, dt_diff, ::IGG) =
_compute_dt(@velocity(S), di, dt_diff, 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

0 comments on commit 40e46e7

Please sign in to comment.