Skip to content

Commit b4a04d8

Browse files
authored
Merge pull request #2102 from CliMA/gb/input_output_vf
Fix reading/writing purely vertical spaces
2 parents 6ad8294 + 3a64eec commit b4a04d8

13 files changed

+87
-19
lines changed

.buildkite/pipeline.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,35 +1146,39 @@ steps:
11461146

11471147
- label: "Unit: spectralelement2d"
11481148
key: unit_spectralelement2d
1149-
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/spectralelement2d.jl"
1149+
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_spectralelement2d.jl"
11501150

11511151
- label: "Unit: hybrid2dbox"
11521152
key: unit_hybrid2dbox
1153-
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/hybrid2dbox.jl"
1153+
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_hybrid2dbox.jl"
11541154

11551155
- label: "Unit: hybrid2dbox topography"
11561156
key: unit_hybrid2dbox_topography
1157-
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/hybrid2dbox_topography.jl"
1157+
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_hybrid2dbox_topography.jl"
11581158

11591159
- label: "Unit: hybrid2dbox stretched"
11601160
key: unit_hybrid2dbox_stretched
1161-
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/hybrid2dbox_stretched.jl"
1161+
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_hybrid2dbox_stretched.jl"
11621162

11631163
- label: "Unit: hybrid3dbox"
11641164
key: unit_hybrid3dbox
1165-
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/hybrid3dbox.jl"
1165+
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_hybrid3dbox.jl"
11661166

11671167
- label: "Unit: hybrid3dcubedsphere"
11681168
key: unit_hybrid3dcubedsphere
1169-
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/hybrid3dcubedsphere.jl"
1169+
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_hybrid3dcubedsphere.jl"
11701170

11711171
- label: "Unit: hybrid3dcubedsphere topography"
11721172
key: unit_hybrid3dcubedsphere_topography
1173-
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/hybrid3dcubedsphere_topography.jl"
1173+
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_hybrid3dcubedsphere_topography.jl"
1174+
1175+
- label: "Unit: finitedifference"
1176+
key: unit_finitedifference
1177+
command: "julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_finitedifference.jl"
11741178

11751179
- label: "Unit: Parallel HDF5 IO tests"
11761180
key: "cpu_parallel_hdf5"
1177-
command: "srun julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/hybrid3dcubedsphere.jl"
1181+
command: "srun julia --color=yes --check-bounds=yes --project=.buildkite test/InputOutput/unit_hybrid3dcubedsphere.jl"
11781182
timeout_in_minutes: 5
11791183
env:
11801184
CLIMACOMMS_CONTEXT: "MPI"

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ClimaCore.jl Release Notes
44
main
55
-------
66

7+
78
- 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:
89
- [ExtrudedCubedSphereSpace]()
910
- [CubedSphereSpace]()
@@ -12,7 +13,12 @@ main
1213
- [SliceXZSpace]()
1314
- [RectangleXYSpace]()
1415

16+
### ![][badge-🐛bugfix] Bug fixes
17+
18+
- Fixed writing/reading purely vertical spaces
19+
1520
v0.14.20
21+
--------
1622

