Created
April 20, 2023 18:18
-
-
Save smartalecH/6bbd9ced25a18fb29c0a9798e159ee24 to your computer and use it in GitHub Desktop.
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 meep as mp | |
import numpy as np | |
import matplotlib.pyplot as plt | |
resolution = 10 | |
r_bank = np.linspace(1.0,1.0+1/resolution,100) | |
sum_bank = [] | |
for r in r_bank: | |
print(r) | |
sim = mp.Simulation( | |
resolution=resolution, | |
cell_size=mp.Vector3(10,0,1), | |
dimensions=mp.CYLINDRICAL, | |
sources = [mp.Source(mp.ContinuousSource(1),mp.Er,size=mp.Vector3(),center=mp.Vector3(r))], | |
m=1, | |
) | |
sim.init_sim() | |
# We need to divide by 2 pi to account for the integral around phi, and then | |
# also divide by resolution ** 2 to account for the pixel. | |
dV = 1 /( 2 * np.pi * resolution * resolution) | |
sum_bank.append(sim.fields.sum_sources(mp.Er) * dV) | |
print(f"Sum: {sum_bank[-1]}") | |
if r > 0: | |
print(f"Ratio: {sum_bank[-1] / r}") | |
print("====================================") | |
plt.figure() | |
plt.plot(r_bank,np.asarray(r_bank) * 0 + 1,color='k',label='ideal sum of weights') | |
plt.plot(r_bank,sum_bank, color='r',label='measured sum of weights',linestyle='--') | |
plt.xlabel("$r$ postion (between two grid points)") | |
plt.ylabel("sum of weights") | |
plt.legend() | |
plt.savefig("weights.png") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment