-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conservation checker interface #167
Conversation
cebcc63
to
db64044
Compare
db64044
to
b739663
Compare
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.
Thanks Lenka! I only quickly went through it because it's a large PR:) I left a few comments. Also, I wonder if it makes sense to add mass conservation as well?
FT = eltype(coupler_sim.surface_masks.land) | ||
|
||
# save radiation source | ||
if radiation != nothing |
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.
We have this in ClimaAtmos which integrates fluxes at the boundaries. It might be useful when you clean up the code.
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.
That's great! We can update to this upon the next ClimaAtmos release.
|
||
Only energy and water are currently implemented. | ||
|
||
Note that kinetic energy is not included in the calculation of the global energy, reflecting the formulation on `ClimaAtmos`, which assumes that kinetic energy is negligible in comparison with the moist static energy components. |
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 think this is a bit confusing because e.g. when you calculate the total energy of atmosphere using e_tot
, it includes kinetic energy. Maybe rephrase it as something like Kinetic energy transfer between atmosphere, land, and ocean is not included
?
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.
That was rather misleading, thanks for pointing it out! It was meant to refer to the KE contribution being neglected in all diffusive fluxes in the atmos interior, so this is consistent with these BCs. In any case, since we won't be needing this function (except perhaps for diagnostics?) in the foreseeable, I've decided to remove it for now. :P
src/ConservationChecker.jl
Outdated
evaporation = cs.fields.F_E # kg/m^2/s / layer depth | ||
precipitation_l = cs.fields.P_liq | ||
precipitation_s = cs.fields.P_snow | ||
@. (evaporation + precipitation_l + precipitation_s) * cs.Δt_cpl # in kg |
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.
@. (evaporation + precipitation_l + precipitation_s) * cs.Δt_cpl # in kg | |
@. (evaporation + precipitation_l + precipitation_s) * cs.Δt_cpl # in kg /m^2 |
I think that's the unit? I'm not sure though.
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.
see above. Now clarified
src/ConservationChecker.jl
Outdated
end | ||
|
||
# save ocean | ||
if ice_sim !== nothing |
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.
if ice_sim !== nothing | |
if ocean_sim !== nothing |
?
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.
Good catch! I missed this after the last rebase! 😳
src/ConservationChecker.jl
Outdated
if land_sim !== nothing | ||
water_content = | ||
@. (land_sim.integrator.u.bucket.σS + land_sim.integrator.u.bucket.W + land_sim.integrator.u.bucket.Ws) # m^3 water / land area / layer height | ||
parent(water_content) .= parent(water_content .* surface_masks.land) * FT(1000) |
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's a bit hard for me to figure out the unit here (without knowing details about the land model). Maybe add some more comments?
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.
Sure! I can comment more lines. Also, instead of the FT(1000), I'm adding ClimaLSM.LSMP.ρ_cloud_liq
which clarifies the units further. The final values are in kg, thanks to ClimaCore's sum
function doing the volume integral for us (rather than a simple sum).
@@ -0,0 +1,8 @@ | |||
[land_mask] |
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.
do we want the artifacts to be checked in to github? I'm not sure it matters too much, just wanted to double check
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 would have thought it would be good to keep it for tracking changes in the files (each time the file is replaced with a new one of the same name, the git-tree-sha1
changes). I just found this issue, which may require using Tar.tree_hash
to be general to all platforms, but apparently this should have been fixed in Julia 1.6. @charleskawczynski do you have any thoughts? I noticed Atmos doesn't check these in?
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.
Yes, I think the artifacts toml is the intended file to be tracked, so that there's a direct mapping between these hashes and the artifacts used.
We don't in ClimaAtmos, but we probably should.
Also, I haven't seen that issue before, it could be that we somehow need to update ArtifactWrappers to use this
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.
For now, I think checking it in is fine, it at least enforces some reproducibility
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.
Thank you, Charlie!
end | ||
|
||
## read in some parsed command line arguments | ||
mode_name = parsed_args["mode_name"] |
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.
maybe not now, but we could consider reading in parsed_args
as a NamedTuple
, then using the (; ...)
syntax to unpack it more concisely
|
||
# import coupler utils | ||
include("coupler_utils/flux_calculator.jl") | ||
include("coupler_utils/regridder.jl") # update_midmonth_data! |
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 think we don't need this since the Regridder module should have all the functionality of the regridder util. If we still have the include, we might not be actually using the functions from Regridder
|
||
using ClimaCoupler.Utilities | ||
using ClimaCore: ClimaCore, Geometry, Meshes, Domains, Topologies, Spaces, Fields, InputOutput | ||
using ClimaCore.Utilities: half |
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 think this is redundant since you already have using ClimaCoupler.Utilities
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.
Actually the half needs to be specifically imported, but line 8 can be removed. :)
""" | ||
check_conservation!(coupler_sim::CoupledSimulation) | ||
|
||
itertes over all specified conservation checks. |
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.
docstring doesn't match function signature
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.
Good catch!
map(x -> check_conservation!(x, coupler_sim, get_slab_energy, get_land_energy), coupler_sim.conservation_checks) | ||
|
||
""" | ||
check_conservation!( |
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.
docstring doesn't match function signature
src/ConservationChecker.jl
Outdated
|
||
Calculate the kinetic energy diffipation of a simulation. | ||
""" | ||
function ke_dissipation(sim) |
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.
could be helpful to annotate the input and return types (at least in the docstring)
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 function is now removed (see above).
src/ConservationChecker.jl
Outdated
end | ||
|
||
""" | ||
check_conservation( |
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.
docstring doesn't match function signature
end | ||
|
||
# https://github.com/jheinen/GR.jl/issues/278#issuecomment-587090846 | ||
ENV["GKSwstype"] = "nul" |
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.
a short comment explaining why this is here could be helpful, then readers can follow the link for more detail
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.
Sure!
@szy21 and @juliasloan25 , thank you both for the review! 🚀 |
We can do, but I'm not sure we're exchanging anything else but water between the models right now, so maybe domain-local conservation checks should be done in the models themselves? |
Yes, I just thought it would be more comprehensive and might be useful for debugging to have all the conservation checks (mass, energy, water) when running the coupled simulation. But you're right there is no mass exchange between atmos and land or ocean, so we can do it in ClimaAtmos. |
b739663
to
223542b
Compare
It's really no problem to add it in here temporarily, if it's useful. But in the long term we should probably have checks for both coupled and standalone runs. I'll put it on the AMIP improvements list and maybe we can reassess in Jan? |
tests for all except land_sea_mask all tests pass, land_sea_mask separated before Project.toml cleanup Project.tomls cleaned up cleanup GeneralUtilities, TestHelper modules docs and formatting modularize conservation checker wip passing tests clean + doc doc trigger test docs rebase plots rebase fix dep + buildkite buildkite fix plots dep unavoidable pip fix tests deps redundant func fix fix revs SB Manifest
223542b
to
5055449
Compare
bors r+ |
Purpose
Move existing energy check to
src
and extend to water conservation.Content
ConservationChecker
modulesrc
coupler-driver_modular.jl
)Notes
coupler_driver.jl
.