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

Fix eigenmode coefficient objective function in Meep metagrating optimization #67

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions Metagrating3D/metagrating_meep_opt_1d.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This python script is for maximizing the diffraction efficiency of the m=+1 order
# for a 3D metagrating with a 1D design.
# for a 1D metagrating.

import meep as mp
import meep.adjoint as mpa
Expand Down Expand Up @@ -30,7 +30,7 @@
# periodic boundary conditions
k_point = mp.Vector3()

# plane of incidence is XZ
# plane of incidence is XY
P_pol = True
src_cmpt = mp.Ex if P_pol else mp.Ez
src_pt = mp.Vector3(0,-0.5*sy+dpml+0.5*dsub)
Expand Down Expand Up @@ -93,9 +93,20 @@ def mapping(x):
k_point=k_point,
eps_averaging=False)

emc = mpa.EigenmodeCoefficient(sim,mp.Volume(center=mp.Vector3(0,0.5*sy-dpml),size=mp.Vector3(px,0)),
mode=1,eig_parity = mp.EVEN_Z if P_pol else mp.ODD_Z,
kpoint_func=lambda *not_used: kdiff)
emc = mpa.EigenmodeCoefficient(
sim,
mp.Volume(
center=mp.Vector3(0, 0.5*sy - dpml),
size=mp.Vector3(px, 0)
),
mode=1,
eig_parity=mp.EVEN_Z if P_pol else mp.ODD_Z,
kpoint_func=lambda *not_used: kdiff,
eig_vol=mp.Volume(
center=mp.Vector3(0, 0.5*sy - dpml),
size=mp.Vector3(1 / resolution, 0, 0)
)
)
ob_list = [emc]

opt = mpa.OptimizationProblem(simulation=sim,objective_functions=J,objective_arguments=ob_list,
Expand Down Expand Up @@ -140,4 +151,4 @@ def f(v, gradient):

x = np.sign(mapping(x)-0.5)/2+0.5
x = x.astype(int)
np.savetxt('optimized_pattern_1d.dat', x)
np.savetxt('optimized_pattern_1d.dat', x)
21 changes: 16 additions & 5 deletions Metagrating3D/metagrating_meep_opt_2d.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This python script is for maximizing the diffraction efficiency of the m=+1 order
# for a 3D metagrating with a 2D design.
# for a 2D metagrating.

import meep as mp
import meep.adjoint as mpa
Expand Down Expand Up @@ -95,9 +95,20 @@ def mapping(x):
k_point=k_point,
eps_averaging=False)

emc = mpa.EigenmodeCoefficient(sim,mp.Volume(center=mp.Vector3(0,0,0.5*sz-dpml),size=mp.Vector3(px,py,0)),
mode=1,eig_parity = mp.EVEN_Y if P_pol else mp.ODD_Y,
kpoint_func=lambda *not_used: kdiff)
emc = mpa.EigenmodeCoefficient(
sim,
mp.Volume(
center=mp.Vector3(0, 0, 0.5*sz - dpml),
size=mp.Vector3(px, py, 0)
),
mode=1,
eig_parity = mp.EVEN_Y if P_pol else mp.ODD_Y,
kpoint_func=lambda *not_used: kdiff,
eig_vol=mp.Volume(
center=mp.Vector3(0, 0, 0.5*sz - dpml),
size=mp.VEctor3(1 / resolution, 1 / resolution, 0)
)
)
ob_list = [emc]

opt = mpa.OptimizationProblem(simulation=sim,objective_functions=J,objective_arguments=ob_list,
Expand Down Expand Up @@ -150,4 +161,4 @@ def f(v, gradient):
x = np.sign(mapping(x)-0.5)/2+0.5
x = x.astype(int)
x = x.reshape(Nx,Ny)
np.savetxt('optimized_pattern_2d.dat', x)
np.savetxt('optimized_pattern_2d.dat', x)
Loading