This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to define the value_shape of an expression class as an argument?

0 votes

Hello,

I would like to define the value_shape of an expression class passing the value as an argument.

My question is somehow related to the item 3 from this example, but i would like to define the value_shape as an argument and not constantly fixed as in the example.

I've tried to define it by calling the init but the value_shape is called before the init....

My idea would be use something like this:

class MyExpression0(Expression):
    def eval(self, value, x):
        dx = x[0] - 0.5
        dy = x[1] - 0.5
        value[0] = 500.0*exp(-(dx*dx + dy*dy)/0.02)
        value[1] = 250.0*exp(-(dx*dx + dy*dy)/0.01)
    def __init__(self, shape):
        self._shape
    def value_shape(self):
        return (self._shape,)

Any idea how to solve this?
Thanks for the help!

asked Sep 18, 2016 by lhdamiani FEniCS User (2,580 points)
...