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

No LinearOperator with a function-like object #8

Closed
pjaap opened this issue Oct 28, 2024 · 2 comments
Closed

No LinearOperator with a function-like object #8

pjaap opened this issue Oct 28, 2024 · 2 comments

Comments

@pjaap
Copy link
Member

pjaap commented Oct 28, 2024

The following academic code does work with a NonlinearOperator but not with a LinearOperator:

using ExtendableFEM

struct Foo end

# create a function-like object
(foo::Foo)(result,input,qpinfo) = nothing

foo = Foo()
u = Unknown("u")

LinearOperator( foo, [id(u)] )

This happens due to a strict dispatch with the type annotation Function in

function LinearOperator(kernel::Function, u_test, ops_test::Array{DataType, 1}; Tv = Float64, kwargs...)
and
mutable struct LinearOperator{Tv <: Real, UT <: Union{Unknown, Integer}, KFT <: Function, ST} <: AbstractOperator

However, this cannot be simply removed since it causes wrong dispatching in the subsequent assembly loops.

@chmerdon
Copy link
Member

I think it works, if one removes the Function in the struct parameter type and in the constructor.

The problem is another one: if the kernel of a LinearOperator depends on input, this input refers not to the evaluations of the test function (these are multiplied with the result of the kernel), but to the evaluations of the argument. However, the [id(u)] above refers to the operators that should be applied to the testfunctions, hence the constructor thinks you want to have a LinearOperator that does not depend on additional arguments. In this case the kernel has the signature
(result, qpinfo).

So, after fixing the constructor of LinearOperator as suggested: To use the foo as defined above you could define

LinearOperator(foo, [id(u)], [grad(u)])

meaning that the input of the kernel contains the gradient evaluation of u.

To use the LinearOperator as defined above you need to change the foo definition to

(foo:Foo)(result, qpinfo) = nothing

@pjaap
Copy link
Member Author

pjaap commented Oct 29, 2024

Thanks @chmerdon for the clarification. I'll try to port your suggestion to my not-so-academic script :)
Issue is resolved for me.

@pjaap pjaap closed this as completed Oct 29, 2024
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

2 participants