Skip to content

Commit

Permalink
Merge pull request #1003 from gridap/zero_affinemap
Browse files Browse the repository at this point in the history
Add zero AffineMap helper
  • Loading branch information
santiagobadia committed Apr 28, 2024
2 parents 532e8de + 7145e70 commit 19d3db8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Fields/AffineMaps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/Fields/Fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
3 changes: 3 additions & 0 deletions test/FieldsTests/AffineMapsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 19d3db8

Please sign in to comment.