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 1 commit
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
20 changes: 6 additions & 14 deletions src/OutputWriters/checkpointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +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 err
if err isa KeyError
@warn "Could not restore $name from checkpoint."
else
rethrow(err)
end
else
@warn "Field $name does not exist in checkpoint and could not be restored."
end
end

Expand All @@ -240,7 +236,7 @@ end

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

Expand All @@ -252,12 +248,8 @@ function set_time_stepper_tendencies!(timestepper, file, model_fields)

tendency⁻_field = timestepper.G⁻[name]
copyto!(tendency⁻_field.data.parent, parent_data)
catch err
if err isa KeyError
@warn "Could not restore tendencies for $name from checkpoint."
else
rethrow(err)
end
else
@warn "Tendencies for $name do not exist in checkpoint and could not be restored."
end
end

Expand Down