I am trying to define a subclass of Expression whose value_shape is determined at run time. Here is an example:
from dolfin import *
import numpy
class MyFunction(Expression):
tensor_shape = None
def __init__(self, tensor_shape):
self.tensor_shape = tensor_shape
def eval(self, value, x):
value[:] = numpy.zeros(self.tensor_shape, dtype = numpy.float_)
def value_shape(self):
return self.tensor_shape
f = MyFunction((1, 1, ))
This fails with "TypeError: object of type 'NoneType' has no len()" because in FEniCS Expression subclass implementation, value_shape() is called before init is called. I am wondering if it is possible to get around this. Thanks.