Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

artifacts in get_source #836

Closed
oskooi opened this issue Apr 24, 2019 · 1 comment
Closed

artifacts in get_source #836

oskooi opened this issue Apr 24, 2019 · 1 comment
Labels

Comments

@oskooi
Copy link
Collaborator

oskooi commented Apr 24, 2019

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.

import meep as mp
import math
import cmath
import numpy as np
import matplotlib.pyplot as plt

resolution = 50        # pixels/μm                                                                                                                                          

sxy = 5
cell_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)

def pw_amp(k,x0):
  def _pw_amp(x):
    return cmath.exp(1j*2*math.pi*k.dot(x-x0))
  return _pw_amp

src_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:

test_get_source_srcpt_m1 2

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:

test_get_source_srcpt_m1 2_nokpt

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):

test_get_source_srcpt_0

Note that these examples do not use symmetries which were fixed in #828.

@oskooi oskooi added the bug label Apr 24, 2019
@oskooi
Copy link
Collaborator Author

oskooi commented Jan 6, 2021

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.

import meep as mp
import math
import cmath
import numpy as np
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt

resolution = 50        # pixels/μm                                                                                                      

sxy = 10
cell_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)

def pw_amp(k,x0):
  def _pw_amp(x):
    return cmath.exp(1j*2*math.pi*k.dot(x-x0))
  return _pw_amp

src_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')

test_get_source2

@oskooi oskooi closed this as completed Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant