Skip to content

Unable to output η using NetCDFWriter #4384

@HXC303

Description

@HXC303

I’m trying to output the free surface η using NetCDFWriter, but I encountered an error. Below is an example:

using Oceananigans
using NCDatasets

grid = RectilinearGrid(size = (20, 40, 100), 
                       extent=(4e5, 8e5, 2e3), 
                       topology = (Periodic, Bounded, Bounded))

model = HydrostaticFreeSurfaceModel(;           grid,
                            buoyancy = BuoyancyTracer(),
                             tracers = :b)

b0=rand(Float64, 100)
using LinearAlgebra
b0=repeat(reshape(b0,(1,1,100)),20,40,1);

set!(model, b=b0)

simulation = Simulation(model, Δt=120, stop_time=24*60*60)

fields = Dict("η" => model.free_surface.η);
simulation.output_writers[:field_writerETA] =
    NetCDFWriter(model, fields, filename="eta.nc", 
    schedule=TimeInterval(60*60), array_type = Array{Float64})

run!(simulation)

This results in the error:

ArgumentError: view indices (1:20, 1:40, 1:101) do not intersect field indices (Colon(), Colon(), 101:101)

I also tried specifying: indices=(:,:,grid.Nz+1),but then got:

ArgumentError: view indices (1:1, 1:1, 101:100) do not intersect field indices (Colon(), Colon(), 101:101)

I attempted with_halos=true, but that led to:

[ Info: Initializing simulation...
DimensionMismatch: new dimensions (26, 46, 107, 1) must be consistent with array size 1196

How can I correctly output the η variable with NetCDFWriter?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions