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

CF(0) * TestFunction does not have TestFunction #73

Open
CAarset opened this issue Jul 24, 2024 · 1 comment
Open

CF(0) * TestFunction does not have TestFunction #73

CAarset opened this issue Jul 24, 2024 · 1 comment

Comments

@CAarset
Copy link

CAarset commented Jul 24, 2024

Ran into an unexpected issue applying a PDE solve to a coefficient-function-based source: The code

v = fes.TestFunction()
LinearForm(f * v * dx)

works for any CoefficientFunction f except f = CoefficientFunction(0), in which case it fails with error "Linearform must have TestFunction". The reason is apparent from

print(CoefficientFunction(0) * VV)

returning ZeroCoefficientFunction, while

print(CoefficientFunction(1) * VV)

returns

coef binary operation '*', real
coef unary operation ' ', real
coef 1, real
coef test-function diffop = Id, real

While this makes some sense from a compression perspective (0 times anything is 0), it makes applying PDE solves to a CF prone to unexpected failure, and notionally it also removes the obvious way to define a 0-LinearForm. Note that interpolating CoefficientFunction(0) to a GridFunction on the fes does work and createas a 0-LinearForm as expected, but is a step I'd rather bypass.

Minimal non-working example attached.
CF0.txt

@Horep
Copy link

Horep commented Aug 26, 2024

As a workaround, you can wrap your float with Parameter.
This prevents the error from occurring, i.e. write
f0 = CoefficientFunction(Parameter(0)).
The other way to produce a 0-LinearForm
is to write
LinearForm(fes)
which will assemble to a vector of zeroes.

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