geodynamics / aspect

A parallel, extensible finite element code to simulate convection in both 2D and 3D models.
https://aspect.geodynamics.org/
Other
224 stars 235 forks source link

Iterated solvers always do one nonlinear iteration, even if the max number is set to 0 #2173

Open anne-glerum opened 6 years ago

anne-glerum commented 6 years ago

Because of the do ... while loop, the iterated solver schemes always perform at least one nonlinear iteration, even though the 2 parameters controlling the maximum number of nonlinear iterations can be set to 0. Besides this behavior being unexpected when setting the max number to 0, in the initial refinement phase it can be really useful not to do any iterations (when not refining based on a solution variable). Maybe we could change the loops to while loops?

gassmoeller commented 6 years ago

Hi Anne, I agree this is a bit inconsistent, but not solving anything when setting Number of nonlinear iterations to 0 also seems a bit surprising to me (what if somebody expected to 'just do a linear solver' when setting this number to 0). Are you only concerned about the initial refinement stage? Then this would be quite similar to #1690, maybe the solution that I described there would already work?

bangerth commented 6 years ago

I think the rationale that we've always had was this, in analogy to figuring out whether we need to keep iterating based on the tolerance: In order to determine whether we've reached the tolerance, we need to assemble the system (to compute the residual), and that gets us most of the way there to already doing one solve, so let's just do that as well. Here, the situation is different because you decide based on the number of iterations, not whether a tolerance was reached.

I'm in favor of always doing one iteration because otherwise there is really nothing you can say about the solution: it could simply be random numbers. Or how would you want to initialize the solution otherwise?

MFraters commented 6 years ago

I have currently two use cases where I find it useful to be able to use 0 iterations.

  1. When I am trying to construct initial conditions on large meshes to see whether I constructed them correctly. Solving the system in this case is unnecessary and expensive (and sometimes even impossible, when I have made a mistake, and then there won't be output to see what I did wrong).

  2. When I am doing a pre-refinment, based on the (still to merge) isoterms plugin. This only uses the temperature to do the refinement, so every solving step is a waste of time.

This is also why the Newton solver is currently implemented as a for loop.

@gassmoeller although I can follow you reasoning, if we want to follow that reasoning for the nonlinear iterations, we should always do nonlinear iterations + 1 for everything. I think that that would become counter-intuitive quickly. The way I think about it is that if you are using a nonlinear solver to solver a nonlinear problem, all solves you do are nonlinear iterations. Therefore I would find it not logical that if the user specifically specifies that he/she wants 0 nonlinear iterations, that he/she gets 1 nonlinear iteration (and if he/she set it to 1, they also get 1).

anne-glerum commented 6 years ago

@gassmoeller concerning #1690, Isn't the parameter Max nonlinear iterations in pre-refinement meant for this? This parameter I find very useful, like for the cases Menno describes. With the restructuring of the solvers, this parameter now also always leads to at least 1 nonlinear iteration.

bobmyhill commented 6 years ago

@anne-glerum @gassmoeller @bangerth @MFraters

It seems like there are two possible solutions to the problems outlined here and in #1690:

I would probably favour the second possibility, both in terms of backwards compatibility and to separate linear from nonlinear solves. In both cases, I would argue that there should be an assertion that Max nonlinear iterations is >0.

Opinions?

bobmyhill commented 6 years ago

@jaustermann is this one fixed by your master plan?

jaustermann commented 6 years ago

@bobmyhill Not sure ... @gassmoeller does what we have discussed for #1690 fix this?

gassmoeller commented 6 years ago

Not quite. #1690 will allow to skip the nonlinear iterations in pre-refinement (so that part is resolved), but it will not allow to use 0 nonlinear iterations (=no solve) in later timesteps. Is that something we want/need?

gassmoeller commented 6 years ago

Ok, after a long discussion a number of us agreed on the following:

Since much of the above is independent of each other, and we should not break compatibility except for corner cases it can be implemented in separate small pull requests instead of one big change and everyone is welcome to implement their favorite part of the above specification.