Skip to content

Commit 5fa652a

Browse files
authored
Try #1487:
2 parents 9c22047 + 5bc3b95 commit 5fa652a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2860
-2426
lines changed

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
1919
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
2020
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
2121
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
22+
Memoize = "c03570c3-d221-55d1-a50c-7939bbd78826"
2223
PkgVersion = "eebad327-c553-4316-9ea0-9fa01ccd7688"
2324
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
2425
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
@@ -28,6 +29,7 @@ Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
2829
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2930
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
3031
UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
32+
WeakValueDicts = "897b6980-f191-5a31-bcb0-bf3c4585e0c1"
3133

3234
[compat]
3335
Adapt = "3"
@@ -43,13 +45,15 @@ GaussQuadrature = "0.5"
4345
GilbertCurves = "0.1"
4446
HDF5 = "0.16, 0.17"
4547
IntervalSets = "0.5, 0.6, 0.7"
48+
Memoize = "0.4"
4649
PkgVersion = "0.1, 0.2, 0.3"
4750
RecursiveArrayTools = "2"
4851
Requires = "1"
4952
RootSolvers = "0.3, 0.4"
5053
Static = "0.4, 0.5, 0.6, 0.7, 0.8"
5154
StaticArrays = "1"
5255
UnPack = "1"
56+
WeakValueDicts = "0.1"
5357
julia = "1.8"
5458

5559
[extras]

docs/src/api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ Spaces.dss_ghost!
219219
Spaces.create_dss_buffer
220220
Spaces.fill_send_buffer!
221221
Spaces.DSSBuffer
222-
Spaces.create_ghost_buffer
223222
Spaces.load_from_recv_buffer!
224223
Spaces.weighted_dss_start!
225224
Spaces.weighted_dss_internal!

examples/hybrid/hybrid3dcs_dss.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ function hybrid3dcubedsphere_dss_profiler(
8585
c = center_initial_condition(ᶜlocal_geometry),
8686
f = face_initial_condition(ᶠlocal_geometry),
8787
)
88-
ghost_buffer = (
89-
c = Spaces.create_ghost_buffer(Y.c),
90-
f = Spaces.create_ghost_buffer(Y.f),
91-
)
88+
ghost_buffer =
89+
(c = Spaces.create_dss_buffer(Y.c), f = Spaces.create_dss_buffer(Y.f))
9290
dss_buffer_f = Spaces.create_dss_buffer(Y.f)
9391
dss_buffer_c = Spaces.create_dss_buffer(Y.c)
9492
nsamples = 10000

src/ClimaCore.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ include("Geometry/Geometry.jl")
1111
include("Domains/Domains.jl")
1212
include("Meshes/Meshes.jl")
1313
include("Topologies/Topologies.jl")
14+
include("Quadratures/Quadratures.jl")
15+
include("Grids/Grids.jl")
1416
include("Spaces/Spaces.jl")
1517
include("Fields/Fields.jl")
1618
include("Operators/Operators.jl")

src/Fields/Fields.jl

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ..slab, ..slab_args, ..column, ..column_args, ..level
55
import ..DataLayouts: DataLayouts, AbstractData, DataStyle
66
import ..Domains
77
import ..Topologies
8+
import ..Grids: ColumnIndex
89
import ..Spaces: Spaces, AbstractSpace, AbstractPointSpace
910
import ..Geometry: Geometry, Cartesian12Vector
1011
import ..Utilities: PlusHalf, half
@@ -38,13 +39,6 @@ Field(::Type{T}, space::S) where {T, S <: AbstractSpace} =
3839

3940
ClimaComms.context(field::Field) = ClimaComms.context(axes(field))
4041

