Ansys Learning Forum › Forums › Discuss Simulation › Photonics › lumopt errors › Reply To: lumopt errors
# Define the geometry function to keep each ring separate
def concentric_rings_function(params):
  central_radius = params[0]  # in meters
  gap_width = params[1]    # in meters
  period = params[2]      # in meters
  verts = []
  for i in range(n_rings):
    # Calculate inner and outer radii for each ring
    r_inner = central_radius + i * period - gap_width / 2
    r_outer = central_radius + i * period + gap_width / 2
    num_sides = 64000 # Increased number of points for smoother rings
    angles = np.linspace(0, 2 * np.pi, num_sides, endpoint=False)
    Â
    # Define outer and inner vertices for each ring
    outer_vertices = np.array([[r_outer * np.cos(theta), r_outer * np.sin(theta)] for theta in angles])
    inner_vertices = np.array([[r_inner * np.cos(theta), r_inner * np.sin(theta)] for theta in angles])
    Â
    # Close the ring by appending the first point at the end of each ring
    ring_vertices = np.vstack((outer_vertices, inner_vertices[::-1], outer_vertices[0:1]))
    verts.append(ring_vertices)  # Keep each ring separate in the list
  return verts  # Returns a list of arrays, each array representing a ring
  return np.array(verts)  # Convert the list to a numpy array with consistent shape
# Create the FunctionDefinedPolygon geometry
geometry = FunctionDefinedPolygon(
  func=concentric_rings_function,
  initial_params=initial_params,
  bounds=bounds,
  z=gold_thickness+sio2_thickness+(gaas_thickness/2),
  depth=gaas_thickness,
  eps_out=1.0 ** 2,     # Dielectric constant outside the rings (e.g., air)
  eps_in=3.47668 ** 2,    # Dielectric constant inside the rings (e.g., GaAs)
  edge_precision=5,     # Precision of the polygon edges
  dx=1.0e-5,  Â
  unfold_symmetry=False,        # Spatial resolution for the polygon
)
# === Define ModeMatch FOM ===
# Initialize ModeMatch with the specified monitor name
mode_match_fom = ModeMatch(
  monitor_name='fom',          # Exact monitor name as in Lumerical FDTD simulation
  mode_number=1,            # Mode number to calculate overlap with
  direction='Forward',         # Propagation direction ('Forward' or 'Backward')
  multi_freq_src=False,         # False for single frequency mode calculation
  target_T_fwd=lambda wl: np.ones(wl.size),  # Target transmission function
  norm_p=1,               # p-norm for figure of merit calculation (1 for standard FOM)
  target_fom=0             # Target value for FOM (optional)
)
# === Define Wavelength Settings ===
wavelengths = Wavelengths(start=1.2e-6, stop=1.6e-6, points=100) Â # Define the wavelength range and points
# === Define Optimization Algorithm ===
optimizer = ScipyOptimizers(
  max_iter=50,
  method='L-BFGS-B',
  scaling_factor=1e9,         # Scales parameters from meters to nanometers
  pgtol=1e-6,
  ftol=1e-6,
  scale_initial_gradient_to=0.0,
  penalty_fun=None,
  penalty_jac=None
)
# === Setup and Run Optimization ===
# Define paths and parameters for optimization
base_script_path = 'cbg2.lsf' Â Â Â Â Â # Path to the Lumerical script file
geometry = None             # Define your specific geometry here
opt = Optimization(
  base_script=base_script_path,    # Path to Lumerical script for simulation setup
  wavelengths=wavelengths,      # Wavelength settings for simulation
  fom=mode_match_fom,         # Figure of Merit (FOM) configuration
  geometry=geometry,         # Geometry configuration, like concentric rings
  optimizer=optimizer,        # Optimizer configuration
  use_var_fdtd=False,         # Use standard FDTD rather than VarFDTD
  hide_fdtd_cad=False,        # Whether to hide the FDTD CAD window
  use_deps=True,           # Use FDTD’s numerical derivatives
  plot_history=True,         # Plot optimization history
  store_all_simulations=True,     # Store all simulation results from each iteration
  save_global_index=False,      # Save global index monitor results (optional)
  label='Bullseye Structure Optimization',  # Label for the optimization project
  source_name='source'        # Name of the source in the Lumerical simulation
)
# Run the optimization, saving results to the specified working directory
working_directory = os.path.join(os.path.dirname(__file__), 'optimization_results')
opt.run(working_directory=working_directory)
this is the code i am using i want to optimize a structure using RCWA which as multiple parameters which i need to optimize. Any insight or help will be greatly appreciatedÂ