Skip to content

Fix correct csqrt input for purely real epsilon and mu

Eskil Vik requested to merge bugfix/fix-csqrt-branch-cut into master

Marked as draft because it is hard to verify whether the modifications are correct or not, so I would like to discuss a bit before merging.

When a purely real valued \epsilon_c and \mu is given as a input, -0j is used as the imaginary part of the input to the complex square root in the following calculations, where it should be +0j (details below for why it should never be -0j). This results causes the output in changes to the impedance the program calculates.

This MR fixes this issue by implementing a function to switch the sign of negative zero imaginary components, and running this function on the inputs of all relevant calls of csqrt(), before they are passed into csqrt() itself.

It would also be possible to implement this functionality directly in csqrt() itself, but arguably this should not be done, since

\lim_{a\to0-} \sqrt{1 + a j} \neq \lim_{a\to0+}\sqrt{1 + a j},

which is what the difference between +0.0 and -0.0 is supposed to represent. If the csqrt() function is to be used other places in the future, this functionality should be retained.


A warning regarding invalid arguments of the bessel function was also removed, since this triggered on the purely real \epsilon_c and \mu case after the fix was made. This warning was (as far as I can tell) obsolete anyway, after the fix to the asymptotic expansion I_{\nu} made earlier. Discussion in comments.


The reference output files corresponding to ./Tests/IW2D_examples/RoundChamberSiO2Input.txt were updated with the new results.

All other tests than this one succeeded after the update (as they should, since the change only affects calculations where \epsilon_c and mu are real, which among the testing inputs is only the case for this one).


More detailed explanation of the mathematics

[moved to a thread so it can be discussed if needed]

Edited by Eskil Vik

Merge request reports

Loading