-
Notifications
You must be signed in to change notification settings - Fork 7
add a test to compare atmosphere and surface fluxes #1541
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
Open
juliasloan25
wants to merge
1
commit into
main
Choose a base branch
from
js/fluxes-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+99
−0
Open
Changes from all commits
Commits
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 hidden or 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,96 @@ | ||||||||||
| # | ||||||||||
| # Flux consistency test (AMIP + bucket land) | ||||||||||
| # | ||||||||||
| # This test sets up an AMIP coupled simulation (atmosphere + bucket land + prescribed | ||||||||||
| # ocean + prescribed sea ice), advances one coupling step, and verifies that the | ||||||||||
| # surface radiative flux seen by the atmosphere matches what each surface model | ||||||||||
| # computes/stores: | ||||||||||
| # - Atmosphere: uses `sim.integrator.p.radiation.ᶠradiation_flux` (positive downward). | ||||||||||
| # - Bucket land: compares against `sim.integrator.p.bucket.R_n` with opposite sign | ||||||||||
| # convention (so atmos ≈ -R_n) on land-dominant cells. | ||||||||||
| # - Prescribed ocean: skipped — SST is prescribed so radiative fluxes are not computed | ||||||||||
| # in the same way. | ||||||||||
| # - Prescribed sea ice: not stored directly; compute using cache fields and compare | ||||||||||
| # to the atmospheric flux on ice-dominant cells. | ||||||||||
|
|
||||||||||
| import Test: @test, @testset | ||||||||||
| import ClimaCore as CC | ||||||||||
| import ClimaComms | ||||||||||
| ClimaComms.@import_required_backends | ||||||||||
| import ClimaCoupler | ||||||||||
|
|
||||||||||
| # Use the AMIP setup helpers to construct a coupled simulation | ||||||||||
| include(joinpath("..", "setup_run.jl")) | ||||||||||
|
|
||||||||||
| @testset "surface radiative flux consistency (AMIP + bucket land)" begin | ||||||||||
| # Build AMIP configuration used in CI by default | ||||||||||
| config_file = joinpath(pkgdir(ClimaCoupler), "config/ci_configs/amip_default.yml") | ||||||||||
| config_dict = get_coupler_config_dict(config_file) | ||||||||||
|
|
||||||||||
| # Make sure radiation is computed during the first step | ||||||||||
| config_dict["dt_rad"] = config_dict["dt"] | ||||||||||
|
|
||||||||||
| # Construct coupled simulation and run one coupling step | ||||||||||
| cs = CoupledSimulation(config_dict) | ||||||||||
| step!(cs) | ||||||||||
| boundary_space = Interfacer.boundary_space(cs) | ||||||||||
|
|
||||||||||
| # Unpack component models | ||||||||||
| (; atmos_sim, land_sim, ocean_sim, ice_sim) = cs.model_sims | ||||||||||
|
|
||||||||||
| # Atmosphere: radiative flux on the surface interface | ||||||||||
| # Convention: positive downward to the surface | ||||||||||
| atmos_flux = CC.Spaces.level( | ||||||||||
| atmos_sim.integrator.p.radiation.ᶠradiation_flux.components.data.:1, | ||||||||||
| CC.Utilities.half, | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| # Integrated land: compare to net radiation stored in the bucket cache | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| # Convention note: bucket R_n is stored with the opposite sign (see climaland_bucket.jl), | ||||||||||
| # so we compare atmos_flux ≈ -R_n on land points. | ||||||||||
|
Comment on lines
+49
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| p = land_sim.integrator.p | ||||||||||
| land_fraction = Interfacer.get_field(land_sim, Val(:area_fraction)) | ||||||||||
| land_flux = Interfacer.remap(land_sim.integrator.p.bucket.R_n, boundary_space) | ||||||||||
| @. land_flux = ifelse(land_fraction ≈ 0, zero(land_flux), land_flux) | ||||||||||
|
|
||||||||||
| err_land = @. atmos_flux - land_flux | ||||||||||
| @. err_land = ifelse(land_fraction ≈ 0, zero(err_land), err_land) | ||||||||||
| @show "Integrated land flux error: $(maximum(abs.(err_land)))" | ||||||||||
| @test maximum(abs.(err_land)) < 5 | ||||||||||
|
|
||||||||||
| # Prescribed ice: radiative fluxes aren't stored; compute from cache and compare | ||||||||||
| p = ice_sim.integrator.p | ||||||||||
| Y = ice_sim.integrator.u | ||||||||||
| FT = eltype(Y) | ||||||||||
|
|
||||||||||
| # Radiative flux toward surface (positive downward) | ||||||||||
| # TODO: get sigma from parameters | ||||||||||
| σ = FT(5.67e-8) | ||||||||||
| (; k_ice, h, T_base, ρ, c, α, ϵ) = p.params | ||||||||||
| ice_rad_flux = | ||||||||||
| (1 .- α) .* p.SW_d .+ | ||||||||||
| ϵ .* (p.LW_d .- σ .* Interfacer.get_field(ice_sim, Val(:surface_temperature)) .^ 4) | ||||||||||
| @. ice_rad_flux = ifelse(p.area_fraction ≈ 0, zero(ice_rad_flux), ice_rad_flux) | ||||||||||
| ice_fraction = Interfacer.get_field(ice_sim, Val(:area_fraction)) | ||||||||||
|
|
||||||||||
| # Prescribed ocean: SST is prescribed, but for this test we can still compute | ||||||||||
| # the radiative flux seen by the ocean surface using the same formula. | ||||||||||
| α = Interfacer.get_field(ocean_sim, Val(:surface_direct_albedo)) | ||||||||||
| ϵ = Interfacer.get_field(ocean_sim, Val(:emissivity)) | ||||||||||
| ocean_rad_flux = | ||||||||||
| (1 .- α) .* cs.fields.SW_d .+ | ||||||||||
| ϵ .* ( | ||||||||||
| cs.fields.LW_d .- | ||||||||||
| σ .* Interfacer.get_field(ocean_sim, Val(:surface_temperature)) .^ 4 | ||||||||||
| ) | ||||||||||
| ocean_fraction = Interfacer.get_field(ocean_sim, Val(:area_fraction)) | ||||||||||
| @. ocean_rad_flux = ifelse(ocean_fraction ≈ 0, zero(ocean_rad_flux), ocean_rad_flux) | ||||||||||
|
|
||||||||||
| # Combine component fluxes by area-weighted sum (incl. bucket sign convention): | ||||||||||
| combined_fluxes = | ||||||||||
| .-land_fraction .* land_flux .+ ice_fraction .* ice_rad_flux .+ | ||||||||||
| ocean_fraction .* ocean_rad_flux | ||||||||||
| err_fluxes = atmos_flux .+ combined_fluxes | ||||||||||
| @show "Combined fluxes error: $(maximum(abs.(err_fluxes)))" | ||||||||||
| @test maximum(abs.(err_fluxes)) < 8 | ||||||||||
| end | ||||||||||
This file contains hidden or 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.