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

Integrate solution cell-wise and have it mapped to these cells

+1 vote

Hi, I want to test an estimator. Therefore I have my own norm which is supposed to integrate over each cell and assigning this cell the integral value.
$$
\int_T(\textrm{ grad}\phi_h-\varepsilon^{-1}\sigma_h)^2
$$
My final goal is to have a function (piecewise constants) for each mesh cell containing the error present in this cell and plot it so it can be seen where the biggest error is in the domain (so I can know where to make the mesh finer)
I cannot find out how this is done

asked Apr 19, 2016 by jayjay FEniCS Novice (340 points)

1 Answer

+1 vote
 
Best answer

You can use DG0 Function:

DG = FunctionSpace(mesh, "DG", 0)
v = TestFunction(DG)
f = 1./CellVolume(mesh)*inner(grad(phi)-1./eps*sigma, v)*dx()
err = Function(DG)
assemble(f, tensor=err.vector())
answered Apr 20, 2016 by Øyvind Evju FEniCS Expert (17,700 points)
selected Apr 20, 2016 by jayjay

Thanks,
It has to be this to work:
1./CellVolume(mesh)*inner(dot(grad(phi)-1./eps*sigma,grad(phi)-1./eps*sigma), v)*dx

...