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

Segmentation fault in Python 3 on Ubuntu 18.04 #83

Closed phoebe-p closed 5 years ago

phoebe-p commented 5 years ago

This issue appears to be related to #42 and #67, however, it only occurs in Ubuntu 18.04.

When installing the S4 Python extension (specifically, this fork which has been modified to be compatible with Python3.x), trying to run any example with patterned layers results in 'Segmentation fault (core dumped)' in Ubuntu 18.04. However, this does not occur when following the same installation steps in Ubuntu 16.04 (other Ubuntu versions have not been tested). Running an example with no patterned layers does not cause a segmentation fault. This happens in Python3.5 and Python3.6.

Unfortunately, there is are no other errors or any traceback to help identify the problem. There are no errors during compilation.

Does anyone have any idea what could be causing this problem? Due to the lack of error messages, I am not sure where to start.

I used this simple example (from @jmllorens in #67) to check whether the segmentation fault occurs:

import S4
import numpy as np

S = S4.New(Lattice = ((.24,0),(0,.24)), NumBasis=100)

S.SetMaterial(Name='silicon',Epsilon = 12+0.01j)
S.SetMaterial(Name='vacuum',Epsilon = 1+0.00j)
S.SetMaterial(Name='b',Epsilon = 12+0.00j)

S.AddLayer(Name = 'incidentMedium', Thickness = 0, Material = 'vacuum');
S.AddLayer(Name = 'pillar', Thickness = 0.120, Material = 'vacuum')

S.SetRegionRectangle('pillar', 'silicon', (0,0), 0, (0.021, 0.021))

S.AddLayer(Name = 'base', Thickness = 10e-3, Material = 'silicon')
S.AddLayer(Name = 'airBellow', Thickness = 0, Material = 'vacuum')

S.SetExcitationPlanewave(IncidenceAngles = (0, 0),\
                        pAmplitude = 1 + 0j,\
                        sAmplitude = 0 + 0j)

freq = np.linspace(2.5, 1.11111, 10);
for freqI in freq:
    S.SetFrequency(freqI);
    [f_front,b_front] = S.GetPowerFlux('incidentMedium', 0);
    [f_back, b_back] = S.GetPowerFlux('airBellow',0);
    reflection = -b_front.real/f_front.real
    transmission = f_back.real/f_front.real
    print(reflection)
jmllorens commented 5 years ago

Hi Phoebe,

There is a problem in the call to Eigensystem. You can check this commit from @jbuencuerpo. In particular the RCWA.cpp file. After applying the patch everything works fine. I tested it with your fork and python example.

José.

PS: To localize the error it is useful to compile the extension with CFLAGS=-g. After recompiling the extension you can debug the code

gdb python
run S4_script.py
backtrace
phoebe-p commented 5 years ago

Hi José, it worked! Thank you very much for the helpful & very fast reply :)