Conversation
1c31806 to
a774839
Compare
a774839 to
af81fe8
Compare
MFraters
left a comment
There was a problem hiding this comment.
@gassmoeller, see my post in #6860. To be honest, I am not entirely sure of the current state of the stabilization in the compressible case. @YiminJin, did you derive and implement that now?
Looking again at this code, it seems we made a very deliberate choice tho split them. I think it should be relatively easy to make sure you get the right results, since the test coverage (at least for hte incompressible case) should be sufficient to pick up if you don't rebuild enough. The harder thing to pick up will be to see if we now maybe rebuild too many times now.
If I remember correctly, the difference between rebuild_stokes_matrix and rebuild_newton_stokes_matrix is the rebuild_newton_stokes_matrix rebuilds the lhs of the Newton system and rebuild_stokes_matrix rebuilds the rhs. When computing the residual, you only need to rebuild the rhs, so you don't need rebuild_newton_stokes_matrix. But maybe I am misremembering this.
I think it should be easy enough to test in the old code whether at key points (for example around line 930 and 934 in newton_stokes.cc, whether rebuild_stokes_matrix == rebuild_newton_stokes_matrix in all tests with a simple assertThrow. And maybe similar for assemble_newton_stokes_matrix and assemble_newton_stokes_system. It seems you are also assuming assemble_newton_stokes_matrix == rebuild_stokes_matrix in assembly.cc now, so maybe test that as well in the old code. If that is the case than you can condense it down even more.
| if (derivative_scaling_factor == 0) | ||
| { | ||
| if (scratch.rebuild_newton_stokes_matrix) | ||
| if (scratch.rebuild_stokes_matrix) |
There was a problem hiding this comment.
If rebuild rebuild_stokes_matrix == rebuild_newton_stokes_matrix, then you can just remove this line, since it is already checked line line 930.
I was trying to confirm that with #6860 the Newton solver works correctly for compressible models. I saw some differences (unrelated to this PR). But while debugging, I had trouble following the logic of when or when not we are assembling a Newton/defect correction system instead of a standard Stokes system. I think our logic for that is unnecessarily complicated at the moment.
In essence we need two switches:
Currently, we have three different bool variables for this, because assembling a standard matrix and assembling a newton matrix is handled by separate variables. However, we never assemble a standard and a Newton matrix, it is always one or the other.
I think the code would be easier to understand with just the two switches I described above. This PR is my attempt at this change.
The first test results I have seen look promising, but it looks like the initial Newton residual is now computed differently (it is larger with my change, therefore the method tends to converge better). I will continue looking for what is different tomorrow, but @MFraters could you check if my basic idea is right? And maybe you already spot what is different with this PR?