-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76dac21
commit 73b9ad8
Showing
5 changed files
with
363 additions
and
7 deletions.
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
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,199 @@ | ||
""" | ||
CommonSpaces | ||
CommonSpaces contains convenience constructors for common | ||
spaces, which builds off of [`CommonGrids`](@ref) and | ||
(when appropriate) requires an additional argument, | ||
`staggering::Staggering` to construct the desired | ||
space. | ||
""" | ||
module CommonSpaces | ||
|
||
export ExtrudedCubedSphereSpace, | ||
CubedSphereSpace, ColumnSpace, Box3DSpace, SliceXZSpace, RectangleXYSpace | ||
|
||
export Grids | ||
import ..Grids | ||
import ..Grids: Staggering | ||
import ..Spaces | ||
import ..CommonGrids | ||
import ..CommonGrids: | ||
ExtrudedCubedSphereGrid, | ||
CubedSphereGrid, | ||
ColumnGrid, | ||
Box3DGrid, | ||
SliceXZGrid, | ||
RectangleXYGrid | ||
|
||
""" | ||
ExtrudedCubedSphereSpace(args...; staggering::Staggering, kwargs...) | ||
Calls [`CommonGrids.ExtrudedCubedSphereGrid`](@ref), | ||
with the args, kwargs, plus an additional `staggering::Staggering` | ||
keyword, to construct a cell center or cell face space. | ||
# Example usage | ||
```julia | ||
using ClimaCore.CommonSpaces | ||
space = ExtrudedCubedSphereSpace(; | ||
z_elem = 10, | ||
z_min = 0, | ||
z_max = 1, | ||
radius = 10, | ||
h_elem = 10, | ||
n_quad_points = 4, | ||
staggering = Grids.CellCenter() | ||
) | ||
``` | ||
""" | ||
function ExtrudedCubedSphereSpace end | ||
|
||
ExtrudedCubedSphereSpace(; kwargs...) = | ||
ExtrudedCubedSphereSpace(Float64; kwargs...) | ||
ExtrudedCubedSphereSpace( | ||
::Type{FT}; | ||
staggering::Staggering, | ||
kwargs..., | ||
) where {FT} = Spaces.ExtrudedFiniteDifferenceSpace( | ||
ExtrudedCubedSphereGrid(FT; kwargs...), | ||
staggering, | ||
) | ||
|
||
""" | ||
CubedSphereSpace(args...; kwargs...) | ||
Calls [`CommonGrids.CubedSphereGrid`](@ref), | ||
with the args, kwargs. | ||
# Example usage | ||
```julia | ||
using ClimaCore.CommonSpaces | ||
space = CubedSphereSpace(; | ||
radius = 10, | ||
n_quad_points = 4, | ||
h_elem = 10, | ||
) | ||
``` | ||
""" | ||
function CubedSphereSpace end | ||
CubedSphereSpace(; kwargs...) = CubedSphereSpace(Float64; kwargs...) | ||
CubedSphereSpace(::Type{FT}; kwargs...) where {FT} = | ||
Spaces.SpectralElementSpace2D(CubedSphereGrid(FT; kwargs...)) | ||
|
||
""" | ||
ColumnSpace(args...; kwargs...) | ||
Calls [`CommonGrids.ColumnGrid`](@ref), | ||
with the args, kwargs, plus an additional `staggering::Staggering` | ||
keyword, to construct a cell center or cell face space. | ||
# Example usage | ||
```julia | ||
using ClimaCore.CommonSpaces | ||
space = ColumnSpace(; | ||
z_elem = 10, | ||
z_min = 0, | ||
z_max = 10, | ||
staggering = Grids.CellCenter() | ||
) | ||
``` | ||
""" | ||
function ColumnSpace end | ||
ColumnSpace(; kwargs...) = ColumnSpace(Float64; kwargs...) | ||
ColumnSpace(::Type{FT}; staggering::Staggering, kwargs...) where {FT} = | ||
Spaces.FiniteDifferenceSpace(ColumnGrid(FT; kwargs...), staggering) | ||
|
||
""" | ||
Box3DSpace(args...; kwargs...) | ||
Calls [`CommonGrids.Box3DGrid`](@ref), | ||
with the args, kwargs, plus an additional `staggering::Staggering` | ||
keyword, to construct a cell center or cell face space. | ||
# Example usage | ||
```julia | ||
using ClimaCore.CommonSpaces | ||
space = Box3DSpace(; | ||
z_elem = 10, | ||
x_min = 0, | ||
x_max = 1, | ||
y_min = 0, | ||
y_max = 1, | ||
z_min = 0, | ||
z_max = 10, | ||
periodic_x = false, | ||
periodic_y = false, | ||
n_quad_points = 4, | ||
x_elem = 3, | ||
y_elem = 4, | ||
staggering = Grids.CellCenter() | ||
) | ||
``` | ||
""" | ||
function Box3DSpace end | ||
Box3DSpace(; kwargs...) = Box3DSpace(Float64; kwargs...) | ||
Box3DSpace(::Type{FT}; staggering::Staggering, kwargs...) where {FT} = | ||
Spaces.ExtrudedFiniteDifferenceSpace(Box3DGrid(FT; kwargs...), staggering) | ||
|
||
""" | ||
SliceXZSpace(args...; kwargs...) | ||
Calls [`CommonGrids.SliceXZGrid`](@ref), | ||
with the args, kwargs, plus an additional `staggering::Staggering` | ||
keyword, to construct a cell center or cell face space. | ||
# Example usage | ||
```julia | ||
using ClimaCore.CommonSpaces | ||
space = SliceXZSpace(; | ||
z_elem = 10, | ||
x_min = 0, | ||
x_max = 1, | ||
z_min = 0, | ||
z_max = 1, | ||
periodic_x = false, | ||
n_quad_points = 4, | ||
x_elem = 4, | ||
staggering = Grids.CellCenter() | ||
) | ||
``` | ||
""" | ||
function SliceXZSpace end | ||
SliceXZSpace(; kwargs...) = SliceXZSpace(Float64; kwargs...) | ||
SliceXZSpace(::Type{FT}; staggering::Staggering, kwargs...) where {FT} = | ||
Spaces.ExtrudedFiniteDifferenceSpace(SliceXZGrid(FT; kwargs...), staggering) | ||
|
||
""" | ||
RectangleXYSpace(args...; kwargs...) | ||
Calls [`CommonGrids.RectangleXYGrid`](@ref), | ||
with the args, kwargs. | ||
# Example usage | ||
```julia | ||
using ClimaCore.CommonSpaces | ||
space = RectangleXYSpace(; | ||
x_min = 0, | ||
x_max = 1, | ||
y_min = 0, | ||
y_max = 1, | ||
periodic_x = false, | ||
periodic_y = false, | ||
n_quad_points = 4, | ||
x_elem = 3, | ||
y_elem = 4, | ||
) | ||
``` | ||
""" | ||
function RectangleXYSpace end | ||
RectangleXYSpace(; kwargs...) = RectangleXYSpace(Float64; kwargs...) | ||
RectangleXYSpace(::Type{FT}; kwargs...) where {FT} = | ||
Spaces.SpectralElementSpace2D(RectangleXYGrid(FT; kwargs...)) | ||
|
||
end # module |
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,137 @@ | ||
#= | ||
julia --project | ||
using Revise; include(joinpath("test", "CommonSpaces", "unit_common_spaces.jl")) | ||
=# | ||
import ClimaComms | ||
ClimaComms.@import_required_backends | ||
using ClimaCore.CommonSpaces | ||
using ClimaCore: | ||
Geometry, | ||
Hypsography, | ||
Fields, | ||
Spaces, | ||
Grids, | ||
Topologies, | ||
Meshes, | ||
DataLayouts | ||
using Test | ||
|
||
@testset "Convenience constructors" begin | ||
function warp_surface(coord) | ||
# sin²(x) form ground elevation | ||
x = Geometry.component(coord, 1) | ||
FT = eltype(x) | ||
hc = FT(500.0) | ||
h = hc * FT(sin(π * x / 25000)^2) | ||
return h | ||
end | ||
|
||
space = ExtrudedCubedSphereSpace(; | ||
z_elem = 10, | ||
z_min = 0, | ||
z_max = 1, | ||
radius = 10, | ||
h_elem = 10, | ||
n_quad_points = 4, | ||
horizontal_layout_type = DataLayouts.IJHF, | ||
staggering = Grids.CellCenter(), | ||
) | ||
grid = Spaces.grid(space) | ||
@test grid isa Grids.ExtrudedFiniteDifferenceGrid | ||
@test grid.horizontal_grid isa Grids.SpectralElementGrid2D | ||
@test Grids.topology(grid.horizontal_grid).mesh isa | ||
Meshes.EquiangularCubedSphere | ||
|
||
function hypsography_fun(h_grid, z_grid) | ||
h_space = Spaces.SpectralElementSpace2D(h_grid) | ||
cf = Fields.coordinate_field(h_space) | ||
warp_fn = warp_surface # closure | ||
z_surface = map(cf) do coord | ||
Geometry.ZPoint(warp_fn(coord)) | ||
end | ||
Hypsography.LinearAdaption(z_surface) | ||
end | ||
|
||
space = ExtrudedCubedSphereSpace(; | ||
z_elem = 10, | ||
z_min = 0, | ||
z_max = 1, | ||
radius = 10, | ||
h_elem = 10, | ||
n_quad_points = 4, | ||
hypsography_fun, | ||
staggering = Grids.CellCenter(), | ||
) | ||
grid = Spaces.grid(space) | ||
@test grid isa Grids.ExtrudedFiniteDifferenceGrid | ||
@test grid.horizontal_grid isa Grids.SpectralElementGrid2D | ||
@test Grids.topology(grid.horizontal_grid).mesh isa | ||
Meshes.EquiangularCubedSphere | ||
@test Grids.topology(grid.horizontal_grid).mesh isa | ||
Meshes.EquiangularCubedSphere | ||
|
||
space = CubedSphereSpace(; radius = 10, n_quad_points = 4, h_elem = 10) | ||
grid = Spaces.grid(space) | ||
@test grid isa Grids.SpectralElementGrid2D | ||
@test Grids.topology(grid).mesh isa Meshes.EquiangularCubedSphere | ||
|
||
space = ColumnSpace(; | ||
z_elem = 10, | ||
z_min = 0, | ||
z_max = 1, | ||
staggering = Grids.CellCenter(), | ||
) | ||
grid = Spaces.grid(space) | ||
@test grid isa Grids.FiniteDifferenceGrid | ||
|
||
space = Box3DSpace(; | ||
z_elem = 10, | ||
x_min = 0, | ||
x_max = 1, | ||
y_min = 0, | ||
y_max = 1, | ||
z_min = 0, | ||
z_max = 10, | ||
periodic_x = false, | ||
periodic_y = false, | ||
n_quad_points = 4, | ||
x_elem = 3, | ||
y_elem = 4, | ||
staggering = Grids.CellCenter(), | ||
) | ||
grid = Spaces.grid(space) | ||
@test grid isa Grids.ExtrudedFiniteDifferenceGrid | ||
@test grid.horizontal_grid isa Grids.SpectralElementGrid2D | ||
@test Grids.topology(grid.horizontal_grid).mesh isa Meshes.RectilinearMesh | ||
|
||
space = SliceXZSpace(; | ||
z_elem = 10, | ||
x_min = 0, | ||
x_max = 1, | ||
z_min = 0, | ||
z_max = 1, | ||
periodic_x = false, | ||
n_quad_points = 4, | ||
x_elem = 4, | ||
staggering = Grids.CellCenter(), | ||
) | ||
grid = Spaces.grid(space) | ||
@test grid isa Grids.ExtrudedFiniteDifferenceGrid | ||
@test grid.horizontal_grid isa Grids.SpectralElementGrid1D | ||
@test Grids.topology(grid.horizontal_grid).mesh isa Meshes.IntervalMesh | ||
|
||
space = RectangleXYSpace(; | ||
x_min = 0, | ||
x_max = 1, | ||
y_min = 0, | ||
y_max = 1, | ||
periodic_x = false, | ||
periodic_y = false, | ||
n_quad_points = 4, | ||
x_elem = 3, | ||
y_elem = 4, | ||
) | ||
grid = Spaces.grid(space) | ||
@test grid isa Grids.SpectralElementGrid2D | ||
@test Grids.topology(grid).mesh isa Meshes.RectilinearMesh | ||
end |