Gradient of a function on a subdomain

Note that gradients of CG functions are discontinuous at internal boundaries, and has to be restricted to either side on the by using the ("+") or ("-") operation. See Integrating over an interior surface

For non-linear problems, please provide a minimal example that shows what you would like to do, as it is not clear to me what the issue is.