How to smoothen a function on the boundary

Hi all,

I have a time dependent function that starts acting rather strange on the boundary after some time. Below is an image of it using Warp by Scalar feature in Paraview.

You can see how jagged it is at the boundary. These are things I have done and hasn’t worked:
1- I have used projections onto spaces with CR, CG and DG elements with low and high degrees. But it didn’t help.
2- I have used very fine mesh close to the boundary but it didn’t work.
3- I have used mesh and boundary smoothing at each time step and that didn’t work.
4- I have done all of the above together with no luck.
I was thinking about replacing the values of the function at the boundary with the average of the function over the boundary but I don’t know how to do so. Can you send me a mini code that does that? Or let me know if you have other easier suggestions to solve this problem.

Best,

It would be helpful if you could provide more context (i.e. the function you’re attempting to discretise) and a MWE.

Well. The function comes from a complex system of PDEs. But if you can make it work for the following It can be done for my case as well. Suppose you don’t know where the function f comes from. How can you set its value on the boundary to be the average of its current values on the boundary?

from dolfin import *
meshlevel =10
degree = 1
dim = 2
mesh = UnitDiscMesh.create(MPI.comm_world, meshlevel, degree, dim)

S = FunctionSpace(mesh,'P',1)

F = Expression('exp(cos(10*x[0])*sin(10*x[1]))',degree=0)

f = project(F,S)

File('test/test.pvd')<<f