Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_source_slice produces segmentation fault when slice area is smaller than source area #669

Closed
oskooi opened this issue Jan 14, 2019 · 0 comments · Fixed by #810 or #828
Closed
Labels

Comments

@oskooi
Copy link
Collaborator

oskooi commented Jan 14, 2019

The get_source_slice routine produces a segmentation fault when the slice area is smaller than the source area. This is demonstrated in the following example of a source with a Gaussian spatial profile centered at the origin and defined by an amplitude function.

import meep as mp
import cmath
import numpy as np
import matplotlib.pyplot as plt

resolution = 50

cell_size = mp.Vector3(7,7,0)

def src_amp(x0):
  if x0.norm() < 2.0:
    return cmath.exp(-x0.norm()**2)
  else:
    return 0

sources = [mp.Source(mp.GaussianSource(1,fwidth=0.2),
                     component=mp.Ez,
                     center=mp.Vector3(),
                     size=mp.Vector3(4,4,0),
                     amp_func=src_amp)]

sim = mp.Simulation(resolution=resolution,
                    cell_size=cell_size,
                    k_point=mp.Vector3(),
                    sources=sources)

sim.init_sim()
src_data = sim.get_source_slice(mp.Ez, center=mp.Vector3(), size=mp.Vector3(6,6,0))

plt.figure(dpi=100)
plt.imshow(np.real(src_data.transpose()), cmap='hot_r', interpolation='spline36')
plt.axis('off')
plt.show()

For the case shown above in which the source area is of size mp.Vector3(4,4,0) and the slice area is mp.Vector3(6,6,0), the results are as expected:

test_get_source4x4_slice6x6

However, when the area of the slice is strictly smaller then that of the source (e.g., mp.Vector3(3,3,0)), a segmentation fault is produced:

Using MPI version 3.1, 1 processes
-----------
Initializing structure...
Working in 2D dimensions.
Computational cell is 7 x 7 x 0 with resolution 50
time for set_epsilon = 0.103206 s
-----------
python3.5: malloc.c:2401: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
[simpetus:12112] *** Process received signal ***
[simpetus:12112] Signal: Aborted (6)
[simpetus:12112] Signal code:  (-6)
[simpetus:12112] [ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0x12890)[0x7f6932423890]
[simpetus:12112] [ 1] /lib/x86_64-linux-gnu/libc.so.6(gsignal+0xc7)[0x7f693205ee97]
[simpetus:12112] [ 2] /lib/x86_64-linux-gnu/libc.so.6(abort+0x141)[0x7f6932060801]
[simpetus:12112] [ 3] /lib/x86_64-linux-gnu/libc.so.6(+0x93a91)[0x7f69320b3a91]
[simpetus:12112] [ 4] /lib/x86_64-linux-gnu/libc.so.6(+0x94ff0)[0x7f69320b4ff0]
[simpetus:12112] [ 5] /lib/x86_64-linux-gnu/libc.so.6(__libc_malloc+0x27d)[0x7f69320b72ed]
[simpetus:12112] [ 6] python3.5[0x59ce9a]
[simpetus:12112] [ 7] python3.5(PyDict_SetItem+0x2c7)[0x5a0897]
[simpetus:12112] [ 8] python3.5[0x5347b7]
[simpetus:12112] [ 9] python3.5(PyEval_EvalFrameEx+0x7cc4)[0x53e444]
[simpetus:12112] [10] python3.5[0x5401ef]
[simpetus:12112] [11] python3.5(PyEval_EvalFrameEx+0x50bf)[0x53b83f]
[simpetus:12112] [12] python3.5[0x53fc97]
[simpetus:12112] [13] python3.5(PyEval_EvalCode+0x1f)[0x5409bf]
[simpetus:12112] [14] python3.5[0x60cb42]
[simpetus:12112] [15] python3.5(PyRun_FileExFlags+0x9a)[0x60efea]
[simpetus:12112] [16] python3.5(PyRun_SimpleFileExFlags+0x1bc)[0x60f7dc]
[simpetus:12112] [17] python3.5(Py_Main+0x456)[0x640256]
[simpetus:12112] [18] python3.5(main+0xe1)[0x4d0001]
[simpetus:12112] [19] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f6932041b97]
[simpetus:12112] [20] python3.5(_start+0x29)[0x5d6999]
[simpetus:12112] *** End of error message ***
Aborted

It should be possible to define the source slice to have an area that is smaller than the overall source area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant