diff --git a/src/AbstractOperations/constant_field_abstract_operations.jl b/src/AbstractOperations/constant_field_abstract_operations.jl index c34544f2ed..9f8097fed0 100644 --- a/src/AbstractOperations/constant_field_abstract_operations.jl +++ b/src/AbstractOperations/constant_field_abstract_operations.jl @@ -35,5 +35,16 @@ using Oceananigans.Fields: ZeroField, ConstantField /(a::ZeroField, b::Number) = a /(a::Number, b::ZeroField) = ConstantField(a / convert(eltype(a), 0)) +# for two ZeroField +for op in (:-, :+, :*) + @eval begin + function $op(z1::ZeroField{T1, N1}, z2::ZeroField{T2, N2}) where {T1, T2, N1, N2} + T = Base.promote_type(T1, T2) + N = max(N1, N2) + return ZeroField{T, N}() + end + end +end + # Unary operations -(a::ZeroField) = a diff --git a/test/test_abstract_operations.jl b/test/test_abstract_operations.jl index 3e9c7e6cab..5a0aa9ea31 100644 --- a/test/test_abstract_operations.jl +++ b/test/test_abstract_operations.jl @@ -134,6 +134,10 @@ for arch in archs @test ZeroField() / 1 == ZeroField() @test 1 / ZeroField() == ConstantField(Inf) + @test ZeroField() + ZeroField() == ZeroField() + @test ZeroField() - ZeroField() == ZeroField() + @test ZeroField() * ZeroField() == ZeroField() + @test compute!(Field(ConstantField(1) + u)) == compute!(Field(1 + u)) @test compute!(Field(ConstantField(1) - u)) == compute!(Field(1 - u)) @test compute!(Field(ConstantField(1) * u)) == compute!(Field(1 * u))