Skip to content

Commit

Permalink
Define CommonSpaces module
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Nov 12, 2024
1 parent 4c1368d commit 3257f4b
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 6 deletions.
20 changes: 14 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ ClimaCore.jl Release Notes
main
-------

- We've added new convenience constructors for spaces PR [2082](https://github.com/CliMA/ClimaCore.jl/pull/2082). Here are links to the new constructors:
- [ExtrudedCubedSphereSpace]()
- [CubedSphereSpace]()
- [ColumnSpace]()
- [Box3DSpace]()
- [SliceXZSpace]()
- [RectangleXYSpace]()

- We've added new convenience constructors for grids PR [1848](https://github.com/CliMA/ClimaCore.jl/pull/1848). Here are links to the new constructors:
- [ExtrudedCubedSphereGrid]()
- [CubedSphereGrid]()
- [ColumnGrid]()
- [Box3DGrid]()
- [SliceXZGrid]()
- [RectangleXYGrid]()
- [ExtrudedCubedSphereGrid](https://github.com/CliMA/ClimaCore.jl/blob/cbb193042fac3b4bef33251fbc0f232427bfe506/src/CommonGrids/CommonGrids.jl#L85-L144)
- [CubedSphereGrid](https://github.com/CliMA/ClimaCore.jl/blob/cbb193042fac3b4bef33251fbc0f232427bfe506/src/CommonGrids/CommonGrids.jl#L200-L235)
- [ColumnGrid](https://github.com/CliMA/ClimaCore.jl/blob/cbb193042fac3b4bef33251fbc0f232427bfe506/src/CommonGrids/CommonGrids.jl#L259-L281)
- [Box3DGrid](https://github.com/CliMA/ClimaCore.jl/blob/cbb193042fac3b4bef33251fbc0f232427bfe506/src/CommonGrids/CommonGrids.jl#L303-L378)
- [SliceXZGrid](https://github.com/CliMA/ClimaCore.jl/blob/cbb193042fac3b4bef33251fbc0f232427bfe506/src/CommonGrids/CommonGrids.jl#L441-L498)
- [RectangleXYGrid](https://github.com/CliMA/ClimaCore.jl/blob/cbb193042fac3b4bef33251fbc0f232427bfe506/src/CommonGrids/CommonGrids.jl#L547-L602)

- A `strict = true` keyword was added to `rcompare`, which checks that the types match. If `strict = false`, then `rcompare` will return `true` for `FieldVector`s and `NamedTuple`s with the same properties but permuted order. For example:
- `rcompare((;a=1,b=2), (;b=2,a=1); strict = true)` will return `false` and
Expand Down
12 changes: 12 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@ Spaces.SpectralElementSpaceSlab
Spaces.node_horizontal_length_scale
```

## CommonSpaces

```@docs
CommonSpaces
CommonSpaces.ExtrudedCubedSphereSpace
CommonSpaces.CubedSphereSpace
CommonSpaces.ColumnSpace
CommonSpaces.Box3DSpace
CommonSpaces.SliceXZSpace
CommonSpaces.RectangleXYSpace
```

### Quadratures


Expand Down
1 change: 1 addition & 0 deletions src/ClimaCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ include("Limiters/Limiters.jl")
include("InputOutput/InputOutput.jl")
include("Remapping/Remapping.jl")
include("CommonGrids/CommonGrids.jl")
include("CommonSpaces/CommonSpaces.jl")

include("deprecated.jl")

Expand Down
105 changes: 105 additions & 0 deletions src/CommonSpaces/CommonSpaces.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
"""
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

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.
"""
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.
"""
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.
"""
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.
"""
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.
"""
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.
"""
function RectangleXYSpace end
RectangleXYSpace(; kwargs...) = RectangleXYSpace(Float64; kwargs...)
RectangleXYSpace(::Type{FT}; kwargs...) where {FT} =
Spaces.SpectralElementSpace2D(RectangleXYGrid(FT; kwargs...))

end # module
137 changes: 137 additions & 0 deletions test/CommonSpaces/unit_common_spaces.jl
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

0 comments on commit 3257f4b

Please sign in to comment.