Last active
January 20, 2023 06:23
-
-
Save oskooi/9be8dafb58d60562d17ae8cfb0771344 to your computer and use it in GitHub Desktop.
Determines whether the fields in a cylindrical-coordinate simulation with m=±1 are purely real
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import numpy as np | |
import meep as mp | |
def dipole_emission(res: float, dpml_r: float, dpml_z: float, s: float, | |
m: int, fcen: float) -> float: | |
"""Computes the complex fields from an Er point source at r=z=0 in vacuum.""" | |
cell_size = mp.Vector3(s+dpml_r,0,s+2*dpml_z) | |
pml_layers = [ | |
mp.PML(dpml_r, direction=mp.R), | |
mp.PML(dpml_z, direction=mp.Z), | |
] | |
sources = [ | |
mp.Source( | |
src=mp.CustomSource(src_func=lambda t: np.sin(2*np.pi*fcen*t)), | |
center=mp.Vector3(), | |
component=mp.Er, | |
), | |
] | |
sim = mp.Simulation( | |
resolution=res, | |
cell_size=cell_size, | |
dimensions=mp.CYLINDRICAL, | |
m=m, | |
sources=sources, | |
boundary_layers=pml_layers, | |
) | |
sim.run(until=40.6) | |
er = sim.get_array( | |
component=mp.Er, | |
center=mp.Vector3(0.5*s,0,0), | |
size=mp.Vector3(s,0,s), | |
cmplx=True, | |
) | |
return er | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
'-res', | |
type=float, | |
default=50., | |
help='resolution (default: 50.0)', | |
) | |
parser.add_argument( | |
'-dpml_r', | |
type=float, | |
default=1., | |
help='PML thickness in r direction (default: 1.0)', | |
) | |
parser.add_argument( | |
'-dpml_z', | |
type=float, | |
default=1., | |
help='PML thickness in z direction (default: 1.0)', | |
) | |
parser.add_argument( | |
'-s', | |
type=float, | |
default=5., | |
help='thickess of non-PML region (default: 5.0)', | |
) | |
args = parser.parse_args() | |
er0 = dipole_emission(args.res, args.dpml_r, args.dpml_z, args.s, -1, +1.) | |
er1 = dipole_emission(args.res, args.dpml_r, args.dpml_z, args.s, -1, -1.) | |
er2 = dipole_emission(args.res, args.dpml_r, args.dpml_z, args.s, +1, +1.) | |
er3 = dipole_emission(args.res, args.dpml_r, args.dpml_z, args.s, +1, -1.) | |
def is_real(x): | |
return np.all(np.conj(x) == x) | |
# print out the first 20 elements of the Er arrays | |
# for inspection of their imaginary parts | |
print(f"er0:, {er0[:20]}") | |
print(f"er1:, {er1[:20]}") | |
print(f"er2:, {er2[:20]}") | |
print(f"er3:, {er3[:20]}") | |
print(f"real? er0: {is_real(er0)}, er1: {is_real(er1)}, " | |
f"er2: {is_real(er2)}, er3: {is_real(er3)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output from running this script: