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

And check conservation of water also without PrognosticSurfaceTemperature #3133

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions examples/hybrid/driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,19 @@ if config.parsed_args["check_conservation"]

@info " Net energy change / total energy: $energy_conservation"
@info " Net mass change / total mass: $mass_conservation"
@info " Net water change / total water: $water_conservation"

sfc = p.atmos.surface_model

if CA.has_no_source_or_sink(config.parsed_args)
@test energy_conservation ≈ 0 atol = 50 * eps(FT)
@test mass_conservation ≈ 0 atol = 50 * eps(FT)
@test water_conservation ≈ 0 atol = 50 * eps(FT)
else
@test energy_conservation ≈ 0 atol = sqrt(eps(FT))
@test mass_conservation ≈ 0 atol = sqrt(eps(FT))
if sfc isa CA.PrognosticSurfaceTemperature
@info " Net water change: $water_conservation"
@test water_conservation ≈ 0 atol = 100 * sqrt(eps(FT))
@test water_conservation ≈ 0 atol = sqrt(eps(FT))
end
end
end
Expand Down
22 changes: 8 additions & 14 deletions src/solver/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,26 +241,20 @@ function check_conservation(sol)
energy_radiation_input,
) / energy_total

mass_conservation =
(sum(sol.u[end].c.ρ) - sum(sol.u[1].c.ρ)) / sum(sol.u[1].c.ρ)

water_conservation = zero(Spaces.undertype(axes(sol.u[end].c.ρ)))
water_surface_change = zero(Spaces.undertype(axes(sol.u[end].c.ρ)))
water_total = sum(sol.u[end].c.ρq_tot)
water_atmos_change = sum(sol.u[end].c.ρq_tot) - sum(sol.u[1].c.ρq_tot)
Sbozzolo marked this conversation as resolved.
Show resolved Hide resolved

if sfc isa PrognosticSurfaceTemperature
# water
water_total = sum(sol.u[end].c.ρq_tot)
water_atmos_change = sum(sol.u[end].c.ρq_tot) - sum(sol.u[1].c.ρq_tot)
water_surface_change = horizontal_integral_at_boundary(
sol.u[end].sfc.water .- sol.u[1].sfc.water,
)

mass_conservation =
(sum(sol.u[end].c.ρ) - sum(sol.u[1].c.ρ) + water_surface_change) /
sum(sol.u[1].c.ρ)

water_conservation =
abs(water_atmos_change + water_surface_change) / water_total
end
mass_conservation =
(sum(sol.u[end].c.ρ) - sum(sol.u[1].c.ρ) + water_surface_change) /
sum(sol.u[1].c.ρ)
water_conservation =
abs(water_atmos_change + water_surface_change) / water_total

return (; energy_conservation, mass_conservation, water_conservation)
end
Loading