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

How to compute the elementwise mean value of a vector-valued function and to assign it to a vector-valued FEM function

0 votes

Hi,

I have an expression of the form

b = Expression(('x[0]', 'x[1]'))

and I would like to compute its element-wise mean value.

mean_val_b1 = assemble((1.0/cell_volume)*b[0]*wh*dx)
mean_val_b2 = assemble((1.0/cell_volume)*b[1]*wh*dx)

where

W = FunctionSpace(mesh, "DG", 0)
wh = TestFunction(W)

First of all, can I do that by using

W2  = VectorFunctionSpace(mesh, "DG", 0)
wh2 = TestFunction(W2)

In any case I would like to represent the element-wise mean value as a Function(W2).

How can I access the values of a W2-function (the 2D vector) at each dof?

Thank you in advance!

asked Jan 31, 2014 by fotini.karakatsani FEniCS Novice (500 points)
edited Jan 31, 2014 by fotini.karakatsani

1 Answer

+1 vote
W2  = VectorFunctionSpace(mesh, "DG", 0)
mean_val = project((1.0/cell_volume)*b, W2)

How can I access the values of a W2-function (the 2D vector) at each dof?

print 'value at coords 42.0, 616.0:', mean_val(42.0, 616.0)
answered Feb 3, 2014 by Jan Blechta FEniCS Expert (51,420 points)
...