Skip to content

Commit

Permalink
Version 0.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Hideousmon committed May 21, 2024
1 parent 9295d5b commit 05f2149
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 26 deletions.
9 changes: 5 additions & 4 deletions docs/gettingstarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ Create a simulation for a waveguide.

```python
from splayout import *
import matplotlib.pyplot as plt

# initialize the simulation frame
fdtd = FDTDSimulation(fdtd_path="C:\\Program Files\\Lumerical\\v202\\api\\python")
fdtd = FDTDSimulation()

# draw waveguides on Lumerical
waveguide = Waveguide(start_point=Point(-3,0), end_point=Point(3,0), width=1, z_start=-0.11, z_end=0.11, material=Si)
waveguide.draw_on_lumerical_CAD(fdtd)

# add simulation region, source, and monitor
fdtd.add_fdtd_region(bottom_left_corner_point=Point(-2, -1.5), top_right_corner_point=Point(2, 1.5), background_index=1.444,dimension=3, height=0.8)
# add simulation region, source, and monitor
fdtd.add_fdtd_region(bottom_left_corner_point=Point(-2, -1.5), top_right_corner_point=Point(2, 1.5), background_index=1.444,dimension=3, height=0.8, use_gpu=0)

fdtd.add_mode_source(position=Point(-1.5,0), width=1.5, height=0.8, wavelength_start=1.54, wavelength_end=1.57, mode_number=1)

Expand Down Expand Up @@ -335,7 +336,7 @@ rectangle.draw(cell,wg_layer)



## Functions for Self-define Components
## Functions for Customizing Components

### AEMD Grating

Expand Down
4 changes: 2 additions & 2 deletions examples/simulation/waveguide.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

if __name__ == '__main__':
# initialize the simulation frame
fdtd = FDTDSimulation(fdtd_path="C:\\Program Files\\Lumerical\\v202\\api\\python")
fdtd = FDTDSimulation()

# draw waveguides on Lumerical
waveguide = Waveguide(start_point=Point(-3,0), end_point=Point(3,0), width=1, z_start=-0.11, z_end=0.11, material=Si)
waveguide.draw_on_lumerical_CAD(fdtd)

# add simulation region, source, and monitor
fdtd.add_fdtd_region(bottom_left_corner_point=Point(-2, -1.5), top_right_corner_point=Point(2, 1.5), background_index=1.444,dimension=3, height=0.8)
fdtd.add_fdtd_region(bottom_left_corner_point=Point(-2, -1.5), top_right_corner_point=Point(2, 1.5), background_index=1.444,dimension=3, height=0.8, use_gpu=0)

fdtd.add_mode_source(position=Point(-1.5,0), width=1.5, height=0.8, wavelength_start=1.54, wavelength_end=1.57, mode_number=1)

Expand Down
6 changes: 5 additions & 1 deletion history.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,8 @@
* Update readme.md
* Update api reference for pixelated regions.
* New functions in FDTDSimulation.
* Add boolean operations example and docs.
* Add boolean operations example and docs.

### Version 0.5.4 (May 21, 2024)
* Automatically search for Ansys Lumerical Python API.
* Add use_gpu option for fdtd_region.
2 changes: 1 addition & 1 deletion splayout/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.5.3"
__version__ = "0.5.4"

## Submodules
from . import utils
Expand Down
57 changes: 40 additions & 17 deletions splayout/lumericalcommun/fdtdapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,35 @@ class FDTDSimulation:
Path to the .fsp file that what want to be loaded (default: None).
"""
def __init__(self,hide=0,fdtd_path = "C:\\Program Files\\Lumerical\\v202\\api\\python\\", load_file = None):
sys.path.append(fdtd_path)
sys.path.append(os.path.dirname(__file__))
try:
os.add_dll_directory(fdtd_path)
except:
pass
try:
import lumapi
except:
raise Exception(
"Lumerical FDTD is not installed in the default path, please specify the python api path with fdtd_path=***.")
def __init__(self, hide=0, fdtd_path=None, load_file = None):
if not fdtd_path is None:
sys.path.append(fdtd_path)
sys.path.append(os.path.dirname(__file__))
try:
os.add_dll_directory(fdtd_path)
except:
pass
try:
import lumapi
except:
raise Exception(
"Can not find Lumerical FDTD in fdtd_path.")
else: # auto find
fdtd_path = find_lumerical()
if not fdtd_path is None:
sys.path.append(fdtd_path)
sys.path.append(os.path.dirname(__file__))
try:
os.add_dll_directory(fdtd_path)
except:
pass
try:
import lumapi
except:
raise Exception("Import lumapi error.")
else: # fail to find
raise Exception("Can not find Lumerical FDTD automatically, please set fdtd_path=*** in FDTDSimulation.")

self.lumapi = lumapi
self.fdtd = self.lumapi.FDTD(hide=hide)
if (type(load_file) != type(None)):
Expand Down Expand Up @@ -487,7 +504,7 @@ def reset_source_phase(self, source_name, phase):

def add_fdtd_region(self,bottom_left_corner_point,top_right_corner_point,simulation_time=5000, background_material = None,
background_index=1.444,mesh_order =2,dimension=3,height = 1, z_min = None,
z_max = None, z_symmetric = 0, y_antisymmetric = 0, y_periodic = 0, pml_layers = 8):
z_max = None, z_symmetric = 0, y_antisymmetric = 0, y_periodic = 0, pml_layers = 8, use_gpu = 0):
"""
Add simulation region in Lumerical FDTD.
Expand Down Expand Up @@ -519,7 +536,10 @@ def add_fdtd_region(self,bottom_left_corner_point,top_right_corner_point,simulat
Whether set anti-symmetric in y-axis (default: 0).
y_periodic : Bool or Int
Whether set periodic in y-axis (default: 0).
pml_layers : Int
Number of pml layers (default: 8).
use_gpu : Bool or Int
Whether to use gpu (default: 8).
Notes
-----
If z_min and z_max are specified, the height property will be invalid.
Expand Down Expand Up @@ -554,16 +574,19 @@ def add_fdtd_region(self,bottom_left_corner_point,top_right_corner_point,simulat
self.fdtd.eval("set(\"mesh accuracy\"," + str(mesh_order) + ");")
self.fdtd.eval("set(\"pml layers\"," +str(pml_layers) +");")

if (dimension == 3 and z_symmetric == 1):
if dimension == 3 and z_symmetric == 1:
self.fdtd.eval("set(\"z min bc\", \"Symmetric\");")

if (y_antisymmetric == 1):
if y_antisymmetric == 1:
self.fdtd.eval("set(\"y min bc\", \"Anti-Symmetric\");")
self.fdtd.eval("set(\"force symmetric y mesh\", 1);")

if (y_periodic == 1):
if y_periodic == 1:
self.fdtd.eval("set(\"y min bc\", \"Periodic\");")

if use_gpu == 1:
self.fdtd.eval("set(\"express mode\", 1);")

def add_index_region(self, bottom_left_corner_point, top_right_corner_point, height = 1, z_min = None, z_max = None, index_monitor_name="index",dimension = 2):
"""
Add index monitor (x-y plane) in Lumerical FDTD.
Expand Down
20 changes: 19 additions & 1 deletion splayout/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import gdspy
import math
import os

## "macros"
RIGHT = 0
Expand Down Expand Up @@ -405,4 +406,21 @@ def make_gdsii_file(filename,cover_source_layer=None,cover_target_layer=None,inv
if (filename[-4:] != ".gds"):
filename += ".gds"

lib.write_gds(filename)
lib.write_gds(filename)

def find_lumerical():
preset_disks = ["C:/", "D:/", "E:/", "F:/", "G:/", "H:/", "I:/", "J:/",
"K:/", "L:/", "M:/", "N:/", "O:/", "P:/", "Q:/", "R:/",
"S:/", "T:/", "U:/", "V:", "W:/", "X:/", "Y:/", "Z:/"]
preset_dir = ["Program Files/Lumerical/", "Lumerical/"]
version_numbers = [str(num) for num in range(202, 250)]
preset_version = [ "v" + version_number + "/api/python" for version_number in version_numbers]

lumerical_api_path = None
for disk in preset_disks:
for pdir in preset_dir:
for pver in preset_version:
if os.path.exists(disk + pdir + pver):
lumerical_api_path = disk + pdir + pver

return lumerical_api_path

0 comments on commit 05f2149

Please sign in to comment.