-
Notifications
You must be signed in to change notification settings - Fork 195
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
A fast netcdf output writer #433
Merged
+338
−126
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0fe221a
Introduces machinary for getting dimensions from fields
suyashbire1 28af45c
Introduces a new netcdf outputwriter
suyashbire1 5e2e910
A working netcdf output writer!
suyashbire1 04ac85b
Adds comments
suyashbire1 bcf9b7b
Consolidates NetCDFOutputwriter in output_writer.jl
suyashbire1 3966930
Moves dims from fields to output_writers
suyashbire1 2e637c6
Provides a simple example of new netcdfoutputwriter
suyashbire1 ad2763a
Some cleanup to the example
suyashbire1 2bc7426
Adds support for attributes, some testing, improves example
suyashbire1 b16197f
Changes to slice, needs to be reviewed
suyashbire1 55b04e5
Restricts face diemensions which solves the size mismatch due to halo…
suyashbire1 2f26c9a
NetCDFoutputwriter tests now pass!
suyashbire1 a543373
Implements a test for sliced output
suyashbire1 83e16f1
Can now specify integers instead of slices, this allows getting sections
suyashbire1 4393817
Testing of integer slices
suyashbire1 9e7e09f
Replaces get_dtype_array function with the base.eltype
suyashbire1 4a1d80b
Improves docstrings
suyashbire1 728ce9a
Small change to the docstring
suyashbire1 c4cc074
Replaces OWClose with close, removes Netcdf.jl dep
suyashbire1 88625d8
Merge branch 'master' into outputwriters_with_assoc_dimensions
suyashbire1 15edb32
Fixes regression tests
suyashbire1 163a538
Minor fixes
suyashbire1 3f772d9
Closes netcdf file in tests
suyashbire1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using Oceananigans, Printf | ||
|
||
#### | ||
#### Model set-up | ||
#### | ||
|
||
Nx, Ny, Nz = 16, 16, 16 # No. of grid points in x, y, and z, respectively. | ||
Lx, Ly, Lz = 100, 100, 100 # Length of the domain in x, y, and z, respectively (m). | ||
tf = 5000 # Length of the simulation (s) | ||
|
||
model = Model(grid=RegularCartesianGrid(N=(Nx, Ny, Nz), L=(Lx, Ly, Lz)), | ||
closure=ConstantIsotropicDiffusivity()) | ||
|
||
# Add a cube-shaped warm temperature anomaly that takes up the middle 50% | ||
# of the domain volume. | ||
i1, i2 = round(Int, Nx/4), round(Int, 3Nx/4) | ||
j1, j2 = round(Int, Ny/4), round(Int, 3Ny/4) | ||
k1, k2 = round(Int, Nz/4), round(Int, 3Nz/4) | ||
model.tracers.T.data[i1:i2, j1:j2, k1:k2] .+= 0.01 | ||
|
||
#### | ||
#### Set up output | ||
#### | ||
|
||
write_grid(model) | ||
|
||
outputs = Dict("u" => model.velocities.u, | ||
"v" => model.velocities.v, | ||
"w" => model.velocities.w, | ||
"T" => model.tracers.T, | ||
"S" => model.tracers.S) | ||
|
||
outputattrib = Dict("u" => ["longname" => "Velocity in the x-direction", "units" => "m/s"], | ||
"v" => ["longname" => "Velocity in the y-direction", "units" => "m/s"], | ||
"w" => ["longname" => "Velocity in the z-direction", "units" => "m/s"], | ||
"T" => ["longname" => "Temperature", "units" => "K"], | ||
"S" => ["longname" => "Salinity", "units" => "g/kg"]) | ||
|
||
globalattrib = Dict("f" => 1e-4, "name" => "Thermal bubble expt 1") | ||
|
||
# The following writer saves a yz plane at xC[5] for all fields that | ||
# have xC as their dimension and at xF[6] for all fields that have xF | ||
# as their dimension. Ranges also can be specified (e.g. xC=2:10) | ||
subsetwriter = NetCDFOutputWriter(model, outputs; | ||
interval=10, filename="dump_subset.nc", | ||
outputattrib=outputattrib, | ||
globalattrib=globalattrib, | ||
xC=5, xF=6) | ||
push!(model.output_writers, subsetwriter) | ||
|
||
# The following writer saves a data from the entire domain | ||
globalwriter = NetCDFOutputWriter(model, outputs, interval=10, | ||
filename="dump_global.nc") | ||
push!(model.output_writers, globalwriter) | ||
|
||
#### | ||
#### Run the simulation | ||
#### | ||
|
||
function terse_message(model, walltime, Δt) | ||
cfl = Δt / Oceananigans.cell_advection_timescale(model) | ||
return @sprintf("i: %d, t: %.4f s, Δt: %.1f s, cfl: %.3f, wall time: %s\n", | ||
model.clock.iteration, model.clock.time, Δt, cfl, prettytime(walltime)) | ||
end | ||
|
||
# A wizard for managing the simulation time-step. | ||
wizard = TimeStepWizard(cfl=0.2, Δt=10.0, max_change=1.1, max_Δt=50.0) | ||
|
||
# Run the model | ||
while model.clock.time < tf | ||
update_Δt!(wizard, model) | ||
walltime = @elapsed time_step!(model, 10, wizard.Δt) | ||
@printf "%s" terse_message(model, walltime, wizard.Δt) | ||
end | ||
|
||
# Close the NetCDFOutputWriter | ||
OWClose(subsetwriter) | ||
OWClose(globalwriter) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine for now but I wonder if there's a way to automatically close NetCDF files so the user doesn't have to worry about this stuff.
Unfortunately Julia doesn't have destructors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh nevermind, Julia does have finalizers:
but not sure if this would be a proper use of them. See JuliaLang/julia#11207
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this function should also be changed to
snake_case
? Let's make sure we use the proper style for all new functions in this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what finalizers/destructors do. Sounds like garbage collection.
Anyway, we already have a list of outputwriters. Could we iterate over it and have
close(outputwriter)
in atry catch
block at the end of the run (may be at the end of the proposed function that will replace the time-step loop)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.