Skip to content

Commit

Permalink
Merge pull request #340 from gridap/gradient_scalar_product
Browse files Browse the repository at this point in the history
Gradient scalar product
  • Loading branch information
fverdugo authored Aug 4, 2020
2 parents b682b9c + b85e637 commit e01557b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Fields/FieldOperations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ end

function kernel_testitem!(
c,k::FieldBinOp,a::AbstractMatrix,b::AbstractVector)
if _valid_checks_matvec(a,b)
if _valid_checks_matvec(a,b)
apply_kernel!(c,k,a,b)
else
c.array
Expand Down Expand Up @@ -284,3 +284,18 @@ for op in (:+,:-)
end
end

for op in (:*,:/)
@eval begin

function apply_kernel_gradient(k::FieldBinOp{typeof($op)},a::Number,b)
gb = field_gradient(b)
apply_kernel_to_field(k,a,gb)
end

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

end
end
6 changes: 6 additions & 0 deletions test/FieldsTests/FieldOperationsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,10 @@ agx = fill(gx,l)
∇agx = fill(∇gx,l)
test_array_of_fields(ag,ax,agx,grad=∇agx)

g = field_operation(*,va,fa)
gx = [*(va,ai) for ai in fax]
∇gx = [*(va,ai) for ai in ∇fax]
test_field(g,x,gx,grad=∇gx)


end # module

0 comments on commit e01557b

Please sign in to comment.