ufl icon indicating copy to clipboard operation
ufl copied to clipboard

`ufl.split` incompatible with `ufl.as_vector`

Open uvilla opened this issue 4 years ago • 0 comments

I found a useful case that is not correctly handled by ufl.split.

Consider the simple code snapshot below. Both broken_case and working_case return a vector-like expression, however ufl.split is unable to correctly extract the list of components for the broken case.

import dolfin as dl
import ufl

def broken_case():
    print("Construct a vector using as_vector")
    a = dl.Constant(1.)
    b = dl.Constant(2.)
    return ufl.as_vector( (a,b) )

def working_case():
    print("Construct a vector constant")
    return dl.Constant( (1., 2.) )

v = working_case()
print( ufl.split(v) )

v = broken_case()
print( ufl.split(v) )

which produces the output.

Construct a vector constant
(Indexed(Coefficient(FunctionSpace(None, VectorElement(FiniteElement('Real', None, 0), dim=2)), 0), MultiIndex((FixedIndex(0),))), Indexed(Coefficient(FunctionSpace(None, VectorElement(FiniteElement('Real', None, 0), dim=2)), 0), MultiIndex((FixedIndex(1),))))

Construct a vector using as_vector
Don't know how to split [f_1, f_2].
Traceback (most recent call last):
  File "my_tesst.py", line 18, in <module>
    print( ufl.split(v) )
  File "/Users/uvilla/anaconda3/envs/fenics-2019.1/lib/python3.7/site-packages/ufl/split_functions.py", line 61, in split
    error("Don't know how to split %s." % (v,))
  File "/Users/uvilla/anaconda3/envs/fenics-2019.1/lib/python3.7/site-packages/ufl/log.py", line 172, in error
    raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Don't know how to split [f_1, f_2].

On the other hand:

v = broken_case()
a,b= v

produces the desired effect.

Then, my question is: Would make sense to replace this error line with return v?

uvilla avatar May 19 '21 19:05 uvilla