Skip to content

marksbrown/pylumerical

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pylumerical

Last Altered : 6th February 2014

Python module to perform tasks with Lumerical FDTD-Solutions

Outline

Pylumerical is a a Python module to alter and execute Lumerical lsf scripts. The code can :

  1. Generate multiple .fsp Lumerical binary files from single Lumerical .lsf script file using the GUI licence to perform parameter sweeps.
  2. Execute valid .fsp files using Engine licence(s) using MPI.
  3. Execute processing .lsf scripts upon completed simulation .fsp files

Original lsf Structure

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.

Processing lsf Structure

    #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.

Parameter Sweep Example

####
# 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!")

About

Python module to work with FDTD software - Lumerical.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages