Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit a88d309

Browse files
committed
Add inverse cube sphere warping
1 parent 8c313a2 commit a88d309

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/gridgenerators.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,26 @@ function cubespherewarp(point)
278278
return point
279279
end
280280

281+
function cubesphereunwarp(point)
282+
# Put the points in reverse magnitude order
283+
p = sortperm(abs.(point))
284+
point = point[p]
285+
286+
# Convert to angles
287+
ξ = 4atan(point[2]/point[3])/π
288+
η = 4atan(point[1]/point[3])/π
289+
R = sign(point[3])*hypot(point...)
290+
291+
x = R
292+
y = R * ξ
293+
z = R * η
294+
295+
# Compute the new points and unpermute
296+
point = SVector(z, y, x)[sortperm(p)]
297+
298+
return point
299+
end
300+
281301
function cubedshellconnectivity(referencecell::LobattoCell,
282302
R::Real,
283303
ncells::Integer;

test/gridgenerators.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,18 @@ end
239239
end
240240
end
241241
end
242+
243+
for p in (
244+
SVector(+0.4, -1.00, +0.3),
245+
SVector(+0.5, +1.00, -0.2),
246+
SVector(-0.5, +1.00, +0.2),
247+
SVector(+1.0, -0.70, -0.2),
248+
SVector(-1.0, -0.70, +0.2),
249+
SVector(+0.3, -0.75, -1.0),
250+
SVector(-0.3, -0.75, +1.0),
251+
)
252+
r = Bennu.cubesphereunwarp(p)
253+
= Bennu.cubespherewarp(r)
254+
@test p
255+
end
242256
end

0 commit comments

Comments
 (0)