# How to derive excitation equation used in Finite-Element-Method waveport-driven simulation?

I am working my way through getdp's linear waveguide example in 3D. It appears to me that the electric fields are excited by the waveports, as defined in the formulations file on lines 161-164:

  Galerkin { [ -2*I[]*k0 * (1/muR[]) * Normal[] /\ ( Normal[] /\ eInc[] ) , {e} ] ;
In BndABC ; Integration I1 ; Jacobian Jac ; }
Galerkin { [ I[]*k0 * (1/muR[]) * Normal[] /\ ( Normal[] /\ Dof{e} ) , {e} ] ;
In BndABC ; Integration I1 ; Jacobian Jac ; }


which I interpret as arising from the PDEs:

$$-2ik_0\left(\frac{1}{\mu_r}\right)\cdot \hat{n}\ \times \left(\hat{n}\ \times \vec{E}_\text{inc}\right) + ik_0\left(\frac{1}{\mu_r}\right)\cdot \hat{n}\ \times \left(\hat{n}\ \times \vec{E}\right)$$

applied to the wave ports ("BndABC").

I cannot determine where these equations arise from, particularly the factor of 2 in the first term. I understand that for an $$\hat{n}$$-directed wave, $$\nabla \times \vec{E} = k_0 \left(\hat{n}\ \times \vec{E}\right)$$, but I have not been able to massage Maxwell's equations to give me something that looks like the above.

It may be benefitial if I understood the basic physics of what this equation was attempting to represent, which also presently escapes me. My best guess at the moment is that it represents a statement that all of the fields on the given port are from the incident wave.

How are the above expressions derived from Maxwell's equations, and what statement of physics do they express?

The second term arises from imposing an impedance/absorbing boundary condition, $$\hat n \times \nabla \times \vec E = -jk_0\cdot \hat n \times \hat n \times \vec E$$, after applying integration by parts to the vector wave equation. The ABC does what it says on the tin: outgoing waves are absorbed instead of being reflected back into the domain. It happens to be exact for normally incident waves (for instance, if you are modeling a TEM waveguide).
The first term arises from a more subtle idea, that "outgoing-ness" is not actually the correct boundary condition for the (total) field $$\vec E$$, but rather the (scattered) field $$\vec E-\vec E_{inc}$$. That is, we should instead impose $$\hat n \times \nabla \times \left( \vec E - \vec E_{inc}\right) = -jk_0\cdot \hat n \times \hat n \times \left( \vec E - \vec E_{inc}\right)$$ on the boundary. When you insert your chosen $$\vec E_{inc}$$ (probably, a TEM wave heading into the domain) and crank carefully, this equation will simultaneously provide a boundary condition on your working variable (the total field $$\vec E$$) and some forcing data (the $$\vec E_{inc}$$ term, including that factor of two).
Intuitively, you might also think of the factor of two as arising from current division. The source term is effectively a sheet current source on the boundary, which launches waves in both directions (the one going in the "wrong"/outgoing direction is immediately absorbed by the BC). So if you want some particular amplitude for $$\vec E_{inc}$$ inside the domain, you need to double up the sheet current to account for this effect. (Though personally I would discourage this interpretation because I feel lacks the same rigor as the explanation above, which is quite general and compatible with more advanced termination conditions).