Skip to content

ConstantField cannot be used for isapprox #4937

@glwagner

Description

@glwagner

What I want to do:

using Oceananigans
grid = RectilinearGrid(size=(4, 4, 4), extent=(1, 1, 1))
c = CenterField(grid)
c  Oceananigans.Fields.ConstantField(1)

gives

ERROR: FieldError: type Oceananigans.Fields.ConstantField has no field `grid`, available fields: `constant`
Stacktrace:
 [1] getproperty
   @ ./Base_compiler.jl:54 [inlined]
 [2] norm(a::Oceananigans.Fields.ConstantField{Int64, 3}; condition::Nothing)
   @ Oceananigans.Fields ~/Projects/Oceananigans.jl/src/Fields/field.jl:647
 [3] norm(a::Oceananigans.Fields.ConstantField{Int64, 3})
   @ Oceananigans.Fields ~/Projects/Oceananigans.jl/src/Fields/field.jl:646
 [4] isapprox(x::Field{Center, Center, Center, Nothing, RectilinearGrid{…}, Tuple{…}, OffsetArrays.OffsetArray{…}, Float64, FieldBoundaryConditions{…}, Nothing, Nothing}, y::Oceananigans.Fields.ConstantField{Int64, 3}; atol::Int64, rtol::Float64, nans::Bool, norm::typeof(LinearAlgebra.norm))
   @ LinearAlgebra ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/LinearAlgebra/src/generic.jl:1984
 [5] isapprox(x::Field{Center, Center, Center, Nothing, RectilinearGrid{…}, Tuple{…}, OffsetArrays.OffsetArray{…}, Float64, FieldBoundaryConditions{…}, Nothing, Nothing}, y::Oceananigans.Fields.ConstantField{Int64, 3})
   @ LinearAlgebra ~/.julia/juliaup/julia-1.12.1+0.aarch64.apple.darwin14/share/julia/stdlib/v1.12/LinearAlgebra/src/generic.jl:1978
 [6] top-level scope
   @ REPL[5]:1
Some type information was truncated. Use `show(err)` to see complete types.

maybe we can just define norm for ConstantField.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions