Skip to content

Commit 021b72e

Browse files
alec-flexcomputetylerflex
authored andcommitted
added lsf converter
1 parent 15b3f7c commit 021b72e

File tree

4 files changed

+1520
-0
lines changed

4 files changed

+1520
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- `ModeSolverData.pol_fraction` and `ModeSolverData.pol_fraction_waveguide` properties to compute polarization fraction of modes using two different definitions.
2121
- `ModeSolverData.to_dataframe()` and `ModeSolverData.modes_info` for a convenient summary of various modal properties of the computed modes.
2222
- Loss upper bound estimation in `PoleResidue` material model.
23+
- Command line tool `tidy3d convert` for conversion from `.lsf` project files into equivalent python scripts implementing the project in Tidy3D. Usage: `tidy3d convert example.lsf tidy3d_script.py`.
2324

2425
### Changed
2526
- Output task URL before and after simulation run and make URLs blue underline formatting.

tests/data/example.lsf

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# https://optics.ansys.com/hc/en-us/articles/360034923553-Lumerical-scripting-language-Alphabetical-list
2+
# https://readthedocs.org/projects/lumopt/downloads/pdf/latest/
3+
4+
switchtolayout;
5+
selectall;
6+
delete;
7+
8+
## SIM PARAMS
9+
size_x=6e-6;
10+
size_y=8e-6;
11+
size_z=0;
12+
mesh_x=20e-9;
13+
mesh_y=20e-9;
14+
finer_mesh_size=2.5e-6;
15+
mesh_accuracy=2;
16+
17+
addsphere;
18+
set("name","new_sphere");
19+
set("x",1e-6);
20+
set("y",2e-6);
21+
set("z",0);
22+
set("radius",0.5e-6);
23+
24+
# testing space with comment
25+
test_dict1 = 'yee';
26+
test_dict2 = test_dict1; # check comment after declaration
27+
test_dict3 = True; # further weird ## comment # case
28+
test_dict4 = False;
29+
30+
## GEOMETRY
31+
#INPUT WAVEGUIDE
32+
addrect;
33+
set('name','input wg');
34+
set('x span',3e-6);
35+
set('y span',0.5e-6);
36+
set('z span',220e-9);
37+
set('y',0.0);
38+
set('x',-2.5e-6);
39+
set('index',2.8);
40+
41+
addplane;
42+
set("injection axis","z");
43+
set("direction","backward");
44+
set("x",0);
45+
set("x span",0.5e-6);
46+
set("y",0);
47+
set("y span",5e-6);
48+
set("z",0e-6);
49+
set("wavelength start",0.3e-6);
50+
set("wavelength stop",1.2e-6);
51+
52+
#OUTPUT WAVEGUIDES
53+
addrect;
54+
set('name','output wg top');
55+
set('x span',3e-6);
56+
set('y span',0.5e-6);
57+
set('z span',220e-9);
58+
set('y',0.35e-6);
59+
set('x',2.5e-6);
60+
set('index',2.8);
61+
62+
addrect;
63+
set('name','output wg bottom');
64+
set('x span',3e-6);
65+
set('y span',0.5e-6);
66+
set('z span',220e-9);
67+
set('y',-0.35e-6);
68+
set('x',2.5e-6);
69+
set('index',2.8);
70+
71+
## SOURCE
72+
addmode;
73+
set('direction','Forward');
74+
set('injection axis','x-axis');
75+
#set('polarization angle',0);
76+
set('wavelength start',0.55e-6);
77+
set('wavelength stop', 0.55e-6);
78+
set('y',0.0);
79+
set('y span',size_y);
80+
set('x span',size_x);
81+
set('x',-1.25e-6);
82+
set('override global source settings',false);
83+
set('mode selection','fundamental TE mode');
84+
addgaussian;
85+
set("injection axis","z");
86+
set("direction","backward");
87+
set("x",0);
88+
set("x span",0.5e-6);
89+
set("y",3);
90+
set("y span",0.3e-6);
91+
set("z",0e-6);
92+
set("use scalar approximation",1);
93+
set("waist radius w0",0.5e-6);
94+
set("distance from waist",-5e-6);
95+
96+
## FDTD
97+
addfdtd;
98+
set('dimension','2D');
99+
set('background index',1.44);
100+
set('mesh accuracy',mesh_accuracy);
101+
set('x',0.0);
102+
set('x span',size_x);
103+
set('y',0.0);
104+
set('y span',size_y);
105+
set('z span',size_z);
106+
set('force symmetric y mesh',true);
107+
set('y min bc','Anti-Symmetric');
108+
set('pml layers',12);
109+
110+
## MESH IN OPTIMIZABLE REGION
111+
addmesh;
112+
set('x',0);
113+
set('x span',finer_mesh_size+2.0*mesh_x);
114+
115+
set('y',0);
116+
set('y span',finer_mesh_size);
117+
set('dx',mesh_x);
118+
set('dy',mesh_y);
119+
120+
## OPTIMIZATION FIELDS MONITOR IN OPTIMIZABLE REGION
121+
addpower;
122+
set('name','opt_fields');
123+
set('monitor type','2D Z-normal');
124+
set('x',0);
125+
set('x span',finer_mesh_size);
126+
set('y',0);
127+
set('y span',finer_mesh_size);
128+
129+
addcircle;
130+
set("name","new_circle");
131+
set("x",-1e-6);
132+
set("y",2e-6);
133+
set("radius",0.25e-6);
134+
set("z",0);
135+
set("z span",10e-6);
136+
137+
138+
139+
vtx = [(1,1),(2,2),(2.5,2),(2,1.5),(2.2,1)]; # comment
140+
addpoly;
141+
set("name","random_polygon");
142+
set("vertices",vtx);
143+
set("z span",2e-6);
144+
145+
adddipole;
146+
set("x",0);
147+
set("y",1e-6);
148+
set("z",0e-6);
149+
150+
## FOM FIELDS
151+
addpower;
152+
set('name','fom');
153+
set('monitor type','2D X-normal');
154+
set('x',finer_mesh_size/2.0);
155+
set('y',0.0);
156+
set('y span',size_y);
157+
158+
addefieldmonitor;
159+
set("name","E_field");
160+
set("monitor type",6); # 2D y-normal
161+
set("x",0);
162+
set("x span",5e-6);
163+
set("y",0);
164+
set("z",0);
165+
set("y span",5e-6);
166+
set("record electrostatic potential",1);
167+
set("save data",1);
168+
filename = "electric_field.mat";
169+
set("filename",filename);
170+
171+
addtestUnavailableCommand;
172+
173+
addmodeexpansion;
174+
set("name","mode monitor");
175+
set("x",0);
176+
set("x span",5e-6);
177+
set("y",0);
178+
set("z",0);
179+
set("y span",5e-6);

tidy3d/web/cli/app.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from tidy3d.web.cli.constants import TIDY3D_DIR, CONFIG_FILE, CREDENTIAL_FILE
1313
from tidy3d.web.cli.migrate import migrate
1414
from tidy3d.web.environment import Env
15+
from tidy3d.web.cli.converter import converter_arg
1516

1617
if not os.path.exists(TIDY3D_DIR):
1718
os.mkdir(TIDY3D_DIR)
@@ -114,5 +115,14 @@ def migration():
114115
migrate()
115116

116117

118+
@click.command()
119+
@click.argument("lsf_file", type=click.Path(exists=True))
120+
@click.argument("new_file")
121+
def convert(lsf_file, new_file):
122+
"""Click command to convert .lsf project into Tidy3D .py file"""
123+
converter_arg(lsf_file, new_file)
124+
125+
117126
tidy3d_cli.add_command(configure)
118127
tidy3d_cli.add_command(migration)
128+
tidy3d_cli.add_command(convert)

0 commit comments

Comments
 (0)