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

Python interface for slanted prisms #1129

Merged
merged 1 commit into from
Feb 19, 2020
Merged

Python interface for slanted prisms #1129

merged 1 commit into from
Feb 19, 2020

Conversation

stevengj
Copy link
Collaborator

Adds sidewall_angle parameter to Python prism objects (defaults to zero), allowing them to interface the new slanted-prism feature in libctl 4.5 (NanoComp/libctl#53).

@stevengj
Copy link
Collaborator Author

stevengj commented Feb 18, 2020

Needs documentation as well. Note that we decided to define the center (centroid) parameter with respect to a sidewall angle of zero, as otherwise changing the sidewall angle would change the vertical offset (because it shifts the centroid with respect to the base).

@oskooi
Copy link
Collaborator

oskooi commented Feb 19, 2020

Some strange artifacts are found in the epsilon profile of a hexagonal prism in the xy plane of a 2d cell whenever the sidewall_angle is not zero as shown below.

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

cell_size = mp.Vector3(2.5,2.5)

resolution = 50

vertices = [mp.Vector3(-1,0),
            mp.Vector3(-0.5,math.sqrt(3)/2),
            mp.Vector3(0.5,math.sqrt(3)/2),
            mp.Vector3(1,0),
            mp.Vector3(0.5,-math.sqrt(3)/2),
            mp.Vector3(-0.5,-math.sqrt(3)/2)]

geometry = [mp.Prism(vertices,                     
                     height=1.5,
                     center=mp.Vector3(),
                     sidewall_angle=np.radians(15),
                     material=mp.Medium(index=3.5))]

sim = mp.Simulation(resolution=resolution,
                    cell_size=cell_size,
                    geometry=geometry)

sim.init_sim()
plt.figure()
sim.plot2D()
plt.savefig('prism_sidewall.png')

sidewall_angle=0

prism_sidewall_0

sidewall_angle=np.radians(15)

prism_sidewall_15

sidewall_angle=np.radians(27)

prism_sidewall_27

Note that the size of the cross section is shrinking as the sidewall_angle increases. This is correct given the intersection of the prism with the z=0 plane.

@oskooi
Copy link
Collaborator

oskooi commented Feb 19, 2020

It seems there might be a small bug in the subpixel smoothing for non-zero sidewall angles. This is because when subpixel smoothing is disabled (eps_averaging=False), the epsilon profiles for the cases above show no artifacts:

sidewall_angle=np.radians(15)

prism_sidewall_15_noepsavg

sidewall_angle=np.radians(27)

prism_sidewall_27_noepsavg

@stevengj
Copy link
Collaborator Author

The "fuzz" around the edges looks a little suspicious, but I'm fine with merging this as an undocumented "experimental" feature.

@stevengj stevengj merged commit b4b7d61 into master Feb 19, 2020
@stevengj stevengj deleted the sidewall branch February 19, 2020 18:32
@oskooi
Copy link
Collaborator

oskooi commented Feb 19, 2020

Artifacts along the prism boundaries also appear in 3d.

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

cell_size = mp.Vector3(3,3,3)

resolution = 50

vertices = [mp.Vector3(-1,0),
            mp.Vector3(-0.5,math.sqrt(3)/2),
            mp.Vector3(0.5,math.sqrt(3)/2),
            mp.Vector3(1,0),
            mp.Vector3(0.5,-math.sqrt(3)/2),
            mp.Vector3(-0.5,-math.sqrt(3)/2)]

geometry = [mp.Prism(vertices,
                     axis=mp.Vector3(0,0,1),
                     height=1.5,
                     center=mp.Vector3(),
                     sidewall_angle=np.radians(10),
                     material=mp.Medium(index=3.5))]

sim = mp.Simulation(resolution=resolution,
                    cell_size=cell_size,
                    geometry=geometry)

sim.run(mp.at_beginning(mp.output_epsilon),until=0)
$ h5topng -o eps-xy.png -z 75 prism_sidewall-eps-000000.00.h5
$ h5topng -o eps-xz.png -y 75 prism_sidewall-eps-000000.00.h5
$ h5topng -o eps-yz.png -x 75 prism_sidewall-eps-000000.00.h5

eps-xy.png

eps-xy

eps-xz.png

eps-xz

eps-yz.png

eps-yz

@danielwboyce
Copy link

From a discussion with @stevengj, a good idea for debugging this may be to check normal_to_prism and intersect_line_segment_with_prism near one of the pixels that looks weird.

@oskooi
Copy link
Collaborator

oskooi commented Feb 19, 2020

When the sidewall angle is 0, no artifacts appear along the boundaries.

eps-xy.png

eps-xy

eps-xz.png

eps-xz

eps-yz.png

eps-yz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants