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

Combining functions

0 votes

Hi,

Is there a way to build a Function() from a combination of other functions. For example, if I have two Functions f and g, then

w = f+g

suits most of my purposes. However, when I try to save this

File("w.pvd") << w

I receive an error "argument 2 of type 'dolfin::Function const &'". This is presumably because w is not actually a Function(). Is there a way to explicitly convert w to a Function ?

Thanks

asked Jun 14, 2014 by sixtysymbols FEniCS User (2,280 points)

1 Answer

+2 votes
 
Best answer

Hi, projecting f+g to some function space V will give you a function in V that you can
save to file

w = project(f + g, V)

As an alternative, if f, g are in the same function, you could get w in V by adding the
expansion coefficents

w = Function(V)                                                                
w.vector().axpy(1, f.vector())    # w has same exp. coeff as f                                       
w.vector().axpy(1, g.vector())    # w is now f+g 
answered Jun 14, 2014 by MiroK FEniCS Expert (80,920 points)
selected Jun 14, 2014 by sixtysymbols
...