S4
S4 copied to clipboard
A problem of "GetAmplitudes"
Hi! I want to use "GetAmplitudes" for calculating reflection phase, but it can not work. The error is "GetAmplitudes: S4_Layer named 'Above1' not found." I am confused about this issue and look forward to your help. The code is attached below.
filename1='GetAmplitudes.csv'; file1=io.output(filename1)
--Parameter------------------------------------- um=1; nm=um1e-3; p=568nm; tg1=0.8p; lambda=1550nm;
S=S4.NewSimulation() S:SetLattice({p,0},{0,0}) S:SetNumG(100) S:AddMaterial("Vacuum",{1,0}) S:AddMaterial("Si",{3.483.48,0}) S:AddLayer('Above1',0,'Vacuum') S:AddLayer('Slab1',tg1,'Vacuum') S:SetLayerPatternRectangle('Slab1', "Si", {0,0}, 0, {0.29p,0}) S:AddLayer('Below1',0,'Vacuum') S:SetExcitationPlanewave({80,0},{0,0},{1,0}) S:SetFrequency(1/lambda)
--Reflection-------------------------------
forw,back = S:GetAmplitudes('Above1',0) file1:write(forw[1][1],",",forw[1][2],",",back[1][1],",",back[1][2],",") file1:write("\n") file1:close()
I also have this issue. I guess 'GetAmplitudes' method is obsolete or broken?
--- a/S4/main_lua.c
+++ b/S4/main_lua.c
@@ -2186,7 +2186,7 @@ static int S4L_Simulation_GetAmplitudes(lua_State *L){
layer_name = luaL_checklstring(L, 2, NULL);
layer = S4_Simulation_GetLayerByName(S, layer_name);
- if(NULL == layer){
+ if(layer < 0){
S4L_error(L, "GetAmplitudes: S4_Layer named '%s' not found.", layer_name);
return 0;
}
@@ -2204,7 +2204,7 @@ static int S4L_Simulation_GetAmplitudes(lua_State *L){
amp = (double*)malloc(sizeof(double)*8*n);
Simulation_GetAmplitudes(S,
- layer,
+ &S->layer[layer],
luaL_checknumber(L, 3),
amp, &[4*n]);
It seems to be working after making this change.
--- a/S4/main_lua.c +++ b/S4/main_lua.c @@ -2186,7 +2186,7 @@ static int S4L_Simulation_GetAmplitudes(lua_State *L){ layer_name = luaL_checklstring(L, 2, NULL); layer = S4_Simulation_GetLayerByName(S, layer_name); - if(NULL == layer){ + if(layer < 0){ S4L_error(L, "GetAmplitudes: S4_Layer named '%s' not found.", layer_name); return 0; } @@ -2204,7 +2204,7 @@ static int S4L_Simulation_GetAmplitudes(lua_State *L){ amp = (double*)malloc(sizeof(double)*8*n); Simulation_GetAmplitudes(S, - layer, + &S->layer[layer], luaL_checknumber(L, 3), amp, &[4*n]);
It seems to be working after making this change.
I did this change, but only GetAmplitudes only works por s-pol. Is the same for you?