Skip to content

Commit 83c8cf9

Browse files
Add fieldvector unit tests
1 parent 9a05ed2 commit 83c8cf9

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

test/Fields/unit_field.jl

+62
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ClimaComms.@import_required_backends
1111
using OrderedCollections
1212
using StaticArrays, IntervalSets
1313
import ClimaCore
14+
import ClimaCore.InputOutput
1415
import ClimaCore.Utilities: PlusHalf
1516
import ClimaCore.DataLayouts
1617
import ClimaCore.DataLayouts: IJFH
@@ -330,6 +331,67 @@ end
330331
@test occursin("==================== Difference found:", s)
331332
end
332333

334+
@testset "FieldVector restart + broadcasting" begin
335+
FT = Float32
336+
root_path = "bucket_restart"
337+
rm(root_path; force = true, recursive = true)
338+
mkpath(root_path)
339+
340+
radius = FT(100)
341+
depth = FT(3.5)
342+
nelements = (1, 10)
343+
npolynomial = 1
344+
dz_tuple = nothing
345+
context = ClimaComms.context()
346+
347+
vertdomain = Domains.IntervalDomain(
348+
Geometry.ZPoint(FT(-depth)),
349+
Geometry.ZPoint(FT(0));
350+
boundary_names = (:bottom, :top),
351+
)
352+
vertmesh = Meshes.IntervalMesh(vertdomain; nelems = nelements[2])
353+
device = ClimaComms.device()
354+
vert_center_space = Spaces.CenterFiniteDifferenceSpace(device, vertmesh)
355+
horzdomain = Domains.SphereDomain(radius)
356+
horzmesh = Meshes.EquiangularCubedSphere(horzdomain, nelements[1])
357+
horztopology = Topologies.Topology2D(context, horzmesh)
358+
quad = Spaces.Quadratures.GLL{npolynomial + 1}()
359+
space = Spaces.SpectralElementSpace2D(horztopology, quad)
360+
361+
vars = (;
362+
bucket = (;
363+
W = Fields.Field(FT, space),
364+
T = Fields.Field(FT, space),
365+
Ws = Fields.Field(FT, space),
366+
σS = Fields.Field(FT, space),
367+
)
368+
)
369+
370+
Y = Fields.FieldVector(; vars...)
371+
Y.bucket.T .= 280.0
372+
Y.bucket.W .= 0.05
373+
Y.bucket.Ws .= 0.0
374+
Y.bucket.σS .= 0.08
375+
376+
output_file = joinpath(root_path, "day0.0.hdf5")
377+
hdfwriter = InputOutput.HDF5Writer(output_file, context)
378+
InputOutput.write_attributes!(
379+
hdfwriter,
380+
"/",
381+
Dict("time" => 0.0, "hash" => "1234"),
382+
)
383+
InputOutput.write!(hdfwriter, Y, "Y")
384+
Base.close(hdfwriter)
385+
386+
restart_file = output_file
387+
Y_restart = Fields.FieldVector(; vars...)
388+
hdfreader = InputOutput.HDF5Reader(restart_file, context)
389+
Y_restart = InputOutput.read_field(hdfreader, "Y")
390+
close(hdfreader)
391+
Y .= Y_restart
392+
393+
end
394+
333395
# https://github.com/CliMA/ClimaCore.jl/issues/1465
334396
@testset "Diagonal FieldVector broadcast expressions" begin
335397
FT = Float64

0 commit comments

Comments
 (0)