Adaptive error indicator

Hi, every one!
I am trying to implement the right code which is about an adaptive error indicator, it works very well with the old version, i.e., 2.19, but the results were computed by the latest version is weird, I don’t know the reason, I need your help to fix it.

Thank you!