|
| 1 | +import Oceananigans as OC |
| 2 | +import ClimaOcean as CO |
| 3 | +import ClimaCoupler: Checkpointer, FieldExchanger, FluxCalculator, Interfacer, Utilities |
| 4 | +import ClimaComms |
| 5 | +import ClimaCore as CC |
| 6 | +import Thermodynamics as TD |
| 7 | +import ClimaOcean.EN4: download_dataset |
| 8 | +using KernelAbstractions: @kernel, @index, @inbounds |
| 9 | + |
| 10 | +""" |
| 11 | + ClimaSeaIceSimulation{SIM, A, OPROP, REMAP} |
| 12 | +
|
| 13 | +The ClimaCoupler simulation object used to run with Oceananigans. |
| 14 | +This type is used by the coupler to indicate that this simulation |
| 15 | +is an surface/ocean simulation for dispatch. |
| 16 | +
|
| 17 | +It contains the following objects: |
| 18 | +- `sea_ice::SIM`: The ClimaSeaIce simulation object. |
| 19 | +- `area_fraction::A`: A ClimaCore Field representing the surface area fraction of this component model on the exchange grid. |
| 20 | +- `melting_speed::MS`: An constant characteristic speed for melting/freezing. |
| 21 | +- `remapping::REMAP`: Objects needed to remap from the exchange (spectral) grid to Oceananigans spaces. |
| 22 | +""" |
| 23 | +struct ClimaSeaIceSimulation{SIM,A,MS,REMAP} <: Interfacer.SeaIceModelSimulation |
| 24 | + sea_ice::SIM |
| 25 | + area_fraction::A |
| 26 | + melting_speed::MS |
| 27 | + remapping::REMAP |
| 28 | +end |
| 29 | + |
| 30 | +""" |
| 31 | + ClimaSeaIceSimulation() |
| 32 | +
|
| 33 | +Creates an OceananigansSimulation object containing a model, an integrator, and |
| 34 | +a surface area fraction field. |
| 35 | +This type is used to indicate that this simulation is an ocean simulation for |
| 36 | +dispatch in coupling. |
| 37 | +
|
| 38 | +Specific details about the default model configuration |
| 39 | +can be found in the documentation for `ClimaOcean.ocean_simulation`. |
| 40 | +""" |
| 41 | +function ClimaSeaIceSimulation(area_fraction, ocean; output_dir) |
| 42 | + # Initialize the sea ice with the same grid as the ocean |
| 43 | + # Initially no sea ice is present |
| 44 | + grid = ocean.ocean.model.grid |
| 45 | + advection = ocean.ocean.model.advection.T |
| 46 | + sea_ice = CO.sea_ice_simulation(grid, ocean.ocean; advection) |
| 47 | + |
| 48 | + melting_speed = 1e-4 |
| 49 | + remapping = ocean.remapping |
| 50 | + |
| 51 | + # Before version 0.96.22, the NetCDFWriter was broken on GPU |
| 52 | + if arch isa OC.CPU || pkgversion(OC) >= v"0.96.22" |
| 53 | + # TODO maybe this is broken |
| 54 | + # Save all tracers and velocities to a NetCDF file at daily frequency |
| 55 | + outputs = prognostic_fields(sea_ice.model) |
| 56 | + netcdf_writer = OC.NetCDFWriter( |
| 57 | + sea_ice.model, |
| 58 | + outputs; |
| 59 | + schedule = OC.TimeInterval(86400), # Daily output |
| 60 | + filename = joinpath(output_dir, "seaice_diagnostics.nc"), |
| 61 | + indices = (:, :, grid.Nz), |
| 62 | + overwrite_existing = true, |
| 63 | + array_type = Array{Float32}, |
| 64 | + ) |
| 65 | + sea_ice.output_writers[:diagnostics] = netcdf_writer |
| 66 | + end |
| 67 | + |
| 68 | + sim = ClimaSeaIceSimulation(sea_ice, area_fraction, melting_speed, remapping) |
| 69 | + return sim |
| 70 | +end |
0 commit comments