Open CAarset opened 1 month ago
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.
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