Skip to content

Commit 5a6d369

Browse files
committed
Fix InputOutput when enable_bubble is true
It turns out that we were not saving and restoring a piece of information that is required to fully reconstruct a `2DSpectralSpace`: the bubble correction. When enabled, the bubble correction recomputes the Jacobian to improve their accuracy. `InputOutput` was not saving this piece of information into the HDF5 file, so spaces read from file always assumed that it was false. This led to discrepancies in the space, and these discrepancies led to problems in the evolution. Interestingly, for the low-resolution cases we consider in the Atmos CI, `enable_bubble` has very small effects on the value of the Jacobian, with a relative difference compared to the case without bubble smaller than the floating point precision for Float32. In spite of this, it affected the evolution in more noticeable way, in particular in vectors and with hyperdiffusion. Now, `bubble` is saved as attribute so that it can be read back. This commit also bumps the version of ClimaCore to 0.14.6
1 parent a084cc8 commit 5a6d369

File tree

6 files changed

+46
-15
lines changed

6 files changed

+46
-15
lines changed

NEWS.md

+16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ ClimaCore.jl Release Notes
44
main
55
-------
66

7+
v0.14.16
8+
-------
9+
10+
### ![][badge-🐛bugfix] Fix restarting simulations from `Space`s with `enable_bubble = true`
11+
12+
Prior to this change, the `ClimaCore.InputOutput` module did not save whether a
13+
`Space` was constructed with `enable_bubble = true`. This meant that restarting
14+
a simulation from a HDF5 file led to inconsistent and incorrect spaces and
15+
`Field`s. This affected only 2D spectral spaces (and extruded ones that have
16+
this type of horizontal space).
17+
18+
We now expect `Space`s read from a file to be bitwise identical to the original
19+
one.
20+
21+
PR [#1999](https://github.com/CliMA/ClimaCore.jl/pull/1999).
22+
723
v0.14.15
824
-------
925

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ClimaCore"
22
uuid = "d414da3d-4745-48bb-8d80-42e94e092884"
33
authors = ["CliMA Contributors <clima-software@caltech.edu>"]
4-
version = "0.14.15"
4+
version = "0.14.16"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/Grids/spectralelement.jl

+2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ mutable struct SpectralElementGrid2D{
129129
local_dss_weights::D
130130
internal_surface_geometry::IS
131131
boundary_surface_geometries::BS
132+
enable_bubble::Bool
132133
end
133134

134135
local_geometry_type(
@@ -467,6 +468,7 @@ function _SpectralElementGrid2D(
467468
dss_local_weights,
468469
internal_surface_geometry,
469470
boundary_surface_geometries,
471+
enable_bubble,
470472
)
471473
end
472474

src/InputOutput/readers.jl

+6-1
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,15 @@ function read_grid_new(reader, name)
333333
quadrature_style =
334334
_scan_quadrature_style(attrs(group)["quadrature_type"], npts)
335335
topology = read_topology(reader, attrs(group)["topology"])
336+
enable_bubble = get(attrs(group), "bubble", "false") == "true"
336337
if type == "SpectralElementGrid1D"
337338
return Grids.SpectralElementGrid1D(topology, quadrature_style)
338339
else
339-
return Grids.SpectralElementGrid2D(topology, quadrature_style)
340+
return Grids.SpectralElementGrid2D(
341+
topology,
342+
quadrature_style;
343+
enable_bubble,
344+
)
340345
end
341346
elseif type == "FiniteDifferenceGrid"
342347
topology = read_topology(reader, attrs(group)["topology"])

src/InputOutput/writers.jl

+1
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ function write_new!(
343343
"quadrature_num_points",
344344
Quadratures.degrees_of_freedom(Spaces.quadrature_style(grid)),
345345
)
346+
write_attribute(group, "bubble", grid.enable_bubble ? "true" : "false")
346347
write_attribute(group, "topology", write!(writer, Spaces.topology(grid)))
347348
return name
348349
end

test/InputOutput/spectralelement2d.jl

+20-13
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,27 @@ end
7171
@info "Using device" device
7272
context = ClimaComms.SingletonCommsContext(device)
7373
grid_topology = Topologies.Topology2D(context, mesh)
74-
space = Spaces.SpectralElementSpace2D(grid_topology, quad)
7574

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

79-
# write field vector to hdf5 file
80-
filename = tempname(pwd())
81-
writer = InputOutput.HDF5Writer(filename, context)
82-
InputOutput.write!(writer, "Y" => Y) # write field vector from hdf5 file
83-
close(writer)
84-
reader = InputOutput.HDF5Reader(filename, context)
85-
restart_Y = InputOutput.read_field(reader, "Y") # read fieldvector from hdf5 file
86-
close(reader)
87-
ClimaComms.allowscalar(device) do
88-
@test restart_Y == Y # test if restart is exact
79+
y0 = init_state.(Fields.local_geometry_field(space), Ref(parameters))
80+
Y = Fields.FieldVector(y0 = y0)
81+
82+
# write field vector to hdf5 file
83+
filename = tempname(pwd())
84+
writer = InputOutput.HDF5Writer(filename, context)
85+
InputOutput.write!(writer, "Y" => Y) # write field vector from hdf5 file
86+
close(writer)
87+
reader = InputOutput.HDF5Reader(filename, context)
88+
restart_Y = InputOutput.read_field(reader, "Y") # read fieldvector from hdf5 file
89+
close(reader)
90+
ClimaComms.allowscalar(device) do
91+
@test restart_Y == Y # test if restart is exact
92+
end
93+
ClimaComms.allowscalar(device) do
94+
@test axes(restart_Y) == axes(Y) # test if restart is exact for space
95+
end
8996
end
9097
end

0 commit comments

Comments
 (0)