Last Altered : 6th February 2014
Python module to perform tasks with Lumerical FDTD-Solutions
Pylumerical is a a Python module to alter and execute Lumerical lsf scripts. The code can :
- Generate multiple .fsp Lumerical binary files from single Lumerical .lsf script file using the GUI licence to perform parameter sweeps.
- Execute valid .fsp files using Engine licence(s) using MPI.
- Execute processing .lsf scripts upon completed simulation .fsp files
First we need to design a simulation using FDTD-Solutions. The script file should take the form :
deleteall;
#Description of simulation
#<variables>#
...
#</variables>#
redrawoff;
<Insert simulation definition here>
redrawon;
Any variables which define the simulation should be placed between the tags. The deleteall command ensures a clean environment before generation. redrawoff and redrawon dramatically speed up the fsp generation time as the GUI is not wasting time drawing the 3D simulation.
#Description of processing script
#<variables>#
...
#</variables>#
system("rm -f "+Savefullpath+"*"); #clears output directory
if(layoutmode==0){
<Processing Script Details Here!>
}else{
?"No data to analysis in this fsp file!";
}
exit(2);
In this we've chosen to always output csv files to SaveFullpath which will be added to the processing script automatically.
####
# DipoleArray Parameter Sweep Example
####
from __future__ import division,print_function
import os
import pylumerical as pyl
from numpy import linspace
##consts
nm = 1e-9
verbose = 1
workingdir = '/tmp/lumerical'
scriptloc = os.path.join(os.getcwd(),'originalscripts')
processingloc = os.path.join(os.getcwd(),'processingscripts')
defaultparams = {'BravaisTheta': 90, 'LX': 100*nm, 'LY': 100*nm, 'MonitorMargin': 2*nm,
'MarginXY' : 200*nm, 'MarginZ' : 100*nm, 'N01': 0, 'N02': 0, 'N11': 0,
'N12': 0, 'MonitorLoc': 0, 'phi': 0,'theta': 0}
newparams = [('MonitorLoc' , [2]),
('MarginXY' , linspace(100,200,4)*nm)]
fsploc, outputloc = pyl.ParameterSweepInput(workingdir, 'MarginVary', newparams,
defaultparams, (scriptloc, 'DipoleArray'), verbose=verbose)
print("Input lsf & FSP Generated")
pyl.ExecuteFSPfiles(fsploc, cores=8, verbose=verbose)
print("FSP Processed")
scriptparams = {'Monitor' : "PowerMonitor"} #optical arguments for processing script
pyl.ProcessGenerated(fsploc, outputloc, processingloc, 'farfieldsave', scriptparams, verbose=verbose)
print("Complete!")