Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use Integral in Newton solver #928

Open
eschnett opened this issue Feb 6, 2024 · 5 comments
Open

Cannot use Integral in Newton solver #928

eschnett opened this issue Feb 6, 2024 · 5 comments

Comments

@eschnett
Copy link
Contributor

eschnett commented Feb 6, 2024

I want to solve a nonlinear PDE where I impose, instead of a boundary condition, that the integral over the domain is zero. I don't know how to express this – the way I tried leads to an error (see below).

Things work if I impose that the solution is zero at a particular point (that's the second term u(0)). When I replace this by sum(Integral()*u), I receive an error about an unimplemented function.

julia> using ApproxFun

julia> newton(u -> [u(-1)-u(1), u(0), u''-1], Fun(x->1))
Fun(Chebyshev(), [0.25, 2.77556e-17, 0.25])

julia> newton(u -> [u(-1)-u(1), sum(Integral()*u), u''-1], Fun(x->1))
ERROR: MethodError: no method matching space(::ApproxFun.DualFun{Fun{Chebyshev{…}, Float64, Vector{…}}, ConstantOperator{Float64, Chebyshev{…}}})

Closest candidates are:
  space(::Fun)
   @ ApproxFunBase ~/.julia/packages/ApproxFunBase/1mBis/src/Fun.jl:339
  space(::ProductFun)
   @ ApproxFunBase ~/.julia/packages/ApproxFunBase/1mBis/src/Multivariate/ProductFun.jl:293
  space(::LowRankFun, ::Integer)
   @ ApproxFunBase ~/.julia/packages/ApproxFunBase/1mBis/src/Multivariate/LowRankFun.jl:348

I'd be happy to implement something, but as I'm new to the code I would need some pointers. For example, which function with what signature should be implemented?

@MikaelSlevinsky
Copy link
Member

What about sum(u)?

@eschnett
Copy link
Contributor Author

eschnett commented Feb 9, 2024

sum(u) works.

Is this how the definite integral should be calculated?

@jishnub
Copy link
Member

jishnub commented Feb 9, 2024

Yes, I believe this comes from Chebfun

@MikaelSlevinsky
Copy link
Member

It's in some sense just a synonym for DefiniteIntegral, but in this case the overrides for the autodiff live here https://github.com/JuliaApproximation/ApproxFun.jl/blob/master/src/Extras/autodifferentiation.jl, and this shows that sum, cumsum and integrate are more probably convenient.

@dlfivefifty
Copy link
Member

I agree it's a confusing pun. An other confusing pun is conflating operators (which should be linear functions of functions) and multiplication.

The idea behind ContinuumArrays.jl/ClassicalOrthogonalPolynomials.jl was to separate the idea of "functions as vectors" and "functions as functions". The long term plan is to make ApproxFun.jl sit on top of these other projects and make a concrete distinction between these two languages. Unfortunately ApproxFun has a lot of features so it is taking a lot of time to realise this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants