From 7145e702de5c542d6c0e88602fdf846d5fbe749f Mon Sep 17 00:00:00 2001 From: Pere Antoni Martorell Date: Fri, 26 Apr 2024 17:00:29 +0200 Subject: [PATCH] add zero affine map function --- src/Fields/AffineMaps.jl | 6 ++++++ src/Fields/Fields.jl | 1 + test/FieldsTests/AffineMapsTests.jl | 3 +++ 3 files changed, 10 insertions(+) diff --git a/src/Fields/AffineMaps.jl b/src/Fields/AffineMaps.jl index 239d09530..9ce5725fc 100644 --- a/src/Fields/AffineMaps.jl +++ b/src/Fields/AffineMaps.jl @@ -108,3 +108,9 @@ function lazy_map(::typeof(∇),a::LazyArray{<:Fill{typeof(affine_map)}}) gradients = a.args[1] lazy_map(constant_field,gradients) end + +function Base.zero(::Type{<:AffineMap{D1,D2,T}}) where {D1,D2,T} + gradient = TensorValue{D1,D2}(tfill(zero(T),Val{D1*D2}())) + origin = Point{D2,T}(tfill(zero(T),Val{D2}())) + AffineMap(gradient,origin) +end diff --git a/src/Fields/Fields.jl b/src/Fields/Fields.jl index 0326604c4..05e5e7a56 100644 --- a/src/Fields/Fields.jl +++ b/src/Fields/Fields.jl @@ -8,6 +8,7 @@ import Gridap.Arrays: testitem using Gridap.Helpers: @abstractmethod, @notimplemented using Gridap.Helpers: @notimplementedif, @unreachable, @check +using Gridap.Helpers: tfill using Gridap.Algebra: mul! diff --git a/test/FieldsTests/AffineMapsTests.jl b/test/FieldsTests/AffineMapsTests.jl index bd205296a..284aaec1d 100644 --- a/test/FieldsTests/AffineMapsTests.jl +++ b/test/FieldsTests/AffineMapsTests.jl @@ -39,6 +39,9 @@ cell_to_∇hx = lazy_map(evaluate,cell_to_∇h,cell_to_x) test_array(cell_to_hx,fill(hx,ncells)) test_array(cell_to_∇hx,fill(∇hx,ncells)) +T = AffineMap{3,3,Int} +@test isa(zero(T),T) + #display(cell_to_hx) #display(cell_to_∇hx) #print_op_tree(cell_to_hx)