# Computation of residual error indicator in adaptive mesh refinement (FEM)

I am attempting to implement an $h$-adaptive FEM scheme for the following simple 1D problem: $$-u''(x) = f(x) \;\text{in}\;(0,1)\\ u(0) = u(1) = 0.$$

To this end, I begin with a coarse, uniform mesh of say, 4 elements and compute an error indicator on each element. I'm looking at an explicit a posteriori indicator based on the residual: $$\eta_{K} = h_{K}^{2}|| f + u_{h}'' ||_{K}^{2}.$$

I've seen such indicators in many papers in CFD, for example, and I've been reading up on the details in the survey paper by Ainsworth and Oden [1]. My question is how to deal with the $u''$ term in the residual. In a typical finite element scheme, we usually work with the basis functions and their (first) spatial derivatives. If we are using linear basis functions, then $u_{h}'' \equiv 0$, yet I've seen AMR papers where linear basis functions are used with this residual error indicator.

Is there something obvious that I'm missing here? I know that in the weak formulation, we would typically "pass" the second derivative to a test function. I can compute something like $\int_{I_{k}} (f+u_{h}'')v\;dx$ where $v \in V_{h}$, and indeed some sources I've looked at mention an $L^{2}$ representation of the residual, but it's not immediately clear to me if this can be used to compute $\eta_{K}$.

You're not missing anything: $u_h''$ is indeed zero in the interior of cells when you use linear elements. This would suggest that for linear elements, the error estimator reduces to $$\eta_K^2 = h_K^2 \|f\|_K^2.$$ (I guess you were missing the square on the left hand side of your definition of $\eta_K$.)
This turns out to be a poor choice, because locally it does not have the correct order of convergence. A better choice would be $$\eta_K^2 = h_K^2 \|f-\bar f\|_K^2$$ where $\bar f$ is the average of $f$ on $K$.
But, either way, this estimator is pretty bad and not something you should use with linear elements. Rather, you should recognize that $u_h''$ is a function that consists of a sequence of delta functions at the interfaces of cells. So, if you wanted to derive an estimator based on that, you'd consider how large each of these delta functions are at the two end points of the interval. I won't write down the whole derivation here, but this leads exactly to the Kelly error estimator (Kelly, Gago, Babuska, et al., early 1980s).