-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
New NewtonSolver._residual0 initialisation (residual) #3611
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,7 +169,10 @@ std::pair<int, bool> nls::petsc::NewtonSolver::solve(Vec x) | |
// Check convergence | ||
bool newton_converged = false; | ||
if (convergence_criterion == "residual") | ||
{ | ||
std::tie(_residual, newton_converged) = this->_converged(*this, _b); | ||
_residual0 = _residual; | ||
} | ||
else if (convergence_criterion == "incremental") | ||
{ | ||
// We need to do at least one Newton step with the ||dx||-stopping | ||
|
@@ -215,13 +218,6 @@ std::pair<int, bool> nls::petsc::NewtonSolver::solve(Vec x) | |
if (_system) | ||
_system(x); | ||
_fnF(x, _b); | ||
// Initialize _residual0 | ||
if (_iteration == 1) | ||
{ | ||
PetscReal _r = 0.0; | ||
VecNorm(_dx, NORM_2, &_r); | ||
_residual0 = _r; | ||
} | ||
|
||
// Test for convergence | ||
if (convergence_criterion == "residual") | ||
|
@@ -232,6 +228,9 @@ std::pair<int, bool> nls::petsc::NewtonSolver::solve(Vec x) | |
// set. | ||
if (_iteration == 1) | ||
{ | ||
PetscReal _r = 0.0; | ||
VecNorm(_dx, NORM_2, &_r); | ||
_residual0 = _r; | ||
_residual = 1.0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to the PR, but I think "residual" initialization Besides the naming is not great and what we call "residual" for incremental criterion is actually increment norm... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this piece of code could be completely refactored so that the convergence criterion can be switched out based on passing a different std::function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can? You can do |
||
newton_converged = false; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Over indented?