S4 icon indicating copy to clipboard operation
S4 copied to clipboard

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

Open amsc1985 opened this issue 6 years ago • 1 comments

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')

amsc1985 avatar May 02 '18 21:05 amsc1985

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})

kwrobert avatar May 02 '18 22:05 kwrobert