NanoComp / meep

free finite-difference time-domain (FDTD) software for electromagnetic simulations
GNU General Public License v2.0
1.21k stars 618 forks source link

single-precision floating point for the fields arrays exacerbates chaotic behavior for Maxwell-Bloch simulation? #1700

Open oskooi opened 3 years ago

oskooi commented 3 years ago

Compiling Meep with --enable-single switches the floating-point precision of the time-domain and DFT fields arrays from double to single precision (#1544, #1675). However, two of the unit tests involving nonlinearities (test_multilevel_atom.py and nonlinear_ex of symmetry.cpp) produce significantly different results (i.e., several orders of magnitude) for single precision compared to double precision that they had to be disabled (#1698). One possible explanation for this effect was proposed by @stevengj :

Maybe we are entering some sort of chaotic regime, in which the precise details (phase etcetera) are extremely sensitive to initial conditions and small calculational errors.

It would be useful to look into this more carefully to verify whether this is true or not. Specifically, why would a Maxwell-Bloch simulation be overly sensitive to floating-point roundoff error?

cc @acerjan

acerjan commented 3 years ago

Sorry for the slow response time here. I think there are a few things that could be occurring, depending on what exactly the nonlinear checks are doing physically. If the nonlinear checker isn't running long enough to reach a steady-state lasing solution, and is instead just running some amount of amplification for a short time on a cavity that is only a few pixels wide, for example, yeah, this could be exceptionally sensitive to the initial conditions as well as the exact step sizes.

Also, if the cavity is completely closed, without any PML, the energy in the system should just slosh back and forth (Rabi oscillations) between the atomic medium and the electromagnetic field. This process would also probably be dependent on the initial conditions.

Anyway, if we want to get to the bottom of this, we'd need to dig into exactly what the check are doing.