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

BUG: += does not assign when combining multiple Cofunctions #3182

Open
pbrubeck opened this issue Oct 21, 2023 · 1 comment
Open

BUG: += does not assign when combining multiple Cofunctions #3182

pbrubeck opened this issue Oct 21, 2023 · 1 comment
Assignees
Labels

Comments

@pbrubeck
Copy link
Contributor

pbrubeck commented Oct 21, 2023

Describe the bug

The Cofunction.__iadd__ method is not using assign when the update consisits of a (weighted) sum of Cofunctions. Instead it returns a FormSum, as opposed to the same operation on Functions, where we numerically compute the linear combination and accumulate the result in the LHS.

Steps to Reproduce

from firedrake import *

mesh = UnitIntervalMesh(2)
V = FunctionSpace(mesh, "CG", 1)

V = V.dual()
b = Function(V)
clist = [Function(V) for k in range(3)]
btype = type(b)

b.dat.data_wo[...] = 1
for c in clist:
    c.dat.data_wo[...] = 1

# this uses assign with Functions and Cofunctions
b += clist[0]
assert type(b) == btype, "b is now a %s" % type(b).__name__

# this only uses assign with Functions
b += clist[0] + clist[1]
assert type(b) == btype, "b is now a %s" % type(b).__name__

Expected behavior

+= should be consistent with Functions and Cofunctions. As these are well defined vector spaces, we have closure of linear combinations. I would expect += to use assign if I'm adding several Cofunctions

Error message

Traceback (most recent call last):
  File "/home/brubeckmarti/git/dphil_thesis/static_condensation/snippets/bug_cofunction.py", line 21, in <module>
    assert type(b) == btype, "b is now a %s" % type(b).__name__
AssertionError: b is now a FormSum
@pbrubeck pbrubeck added the bug label Oct 21, 2023
@pbrubeck pbrubeck changed the title BUG: += does not assign when combining multiple Cofunctions BUG: += does not assign when combining multiple Cofunctions Oct 21, 2023
@Ig-dolci
Copy link
Contributor

I am interested in this issue. I will dig into this.

@Ig-dolci Ig-dolci self-assigned this Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants