"""
Reconstruct fields from eigenbuild values and solver solutions.

Takes arguments of k0 = 2 pi / wavelength 
and matrices generated by philsol eigenbuild

"""

def extra_feilds(k0, beta, Ex, Ey, matrices):
    
    Hz = 1j * (matrices['uy'] * Ex - matrices['ux'] * Ey) / k0
    Hx = (1j * matrices['vx'] * Hz - k0 * matrices['epsy'] * Ey) / beta
    Hy = (k0 * matrices['epsx'] * Ex - 1j * matrices['vy'] * Hz) / beta
    
    Ez = matrices['epszi'] * (-matrices['vy'] * Hx + matrices['vx'] * Hy) 

    return Ez, Hx, Hy, Hz

