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

algebraic operators do not handle sympy/Matrix #145

Open
ratnania opened this issue Feb 18, 2024 · 1 comment
Open

algebraic operators do not handle sympy/Matrix #145

ratnania opened this issue Feb 18, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@ratnania
Copy link
Contributor

The algebraic operators dot, cross, inner and outer do not handle correctly Matrix objects from sympy.

We consider the following

from sympde.topology import VectorFunctionSpace, Cube, element_of
from sympde.calculus import grad, dot, inner, outer, cross, div, Transpose

from sympy import Matrix

domain = Cube()

I = Matrix([[1, 2, 3], [0, 1, 0], [0, 0, 1]])

V = VectorFunctionSpace('V', domain)

u,v = [element_of(V, name=i) for i in ['u', 'v']]

Then all the following operations lead to the same error

>>> A = Matrix([[1, 2, 3], [2, 1, 0], [3, 0, 1]])

>>> dot(A*u, v)
...
AttributeError: 'MutableDenseMatrix' object has no attribute 'is_commutative'
>>> cross(A*u, v)
...
AttributeError: 'MutableDenseMatrix' object has no attribute 'is_commutative'
>>> outer(A*u, v)
...
AttributeError: 'MutableDenseMatrix' object has no attribute 'is_commutative'

>>> D = Matrix([[div(u), 0, 0], [0, div(u), 0], [0, 0, div(u)]])

>>> inner(D,D)
...
AttributeError: 'MutableDenseMatrix' object has no attribute 'is_commutative'

The problem comes from the same piece of code when treating the Mul objects;

        if isinstance(arg1, Mul):
            a = arg1.args
        else:
            a = [arg1]

        if isinstance(arg2, Mul):
            b = arg2.args
        else:
            b = [arg2]

        args_1 = [i for i in a if not i.is_commutative]
        c1     = [i for i in a if not i in args_1]
        args_2 = [i for i in b if not i.is_commutative]
        c2     = [i for i in b if not i in args_2]

        a = reduce(mul, args_1)
        b = reduce(mul, args_2)
        c = Mul(*c1)*Mul(*c2)
@ratnania ratnania added the bug Something isn't working label Feb 18, 2024
@ratnania ratnania self-assigned this Feb 18, 2024
@e-moral-sanchez
Copy link
Contributor

We want to be able to assemble the bilinear form $\int_{\Omega} (\boldsymbol{b} \times \boldsymbol{u}) \cdot \boldsymbol{v} d \boldsymbol{x}$ using the cross product matrix.
Fixing this bug will allow us to use the matrix as intended BilinearForm((u, v), integral(domain, dot(S*u, v))), instead of having to type the expression component by component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants