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

Difference between math expression in python and C++ in fenics

0 votes

I posted a question about the difference in the way that an expression was defined in c++ and python in some demos provided by fenics team.

I posted the question here.

https://fenicsproject.org/qa/10088/difference-in-defining-function-expression-in-python-and-c

Dr. Kent has already explained why it is done. In addition to that, it would be great if someone can explain how the two expressions are equal.

asked Jul 5, 2016 by Chaitanya_Raj_Goyal FEniCS User (4,150 points)

1 Answer

0 votes

I think this is a general problem with many programming languages.
It has nothing to do with FEniCS.
Consider the case where you have an array 'a' and you want to compute
b = cos(a) + sin(a) + a

what will happen here is that an temporal array is constructed
that holds the values of sin(a) + a. This temp array is then later
added to cos(a). If you have a more complicated expression then
many temp arrays may be constructed during the evaluation.
If you don't what this to happen, you need to vectorize
the expression.

answered Jul 5, 2016 by Kent-Andre Mardal FEniCS Expert (14,380 points)
...