Skip to content

Commit

Permalink
Merge pull request #1999 from CliMA/gb/fix_bubble
Browse files Browse the repository at this point in the history
Fix InputOutput when enable_bubble is true
  • Loading branch information
charleskawczynski authored Sep 19, 2024
2 parents a084cc8 + 5a6d369 commit bd20629
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
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 <[email protected]>"]
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

2 comments on commit bd20629

@Sbozzolo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/115503

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.16 -m "<description of version>" bd2062995748959f699a1cb078034985ab0fb8b6
git push origin v0.14.16

Please sign in to comment.