Identical to `GaussianBeam3DSource` except that the beam is defined in 2d. This is useful for 2d simulations where the 3d beam is not exact.
| 813 | |
| 814 | |
| 815 | class GaussianBeam2DSource(GaussianBeam3DSource): |
| 816 | """ |
| 817 | Identical to `GaussianBeam3DSource` except that the beam is defined in 2d. |
| 818 | This is useful for 2d simulations where the 3d beam is not exact. |
| 819 | """ |
| 820 | |
| 821 | def get_fields(self, sim): |
| 822 | """Calls green2d under various conditions (incoming vs outgoing) providing the correct Hankel functions and returns the fields at the slice provided by the source.""" |
| 823 | from scipy.special import hankel1e, hankel2e, jve |
| 824 | from sys import float_info |
| 825 | |
| 826 | # Beam parameters |
| 827 | freq = self.src.swigobj.frequency().real |
| 828 | eps = sim.fields.get_eps( |
| 829 | mp.py_v3_to_vec(sim.dimensions, self.center, sim.is_cylindrical) |
| 830 | ).real |
| 831 | mu = sim.fields.get_mu( |
| 832 | mp.py_v3_to_vec(sim.dimensions, self.center, sim.is_cylindrical) |
| 833 | ).real |
| 834 | k = 2 * np.pi * freq * np.sqrt(eps * mu) |
| 835 | |
| 836 | # Get this coordinate system |
| 837 | center = mp.py_v3_to_vec(sim.dimensions, self.center, sim.is_cylindrical) |
| 838 | size = mp.py_v3_to_vec(sim.dimensions, self.size, sim.is_cylindrical) |
| 839 | beam_x0 = mp.py_v3_to_vec(sim.dimensions, self.beam_x0, sim.is_cylindrical) |
| 840 | beam_kdir = mp.py_v3_to_vec(sim.dimensions, self.beam_kdir, sim.is_cylindrical) |
| 841 | beam_E0 = self.beam_E0 |
| 842 | |
| 843 | # Check for errors |
| 844 | if size.x() and size.y(): |
| 845 | raise Exception( |
| 846 | "GaussianBeam2DSource should be a line source, not a plane. Either set size.x or size.y to zero." |
| 847 | ) |
| 848 | |
| 849 | # Complex point source |
| 850 | x0 = center.x() + beam_x0.x() |
| 851 | y0 = center.y() + beam_x0.y() |
| 852 | z0 = k * self.beam_w0**2 / 2 |
| 853 | kdir = beam_kdir.x() + 1j * beam_kdir.y() |
| 854 | kdir = kdir / np.abs(kdir) |
| 855 | jx0 = 1j * z0 * np.real(kdir) |
| 856 | jy0 = 1j * z0 * np.imag(kdir) |
| 857 | X0 = np.array([x0 + jx0, y0 + jy0]).astype(complex) |
| 858 | |
| 859 | # Create grid |
| 860 | x = ( |
| 861 | np.linspace( |
| 862 | center.x() - size.x() / 2, |
| 863 | center.x() + size.x() / 2, |
| 864 | int(2 * sim.resolution * size.x()), |
| 865 | ) |
| 866 | if size.x() > 0 |
| 867 | else np.array([center.x()]) |
| 868 | ) |
| 869 | y = ( |
| 870 | np.linspace( |
| 871 | center.y() - size.y() / 2, |
| 872 | center.y() + size.y() / 2, |
nothing calls this directly
no outgoing calls
no test coverage detected