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

How to make Function/Expression that represents series?

0 votes

I've presented solution of my PDE in form of series. So I want to calculate an error of FEM-solution.
Let uh be FEM-solution, u - exact solution (series).
I want to run this:

errornorm(u, uh, norm_type='l2')

How can I get Expression for finite sum (that approximates series)?

My ideas:

  1. to make Expressions for all summands and sum them. But sum of Expressions returns ufl.algebra.Sum that is unsuitable for errornorm. Maybe there is some way to transform it into Expression?
  2. to make str for my sum and put it in Expression init. This approach is very wasteful for sums with large amount of summands.

Or maybe there is some function for getting sum?

asked Mar 23, 2016 by Illusion FEniCS Novice (290 points)

1 Answer

+2 votes

Hi,
consider:

from dolfin import *

mesh = UnitSquareMesh(20, 20)
V = FunctionSpace(mesh, "CG", 1)

u = Function(V)

f = Expression("sin(i*x[0])*cos(j*x[1])", i = 0.0, j = 0.0)
for i in range(1,10):
    f.i = i
    for j in range(1,10):
        f.j = j
        u.vector()[:] += ( interpolate(f, V) ).vector()
        plot(u, interactive=True)
answered Mar 23, 2016 by hernan_mella FEniCS Expert (19,460 points)
edited Apr 26, 2016 by hernan_mella
...