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

Make it easier to restart a simulation from a checkpoint with additional passive tracers #2938

Merged
merged 2 commits into from
Feb 23, 2023
Merged
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
26 changes: 15 additions & 11 deletions src/OutputWriters/checkpointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ function set!(model, filepath::AbstractString)
model_fields = prognostic_fields(model)

for name in propertynames(model_fields)
try
if string(name) ∈ keys(file) # Test if variable exist in checkpoint
Copy link
Member

Choose a reason for hiding this comment

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

I like this! Easier to understand when reading it

parent_data = file["$name/data"]
model_field = model_fields[name]
copyto!(model_field.data.parent, parent_data)
catch
@warn "Could not retore $name from checkpoint."
else
@warn "Field $name does not exist in checkpoint and could not be restored."
end
end

Expand All @@ -236,17 +236,21 @@ end

function set_time_stepper_tendencies!(timestepper, file, model_fields)
for name in propertynames(model_fields)
# Tendency "n"
parent_data = file["timestepper/Gⁿ/$name/data"]
if string(name) ∈ keys(file["timestepper/Gⁿ"]) # Test if variable tendencies exist in checkpoint
# Tendency "n"
parent_data = file["timestepper/Gⁿ/$name/data"]

tendencyⁿ_field = timestepper.Gⁿ[name]
copyto!(tendencyⁿ_field.data.parent, parent_data)
tendencyⁿ_field = timestepper.Gⁿ[name]
copyto!(tendencyⁿ_field.data.parent, parent_data)

# Tendency "n-1"
parent_data = file["timestepper/G⁻/$name/data"]
# Tendency "n-1"
parent_data = file["timestepper/G⁻/$name/data"]

tendency⁻_field = timestepper.G⁻[name]
copyto!(tendency⁻_field.data.parent, parent_data)
tendency⁻_field = timestepper.G⁻[name]
copyto!(tendency⁻_field.data.parent, parent_data)
else
@warn "Tendencies for $name do not exist in checkpoint and could not be restored."
end
end

return nothing
Expand Down