-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Remove dependency of Oceananigans on OrthogonalSphericalShellGrids #47
Open
simone-silvestri
wants to merge
4
commits into
main
Choose a base branch
from
ss/test-vector-rotation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# This test is copied from the Cubed Sphere test in Oceananigans.jl (https://github.com/CliMA/Oceananigans.jl/) at: | ||
# https://github.com/CliMA/Oceananigans.jl/blob/main/test/test_cubed_spheres.jl | ||
|
||
using Oceananigans.Operators: intrinsic_vector, extrinsic_vector | ||
|
||
# To be used in the test below as `KernelFunctionOperation`s | ||
@inline intrinsic_vector_x_component(i, j, k, grid, uₑ, vₑ) = | ||
@inbounds intrinsic_vector(i, j, k, grid, uₑ, vₑ)[1] | ||
|
||
@inline intrinsic_vector_y_component(i, j, k, grid, uₑ, vₑ) = | ||
@inbounds intrinsic_vector(i, j, k, grid, uₑ, vₑ)[2] | ||
|
||
@inline extrinsic_vector_x_component(i, j, k, grid, uᵢ, vᵢ) = | ||
@inbounds extrinsic_vector(i, j, k, grid, uᵢ, vᵢ)[1] | ||
|
||
@inline extrinsic_vector_y_component(i, j, k, grid, uᵢ, vᵢ) = | ||
@inbounds extrinsic_vector(i, j, k, grid, uᵢ, vᵢ)[2] | ||
|
||
function kinetic_energy(u, v) | ||
ke = Field(0.5 * (u * u + v * v)) | ||
return compute!(ke) | ||
end | ||
|
||
function test_vector_rotation(grid) | ||
u = XFaceField(grid) | ||
v = YFaceField(grid) | ||
|
||
# Purely longitudinal flow in the extrinsic coordinate system | ||
set!(u, 1) | ||
set!(v, 0) | ||
|
||
# Convert it to an "Instrinsic" reference frame | ||
uᵢ = KernelFunctionOperation{Face, Center, Center}(intrinsic_vector_x_component, grid, u, v) | ||
vᵢ = KernelFunctionOperation{Center, Face, Center}(intrinsic_vector_y_component, grid, u, v) | ||
|
||
uᵢ = compute!(Field(uᵢ)) | ||
vᵢ = compute!(Field(vᵢ)) | ||
|
||
# The extrema of u and v, as well as their mean value should | ||
# be equivalent on an "intrinsic" frame | ||
@test maximum(uᵢ) ≈ maximum(vᵢ) | ||
@test minimum(uᵢ) ≈ minimum(vᵢ) | ||
@test mean(uᵢ) ≈ mean(vᵢ) | ||
@test mean(uᵢ) > 0 # The mean value should be positive | ||
|
||
# Kinetic energy should remain the same | ||
KE = kinetic_energy(uᵢ, vᵢ) | ||
@test all(on_architecture(CPU(), interior(KE)) .≈ 0.5) | ||
|
||
# Convert it back to a purely zonal velocity (vₑ == 0) | ||
uₑ = KernelFunctionOperation{Face, Center, Center}(extrinsic_vector_x_component, grid, uᵢ, vᵢ) | ||
vₑ = KernelFunctionOperation{Center, Face, Center}(extrinsic_vector_y_component, grid, uᵢ, vᵢ) | ||
|
||
uₑ = compute!(Field(uₑ)) | ||
vₑ = compute!(Field(vₑ)) | ||
|
||
# Make sure that the flow was converted back to a | ||
# purely zonal flow in the extrensic frame (v ≈ 0) | ||
@test all(on_architecture(CPU(), interior(vₑ)) .≈ 0) | ||
@test all(on_architecture(CPU(), interior(uₑ)) .≈ 1) | ||
|
||
# Purely meridional flow in the extrinsic coordinate system | ||
set!(u, 0) | ||
set!(v, 1) | ||
|
||
# Convert it to an "Instrinsic" reference frame | ||
uᵢ = KernelFunctionOperation{Face, Center, Center}(intrinsic_vector_x_component, grid, u, v) | ||
vᵢ = KernelFunctionOperation{Center, Face, Center}(intrinsic_vector_y_component, grid, u, v) | ||
|
||
uᵢ = compute!(Field(uᵢ)) | ||
vᵢ = compute!(Field(vᵢ)) | ||
|
||
# The extrema of u and v, as well as their mean value should | ||
# be equivalent on an "intrinsic" frame | ||
@test maximum(uᵢ) ≈ maximum(vᵢ) | ||
@test minimum(uᵢ) ≈ minimum(vᵢ) | ||
@test mean(uᵢ) ≈ mean(vᵢ) | ||
@test mean(vᵢ) > 0 # The mean value should be positive | ||
|
||
# Kinetic energy should remain the same | ||
KE = kinetic_energy(uᵢ, vᵢ) | ||
@test all(on_architecture(CPU(), interior(KE)) .≈ 0.5) | ||
|
||
# Convert it back to a purely zonal velocity (vₑ == 0) | ||
uₑ = KernelFunctionOperation{Face, Center, Center}(extrinsic_vector_x_component, grid, uᵢ, vᵢ) | ||
vₑ = KernelFunctionOperation{Center, Face, Center}(extrinsic_vector_y_component, grid, uᵢ, vᵢ) | ||
|
||
uₑ = compute!(Field(uₑ)) | ||
vₑ = compute!(Field(vₑ)) | ||
|
||
# Make sure that the flow was converted back to a | ||
# purely zonal flow in the extrensic frame (v ≈ 0) | ||
@test all(on_architecture(CPU(), interior(vₑ)) .≈ 1) | ||
@test all(on_architecture(CPU(), interior(uₑ)) .≈ 0) | ||
|
||
# Mixed zonal and meridional flow. | ||
set!(u, 0.5) | ||
set!(v, 0.5) | ||
|
||
# Convert it to an "Instrinsic" reference frame | ||
uᵢ = KernelFunctionOperation{Face, Center, Center}(intrinsic_vector_x_component, grid, u, v) | ||
vᵢ = KernelFunctionOperation{Center, Face, Center}(intrinsic_vector_y_component, grid, u, v) | ||
|
||
uᵢ = compute!(Field(uᵢ)) | ||
vᵢ = compute!(Field(vᵢ)) | ||
|
||
# The extrema of u and v, as well as their mean value should | ||
# be equivalent on an "intrinsic" frame | ||
@test maximum(uᵢ) ≈ maximum(vᵢ) | ||
@test minimum(uᵢ) ≈ minimum(vᵢ) | ||
@test mean(uᵢ) ≈ mean(vᵢ) | ||
@test mean(vᵢ) > 0 # The mean value should be positive | ||
|
||
# Kinetic energy should remain the same | ||
KE = kinetic_energy(uᵢ, vᵢ) | ||
@test all(on_architecture(CPU(), interior(KE)) .≈ 0.25) | ||
|
||
# Convert it back to a purely zonal velocity (vₑ == 0) | ||
uₑ = KernelFunctionOperation{Face, Center, Center}(extrinsic_vector_x_component, grid, uᵢ, vᵢ) | ||
vₑ = KernelFunctionOperation{Center, Face, Center}(extrinsic_vector_y_component, grid, uᵢ, vᵢ) | ||
|
||
uₑ = compute!(Field(uₑ)) | ||
vₑ = compute!(Field(vₑ)) | ||
|
||
# Make sure that the flow was converted back to a | ||
# purely zonal flow in the extrensic frame (v ≈ 0) | ||
@test all(on_architecture(CPU(), interior(vₑ)) .≈ 0.5) | ||
@test all(on_architecture(CPU(), interior(uₑ)) .≈ 0.5) | ||
end | ||
|
||
@testset "Conversion from Intrinsic to Extrinsic reference frame" begin | ||
@info " Testing the conversion of a vector between the Intrinsic and Extrinsic reference frame" | ||
grid = TripolarGrid(size = (20, 20, 1), z = (0, 1)) | ||
|
||
test_vector_rotation(grid) | ||
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. It'd be nice to somehow grab the implementation from Oceananigans, but I'm not sure how to do that if the codes live in different repos as we have designed this code. |
||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
All of these tests belong in Oceananigans. Also, they are not specific to the TripolarGrid.