|
|
Line 1: |
Line 1: |
− | ## LionixPyScriptExampleFDM.py
| |
− | ## SAVE AS ".py"
| |
| | | |
− |
| |
− | ## Basic commands to initialize communication with running Fimmwave program
| |
− | from pdPythonLib import *
| |
− | fimm = pdApp()
| |
− | fimm.ConnectToApp()
| |
− |
| |
− | ## Naming convention for you files you may find this to be helpful
| |
− | DeviceName = 'LioniX Strip WG'
| |
− | Sweep = 'w_WG,h_WG'
| |
− | Description = 'LioniX WG 2 Mode Summary'
| |
− |
| |
− | ## Write file with parameters first
| |
− | filename = DeviceName+' - SWEEP_'+Sweep+' - '+Description+'.dat'
| |
− | f = open(filename,'a') # Have found that 'a'pending to files prevents lost data you can also'w'rite over whatever was in the previous file of that name.
| |
− |
| |
− |
| |
− | ## (OPTIONAL) Set constants, else you can set them in the Fimmwave GUI
| |
− | xDomain = 10
| |
− | fimm.Exec("app.subnodes[1].subnodes[2].setvariable(xDomain,{xDomain})")
| |
− | yDomain = 10
| |
− | fimm.Exec("app.subnodes[1].subnodes[2].setvariable(yDomain,{yDomain})")
| |
− | n_SiO2 = 1.4456
| |
− | fimm.Exec("app.subnodes[1].subnodes[2].setvariable(n_SiO2,{n_SiO2})")
| |
− | n_Si3N4 = 1.9835
| |
− | fimm.Exec("app.subnodes[1].subnodes[2].setvariable(n_Si3N4,{n_Si3N4})")
| |
− | lambda0 = 1.55
| |
− | fimm.Exec("app.subnodes[1].subnodes[2].setvariable(lambda0,{lambda0})")
| |
− |
| |
− | ## Create File Header
| |
− | f.write(DeviceName+'\t')
| |
− | f.write('\n')
| |
− | f.write('User = PyScript NOOB!!!'+'\t')
| |
− | f.write('\n')
| |
− | f.write('\n')
| |
− |
| |
− | ## Records the actual values of your constants to the file for later reference
| |
− | f.write('xDomain ='+'\t')
| |
− | xDomain = fimm.Exec("app.subnodes[1].subnodes[2].getvariable(xDomain)")
| |
− | f.write(str(xDomain)+'\t')
| |
− | f.write('um'+'\t')
| |
− | f.write('\n')
| |
− | f.write('yDomain ='+'\t')
| |
− | yDomain = fimm.Exec("app.subnodes[1].subnodes[2].getvariable(yDomain)")
| |
− | f.write(str(yDomain)+'\t')
| |
− | f.write('um'+'\t')
| |
− | f.write('\n')
| |
− | f.write('n_SiO2 ='+'\t')
| |
− | n_SiO2 = fimm.Exec("app.subnodes[1].subnodes[2].getvariable(n_SiO2)")
| |
− | f.write(str(n_SiO2)+'\t')
| |
− | f.write('\n')
| |
− | f.write('n_Si3N4 ='+'\t')
| |
− | n_Si3N4 = fimm.Exec("app.subnodes[1].subnodes[2].getvariable(n_Si3N4)")
| |
− | f.write(str(n_Si3N4)+'\t')
| |
− | f.write('lambda0 ='+'\t')
| |
− | lambda0 = fimm.Exec("app.subnodes[1].subnodes[2].getvariable(lambda0)")
| |
− | f.write(str(lambda0)+'\t')
| |
− | f.write('um'+'\t')
| |
− | f.write('\n')
| |
− | f.write('\n')
| |
− |
| |
− | ## Prints the file header
| |
− | print(DeviceName+'\t')
| |
− |
| |
− | print('User = PyScript NOOB!!!'+'\t')
| |
− |
| |
− |
| |
− |
| |
− | ## Print the actual values of your constants to the file for later reference
| |
− | print('xDomain ='+'\t')
| |
− | xDomain = fimm.Exec("app.subnodes[1].subnodes[2].getvariable(xDomain)")
| |
− | print(str(xDomain)+'\t')
| |
− | print('um'+'\t')
| |
− |
| |
− | print('yDomain ='+'\t')
| |
− | yDomain = fimm.Exec("app.subnodes[1].subnodes[2].getvariable(yDomain)")
| |
− | print(str(yDomain)+'\t')
| |
− | print('um'+'\t')
| |
− |
| |
− | print('n_SiO2 ='+'\t')
| |
− | n_SiO2 = fimm.Exec("app.subnodes[1].subnodes[2].getvariable(n_SiO2)")
| |
− | print(str(n_SiO2)+'\t')
| |
− |
| |
− | print('n_Si3N4 ='+'\t')
| |
− | n_Si3N4 = fimm.Exec("app.subnodes[1].subnodes[2].getvariable(n_Si3N4)")
| |
− | print(str(n_Si3N4)+'\t')
| |
− | print('lambda0 ='+'\t')
| |
− | lambda0 = fimm.Exec("app.subnodes[1].subnodes[2].getvariable(lambda0)")
| |
− | print(str(lambda0)+'\t')
| |
− | print('um'+'\t')
| |
− |
| |
− |
| |
− |
| |
− | f.close() # In case the program crashes while simulating I like to only open the file when I'm writing to it.
| |
− |
| |
− | ## Saves the Fimmwave file in its current state. You may fine that you would like to do this in other places in your program.
| |
− | fimm.Exec("app.subnodes[1].savetofile()")
| |
− |
| |
− |
| |
− | ## SWEEP w_WG
| |
− | starti = 2.5
| |
− | stepi = .25
| |
− | stopi = 3
| |
− | n_stepsi = (stopi-starti)/stepi+1
| |
− |
| |
− | ## SWEEP h_WG
| |
− | startj = 0.05
| |
− | stepj = 0.05
| |
− | stopj = 0.1
| |
− | n_stepsj = (stopj-startj)/stepj+1
| |
− |
| |
− | Nmodes = 2
| |
− |
| |
− | print "n_stepsi = "+str(n_stepsi)+"\n"
| |
− | print "n_stepsj = "+str(n_stepsj)+"\n"
| |
− | print "Nmodes = "+str(Nmodes)+"\n"
| |
− |
| |
− | for i in range (0,n_stepsi):
| |
− | w_WG = stepi*i+starti
| |
− | fimm.Exec("app.subnodes[1].subnodes[2].setvariable(w_WG,{w_WG})")
| |
− | # Note: use {} to reference the value of Pyton variable in the command lines that you send Fimmwave.
| |
− |
| |
− |
| |
− | for j in range (0,n_stepsj):
| |
− | h_WG = stepj*j+startj
| |
− | fimm.Exec("app.subnodes[1].subnodes[2].setvariable(h_WG,{h_WG})")
| |
− |
| |
− | ## Define the mode calculation parameters
| |
− |
| |
− | ## This code is specific to the FDM solver. For FMM you will find suble differences see LionixPyScriptExampleFMM.py
| |
− | fimm.Exec("app.subnodes[1].subnodes[1].evlist.svp.lambda={lambda0}" + "\n" +
| |
− | "app.subnodes[1].subnodes[1].evlist.svp.hcurv=0" + "\n" +
| |
− | "app.subnodes[1].subnodes[1].evlist.svp.solvid=71" + "\n" +
| |
− | "app.subnodes[1].subnodes[1].evlist.svp.hsymmetry=3" + "\n" +
| |
− | "app.subnodes[1].subnodes[1].evlist.svp.vsymmetry=0" + "\n" +
| |
− | "app.subnodes[1].subnodes[1].evlist.svp.buff=V1 200 400 0 100 0.010000" + "\n" +
| |
− | "app.subnodes[1].subnodes[1].evlist.mlp.autorun=0" + "\n" +
| |
− | "app.subnodes[1].subnodes[1].evlist.mlp.speed=0" + "\n" +
| |
− | "app.subnodes[1].subnodes[1].evlist.mlp.mintefrac=0" + "\n" +
| |
− | "app.subnodes[1].subnodes[1].evlist.mlp.maxtefrac=100" + "\n" +
| |
− | "app.subnodes[1].subnodes[1].evlist.mlp.maxnmodes={Nmodes}" + "\n" +
| |
− | "app.subnodes[1].subnodes[1].evlist.mlp.evstart=1e+050" + "\n" +
| |
− | "app.subnodes[1].subnodes[1].evlist.mlp.evend=-1e+050" + "\n" +
| |
− | "app.subnodes[1].subnodes[1].evlist.mlp.nx=200" + "\n" +
| |
− | "app.subnodes[1].subnodes[1].evlist.mlp.ny=400")
| |
− | ## Defines the region to calculate the confinement factor over (THIS IS VARY PARTICULAR TO THIS LIONIX WG STRUCTURE!!!!)
| |
− | fimm.Exec("app.subnodes[1].subnodes[1].slices[2].layers[2].cfseg = 1") # assumes all other layers are not tag "cfseg"
| |
− |
| |
− | ## Calculate the modes
| |
− | fimm.Exec("app.subnodes[1].subnodes[1].evlist.update")
| |
− |
| |
− | #### I have included these polishing commands as is is sometimes faster to first calculate at low res and then polish to higher.
| |
− | ####
| |
− | ## ## Change the resolution of the FDM solver (you will find this command above)
| |
− | ## fimm.Exec("app.subnodes[1].subnodes[1].evlist.svp.buff=V1 300 500 0 100 0.010000")
| |
− | ## ## Polish the modes
| |
− | ## fimm.Exec("app.subnodes[1].subnodes[1].evlist.polishevs")
| |
− | ## ## In the event that the polishing reduces the number of modes, this grabs the new number
| |
− | ## Nmodes = fimm.Exec("app.subnodes[1].subnodes[1].evlist.nevals")
| |
− |
| |
− | f = open(filename,'a')
| |
− | temp = [0]*int(Nmodes)
| |
− | for k in range (1,Nmodes+1):
| |
− | if (i == 0) & (j == 0) & (k == 1):
| |
− | ## Write table header to file
| |
− | f.write('WG Width (um)'+'\t')
| |
− | f.write('WG Hieght (um)'+'\t')
| |
− | f.write('Mode Number'+'\t')
| |
− | f.write('TE (%)'+'\t')
| |
− | f.write('Effective Area'+'\t')
| |
− | f.write('neff'+'\t')
| |
− | f.write('WG Overlap'+'\t')
| |
− |
| |
− | f.write('\n')
| |
− |
| |
− | ## Write table header to screen
| |
− | print('WG Width (um)'+'\t'+
| |
− | 'WG Hieght (um)'+'\t'+
| |
− | 'Mode Number'+'\t'+
| |
− | 'TE (%)'+'\t'+
| |
− | 'Effective Area'+'\t'+
| |
− | 'neff'+'\t'+
| |
− | 'WG Overlap'+'\n')
| |
− |
| |
− | ## Write table to file
| |
− | f.write(str(fimm.Exec("app.subnodes[1].subnodes[2].getvariable(w_WG)"))+'\t')
| |
− | f.write(str(fimm.Exec("app.subnodes[1].subnodes[2].getvariable(h_WG)"))+'\t')
| |
− | f.write(str(k)+'\t') # Mode Number
| |
− | f.write(str(fimm.Exec("app.subnodes[1].subnodes[1].evlist.list[{k}].modedata.tefrac"))+'\t')
| |
− | f.write(str(fimm.Exec("app.subnodes[1].subnodes[1].evlist.list[1].modedata.a_eff"))+'\t')
| |
− | f.write(str(fimm.Exec("app.subnodes[1].subnodes[1].evlist.list[{k}].neff").real)+'\t')
| |
− | f.write(str(fimm.Exec("app.subnodes[1].subnodes[1].evlist.list[{k}].modedata.fillFac"))+'\n')
| |
− |
| |
− | ## Print table to screen
| |
− | print(str(fimm.Exec("app.subnodes[1].subnodes[2].getvariable(w_WG)"))+'\t'+
| |
− | str(fimm.Exec("app.subnodes[1].subnodes[2].getvariable(h_WG)"))+'\t'+
| |
− | str(k)+'\t'+
| |
− | str(fimm.Exec("app.subnodes[1].subnodes[1].evlist.list[{k}].modedata.tefrac"))+'\t'+
| |
− | str(fimm.Exec("app.subnodes[1].subnodes[1].evlist.list[1].modedata.a_eff"))+'\t'+
| |
− | str(fimm.Exec("app.subnodes[1].subnodes[1].evlist.list[{k}].neff").real)+'\t'+
| |
− | str(fimm.Exec("app.subnodes[1].subnodes[1].evlist.list[{k}].modedata.fillFac"))+'\n')
| |
− |
| |
− | f.close()
| |
− |
| |
− | raw_input("Done (Press any key):")
| |
− | del fimm
| |