41-
ClimaComms.context(space::Spaces.ExtrudedFiniteDifferenceSpace) =
42-
ClimaComms.context(Spaces.horizontal_space(space))
43-
ClimaComms.context(space::Spaces.SpectralElementSpace2D) =
44-
ClimaComms.context(space.topology)
45-
ClimaComms.context(space::S) where {S <: Spaces.AbstractSpace} =
46-
ClimaComms.context(space.topology)
47-
4842
ClimaComms.context(topology::Topologies.Topology2D) = topology.context
4943
ClimaComms.context(topology::T) where {T <: Topologies.AbstractTopology} =
5044
topology.context
@@ -93,11 +87,12 @@ const CenterExtrudedFiniteDifferenceField{V, S} = Field{
9387
} where {V <: AbstractData, S <: Spaces.CenterExtrudedFiniteDifferenceSpace}
9488

9589
# Cubed Sphere Fields
90+
#=
9691
const CubedSphereSpectralElementField2D{V, S} = Field{
9792
V,
9893
S,
9994
} where {V <: AbstractData, S <: Spaces.CubedSphereSpectralElementSpace2D}
100-
95+
=#
10196

10297
Base.propertynames(field::Field) = propertynames(getfield(field, :values))
10398
@inline field_values(field::Field) = getfield(field, :values)
@@ -333,22 +328,12 @@ function interpcoord(elemrange, x::Real)
333328
return z, ξ
334329
end
335330

336-
"""
337-
Spaces.variational_solve!(field)
338-
339-
Divide `field` by the mass matrix.
340-
"""
341-
function Spaces.variational_solve!(field::Field)
342-
Spaces.variational_solve!(field_values(field), axes(field))
343-
return field
344-
end
345-
346331
"""
347332
Spaces.weighted_dss!(f::Field[, ghost_buffer = Spaces.create_dss_buffer(field)])
348333
349334
Apply weighted direct stiffness summation (DSS) to `f`. This operates in-place
350335
(i.e. it modifies the `f`). `ghost_buffer` contains the necessary information
351-
for communication in a distributed setting, see [`Spaces.create_ghost_buffer`](@ref).
336+
for communication in a distributed setting, see [`Spaces.create_dss_buffer`](@ref).
352337
353338
This is a projection operation from the piecewise polynomial space
354339
``\\mathcal{V}_0`` to the continuous space ``\\mathcal{V}_1 = \\mathcal{V}_0
@@ -389,13 +374,6 @@ Spaces.weighted_dss_internal!(field::Field, dss_buffer) =
389374
Spaces.weighted_dss_ghost!(field::Field, dss_buffer) =
390375
Spaces.weighted_dss_ghost!(field_values(field), axes(field), dss_buffer)
391376

392-
"""
393-
Spaces.create_ghost_buffer(field::Field)
394-
395-
Create a buffer for communicating neighbour information of `field`.
396-
"""
397-
Spaces.create_ghost_buffer(field::Field) = Spaces.create_dss_buffer(field)
398-
399377
"""
400378
Spaces.create_dss_buffer(field::Field)
401379
@@ -406,20 +384,6 @@ function Spaces.create_dss_buffer(field::Field)
406384
hspace = Spaces.horizontal_space(space)
407385
Spaces.create_dss_buffer(field_values(field), hspace)
408386
end
409-
# Add definitions for backward compatibility
410-
Spaces.weighted_dss2!(
411-
field::Field,
412-
dss_buffer = Spaces.create_dss_buffer(field),
413-
) = Spaces.weighted_dss!(field, dss_buffer)
414-
415-
Spaces.weighted_dss_start2!(field::Field, ghost_buffer) =
416-
Spaces.weighted_dss_start!(field, ghost_buffer)
417-
418-
Spaces.weighted_dss_internal2!(field::Field, ghost_buffer) =
419-
Spaces.weighted_dss_internal!(field, ghost_buffer)
420-
421-
Spaces.weighted_dss_ghost2!(field, ghost_buffer) =
422-
Spaces.weighted_dss_ghost!(field, ghost_buffer)
423387

