NanoComp / meep

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

Reduce `L` parameter to improve convergence of BiCGSTAB-L algorithm of CW solver in unit test for single precision #2548

Closed oskooi closed 1 year ago

oskooi commented 1 year ago

The CW solver uses the BiCGSTAB-L algorithm which contains a parameter L as described in the docs:

Finally, there is a parameter L that determines a tradeoff between memory and work 
per step and convergence rate of the iterative algorithm, biconjugate gradient 
stabilized BiCGSTAB-L, that is used; larger values of L will often lead to faster 
convergence at the expense of more memory and more work per iteration.

A unit test for the CW solver in test_array_metadata.py occasionally fails when using single-precision floating point for the fields. This failure is traced to the failure of the BiCGSTAB-L algorithm to converge to the correct resonant frequency of the ring resonator used in the test. Reducing L from 10 to 7 (only for single precision) fixes the convergence which in turn reduces the flakiness of this test.

In addition to the change in the L parameter of solve_cw (as well as a comment to explain why this change is necessary), this PR also includes some improvements to the formatting of this test.