MCPcopy Create free account
hub / github.com/NanoComp/meep / run_shape_optimization

Function run_shape_optimization

python/examples/waveguide_crossing.py:280–377  ·  view source on GitHub ↗

Run shape optimization using a cross as a starting guess. Args: resolution: Simulation resolution in pixels/micron. beta: Tanh function projection strength parameter, ranging from [0,∞]. maxeval: Maximum number of optimization iterations to run. use_smoothed_proj

(
    resolution: float,
    beta: float,
    maxeval: int,
    use_smoothed_projection: bool = True,
    damping_factor: float = 0.0,
    dx: float = DEFAULT_DESIGN_REGION_WIDTH,
    dy: float = DEFAULT_DESIGN_REGION_HEIGHT,
    waveguide_width: float = DEFAULT_WAVEGUIDE_WIDTH,
    output_filename_prefix: Optional[str] = None,
    plot_results: bool = True,
)

Source from the content-addressed store, hash-verified

278
279
280def run_shape_optimization(
281 resolution: float,
282 beta: float,
283 maxeval: int,
284 use_smoothed_projection: bool = True,
285 damping_factor: float = 0.0,
286 dx: float = DEFAULT_DESIGN_REGION_WIDTH,
287 dy: float = DEFAULT_DESIGN_REGION_HEIGHT,
288 waveguide_width: float = DEFAULT_WAVEGUIDE_WIDTH,
289 output_filename_prefix: Optional[str] = None,
290 plot_results: bool = True,
291):
292 """Run shape optimization using a cross as a starting guess.
293
294 Args:
295 resolution: Simulation resolution in pixels/micron.
296 beta: Tanh function projection strength parameter, ranging from [0,∞].
297 maxeval: Maximum number of optimization iterations to run.
298 use_smoothed_projection: Whether or not to use the smoothed projection.
299 dx: Design region width in microns.
300 dy: Design region height in microns.
301 waveguide_width: Waveguide width in microns.
302 output_filename_prefix: The filename prefix that will store the
303 optimization results. If `None`, no file is saved.
304 plot_results: Whether or not to plot results.
305
306 Returns:
307 The design and FOM result arrays, along with the optimization problem
308 and mapping function.
309
310 """
311 # Initialize the optimization problem and mapping functions
312 opt, mapping = build_optimization_problem(
313 resolution=resolution,
314 beta=beta,
315 dx=dx,
316 dy=dy,
317 waveguide_width=waveguide_width,
318 use_smoothed_projection=use_smoothed_projection,
319 damping_factor=damping_factor,
320 )
321
322 # pull number of parameters from the design region
323 n = opt.design_regions[0].design_parameters.weights.size
324 grid_size = opt.design_regions[0].design_parameters.grid_size
325 Nx, Ny = int(grid_size.x), int(grid_size.y)
326
327 # Set up the optimizer
328 algorithm = nlopt.LD_CCSAQ
329 solver = nlopt.opt(algorithm, n)
330 solver.set_lower_bounds(0)
331 solver.set_upper_bounds(1)
332 solver.set_maxeval(maxeval)
333
334 # initial guess, which is just a simple waveguide crossing
335 x = np.linspace(-dx / 2, dy / 2, Nx)
336 y = np.linspace(-dx / 2, dy / 2, Ny)
337 X, Y = np.meshgrid(x, y)

Callers 1

analyze_FOM_convergenceFunction · 0.85

Calls 5

mappingFunction · 0.85
nlopt_fomFunction · 0.85
update_designMethod · 0.80

Tested by

no test coverage detected