Given the fields along a slice, returns the equivalent sources as meep source objects for the beam.
(field, normal_vec, time_src, center, size)
| 778 | |
| 779 | |
| 780 | def get_equiv_sources(field, normal_vec, time_src, center, size): |
| 781 | """Given the fields along a slice, returns the equivalent sources as meep source objects for the beam.""" |
| 782 | # Get fields |
| 783 | Ex, Ey, Ez, Hx, Hy, Hz = field |
| 784 | nHat = normal_vec |
| 785 | |
| 786 | # Electric current K = nHat x H |
| 787 | Kx = nHat[1] * Hz - nHat[2] * Hy |
| 788 | Ky = nHat[2] * Hx - nHat[0] * Hz |
| 789 | Kz = nHat[0] * Hy - nHat[1] * Hx |
| 790 | |
| 791 | # Mangnetic current N = - nHat x E |
| 792 | Nx = nHat[2] * Ey - nHat[1] * Ez |
| 793 | Ny = nHat[0] * Ez - nHat[2] * Ex |
| 794 | Nz = nHat[1] * Ex - nHat[0] * Ey |
| 795 | |
| 796 | # Source components |
| 797 | components = {mp.Ex: Kx, mp.Ey: Ky, mp.Ez: Kz, mp.Hx: Nx, mp.Hy: Ny, mp.Hz: Nz} |
| 798 | |
| 799 | # Make sources |
| 800 | sources = [ |
| 801 | mp.Source( |
| 802 | time_src, |
| 803 | field_comp, |
| 804 | center=center, |
| 805 | size=size, |
| 806 | amp_data=source_comp, |
| 807 | ) |
| 808 | for field_comp, source_comp in components.items() |
| 809 | if np.sum(np.abs(source_comp)) |
| 810 | ] |
| 811 | |
| 812 | return sources |
| 813 | |
| 814 | |
| 815 | class GaussianBeam2DSource(GaussianBeam3DSource): |