1723
- 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:
1824
- [ExtrudedCubedSphereGrid](https://github.com/CliMA/ClimaCore.jl/blob/cbb193042fac3b4bef33251fbc0f232427bfe506/src/CommonGrids/CommonGrids.jl#L85-L144)

src/InputOutput/readers.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,19 @@ function _scan_data_layout(layoutstring::AbstractString)
152152
"IFH",
153153
"IHF",
154154
"IF",
155+
"VF",
155156
"VIJFH",
156157
"VIJHF",
157158
"VIFH",
158159
"VIHF",
159-
)
160+
) "datalayout is $layoutstring"
160161
layoutstring == "IJFH" && return DataLayouts.IJFH
161162
layoutstring == "IJHF" && return DataLayouts.IJHF
162163
layoutstring == "IJF" && return DataLayouts.IJF
163164
layoutstring == "IFH" && return DataLayouts.IFH
164165
layoutstring == "IHF" && return DataLayouts.IHF
165166
layoutstring == "IF" && return DataLayouts.IF
167+
layoutstring == "VF" && return DataLayouts.VF
166168
layoutstring == "VIJFH" && return DataLayouts.VIJFH
167169
layoutstring == "VIJHF" && return DataLayouts.VIJHF
168170
return DataLayouts.VIFH
@@ -482,8 +484,10 @@ function read_field(reader::HDF5Reader, name::AbstractString)
482484
topology = Spaces.topology(space)
483485
ArrayType = ClimaComms.array_type(topology)
484486
data_layout = attrs(obj)["data_layout"]
487+
has_horizontal = occursin('I', data_layout)
485488
DataLayout = _scan_data_layout(data_layout)
486-
h_dim = DataLayouts.h_dim(DataLayouts.singleton(DataLayout))
489+
has_horizontal &&
490+
(h_dim = DataLayouts.h_dim(DataLayouts.singleton(DataLayout)))
487491
if topology isa Topologies.Topology2D
488492
nd = ndims(obj)
489493
localidx =
@@ -492,7 +496,7 @@ function read_field(reader::HDF5Reader, name::AbstractString)
492496
else
493497
data = ArrayType(read(obj))
494498
end
495-
Nij = size(data, findfirst("I", data_layout)[1])
499+
has_horizontal && (Nij = size(data, findfirst("I", data_layout)[1]))
496500
# For when `Nh` is added back to the type space
497501
# Nhd = Nh_dim(data_layout)
498502
# Nht = Nhd == -1 ? () : (size(data, Nhd),)
@@ -501,6 +505,9 @@ function read_field(reader::HDF5Reader, name::AbstractString)
501505
Nv = size(data, 1)
502506
# values = DataLayout{ElType, Nv, Nij, Nht...}(data) # when Nh is in type-domain
503507
values = DataLayout{ElType, Nv, Nij}(data)
508+
elseif data_layout in ("VF",)
509+
Nv = size(data, 1)
510+
values = DataLayout{ElType, Nv}(data)
504511
else
505512
# values = DataLayout{ElType, Nij, Nht...}(data) # when Nh is in type-domain
506513
values = DataLayout{ElType, Nij}(data)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Test
2+
import ClimaCore
3+
import ClimaCore.Fields
4+
5+
using ClimaComms
6+
const comms_ctx = ClimaComms.context(ClimaComms.CPUSingleThreaded())
7+
pid, nprocs = ClimaComms.init(comms_ctx)
8+
filename = ClimaComms.bcast(comms_ctx, tempname(pwd()))
9+
if ClimaComms.iamroot(comms_ctx)
10+
@info "Comms context" comms_ctx nprocs filename
11+
end
12+
13+
@testset "HDF5 restart test for 1d finite difference space" begin
14+
FT = Float32
15+
16+
z_min = FT(0)
17+
z_max = FT(30e3)
18+
z_elem = 10
19+
center_staggering = ClimaCore.Grids.CellCenter()
20+
face_staggering = ClimaCore.Grids.CellFace()
21+
22+
center_space = ClimaCore.CommonSpaces.ColumnSpace(;
23+
z_min,
24+
z_max,
25+
z_elem,
26+
staggering = center_staggering,
27+
)
28+
29+
face_space = ClimaCore.CommonSpaces.ColumnSpace(;
30+
z_min,
31+
z_max,
32+
z_elem,
33+
staggering = face_staggering,
34+
)
35+
36+
center_field = Fields.local_geometry_field(center_space)
37+
face_field = Fields.local_geometry_field(face_space)
38+
39+
Y = ClimaCore.Fields.FieldVector(; c = center_field, f = face_field)
40+
41+
# write field vector to hdf5 file
42+
writer = ClimaCore.InputOutput.HDF5Writer(filename, comms_ctx)
43+
ClimaCore.InputOutput.write!(writer, Y, "Y")
44+
close(writer)
45+
46+
reader = ClimaCore.InputOutput.HDF5Reader(filename, comms_ctx)
47+
restart_Y = ClimaCore.InputOutput.read_field(reader, "Y") # read fieldvector from hdf5 file
48+
close(reader)
49+
@test restart_Y == Y # test if restart is exact
50+
end
File renamed without changes.

0 commit comments

Comments
 (0)