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

What's the best way to achieve the summation operator in expression?

+1 vote

Want to make an expression for
enter image description here

(typos, should be i=1 in the figure, and missed right bracket as well)
where Ri is a random number from [-0.1,0.1]

I understand I could use random.uniform(-0.1,0.1) to get the random number, but I don't know how i could do it in the Expression(" "). And I don't know how to use do the summation operator either.

Please help.

asked Dec 6, 2014 by cutejeff FEniCS Novice (230 points)
edited Dec 6, 2014 by cutejeff

1 Answer

0 votes

I suggest you do a subclassing of the Expression class, as it is explained in the documentation of the Expression.

class MyExpression0(Expression):
    def eval(self, value, x):
        # your python code goes here like
        xval, yval = x[1], x[0]
        value[0] = xval # here you have to set the function values
        value[1] = yval # ... 
    def value_shape(self):
        return (2,)

f0 = MyExpression0()  # instantiate your Expression for use in dolfin
answered Dec 7, 2014 by Jan FEniCS User (8,290 points)
...