Skip to content

Commit

Permalink
Merge pull request #391 from gridap/apply_gradient_Number_array
Browse files Browse the repository at this point in the history
Fixes to `apply_gradient` related to issue #388
  • Loading branch information
fverdugo authored Aug 27, 2020
2 parents 7e56106 + ce81643 commit a903e99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Fields/FieldOperations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ for op in (:*,⋅)

# Global level

function apply_gradient(k::Valued{FieldOpKernel{typeof($op)}},a::Number,b)
function apply_gradient(k::Valued{FieldOpKernel{typeof($op)}},a::AbstractArray{<:Number},b)
gb = field_array_gradient(b)
apply(k,a,gb)
end

function apply_gradient(k::Valued{FieldOpKernel{typeof($op)}},b,a::Number)
function apply_gradient(k::Valued{FieldOpKernel{typeof($op)}},b,a::AbstractArray{<:Number})
gb = field_array_gradient(b)
apply(k,gb,a)
end
Expand Down Expand Up @@ -534,4 +534,3 @@ function apply(k::IntKernel,f::VectorOfBlockArrayCoo{T,3} where T,w::AbstractArr
blockids = [ (ids[2], ids[3]) for ids in f.blockids ]
VectorOfBlockArrayCoo(blocks,blockids,ax)
end

9 changes: 9 additions & 0 deletions test/FieldsTests/FieldArraysTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ struct FieldPlaceHolder <: Field end
ag = apply_to_field_array(FieldPlaceHolder,FieldOpKernel(+),af,af)
test_array(evaluate_field_array(ag,ax),agx)

c = 0.5
ac = fill(c,l)
ag = apply_to_field_array(FieldOpKernel(*),ac,af)
gx = fill(c*v,np)
∇gx = fill(VectorValue(c*v,0.0),np)
agx = fill(gx,l)
a∇gx = fill(∇gx,l)
test_array_of_fields(ag,ax,agx,grad=a∇gx)

w = 2.0
aw = fill(w,l)
ag = apply_to_field_array(FieldOpKernel(+),af,aw)
Expand Down

0 comments on commit a903e99

Please sign in to comment.