Skip to content

Commit

Permalink
Add fieldvector unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Nov 4, 2024
1 parent 9a05ed2 commit 83c8cf9
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/Fields/unit_field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ClimaComms.@import_required_backends
using OrderedCollections
using StaticArrays, IntervalSets
import ClimaCore
import ClimaCore.InputOutput
import ClimaCore.Utilities: PlusHalf
import ClimaCore.DataLayouts
import ClimaCore.DataLayouts: IJFH
Expand Down Expand Up @@ -330,6 +331,67 @@ end
@test occursin("==================== Difference found:", s)
end

@testset "FieldVector restart + broadcasting" begin
FT = Float32
root_path = "bucket_restart"
rm(root_path; force = true, recursive = true)
mkpath(root_path)

radius = FT(100)
depth = FT(3.5)
nelements = (1, 10)
npolynomial = 1
dz_tuple = nothing
context = ClimaComms.context()

vertdomain = Domains.IntervalDomain(
Geometry.ZPoint(FT(-depth)),
Geometry.ZPoint(FT(0));
boundary_names = (:bottom, :top),
)
vertmesh = Meshes.IntervalMesh(vertdomain; nelems = nelements[2])
device = ClimaComms.device()
vert_center_space = Spaces.CenterFiniteDifferenceSpace(device, vertmesh)
horzdomain = Domains.SphereDomain(radius)
horzmesh = Meshes.EquiangularCubedSphere(horzdomain, nelements[1])
horztopology = Topologies.Topology2D(context, horzmesh)
quad = Spaces.Quadratures.GLL{npolynomial + 1}()
space = Spaces.SpectralElementSpace2D(horztopology, quad)

vars = (;
bucket = (;
W = Fields.Field(FT, space),
T = Fields.Field(FT, space),
Ws = Fields.Field(FT, space),
σS = Fields.Field(FT, space),
)
)

Y = Fields.FieldVector(; vars...)
Y.bucket.T .= 280.0
Y.bucket.W .= 0.05
Y.bucket.Ws .= 0.0
Y.bucket.σS .= 0.08

output_file = joinpath(root_path, "day0.0.hdf5")
hdfwriter = InputOutput.HDF5Writer(output_file, context)
InputOutput.write_attributes!(
hdfwriter,
"/",
Dict("time" => 0.0, "hash" => "1234"),
)
InputOutput.write!(hdfwriter, Y, "Y")
Base.close(hdfwriter)

restart_file = output_file
Y_restart = Fields.FieldVector(; vars...)
hdfreader = InputOutput.HDF5Reader(restart_file, context)
Y_restart = InputOutput.read_field(hdfreader, "Y")
close(hdfreader)
Y .= Y_restart

end

# https://github.com/CliMA/ClimaCore.jl/issues/1465
@testset "Diagonal FieldVector broadcast expressions" begin
FT = Float64
Expand Down

0 comments on commit 83c8cf9

Please sign in to comment.