Skip to content

Fix bug in SetLayer and SetLayerThickness#95

Open
hamdav wants to merge 1 commit intovictorliu:masterfrom
hamdav:master
Open

Fix bug in SetLayer and SetLayerThickness#95
hamdav wants to merge 1 commit intovictorliu:masterfrom
hamdav:master

Conversation

@hamdav
Copy link
Copy Markdown

@hamdav hamdav commented Jan 26, 2021

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

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.
@hamdav
Copy link
Copy Markdown
Author

hamdav commented Jan 26, 2021

Should solve #74 btw

@WangL3i
Copy link
Copy Markdown

WangL3i commented Mar 16, 2022

Do I need to recompile after modification?

@WangL3i
Copy link
Copy Markdown

WangL3i commented Mar 16, 2022

Why do I get an error when recompiling?

@hamdav
Copy link
Copy Markdown
Author

hamdav commented Mar 16, 2022

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
Copy link
Copy Markdown

WangL3i commented Mar 16, 2022

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
Copy link
Copy Markdown

WangL3i commented Mar 16, 2022 via email

@hamdav
Copy link
Copy Markdown
Author

hamdav commented Mar 16, 2022

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants