-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NOX] Clean up of NOX::Solver::SingleStep
#379
Comments
@vovannikov Thanks for starting to look at this so quickly. Maybe I can share my view. As far as I know, the single step thing is not used much at all, which basically explains the bad testing … to me it seems like a very special implementation for some Sandia internal application code. The But I agree with all your points … mainly consistency is missing. |
In addition it would be interesting to see how important the single step functionality really is … not quite sure about it. |
@maxfirmbach I guess this functionality could be not the most frequently used one, but this is still a tricky aspect. If we want to have a generalized wrapper for the |
@maxfirmbach the single step solver is used in the explicit time integration where Newton Raphson is not necessary. @vovannikov I did not fully recall the details, but for the single step solver we tried to avoid calling
I did not get your point here. The original intention is not memory optimization, but to tell explicitly that we do not change the direction vector in the process, i.e., |
@vryy thank you for your comments. Indeed, explicit time integration is an important use case. In fact, not all predictors call By memory usage optimization I meant this trick in // Reuse memory in group instead of new allocation for dir
NOX::Abstract::Vector& dir = const_cast<NOX::Abstract::Vector&>(solnPtr->getNewton()); |
Description
The more I look into the code, the more I figure out that certain "non-optimal" design desicions in 4C were made due to the mistakes in the design of
Trilinos
itself. And I think this is the right time to figure out how they should be tackled properly.There is
SingleStep
solver in 4C which is based onNOX::Solver::SingleStep
fromTrilinos
and itssolve()
function looks like this:4C/src/structure_new/src/nonlinear_solver/4C_structure_new_nln_solver_singlestep.cpp
Lines 103 to 124 in 67d3f53
You may see that the
step()
function is customized with some strange calls:Note that
set_is_valid_newton()
andset_is_valid_rhs()
are used only in the implementation of the single step solver, not anywhere else in the code, which makes me think that it was a clear hack to resolve some problem.Indeed, this implementation is dictated by this piece of code
https://github.com/trilinos/Trilinos/blob/62ff542b83d63ad9a56b91ef7af177c485459dc2/packages/nox/src/NOX_Solver_SingleStep.C#L131-L138
Here the author optimized memory usage. Well,
const_cast
is not nice, but what makes it worse is thatgetNewton()
can thrown an exception:https://github.com/trilinos/Trilinos/blob/62ff542b83d63ad9a56b91ef7af177c485459dc2/packages/nox/src-epetra/NOX_Epetra_Group.C#L547-L555
And the only way to set flag
isValidNewton
totrue
is to callGroup::computeNewton()
, and that call is not performed inNOX::Solver::SingleStep
. Aparently, this makesNOX::Epetra::Group
absolutely incompatible withNOX::Solver::SingleStep
. And what it makes the situation even worse is that this behavior is not consistent between different group implementations inTrilinos
itself. For instance,getNewton()
inThyra::Group
can not throw a similar exception because it has not similar checks inside: https://github.com/trilinos/Trilinos/blob/62ff542b83d63ad9a56b91ef7af177c485459dc2/packages/nox/src-thyra/NOX_Thyra_Group.C#L750-L753. Well, in fact, it can throw an exception, but due to dereferencing a nullptr (if that happens), but not due that the flagisNewtonValid=false
.Then a question may arrise: how did Trilinos authors not notice this ever? I think the answer is that they have never used
Epetra::Group
a lot themselves and mainly usedThyra
, at least there is only one test inTrilinos
for the single step solver and it usesThyra
: https://github.com/trilinos/Trilinos/blob/62ff542b83d63ad9a56b91ef7af177c485459dc2/packages/nox/test/epetra/Thyra/Thyra_SingleStepSolver_1D.C.Possible solutions
SingleStep
solver inTrilinos
, should be harmless except from the slightly larger memory consumption, the vector can be created in ctor and then reused. I would go for this option, I think this is a bad design decision inTrilinos
.isNewton()
fromEpetra::Group
class inTrilinos
, but that can be risky since this is a very old legacy code and we do not know whether other codes rely on this behavior.Continue using hacks in 4C.(no way)LinAlg::Vector
).Conclusion
This is a single example. I bet there are more of this, if I keep on tracking the code. While at the beginning I was a bit sceptical about getting rid of
Epetra::Group
as one of the first steps, I think that the need for switching to our own group will get more and more pressing.Epetra::Group
is very much stateful, its behavior is so much dependent on the interplay between its flags (which are a lot), that makes it difficult to use it properly for various solution scenarious which may imply evaluation of only certain parts of the group.I think that probably switching to our own group would still be a bit too much at the moment, since some parts of the code can still be optimized without this move.
@vryy @mayrmt @amgebauer @sebproell @maxfirmbach @georghammerl
The text was updated successfully, but these errors were encountered: