Post-processing: integrate on boundary product of functions
n = FacetNormal(mesh)
flux = -k*dot(grad(u), n)*ds
total_flux = assemble(flux)
In the aforementioned example, `k` is a constant. How can I extend this to the case where `k` is a function as such
# big complicated computation
and then use it directly to define the flux, passing the spatial coordinates as an argument:
def k(x): return x**2 + x**2 + 1.0
x = SpatialCoordinate(mesh) flux = -k(x)*dot(grad(u),n)*ds
The assembly would then use the same line of code.
An additional remark, though, on flux extraction: If this flux is on a Dirichlet boundary where you are prescribing \(u\), you might look into conservative flux extraction instead of direct evaluation. See, e.g., my post here:
and references cited therein.