adflow icon indicating copy to clipboard operation
adflow copied to clipboard

Complex step residuals will underflow with small complex step sizes

Open anilyil opened this issue 3 years ago • 1 comments

Description

The PR #130 makes several changes to the adflow behavior in complex mode. One of these is how the complex residuals are reported. We now report the real and complex residuals separately, and use the L2 norm for both. As a result, the complex part of the residual is squared for each cell, summed up over all cells, and then we take the square root.

Recently, @joanibal realized that we could use complex step sizes of around 1e-200 to eliminate any complex-step related errors in the real part of the solution. With this method, the error terms drop out due to underflow. However, as a side effect, the L2 norm computation of the complex residuals will also underflow with a step size of this magnitude.

This issue is purely with how the residuals are reported. The complex code will still work and generate the correct derivatives. However, the complex residuals will be exactly zero for these step sizes for all iterations, which make convergence monitoring difficult.

In a separate PR, we should have a few fixes on this:

  1. Update all complex-step values to 1e-200 in the tests we already have.
  2. Modify the residual norm computation so that the complex residual does not underflow with this value. We can have a reference complex-step multiplier in the code to scale the values before and after the L2 norm computation to avoid this. Or we can just use a 1-norm for the complex residual.

anilyil avatar Mar 11 '21 15:03 anilyil

As I've mentioned, this isn't a bug it's a feature.

If you add a small imaginary perturbation to the residual and then take the sqrt(sum(res^2)) then the imaginary part represents h*d|Rtot|/dx

It sounds like you want |dRtot/dx|. This isn't just a derivative and thus there is no guarantee that you won't need to take the product of derivative seeds to form it. So I suggest first calculating dR/dx (take the imaginary part divide by h) before doing anything else with it, since for a general function a magnitude of 1e-200 might cause a problem.

joanibal avatar Mar 16 '21 15:03 joanibal