Skip to content

coordinate_field returns a reference to the coordinates, so modifying the resulting Field modifies the underlying space #2265

@Sbozzolo

Description

@Sbozzolo
using ClimaCore.CommonSpaces
using ClimaCore.Fields
space = ExtrudedCubedSphereSpace(;
           z_elem = 10,
           z_min = 0,
           z_max = 1,
           radius = 10,
           h_elem = 10,
           n_quad_points = 4,
           staggering = CellFace()
       )
field = Fields.coordinate_field(space)
fill!(field.z, NaN)

all(isnan, parent(space.grid.face_local_geometry.coordinates.z))
# true

I mean, I guess it makes sense considering how Fields are created, but I think this is dangerous.

I personally often use Fields.coordinate_field as a starting point to create new Fields (in particular, when I want to evaulate an analytical function of the coordinates) and I wasn't expecting that modifying this Field would change the underlying space.

At minimum, this should be documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions