@@ -924,7 +924,6 @@ def _addfdtd(Lines, i: int, v_dict: dict) -> str:
924
924
gridspec_string += " wavelength=1.0)"
925
925
sim_string += gridspec_string
926
926
sim_string += ",\n )\n "
927
-
928
927
return sim_string , gridspec_string
929
928
930
929
@@ -962,10 +961,65 @@ def _addmesh(Lines, i: int, overstrct: int):
962
961
override_string += "\t geometry=td.Box(center=(" + x + "," + y + "," + z + "),"
963
962
override_string += "size=(" + xl + "," + yl + "," + zl + ")),\n "
964
963
override_string += "\t dl=(" + dx + "," + dy + "," + dz + "),\n )\n "
965
-
966
964
return override_string , name .replace (" " , "_" )
967
965
968
966
967
+ def _addindex (Lines , i : int , indexmon : int ):
968
+ x , y , z = "0" , "0" , "0"
969
+ xl , yl , zl = "0" , "0" , "0"
970
+ name = "permittivity_monitor_" + str (indexmon )
971
+ freqs = " # NOTE: please specify"
972
+ wave_center , wave_span = "0.5" , "0.1"
973
+ index_monitor_string = " = td.PermittivityMonitor(\n "
974
+ while Lines [i ][0 ] == "\n " or Lines [i ][:5 ] == "set('" or Lines [i ][0 ] == "#" :
975
+ if Lines [i ][5 :9 ] == "name" :
976
+ name = Lines [i ][12 :].split ("'" )[0 ]
977
+ elif Lines [i ][5 :7 ] == "x'" :
978
+ x = Lines [i ][8 :].split (";" )[0 ][:- 1 ]
979
+ elif Lines [i ][5 :7 ] == "y'" :
980
+ y = Lines [i ][8 :].split (";" )[0 ][:- 1 ]
981
+ elif Lines [i ][5 :7 ] == "z'" :
982
+ z = Lines [i ][8 :].split (";" )[0 ][:- 1 ]
983
+ elif Lines [i ][5 :11 ] == "x span" :
984
+ xl = Lines [i ][13 :].split (";" )[0 ][:- 1 ]
985
+ elif Lines [i ][5 :11 ] == "y span" :
986
+ yl = Lines [i ][13 :].split (";" )[0 ][:- 1 ]
987
+ elif Lines [i ][5 :11 ] == "z span" :
988
+ zl = Lines [i ][13 :].split (";" )[0 ][:- 1 ]
989
+ elif Lines [i ][5 :9 ] == "name" :
990
+ name = Lines [i ][12 :].split ("'" )[0 ]
991
+ elif Lines [i ][5 :22 ] == "wavelength center" :
992
+ wave_center = Lines [i ][24 :].split (";" )[0 ][:- 1 ] + "*1e6"
993
+ elif Lines [i ][5 :20 ] == "wavelength span" :
994
+ wave_span = Lines [i ][22 :].split (";" )[0 ][:- 1 ] + "*1e6"
995
+ elif Lines [i ][5 :21 ] == "frequency points" :
996
+ num_freqs = Lines [i ][23 :].split (";" )[0 ][:- 1 ]
997
+ freqs = (
998
+ "np.linspace("
999
+ + wave_center
1000
+ + "-"
1001
+ + wave_span
1002
+ + "/2,"
1003
+ + wave_center
1004
+ + "+"
1005
+ + wave_span
1006
+ + "/2,"
1007
+ + num_freqs
1008
+ + ")"
1009
+ )
1010
+ i += 1
1011
+ if i == len (Lines ):
1012
+ break
1013
+ x , y , z , xl , yl , zl = _to_um ([x , y , z , xl , yl , zl ])
1014
+ index_monitor_string += "\t center=(" + x + "," + y + "," + z + "),\n "
1015
+ index_monitor_string += "\t size=(" + xl + "," + yl + "," + zl + "),\n "
1016
+ index_monitor_string += "\t name='" + name + "',\n "
1017
+ index_monitor_string += "\t interval_space=(1,1,1),\n "
1018
+ index_monitor_string += "\t freqs=" + freqs + ",\n "
1019
+ index_monitor_string += ")\n "
1020
+ return index_monitor_string , name .replace (" " , "_" )
1021
+
1022
+
969
1023
def _addpower (Lines , i : int , fluxmon : int ):
970
1024
x , y , z = "0" , "0" , "0"
971
1025
xl , yl , zl = "0" , "0" , "0"
@@ -1021,6 +1075,62 @@ def _addpower(Lines, i: int, fluxmon: int):
1021
1075
return flux_monitor_string , name .replace (" " , "_" )
1022
1076
1023
1077
1078
+ def _addmovie (Lines , i : int , fieldTime : int ):
1079
+ # https://optics.ansys.com/hc/en-us/articles/360034924633-addefieldmonitor
1080
+ x , y , z = "0" , "0" , "0"
1081
+ xl , yl , zl = "0" , "0" , "0"
1082
+ x_min , x_max = "0" , "0"
1083
+ y_min , y_max = "0" , "0"
1084
+ z_min , z_max = "0" , "0"
1085
+ name = "field_time_monitor_" + str (fieldTime )
1086
+ field_monitor_string = " = td.FieldTimeMonitor(\n "
1087
+ while Lines [i ][0 ] == "\n " or Lines [i ][:5 ] == "set('" or Lines [i ][0 ] == "#" :
1088
+ if Lines [i ][5 :9 ] == "name" :
1089
+ name = Lines [i ][12 :].split ("'" )[0 ]
1090
+ elif Lines [i ][5 :7 ] == "x'" :
1091
+ x = Lines [i ][8 :].split (";" )[0 ][:- 1 ]
1092
+ elif Lines [i ][5 :7 ] == "y'" :
1093
+ y = Lines [i ][8 :].split (";" )[0 ][:- 1 ]
1094
+ elif Lines [i ][5 :7 ] == "z'" :
1095
+ z = Lines [i ][8 :].split (";" )[0 ][:- 1 ]
1096
+ elif Lines [i ][5 :10 ] == "x_min" :
1097
+ x_min = Lines [i ][12 :].split (";" )[0 ][:- 1 ]
1098
+ xl = x_max + "-" + x_min
1099
+ elif Lines [i ][5 :10 ] == "x_max" :
1100
+ x_max = Lines [i ][12 :].split (";" )[0 ][:- 1 ]
1101
+ xl = x_max + "-" + x_min
1102
+ elif Lines [i ][5 :10 ] == "y_min" :
1103
+ y_min = Lines [i ][12 :].split (";" )[0 ][:- 1 ]
1104
+ yl = y_max + "-" + y_min
1105
+ elif Lines [i ][5 :10 ] == "y_max" :
1106
+ y_max = Lines [i ][12 :].split (";" )[0 ][:- 1 ]
1107
+ yl = y_max + "-" + y_min
1108
+ elif Lines [i ][5 :10 ] == "z_min" :
1109
+ z_min = Lines [i ][12 :].split (";" )[0 ][:- 1 ]
1110
+ zl = z_max + "-" + z_min
1111
+ elif Lines [i ][5 :10 ] == "z_max" :
1112
+ z_max = Lines [i ][12 :].split (";" )[0 ][:- 1 ]
1113
+ zl = z_max + "-" + z_min
1114
+ elif Lines [i ][5 :11 ] == "x span" :
1115
+ xl = Lines [i ][13 :].split (";" )[0 ][:- 1 ]
1116
+ elif Lines [i ][5 :11 ] == "y span" :
1117
+ yl = Lines [i ][13 :].split (";" )[0 ][:- 1 ]
1118
+ elif Lines [i ][5 :11 ] == "z span" :
1119
+ zl = Lines [i ][13 :].split (";" )[0 ][:- 1 ]
1120
+ i += 1
1121
+ if i == len (Lines ):
1122
+ break
1123
+ x , y , z , xl , yl , zl = _to_um ([x , y , z , xl , yl , zl ])
1124
+ field_monitor_string += "\t center=(" + x + "," + y + "," + z + "),\n "
1125
+ field_monitor_string += "\t size=(" + xl + "," + yl + "," + zl + "),\n "
1126
+ field_monitor_string += "\t name='" + name + "',\n "
1127
+ field_monitor_string += "\t interval=1,\n "
1128
+ field_monitor_string += "\t start=0.0,\n "
1129
+ field_monitor_string += "\t stop=None,\n "
1130
+ field_monitor_string += ")\n "
1131
+ return field_monitor_string , name .replace (" " , "_" )
1132
+
1133
+
1024
1134
def _addefieldmonitor (Lines , i : int , fieldmon : int ):
1025
1135
# https://optics.ansys.com/hc/en-us/articles/360034924633-addefieldmonitor
1026
1136
x , y , z = "0" , "0" , "0"
@@ -1196,7 +1306,7 @@ def lsf_reader(filename: str) -> None:
1196
1306
rect , sph , cyl , polyslab = 0 , 0 , 0 , 0
1197
1307
sources , modesrc , planewv , ptdipole , gauss , tfsf = "[" , 0 , 0 , 0 , 0 , 0
1198
1308
monitors = "["
1199
- modemon , fluxmon , fieldmon = 0 , 0 , 0
1309
+ modemon , fluxmon , fieldmon , fieldTime , indexmon = 0 , 0 , 0 , 0 , 0
1200
1310
gridspec_string = "grid_spec=td.GridSpec.auto()"
1201
1311
override_structures , overstrct = "[" , 0
1202
1312
@@ -1267,12 +1377,35 @@ def lsf_reader(filename: str) -> None:
1267
1377
override_structures += refine_box_name + ", "
1268
1378
tidy3d_file += refine_box_name + override_string
1269
1379
overstrct += 1
1380
+ elif (
1381
+ line [:9 ] == "addindex;"
1382
+ or line [:18 ] == "addeffectiveindex;"
1383
+ or line [:12 ] == "addemeindex;"
1384
+ ):
1385
+ addindex_string , index_name = _addindex (Lines , i + 1 , indexmon )
1386
+ monitors += index_name + ", "
1387
+ tidy3d_file += index_name + addindex_string
1388
+ indexmon += 1
1270
1389
elif line [:9 ] == "addpower;" :
1271
1390
addpower_string , power_name = _addpower (Lines , i + 1 , fluxmon )
1272
1391
monitors += power_name + ", "
1273
1392
tidy3d_file += power_name + addpower_string
1274
1393
fluxmon += 1
1275
- elif line [:17 ] == "addefieldmonitor;" :
1394
+ elif (
1395
+ line [:9 ] == "addmovie;"
1396
+ or line [:22 ] == "addemfieldtimemonitor;"
1397
+ or line [:8 ] == "addtime;"
1398
+ ):
1399
+ addmovie_string , movie_name = _addmovie (Lines , i + 1 , fieldTime )
1400
+ monitors += movie_name + ", "
1401
+ tidy3d_file += movie_name + addmovie_string
1402
+ fieldTime += 1
1403
+ elif (
1404
+ line [:17 ] == "addefieldmonitor;"
1405
+ or line [:11 ] == "addprofile;"
1406
+ or line [:18 ] == "addemfieldmonitor;"
1407
+ or line [:14 ] == "addemeprofile;"
1408
+ ):
1276
1409
addefieldmonitor_string , monitor_name = _addefieldmonitor (Lines , i + 1 , fieldmon )
1277
1410
monitors += monitor_name + ", "
1278
1411
tidy3d_file += monitor_name + addefieldmonitor_string
@@ -1293,11 +1426,22 @@ def lsf_reader(filename: str) -> None:
1293
1426
pass
1294
1427
else :
1295
1428
tidy3d_file += "# " + line [:- 1 ] + " # NOTE: does not yet parse to Tidy3D\n "
1296
- structures = structures [:- 2 ] + "]"
1297
- sources = sources [:- 2 ] + "]"
1298
- monitors = monitors [:- 2 ] + "]"
1299
- override_structures = override_structures [:- 2 ] + "]"
1300
-
1429
+ if len (structures ) > 1 :
1430
+ structures = structures [:- 2 ] + "]"
1431
+ else :
1432
+ structures = "[]"
1433
+ if len (sources ) > 1 :
1434
+ sources = sources [:- 2 ] + "]"
1435
+ else :
1436
+ sources = "[]"
1437
+ if len (monitors ) > 1 :
1438
+ monitors = monitors [:- 2 ] + "]"
1439
+ else :
1440
+ monitors = "[]"
1441
+ if len (override_structures ) > 1 :
1442
+ override_structures = override_structures [:- 2 ] + "]"
1443
+ else :
1444
+ override_structures = "[]"
1301
1445
tidy3d_file += "\n sim = sim.copy(update=dict(structures=" + structures + ","
1302
1446
tidy3d_file += " # NOTE: Check order of structures for potential overlap issues\n "
1303
1447
tidy3d_file += "\t sources=" + sources + ",\n "
@@ -1310,7 +1454,6 @@ def lsf_reader(filename: str) -> None:
1310
1454
+ ")\n \t )\n "
1311
1455
)
1312
1456
tidy3d_file += ")"
1313
-
1314
1457
return tidy3d_file
1315
1458
1316
1459
0 commit comments