There seems to be unwanted artifacts along the outer edges of a MaterialGrid which could introduce errors into a simulation. This can be demonstrated by using plot2D to visualize a MaterialGrid in a 2d cell consisting of a linear interpolation along a single direction of medium1 (index n1) and medium2 (index n2). The edge artifacts are independent of the resolution. The edge artifacts seem to disappear when the MaterialGrid is defined as the default_medium (rather than a Block object) which suggests there is probably a bug in the interpolation for grid voxels near the edges.
(Possibly related to #1399.)



import meep as mp
import numpy as np
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
resolution = 50
cell_size = mp.Vector3(2,2,0)
Nx = 101
Ny = 101
lin_interp = np.linspace(0,1,Nx)
weights = np.tile(lin_interp,(Ny,1))
mat_interp = mp.MaterialGrid(mp.Vector3(Nx,Ny,0),
mp.Medium(index=1.5),
mp.Medium(index=3.5),
weights=weights)
geometry = [mp.Block(material=mat_interp,
center=mp.Vector3(),
size=mp.Vector3(1,1,0))]
sim = mp.Simulation(cell_size=cell_size,
resolution=resolution,
geometry=geometry)
sim.plot2D()
plt.title('resolution = {}, (Nx,Ny) = ({},{})'.format(resolution,Nx,Ny))
plt.savefig('matgrid_graded_res{}_{}_{}.png'.format(resolution,Nx,Ny),
bbox_inches='tight',
dpi=150)
There seems to be unwanted artifacts along the outer edges of a
MaterialGridwhich could introduce errors into a simulation. This can be demonstrated by usingplot2Dto visualize aMaterialGridin a 2d cell consisting of a linear interpolation along a single direction ofmedium1(indexn1) andmedium2(indexn2). The edge artifacts are independent of theresolution. The edge artifacts seem to disappear when theMaterialGridis defined as thedefault_medium(rather than aBlockobject) which suggests there is probably a bug in the interpolation for grid voxels near the edges.(Possibly related to #1399.)