victorliu / S4

Stanford Stratified Structure Solver - Electromagnetic simulator for layered periodic structures
http://www.stanford.edu/group/fan/S4/
GNU General Public License v2.0
128 stars 149 forks source link

how to create multiple layers with different fill factors using a for loop? #71

Open amsc1985 opened 6 years ago

amsc1985 commented 6 years ago

Hi I would like to create a taper in 1D simulation. While I can write AddLayers and SetLayerPatternRectangle multiple times. However, this is not practical as the height of the grating increase. I tried writing a for loop but I get error message - GetEpsilon: A duplicate layer name was found. Does anyone know how to create multiple layers with different fill factors using a for loop?

thanks, A

S:AddLayer('S1',2, 'Hi_index') S:AddLayer('S2',0.5, 'Vacuum') S:SetLayerPatternRectangle('S2', -- which layer to alter 'Hi_index', -- material in rectangle {0,0}, -- center 0, -- tilt angle (degrees) {0.5*ff, 0.5}) -- half-widths

for xx=1,5,1 do c = xx print (2c) S:AddLayer('c',0.1c, 'Vacuum') S:SetLayerPatternRectangle('c','Vacuum', {0,0},0, {c*0.025,0.5}) end S:AddLayer('Slab3',0.5, 'Hi_index')
S:AddLayer('AirBelow', 0, 'Vacuum')

kwrobert commented 6 years ago

Your problem is that your S:AddLayer command within the for loop is passing in the string c, instead of your integer loop variable. This means every layer has the name 'c', which is not allows and is why you're seeing this duplicate layer name error. Try changing

S:AddLayer('c',0.1c, 'Vacuum')
S:SetLayerPatternRectangle('c','Vacuum', {0,0},0, {c*0.025,0.5})

to

S:AddLayer(tostring(c),0.1*c, 'Vacuum')
S:SetLayerPatternRectangle(tostring(c),'Vacuum', {0,0},0, {c*0.025,0.5})