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

Simple smoothing

+1 vote

Does anyone have a good (MPI friendly) technique to spatially smooth a function?
I want a random field for an initial condition, but varying more slowly than the mesh vertices. A convolution would do for example but I'm not sure how to go about doing that in FEniCS?

Thanks!

asked Jun 19, 2014 by mwelland FEniCS User (8,410 points)

In lieu of a better (read: more direct) method, I just slapped together a simple diffusion model which smooths things out:

psm = TrialFunction(V1)
psmOld = interpolate(InitialCondition(), V1)
test_psm = TestFunction(V1)
asm = ( psm*test_psm + inner(grad(psm), grad(test_psm)) )*dx
Lsm = psmOld*test_psm*dx
psm = Function(V1)
Asm, bsm = assemble_system(asm, Lsm, [])
solver_sm = PETScKrylovSolver('cg')
while (psmOld.vector().max() > 1): 
    solver_sm.solve(Asm, psm.vector(), bsm)
    psmOld.vector()[:] = psm.vector()
    bsm = assemble(Lsm, tensor=bsm)
...