diff --git a/src/diff.jl b/src/diff.jl index 5f354b03b..131a1fe0d 100644 --- a/src/diff.jl +++ b/src/diff.jl @@ -809,7 +809,7 @@ Laplacian(vars) = Nabla(vars) ⋅ Nabla(vars) function (D::ArrayDifferentialOperator)(x::SymVec) @assert length(D.vars) == length(x) "Vector must be same length as vars in Operator $(D.name)." - @arrayop (i,) unwrap((D.differentials)[i](x[i])) term=D(y) reduce=+ + @arrayop (i,) (D.differentials)[i](x[i]) term=D(y) end (D::ArrayDifferentialOperator)(x::Arr) = Arr(D(value(x))) @@ -821,9 +821,10 @@ end function LinearAlgebra.dot(D::ArrayDifferentialOperator, x::SymVec) @assert length(D.vars) == length(x) "Vector must be same length as vars in Operator $(D.name)." - sum(D(x)) + @show D(x), scalarize(D(x)) + sum(scalarize(D(x))) end -LinearAlgebra.dot(D::ArrayDifferentialOperator, x::Arr) = D ⋅ value(x) +LinearAlgebra.dot(D::ArrayDifferentialOperator, x::Arr) = Num(D ⋅ value(x)) function LinearAlgebra.dot(x::SymVec, D::ArrayDifferentialOperator) @assert length(D.vars) == length(x) "Vector must be same length as vars in Operator $(D.name)." @@ -837,16 +838,6 @@ function LinearAlgebra.dot(D1::ArrayDifferentialOperator, D2::ArrayDifferentialO (x) -> @arrayop (i,) lap(x[i]) term=(D1⋅D2)(x) reduce=+ end -function εijk_cond(i, j, k) - if (i, j, k) in [(1, 2, 3), (2, 3, 1), (3, 1, 2)] - 1 - elseif (i == j) || (j == k) || (k == i) - 0 - else - -1 - end -end - function crosscompose(a, b) v1 = x -> (a[2] ∘ b[3])(x) - (a[3] ∘ b[2])(x) v2 = x -> (a[3] ∘ b[1])(x) - (a[1] ∘ b[3])(x) @@ -884,4 +875,4 @@ Base.nameof(D::ArrayDifferentialOperator) = Symbol(D.name) function Base.:(==)(D1::ArrayDifferentialOperator, D2::ArrayDifferentialOperator) @variables x[1:length(D1.vars)] all(scalarize(isequal.(D1.vars, D2.vars))) && all(scalarize(isequal.(D1(x), D2(x)))) -end +end \ No newline at end of file diff --git a/test/diff.jl b/test/diff.jl index 7486a78e7..17dff5bc7 100644 --- a/test/diff.jl +++ b/test/diff.jl @@ -348,3 +348,41 @@ let @test isequal(expand_derivatives(Differential(t)(im*t)), im) @test isequal(expand_derivatives(Differential(t)(t^2 + im*t)), 2t + im) end + +## Vector Calculus + + +@variables x[1:3] y[1:3] + +∇ = Nabla(x) + +out = ∇(y) +@test all(isequal.(scalarize(out), [Differential(x[1])(y[1]), Differential(x[2])(y[2]), Differential(x[3])(y[3])])) + + +out = ∇ ⋅ y +@test isequal(out, Div(x)(y)) +@test isequal(out, Differential(x[1])(y[1]) + Differential(x[2])(y[2]) + Differential(x[3])(y[3])) + +out = ∇ × y +@test isequal(out, Curl(x)(y)) +@test all(isequal.(scalarize(out), [Differential(x[2])(y[3]) - Differential(x[3])(y[2]), + Differential(x[3])(y[1]) - Differential(x[1])(y[3]), + Differential(x[1])(y[2]) - Differential(x[2])(y[1])])) + + + +out = (∇ ⋅ ∇)(y) +@test isequal(out, Laplacian(x)(y)) +@test all(isequal.(scalarize(out), [Differential(x[1])(Differential(x[1])(y[1])) + Differential(x[2])(Differential(x[2])(y[1])) + Differential(x[3])(Differential(x[3])(y[1])), + Differential(x[1])(Differential(x[1])(y[2])) + Differential(x[2])(Differential(x[2])(y[2])) + Differential(x[3])(Differential(x[3])(y[2])), + Differential(x[1])(Differential(x[1])(y[3])) + Differential(x[2])(Differential(x[2])(y[3])) + Differential(x[3])(Differential(x[3])(y[3]))])) + + +out = (∇ × ∇)(y) + +@test isequal(out, Curl(x)(Curl(x)(y))) +@test all(isequal.(scalarize(out), [Differential(x[2])(Differential(x[3])(y[1])) - Differential(x[3])(Differential(x[2])(y[1])), + Differential(x[3])(Differential(x[1])(y[2])) - Differential(x[1])(Differential(x[3])(y[2])), + Differential(x[1])(Differential(x[2])(y[3])) - Differential(x[2])(Differential(x[1])(y[3]))])) +