Basic Session Management#
This example demonstrates how to initialize a local Lumerical session. PyLumerical interacts with Lumerical products through sessions.
Prerequisites:#
Valid FDTD and MODE licenses are required.
Perform required imports#
[ ]:
1import ansys.lumerical.core as lumapi
Open an interactive session#
[ ]:
2fdtd = lumapi.FDTD()
3# Wait for a second, then add FDTD region
4fdtd.pause(1)
5fdtd.addfdtd()
6fdtd.print("Example complete. Press space bar to close.")
7fdtd.pause(30) # Will close in 30 seconds if left idle
8fdtd.close()
9
10mode = lumapi.MODE()
11mode.print("Example complete. Press space bar to close.")
12mode.pause(30)
13mode.close()
14
15# Load a session but hide the application window
16fdtd = lumapi.FDTD(hide=True)
17fdtd.close()
Use the “with” context manager#
[ ]:
18with lumapi.FDTD() as fdtd:
19 fdtd.addfdtd()
20 fdtd.print("Example complete. Press space bar to close.")
21 fdtd.pause(30)
22# FDTD closes automatically
Session wrapped in a function#
Get the number of grid cells in FDTD region for set span
[ ]:
23def get_x_cells(fdtd_span):
24 """Return the number of grid cells in FDTD region for a set span."""
25 with lumapi.FDTD() as fdtd:
26 # Adds FDTD region with span set by fdtd_span
27 fdtd.addfdtd(dimension="3D", x_span=fdtd_span, y_span=fdtd_span, z_span=fdtd_span)
28 # Get the x-coordinates of created FDTD region
29 x = fdtd.getresult("FDTD", "x")
30 x_cells = len(x)
31 return x_cells
Test the function and print out the result#
[ ]:
32test = get_x_cells(1e-6)
33print(test)