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

Difference in defining function expression in python and c++

+1 vote

Dear all,

The expression for acceleration vector update in python for elastodynamics is shown below:

a_vec = (1.0/(2.0*beta))*( (u_vec - u0_vec - v0_vec*dt)/(0.5*dt*dt) - (1.0-2.0*beta)*a0_vec )

I was looking at elastodynamics demo in c++ at the foolowing link:

https://github.com/FEniCS/dolfin/blob/master/demo/undocumented/elastodynamics/cpp/main.cpp

Here, they define the same expression as:

// Acceleration update

void update_a(Function& a, const Function& u, const Function& a0,
              const Function& v0,  const Function& u0,
              double beta, double dt)
{
  *a.vector()  = *u.vector();
  *a.vector() -= *u0.vector();
  *a.vector() *= 1.0/dt;
  *a.vector() -= *v0.vector();
  *a.vector() *= 1.0/((0.5-beta)*dt);
  *a.vector() -= *a0.vector();
  *a.vector() *= (0.5-beta)/beta;
}

Can some one please shed some light on why the same math expression is defined like this? I can't even make out if it is the same. Thanks!

asked May 12, 2016 by Chaitanya_Raj_Goyal FEniCS User (4,150 points)
edited May 12, 2016 by Chaitanya_Raj_Goyal

1 Answer

0 votes

You may speed up the computations significantly by explicitly writing
out the linear algebra operations in this way. In particular
temporary arrays may be constructed behind the scene if
you just write it out in Python like in the first example.

answered May 13, 2016 by Kent-Andre Mardal FEniCS Expert (14,380 points)

Thank you very much for your reply Dr. Mardal.

Is this described in more detail in any section of fenics manual/ book or any other document in your knowledge?

...