Skip to content

Commit

Permalink
Try #1496:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Oct 11, 2023
2 parents 88c3f78 + c8c1ff7 commit d0a2b82
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 51 deletions.
30 changes: 20 additions & 10 deletions src/Operators/finitedifference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ Base.@propagate_inbounds function stencil_interior(
)
a⁺ = getidx(space, arg, loc, idx + half, hidx)
a⁻ = getidx(space, arg, loc, idx - half, hidx)
RecursiveApply.rdiv(a⁺ a⁻, 2)
FT = Spaces.undertype(space)
RecursiveApply.rmul(a⁺ a⁻, FT(0.5))
end

boundary_width(::InterpolateF2C, ::AbstractBoundaryCondition) = 0
Expand Down Expand Up @@ -423,7 +424,8 @@ Base.@propagate_inbounds function stencil_interior(
)
a⁺ = getidx(space, arg, loc, idx + half, hidx)
a⁻ = getidx(space, arg, loc, idx - half, hidx)
RecursiveApply.rdiv(a⁺ a⁻, 2)
FT = Spaces.undertype(space)
RecursiveApply.rmul(a⁺ a⁻, FT(0.5))
end
boundary_width(::InterpolateC2F, ::AbstractBoundaryCondition) = 1

Expand Down Expand Up @@ -467,7 +469,8 @@ Base.@propagate_inbounds function stencil_left_boundary(
getidx(space, bc.val, loc, nothing, hidx),
Geometry.LocalGeometry(space, idx, hidx),
)
a⁺ RecursiveApply.rdiv(v₃, 2)
FT = Spaces.undertype(space)
a⁺ RecursiveApply.rmul(v₃, FT(0.5))
end
Base.@propagate_inbounds function stencil_right_boundary(
::InterpolateC2F,
Expand All @@ -484,7 +487,8 @@ Base.@propagate_inbounds function stencil_right_boundary(
getidx(space, bc.val, loc, nothing, hidx),
Geometry.LocalGeometry(space, idx, hidx),
)
a⁻ RecursiveApply.rdiv(v₃, 2)
FT = Spaces.undertype(space)
a⁻ RecursiveApply.rmul(v₃, FT(0.5))
end

Base.@propagate_inbounds function stencil_left_boundary(
Expand Down Expand Up @@ -1180,7 +1184,8 @@ Base.@propagate_inbounds function stencil_left_boundary(
getidx(space, bc.val, loc, nothing, hidx),
Geometry.LocalGeometry(space, idx, hidx),
)
a⁺ RecursiveApply.rdiv(v₃, 2)
FT = Spaces.undertype(space)
a⁺ RecursiveApply.rmul(v₃, FT(0.5))
end
Base.@propagate_inbounds function stencil_right_boundary(
::WeightedInterpolateC2F,
Expand All @@ -1198,7 +1203,8 @@ Base.@propagate_inbounds function stencil_right_boundary(
getidx(space, bc.val, loc, nothing, hidx),
Geometry.LocalGeometry(space, idx, hidx),
)
a⁻ RecursiveApply.rdiv(v₃, 2)
FT = Spaces.undertype(space)
a⁻ RecursiveApply.rmul(v₃, FT(0.5))
end

Base.@propagate_inbounds function stencil_left_boundary(
Expand Down Expand Up @@ -1916,7 +1922,8 @@ Base.@propagate_inbounds function stencil_interior(
getidx(space, velocity, loc, idx, hidx),
Geometry.LocalGeometry(space, idx, hidx),
)
∂θ₃ = RecursiveApply.rdiv(θ⁺ θ⁻, 2)
FT = Spaces.undertype(space)
∂θ₃ = RecursiveApply.rmul(θ⁺ θ⁻, FT(0.5))
return ∂θ₃
end
boundary_width(::AdvectionF2F, ::AbstractBoundaryCondition) = 1
Expand Down Expand Up @@ -1986,7 +1993,8 @@ Base.@propagate_inbounds function stencil_interior(
)
∂θ₃⁺ = θ⁺ θ
∂θ₃⁻ = θ θ⁻
return RecursiveApply.rdiv((w³⁺ ∂θ₃⁺) (w³⁻ ∂θ₃⁻), 2)
FT = Spaces.undertype(space)
return RecursiveApply.rmul((w³⁺ ∂θ₃⁺) (w³⁻ ∂θ₃⁻), FT(0.5))
end

boundary_width(::AdvectionC2C, ::AbstractBoundaryCondition) = 1
Expand Down Expand Up @@ -2014,7 +2022,8 @@ Base.@propagate_inbounds function stencil_left_boundary(
)
∂θ₃⁺ = θ⁺ θ
∂θ₃⁻ = 2 θ⁻)
return RecursiveApply.rdiv((w³⁺ ∂θ₃⁺) (w³⁻ ∂θ₃⁻), 2)
FT = Spaces.undertype(space)
return RecursiveApply.rmul((w³⁺ ∂θ₃⁺) (w³⁻ ∂θ₃⁻), FT(0.5))
end
Base.@propagate_inbounds function stencil_right_boundary(
::AdvectionC2C,
Expand All @@ -2040,7 +2049,8 @@ Base.@propagate_inbounds function stencil_right_boundary(
)
∂θ₃⁺ = 2 (θ⁺ θ)
∂θ₃⁻ = θ θ⁻
return RecursiveApply.rdiv((w³⁺ ∂θ₃⁺) (w³⁻ ∂θ₃⁻), 2)
FT = Spaces.undertype(space)
return RecursiveApply.rmul((w³⁺ ∂θ₃⁺) (w³⁻ ∂θ₃⁻), FT(0.5))
end

Base.@propagate_inbounds function stencil_left_boundary(
Expand Down
10 changes: 7 additions & 3 deletions src/Operators/numericalflux.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ end
function (fn::RusanovNumericalFlux)(normal, argvals⁻, argvals⁺)
y⁻ = argvals⁻[1]
y⁺ = argvals⁺[1]
Favg =
RecursiveApply.rdiv(fn.fluxfn(argvals⁻...) fn.fluxfn(argvals⁺...), 2)
λ = max(fn.wavespeedfn(argvals⁻...), fn.wavespeedfn(argvals⁺...))
return RecursiveApply.rmap(f -> f' * normal, Favg) / 2) (y⁻ y⁺)
FT = typeof(λ)
Favg = RecursiveApply.rmul(
fn.fluxfn(argvals⁻...) fn.fluxfn(argvals⁺...),
FT(0.5),
)
return RecursiveApply.rmap(f -> f' * normal, Favg)
(FT(0.5) * λ) (y⁻ y⁺)
end


Expand Down
18 changes: 12 additions & 6 deletions src/Operators/operator2stencil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ function stencil_interior(
hidx,
arg,
)
val⁻ = RecursiveApply.rdiv(getidx(space, arg, loc, idx - half, hidx), 2)
val⁺ = RecursiveApply.rdiv(getidx(space, arg, loc, idx + half, hidx), 2)
FT = Spaces.undertype(space)
val⁻ =
RecursiveApply.rmul(getidx(space, arg, loc, idx - half, hidx), FT(0.5))
val⁺ =
RecursiveApply.rmul(getidx(space, arg, loc, idx + half, hidx), FT(0.5))
return StencilCoefs{-half, half}((val⁻, val⁺))
end
function stencil_left_boundary(
Expand Down Expand Up @@ -231,8 +234,9 @@ function stencil_interior(
θ⁻ = getidx(space, arg, loc, idx - 1, hidx)
θ = getidx(space, arg, loc, idx, hidx)
θ⁺ = getidx(space, arg, loc, idx + 1, hidx)
val⁻ = RecursiveApply.rdiv(w³⁻ θ⁻), 2)
val⁺ = RecursiveApply.rdiv(w³⁺ (θ⁺ θ), 2)
FT = Spaces.undertype(space)
val⁻ = RecursiveApply.rmul(w³⁻ θ⁻), FT(0.5))
val⁺ = RecursiveApply.rmul(w³⁺ (θ⁺ θ), FT(0.5))
return StencilCoefs{-half, half}((val⁻, val⁺))
end
# TODO: find out why using Base.@propagate_inbounds blows up compilation time
Expand All @@ -258,7 +262,8 @@ function stencil_left_boundary(
θ = getidx(space, arg, loc, idx, hidx)
θ⁺ = getidx(space, arg, loc, idx + 1, hidx)
val⁻ = w³⁻ θ⁻)
val⁺ = RecursiveApply.rdiv(w³⁺ (θ⁺ θ), 2)
FT = Spaces.undertype(space)
val⁺ = RecursiveApply.rmul(w³⁺ (θ⁺ θ), FT(0.5))
return StencilCoefs{-half, half}((val⁻, val⁺))
end
# TODO: find out why using Base.@propagate_inbounds blows up compilation time
Expand All @@ -283,7 +288,8 @@ function stencil_right_boundary(
θ⁻ = getidx(space, arg, loc, idx - 1, hidx)
θ = getidx(space, arg, loc, idx, hidx)
θ⁺ = getidx(space, bc.val, loc, nothing, hidx)
val⁻ = RecursiveApply.rdiv(w³⁻ θ⁻), 2)
FT = Spaces.undertype(space)
val⁻ = RecursiveApply.rmul(w³⁻ θ⁻), FT(0.5))
val⁺ = w³⁺ (θ⁺ θ)
return StencilCoefs{-half, half}((val⁻, val⁺))
end
Expand Down
48 changes: 24 additions & 24 deletions src/Operators/spectralelement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ function apply_operator(op::Divergence{(1,)}, space, slabidx, arg)
@inbounds for i in 1:Nq
ij = CartesianIndex((i,))
local_geometry = get_local_geometry(space, ij, slabidx)
out[i] = RecursiveApply.rdiv(out[i], local_geometry.J)
out[i] = RecursiveApply.rmul(out[i], local_geometry.invJ)
end
return Field(SArray(out), space)
end
Expand Down Expand Up @@ -777,7 +777,7 @@ Base.@propagate_inbounds function apply_operator(
@inbounds for j in 1:Nq, i in 1:Nq
ij = CartesianIndex((i, j))
local_geometry = get_local_geometry(space, ij, slabidx)
out[i, j] = RecursiveApply.rdiv(out[i, j], local_geometry.J)
out[i, j] = RecursiveApply.rmul(out[i, j], local_geometry.invJ)
end
return Field(SArray(out), space)
end
Expand Down Expand Up @@ -846,7 +846,7 @@ Base.@propagate_inbounds function operator_evaluate(
for k in 1:Nq
DJv = DJv D[j, k] Jv²[i, k, vt]
end
return RecursiveApply.rdiv(DJv, local_geometry.J)
return RecursiveApply.rmul(DJv, local_geometry.invJ)
end

"""
Expand Down Expand Up @@ -1213,7 +1213,7 @@ function apply_operator(op::WeakGradient{(1,)}, space, slabidx, arg)
@inbounds for i in 1:Nq
ij = CartesianIndex((i,))
local_geometry = get_local_geometry(space, ij, slabidx)
W = local_geometry.WJ / local_geometry.J
W = local_geometry.WJ * local_geometry.invJ
Wx = W get_node(space, arg, ij, slabidx)
for ii in 1:Nq
Dᵀ₁Wf = Geometry.Covariant1Vector(D[i, ii]) Wx
Expand All @@ -1223,7 +1223,7 @@ function apply_operator(op::WeakGradient{(1,)}, space, slabidx, arg)
@inbounds for i in 1:Nq
ij = CartesianIndex((i,))
local_geometry = get_local_geometry(space, ij, slabidx)
W = local_geometry.WJ / local_geometry.J
W = local_geometry.WJ * local_geometry.invJ
out[i] = RecursiveApply.rdiv(out[i], W)
end
return Field(SArray(out), space)
Expand All @@ -1242,7 +1242,7 @@ function apply_operator(op::WeakGradient{(1, 2)}, space, slabidx, arg)
@inbounds for j in 1:Nq, i in 1:Nq
ij = CartesianIndex((i, j))
local_geometry = get_local_geometry(space, ij, slabidx)
W = local_geometry.WJ / local_geometry.J
W = local_geometry.WJ * local_geometry.invJ
Wx = W get_node(space, arg, ij, slabidx)
for ii in 1:Nq
Dᵀ₁Wf = Geometry.Covariant12Vector(D[i, ii], zero(eltype(D))) Wx
Expand All @@ -1256,7 +1256,7 @@ function apply_operator(op::WeakGradient{(1, 2)}, space, slabidx, arg)
@inbounds for j in 1:Nq, i in 1:Nq
ij = CartesianIndex((i, j))
local_geometry = get_local_geometry(space, ij, slabidx)
W = local_geometry.WJ / local_geometry.J
W = local_geometry.WJ * local_geometry.invJ
out[i, j] = RecursiveApply.rdiv(out[i, j], W)
end
return Field(SArray(out), space)
Expand Down Expand Up @@ -1287,7 +1287,7 @@ Base.@propagate_inbounds function operator_fill_shmem!(
)
vt = threadIdx().z
local_geometry = get_local_geometry(space, ij, slabidx)
W = local_geometry.WJ / local_geometry.J
W = local_geometry.WJ * local_geometry.invJ
i, j = ij.I
Wf[i, j, vt] = W arg
end
Expand All @@ -1308,7 +1308,7 @@ Base.@propagate_inbounds function operator_evaluate(
D = Quadratures.differentiation_matrix(FT, QS)

local_geometry = get_local_geometry(space, ij, slabidx)
W = local_geometry.WJ / local_geometry.J
W = local_geometry.WJ * local_geometry.invJ

Dᵀ₁Wf = D[1, i] Wf[1, j, vt]
Dᵀ₂Wf = D[1, j] Wf[i, 1, vt]
Expand Down Expand Up @@ -1423,7 +1423,7 @@ function apply_operator(op::Curl{(1,)}, space, slabidx, arg)
@inbounds for i in 1:Nq
ij = CartesianIndex((i,))
local_geometry = get_local_geometry(space, ij, slabidx)
out[i] = RecursiveApply.rdiv(out[i], local_geometry.J)
out[i] = RecursiveApply.rmul(out[i], local_geometry.invJ)
end
return Field(SArray(out), space)
end
Expand Down Expand Up @@ -1511,7 +1511,7 @@ Base.@propagate_inbounds function operator_evaluate(
D₂v₁ = D₂v₁ D[j, k] v₁[i, k, vt]
end
return Geometry.Contravariant3Vector(
RecursiveApply.rdiv(D₁v₂ D₂v₁, local_geometry.J),
RecursiveApply.rmul(D₁v₂ D₂v₁, local_geometry.invJ),
)
elseif length(work) == 1
(v₃,) = work
Expand All @@ -1522,8 +1522,8 @@ Base.@propagate_inbounds function operator_evaluate(
D₂v₃ = D₂v₃ D[j, k] v₃[i, k, vt]
end
return Geometry.Contravariant12Vector(
RecursiveApply.rdiv(D₂v₃, local_geometry.J),
(RecursiveApply.rdiv(D₁v₃, local_geometry.J)),
RecursiveApply.rmul(D₂v₃, local_geometry.invJ),
(RecursiveApply.rmul(D₁v₃, local_geometry.invJ)),
)
else
v₁, v₂, v₃ = work
Expand All @@ -1538,9 +1538,9 @@ Base.@propagate_inbounds function operator_evaluate(
D₂v₃ = D₂v₃ D[j, k] v₃[i, k, vt]
end
return Geometry.Contravariant123Vector(
RecursiveApply.rdiv(D₂v₃, local_geometry.J),
(RecursiveApply.rdiv(D₁v₃, local_geometry.J)),
RecursiveApply.rdiv(D₁v₂ D₂v₁, local_geometry.J),
RecursiveApply.rmul(D₂v₃, local_geometry.invJ),
(RecursiveApply.rmul(D₁v₃, local_geometry.invJ)),
RecursiveApply.rmul(D₁v₂ D₂v₁, local_geometry.invJ),
)
end
end
Expand Down Expand Up @@ -1621,7 +1621,7 @@ function apply_operator(op::Curl{(1, 2)}, space, slabidx, arg)
@inbounds for j in 1:Nq, i in 1:Nq
ij = CartesianIndex((i, j))
local_geometry = get_local_geometry(space, ij, slabidx)
out[i, j] = RecursiveApply.rdiv(out[i, j], local_geometry.J)
out[i, j] = RecursiveApply.rmul(out[i, j], local_geometry.invJ)
end
return Field(SArray(out), space)
end
Expand Down Expand Up @@ -1684,7 +1684,7 @@ function apply_operator(op::WeakCurl{(1,)}, space, slabidx, arg)
ij = CartesianIndex((i,))
local_geometry = get_local_geometry(space, ij, slabidx)
v = get_node(space, arg, ij, slabidx)
W = local_geometry.WJ / local_geometry.J
W = local_geometry.WJ * local_geometry.invJ
Wv₃ = W Geometry.covariant3(v, local_geometry)
for ii in 1:Nq
Dᵀ₁Wv₃ = D[i, ii] Wv₃
Expand All @@ -1696,7 +1696,7 @@ function apply_operator(op::WeakCurl{(1,)}, space, slabidx, arg)
ij = CartesianIndex((i,))
local_geometry = get_local_geometry(space, ij, slabidx)
v = get_node(space, arg, ij, slabidx)
W = local_geometry.WJ / local_geometry.J
W = local_geometry.WJ * local_geometry.invJ
Wv₂ = W Geometry.covariant2(v, local_geometry)
for ii in 1:Nq
Dᵀ₁Wv₂ = D[i, ii] Wv₂
Expand All @@ -1708,7 +1708,7 @@ function apply_operator(op::WeakCurl{(1,)}, space, slabidx, arg)
ij = CartesianIndex((i,))
local_geometry = get_local_geometry(space, ij, slabidx)
v = get_node(space, arg, ij, slabidx)
W = local_geometry.WJ / local_geometry.J
W = local_geometry.WJ * local_geometry.invJ
Wv₃ = W Geometry.covariant3(v, local_geometry)
Wv₂ = W Geometry.covariant2(v, local_geometry)
for ii in 1:Nq
Expand Down Expand Up @@ -1745,7 +1745,7 @@ function apply_operator(op::WeakCurl{(1, 2)}, space, slabidx, arg)
ij = CartesianIndex((i, j))
local_geometry = get_local_geometry(space, ij, slabidx)
v = get_node(space, arg, ij, slabidx)
W = local_geometry.WJ / local_geometry.J
W = local_geometry.WJ * local_geometry.invJ
Wv₁ = W Geometry.covariant1(v, local_geometry)
for jj in 1:Nq
Dᵀ₂Wv₁ = D[j, jj] Wv₁
Expand All @@ -1764,7 +1764,7 @@ function apply_operator(op::WeakCurl{(1, 2)}, space, slabidx, arg)
ij = CartesianIndex((i, j))
local_geometry = get_local_geometry(space, ij, slabidx)
v = get_node(space, arg, ij, slabidx)
W = local_geometry.WJ / local_geometry.J
W = local_geometry.WJ * local_geometry.invJ
Wv₃ = W Geometry.covariant3(v, local_geometry)
for ii in 1:Nq
Dᵀ₁Wv₃ = D[i, ii] Wv₃
Expand All @@ -1784,7 +1784,7 @@ function apply_operator(op::WeakCurl{(1, 2)}, space, slabidx, arg)
ij = CartesianIndex((i, j))
local_geometry = get_local_geometry(space, ij, slabidx)
v = get_node(space, arg, ij, slabidx)
W = local_geometry.WJ / local_geometry.J
W = local_geometry.WJ * local_geometry.invJ
Wv₁ = W Geometry.covariant1(v, local_geometry)
Wv₂ = W Geometry.covariant2(v, local_geometry)
Wv₃ = W Geometry.covariant3(v, local_geometry)
Expand Down Expand Up @@ -1862,7 +1862,7 @@ Base.@propagate_inbounds function operator_fill_shmem!(
vt = threadIdx().z
i, j = ij.I
local_geometry = get_local_geometry(space, ij, slabidx)
W = local_geometry.WJ / local_geometry.J
W = local_geometry.WJ * local_geometry.invJ
RT = operator_return_eltype(op, typeof(arg))
if RT <: Geometry.Contravariant3Vector
Wv₁, Wv₂ = work
Expand Down
3 changes: 2 additions & 1 deletion src/Remapping/interpolate_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function interpolate_slab_level(
end
f_lo = interpolate_slab(field, Fields.SlabIndex(v_lo, h), Is)
f_hi = interpolate_slab(field, Fields.SlabIndex(v_hi, h), Is)
return ((1 - ξ3) * f_lo + (1 + ξ3) * f_hi) / 2
FT = Spaces.undertype(axes(field))
return FT(0.5) * ((1 - ξ3) * f_lo + (1 + ξ3) * f_hi)
end

"""
Expand Down
Loading

0 comments on commit d0a2b82

Please sign in to comment.