Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix InputOutput when enable_bubble is true #1999

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ ClimaCore.jl Release Notes
main
-------

v0.14.16
-------

### ![][badge-🐛bugfix] Fix restarting simulations from `Space`s with `enable_bubble = true`

Prior to this change, the `ClimaCore.InputOutput` module did not save whether a
`Space` was constructed with `enable_bubble = true`. This meant that restarting
a simulation from a HDF5 file led to inconsistent and incorrect spaces and
`Field`s. This affected only 2D spectral spaces (and extruded ones that have
this type of horizontal space).

We now expect `Space`s read from a file to be bitwise identical to the original
one.

PR [#1999](https://github.com/CliMA/ClimaCore.jl/pull/1999).

v0.14.15
-------

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClimaCore"
uuid = "d414da3d-4745-48bb-8d80-42e94e092884"
authors = ["CliMA Contributors <clima-software@caltech.edu>"]
version = "0.14.15"
version = "0.14.16"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
2 changes: 2 additions & 0 deletions src/Grids/spectralelement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ mutable struct SpectralElementGrid2D{
local_dss_weights::D
internal_surface_geometry::IS
boundary_surface_geometries::BS
enable_bubble::Bool
end

local_geometry_type(
Expand Down Expand Up @@ -467,6 +468,7 @@ function _SpectralElementGrid2D(
dss_local_weights,
internal_surface_geometry,
boundary_surface_geometries,
enable_bubble,
)
end

Expand Down
7 changes: 6 additions & 1 deletion src/InputOutput/readers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,15 @@ function read_grid_new(reader, name)
quadrature_style =
_scan_quadrature_style(attrs(group)["quadrature_type"], npts)
topology = read_topology(reader, attrs(group)["topology"])
enable_bubble = get(attrs(group), "bubble", "false") == "true"
if type == "SpectralElementGrid1D"
return Grids.SpectralElementGrid1D(topology, quadrature_style)
else
return Grids.SpectralElementGrid2D(topology, quadrature_style)
return Grids.SpectralElementGrid2D(
topology,
quadrature_style;
enable_bubble,
)
end
elseif type == "FiniteDifferenceGrid"
topology = read_topology(reader, attrs(group)["topology"])
Expand Down
1 change: 1 addition & 0 deletions src/InputOutput/writers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ function write_new!(
"quadrature_num_points",
Quadratures.degrees_of_freedom(Spaces.quadrature_style(grid)),
)
write_attribute(group, "bubble", grid.enable_bubble ? "true" : "false")
write_attribute(group, "topology", write!(writer, Spaces.topology(grid)))
return name
end
Expand Down
33 changes: 20 additions & 13 deletions test/InputOutput/spectralelement2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,27 @@ end
@info "Using device" device
context = ClimaComms.SingletonCommsContext(device)
grid_topology = Topologies.Topology2D(context, mesh)
space = Spaces.SpectralElementSpace2D(grid_topology, quad)

y0 = init_state.(Fields.local_geometry_field(space), Ref(parameters))
Y = Fields.FieldVector(y0 = y0)
for enable_bubble in (true, false)
space =
Spaces.SpectralElementSpace2D(grid_topology, quad; enable_bubble)

# write field vector to hdf5 file
filename = tempname(pwd())
writer = InputOutput.HDF5Writer(filename, context)
InputOutput.write!(writer, "Y" => Y) # write field vector from hdf5 file
close(writer)
reader = InputOutput.HDF5Reader(filename, context)
restart_Y = InputOutput.read_field(reader, "Y") # read fieldvector from hdf5 file
close(reader)
ClimaComms.allowscalar(device) do
@test restart_Y == Y # test if restart is exact
y0 = init_state.(Fields.local_geometry_field(space), Ref(parameters))
Y = Fields.FieldVector(y0 = y0)

# write field vector to hdf5 file
filename = tempname(pwd())
writer = InputOutput.HDF5Writer(filename, context)
InputOutput.write!(writer, "Y" => Y) # write field vector from hdf5 file
close(writer)
reader = InputOutput.HDF5Reader(filename, context)
restart_Y = InputOutput.read_field(reader, "Y") # read fieldvector from hdf5 file
close(reader)
ClimaComms.allowscalar(device) do
@test restart_Y == Y # test if restart is exact
end
ClimaComms.allowscalar(device) do
@test axes(restart_Y) == axes(Y) # test if restart is exact for space
end
end
end
Loading