Subclassing Expression with non-hard-coded value_shape
Is it possible to subclass Expression without hard-coding the value_shape? For example, I would like to do something like
class ExpSubClass(
def __init__(self, V, **kwargs):
self.ndims = kwargs['ndims']
def eval_cell(self, values, x, ufc_cell):
values[:] = whatever....
def value_shape(self):
return self.ndims, # instead of "return 3," for example
But if I do this, I get the following error:
Traceback (most recent call last):
....
File "/home/
element = _auto_select_
File "/scratch/
return self.ndims,
AttributeError: 'ExpSubClass' object has no attribute 'ndims'
After some testing, it would appear that value_shape gets called before __init__ . I have read the documentation about subclassing Expression which says **kwargs should be used, but I'm not sure if I have understood the "magic behind the scenes" correctly :)
Thanks.
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Mikael Mortensen
- Solved:
- Last query:
- Last reply: