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

How to calculate Facet average

+1 vote

What's the best way to compute the average value of a function on each facet of the mesh?

I suppose one way is to explicitly call assemble in a loop with the domain restricted to each facet in turn.. but maybe there's a better way?

asked Feb 24, 2014 by Nikolaus Rath FEniCS User (2,100 points)

1 Answer

+2 votes
 
Best answer

Could you use Crouzeix-Raviart elements?

CR = FunctionSpace(mesh, "CR", 1)
facet_avg = interpolate(function, CR)
answered Feb 25, 2014 by Øyvind Evju FEniCS Expert (17,700 points)
selected Feb 25, 2014 by Nikolaus Rath

That's clever. I didn't think of using a different finite element for this.

I was looking for something else and I saw this answer. The average value of a function it is not always equal to its value at the midpoint ... that is valid only for constants and linear polynomials.

Yes, that's why you have to use Crouzeix-Raviart elements. For CR, the value on each face is constant and thus equal to the average of the interpolated function.

Maybe I do not understand how the interpolant is computed in FEniCS, but interpolation at a point means that we take the value of the function at that point.
The average value of a function g on a facet F is
1/facet_area(F) \int_F g(s) ds.
How can that be equal to the value g(midpoint of F) which is exactly what you get when you interpolate g by using CR elements.

I was just about to write that interpolate minimizes the mean square deviation between the two functions, but then I realized that I may have confused this project. So your point may be valid.. Maybe the proper way to do this is to project into the CR space. Hm.

...