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

Issue regarding loops #25

Closed bridgetjs closed 6 years ago

bridgetjs commented 6 years ago

Hi

First of all thanks for publishing all this code! If you have the time, I would appreciate some help with my current problem

I would like to use light pipes to carry out a focus scan of a laser beam.

The approach I've been taking follows the example shown in manual section "5.7. Spherical coordinates" and adding different amounts of defocusing Zernike to scan across the focus. (Perhaps there is a better way)

However when I do this I see some strange behaviour (please see attached files)

FocusingScan 2.zip

In focussingScan.py you will find 3 functions

  1. makefield() produces a field and adds a Gaussian mode and some astigmatism

The 2nd and 3rd functions perform focal scans by calling Propagation() which is based on the example in manual section 5.7

  1. Focus_Scan() performs a focus scan calling makefield() on every loop
  2. broken_focus_scan() does the same thing, except for the fact that the field is only initialised at the beginning. When running this it generates and error message and different results to the first function error in LensFresnel: Behind focus

The function Propagation() is included in the second file.

While I'm happy to code around this, I'm completely lost in trying to identify the source of the problem

guyskk commented 6 years ago

Hi @bridgetjs, I reproduced your problem, the error message is here: https://github.com/opticspy/lightpipes/blob/7dd0e0d6dea5f2511837c878908406a9c9209e45/LightPipes/lpspy.cpp#L619 The field changed on each iteration and may be invalid for next transform(I'm not sure).

bridgetjs commented 6 years ago

Hi @guyskk

So field is changed by the functions in Light Pipes? e.g the following?

field_out = LensFresnel(f,z,field_in) 

Will also have an impact on field_in? Otherwise I'm not sure how the field changes on each iteration

Furthermore testing source of the error message

    z1= -z*f/(z-f);
    if (z1 < 0.0){
            cout << "error in LensFresnel: Behind focus" << endl;
            return Field;
    }

Returns the same result in each case (as expected)

FredvanGoor commented 6 years ago

The grid size is changed in LensFresnel. This causes the error message in the next iteration. Fred

Op ma 20 nov. 2017 om 10:31 schreef bridgetjs notifications@github.com

Hi @guyskk https://github.com/guyskk

So field is changed by the functions in Light Pipes? e.g the following?

field_out = LensFresnel(f,z,field_in)

Will also have an impact on field_in? Otherwise I'm not sure how the field changes on each iteration

Furthermore testing source of the error message

z1= -z*f/(z-f);
if (z1 < 0.0){
        cout << "error in LensFresnel: Behind focus" << endl;
        return Field;
}

Returns the same result in each case (as expected)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/opticspy/lightpipes/issues/25#issuecomment-345639449, or mute the thread https://github.com/notifications/unsubscribe-auth/APLN05ZHpuX7oEvi-WcKXcMGG1034CY6ks5s4UbsgaJpZM4QjV5m .

bridgetjs commented 6 years ago

Exactly what I needed to know. Thank you @FredvanGoor @guyskk