Skip to content

Commit

Permalink
Merge pull request #67 from jbisits/jib-fixsavingbacgroundstate
Browse files Browse the repository at this point in the history
Ensure data that is being saved is `Array` on `CPU`
  • Loading branch information
jbisits authored Nov 15, 2024
2 parents c6abf93 + 46d7d72 commit 41c7047
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/staircase_restoring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,38 +91,41 @@ function save_background_state!(simulation, model, initial_conditions::Periodoic

S_background = Field(model.background_fields.tracers.S)
compute!(S_background)
S_background_array = Array(interior(S_background, :, :, :))
T_background = Field(model.background_fields.tracers.T)
compute!(T_background)
T_background_array = Array(interior(T_background, :, :, :))
σ_background = Field(seawater_density(model, temperature = T_background, salinity = S_background,
geopotential_height = 0))
compute!(σ_background)
σ_background_array = Array(interior(σ_background, :, :, :))

if simulation.output_writers[:tracers] isa NetCDFOutputWriter

NCDataset(simulation.output_writers[:tracers].filepath, "a") do ds
defVar(ds, "S_background", S_background, ("xC", "yC", "zC"),
defVar(ds, "S_background", S_background_array, ("xC", "yC", "zC"),
attrib = Dict("longname" => "Background field for salinity",
"units" => "gkg⁻¹"))
defVar(ds, "T_background", T_background, ("xC", "yC", "zC"),
defVar(ds, "T_background", T_background_array, ("xC", "yC", "zC"),
attrib = Dict("longname" => "Background field for temperature",
"units" => "°C"))
end

NCDataset(simulation.output_writers[:computed_output].filepath, "a") do ds
defVar(ds, "σ_background", σ_background, ("xC", "yC", "zC"),
defVar(ds, "σ_background", σ_background_array, ("xC", "yC", "zC"),
attrib = Dict("longname" => "Background field for potential density (0dbar) computed from the `S` and `T` background fields",
"units" => "kgm⁻³"))
end

elseif simulation.output_writers[:tracers] isa JLD2OutputWriter

jldopen(simulation.output_writers[:tracers].filepath, "a+") do f
f["S_background"] = S_background
f["T_background"] = T_background
f["S_background"] = S_background_array
f["T_background"] = T_background_array
end

jldopen(simulation.output_writers[:computed_output].filepath, "a+") do f
f["σ_background"] = σ_background
f["σ_background"] = σ_background_array
end

end
Expand Down

0 comments on commit 41c7047

Please sign in to comment.