424388
Base.@propagate_inbounds function level(
425389
field::Union{

src/Fields/indices.jl

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,3 @@
1-
"""
2-
ColumnIndex(ij,h)
3-
4-
An index into a column of a field. This can be used as an argument to `getindex`
5-
of a `Field`, to return a field on that column.
6-
7-
# Example
8-
```julia
9-
colidx = ColumnIndex((1,1),1)
10-
field[colidx]
11-
```
12-
"""
13-
struct ColumnIndex{N}
14-
ij::NTuple{N, Int}
15-
h::Int
16-
end
171

182
Base.@propagate_inbounds Base.getindex(field::Field, colidx::ColumnIndex) =
193
column(field, colidx)
@@ -145,7 +129,7 @@ bycolumn(
145129
fn,
146130
space::Spaces.ExtrudedFiniteDifferenceSpace,
147131
device::ClimaComms.AbstractCPUDevice,
148-
) = bycolumn(fn, space.horizontal_space, device)
132+
) = bycolumn(fn, Spaces.horizontal_space(space), device)
149133

150134

151135
function bycolumn(fn, space::AbstractSpace, ::ClimaComms.CUDADevice)
@@ -164,7 +148,7 @@ Number of columns in a given space.
164148
ncolumns(field::Field) = ncolumns(axes(field))
165149

166150
ncolumns(space::Spaces.ExtrudedFiniteDifferenceSpace) =
167-
ncolumns(space.horizontal_space)
151+
ncolumns(Spaces.horizontal_space(space))
168152

169153
function ncolumns(space::Spaces.SpectralElementSpace1D)
170154
Nh = Topologies.nlocalelems(space)
@@ -219,7 +203,7 @@ function byslab(
219203
::ClimaComms.CPUSingleThreaded,
220204
space::Spaces.AbstractSpectralElementSpace,
221205
)
222-
Nh = Topologies.nlocalelems(space.topology)::Int
206+
Nh = Topologies.nlocalelems(Spaces.topology(space))::Int
223207
@inbounds for h in 1:Nh
224208
fn(SlabIndex(nothing, h))
225209
end

src/Geometry/localgeometry.jl

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,89 @@ end
5151

5252
undertype(::Type{LocalGeometry{I, C, FT, S}}) where {I, C, FT, S} = FT
5353
undertype(::Type{SurfaceGeometry{FT, N}}) where {FT, N} = FT
54+
55+
56+
function blockmat(
57+
a::Geometry.Axis2Tensor{
58+
FT,
59+
Tuple{Geometry.UAxis, Geometry.Covariant1Axis},
60+
SMatrix{1, 1, FT, 1},
61+
},
62+
b::Geometry.Axis2Tensor{
63+
FT,
64+
Tuple{Geometry.WAxis, Geometry.Covariant3Axis},
65+
SMatrix{1, 1, FT, 1},
66+
},
67+
) where {FT}
68+
A = Geometry.components(a)
69+
B = Geometry.components(b)
70+
Geometry.AxisTensor(
71+
(Geometry.UWAxis(), Geometry.Covariant13Axis()),
72+
SMatrix{2, 2}(A[1, 1], zero(FT), zero(FT), B[1, 1]),
73+
)
74+
end
75+
76+
function blockmat(
77+
a::Geometry.Axis2Tensor{
78+
FT,
79+
Tuple{Geometry.VAxis, Geometry.Covariant2Axis},
80+
SMatrix{1, 1, FT, 1},
81+
},
82+
b::Geometry.Axis2Tensor{
83+
FT,
84+
Tuple{Geometry.WAxis, Geometry.Covariant3Axis},
85+
SMatrix{1, 1, FT, 1},
86+
},
87+
) where {FT}
88+
A = Geometry.components(a)
89+
B = Geometry.components(b)
90+
Geometry.AxisTensor(
91+
(Geometry.VWAxis(), Geometry.Covariant23Axis()),
92+
SMatrix{2, 2}(A[1, 1], zero(FT), zero(FT), B[1, 1]),
93+
)
94+
end
95+
96+
function blockmat(
97+
a::Geometry.Axis2Tensor{
98+
FT,
99+
Tuple{Geometry.UVAxis, Geometry.Covariant12Axis},
100+
SMatrix{2, 2, FT, 4},
101+
},
102+
b::Geometry.Axis2Tensor{
103+
FT,
104+
Tuple{Geometry.WAxis, Geometry.Covariant3Axis},
105+
SMatrix{1, 1, FT, 1},
106+
},
107+
) where {FT}
108+
A = Geometry.components(a)
109+
B = Geometry.components(b)
110+
Geometry.AxisTensor(
111+
(Geometry.UVWAxis(), Geometry.Covariant123Axis()),
112+
SMatrix{3, 3}(
113+
A[1, 1],
114+
A[2, 1],
115+
zero(FT),
116+
A[1, 2],
117+
A[2, 2],
118+
zero(FT),
119+
zero(FT),
120+
zero(FT),
121+
B[1, 1],
122+
),
123+
)
124+
end
125+
126+
function product_geometry(
127+
horizontal_local_geometry::Geometry.LocalGeometry,
128+
vertical_local_geometry::Geometry.LocalGeometry,
129+
)
130+
coordinates = Geometry.product_coordinates(
131+
horizontal_local_geometry.coordinates,
132+
vertical_local_geometry.coordinates,
133+
)
134+
J = horizontal_local_geometry.J * vertical_local_geometry.J
135+
WJ = horizontal_local_geometry.WJ * vertical_local_geometry.WJ
136+
∂x∂ξ =
137+
blockmat(horizontal_local_geometry.∂x∂ξ, vertical_local_geometry.∂x∂ξ)
138+
return Geometry.LocalGeometry(coordinates, J, WJ, ∂x∂ξ)
139+
end

src/Grids/Grids.jl

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
module Grids
2+
3+
import ClimaComms, Adapt, ForwardDiff, LinearAlgebra
4+
import LinearAlgebra: det, norm
5+
import Memoize: @memoize
6+
import WeakValueDicts: WeakValueDict
7+
import ..DataLayouts,
8+
..Domains, ..Meshes, ..Topologies, ..Geometry, ..Quadratures
9+
import ..Utilities: PlusHalf, half
10+
import ..slab, ..column, ..level
11+
12+
using StaticArrays
13+
14+
"""
15+
Grids.AbstractGrid
16+
17+
Grids should define the following
18+
19+
20+
- [`topology`](@ref): the topology of the grid
21+
- [`mesh`](@ref): the mesh of the grid
22+
- [`domain`](@ref): the domain of the grid
23+
- `ClimaComms.context`
24+
- `ClimaComms.device`
25+
26+
- [`local_geometry_data`](@ref): the `DataLayout` object containing the local geometry data information
27+
28+
"""
29+
abstract type AbstractGrid end
30+
31+
32+
"""
33+
Grids.topology(grid::AbstractGrid)
34+
35+
Get the topology of a grid.
36+
"""
37+
function topology end
38+
39+
function vertical_topology end
40+
41+
"""
42+
Grids.local_geometry_data(
43+
grid :: AbstractGrid,
44+
staggering :: Union{Staggering, Nothing},
45+
)
46+
47+
Get the `DataLayout` object containing the local geometry data information of
48+
the `grid` with staggering `staggering`.
49+
50+
If the grid is not staggered, `staggering` should be `nothing`.
51+
"""
52+
function local_geometry_data end
53+
54+
function local_dss_weights end
55+
function quadrature_style end
56+
function vertical_topology end
57+
58+
59+
60+
ClimaComms.context(grid::AbstractGrid) = ClimaComms.context(topology(grid))
61+
ClimaComms.device(grid::AbstractGrid) = ClimaComms.device(topology(grid))
62+
63+
Meshes.domain(grid::AbstractGrid) = Meshes.domain(Topologies.topology(grid))
64+
65+
include("finitedifference.jl")
66+
include("spectralelement.jl")
67+
include("extruded.jl")
68+
include("column.jl")
69+
include("level.jl")
70+
71+
72+
73+
end # module

0 commit comments

Comments
 (0)