rafael-fuente / diffractsim

✨🔬 A flexible diffraction simulator for exploring and visualizing physical optics.
https://rafael-fuente.github.io/simulating-diffraction-patterns-with-the-angular-spectrum-method-and-python.html
Other
740 stars 91 forks source link

Rectangular Slit with CUDA #5

Closed ethan-becker-fathom closed 2 years ago

ethan-becker-fathom commented 2 years ago

Running a rectungular slit with CUDA backend gives me the following error:

Traceback (most recent call last): File "C:/Users/ethan/Documents/PycharmProjects/diffraction/examples/circular_aperture_lens.py", line 27, in F.add_rectangular_slit(x0=0, y0=0, width=1.5 mm, height=1.5 mm) File "C:\Users\ethan\Documents\PycharmProjects\diffraction\venv\lib\site-packages\diffractsim\monochromatic_simulator.py", line 68, in add_rectangularslit [bd.ones(self.E.shape), bd.zeros(self.E.shape)], File "C:\Users\ethan\Documents\PycharmProjects\diffraction\venv\lib\site-packages\cupy_indexing\indexing.py", line 199, in select if cond.dtype.type is not cupy.bool: AttributeError: 'bool' object has no attribute 'dtype'

Can be fixed by modifying assignment if the 't' variable in the 'add_rectangular_slit' function.

t = bd.select(
            [
                ((self.xx > (x0 - width / 2)) & (self.xx < (x0 + width / 2)))
                & ((self.yy > (y0 - height / 2)) & (self.yy < (y0 + height / 2))),
                bd.full(self.E.shape, True, dtype=bool)
            ],
            [bd.ones(self.E.shape), bd.zeros(self.E.shape)],
        )
rafael-fuente commented 2 years ago

Thank you for noticing the bug. It's fixed in the new update.