Skip to content

Regridding a constant field from TripolarGrid to CubedSphere introduces extrema #63

@juliasloan25

Description

@juliasloan25

When we regrid a constant, non-zero field from the Oceananigans TripolarGrid to ClimaCore CubedSphere, new extrema are introduced. When we run without RightFaceFolded, there are zeros along the southernmost latitudes and new maxima near the northern latitudes. When we run with RightFaceFolded, the southern zeros remain but we don't see the unusual pattern in northern latitudes.

I'm running this on a branch with the fixes from both #60 and #56

Regridding a field of ones without RightFaceFolded

Dest field

Image
To reproduce
using ConservativeRegridding
using ConservativeRegridding: Trees
import GeometryOps as GO, GeoInterface as GI, LibGEOS

using ClimaCore:
    CommonSpaces, Fields, Spaces, RecursiveApply, Meshes, Quadratures, Topologies, Domains, ClimaComms
using Oceananigans

const ClimaCoreExt = Base.get_extension(ConservativeRegridding, :ConservativeRegriddingClimaCoreExt)

    tripolar_grid = TripolarGrid(size=(360, 180, 1))
    cubedsphere_space = CommonSpaces.CubedSphereSpace(;
        radius = tripolar_grid.radius,
        n_quad_points = 2,
        h_elem = 32,
    )

    # Set the source field to a constant, non-zero value
    src_tripolar = Field{Center, Center, Nothing}(tripolar_grid)
    set!(src_tripolar, src_tripolar + 1)

    dst_cubedsphere = zeros(cubedsphere_space)
    ones_cubedsphere = ones(cubedsphere_space)
    cubed_sphere_vals = zeros(Meshes.nelements(cubedsphere_space.grid.topology.mesh))

    regridder = ConservativeRegridding.Regridder(cubedsphere_space, tripolar_grid)

    ConservativeRegridding.regrid!(cubed_sphere_vals, regridder, vec(interior(src_tripolar)))

    ClimaCoreExt.set_value_per_element!(dst_cubedsphere, cubed_sphere_vals)
    @show extrema(dst_cubedsphere) # Should be (1.0, 1.0) but we get (0.0, 1.707097145678124)

    # using ClimaCoreMakie, Makie, CairoMakie
    # fig = Figure();
    # ax = Axis(fig[1, 1])
    # hm = fieldheatmap!(ax, dst_cubedsphere)
    # Colorbar(fig[:, 2], hm)
    # fig

Regridding a field of ones with RightFaceFolded

Dest field

Image
To reproduce
using ConservativeRegridding
using ConservativeRegridding: Trees
import GeometryOps as GO, GeoInterface as GI, LibGEOS

using ClimaCore:
    CommonSpaces, Fields, Spaces, RecursiveApply, Meshes, Quadratures, Topologies, Domains, ClimaComms
using Oceananigans

const ClimaCoreExt = Base.get_extension(ConservativeRegridding, :ConservativeRegriddingClimaCoreExt)

    tripolar_grid = TripolarGrid(size=(360, 180, 1), fold_topology = RightFaceFolded)
    cubedsphere_space = CommonSpaces.CubedSphereSpace(;
        radius = tripolar_grid.radius,
        n_quad_points = 2,
        h_elem = 16,
    )

    # Set the source field to a constant, non-zero value
    src_tripolar = Field{Center, Center, Nothing}(tripolar_grid)
    set!(src_tripolar, src_tripolar + 1)

    dst_cubedsphere = zeros(cubedsphere_space)
    ones_cubedsphere = ones(cubedsphere_space)
    cubed_sphere_vals = zeros(Meshes.nelements(cubedsphere_space.grid.topology.mesh))

    regridder = ConservativeRegridding.Regridder(cubedsphere_space, tripolar_grid)

    ConservativeRegridding.regrid!(cubed_sphere_vals, regridder, vec(interior(src_tripolar)))

    ClimaCoreExt.set_value_per_element!(dst_cubedsphere, cubed_sphere_vals)
    @show extrema(dst_cubedsphere) # Should be (1.0, 1.0) but we get (0.0 1.000000000000009)

    # using ClimaCoreMakie, Makie, CairoMakie
    # fig = Figure();
    # ax = Axis(fig[1, 1])
    # hm = fieldheatmap!(ax, dst_cubedsphere)
    # Colorbar(fig[:, 2], hm)
    # fig

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