opticspy / lightpipes

LightPipes for Python, "Pure Python version"
https://opticspy.github.io/lightpipes/
BSD 3-Clause "New" or "Revised" License
228 stars 53 forks source link

Reducing computations by considering only x-z plane #31

Open feature-engineer opened 4 years ago

feature-engineer commented 4 years ago

In most cases, it would suffice to only look at what happens in one spatial dimension (x) along the optical axis (z).

This would greatly speed up calculations and reduce the amount of memory used.

Is there a way to create such a 1d field and propagate it?

e.g.

x = np.linspace(-WORLD_SIZE/2, WORLD_SIZE/2, GRID_POINTS)
f = np.exp(-x**2)

f would be our gaussian field.. Currently we get f = np.exp(-y**2+x**2) as far as I can tell...

FredvanGoor commented 4 years ago

I'm going to try to make a new version with different # of gridpoints in x and y. Suggestions are welcome!

Fred van Goor

ldoyle commented 4 years ago

Hi feature-engineer, this depends on the details I guess. A 1D simulation is not the same as a 2D Nx1 simulation. In your case, do you assume infinite extent in the other dimension (simulating e.g. x-z-plane with infinite y) or radial/cylindrical symmetry (r-z-plane simulation)? For example using the Forward() function (or writing down the 2D integrals by hand) will spread the intensity in 3D space, so effectively your simulation is just a "slit" source and a "slit" observer but most light diffracts away from the observer. Maybe the shape will be the same as in the infinitely extended case, but the intensity will be wrong. For the radially symmetric case I'm not sure of the necessary corrections right now. For the Forvard(), if I am informed correctly, the Fourier method uses periodic boundary conditions, effectively generating the infinite extent in the x- and y-dimension. But you would have to double-check that in the manual.

In any case, a simulation with different X and Y dimensions can very much make sense and shouldn't be hard to implement, so maybe someone will take care of that in the (near) future.

jmmelko commented 3 years ago

In most cases, a radial symmetry is enough. Especially with x_shift/y_shift=0 and tx/ty=0 A Hankel transform can be used to handle this case.

Otherwise, there might be a way to compute only one quarter of the grid, and apply a symmetry conditions on the border(?). as done with FEM simulations?