You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are artifacts in the get_source slicing routine demonstrated by the following example involving an arbitrary oblique planewave source defined by an amplitude function spanning the entire cell area.
importmeepasmpimportmathimportcmathimportnumpyasnpimportmatplotlib.pyplotaspltresolution=50# pixels/μm sxy=5cell_size=mp.Vector3(sxy,sxy,0)
# rotation angle of incident planewave; counter clockwise (CCW) about Z axis, 0 degrees along +X axis theta_in=math.radians(27.3151)
# k (in source medium) with correct length (plane of incidence: XY) k=mp.Vector3(math.cos(theta_in),math.sin(theta_in),0)
defpw_amp(k,x0):
def_pw_amp(x):
returncmath.exp(1j*2*math.pi*k.dot(x-x0))
return_pw_ampsrc_pt=mp.Vector3(-0.5*sxy+1.3)
sources= [mp.Source(mp.GaussianSource(1,fwidth=0.2),
component=mp.Ez,
center=src_pt,
size=cell_size,
amp_func=pw_amp(k,src_pt))]
sim=mp.Simulation(resolution=resolution,
cell_size=cell_size,
k_point=k,
sources=sources)
sim.init_sim()
src_data=sim.get_source(mp.Ez, center=mp.Vector3(), size=cell_size)
plt.figure(dpi=150)
plt.imshow(np.real(src_data.transpose()), interpolation='spline36')
plt.axis('off')
plt.show()
For the case in which the source center is src_pt = mp.Vector3(-0.5*sxy+1.3) (i.e., off center), a line artifact appears in the output at the source location:
If the k_point is removed from the Simulation constructor, the line artifact becomes an empty finite region which extends to the edge of the cell:
Finally, if the source center is at the origin, src_pt = mp.Vector3(), there are no artifacts and the output is as expected (with or without k_point):
Note that these examples do not use symmetries which were fixed in #828.
The text was updated successfully, but these errors were encountered:
Actually, this is not a bug in get_source because the position and size of the source (src_pt and cell_size) were inadvertently chosen such that the source was extending outside of the computational cell. This causes the results from get_source to be unpredictable especially when there are periodic boundaries.
When the source object is defined to lie entirely within the cell volume, get_source works fine.
importmeepasmpimportmathimportcmathimportnumpyasnpimportmatplotlibmatplotlib.use('agg')
importmatplotlib.pyplotaspltresolution=50# pixels/μm sxy=10cell_size=mp.Vector3(sxy,sxy,0)
# rotation angle of incident planewave; counter clockwise (CCW) about Z axis, 0 degrees along +X axis theta_in=math.radians(27.3151)
# k (in source medium) with correct length (plane of incidence: XY) k=mp.Vector3(math.cos(theta_in),math.sin(theta_in),0)
defpw_amp(k,x0):
def_pw_amp(x):
returncmath.exp(1j*2*math.pi*k.dot(x-x0))
return_pw_ampsrc_pt=mp.Vector3(-1.2,2.3)
sources= [mp.Source(mp.GaussianSource(1,fwidth=0.2),
component=mp.Ez,
center=src_pt,
size=mp.Vector3(3,3),
amp_func=pw_amp(k,src_pt))]
sim=mp.Simulation(resolution=resolution,
cell_size=cell_size,
k_point=k,
sources=sources)
sim.init_sim()
src_data=sim.get_source(mp.Ez, center=mp.Vector3(), size=cell_size)
plt.figure(dpi=150)
plt.imshow(np.real(src_data.transpose()), interpolation='spline36')
plt.axis('off')
plt.savefig('test_get_source.png',bbox_inches='tight')
There are artifacts in the
get_source
slicing routine demonstrated by the following example involving an arbitrary oblique planewave source defined by an amplitude function spanning the entire cell area.For the case in which the source center is
src_pt = mp.Vector3(-0.5*sxy+1.3)
(i.e., off center), a line artifact appears in the output at the source location:If the
k_point
is removed from theSimulation
constructor, the line artifact becomes an empty finite region which extends to the edge of the cell:Finally, if the source center is at the origin,
src_pt = mp.Vector3()
, there are no artifacts and the output is as expected (with or withoutk_point
):Note that these examples do not use
symmetries
which were fixed in #828.The text was updated successfully, but these errors were encountered: