gevero / py_gmm

A Generalized Multiparticle Mie code, especially suited for plasmonics
GNU General Public License v3.0
23 stars 12 forks source link

Is it possible to use py_gmm for dielectric objects? #5

Open paulmueller opened 8 years ago

paulmueller commented 8 years ago

I would like to compute the near field behind a dielectric sphere using py_gmm. From the ipython notebooks, I can tell that I need to define a material in the epsilon folder (https://github.com/gevero/py_gmm/tree/master/epsilon).

Is there a simpler way of computing the field behind a sphere given just the radius in wavelengths and refractive indices of the sphere and the medium?

I appreciate any help to get me started.

Thanks, Paul

gevero commented 8 years ago

Hi Paul

You can certainly do that. Let me comment on a few things in order to help you out:

Best

Giovanni

PS Please remember that py_gmm needs at least two spheres. If you want to study a single sphere you can simply add a very small dummy sphere very far away from the sphere of interest

paulmueller commented 8 years ago

Hi Giovanni,

thank you. It would very much help me if you could create a little toy example and if it is not too much trouble for you. I am actually looking for Mie scattering code that can also deal with large dielectric spheres. I have played around with GMM-FIELD, but there the size of the sphere is limited.

Is it, in principle, possible to use py_gmm with very large radii (e.g. 5-20 wavelengths) and a refractive index of glass (~1.46) embedded in a medium (~1.333)?

I am also looking into scattnlay (https://github.com/ovidiopr/scattnlay/issues/6#) and Kostya proposed to use BHFIELD (http://www.scattport.org/index.php/light-scattering-software/mie-type-codes/list/521-bhfield) for large spheres, because it has arbitrary accuracy.

Regards Paul

gevero commented 8 years ago

Hi Paul

Yes, in principle and in practice it is possible. I will happily put up a small toy example for you. It seems you need large silica spheres in water. In the meantime let me explain you how it works:

Finally, you should simply proceed as follows:

best

Giovanni

kostyfisik commented 8 years ago

Dear Giovanni,

I am not sure, but I believe that the origin of Pauls problem is not physical (the number of multipoles needed) but a mathematical one (Bessels functions are oscillating). I have checked the downward recursive calculation of the Riccati-Bessel functions (it looks that in Scattnlay we evaluate them in a similar to GMM way) against Wolfram-Alpha, and it does not converge even for large number of elements in the recursion if the argument is large enough. (Note that Matlab`s functions give a little bit different result compared to Wolfram-Alpha, I believe that Matlab is wrong). So the obvious way is to increase the precision of the evaluation from 16 digits of double precision to any needed number of digits is to use some arbitrary precision lib, that why I mentioned BHFIELD .

Best regards, Kostya

gevero commented 8 years ago

Hi Kostya

Thanks for your comment. I must confess that a lot of time passed since I implemented the single particle routines of py_gmm, almost ten years, so I think I am kind of rusty... My understanding is that the problem is of course mathematical, but the stability (or instability) of the recurrence is determined by the fact that riccati-bessel functions of the first kind monotonically decrease as the order n increases. So, for upward recurrence, at each jump of order of magnitude, I am losing a significant digit. On the other hand, if I perform downward recurrence, even if starting from a random value, I gain a significant digit each jump of order of magnitude. Of course it may take many iterations to recover the needed significant digits. The paper I linked uses Kapteyn inequality to estimate the number of recursions needed to recover all the necessary significant digits, so It was my belief that py_gmm could handle the situation, nevertheless I might be wrong, especially because I almost always work with metals. In any case, I think that a size parameter of 10 or 20 should not be an issue for any normal Mie code. I shall setup a toy model very soon, in order to check my code.

Best

Giovanni

kostyfisik commented 8 years ago

Dear Giovanni,

Thank you for the link, one more (looks to be useful too) I found in your code, so both this papers are mentioned in an issue for scattnalay about large size parameters. https://github.com/ovidiopr/scattnlay/issues/3

I added a proof-of-concept multiprecision support (early alpha) to Scattnlay, with C++ templates and Boost::Multiprecision lib it was rather strighforward, the code is in "mp" branch at GitHub now . I hope I will have some spare time later on to provide a detailed research in this area and to share the results...

I have check Scattnlay with FEM for large (D=1.5\lambda) particles, and we have addittional self check due to multilayer property (the outgoing field from the inner layer should be zero, if it is not - for sure there is a stability problem). Still it looks to me like the multi precision is the only reliable way to do the check for any size parameter\material properties... Very fast FEM for large 3D particles becomes too time consuming and memory hungry...

Best regards, Kostya

kostyfisik commented 7 years ago

Hi all,

If anyone cares - it looks that multi-precision in Scattnlay works fine now, I was told by @ovidiopr that he checked several examples from Du`s papers, MP fit well while double precision had failed.

gevero commented 7 years ago

Hi Kostya

Thanks for the update. I am happy that Scattnlay work fine. Still MIECPP from Du's paper is a code working in double precision, so i do not understand why another code would need multiple precision to do the same computation. I still believe that the whole issue can be solved by a correct implementation in double precision.

Best

Giovanni

kostyfisik commented 7 years ago

For sure you are right, Du`s algorithm seems to be a superior one. However, it is always nice to verify the result using several independent approaches.

gevero commented 7 years ago

Sure!!! I browsed the code from scattnlay and I guess that the problem is two-fold:

1) the recursion for bessel functions of complex argument is performed directly, and this exposes the code to an overflow problem when the imaginary part of the argument is big. If instead one performs the recursion over the ratio of bessel functions, as in Du's paper, the problem is solved. One then of course needs to express the all expansion coefficients (a[n,l],b[n,l],...) for each layer of the sphere as a function of the ratio of bessel functions. 2) The recursion must be performed using kaptein inequality as in Du, in order to recover all the needed significant digits

Other than that no futher modifications should be needed

Best

Giovanni

kostyfisik commented 7 years ago

Giovanni! You are great! I hope I will find some free time to read Du paper carefully and to take you notes into account. However, this is not a plan for near future :(

gevero commented 7 years ago

I wish I was more familiar than I am with C++, otherwise I could try a pull request myself. Anyway never say never! :)

kostyfisik commented 7 years ago

Feel free to ask any help if you decide to start :) Actually, there are many C++ tutorials around, and modern C++11 with std:: library is very expressive, most of the functions needed for scientific computing you can find in std:: or boost:: libs, and there are a number of good other libs easily available under linux.

The most obvious benefit of C++ is performance - in some case you can turn your C++ to use all cores with an additional single line in the code (via OpenMP routines). With python it turns to be much harder.

jeffmoreland commented 7 years ago

Giovanni,

Did you ever create the toy example for Paul with large silica particles in water consisting of "very large radii (e.g. 5-20 wavelengths) and a refractive index of glass (~1.46) embedded in a medium (~1.333)"? I would be interested to see the code for that example.

gevero commented 7 years ago

Hi Jeff

Actually, I did not. But since you asked, I will post it so in the next couple of days.

Best

Giovanni