Sets up the adjoint optimization of a 1D grating. Args: pol: the polarization state (S or P). Returns: A meep.adjoint.OptimizationProblem object for the simulation.
(pol: Polarization)
| 174 | |
| 175 | |
| 176 | def grating_1d(pol: Polarization) -> mpa.OptimizationProblem: |
| 177 | """Sets up the adjoint optimization of a 1D grating. |
| 178 | |
| 179 | Args: |
| 180 | pol: the polarization state (S or P). |
| 181 | |
| 182 | Returns: |
| 183 | A meep.adjoint.OptimizationProblem object for the simulation. |
| 184 | """ |
| 185 | |
| 186 | frequency = 1 / WAVELENGTH_UM |
| 187 | pml_layers = [mp.PML(direction=mp.X, thickness=PML_UM)] |
| 188 | glass = mp.Medium(index=N_GLASS) |
| 189 | size_x_um = ( |
| 190 | PML_UM |
| 191 | + SUBSTRATE_UM |
| 192 | + GRATING_HEIGHT_UM |
| 193 | + GRATING_HEIGHT_PERTURBATION_UM |
| 194 | + AIR_UM |
| 195 | + PML_UM |
| 196 | ) |
| 197 | size_y_um = GRATING_PERIOD_UM |
| 198 | cell_size = mp.Vector3(size_x_um, size_y_um, 0) |
| 199 | k_point = mp.Vector3() |
| 200 | |
| 201 | if pol.name == "S": |
| 202 | eig_parity = mp.ODD_Z |
| 203 | src_cmpt = mp.Ez |
| 204 | else: |
| 205 | eig_parity = mp.EVEN_Z |
| 206 | src_cmpt = mp.Hz |
| 207 | |
| 208 | src_pt = mp.Vector3(-0.5 * size_x_um + PML_UM, 0, 0) |
| 209 | sources = [ |
| 210 | mp.Source( |
| 211 | mp.GaussianSource(frequency, fwidth=0.1 * frequency), |
| 212 | component=src_cmpt, |
| 213 | center=src_pt, |
| 214 | size=mp.Vector3(0, size_y_um, 0), |
| 215 | ) |
| 216 | ] |
| 217 | |
| 218 | matgrid = mp.MaterialGrid( |
| 219 | mp.Vector3(nx_sim_grid, ny_sim_grid), |
| 220 | mp.air, |
| 221 | glass, |
| 222 | weights=np.ones((nx_sim_grid, ny_sim_grid)), |
| 223 | do_averaging=False, |
| 224 | ) |
| 225 | |
| 226 | matgrid_region = mpa.DesignRegion( |
| 227 | matgrid, |
| 228 | volume=mp.Volume( |
| 229 | center=mp.Vector3( |
| 230 | (-0.5 * size_x_um + PML_UM + SUBSTRATE_UM + 0.5 * design_region_size.x), |
| 231 | 0, |
| 232 | 0, |
| 233 | ), |
no outgoing calls
no test coverage detected