Skip to content

Add an energy conservation example and test#186

Open
simone-silvestri wants to merge 56 commits into
mainfrom
ss/test-conservation
Open

Add an energy conservation example and test#186
simone-silvestri wants to merge 56 commits into
mainfrom
ss/test-conservation

Conversation

@simone-silvestri
Copy link
Copy Markdown
Member

This PR introduces an energy conservation example and a test for energy conservation.
It depends on the fixes scattered through here and ClimaSeaIce (#164 and https://github.com/CliMA/ClimaSeaIce.jl/pulls).

The freshwater flux is also calculated but not balanced, so when the issue of energy conservation is resolved and this is merged I will focus on tracking down mass conservation

simone-silvestri and others added 30 commits April 15, 2026 12:55
- Bathymetry: minor fix in regrid_bathymetry
- DataWrangling: inpainting and restoring improvements
- Diagnostics: MLD minor update
- EarthSystemModels: simplify time stepping, minor earth_system_model cleanup
- InterfaceComputations: minor refactors in sea_ice_ocean fluxes and heat flux formulations

Note: Ocean simulation refactoring (flux_and_restoring, Oceans.jl, ocean_simulation.jl)
and Diagnostics (interface_fluxes) are handled in PR #155 and #158.
- Bathymetry: minor fix in regrid_bathymetry
- DataWrangling: inpainting and restoring improvements
- Diagnostics: interface flux diagnostics and MLD updates
- Oceans: refactor ocean simulation, extract flux_and_restoring
- EarthSystemModels: simplify time stepping, minor earth_system_model cleanup
- InterfaceComputations: minor refactors in sea_ice_ocean fluxes and heat flux formulations
New type SeaIceAlbedo implementing the CCSM3 albedo parameterization
(Briegleb et al. 2004):
- Broadband albedos: bare ice 0.54, snow-covered 0.83
- Temperature-dependent reduction near melting (implicit melt ponds)
- Thin-ice transition to ocean albedo below 0.5 m
- Snow cover blending (full snow albedo at hs > 0.02 m)
- Handles nothing snow_thickness gracefully

Also evaluates state-dependent albedo to scalar via stateindex at
the top of the atmosphere-sea ice flux kernel, fixing a potential
struct-in-arithmetic bug when the albedo is not a plain number.

Changes to atmosphere_sea_ice_fluxes.jl:
- Evaluate radiation properties (α, ϵ) via stateindex before iteration
- Pass local_interface_properties with scalar values to compute_interface_state
- Add hs (snow thickness) to local_interior_state
- Rename h → hi for ice thickness in interior state

References:
- Briegleb et al. (2004): NCAR Tech Note
- Briegleb & Light (2007): NCAR/TN-472+STR
- Add Adapt.adapt_structure for InterfaceProperties so that
  SeaIceAlbedo Fields are properly adapted for GPU kernels
- Fix get_snow_thickness call to pass grid argument

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Snow support for OMIP simulations:

Sea ice model changes:
- sea_ice_simulation: add with_snow, snow_conductivity, snowfall kwargs
- Update imports for ClimaSeaIce ss/snow-model (SlabThermodynamics,
  sea_ice_slab_thermodynamics, snow_slab_thermodynamics)
- default_ai_temperature dispatches on IceSnowConductiveFlux when snow present
- Add snowfall to net_fluxes (top fluxes NamedTuple)
- Sea ice exchanger state: rename h → hi, add hs (snow thickness)

Surface temperature solve:
- New flux_balance_temperature dispatch for IceSnowConductiveFlux
  using combined resistance R = hs/ks + hi/ki
- Refactored into shared conductive_flux_balance_temperature (DRY)
- ConductiveFlux dispatch updated: Ψi.h → Ψi.hi

Snowfall routing:
- Atmosphere exchanger: add Jˢⁿ field (interpolated snow flux)
- Interpolation kernel: interpolate snow component separately
- Sea ice flux assembly: write Jˢⁿ into top_fluxes.snowfall
- ClimaSeaIce reads model.snowfall during thermodynamic step

Requires ClimaSeaIce >= 0.4.8 (snow-model branch merged).
ice_heat_capacity → heat_capacity, ice_density → density

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Strip out changes that belong to other PRs or branches:
- FluxAndRestoring struct and plumbing (separate PR)
- Bottom drag rework (drag_bulk_velocity, Uᴮ)
- Barotropic potential toggle, clock kwarg, materialize_buoyancy_gradients
- TKE advection change, meridional heat transport deletion
- Bathymetry minimum depth, inpainting NaN fill, restoring extract_field_time_series
- Sea ice albedo (CCSM3 scheme) and Adapt for InterfaceProperties (PR #163)
- ocean_surface_salinity/temperature view change

Keep only snow model integration: snow thermodynamics, snowfall routing,
IceSnowConductiveFlux flux balance, hs in exchanger and interior state.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Unit tests:
- sea_ice_simulation with/without snow (with_snow kwarg)
- PhaseTransitions API (heat_capacity/density kwargs)
- ComponentExchanger includes hs (ZeroField without snow, Field with snow)
- default_ai_temperature dispatches on ConductiveFlux vs IceSnowConductiveFlux
- net_fluxes includes snowfall
- Thermal resistance: R_snow > R_ice

Integration tests:
- Coupled model without snow (time_step succeeds)
- Coupled model with snow (time_step succeeds)
- Snowfall routing: Jsn in exchanger, snowfall in net fluxes
- Snow insulation: IceSnowConductiveFlux wired with correct conductivities

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Build two coupled models (bare ice vs ice+snow), time-step both,
verify the snowy surface temperature is warmer due to added thermal
resistance from the snow layer.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Already covered by test_ocean_sea_ice_model.jl.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When with_snow=false, sea_ice.model.snowfall is a ConstantField(0) which
cannot be written to. Always allocate a writable Field for the net snowfall
flux since the kernel writes into it unconditionally.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Monkey-patch restore_prognostic_state! for SeaIceModel so that old
checkpoints (saved before snow_thickness was added to the model) can
be restored without error. The snow_thickness field is only restored
if present in the checkpoint state; otherwise it is silently skipped.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rature dispatch

Two fixes from ss/omip-prototype debugging:

1. default_snow_thermodynamics: pass PrescribedTemperature as the snow
   top heat BC. Without this, ClimaSeaIce runs its own surface temperature
   solve (MeltingConstrainedFluxBalance) that conflicts with NumericalEarth's
   coupled flux solver, producing NaN on the first time step.

2. atmosphere_sea_ice_interface: use snow_thermo.top_surface_temperature
   when snow is present. The atmosphere interacts with the snow surface,
   not the ice-snow interface.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
These were accidentally included from the omip-prototype branch.
The experiments/ directory belongs in ss/omip-prototype, not here.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…/NumericalEarth.jl into ss/snow-model-integration
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread examples/coupled_conservation.jl Outdated
Base automatically changed from ss/snow-model-integration to main May 12, 2026 12:40
An error occurred while trying to automatically change base from ss/snow-model-integration to main May 12, 2026 12:40
Comment thread src/Atmospheres/interpolate_atmospheric_state.jl Outdated
Comment thread Project.toml Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants