I need to use analytically calculated expansion coefficients for a Function. Calculation of each coefficient is relatively costly (it is the magnetic field from a coil, calculated by integration over the coil) and I've found that use of Expression is extremely inefficient.

In previous (1.0?) version of dolfin the coefficients were stored quite naturally and I was able get vector of coefficients with function.vector() and simply fill it. Now the scheme is much more complicated and (I guess) I need to access the dof map and use it, but it seems to be a tricky and not stable solution.

Is there any other method?

A quick comment for latecomers like me: In newer versions of FEniCS,

has become: