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
131 stars 149 forks source link

SetLayerThickness not working? #74

Closed Chronum94 closed 2 years ago

Chronum94 commented 6 years ago

Code:

sim = S4.NewSimulation()
-- Real and image eps for x, y, and z directions
exr, exi, eyr, eyi, ezr, ezi = 5, 0, 10, 0, 11, 0
pcall(loadstring(S4.arg))
sim:SetNumG(1) -- only need 1 G vector because homogeneus layer

sim:AddMaterial('Air', {1, 0}) -- Air with permittivity 1 + 0i

-- Borophene permittivity. The components are entered in via cli args.
borophene_permittivity = {{exr, exi}, {0, 0}, {0, 0},
                          {0, 0}, {eyr, eyi}, {0, 0},
                          {0, 0}, {0, 0}, {ezr, ezi}}
sim:AddMaterial('Boron', borophene_permittivity)

-- Layer of freestanding boron in air.
sim:AddLayer('AirAbove', 0, 'Air')
sim:AddLayer('Boronsheet', 1, 'Boron')
sim:AddLayerCopy('AirBelow', 0, 'AirAbove')

sim:SetExcitationPlanewave({0, 0}, {1, 0}, {0, 0})
for thickness=1,2,0.1 do
  sim:SetLayerThickness('Boronsheet', thickness)
  sim:SetLayerThickness('AirBelow', 0)
  forfirst, backfirst = sim:GetPowerFlux('AirAbove', 0)
  forlast, backlast = sim:GetPowerFlux('AirBelow', 0)
  print(thickness, forfirst, backfirst, forlast, backlast)
end

Running with: ./S4 -a "" boron_monolayer_optical_properties.lua

Gives me:

1       1       -0.33118391752986       0.66881608247014        0
1.1     1       -0.33118391752986       0.66881608247014        0
1.2     1       -0.33118391752986       0.66881608247014        0
1.3     1       -0.33118391752986       0.66881608247014        0
1.4     1       -0.33118391752986       0.66881608247014        0
1.5     1       -0.33118391752986       0.66881608247014        0
1.6     1       -0.33118391752986       0.66881608247014        0
1.7     1       -0.33118391752986       0.66881608247014        0
1.8     1       -0.33118391752986       0.66881608247014        0
1.9     1       -0.33118391752986       0.66881608247014        0

What's going on here? Any help appreciated.

hamdav commented 3 years ago

Hey! I found the same thing so I fixed it, see my pull request at #95. If you are still interested that is, two years is a while...