CliMA / Oceananigans.jl

🌊 Julia software for fast, friendly, flexible, ocean-flavored fluid dynamics on CPUs and GPUs
https://clima.github.io/OceananigansDocumentation/stable
MIT License
991 stars 194 forks source link

`NetCDFOutputWriter` cannot find `default_dimension_attributes` for immersed boundary grids #3069

Closed Yixiao-Zhang closed 1 year ago

Yixiao-Zhang commented 1 year ago

These lines do not work for ImmersedBoundaryGrid.

https://github.com/CliMA/Oceananigans.jl/blob/be00e364f9dcd712b3d0c3d48e32b94b181a02fc/src/OutputWriters/netcdf_output_writer.jl#L391-L395

Changing the first line to

if model.grid isa AbstractRectilinearGrid || model.grid isa ImmersedBoundaryGrid{<:Any,<:Any,<:Any,<:Any,<:AbstractRectilinearGrid}

temporarily fixed my problem. Here is the script that I use for testing this issue:

using Oceananigans

underlying_grid = RectilinearGrid(
        size=(32, 32, 16),
        x=(-3.0, 3.0), y=(-3.0, 3.0), z=(0.0, 1.0),
        topology=(Periodic, Periodic, Bounded),
        halo=(4, 4, 4),
)

hill(x::Real, y::Real) = 0.1 + 0.1 * exp(-x^2 - y^2)

grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(hill))

model = NonhydrostaticModel(;
    grid,
    advection = WENO(),
)

simulation = Oceananigans.Simulation(model; Δt = 1.0, stop_time = 100.0)

fields = model.velocities

simulation.output_writers[:fields] = NetCDFOutputWriter(
    model,
    fields,
    filename = "output.nc",
    schedule = Oceananigans.TimeInterval(10.0),
)

run!(simulation)
Yixiao-Zhang commented 1 year ago

A better solution might be to define a function for default_dimension_attributes:

function find_default_dimension_attributes(grid::AbstractRectilinearGrid)
    return default_dimension_attributes_rectilinear
end

function find_default_dimension_attributes(grid::AbstractCurvilinearGrid)
    return default_dimension_attributes_curvilinear
end

function find_default_dimension_attributes(grid::ImmersedBoundaryGrid)
    return find_default_dimension_attributes(grid.underlying_grid)
end