# Manipulating field expression in volume integral in cavity

We have an electromagnetic cavity resonator that has a shape similar to a cuboid, but with perfectly conductive walls at top and bottom surfaces (so, tangent $E$ is zero there) and perfect magnetic boundary at all the remaining side walls (so, tangent $H$ is zero there). There is a resonant field inside the cavity.

The stored electric field energy in cavity is proportional to

$$\iiint_{V} \boldsymbol{E}. \boldsymbol{E^{*}} dV$$

where V is the cavity volume, bold symbols are vectors and * denotes complex conjugate.

Now if we try to convert this to a surface integral using Gauss theorem and using the vector identity $\boldsymbol{A}.(\boldsymbol{B\times C})=\boldsymbol{B}.(\boldsymbol{C\times A})$ and the fact that Maxwell equations give $\boldsymbol{E}=\frac{-i \nabla\times\boldsymbol{H}}{\omega \epsilon}$ inside the cavity, the integral becomes proportional to (scalar constants suppressed here)

$$\iiint_{V} \boldsymbol{E}. \boldsymbol{E^{*}} dV \rightarrow \iiint_{V} \boldsymbol{\nabla}.( \boldsymbol{H^{*}\times(\nabla\times H)} ) = \oint_{A}\boldsymbol{H^{*}\times(\nabla\times H).dA}=\oint_{A}(\boldsymbol{H^{*}\times E).dA}$$

Where $A$ is the closed surface enclosing the cavity, and $dA$ is the vector of surface element directed normal to cavity walls. (This result seems relevant to Poynting vector.)

However, since either the tangent E or the tangent H fields will be zero at the cavity walls, the surface integral will vanish completely and we get zero result.

This doesn't make sense, because the volume integral we started with is clearly a positive nonzero value. What has gone wrong? And how can we write the correct surface integral equivalent to the original volume integral as to give the right answer? The aim is to find the energy using a surface integral form.

$\boldsymbol{E}=\frac{-i \nabla\times\boldsymbol{H}}{\omega \epsilon}$