@@ -13,6 +13,11 @@ using ClimaCore:
1313 InputOutput,
1414 Grids
1515
16+ @isdefined (TU) || include (
17+ joinpath (pkgdir (ClimaCore), " test" , " TestUtilities" , " TestUtilities.jl" ),
18+ );
19+ import . TestUtilities as TU;
20+
1621using ClimaComms
1722const comms_ctx = ClimaComms. context (ClimaComms. CPUSingleThreaded ())
1823pid, nprocs = ClimaComms. init (comms_ctx)
5459 z_max / 8 .* (
5560 cosd .(Fields. coordinate_field (h_space). lat) .+
5661 cosd .(Fields. coordinate_field (h_space). long) .+ 1
57- )
62+ ),
5863 )
5964
6065 z_mesh = Meshes. IntervalMesh (z_domain, nelems = z_elem)
9095 end
9196 end
9297end
98+
99+
100+ @testset " HDF5 restart test for a Named Tuple of Levels of a 3D hybrid cubed sphere for deep" begin
101+ # This I/O is used for the computation of the topographic drag
102+ FT = Float32
103+
104+ for space in (
105+ TU. CenterExtrudedFiniteDifferenceSpace (FT, context = comms_ctx),
106+ TU. FaceExtrudedFiniteDifferenceSpace (FT, context = comms_ctx),
107+ )
108+ TU. levelable (space) || continue
109+ field = fill ((; x = FT (1 )), space)
110+
111+ level_of_field = Fields. Field (
112+ Spaces. level (Fields. field_values (field. x), 1 ),
113+ Spaces. level (space, TU. fc_index (1 , space)),
114+ )
115+
116+ fake_drag = fill (
117+ (;
118+ t11 = FT (0.0 ),
119+ t12 = FT (0.0 ),
120+ t21 = FT (0.0 ),
121+ t22 = FT (0.0 ),
122+ hmin = FT (0.0 ),
123+ hmax = FT (0.0 ),
124+ ),
125+ axes (level_of_field),
126+ )
127+
128+ # write field vector to hdf5 file
129+ InputOutput. HDF5Writer (filename, comms_ctx) do writer
130+ InputOutput. write! (writer, fake_drag, " fake_drag" )
131+ end
132+
133+ InputOutput. HDF5Reader (filename, comms_ctx) do reader
134+ restart_fake_drag = InputOutput. read_field (reader, " fake_drag" ) # read fieldvector from hdf5 file
135+
136+ # The underlying space is of a different instance, so we cannot use == to check for equivalence.
137+ # Instead, we make sure that the values and types are the same.
138+ @test typeof (restart_fake_drag) == typeof (fake_drag)
139+ @test maximum (
140+ abs .(parent (fake_drag. t21) .- parent (restart_fake_drag. t21)),
141+ ) == 0.0f0
142+ end
143+ end
144+ end
0 commit comments