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

Fix bug in SetLayer and SetLayerThickness #95

Open hamdav opened 3 years ago

hamdav commented 3 years ago

Previously SetLayer and SetLayerThickness had no effect. This was due to the wrong function being called. I added the material argument to S4_Simulation_SetLayer in SetLayer and called Simulation_ChangeLayerThickness in SetLayerThickness.

If you before my commit ran the code at the bottom, it printed

0.69436509370145
0.69436509370145
0.69436509370145

which is clearly wrong, the new thickness should change the result. After the commit it prints

0.69436509370145
0.70218448995991
0.70206228871898

The lua code to test it was

-- Create a new simulation object
S = S4.NewSimulation()

-- Create the different materials
S:AddMaterial("vacuum", {1.000000,0.000000})
S:AddMaterial("GAAS", {11.38482,0.000000})

-- Add the layers
S:AddLayer('Layer_Above', 0.000000, 'vacuum')
S:AddLayer('gaas_0', 100, 'GAAS')
S:AddLayer('Layer_Below', 0.000000, 'vacuum')

-- Set exitiation and freq
S:SetExcitationPlanewave({0.0,0.0},{1.0, 0.0},{0.0,0.0})
S:SetFrequency(1/1550)

-- Print the results
incidence_flux, reflection_flux_vacuum = S:GetPoyntingFlux('Layer_Above', 0.000000)
reflection_flux_vacuum = (-1) * reflection_flux_vacuum / incidence_flux;
print(reflection_flux_vacuum);

-- Change middle thickness
S:SetLayer('gaas_0', 110, 'GAAS')

-- Print the results
incidence_flux, reflection_flux_vacuum = S:GetPoyntingFlux('Layer_Above', 0.000000)
reflection_flux_vacuum = (-1) * reflection_flux_vacuum / incidence_flux;
print(reflection_flux_vacuum);

-- Change middle thickness
S:SetLayerThickness('gaas_0', 120)

-- Print the results
incidence_flux, reflection_flux_vacuum = S:GetPoyntingFlux('Layer_Above', 0.000000)
reflection_flux_vacuum = (-1) * reflection_flux_vacuum / incidence_flux;
print(reflection_flux_vacuum);

I also found that testing/runtests.sh wasn't functioning, but haven't done anything about that. Anyway, nice work apart from this :)

hamdav commented 3 years ago

Should solve #74 btw

WangL3i commented 2 years ago

Do I need to recompile after modification?

WangL3i commented 2 years ago

Why do I get an error when recompiling?

hamdav commented 2 years ago

Yes you have to recompile after you merge the pull request. I don't know why you get an error, if you want help you'll have to provide more than just "I get an error". And yes the thing you pasted is one of the things I changed

WangL3i commented 2 years ago

Hamdav, thank you for your reply!!! When I tried to recompile again, the error is gone. But a new problem arose during my use, when I use the S:Clone() function, I always get an error of Segmentation fault (core dumped). Have you ever encountered such a problem? This problem has been bothering me for many days.

WangL3i commented 2 years ago
font{
    line-height: 1.6;
}
ul,ol{
    padding-left: 20px;
    list-style-position: inside;
}

    Hamdav, thank you for your reply!!! When I tried to recompile again, the error is gone. But a new problem arose during my use, when I use the S:Clone() function, I always get an error of Segmentation fault (core dumped). Have you ever encountered such a problem? This problem has been bothering me for many days.

                ***@***.***

On 3/16/2022 ***@***.***> wrote: 

Yes you have to recompile after you merge the pull request. I don't know why you get an error, if you want help you'll have to provide more than just "I get an error". And yes the thing you pasted is one of the things I changed

—Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>

hamdav commented 2 years ago

No, sorry. It is usually an indication that you are accessing memory that you are not allowed to access, but it can be many things...