Skip to content

Commit 97b40e2

Browse files
authored
Fix grad for bivariate Fun (#247)
* fix grad * version bump to v0.7.25 * return a Fun in grad
1 parent 5fc4151 commit 97b40e2

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.7.24"
3+
version = "0.7.25"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/Operators/general/algebra.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,8 @@ mul_coefficients(A::PlusOperator,b::Fun) =
623623
mapreduce(x->mul_coefficients(x,b),+,A.ops)
624624

625625
*(A::Operator, b::AbstractMatrix{<:Fun}) = A*Fun(b)
626-
*(A::Vector{<:Operator}, b::Fun) = map(a->a*b,strictconvert(Array{Any,1},A))
626+
*(A::AbstractVector{<:Operator}, b::Fun) = map(a->a*b, A)
627+
*(A::AbstractVector{<:Operator}, b::ScalarFun) = map(a->a*b, A)
627628

628629

629630

src/PDE/KroneckerOperator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ end
450450
function (*)(ko::KroneckerOperator{<:Operator, <:ConstantOperator}, pf::ProductFun)
451451
O1, O2 = ko.ops
452452
O12 = O2.λ * O1
453-
ProductFun(map(x -> O12*x, pf.coefficients), factors(pf.space)[2])
453+
ProductFun(map(x -> O12*x, pf.coefficients), factor(pf.space, 2))
454454
end
455455

456456
function (*)(ko::KroneckerOperator, lrf::LowRankFun)

src/PDE/PDE.jl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ function Laplacian(d::BivariateSpace,k::Integer)
2222
end
2323

2424
Laplacian(d::EuclideanDomain{2}, k::Integer) = Laplacian(Space(d),k)
25-
grad(d::ProductDomain) = [Derivative(d,[1,0]),Derivative(d,[0,1])]
26-
25+
grad(d::ProductDomain) = grad(Space(d))
26+
function grad(d::BivariateSpace)
27+
n = length(factors(d))
28+
@assert n == 2 "grad for n>2 is not implemented"
29+
Vec{2}(Derivative(d, Vec{2}(1,0)), Derivative(d, Vec{2}(0,1)))
30+
end
31+
grad(f::Fun{<:BivariateSpace}) = Fun(grad(space(f)) * f)
2732

2833
function tensor_Dirichlet(d::Union{ProductDomain,TensorSpace},k)
2934
@assert nfactors(d)==2
@@ -49,15 +54,17 @@ function timedirichlet(d::Union{ProductDomain,TensorSpace})
4954
end
5055

5156

52-
# Operators on an univariate space may act on the second space of the ProductFun,
53-
# consistent with treating it as an expansion in the second space
57+
# Operators on a univariate space act on the coefficient Funs when multiplied from the left,
58+
# and on the basis of the second space when multiplied from the right.
59+
# Note that the latter produces a function, and not an operator. To obtain an operator,
60+
# right multiply by a kronecker product of operators
5461
# We re-route through _mulop to distinguish between operators on UnivariateSpace and
5562
# those on BivariateSpace
5663
function _mulop(B::Operator, ::UnivariateSpace, f::ProductFun)
5764
if isafunctional(B)
5865
Fun(factor(space(f),2),map(c->Number(B*c),f.coefficients))
5966
else
60-
ProductFun(space(f),map(c->B*c,f.coefficients))
67+
ProductFun(map(c->B*c,f.coefficients), space(f))
6168
end
6269
end
6370
*(B::Operator,f::ProductFun) = _mulop(B, domainspace(B), f)

0 commit comments

Comments
 (0)